|
@ -4,7 +4,7 @@ |
|
|
#ifndef LIBPEPDATATYPES_NFC_HH |
|
|
#ifndef LIBPEPDATATYPES_NFC_HH |
|
|
#define LIBPEPDATATYPES_NFC_HH |
|
|
#define LIBPEPDATATYPES_NFC_HH |
|
|
|
|
|
|
|
|
#include "string_view.hh" // to switch between std::string_view or boost::string_view.hh |
|
|
#include <string_view> |
|
|
#include <string> |
|
|
#include <string> |
|
|
#include <stdexcept> |
|
|
#include <stdexcept> |
|
|
#include <iosfwd> |
|
|
#include <iosfwd> |
|
@ -25,8 +25,8 @@ std::ostream& operator<<(std::ostream& o, IsNFC is_nfc); |
|
|
class illegal_utf : public std::runtime_error |
|
|
class illegal_utf : public std::runtime_error |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
illegal_utf( string_view, unsigned position, const std::string& reason); |
|
|
illegal_utf( std::string_view, unsigned position, const std::string& reason); |
|
|
illegal_utf(u16string_view, unsigned position, const std::string& reason); |
|
|
illegal_utf(std::u16string_view, unsigned position, const std::string& reason); |
|
|
protected: |
|
|
protected: |
|
|
explicit illegal_utf(const std::string& message); |
|
|
explicit illegal_utf(const std::string& message); |
|
|
}; |
|
|
}; |
|
@ -51,22 +51,22 @@ public: |
|
|
/// 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_utf exception
|
|
|
/// might throw illegal_utf exception
|
|
|
static |
|
|
static |
|
|
IsNFC isNFC_quick_check(basic_string_view<CharT> s); |
|
|
IsNFC isNFC_quick_check(std::basic_string_view<CharT> 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".
|
|
|
static |
|
|
static |
|
|
bool isNFC(basic_string_view<CharT> s); |
|
|
bool isNFC(std::basic_string_view<CharT> s); |
|
|
|
|
|
|
|
|
/// returns true if the sequence is valid UTF-8
|
|
|
/// returns true if the sequence is valid UTF-8
|
|
|
bool isUtf(const CharT* begin, const CharT* end); |
|
|
bool isUtf(const CharT* begin, const CharT* end); |
|
|
|
|
|
|
|
|
/// converts a C++ string (in UTF-8/-16) into NFC form
|
|
|
/// converts a C++ string (in UTF-8/-16) into NFC form
|
|
|
static |
|
|
static |
|
|
std::basic_string<CharT> toNFC(basic_string_view<CharT> s); |
|
|
std::basic_string<CharT> toNFC(std::basic_string_view<CharT> s); |
|
|
|
|
|
|
|
|
/// calculates the number of "code units" in the target Unicode Transfer Format.
|
|
|
/// calculates the number of "code units" in the target Unicode Transfer Format.
|
|
|
static |
|
|
static |
|
|
size_t utf_length(u32string_view s); |
|
|
size_t utf_length(std::u32string_view s); |
|
|
|
|
|
|
|
|
/// generates a whole u32string at once
|
|
|
/// generates a whole u32string at once
|
|
|
static |
|
|
static |
|
@ -74,7 +74,7 @@ public: |
|
|
|
|
|
|
|
|
/// creates an NFD u32string from UTF-8/UTF-16 input string s
|
|
|
/// creates an NFD u32string from UTF-8/UTF-16 input string s
|
|
|
static |
|
|
static |
|
|
std::u32string fromUtf_decompose(basic_string_view<CharT> s); |
|
|
std::u32string fromUtf_decompose(std::basic_string_view<CharT> s); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
using UTF8 = UTF<char>; |
|
|
using UTF8 = UTF<char>; |
|
@ -82,7 +82,7 @@ using UTF16 = UTF<char16_t>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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(string_view s); |
|
|
void assert_utf8(std::string_view s); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// convert NFD to NFC
|
|
|
// convert NFD to NFC
|
|
@ -92,11 +92,11 @@ 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_utf exception
|
|
|
// might throw illegal_utf exception
|
|
|
template<class CharT> |
|
|
template<class CharT> |
|
|
IsNFC isNFC_quick_check(basic_string_view<CharT> s); |
|
|
IsNFC isNFC_quick_check(std::basic_string_view<CharT> 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".
|
|
|
template<class CharT> |
|
|
template<class CharT> |
|
|
bool isNFC(basic_string_view<CharT> s); |
|
|
bool isNFC(std::basic_string_view<CharT> 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); |
|
@ -104,15 +104,16 @@ 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.
|
|
|
template<class CharT> |
|
|
template<class CharT> |
|
|
std::basic_string<CharT> toNFC(basic_string_view<CharT> s); |
|
|
std::basic_string<CharT> toNFC(std::basic_string_view<CharT> s); |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
// creates a UTF-8-encoded NFC string from s
|
|
|
// creates a UTF-8-encoded NFC string from s
|
|
|
std::string toNFC_8(u16string_view s); |
|
|
std::string toNFC_8(std::u16string_view s); |
|
|
|
|
|
|
|
|
// convenience functions to avoid ::strdup(pEp::toNFC<char>(text).c_str());
|
|
|
// convenience functions to avoid ::strdup(pEp::toNFC<char>(text).c_str());
|
|
|
// and unecessary temporary std::string etc.
|
|
|
// and unecessary temporary std::string etc.
|
|
|
char* strdup_NFC(string_view s); |
|
|
char* strdup_NFC(std::string_view s); |
|
|
|
|
|
|
|
|
pEp_identity *identity_dup_NFC(const ::pEp_identity* value); |
|
|
pEp_identity *identity_dup_NFC(const ::pEp_identity* value); |
|
|
::identity_list* identity_list_dup_NFC(const ::identity_list* value); |
|
|
::identity_list* identity_list_dup_NFC(const ::identity_list* value); |
|
|
|
|
|
|
|
|