-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnut_platform_strings.hpp
More file actions
33 lines (26 loc) · 894 Bytes
/
nut_platform_strings.hpp
File metadata and controls
33 lines (26 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once
#include "nut_types.hpp"
namespace nut {
namespace platform {
//! UTF-8 to wide string conversion.
inline wstring utf8ToWide( string_view in ) noexcept
{
int length = MultiByteToWideChar( CP_UTF8, 0, in.data(), -1, nullptr, 0 );
if ( length == 0 )
return {};
vector<wchar_t> conversion( length );
MultiByteToWideChar( CP_UTF8, 0, in.data(), -1, &conversion[0], length );
return &conversion[0];
}
//! Wide string to UTF-8 conversion.
inline string wideToUtf8( wstring_view in ) noexcept
{
int length = WideCharToMultiByte( CP_UTF8, 0, in.data(), -1, nullptr, 0, nullptr, FALSE );
if ( length == 0 )
return {};
vector<char> conversion( length );
WideCharToMultiByte( CP_UTF8, 0, in.data(), -1, &conversion[0], length, nullptr, FALSE );
return &conversion[0];
}
}
}