|
|
|
@ -89,7 +89,7 @@ namespace
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string escape(sv s)
|
|
|
|
|
std::string escape(pEp::string_view s)
|
|
|
|
|
{
|
|
|
|
|
std::string ret; ret.reserve(s.size() + 16 );
|
|
|
|
|
for(char c : s)
|
|
|
|
@ -176,6 +176,8 @@ namespace
|
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace pEp {
|
|
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& o, IsNFC is_nfc)
|
|
|
|
|
{
|
|
|
|
|
switch(is_nfc)
|
|
|
|
@ -309,7 +311,7 @@ std::string toUtf8(const std::u32string& u32)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
illegal_utf8::illegal_utf8( sv s, unsigned position, const std::string& reason)
|
|
|
|
|
illegal_utf8::illegal_utf8( 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 )
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
@ -319,7 +321,7 @@ illegal_utf8::illegal_utf8( const std::string& msg )
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void assert_utf8(sv s)
|
|
|
|
|
void assert_utf8(string_view s)
|
|
|
|
|
{
|
|
|
|
|
const char* begin = s.data();
|
|
|
|
|
const char* const end = s.data() + s.size();
|
|
|
|
@ -339,7 +341,7 @@ void assert_utf8(sv s)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// creates a NFD string from s
|
|
|
|
|
std::u32string fromUtf8_decompose(sv s)
|
|
|
|
|
std::u32string fromUtf8_decompose(string_view s)
|
|
|
|
|
{
|
|
|
|
|
std::u32string u32s;
|
|
|
|
|
u32s.reserve( static_cast<std::size_t>(s.size()*1.25) );
|
|
|
|
@ -423,7 +425,7 @@ std::u32string createNFC(std::u32string nfd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IsNFC isNFC_quick_check(sv s)
|
|
|
|
|
IsNFC isNFC_quick_check(string_view s)
|
|
|
|
|
{
|
|
|
|
|
const char* begin = s.data();
|
|
|
|
|
const char* const end = s.data() + s.size();
|
|
|
|
@ -452,7 +454,7 @@ IsNFC isNFC_quick_check(sv s)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isNFC(sv s)
|
|
|
|
|
bool isNFC(string_view s)
|
|
|
|
|
{
|
|
|
|
|
switch( isNFC_quick_check(s) )
|
|
|
|
|
{
|
|
|
|
@ -480,7 +482,7 @@ try{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
{
|
|
|
|
|
if(isNFC_quick_check(s)==IsNFC::Yes)
|
|
|
|
|
return std::string{s};
|
|
|
|
@ -503,3 +505,5 @@ std::map< std::pair<unsigned, unsigned>, unsigned> generate_nfc_compose()
|
|
|
|
|
|
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // end of namespace pEp
|
|
|
|
|