From 640d7d210b7d5b7e4a39e7268543d365b5a1d4e1 Mon Sep 17 00:00:00 2001 From: roker Date: Fri, 8 Oct 2021 09:01:46 +0200 Subject: [PATCH] implement the last missing method: nfc_string::normalize(). --- src/nfc.cc | 11 +++++++++++ src/nfc.hh | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) 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