Debian Codegraph @

src/index/vsutf16.h

raw symbols SCIP
1 /*
2 * Copyright (c) 2017 Fredrik Mellbin
3 *
4 * This file is part of VapourSynth.
5 *
6 * VapourSynth is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * VapourSynth is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with VapourSynth; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef VSUTF16_H
22 #define VSUTF16_H
23
24 #include <string>
25 #ifndef NOMINMAX
26 #define NOMINMAX
27 #endif
28 #include <windows.h>
29
30 static std::string utf16_to_utf8(const std::wstring &wstr) {
31 int required_size = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
32 std::string buffer;
33 buffer.resize(required_size - 1);
34 WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), static_cast<int>(wstr.size()), &buffer[0], required_size, nullptr, nullptr);
35 return buffer;
36 }
37
38 static std::wstring utf16_from_utf8(const std::string &str) {
39 int required_size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
40 std::wstring wbuffer;
41 wbuffer.resize(required_size - 1);
42 MultiByteToWideChar(CP_UTF8, 0, str.c_str(), static_cast<int>(str.size()), &wbuffer[0], required_size);
43 return wbuffer;
44 }
45
46 #endif