21 template <
typename octet_iterator>
22 std::pair<octet_iterator, uint32_t>
find_invalid(octet_iterator start, octet_iterator end,
23 const std::pair<uint32_t, uint32_t>& invalid_range)
25 FC_ASSERT( invalid_range.first <= invalid_range.second );
26 octet_iterator result = start;
28 while( result != end ) {
29 octet_iterator itr = result;
33 if(
value >= invalid_range.first &&
value <= invalid_range.second )
41 const auto invalid_range = std::make_pair<uint32_t, uint32_t>(0x80, 0x9F);
42 auto [itr, v] =
find_invalid( str.begin(), str.end(), invalid_range );
43 return itr == str.end();
48 const auto invalid_range = std::make_pair<uint32_t, uint32_t>(0x80, 0x9F);
49 auto [itr, v] =
find_invalid( str.begin(), str.end(), invalid_range );
50 if( itr == str.end() )
return std::string( str );
53 auto escape = [&result](
uint32_t v) {
59 result =
string( str.begin(), itr );
61 while( itr != str.end() ) {
64 std::tie(itr, v) =
find_invalid( start, str.end(), invalid_range );
65 result +=
string( start, itr );
71 void decodeUtf8(
const std::string& input, std::wstring* storage)
75 utf8::utf8to32(input.begin(), input.end(), std::back_inserter(*storage));
78 void encodeUtf8(
const std::wstring& input, std::string* storage)
82 utf8::utf32to8(input.begin(), input.end(), std::back_inserter(*storage));
Defines exception's used by fc.
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
void decodeUtf8(const std::string &input, std::wstring *storage)
bool is_valid_utf8(const std::string_view &str)
void encodeUtf8(const std::wstring &input, std::string *storage)
bool is_utf8(const std::string &str)
constexpr char hex_digits[]
std::pair< octet_iterator, uint32_t > find_invalid(octet_iterator start, octet_iterator end, const std::pair< uint32_t, uint32_t > &invalid_range)
std::string prune_invalid_utf8(const std::string_view &str)
utf_error validate_next(octet_iterator &it, octet_iterator end, uint32_t &code_point)
octet_iterator utf32to8(u32bit_iterator start, u32bit_iterator end, octet_iterator result)
u32bit_iterator utf8to32(octet_iterator start, octet_iterator end, u32bit_iterator result)
bool is_valid(octet_iterator start, octet_iterator end)