File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 1818#include " network/network_string.hpp"
1919
2020#include " utils/string_utils.hpp"
21+ #include " utils/utf8/core.h"
2122
2223#include < algorithm> // for std::min
2324#include < iomanip>
@@ -148,17 +149,30 @@ BareNetworkString& BareNetworkString::encodeString16(
148149int BareNetworkString::decodeString16 (irr::core::stringw* out) const
149150{
150151 uint16_t str_len = getUInt16 ();
151- std::u32string convert;
152+ // Irrlicht string has bad append speed for large string
153+ if (sizeof (wchar_t ) == 4 )
154+ out->reserve (str_len + 1 );
155+ else
156+ out->reserve ((str_len * 2 ) + 1 );
152157 for (unsigned i = 0 ; i < str_len; i++)
153158 {
154159 uint32_t c = getUInt32 ();
155160 if (sizeof (wchar_t ) == 2 )
156- convert += (char32_t )c;
161+ {
162+ if (c > 0xffff )
163+ {
164+ c -= 0x10000 ;
165+ // Make a surrogate pair
166+ using namespace utf8 ::internal;
167+ out->append (wchar_t ((c >> 10 ) + LEAD_SURROGATE_MIN));
168+ out->append (wchar_t ((c & 0x3ff ) + TRAIL_SURROGATE_MIN));
169+ }
170+ else
171+ out->append ((wchar_t )c);
172+ }
157173 else
158174 out->append ((wchar_t )c);
159175 }
160- if (str_len > 0 && !convert.empty ())
161- *out = StringUtils::utf32ToWide (convert);
162176 return str_len * 4 + 2 ;
163177} // decodeString16
164178
You can’t perform that action at this time.
0 commit comments