| 316 | } |
| 317 | |
| 318 | string DataTree::wsEncode(const wstring& wstr) { |
| 319 | stringstream encStream; |
| 320 | |
| 321 | //wchar_t is typically 16 bits on windows, and 32 bits on Unix, so use sizeof(wchar_t) everywhere. |
| 322 | size_t bufSizeBytes = (wstr.length()+1) * sizeof(wchar_t); |
| 323 | |
| 324 | char *data_str = (char *)calloc(bufSizeBytes, sizeof(char)); |
| 325 | |
| 326 | wcstombs(data_str, wstr.c_str(), bufSizeBytes - sizeof(wchar_t)); |
| 327 | |
| 328 | std::string byte_str(data_str); |
| 329 | |
| 330 | free(data_str); |
| 331 | |
| 332 | encStream << std::hex; |
| 333 | |
| 334 | for(char & i : byte_str) { |
| 335 | encStream << '%' << setfill('0') << (unsigned int)((unsigned char)i); |
| 336 | } |
| 337 | |
| 338 | return encStream.str(); |
| 339 | } |
| 340 | |
| 341 | wstring DataTree::wsDecode(const string& str) { |
| 342 | |