46 G_EXCEPTION_CLASS( NarrowError ,
tx(
"string character-set narrowing error") )
47 G_EXCEPTION_CLASS( WidenError ,
tx(
"string character-set widening error") )
48 using unicode_type = std::uint_least32_t ;
49 static_assert(
sizeof(unicode_type) >=
sizeof(
wchar_t) ,
"" ) ;
50 static constexpr unicode_type unicode_error = ~(unicode_type)0 ;
51 using ParseFn = std::function<bool(unicode_type,std::size_t,std::size_t)> ;
53 static std::wstring
widen( std::string_view ) ;
57 static bool valid( std::string_view ) noexcept ;
60 static std::string
narrow(
const std::wstring & ) ;
64 static std::string
narrow(
const wchar_t * ) ;
67 static std::string
narrow(
const wchar_t * , std::size_t n ) ;
70 static bool invalid(
const std::wstring & ) ;
73 static bool invalid(
const std::string & ) ;
76 static std::size_t
u8out( unicode_type ,
char * & ) noexcept ;
82 static std::pair<unicode_type,std::size_t>
u8in(
const unsigned char * , std::size_t n ) noexcept ;
87 static void u8parse( std::string_view , ParseFn ) ;
93 static bool utf16(
bool ) ;
100 static bool m_utf16 ;
101 static std::wstring widenImp(
const char * , std::size_t ) ;
102 static std::size_t widenImp(
const char * , std::size_t ,
wchar_t * ,
bool * =
nullptr ) noexcept ;
103 static std::string narrowImp(
const wchar_t * , std::size_t ) ;
104 static std::size_t narrowImp(
const wchar_t * , std::size_t ,
char * ) noexcept ;
105 static unicode_type unicode_cast(
wchar_t c ) noexcept ;
106 static char char_cast(
unsigned int ) noexcept ;
A static class which provides string encoding conversion functions between UTF-8 and wchar_t.
static std::wstring widen(std::string_view)
Widens from UTF-8 to UTF-16/UCS-4 wstring.
static std::pair< unicode_type, std::size_t > u8in(const unsigned char *, std::size_t n) noexcept
Reads a Unicode character from a UTF-8 buffer together with the number of bytes consumed.
static bool invalid(const std::wstring &)
Returns true if the string contains L'\xFFFD'.
static void u8parse(std::string_view, ParseFn)
Calls a function for each Unicode value in the given UTF-8 string.
static std::string narrow(const std::wstring &)
Narrows from UTF-16/UCS-4 wstring to UTF-8.
static std::size_t u8out(unicode_type, char *&) noexcept
Puts a Unicode character value into a character buffer with UTF-8 encoding.
static bool valid(std::string_view) noexcept
Returns true if the string is valid UTF-8.
static bool utf16(bool)
Forces UTF-16 even if wchar_t is 4 bytes. Used in testing.
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().