Corrade::Utility::Unicode namespace

Unicode utilities.

This library is built if CORRADE_WITH_UTILITY is enabled when building Corrade. To use this library with CMake, request the Utility component of the Corrade package and link to the Corrade::Utility target.

find_package(Corrade REQUIRED Utility)

# ...
target_link_libraries(your-app PRIVATE Corrade::Utility)

See also Downloading and building Corrade and Using Corrade with CMake for more information.

Functions

auto nextChar(Containers::ArrayView<const char> text, std::size_t cursor) -> std::pair<char32_t, std::size_t>
Next UTF-8 character.
auto nextChar(const std::string& text, const std::size_t cursor) -> std::pair<char32_t, std::size_t>
template<std::size_t size>
auto nextChar(const char(&text)[size], const std::size_t cursor) -> std::pair<char32_t, std::size_t>
auto prevChar(Containers::ArrayView<const char> text, std::size_t cursor) -> std::pair<char32_t, std::size_t>
Previous UTF-8 character.
auto prevChar(const std::string& text, const std::size_t cursor) -> std::pair<char32_t, std::size_t>
template<std::size_t size>
auto prevChar(const char(&text)[size], const std::size_t cursor) -> std::pair<char32_t, std::size_t>
auto utf32(const std::string& text) -> std::u32string
Convert UTF-8 to UTF-32.
auto utf8(char32_t character, Containers::StaticArrayView<4, char> result) -> std::size_t
Convert UTF-32 character to UTF-8.
auto widen(Containers::StringView text) -> Containers::Array<wchar_t>
Widen a UTF-8 string for use with Windows Unicode APIs.
auto widen(const char* text) -> Containers::Array<wchar_t>
auto widen(const std::string& text) -> std::wstring
auto narrow(Containers::ArrayView<const wchar_t> text) -> Containers::String
Narrow a string to UTF-8 for use with Windows Unicode APIs.
auto narrow(const wchar_t* text) -> Containers::String
auto narrow(const std::wstring& text) -> std::string

Function documentation

std::pair<char32_t, std::size_t> Corrade::Utility::Unicode::nextChar(Containers::ArrayView<const char> text, std::size_t cursor)

Next UTF-8 character.

Returns Unicode codepoint of character on the cursor and position of the following character. If an error occurs, returns position of next byte and 0xffffffffu as codepoint.

std::pair<char32_t, std::size_t> Corrade::Utility::Unicode::nextChar(const std::string& text, const std::size_t cursor)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<std::size_t size>
std::pair<char32_t, std::size_t> Corrade::Utility::Unicode::nextChar(const char(&text)[size], const std::size_t cursor)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

std::pair<char32_t, std::size_t> Corrade::Utility::Unicode::prevChar(Containers::ArrayView<const char> text, std::size_t cursor)

Previous UTF-8 character.

Returns Unicode codepoint of character before the cursor and its position. If an error occurs, returns position of previous byte and 0xffffffffu as codepoint.

std::pair<char32_t, std::size_t> Corrade::Utility::Unicode::prevChar(const std::string& text, const std::size_t cursor)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<std::size_t size>
std::pair<char32_t, std::size_t> Corrade::Utility::Unicode::prevChar(const char(&text)[size], const std::size_t cursor)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

std::size_t Corrade::Utility::Unicode::utf8(char32_t character, Containers::StaticArrayView<4, char> result)

Convert UTF-32 character to UTF-8.

Parameters
character in UTF-32 character to convert
result out Where to put the UTF-8 result

Returns length of the encoding (1, 2, 3 or 4). If character is outside of UTF-32 range, returns 0.

Containers::Array<wchar_t> Corrade::Utility::Unicode::widen(Containers::StringView text)

Widen a UTF-8 string for use with Windows Unicode APIs.

Converts a UTF-8 string to a wide-string (UTF-16) representation. The primary purpose of this API is easy interaction with Windows Unicode APIs, thus the function doesn't return char16_t but rather a wchar_t. If the text is not empty, the returned array contains a sentinel null terminator (i.e., not counted into its size).

Containers::Array<wchar_t> Corrade::Utility::Unicode::widen(const char* text)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Expects that text is null-terminated.

std::wstring Corrade::Utility::Unicode::widen(const std::string& text)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Containers::String Corrade::Utility::Unicode::narrow(Containers::ArrayView<const wchar_t> text)

Narrow a string to UTF-8 for use with Windows Unicode APIs.

Converts a wide-string (UTF-16) to a UTF-8 representation. The primary purpose is easy interaction with Windows Unicode APIs, thus the function doesn't take char16_t but rather a wchar_t.

Containers::String Corrade::Utility::Unicode::narrow(const wchar_t* text)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Expects that text is null-terminated.

std::string Corrade::Utility::Unicode::narrow(const std::wstring& text)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.