diff --git a/server/nfc.cc b/server/nfc.cc index e3858f8..149a2c5 100644 --- a/server/nfc.cc +++ b/server/nfc.cc @@ -159,7 +159,7 @@ illegal_utf8::illegal_utf8( const std::string& msg ) {} -IsNFC isNFC(const std::string& s) +IsNFC isNFC_quick_check(const std::string& s) { const char* begin = s.data(); const char* const end = s.data() + s.size(); @@ -180,15 +180,29 @@ IsNFC isNFC(const std::string& s) return IsNFC::Yes; } + +bool isNFC(const std::string& s) +{ + switch( isNFC_quick_check(s) ) + { + case IsNFC::Yes : return true; + case IsNFC::No : return false; + case IsNFC::Maybe: + { + throw std::logic_error("Deep NGC check is not yet implemented. Sorry."); + } + } + + throw -1; // could never happen, but compiler is too dumb to see this. +} + + // s is ''moved'' to the return value if possible so no copy is done here. std::string toNFC(std::string s) { - if(isNFC(s)==IsNFC::Yes) + if(isNFC(s)) return s; - std::string ret; - // TODO: - - return ret; + throw std::logic_error("NFC normalization is necessary, but unimplemented. Sorry."); } diff --git a/server/nfc.hh b/server/nfc.hh index 2bde904..cd16336 100644 --- a/server/nfc.hh +++ b/server/nfc.hh @@ -23,7 +23,10 @@ protected: // return No or Maybe, if at least one character with NFC_Quickcheck class is "No" or "Maybe" // might throw illegal_utf8 exception -IsNFC isNFC(const std::string& s); +IsNFC isNFC_quick_check(const std::string& s); + +// runs first quick check and a deep test if quick check returns "Maybe". +bool isNFC(const std::string& s); // converts a C++ string (in UTF-8) into NFC form // s is ''moved'' to the return value if possible so no copy is done here.