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

Diff of /smsdaemon/Util.cpp

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

revision 141 by torben, Sun Dec 7 13:28:52 2008 UTC revision 196 by torben, Thu Dec 18 06:53:29 2008 UTC
# Line 13  Line 13 
13  #include <stdlib.h>  #include <stdlib.h>
14    
15  #include <cstring>  #include <cstring>
16  #include "util.h"  #include "Util.h"
17    
18  using namespace std;  using namespace std;
19    
# Line 146  namespace Util Line 146  namespace Util
146                  return str;                  return str;
147          }          }
148    
149    
150            vector<string>  str_split(string input)
151            {
152                    string buf;
153                    stringstream ss(input);
154                    vector<string> tokens;
155                    while (ss >> buf)
156                            tokens.push_back(buf);
157                    return tokens;
158            }
159    
160    
161          vector<string> str_split(string input, string delimiter)          vector<string> str_split(string input, string delimiter)
162          {          {
163                  vector<string> retval;                  vector<string> retval;
# Line 168  namespace Util Line 180  namespace Util
180                  return retval;                  return retval;
181          }          }
182    
183          char my_toupper(char ch)          char danish_map[3][2] = { {198,230}, {216,248}, {197,229} }; // aelig, oslash, aring
184    
185            unsigned char my_toupper(unsigned char ch)
186          {          {
187                  if (ch == 'æ')                  if (ch == 230)
188                          return 'Æ';                          return 198;
189                  if (ch == 'ø')                  if (ch == 248)
190                          return 'Ø';                          return 216;
191                  if (ch == 'å')                  if (ch == 229)
192                          return 'Å';                          return 197;
193    
194                  return ::toupper(ch);                  return ::toupper(ch);
195          }          }
196    
197          char my_tolower(char ch)          unsigned char my_tolower(unsigned char ch)
198          {          {
199                  if (ch == 'Æ')                  if (ch == 198)
200                          return 'æ';                          return 230;
201                  if (ch == 'Ø')                  if (ch == 216)
202                          return 'ø';                          return 248;
203                  if (ch == 'Å')                  if (ch == 197)
204                          return 'å';                          return 229;
205    
206                  return ::tolower(ch);                  return ::tolower(ch);
207          }          }
# Line 223  namespace Util Line 237  namespace Util
237                  string rep;                  string rep;
238                  rep.append(1,197);                  rep.append(1,197);
239                  str = str_replace(str, "&#197;", rep);                  str = str_replace(str, "&#197;", rep);
240                    str = str_replace(str, "&Aring;", rep);
241    
242                  rep.at(0) = 198;                  rep.at(0) = 198;
243                  str = str_replace(str, "&#198;", rep);                  str = str_replace(str, "&#198;", rep);
244                    str = str_replace(str, "&AElig;", rep);
245    
246                  rep.at(0) = 216;                  rep.at(0) = 216;
247                  str = str_replace(str, "&#216;", rep);                  str = str_replace(str, "&#216;", rep);
248                    str = str_replace(str, "&Oslash;", rep);
249    
250    
251                  rep.at(0) = 229;                  rep.at(0) = 229;
252                  str = str_replace(str, "&#229;", rep);                  str = str_replace(str, "&#229;", rep);
253                    str = str_replace(str, "&aring;", rep);
254    
255                  rep.at(0) = 230;                  rep.at(0) = 230;
256                  str = str_replace(str, "&#230;", rep);                  str = str_replace(str, "&#230;", rep);
257                    str = str_replace(str, "&aelig;", rep);
258    
259                  rep.at(0) = 248;                  rep.at(0) = 248;
260                  str = str_replace(str, "&#248;", rep);                  str = str_replace(str, "&#248;", rep);
261                    str = str_replace(str, "&oslash;", rep);
262    
263                  return str;                  return str;
264          }          }
# Line 246  namespace Util Line 266  namespace Util
266    
267          string str_gsm2latin(string str)          string str_gsm2latin(string str)
268          {          {
269                  for (unsigned i=0; i<str.size(); i++) {                  for (unsigned i=0; i<str.size(); i++)
270                    {
271                          str.at(i) = char_def_alphabet_decode(str.at(i));                          str.at(i) = char_def_alphabet_decode(str.at(i));
272                  }                  }
273                  return str;                  return str;
# Line 254  namespace Util Line 275  namespace Util
275    
276          string str_latin2gsm(string str)          string str_latin2gsm(string str)
277          {          {
278                  for (unsigned i=0; i<str.size(); i++) {                  for (unsigned i=0; i<str.size(); i++)
279                    {
280                          str.at(i) = char_def_alphabet_encode(str.at(i));                          str.at(i) = char_def_alphabet_encode(str.at(i));
281                  }                  }
282                  return str;                  return str;
283          }          }
284    
285            /* deprecated, use HttpClient instead
286          string readUrl(string url, string tempfile)          string readUrl(string url, string tempfile)
287          {          {
288                  char buf[128000];                  char buf[128000];
# Line 294  namespace Util Line 317  namespace Util
317                  unlink(tempfile.c_str());                  unlink(tempfile.c_str());
318    
319                  return document;                  return document;
320          }          }*/
321    
322    
323    
# Line 403  namespace Util Line 426  namespace Util
426                  ifstream in(filename.c_str());                  ifstream in(filename.c_str());
427                  if (in)                  if (in)
428                  {                  {
429                          char buffer[2048];                          char buffer[4096];
430                          in.read(buffer, 2047);                          in.read(buffer, 4095);
431                          buffer[ in.gcount() ] = 0;                          buffer[ in.gcount() ] = 0;
432                          str = string(buffer);                          str = string(buffer);
433                          in.close();                          in.close();
434                  }                  }
435                  else                  else
436                  {                  {
437                          string message =  "Could no open ";                          string message =  "Could not open ";
438                          message +=  filename;                          message +=  filename;
439                          throw std::runtime_error(message);                          throw std::runtime_error(message);
440                  }                  }

Legend:
Removed from v.141  
changed lines
  Added in v.196

  ViewVC Help
Powered by ViewVC 1.1.20