Normalize `input` with ICU's normalizer with `mode`.
| 60 | #ifdef ENABLE_NFKC_COMPILE |
| 61 | // Normalize `input` with ICU's normalizer with `mode`. |
| 62 | Builder::Chars UnicodeNormalize(UNormalizationMode mode, |
| 63 | const Builder::Chars &input) { |
| 64 | const std::string utf8 = string_util::UnicodeTextToUTF8(input); |
| 65 | CHECK(!utf8.empty()); |
| 66 | |
| 67 | icu::UnicodeString ustr = icu::UnicodeString::fromUTF8(utf8.c_str()); |
| 68 | |
| 69 | UErrorCode status = U_ZERO_ERROR; |
| 70 | icu::UnicodeString dst; |
| 71 | icu::Normalizer::normalize(ustr, mode, 0, dst, status); |
| 72 | CHECK(U_SUCCESS(status)); |
| 73 | std::string normalized; |
| 74 | normalized.reserve(dst.length() * 3); |
| 75 | dst.toUTF8String(normalized); |
| 76 | return string_util::UTF8ToUnicodeText(normalized); |
| 77 | } |
| 78 | |
| 79 | Builder::Chars ToNFKD(const Builder::Chars &input) { |
| 80 | return UnicodeNormalize(UNORM_NFKD, input); |
no test coverage detected