MCPcopy Create free account
hub / github.com/MyGUI/mygui / convert_buffer_utf8

Function convert_buffer_utf8

Tools/EditorFramework/pugixml.cpp:1359–1379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1357}
1358
1359PUGI__FN bool convert_buffer_utf8(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size)
1360{
1361 const uint8_t* data = static_cast<const uint8_t*>(contents);
1362
1363 // first pass: get length in wchar_t units
1364 out_length = utf_decoder<wchar_counter>::decode_utf8_block(data, size, 0);
1365
1366 // allocate buffer of suitable length
1367 out_buffer = static_cast<char_t*>(xml_memory::allocate((out_length > 0 ? out_length : 1) * sizeof(char_t)));
1368 if (!out_buffer)
1369 return false;
1370
1371 // second pass: convert utf8 input to wchar_t
1372 wchar_writer::value_type out_begin = reinterpret_cast<wchar_writer::value_type>(out_buffer);
1373 wchar_writer::value_type out_end = utf_decoder<wchar_writer>::decode_utf8_block(data, size, out_begin);
1374
1375 assert(out_end == out_begin + out_length);
1376 (void)!out_end;
1377
1378 return true;
1379}
1380
1381template<typename opt_swap>
1382PUGI__FN bool convert_buffer_utf16(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap)

Callers 1

convert_bufferFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected