Conversion between UTF-8 and std::wstring.
More...
#include <cstddef>
#include <cstdint>
#include <stdexcept>
#include <string>
#include <string_view>
Go to the source code of this file.
Conversion between UTF-8 and std::wstring.
- Author
- Diego Dasso Migotto (diegomigotto at hotmail dot com)
The core works in UTF-8 (std::string). Libraries with a std::wstring API convert at the boundary. wchar_t is UTF-16 on Windows and UTF-32 elsewhere; both are handled, so the UTF-8 is the same on every platform.
Definition in file utf8.hpp.
◆ from_utf8()
| std::wstring dasmig::core::from_utf8 |
( |
std::string_view |
text | ) |
|
|
inline |
Convert UTF-8 to a wide string.
- Parameters
-
- Returns
- UTF-16 (Windows) or UTF-32 text.
- Exceptions
-
| std::invalid_argument | If text is not well-formed UTF-8. |
Definition at line 131 of file utf8.hpp.
◆ is_utf8()
| constexpr bool dasmig::core::is_utf8 |
( |
std::string_view |
text | ) |
|
|
constexprnoexcept |
Whether a byte string is well-formed UTF-8.
- Parameters
-
- Returns
- True when valid.
Definition at line 67 of file utf8.hpp.
◆ to_utf8()
| std::string dasmig::core::to_utf8 |
( |
std::wstring_view |
text | ) |
|
|
inline |
Convert a wide string to UTF-8.
- Parameters
-
| text | UTF-16 (Windows) or UTF-32 text. |
- Returns
- The UTF-8 encoding.
- Exceptions
-
| std::invalid_argument | On an unpaired surrogate or a value above U+10FFFF. |
Definition at line 77 of file utf8.hpp.
◆ utf8_invalid_offset()
| constexpr std::size_t dasmig::core::utf8_invalid_offset |
( |
std::string_view |
text | ) |
|
|
constexprnoexcept |
Whether a byte string is well-formed UTF-8.
Rejects overlong forms, surrogates (U+D800 to U+DFFF) and code points above U+10FFFF.
- Parameters
-
- Returns
- The offset of the first invalid byte, or
std::string_view::npos when the text is valid.
Definition at line 32 of file utf8.hpp.