7 |
#include <iostream> |
#include <iostream> |
8 |
#include <fstream> |
#include <fstream> |
9 |
#include <iconv.h> |
#include <iconv.h> |
10 |
|
#include <stdexcept> |
11 |
#include <time.h> |
#include <time.h> |
12 |
|
|
13 |
#include "util.h" |
#include "util.h" |
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; |
147 |
} |
} |
148 |
|
|
149 |
|
|
150 |
string str_gsm2latin1(string str) |
string str_gsm2latin(string str) |
151 |
{ |
{ |
152 |
str = str_replace_char(str, 0x1c, 198); //AE |
str = str_replace_char(str, 0x1c, 198); //AE |
153 |
str = str_replace_char(str, 0x0b, 216); //OE |
str = str_replace_char(str, 0x0b, 216); //OE |
159 |
return str; |
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]; |
177 |
string document; |
string document; |
178 |
|
|
179 |
ostringstream command; |
ostringstream command; |
180 |
command << "wget -O " << tempfile << " -o /dev/null \"" << url << "\""; |
command << "wget -O " << tempfile << " --tries=1 --timeout=15 -o /dev/null \"" << url << "\""; |
181 |
system( command.str().c_str() ); |
int res = system( command.str().c_str() ); |
182 |
|
if (res) |
183 |
|
throw std::runtime_error("Command time out"); |
184 |
|
|
185 |
ifstream in( tempfile.c_str() ); |
ifstream in( tempfile.c_str() ); |
186 |
|
|