diff --git a/src/nfc.cc b/src/nfc.cc index 3e09c66..6c0821f 100644 --- a/src/nfc.cc +++ b/src/nfc.cc @@ -787,6 +787,17 @@ UTF::nfc_string UTF::nfc_string::substr(std::size_t pos, std::size return nfc_string{s.substr(pos,count)}; } + +template +void UTF::nfc_string::normalize() +{ + if(isNFC_quick_check(s) != IsNFC::Yes) + { + s = generate( createNFC( fromUtf_decompose(s) )); + } +} + + // convenience function to avoid ::strdup(pEp::toNFC(text).c_str()); // and unecessary temporary std::string etc. char* strdup_NFC(std::string_view s) diff --git a/src/nfc.hh b/src/nfc.hh index 72c286e..c5774ab 100644 --- a/src/nfc.hh +++ b/src/nfc.hh @@ -47,7 +47,6 @@ public: static void generate(const char32_t c, OutIter& out); - /// returns whether the sequence starts with IsNFC==Yes char static bool is_safe_NFC_start(std::basic_string_view s); @@ -62,6 +61,7 @@ public: bool isNFC(std::basic_string_view s); /// returns true if the sequence is valid UTF-8 + static bool isUtf(const CharT* begin, const CharT* end); /// converts a C++ string (in UTF-8/-16) into NFC form