Map the characters according to IDNA, returning the empty string on error.
| 2824 | |
| 2825 | // Map the characters according to IDNA, returning the empty string on error. |
| 2826 | std::u32string map(std::u32string_view input) { |
| 2827 | // [Map](https://www.unicode.org/reports/tr46/#ProcessingStepMap). |
| 2828 | // For each code point in the domain_name string, look up the status |
| 2829 | // value in Section 5, [IDNA Mapping |
| 2830 | // Table](https://www.unicode.org/reports/tr46/#IDNA_Mapping_Table), |
| 2831 | // and take the following actions: |
| 2832 | // * disallowed: Leave the code point unchanged in the string, and |
| 2833 | // record that there was an error. |
| 2834 | // * ignored: Remove the code point from the string. This is |
| 2835 | // equivalent to mapping the code point to an empty string. |
| 2836 | // * mapped: Replace the code point in the string by the value for |
| 2837 | // the mapping in Section 5, [IDNA Mapping |
| 2838 | // Table](https://www.unicode.org/reports/tr46/#IDNA_Mapping_Table). |
| 2839 | // * valid: Leave the code point unchanged in the string. |
| 2840 | static std::u32string error = U""; |
| 2841 | std::u32string answer; |
| 2842 | answer.reserve(input.size()); |
| 2843 | for (char32_t x : input) { |
| 2844 | size_t index = find_range_index(x); |
| 2845 | uint32_t descriptor = table[index][1]; |
| 2846 | uint8_t code = uint8_t(descriptor); |
| 2847 | switch (code) { |
| 2848 | case 0: |
| 2849 | break; // nothing to do, ignored |
| 2850 | case 1: |
| 2851 | answer.push_back(x); // valid, we just copy it to output |
| 2852 | break; |
| 2853 | case 2: |
| 2854 | return error; // disallowed |
| 2855 | // case 3 : |
| 2856 | default: |
| 2857 | // We have a mapping |
| 2858 | { |
| 2859 | size_t char_count = (descriptor >> 24); |
| 2860 | uint16_t char_index = uint16_t(descriptor >> 8); |
| 2861 | for (size_t idx = char_index; idx < char_index + char_count; idx++) { |
| 2862 | answer.push_back(mappings[idx]); |
| 2863 | } |
| 2864 | } |
| 2865 | } |
| 2866 | } |
| 2867 | return answer; |
| 2868 | } |
| 2869 | } // namespace ada::idna |
| 2870 | /* end file src/mapping.cpp */ |
| 2871 | /* begin file src/normalization.cpp */ |
no test coverage detected