MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / appendUTF8ToNative

Function appendUTF8ToNative

Libraries/Common/StringSpan.h:280–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

278 private:
279#if SC_PLATFORM_WINDOWS
280 bool appendUTF8ToNative(native_char_t* buffer, size_t capacity, size_t& numWritten) const
281 {
282 const char* it = bytesWithoutTerminator();
283 const char* end = it + sizeInBytes();
284 while (it < end)
285 {
286 uint32_t codePoint = 0;
287 if (not decodeUTF8(it, end, codePoint))
288 return false;
289 if (codePoint <= 0xFFFF)
290 {
291 if (numWritten + 1 >= capacity)
292 return false;
293 buffer[numWritten++] = static_cast<wchar_t>(codePoint);
294 }
295 else
296 {
297 if (numWritten + 2 >= capacity)
298 return false;
299 codePoint -= 0x10000;
300 buffer[numWritten++] = static_cast<wchar_t>(0xD800u + (codePoint >> 10));
301 buffer[numWritten++] = static_cast<wchar_t>(0xDC00u + (codePoint & 0x3FFu));
302 }
303 }
304 buffer[numWritten] = L'\0';
305 return true;
306 }
307#endif
308
309 static constexpr bool decodeUTF8(const char*& it, const char* end, uint32_t& codePoint)

Callers 1

appendNullTerminatedToFunction · 0.85

Calls 3

bytesWithoutTerminatorFunction · 0.85
decodeUTF8Function · 0.85
sizeInBytesFunction · 0.70

Tested by

no test coverage detected