winapi_utf8
utf8.hpp
Go to the documentation of this file.
1 // Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
2 // This file is part of the "winapi-utf8" project.
3 // For details, see https://github.com/egor-tensin/winapi-utf8.
4 // Distributed under the MIT License.
5 
11 #pragma once
12 
13 #include <cstddef>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 namespace winapi {
19 
20 /* sizeof(wchar_t) == 4 on Linux, we don't care about that. */
21 static_assert(sizeof(wchar_t) == 2, "This is Windows, right?");
22 
24 std::wstring widen(const std::string&);
25 
31 std::wstring widen(const void* src, std::size_t nb);
32 
37 template <typename T, typename Alloc = std::allocator<T>>
38 std::wstring widen(const std::vector<T, Alloc>& src) {
39  return widen(src.data(), src.size() * sizeof(T));
40 }
41 
43 std::string narrow(const std::wstring&);
44 
46 std::string narrow(const std::u16string&);
47 
53 std::string narrow(const void* src, std::size_t nb);
54 
59 template <typename T, typename Alloc = std::allocator<T>>
60 std::string narrow(const std::vector<T, Alloc>& src) {
61  return narrow(src.data(), src.size() * sizeof(T));
62 }
63 
64 } // namespace winapi
std::wstring widen(const std::string &)
Definition: convert.cpp:99
std::string narrow(const std::wstring &)
Definition: convert.cpp:128