diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2020-10-18 02:26:27 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2020-10-18 02:26:27 +0300 |
commit | 017580252940649865e66002c7bc292687c56a54 (patch) | |
tree | 6823c2396c52e3e34f357324b02bfdbdd5ab2ce6 | |
parent | cmake: files are per-directory, not per-extension (diff) | |
download | winapi-utf8-017580252940649865e66002c7bc292687c56a54.tar.gz winapi-utf8-017580252940649865e66002c7bc292687c56a54.zip |
more convenience overloads
Diffstat (limited to '')
-rw-r--r-- | include/winapi/utf8.hpp | 1 | ||||
-rw-r--r-- | src/convert.cpp | 8 |
2 files changed, 7 insertions, 2 deletions
diff --git a/include/winapi/utf8.hpp b/include/winapi/utf8.hpp index 57b3c53..c6fc77b 100644 --- a/include/winapi/utf8.hpp +++ b/include/winapi/utf8.hpp @@ -16,6 +16,7 @@ std::wstring widen(const std::vector<unsigned char>&); std::wstring widen(const void*, std::size_t nb); std::string narrow(const std::wstring&); +std::string narrow(const wchar_t*, std::size_t nch); std::string narrow(const std::vector<unsigned char>&); std::string narrow(const void*, std::size_t nb); diff --git a/src/convert.cpp b/src/convert.cpp index 39485ee..f3f0730 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -116,8 +116,12 @@ std::wstring widen(const void* src, std::size_t in_nb) { } std::string narrow(const std::wstring& src) { - static_assert(sizeof(std::wstring::value_type) == sizeof(WCHAR), "wchar_t != WCHAR"); - return narrow(src.c_str(), src.size() * sizeof(std::wstring::value_type)); + return narrow(src.c_str(), src.size()); +} + +std::string narrow(const wchar_t* src, std::size_t nch) { + static_assert(sizeof(wchar_t) == sizeof(WCHAR), "wchar_t != WCHAR"); + return narrow(src, nch * sizeof(wchar_t)); } std::string narrow(const std::vector<unsigned char>& src) { |