diff --git a/src/nfc.cc b/src/nfc.cc index c52f204..f5ea3cc 100644 --- a/src/nfc.cc +++ b/src/nfc.cc @@ -573,7 +573,6 @@ bool UTF::is_safe_NFC_start(std::basic_string_view s) } - template IsNFC UTF::isNFC_quick_check(std::basic_string_view s) { @@ -730,6 +729,44 @@ UTF::nfc_string& UTF::nfc_string::assign(String&& src) return *this; } +template +typename +UTF::nfc_string& UTF::nfc_string::push_back(CharT c) +{ + s += c; + if( !is_safe_NFC_start(StringView{&c, 1}) ) + { + normalize(); + } + return *this; +} + +template +typename +UTF::nfc_string& UTF::nfc_string::operator+=(StringView sv) +{ + const String& sv_nfc = toNFC(sv); + s += sv_nfc; + if( !is_safe_NFC_start(sv_nfc) ) + { + normalize(); + } + return *this; +} + +template +typename +UTF::nfc_string& UTF::nfc_string::operator+=(const UTF::nfc_string& ns) +{ + s += ns.get(); + if( !is_safe_NFC_start(ns) ) + { + normalize(); + } + return *this; +} + + // convenience function to avoid ::strdup(pEp::toNFC(text).c_str()); // and unecessary temporary std::string etc. diff --git a/src/nfc.hh b/src/nfc.hh index 8a8a0bc..31b3922 100644 --- a/src/nfc.hh +++ b/src/nfc.hh @@ -123,6 +123,8 @@ public: /// read-only: shares representation operator const String&() const noexcept { return s; } + const String& get() const noexcept { return s;} + /// read write: copy content operator String() const { return s; } @@ -177,13 +179,13 @@ public: return *this; } - nfc_string& operator+=(const StringView& s); + nfc_string& operator+=(StringView s); /// optimization possible to avoid re-normalization in most cases. nfc_string& operator+=(const nfc_string& s); /// optimization possible to avoid re-normalization in most cases. - nfc_string& operator+=(CharT c); + nfc_string& operator+=(CharT c) { push_back(c); return *this; } /// delegates all 9 compare() overloads to s template