|
|
@ -118,7 +118,7 @@ namespace |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
std::string escape(pEp::string_view s) |
|
|
|
std::string escape(std::string_view s) |
|
|
|
{ |
|
|
|
std::string ret; ret.reserve(s.size() + 16 ); |
|
|
|
for(char c : s) |
|
|
@ -136,7 +136,7 @@ namespace |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
std::string escape(pEp::u16string_view s) |
|
|
|
std::string escape(std::u16string_view s) |
|
|
|
{ |
|
|
|
std::string ret; ret.reserve(s.size() + 16 ); |
|
|
|
for(char16_t c : s) |
|
|
@ -224,7 +224,7 @@ namespace |
|
|
|
|
|
|
|
namespace pEp { |
|
|
|
|
|
|
|
std::string escape_utf16(u16string_view s) |
|
|
|
std::string escape_utf16(std::u16string_view s) |
|
|
|
{ |
|
|
|
return escape(s); |
|
|
|
} |
|
|
@ -435,11 +435,11 @@ std::basic_string<CharT> UTF<CharT>::generate(const std::u32string& u32) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
illegal_utf::illegal_utf( string_view s, unsigned position, const std::string& reason) |
|
|
|
illegal_utf::illegal_utf( std::string_view s, unsigned position, const std::string& reason) |
|
|
|
: std::runtime_error( "Illegal UTF-8 string \"" + escape(s) + "\" at position " + std::to_string(position) + ": " + reason ) |
|
|
|
{} |
|
|
|
|
|
|
|
illegal_utf::illegal_utf( u16string_view s, unsigned position, const std::string& reason) |
|
|
|
illegal_utf::illegal_utf( std::u16string_view s, unsigned position, const std::string& reason) |
|
|
|
: std::runtime_error( "Illegal UTF-16 string \"" + escape(s) + "\" at position " + std::to_string(position) + ": " + reason ) |
|
|
|
{} |
|
|
|
|
|
|
@ -449,7 +449,7 @@ illegal_utf::illegal_utf( const std::string& msg ) |
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
void assert_utf8(string_view s) |
|
|
|
void assert_utf8(std::string_view s) |
|
|
|
{ |
|
|
|
const char* begin = s.data(); |
|
|
|
const char* const end = s.data() + s.size(); |
|
|
@ -470,7 +470,7 @@ void assert_utf8(string_view s) |
|
|
|
|
|
|
|
// creates a NFD string from s
|
|
|
|
template<class CharT> |
|
|
|
std::u32string UTF<CharT>::fromUtf_decompose(basic_string_view<CharT> s) |
|
|
|
std::u32string UTF<CharT>::fromUtf_decompose(std::basic_string_view<CharT> s) |
|
|
|
{ |
|
|
|
std::u32string u32s; |
|
|
|
u32s.reserve( static_cast<std::size_t>(s.size()*1.25) ); |
|
|
@ -555,7 +555,7 @@ std::u32string createNFC(std::u32string nfd) |
|
|
|
|
|
|
|
|
|
|
|
template<class CharT> |
|
|
|
IsNFC UTF<CharT>::isNFC_quick_check(basic_string_view<CharT> s) |
|
|
|
IsNFC UTF<CharT>::isNFC_quick_check(std::basic_string_view<CharT> s) |
|
|
|
{ |
|
|
|
const CharT* begin = s.data(); |
|
|
|
const CharT* const end = s.data() + s.size(); |
|
|
@ -585,7 +585,7 @@ IsNFC UTF<CharT>::isNFC_quick_check(basic_string_view<CharT> s) |
|
|
|
|
|
|
|
|
|
|
|
template<class CharT> |
|
|
|
bool UTF<CharT>::isNFC(basic_string_view<CharT> s) |
|
|
|
bool UTF<CharT>::isNFC(std::basic_string_view<CharT> s) |
|
|
|
{ |
|
|
|
switch( isNFC_quick_check(s) ) |
|
|
|
{ |
|
|
@ -618,7 +618,7 @@ try{ |
|
|
|
|
|
|
|
// s is ''moved'' to the return value if possible so no copy is done here.
|
|
|
|
template<class CharT> |
|
|
|
std::basic_string<CharT> UTF<CharT>::toNFC(basic_string_view<CharT> s) |
|
|
|
std::basic_string<CharT> UTF<CharT>::toNFC(std::basic_string_view<CharT> s) |
|
|
|
{ |
|
|
|
if(isNFC_quick_check(s)==IsNFC::Yes) |
|
|
|
return std::basic_string<CharT>{s}; |
|
|
@ -628,7 +628,7 @@ std::basic_string<CharT> UTF<CharT>::toNFC(basic_string_view<CharT> s) |
|
|
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
size_t UTF<char>::utf_length(u32string_view s) |
|
|
|
size_t UTF<char>::utf_length(std::u32string_view s) |
|
|
|
{ |
|
|
|
size_t len = 0; |
|
|
|
for(const char32_t c : s) |
|
|
@ -659,7 +659,7 @@ size_t UTF<char>::utf_length(u32string_view s) |
|
|
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
size_t UTF<char16_t>::utf_length(u32string_view s) |
|
|
|
size_t UTF<char16_t>::utf_length(std::u32string_view s) |
|
|
|
{ |
|
|
|
size_t len = 0; |
|
|
|
for(const char32_t c : s) |
|
|
@ -685,7 +685,7 @@ size_t UTF<char16_t>::utf_length(u32string_view s) |
|
|
|
|
|
|
|
// convenience function to avoid ::strdup(pEp::toNFC<char>(text).c_str());
|
|
|
|
// and unecessary temporary std::string etc.
|
|
|
|
char* strdup_NFC(string_view s) |
|
|
|
char* strdup_NFC(std::string_view s) |
|
|
|
{ |
|
|
|
if(UTF8::isNFC_quick_check(s)==IsNFC::Yes) |
|
|
|
return ::new_string(s.data(), s.size()); |
|
|
|