MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / UnicodeNormalize

Function UnicodeNormalize

external/sentencepiece/src/builder.cc:62–77  ·  view source on GitHub ↗

Normalize `input` with ICU's normalizer with `mode`.

Source from the content-addressed store, hash-verified

60#ifdef ENABLE_NFKC_COMPILE
61// Normalize `input` with ICU's normalizer with `mode`.
62Builder::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
79Builder::Chars ToNFKD(const Builder::Chars &input) {
80 return UnicodeNormalize(UNORM_NFKD, input);

Callers 4

ToNFKDFunction · 0.85
ToNFKCFunction · 0.85
ToNFCFunction · 0.85
ToNFDFunction · 0.85

Calls 4

UnicodeTextToUTF8Function · 0.85
UTF8ToUnicodeTextFunction · 0.85
emptyMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected