diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2021-09-27 16:44:30 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2021-09-27 16:44:49 +0300 |
commit | 68c45ee5bb9c998923f7a8ce7857128803dbe93a (patch) | |
tree | 73f3cca98f183577cfaa3139be2cb876dd4a480a | |
parent | docs: refine Doxygen comments (diff) | |
download | winapi-utf8-68c45ee5bb9c998923f7a8ce7857128803dbe93a.tar.gz winapi-utf8-68c45ee5bb9c998923f7a8ce7857128803dbe93a.zip |
add a std::u16string overload
Diffstat (limited to '')
-rw-r--r-- | include/winapi/utf8.hpp | 6 | ||||
-rw-r--r-- | src/convert.cpp | 4 |
2 files changed, 10 insertions, 0 deletions
diff --git a/include/winapi/utf8.hpp b/include/winapi/utf8.hpp index 9259df6..c6bb03a 100644 --- a/include/winapi/utf8.hpp +++ b/include/winapi/utf8.hpp @@ -17,6 +17,9 @@ namespace winapi { +/* sizeof(wchar_t) == 4 on Linux, we don't care about that. */ +static_assert(sizeof(wchar_t) == 2, "This is Windows, right?"); + /** Convert UTF-8 string to UTF-16. */ std::wstring widen(const std::string&); @@ -39,6 +42,9 @@ std::wstring widen(const std::vector<T, Alloc>& src) { /** Convert UTF-16 string to UTF-8. */ std::string narrow(const std::wstring&); +/** Convert UTF-16 string to UTF-8. */ +std::string narrow(const std::u16string&); + /** * Convert UTF-16 string to UTF-8. * \param src Memory address of a UTF-16 string. diff --git a/src/convert.cpp b/src/convert.cpp index bacea60..4ccc3a0 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -130,6 +130,10 @@ std::string narrow(const std::wstring& src) { return narrow(src.c_str(), src.size() * sizeof(std::wstring::value_type)); } +std::string narrow(const std::u16string& src) { + return narrow(src.c_str(), src.size() * sizeof(std::u16string::value_type)); +} + std::string narrow(const void* src, std::size_t in_nb) { const DWORD flags = WC_ERR_INVALID_CHARS; |