diff options
author | Tofu Linden <tofu.linden@lindenlab.com> | 2010-07-23 09:51:15 +0100 |
---|---|---|
committer | Tofu Linden <tofu.linden@lindenlab.com> | 2010-07-23 09:51:15 +0100 |
commit | 77911533dc68731f50f40b18cd44e287df28f476 (patch) | |
tree | d2f08b7df7c836cf6d23551a0a97cf0769e1ec3a /indra/llcommon/llstring.cpp | |
parent | 7ee930ea4a5721077974bc5b24d8cc1c6b6a2fae (diff) | |
parent | 66bdd0903d1ded7a2e113938ad47ad8d6076416b (diff) |
merge from PE's viewer-release
Diffstat (limited to 'indra/llcommon/llstring.cpp')
-rw-r--r-- | indra/llcommon/llstring.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index 1561bda201..804c00fd60 100644 --- a/indra/llcommon/llstring.cpp +++ b/indra/llcommon/llstring.cpp @@ -633,14 +633,14 @@ namespace snprintf_hack } } -std::string ll_convert_wide_to_string(const wchar_t* in) +std::string ll_convert_wide_to_string(const wchar_t* in, unsigned int code_page) { std::string out; if(in) { int len_in = wcslen(in); int len_out = WideCharToMultiByte( - CP_ACP, + code_page, 0, in, len_in, @@ -655,7 +655,7 @@ std::string ll_convert_wide_to_string(const wchar_t* in) if(pout) { WideCharToMultiByte( - CP_ACP, + code_page, 0, in, len_in, @@ -669,6 +669,31 @@ std::string ll_convert_wide_to_string(const wchar_t* in) } return out; } + +wchar_t* ll_convert_string_to_wide(const std::string& in, unsigned int code_page) +{ + int output_str_len = MultiByteToWideChar(code_page, 0, in.c_str(), in.length(), NULL, 0); + + // reserve place to NULL terminator + wchar_t* w_out = new wchar_t[output_str_len + 1]; + + memset(w_out, 0, output_str_len + 1); + MultiByteToWideChar (code_page, 0, in.c_str(), in.length(), w_out, output_str_len); + + //looks like MultiByteToWideChar didn't add null terminator to converted string, see EXT-4858. + w_out[output_str_len] = 0; + + return w_out; +} + +std::string ll_convert_string_to_utf8_string(const std::string& in) +{ + wchar_t* w_mesg = ll_convert_string_to_wide(in, CP_ACP); + std::string out_utf8 = ll_convert_wide_to_string(w_mesg, CP_UTF8); + delete[] w_mesg; + + return out_utf8; +} #endif // LL_WINDOWS long LLStringOps::sPacificTimeOffset = 0; |