diff options
author | Davide Beatrici <davidebeatrici@gmail.com> | 2019-08-10 03:05:00 +0300 |
---|---|---|
committer | Davide Beatrici <davidebeatrici@gmail.com> | 2019-10-11 22:58:46 +0300 |
commit | ed6ff7ca9a18ca6bf416156849f27172d7726054 (patch) | |
tree | 7559bcb0aeaf788c48fcbdb14dc9df4ac4913375 /plugins | |
parent | 5e247f258c0a2fbdabb74361890cad1ccac68407 (diff) |
plugins: convert UTF-16 to UTF-8 using C++11 features
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/mumble_plugin_utils.h | 8 | ||||
-rw-r--r-- | plugins/ut99/ut99.cpp | 13 |
2 files changed, 10 insertions, 11 deletions
diff --git a/plugins/mumble_plugin_utils.h b/plugins/mumble_plugin_utils.h index 0f7742f87..307dc76ff 100644 --- a/plugins/mumble_plugin_utils.h +++ b/plugins/mumble_plugin_utils.h @@ -6,6 +6,14 @@ #ifndef MUMBLE_MUMBLE_PLUGIN_UTILS_H_ #define MUMBLE_MUMBLE_PLUGIN_UTILS_H_ +#include <codecvt> +#include <locale> + +static inline std::string utf16ToUtf8(const std::wstring &wstr) { + std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> conv; + return conv.to_bytes(wstr); +} + // escape lossily converts the given // string to ASCII, replacing any // character not within the printable diff --git a/plugins/ut99/ut99.cpp b/plugins/ut99/ut99.cpp index 827ff9310..9b5a11a00 100644 --- a/plugins/ut99/ut99.cpp +++ b/plugins/ut99/ut99.cpp @@ -35,20 +35,12 @@ */ #include "../mumble_plugin_main.h" +#include "../mumble_plugin_utils.h" procptr_t posptr; procptr_t frtptr; procptr_t topptr; -static void wcsToMultibyteStdString(wchar_t *wcs, std::string &str) { - const int size = WideCharToMultiByte(CP_UTF8, 0, wcs, -1, NULL, 0, NULL, NULL); - if (size == 0) return; - - str.resize(size); - - WideCharToMultiByte(CP_UTF8, 0, wcs, -1, &str[0], size, NULL, NULL); -} - static bool cross(float *a, float *b, float *c) { if (a == 0 || b == 0 || c == 0) return false; @@ -161,8 +153,7 @@ static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, floa wservername[sizeof(wservername)/sizeof(wservername[0]) - 1] = '\0'; - std::string servername; - wcsToMultibyteStdString(wservername, servername); + const std::string servername = utf16ToUtf8(wservername); std::ostringstream contextss; contextss << "{" |