/[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 42 by torben, Tue Jun 10 22:22:19 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 115  namespace Util Line 126  namespace Util
126                  return str;                  return str;
127          }          }
128    
129    
130            string str_gsm2latin1(string str)
131            {
132                    str = str_replace_char(str, 0x1c, 198); //AE
133                    str = str_replace_char(str, 0x0b, 216); //OE
134                    str = str_replace_char(str, 0x0e, 197); //AA
135    
136                    str = str_replace_char(str, 0x1d, 230); //ae
137                    str = str_replace_char(str, 0x0c, 248); //oe
138                    str = str_replace_char(str, 0x0f, 229); //aa
139                    return str;
140            }
141    
142          string readUrl(string url, string tempfile)          string readUrl(string url, string tempfile)
143          {          {
144                  char buf[128000];                  char buf[128000];
# Line 141  namespace Util Line 165  namespace Util
165                  return document;                  return document;
166          }          }
167    
168          string convertToUnicode(string _input)          
169    
170            string iconv_wrapper(string _input, string to_format, string from_format)
171          {          {
172                  char* input,*output,*input_ptr, *output_ptr;                  char* input,*output,*input_ptr, *output_ptr;
173                  input = input_ptr = (char*) malloc(_input.size()+1);                  input = input_ptr = (char*) malloc(_input.size()+1);
# Line 153  namespace Util Line 179  namespace Util
179                                    
180                  unsigned int realinsize,insize,outsize,realsize;                  unsigned int realinsize,insize,outsize,realsize;
181                                    
182                  iconv_t icv = iconv_open("UTF8", "ISO8859-1");                  iconv_t icv = iconv_open(to_format.c_str(), from_format.c_str());
183                  if (icv == (iconv_t)-1)                  if (icv == (iconv_t)-1)
184                  {                  {
185                          perror(0);                          perror(0);
# Line 189  namespace Util Line 215  namespace Util
215              return returnstr;              return returnstr;
216          }          }
217    
218            std::string convertToUnicode(std::string str)
219            {
220                    return iconv_wrapper(str, "UTF-8", "ISO8859-1");
221            }
222    
223            std::string convertFromUnicode(std::string str)
224            {
225                    return iconv_wrapper(str, "ISO8859-1", "UTF-8");
226            }
227    
228          int uTimeDiff(const timeval& then, const timeval& now)          int uTimeDiff(const timeval& then, const timeval& now)
229          {          {
230                  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.42

  ViewVC Help
Powered by ViewVC 1.1.20