Corrade::Utility::Unicode namespace

Unicode utilities.

Contents

This library is built if WITH_UTILITY is enabled when building Corrade. To use this library with CMake, you need to 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 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 prevChar(Containers::ArrayView<const char> text, std::size_t cursor) -> std::pair<char32_t, std::size_t>
Previous UTF-8 character.
auto utf8(char32_t character, Containers::StaticArrayView<4, char> result) -> std::size_t
Convert UTF-32 character to UTF-8.
auto utf32(const std::string& text) -> std::u32string
Convert UTF-8 to UTF-32.
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(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 widen(const std::string& text) -> std::wstring
Widen UTF-8 string for use with Windows Unicode APIs.
auto widen(Containers::ArrayView<const char> text) -> std::wstring
auto widen(const char* text) -> std::wstring
auto narrow(const std::wstring& text) -> std::string
Narrow string to UTF-8 for use with Windows Unicode APIs.
auto narrow(Containers::ArrayView<const wchar_t> text) -> std::string
auto narrow(const wchar_t* 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::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::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.

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(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::wstring Corrade::Utility::Unicode::widen(const std::string& text)

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

Converts UTF-8 string to wide-string (UTF-16) representation. Primary purpose is easy interaction with Windows Unicode APIs, thus the function doesn't return std::u16string but a std::wstring.

std::wstring Corrade::Utility::Unicode::widen(Containers::ArrayView<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.

std::wstring 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::string Corrade::Utility::Unicode::narrow(const std::wstring& text)

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

Converts wide-string (UTF-16) to UTF-8 representation. Primary purpose is easy interaction with Windows Unicode APIs, thus the function doesn't accept std::u16string but a std::wstring.

std::string Corrade::Utility::Unicode::narrow(Containers::ArrayView<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.

std::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.