/[projects]/smsdaemon/Util.cpp
ViewVC logotype

Diff of /smsdaemon/Util.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 38 by torben, Tue Jun 10 20:25:15 2008 UTC revision 43 by torben, Wed Jun 11 06:46:14 2008 UTC
# Line 42  namespace Util Line 42  namespace Util
42                  return str;                  return str;
43          }          }
44    
45        std::string str_replace_char(std::string str, char search, char replace)
46            {
47                    unsigned int pos = 0;
48    
49                    while ( (pos = str.find(search,pos)) != string::npos)
50                    {
51                            str.replace(pos, 1, 1, replace);
52                    }
53                    return str;
54            }
55    
56                    
57    
58          string str_trim(string str)          string str_trim(string str)
# Line 90  namespace Util Line 101  namespace Util
101                  return retval;                  return retval;
102          }          }
103    
104    
105        string str_toupper(string str)
106            {
107                    for (unsigned i=0; i<str.length(); ++i)
108                    {
109                            str.replace(i, 1 ,1, ::toupper(str.at(i)));
110                    }
111                    return str;
112            }
113    
114            string str_tolower(string str)
115            {
116                    for (unsigned i=0; i<str.length(); ++i)
117                    {
118                            str.replace(i, 1 ,1, ::tolower(str.at(i)));
119                    }
120                    return str;
121            }
122    
123    
124          string str_characters(string str)          string str_characters(string str)
125          {          {
126                  string rep;                  string rep;
# Line 115  namespace Util Line 146  namespace Util
146                  return str;                  return str;
147          }          }
148    
149    
150            string str_gsm2latin(string str)
151            {
152                    str = str_replace_char(str, 0x1c, 198); //AE
153                    str = str_replace_char(str, 0x0b, 216); //OE
154                    str = str_replace_char(str, 0x0e, 197); //AA
155    
156                    str = str_replace_char(str, 0x1d, 230); //ae
157                    str = str_replace_char(str, 0x0c, 248); //oe
158                    str = str_replace_char(str, 0x0f, 229); //aa
159                    return str;
160            }
161    
162            string str_latin2gsm(string str)
163            {
164                    str = str_replace_char(str, 198, 0x1c); //AE
165                    str = str_replace_char(str, 216, 0x0b); //OE
166                    str = str_replace_char(str, 197, 0x0e); //AA
167    
168                    str = str_replace_char(str, 230, 0x1d); //ae
169                    str = str_replace_char(str, 248, 0x0c); //oe
170                    str = str_replace_char(str, 229, 0x0f); //aa
171                    return str;
172            }
173    
174          string readUrl(string url, string tempfile)          string readUrl(string url, string tempfile)
175          {          {
176                  char buf[128000];                  char buf[128000];
# Line 141  namespace Util Line 197  namespace Util
197                  return document;                  return document;
198          }          }
199    
200          string convertToUnicode(string _input)          
201    
202            string iconv_wrapper(string _input, string to_format, string from_format)
203          {          {
204                  char* input,*output,*input_ptr, *output_ptr;                  char* input,*output,*input_ptr, *output_ptr;
205                  input = input_ptr = (char*) malloc(_input.size()+1);                  input = input_ptr = (char*) malloc(_input.size()+1);
# Line 153  namespace Util Line 211  namespace Util
211                                    
212                  unsigned int realinsize,insize,outsize,realsize;                  unsigned int realinsize,insize,outsize,realsize;
213                                    
214                  iconv_t icv = iconv_open("UTF8", "ISO8859-1");                  iconv_t icv = iconv_open(to_format.c_str(), from_format.c_str());
215                  if (icv == (iconv_t)-1)                  if (icv == (iconv_t)-1)
216                  {                  {
217                          perror(0);                          perror(0);
# Line 189  namespace Util Line 247  namespace Util
247              return returnstr;              return returnstr;
248          }          }
249    
250            std::string convertToUnicode(std::string str)
251            {
252                    return iconv_wrapper(str, "UTF-8", "ISO8859-1");
253            }
254    
255            std::string convertFromUnicode(std::string str)
256            {
257                    return iconv_wrapper(str, "ISO8859-1", "UTF-8");
258            }
259    
260          int uTimeDiff(const timeval& then, const timeval& now)          int uTimeDiff(const timeval& then, const timeval& now)
261          {          {
262                  return ( (now.tv_sec - then.tv_sec)*1000000) + (now.tv_usec-then.tv_usec);                  return ( (now.tv_sec - then.tv_sec)*1000000) + (now.tv_usec-then.tv_usec);

Legend:
Removed from v.38  
changed lines
  Added in v.43

  ViewVC Help
Powered by ViewVC 1.1.20