| 1292 | } |
| 1293 | |
| 1294 | PUGI__FN bool convert_buffer(char_t*& out_buffer, size_t& out_length, xml_encoding encoding, const void* contents, size_t size, bool is_mutable) |
| 1295 | { |
| 1296 | // get native encoding |
| 1297 | xml_encoding wchar_encoding = get_wchar_encoding(); |
| 1298 | |
| 1299 | // fast path: no conversion required |
| 1300 | if (encoding == wchar_encoding) return get_mutable_buffer(out_buffer, out_length, contents, size, is_mutable); |
| 1301 | |
| 1302 | // only endian-swapping is required |
| 1303 | if (need_endian_swap_utf(encoding, wchar_encoding)) return convert_buffer_endian_swap(out_buffer, out_length, contents, size, is_mutable); |
| 1304 | |
| 1305 | // source encoding is utf8 |
| 1306 | if (encoding == encoding_utf8) return convert_buffer_utf8(out_buffer, out_length, contents, size); |
| 1307 | |
| 1308 | // source encoding is utf16 |
| 1309 | if (encoding == encoding_utf16_be || encoding == encoding_utf16_le) |
| 1310 | { |
| 1311 | xml_encoding native_encoding = is_little_endian() ? encoding_utf16_le : encoding_utf16_be; |
| 1312 | |
| 1313 | return (native_encoding == encoding) ? |
| 1314 | convert_buffer_utf16(out_buffer, out_length, contents, size, opt_false()) : |
| 1315 | convert_buffer_utf16(out_buffer, out_length, contents, size, opt_true()); |
| 1316 | } |
| 1317 | |
| 1318 | // source encoding is utf32 |
| 1319 | if (encoding == encoding_utf32_be || encoding == encoding_utf32_le) |
| 1320 | { |
| 1321 | xml_encoding native_encoding = is_little_endian() ? encoding_utf32_le : encoding_utf32_be; |
| 1322 | |
| 1323 | return (native_encoding == encoding) ? |
| 1324 | convert_buffer_utf32(out_buffer, out_length, contents, size, opt_false()) : |
| 1325 | convert_buffer_utf32(out_buffer, out_length, contents, size, opt_true()); |
| 1326 | } |
| 1327 | |
| 1328 | // source encoding is latin1 |
| 1329 | if (encoding == encoding_latin1) return convert_buffer_latin1(out_buffer, out_length, contents, size); |
| 1330 | |
| 1331 | assert(!"Invalid encoding"); |
| 1332 | return false; |
| 1333 | } |
| 1334 | #else |
| 1335 | template <typename opt_swap> PUGI__FN bool convert_buffer_utf16(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) |
| 1336 | { |
no test coverage detected