--- smsdaemon/util.cpp 2008/06/10 20:25:15 38 +++ smsdaemon/util.cpp 2008/06/10 22:22:19 42 @@ -42,6 +42,17 @@ return str; } + std::string str_replace_char(std::string str, char search, char replace) + { + unsigned int pos = 0; + + while ( (pos = str.find(search,pos)) != string::npos) + { + str.replace(pos, 1, 1, replace); + } + return str; + } + string str_trim(string str) @@ -115,6 +126,19 @@ return str; } + + string str_gsm2latin1(string str) + { + str = str_replace_char(str, 0x1c, 198); //AE + str = str_replace_char(str, 0x0b, 216); //OE + str = str_replace_char(str, 0x0e, 197); //AA + + str = str_replace_char(str, 0x1d, 230); //ae + str = str_replace_char(str, 0x0c, 248); //oe + str = str_replace_char(str, 0x0f, 229); //aa + return str; + } + string readUrl(string url, string tempfile) { char buf[128000]; @@ -141,7 +165,9 @@ return document; } - string convertToUnicode(string _input) + + + string iconv_wrapper(string _input, string to_format, string from_format) { char* input,*output,*input_ptr, *output_ptr; input = input_ptr = (char*) malloc(_input.size()+1); @@ -153,7 +179,7 @@ unsigned int realinsize,insize,outsize,realsize; - iconv_t icv = iconv_open("UTF8", "ISO8859-1"); + iconv_t icv = iconv_open(to_format.c_str(), from_format.c_str()); if (icv == (iconv_t)-1) { perror(0); @@ -189,6 +215,16 @@ return returnstr; } + std::string convertToUnicode(std::string str) + { + return iconv_wrapper(str, "UTF-8", "ISO8859-1"); + } + + std::string convertFromUnicode(std::string str) + { + return iconv_wrapper(str, "ISO8859-1", "UTF-8"); + } + int uTimeDiff(const timeval& then, const timeval& now) { return ( (now.tv_sec - then.tv_sec)*1000000) + (now.tv_usec-then.tv_usec);