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

Input parameter must be a valid UTF-32 code point ( <0x10FFFF)

◆ 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

Each character in the input string should be a valid UTF-32 code point ( <0x10FFFF)

◆ 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

Each character in the input string should be a valid UTF-32 code point ( <0x10FFFF)

◆ narrow() [4/5]

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

Conversion from wide character to UTF-8.

Parameters
sinput 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

The function throws an exception if it encounters an invalid UTF-8 encoding.

◆ 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

The function throws an exception if it encounters an invalid UTF-8 encoding.

◆ 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