|
@ -1,14 +1,16 @@ |
|
|
// This file is under GNU General Public License 3.0
|
|
|
// This file is under GNU General Public License 3.0
|
|
|
// see LICENSE.txt
|
|
|
// see LICENSE.txt
|
|
|
|
|
|
|
|
|
#ifndef JSON_ADAPTER_NFC_HH |
|
|
#ifndef LIBPEPDATATYPES_NFC_HH |
|
|
#define JSON_ADAPTER_NFC_HH |
|
|
#define LIBPEPDATATYPES_NFC_HH |
|
|
|
|
|
|
|
|
#include "config.hh" // to switch between std::string_view or boost::string_view.hh |
|
|
#include "string_view.hh" // to switch between std::string_view or boost::string_view.hh |
|
|
#include <string> |
|
|
#include <string> |
|
|
#include <stdexcept> |
|
|
#include <stdexcept> |
|
|
#include <iosfwd> |
|
|
#include <iosfwd> |
|
|
|
|
|
|
|
|
|
|
|
namespace pEp { |
|
|
|
|
|
|
|
|
enum class IsNFC |
|
|
enum class IsNFC |
|
|
{ |
|
|
{ |
|
|
No=0, // contains a character that cannot occur in NFC
|
|
|
No=0, // contains a character that cannot occur in NFC
|
|
@ -22,7 +24,7 @@ std::ostream& operator<<(std::ostream& o, IsNFC is_nfc); |
|
|
class illegal_utf8 : public std::runtime_error |
|
|
class illegal_utf8 : public std::runtime_error |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
illegal_utf8(sv, unsigned position, const std::string& reason); |
|
|
illegal_utf8(string_view, unsigned position, const std::string& reason); |
|
|
protected: |
|
|
protected: |
|
|
explicit illegal_utf8(const std::string& message); |
|
|
explicit illegal_utf8(const std::string& message); |
|
|
}; |
|
|
}; |
|
@ -35,26 +37,28 @@ uint32_t parseUtf8(const char*& c, const char* end); |
|
|
void toUtf8(const char32_t c, std::string& ret); |
|
|
void toUtf8(const char32_t c, std::string& ret); |
|
|
|
|
|
|
|
|
// throws illegal_utf8 exception if s is not valid UTF-8
|
|
|
// throws illegal_utf8 exception if s is not valid UTF-8
|
|
|
void assert_utf8(sv s); |
|
|
void assert_utf8(string_view s); |
|
|
|
|
|
|
|
|
// creates an NFD u32string from UTF-8 input string s
|
|
|
// creates an NFD u32string from UTF-8 input string s
|
|
|
std::u32string fromUtf8_decompose(sv s); |
|
|
std::u32string fromUtf8_decompose(string_view s); |
|
|
|
|
|
|
|
|
// convert NFD to NFC
|
|
|
// convert NFD to NFC
|
|
|
std::u32string createNFC(std::u32string nfd_string); |
|
|
std::u32string createNFC(std::u32string nfd_string); |
|
|
|
|
|
|
|
|
// return No or Maybe, if at least one character with NFC_Quickcheck class is "No" or "Maybe"
|
|
|
// return No or Maybe, if at least one character with NFC_Quickcheck class is "No" or "Maybe"
|
|
|
// might throw illegal_utf8 exception
|
|
|
// might throw illegal_utf8 exception
|
|
|
IsNFC isNFC_quick_check(sv s); |
|
|
IsNFC isNFC_quick_check(string_view s); |
|
|
|
|
|
|
|
|
// runs first quick check and a deep test if quick check returns "Maybe".
|
|
|
// runs first quick check and a deep test if quick check returns "Maybe".
|
|
|
bool isNFC(sv s); |
|
|
bool isNFC(string_view s); |
|
|
|
|
|
|
|
|
// returns true if the sequence is valid UTF-8
|
|
|
// returns true if the sequence is valid UTF-8
|
|
|
bool isUtf8(const char* begin, const char* end); |
|
|
bool isUtf8(const char* begin, const char* end); |
|
|
|
|
|
|
|
|
// converts a C++ string (in UTF-8) into NFC form
|
|
|
// 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.
|
|
|
// s is ''moved'' to the return value if possible so no copy is done here.
|
|
|
std::string toNFC(sv s); |
|
|
std::string toNFC(string_view s); |
|
|
|
|
|
|
|
|
|
|
|
} // end of namespace pEp
|
|
|
|
|
|
|
|
|
#endif // JSON_ADAPTER_NFC_HH
|
|
|
#endif // LIBPEPDATATYPES_NFC_HH
|
|
|