aboutsummaryrefslogtreecommitdiff
path: root/utils/telldus-core/patches/200-no-iconv.patch
blob: de9493b8b3818b4e76975bd3e71fbd86a583fb1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--- 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(
 	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(co
 #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
 }