| 1100 | } |
| 1101 | |
| 1102 | bool convert_buffer_utf8(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size) |
| 1103 | { |
| 1104 | const uint8_t* data = static_cast<const uint8_t*>(contents); |
| 1105 | |
| 1106 | // first pass: get length in wchar_t units |
| 1107 | out_length = utf_decoder<wchar_counter>::decode_utf8_block(data, size, 0); |
| 1108 | |
| 1109 | // allocate buffer of suitable length |
| 1110 | out_buffer = static_cast<char_t*>(global_allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); |
| 1111 | if (!out_buffer) return false; |
| 1112 | |
| 1113 | // second pass: convert utf8 input to wchar_t |
| 1114 | wchar_writer::value_type out_begin = reinterpret_cast<wchar_writer::value_type>(out_buffer); |
| 1115 | wchar_writer::value_type out_end = utf_decoder<wchar_writer>::decode_utf8_block(data, size, out_begin); |
| 1116 | |
| 1117 | assert(out_end == out_begin + out_length); |
| 1118 | (void)!out_end; |
| 1119 | |
| 1120 | return true; |
| 1121 | } |
| 1122 | |
| 1123 | template <typename opt_swap> bool convert_buffer_utf16(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) |
| 1124 | { |
no test coverage detected