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
31std::wstring widen(const void* src, std::size_t nb);
32
37template <typename T, typename Alloc = std::allocator<T>>
38std::wstring widen(const std::vector<T, Alloc>& src) {
39 return widen(src.data(), src.size() * sizeof(T));
40}
41
43std::string narrow(const std::wstring&);
44
46std::string narrow(const std::u16string&);
47
53std::string narrow(const void* src, std::size_t nb);
54
59template <typename T, typename Alloc = std::allocator<T>>
60std::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