181 return MultiByteToWideChar( aCodePage, 0, aSource, aSourceLen, aTarget, aTargetLen); |
181 return MultiByteToWideChar( aCodePage, 0, aSource, aSourceLen, aTarget, aTargetLen); |
182 } |
182 } |
183 |
183 |
184 #endif // __linux__ |
184 #endif // __linux__ |
185 |
185 |
186 |
|
187 #ifndef __linux__ |
|
188 /* |
|
189 DllExport std::string Util::wstring2string (const std::wstring& aWide) |
|
190 { |
|
191 int max = ConvertWideCharToMultiByte(aWide.c_str(),aWide.length(),0,0); |
|
192 std::string reply; |
|
193 if (max > 0 ) |
|
194 { |
|
195 char* buffer = new char [max]; |
|
196 try |
|
197 { |
|
198 ConvertWideCharToMultiByte(aWide.c_str(),aWide.length(),buffer,max); |
|
199 reply = std::string (buffer, max); |
|
200 } |
|
201 catch (...) |
|
202 { |
|
203 } |
|
204 delete [] buffer; |
|
205 } |
|
206 return reply; |
|
207 } |
|
208 |
|
209 std::wstring Util::string2wstring (const std::string& aNarrow) |
|
210 { |
|
211 int max = ConvertMultiByteToWideChar(aNarrow.c_str(),aNarrow.length(),0,0); |
|
212 std::wstring reply; |
|
213 if (max > 0 ) |
|
214 { |
|
215 wchar_t* buffer = new wchar_t [max]; |
|
216 try |
|
217 { |
|
218 ConvertMultiByteToWideChar(aNarrow.c_str(),aNarrow.length(),buffer,max); |
|
219 reply = std::wstring (buffer, max); |
|
220 } |
|
221 catch (...) |
|
222 { |
|
223 } |
|
224 delete [] buffer; |
|
225 } |
|
226 return reply; |
|
227 } |
|
228 */ |
|
229 #endif |
|
230 |
|
231 std::wstring Util::string2wstring (const char* aNarrow) |
186 std::wstring Util::string2wstring (const char* aNarrow) |
232 { |
187 { |
233 std::string narrowStr(aNarrow); |
188 std::string narrowStr(aNarrow); |
234 int max = ConvertMultiByteToWideChar(aNarrow, strlen(aNarrow),0,0); |
189 int max = ConvertMultiByteToWideChar(aNarrow, strlen(aNarrow),0,0); |
235 std::wstring reply; |
190 std::wstring reply; |
290 return encodedString; |
245 return encodedString; |
291 } |
246 } |
292 |
247 |
293 std::string Util::Base64Decode( const std::string& aEncodedData ) |
248 std::string Util::Base64Decode( const std::string& aEncodedData ) |
294 { |
249 { |
295 BIO *mem = BIO_new(BIO_s_mem()); |
250 unsigned char* pIn = aEncodedData.c_str(); |
296 BIO_write(mem, aEncodedData.c_str(), aEncodedData.length()); |
251 int inLen = aEncodedData.length(); |
297 |
252 unsigned char* pOut = new unsigned char[inLen]; |
298 BIO* b64 = BIO_new(BIO_f_base64()); |
253 |
299 mem = BIO_push(b64, mem); |
254 int outLen; |
300 int inlen = 0; |
255 std::string aDecodeData; |
301 char inbuf[40]={0}; |
256 |
302 |
257 // create a memory buffer containing base64 encoded data |
303 inlen = BIO_read(b64, inbuf, aEncodedData.length()); |
258 BIO* bmem = BIO_new_mem_buf((void*)pIn, inLen); |
304 BIO_write(mem, inbuf, inlen); |
259 |
305 std::string decodedData = inbuf; |
260 // push a Base64 filter so that reading from buffer decodes it |
306 |
261 BIO *bioCmd = BIO_new(BIO_f_base64()); |
307 BIO_free_all(mem); |
262 // we don't want newlines |
308 return decodedData; |
263 BIO_set_flags(bioCmd, BIO_FLAGS_BASE64_NO_NL); |
309 } |
264 bmem = BIO_push(bioCmd, bmem); |
310 |
265 |
|
266 int finalLen = BIO_read(bmem, (void*)pOut, outLen); |
|
267 |
|
268 aDecodeData.assign(pOut, pOut+finalLen); |
|
269 delete pOut; |
|
270 BIO_free_all(bmem); |
|
271 |
|
272 return aDecodeData; |
|
273 } |
311 |
274 |
312 TUint32 Util::Crc32(const void* aPtr, TInt aLength) |
275 TUint32 Util::Crc32(const void* aPtr, TInt aLength) |
313 { |
276 { |
314 const TUint8* p = (const TUint8*)aPtr; |
277 const TUint8* p = (const TUint8*)aPtr; |
315 const TUint8* q = p + aLength; |
278 const TUint8* q = p + aLength; |