| 1165 | } |
| 1166 | |
| 1167 | bool convert_buffer(char_t*& out_buffer, size_t& out_length, xml_encoding encoding, const void* contents, size_t size, bool is_mutable) |
| 1168 | { |
| 1169 | // get native encoding |
| 1170 | xml_encoding wchar_encoding = get_wchar_encoding(); |
| 1171 | |
| 1172 | // fast path: no conversion required |
| 1173 | if (encoding == wchar_encoding) return get_mutable_buffer(out_buffer, out_length, contents, size, is_mutable); |
| 1174 | |
| 1175 | // only endian-swapping is required |
| 1176 | if (need_endian_swap_utf(encoding, wchar_encoding)) return convert_buffer_endian_swap(out_buffer, out_length, contents, size, is_mutable); |
| 1177 | |
| 1178 | // source encoding is utf8 |
| 1179 | if (encoding == encoding_utf8) return convert_buffer_utf8(out_buffer, out_length, contents, size); |
| 1180 | |
| 1181 | // source encoding is utf16 |
| 1182 | if (encoding == encoding_utf16_be || encoding == encoding_utf16_le) |
| 1183 | { |
| 1184 | xml_encoding native_encoding = is_little_endian() ? encoding_utf16_le : encoding_utf16_be; |
| 1185 | |
| 1186 | return (native_encoding == encoding) ? |
| 1187 | convert_buffer_utf16(out_buffer, out_length, contents, size, opt_false()) : |
| 1188 | convert_buffer_utf16(out_buffer, out_length, contents, size, opt_true()); |
| 1189 | } |
| 1190 | |
| 1191 | // source encoding is utf32 |
| 1192 | if (encoding == encoding_utf32_be || encoding == encoding_utf32_le) |
| 1193 | { |
| 1194 | xml_encoding native_encoding = is_little_endian() ? encoding_utf32_le : encoding_utf32_be; |
| 1195 | |
| 1196 | return (native_encoding == encoding) ? |
| 1197 | convert_buffer_utf32(out_buffer, out_length, contents, size, opt_false()) : |
| 1198 | convert_buffer_utf32(out_buffer, out_length, contents, size, opt_true()); |
| 1199 | } |
| 1200 | |
| 1201 | assert(!"Invalid encoding"); |
| 1202 | return false; |
| 1203 | } |
| 1204 | #else |
| 1205 | template <typename opt_swap> bool convert_buffer_utf16(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) |
| 1206 | { |
no test coverage detected