MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / convertUTF8toUTF16N

Function convertUTF8toUTF16N

Engine/source/core/strings/unicode.cpp:153–194  ·  view source on GitHub ↗

-----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

151
152//-----------------------------------------------------------------------------
153U32 convertUTF8toUTF16N(const UTF8 *unistring, UTF16 *outbuffer, U32 len)
154{
155 AssertFatal(len >= 1, "Buffer for unicode conversion must be large enough to hold at least the null terminator.");
156 PROFILE_SCOPE(convertUTF8toUTF16);
157
158#ifdef TORQUE_ENABLE_UTF16_CACHE
159 // If we have cached this conversion already, don't do it again
160 U32 hashKey = Torque::hash((const U8 *)unistring, dStrlen(unistring), 0);
161 UTF16CacheTable::Iterator cacheItr = sgUTF16Cache.find(hashKey);
162 if(cacheItr != sgUTF16Cache.end())
163 {
164 const UTF16Cache &cache = (*cacheItr).value;
165 cache.copyToBuffer(outbuffer, len);
166 return getMin(cache.mLength,len - 1);
167 }
168#endif
169
170 U32 walked, nCodepoints;
171 UTF32 middleman;
172
173 nCodepoints=0;
174 while(*unistring != '\0' && nCodepoints < len)
175 {
176 walked = 1;
177 middleman = oneUTF8toUTF32(unistring,&walked);
178 outbuffer[nCodepoints] = oneUTF32toUTF16(middleman);
179 unistring+=walked;
180 nCodepoints++;
181 }
182
183 nCodepoints = getMin(nCodepoints,len - 1);
184 outbuffer[nCodepoints] = '\0';
185
186#ifdef TORQUE_ENABLE_UTF16_CACHE
187 // Cache the results.
188 // FIXME As written, this will result in some unnecessary memory copying due to copy constructor calls.
189 UTF16Cache cache(outbuffer, nCodepoints);
190 sgUTF16Cache.insertUnique(hashKey, cache);
191#endif
192
193 return nCodepoints;
194}
195
196//-----------------------------------------------------------------------------
197U32 convertUTF16toUTF8N( const UTF16 *unistring, UTF8 *outbuffer, U32 len)

Callers 15

drawTextNMethod · 0.85
getStrNWidthMethod · 0.85
getStrNWidthPreciseMethod · 0.85
setMethod · 0.85
convertUTF8toUTF16Function · 0.85
createUTF16stringFunction · 0.85
dFileDeleteFunction · 0.85
dFileRenameFunction · 0.85
dFileTouchFunction · 0.85
dPathCopyFunction · 0.85
openMethod · 0.85
recurseDumpPathFunction · 0.85

Calls 8

oneUTF8toUTF32Function · 0.85
oneUTF32toUTF16Function · 0.85
copyToBufferMethod · 0.80
insertUniqueMethod · 0.80
dStrlenFunction · 0.70
hashFunction · 0.50
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected