summaryrefslogtreecommitdiff
path: root/indra/llcommon/llstring.cpp
diff options
context:
space:
mode:
authorLeyla Farazha <leyla@lindenlab.com>2010-07-30 18:07:35 -0700
committerLeyla Farazha <leyla@lindenlab.com>2010-07-30 18:07:35 -0700
commit854e6acb424faa843f9bff7875927fcfec2cb1d4 (patch)
tree5a5f21c59ba6eb1c6551bb37538f3125c2c4ccbb /indra/llcommon/llstring.cpp
parent547bcc907389aeb1a3d974025b621e98d1178714 (diff)
parentafaa076b7dd300a2836205fe6eb9ba5ab08bfb28 (diff)
Merge with dessie/viewer-release
Diffstat (limited to 'indra/llcommon/llstring.cpp')
-rw-r--r--indra/llcommon/llstring.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp
index e9a54c3bf4..2d391839ef 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,38 @@ 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)
+{
+ // From review:
+ // We can preallocate a wide char buffer that is the same length (in wchar_t elements) as the utf8 input,
+ // plus one for a null terminator, and be guaranteed to not overflow.
+
+ // Normally, I'd call that sort of thing premature optimization,
+ // but we *are* seeing string operations taking a bunch of time, especially when constructing widgets.
+// int output_str_len = MultiByteToWideChar(code_page, 0, in.c_str(), in.length(), NULL, 0);
+
+ // reserve place to NULL terminator
+ int output_str_len = in.length();
+ wchar_t* w_out = new wchar_t[output_str_len + 1];
+
+ memset(w_out, 0, output_str_len + 1);
+ int real_output_str_len = 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[real_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;