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

--- a/common/Strings.cpp
+++ b/common/Strings.cpp
@@ -12,7 +12,8 @@
#ifdef _WINDOWS
#include <windows.h>
#else
-#include <iconv.h>
+#include <locale>
+#include <codecvt>
#endif
#include <algorithm>
#include <sstream>
@@ -50,35 +51,8 @@ std::wstring TelldusCore::charToWstring(const char *value) {
return retval;
#else
- size_t utf8Length = strlen(value);
- size_t outbytesLeft = utf8Length*sizeof(wchar_t);
-
- // Copy the instring
- char *inString = new char[utf8Length+1];
- snprintf(inString, utf8Length+1, "%s", value);
-
- // Create buffer for output
- char *outString = reinterpret_cast<char*>(new wchar_t[utf8Length+1]);
- memset(outString, 0, sizeof(wchar_t)*(utf8Length+1));
-
-#ifdef _FREEBSD
- const char *inPointer = inString;
-#else
- char *inPointer = inString;
-#endif
- char *outPointer = outString;
-
- iconv_t convDesc = iconv_open(WCHAR_T_ENCODING, "UTF-8");
- iconv(convDesc, &inPointer, &utf8Length, &outPointer, &outbytesLeft);
- iconv_close(convDesc);
-
- std::wstring retval( reinterpret_cast<wchar_t *>(outString) );
-
- // Cleanup
- delete[] inString;
- delete[] outString;
-
- return retval;
+ std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
+ return converter.from_bytes(value);
#endif
}
@@ -211,19 +185,8 @@ std::string TelldusCore::wideToString(const std::wstring &input) {
#else
char *inPointer = inString;
#endif
- char *outPointer = outString;
-
- iconv_t convDesc = iconv_open("UTF-8", WCHAR_T_ENCODING);
- iconv(convDesc, &inPointer, &wideSize, &outPointer, &outbytesLeft);
- iconv_close(convDesc);
-
- std::string retval(outString);
-
- // Cleanup
- delete[] inString;
- delete[] outString;
-
- return retval;
+ std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
+ return converter.to_bytes(input);
#endif
}