| 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 | { |
| 1125 | const uint16_t* data = static_cast<const uint16_t*>(contents); |
| 1126 | size_t length = size / sizeof(uint16_t); |
| 1127 | |
| 1128 | // first pass: get length in wchar_t units |
| 1129 | out_length = utf_decoder<wchar_counter, opt_swap>::decode_utf16_block(data, length, 0); |
| 1130 | |
| 1131 | // allocate buffer of suitable length |
| 1132 | out_buffer = static_cast<char_t*>(global_allocate((out_length > 0 ? out_length : 1) * sizeof(char_t))); |
| 1133 | if (!out_buffer) return false; |
| 1134 | |
| 1135 | // second pass: convert utf16 input to wchar_t |
| 1136 | wchar_writer::value_type out_begin = reinterpret_cast<wchar_writer::value_type>(out_buffer); |
| 1137 | wchar_writer::value_type out_end = utf_decoder<wchar_writer, opt_swap>::decode_utf16_block(data, length, out_begin); |
| 1138 | |
| 1139 | assert(out_end == out_begin + out_length); |
| 1140 | (void)!out_end; |
| 1141 | |
| 1142 | return true; |
| 1143 | } |
| 1144 | |
| 1145 | template <typename opt_swap> bool convert_buffer_utf32(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) |
| 1146 | { |
no test coverage detected