Bicameral Engine
GPU-resident engine for a magic-research open-world game
Loading...
Searching...
No Matches
unicode.cpp
Go to the documentation of this file.
1
// unicode.cpp — unicode.h の実装。Win32 の WideCharToMultiByte / MultiByteToWideChar を使う。
2
//
3
// core はプリコンパイルヘッダを持たない小さな静的ライブラリなので、windows.h はここで直接 include する。
4
#include "
core/unicode.h
"
5
6
#include <windows.h>
7
8
namespace
bicameral
{
9
10
std::string
ToUtf8
(std::wstring_view text) {
11
if
(text.empty())
12
return
{};
13
14
const
int
length =
static_cast<
int
>
(text.size());
15
const
int
sizeBytes = WideCharToMultiByte(CP_UTF8, 0, text.data(), length,
nullptr
, 0,
nullptr
,
nullptr
);
16
std::string result(
static_cast<
size_t
>
(sizeBytes),
'\0'
);
17
WideCharToMultiByte(CP_UTF8, 0, text.data(), length, result.data(), sizeBytes,
nullptr
,
nullptr
);
18
19
return
result;
20
}
21
22
std::wstring
ToWide
(std::string_view text) {
23
if
(text.empty())
24
return
{};
25
26
const
int
length =
static_cast<
int
>
(text.size());
27
const
int
count = MultiByteToWideChar(CP_UTF8, 0, text.data(), length,
nullptr
, 0);
28
std::wstring result(
static_cast<
size_t
>
(count), L
'\0'
);
29
MultiByteToWideChar(CP_UTF8, 0, text.data(), length, result.data(), count);
30
31
return
result;
32
}
33
34
}
// namespace bicameral
bicameral
Definition
aliases.h:12
bicameral::ToUtf8
std::string ToUtf8(std::wstring_view text)
Definition
unicode.cpp:10
bicameral::ToWide
std::wstring ToWide(std::string_view text)
Definition
unicode.cpp:22
unicode.h
engine
src
core
unicode.cpp
Generated by
1.15.0