From b0784ba87168e24b0533fc8718a0157cda5ea405 Mon Sep 17 00:00:00 2001 From: est31 Date: Tue, 7 Jul 2015 05:55:07 +0200 Subject: Use UTF-8 instead of narrow Use wide_to_utf8 and utf8_to_wide instead of wide_to_narrow and narrow_to_wide at almost all places. Only exceptions: test functions for narrow conversion, and chat, which is done in a separate commit. --- src/util/string.cpp | 10 ++++++++++ src/util/string.h | 2 ++ 2 files changed, 12 insertions(+) (limited to 'src/util') diff --git a/src/util/string.cpp b/src/util/string.cpp index 187d2a078..60ccc9300 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -168,6 +168,16 @@ std::string wide_to_utf8(const std::wstring &input) #endif // _WIN32 +wchar_t *utf8_to_wide_c(const char *str) +{ + std::wstring ret = utf8_to_wide(std::string(str)).c_str(); + size_t len = ret.length(); + wchar_t *ret_c = new wchar_t[len + 1]; + memset(ret_c, 0, (len + 1) * sizeof(wchar_t)); + memcpy(ret_c, ret.c_str(), len * sizeof(wchar_t)); + return ret_c; +} + // You must free the returned string! // The returned string is allocated using new wchar_t *narrow_to_wide_c(const char *str) diff --git a/src/util/string.h b/src/util/string.h index 6980060e4..793baad0e 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -47,6 +47,8 @@ struct FlagDesc { std::wstring utf8_to_wide(const std::string &input); std::string wide_to_utf8(const std::wstring &input); +wchar_t *utf8_to_wide_c(const char *str); + // NEVER use those two functions unless you have a VERY GOOD reason to // they just convert between wide and multibyte encoding // multibyte encoding depends on current locale, this is no good, especially on Windows -- cgit v1.2.3