| 642 | |
| 643 | template <typename forward_iterator, typename unary_op> |
| 644 | inline void convert_to_utf32( |
| 645 | forward_iterator ibegin, |
| 646 | forward_iterator iend, |
| 647 | unary_op op |
| 648 | ) |
| 649 | { |
| 650 | |
| 651 | using char_type = std::decay_t<decltype(*ibegin)>; |
| 652 | static_assert(std::is_same<char_type, char>::value || |
| 653 | std::is_same<char_type, wchar_t>::value || |
| 654 | std::is_same<char_type, unichar>::value, |
| 655 | "char_type must be either char or unichar"); |
| 656 | |
| 657 | if (std::is_same<char_type, unichar>::value) |
| 658 | { |
| 659 | while (ibegin != iend) |
| 660 | op(*(ibegin++)); |
| 661 | return; |
| 662 | } |
| 663 | |
| 664 | if (std::is_same<char_type, wchar_t>::value) |
| 665 | { |
| 666 | // Unix |
| 667 | if (sizeof(wchar_t) == 4) |
| 668 | { |
| 669 | while (ibegin != iend) |
| 670 | op(static_cast<unichar>(*(ibegin++))); |
| 671 | return; |
| 672 | } |
| 673 | // Win32 |
| 674 | if (sizeof(wchar_t) == 2) |
| 675 | { |
| 676 | while (ibegin != iend) |
| 677 | { |
| 678 | if (is_surrogate(*ibegin)) |
| 679 | { |
| 680 | op(surrogate_pair_to_unichar(*ibegin, *(ibegin+ 1))); |
| 681 | ibegin += 2; |
| 682 | } |
| 683 | else |
| 684 | { |
| 685 | op(zero_extend_cast<unichar>(*ibegin)); |
| 686 | ibegin += 1; |
| 687 | } |
| 688 | } |
| 689 | return; |
| 690 | } |
| 691 | throw invalid_utf8_error(); |
| 692 | } |
| 693 | |
| 694 | if (std::is_same<char_type, char>::value) |
| 695 | { |
| 696 | unichar ch; |
| 697 | int status = 0; |
| 698 | while (ibegin != iend) |
| 699 | { |
| 700 | status = unicode_helpers::u8_to_u32(ch, ibegin, iend); |
| 701 | if (status > 0) |
no test coverage detected