winapi_utf8
Loading...
Searching...
No Matches
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
18namespace winapi {
19
20/* sizeof(wchar_t) == 4 on Linux, we don't care about that. */
21static_assert(sizeof(wchar_t) == 2, "This is Windows, right?");
22
24std::wstring widen(const std::string&);
25#ifdef __cpp_lib_char8_t
26std::wstring widen(const std::u8string&);
27#endif
28
34std::wstring widen(const void* src, std::size_t nb);
35
40template <typename T, typename Alloc = std::allocator<T>>
41std::wstring widen(const std::vector<T, Alloc>& src) {
42 return widen(src.data(), src.size() * sizeof(T));
43}
44
46std::string narrow(const std::wstring&);
47
49std::string narrow(const std::u16string&);
50
56std::string narrow(const void* src, std::size_t nb);
57
62template <typename T, typename Alloc = std::allocator<T>>
63std::string narrow(const std::vector<T, Alloc>& src) {
64 return narrow(src.data(), src.size() * sizeof(T));
65}
66
67} // namespace winapi
std::wstring widen(const std::string &)
Definition convert.cpp:99
std::string narrow(const std::wstring &)
Definition convert.cpp:134