UTF8 - Simple Library for Internationalization
Loading...
Searching...
No Matches
Narrowing/Widening Functions

Basic conversion functions between UTF-8, UTF-16 and UTF-32. More...

Functions

std::string utf8::narrow (const wchar_t *s, size_t nch)
 Conversion from wide character to UTF-8.
 
std::string utf8::narrow (const std::wstring &ws)
 Conversion from wide character to UTF-8.
 
std::string utf8::narrow (const char32_t *s, size_t nch)
 Conversion from UTF32 to UTF8.
 
std::string utf8::narrow (const std::u32string &s)
 Conversion from UTF32 to UTF8.
 
std::string utf8::narrow (char32_t r)
 Conversion from UTF32 to UTF8.
 
std::wstring utf8::widen (const char *s, size_t nch)
 Conversion from UTF-8 to wide character.
 
std::wstring utf8::widen (const std::string &s)
 Conversion from UTF-8 to wide character.
 
std::u32string utf8::runes (const char *s, size_t nch)
 Conversion from UTF-8 to UTF-32.
 
std::u32string utf8::runes (const std::string &s)
 Converts a string of characters from UTF-8 to UTF-32.
 
char32_t utf8::rune (const char *p)
 Conversion from UTF-8 to UTF-32.
 
char32_t utf8::rune (const std::string::const_iterator &p)
 Conversion from UTF-8 to UTF-32.
 

Detailed Description

Basic conversion functions between UTF-8, UTF-16 and UTF-32.

Function Documentation

◆ narrow() [1/5]

std::string utf8::narrow ( char32_t  r)

Conversion from UTF32 to UTF8.

Parameters
rUTF-32 encoded character
Returns
UTF-8 encoded string

If the input string contains invalid UTF-32 characters, they are replaced with utf8::REPLACEMENT_CHARACTER (0xFFFD) or the function throws an exception, depending on error handling mode.

◆ narrow() [2/5]

std::string utf8::narrow ( const char32_t *  s,
size_t  nch 
)

Conversion from UTF32 to UTF8.

Parameters
sUTF-32 encoded string
nchnumber of character to convert or 0 if string is null-terminated
Returns
UTF-8 encoded string

If the input string contains invalid UTF-32 characters, they are replaced with utf8::REPLACEMENT_CHARACTER (0xFFFD) or the function throws an exception, depending on error handling mode.

◆ narrow() [3/5]

std::string utf8::narrow ( const std::u32string &  s)

Conversion from UTF32 to UTF8.

Parameters
sUTF-32 encoded string
Returns
UTF-8 encoded string

If the input string contains invalid UTF-32 characters, they are replaced with utf8::REPLACEMENT_CHARACTER (0xFFFD) or the function throws an exception, depending on error handling mode.

◆ narrow() [4/5]

std::string utf8::narrow ( const std::wstring &  ws)

Conversion from wide character to UTF-8.

Parameters
wsinput string
Returns
UTF-8 character string

◆ narrow() [5/5]

std::string utf8::narrow ( const wchar_t *  s,
size_t  nch 
)

Conversion from wide character to UTF-8.

Parameters
sinput string
nchnumber of character to convert or 0 if string is null-terminated
Returns
UTF-8 character string

◆ rune() [1/2]

char32_t utf8::rune ( const char *  p)
inline

Conversion from UTF-8 to UTF-32.

Parameters
ppointer to character
Returns
UTF-32 encoded character or utf8::REPLACEMENT_CHARACTER (0xfffd) if it is an invalid UTF-8 encoding

◆ rune() [2/2]

char32_t utf8::rune ( const std::string::const_iterator &  p)
inline

Conversion from UTF-8 to UTF-32.

Parameters
ppointer to character
Returns
UTF-32 encoded character or utf8::REPLACEMENT_CHARACTER (0xfffd) if it is an invalid UTF-8 encoding

◆ runes() [1/2]

std::u32string utf8::runes ( const char *  s,
size_t  nch 
)

Conversion from UTF-8 to UTF-32.

Parameters
sUTF-8 encoded string
nchnumber of characters to convert or 0 if string is null-terminated
Returns
UTF-32 encoded string

If the input string contains invalid UTF-8 characters, they are replaced with utf8::REPLACEMENT_CHARACTER (0xFFFD) or the function throws an exception, depending on error handling mode.

◆ runes() [2/2]

std::u32string utf8::runes ( const std::string &  s)

Converts a string of characters from UTF-8 to UTF-32.

Parameters
sUTF-8 encoded string
Returns
UTF-32 encoded string

If the input string contains invalid UTF-8 characters, they are replaced with utf8::REPLACEMENT_CHARACTER (0xFFFD) or the function throws an exception, depending on error handling mode.

◆ widen() [1/2]

std::wstring utf8::widen ( const char *  s,
size_t  nch 
)

Conversion from UTF-8 to wide character.

Parameters
sinput string
nchnumber of characters to convert or 0 if string is null-terminated
Returns
wide character string

◆ widen() [2/2]

std::wstring utf8::widen ( const std::string &  s)

Conversion from UTF-8 to wide character.

Parameters
sinput string
Returns
wide character string