You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.7 KiB

  1. --- a/common/Strings.cpp
  2. +++ b/common/Strings.cpp
  3. @@ -12,7 +12,8 @@
  4. #ifdef _WINDOWS
  5. #include <windows.h>
  6. #else
  7. -#include <iconv.h>
  8. +#include <locale>
  9. +#include <codecvt>
  10. #endif
  11. #include <algorithm>
  12. #include <sstream>
  13. @@ -50,35 +51,8 @@ std::wstring TelldusCore::charToWstring(
  14. return retval;
  15. #else
  16. - size_t utf8Length = strlen(value);
  17. - size_t outbytesLeft = utf8Length*sizeof(wchar_t);
  18. -
  19. - // Copy the instring
  20. - char *inString = new char[utf8Length+1];
  21. - snprintf(inString, utf8Length+1, "%s", value);
  22. -
  23. - // Create buffer for output
  24. - char *outString = reinterpret_cast<char*>(new wchar_t[utf8Length+1]);
  25. - memset(outString, 0, sizeof(wchar_t)*(utf8Length+1));
  26. -
  27. -#ifdef _FREEBSD
  28. - const char *inPointer = inString;
  29. -#else
  30. - char *inPointer = inString;
  31. -#endif
  32. - char *outPointer = outString;
  33. -
  34. - iconv_t convDesc = iconv_open(WCHAR_T_ENCODING, "UTF-8");
  35. - iconv(convDesc, &inPointer, &utf8Length, &outPointer, &outbytesLeft);
  36. - iconv_close(convDesc);
  37. -
  38. - std::wstring retval( reinterpret_cast<wchar_t *>(outString) );
  39. -
  40. - // Cleanup
  41. - delete[] inString;
  42. - delete[] outString;
  43. -
  44. - return retval;
  45. + std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
  46. + return converter.from_bytes(value);
  47. #endif
  48. }
  49. @@ -211,19 +185,8 @@ std::string TelldusCore::wideToString(co
  50. #else
  51. char *inPointer = inString;
  52. #endif
  53. - char *outPointer = outString;
  54. -
  55. - iconv_t convDesc = iconv_open("UTF-8", WCHAR_T_ENCODING);
  56. - iconv(convDesc, &inPointer, &wideSize, &outPointer, &outbytesLeft);
  57. - iconv_close(convDesc);
  58. -
  59. - std::string retval(outString);
  60. -
  61. - // Cleanup
  62. - delete[] inString;
  63. - delete[] outString;
  64. -
  65. - return retval;
  66. + std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
  67. + return converter.to_bytes(input);
  68. #endif
  69. }