-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStrUtils.cc
39 lines (35 loc) · 983 Bytes
/
StrUtils.cc
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
34
35
36
37
38
39
#include <codecvt>
#include <locale>
#include <cassert>
#include <algorithm>
#include <cctype>
#include <regex>
#include "StrUtils.hpp"
void StrUtils::ToStdWString(std::string const &src, std::wstring &dst) {
dst = ToStdWString(src);
}
std::wstring StrUtils::ToStdWString(std::string const &src) {
#ifdef __APPLE__
using cvt_t = std::codecvt_utf8<wchar_t>;
#elif __GNUC__
#elif _MSC_VER
using cvt_t = std::codecvt_utf8_utf16<wchar_t>;
#else
#error "Your compiler is not supported"
#endif
return std::wstring_convert<cvt_t>().from_bytes(src);
}
void StrUtils::ToStdString(std::wstring const &src, std::string &dst) {
dst = ToStdString(src);
}
std::string StrUtils::ToStdString(std::wstring const &src) {
#ifdef __APPLE__
using cvt_t = std::codecvt_utf8<wchar_t>;
#elif __GNUC__
#elif _MSC_VER
using cvt_t = std::codecvt_utf8_utf16<wchar_t>;
#else
#error "Your compiler is not supported"
#endif
return std::wstring_convert<cvt_t>().to_bytes(src);
}