| 1449 | } |
| 1450 | |
| 1451 | PUGI__FN bool convert_buffer( |
| 1452 | char_t*& out_buffer, |
| 1453 | size_t& out_length, |
| 1454 | xml_encoding encoding, |
| 1455 | const void* contents, |
| 1456 | size_t size, |
| 1457 | bool is_mutable) |
| 1458 | { |
| 1459 | // get native encoding |
| 1460 | xml_encoding wchar_encoding = get_wchar_encoding(); |
| 1461 | |
| 1462 | // fast path: no conversion required |
| 1463 | if (encoding == wchar_encoding) |
| 1464 | return get_mutable_buffer(out_buffer, out_length, contents, size, is_mutable); |
| 1465 | |
| 1466 | // only endian-swapping is required |
| 1467 | if (need_endian_swap_utf(encoding, wchar_encoding)) |
| 1468 | return convert_buffer_endian_swap(out_buffer, out_length, contents, size, is_mutable); |
| 1469 | |
| 1470 | // source encoding is utf8 |
| 1471 | if (encoding == encoding_utf8) |
| 1472 | return convert_buffer_utf8(out_buffer, out_length, contents, size); |
| 1473 | |
| 1474 | // source encoding is utf16 |
| 1475 | if (encoding == encoding_utf16_be || encoding == encoding_utf16_le) |
| 1476 | { |
| 1477 | xml_encoding native_encoding = is_little_endian() ? encoding_utf16_le : encoding_utf16_be; |
| 1478 | |
| 1479 | return (native_encoding == encoding) |
| 1480 | ? convert_buffer_utf16(out_buffer, out_length, contents, size, opt_false()) |
| 1481 | : convert_buffer_utf16(out_buffer, out_length, contents, size, opt_true()); |
| 1482 | } |
| 1483 | |
| 1484 | // source encoding is utf32 |
| 1485 | if (encoding == encoding_utf32_be || encoding == encoding_utf32_le) |
| 1486 | { |
| 1487 | xml_encoding native_encoding = is_little_endian() ? encoding_utf32_le : encoding_utf32_be; |
| 1488 | |
| 1489 | return (native_encoding == encoding) |
| 1490 | ? convert_buffer_utf32(out_buffer, out_length, contents, size, opt_false()) |
| 1491 | : convert_buffer_utf32(out_buffer, out_length, contents, size, opt_true()); |
| 1492 | } |
| 1493 | |
| 1494 | // source encoding is latin1 |
| 1495 | if (encoding == encoding_latin1) |
| 1496 | return convert_buffer_latin1(out_buffer, out_length, contents, size); |
| 1497 | |
| 1498 | assert(!"Invalid encoding"); |
| 1499 | return false; |
| 1500 | } |
| 1501 | #else |
| 1502 | template<typename opt_swap> |
| 1503 | PUGI__FN bool convert_buffer_utf16(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, opt_swap) |
no test coverage detected