-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconversions.cpp
93 lines (66 loc) · 1.77 KB
/
conversions.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "conversions.h"
std::wstring StringToWString(const std::string& s)
{
std::wstring ws(s.begin(), s.end());
return ws;
}
std::string wide_string_to_string(std::wstring wide_string)
{
if (wide_string.empty())
{
return "";
}
const auto size_needed = WideCharToMultiByte(CP_UTF8, 0, &wide_string.at(0), (uint64_t)wide_string.size(), nullptr, 0, nullptr, nullptr);
if (size_needed <= 0)
{
throw std::runtime_error("WideCharToMultiByte() failed: " + std::to_string(size_needed));
}
std::string result(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, &wide_string.at(0), (uint64_t)wide_string.size(), &result.at(0), size_needed, nullptr, nullptr);
return result;
}
std::string to_lower_string(std::string s)
{
for (uint64_t i = 0; i < s.size(); i++)
{
s.at(i) = towlower(s.at(i));
}
return s;
}
std::string wide_string_to_string_REF(std::wstring& wide_string)
{
if (wide_string.empty())
{
return "";
}
const auto size_needed = WideCharToMultiByte(CP_UTF8, 0, &wide_string.at(0), (uint64_t)wide_string.size(), nullptr, 0, nullptr, nullptr);
if (size_needed <= 0)
{
throw std::runtime_error("WideCharToMultiByte() failed: " + std::to_string(size_needed));
}
std::string result(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, &wide_string.at(0), (uint64_t)wide_string.size(), &result.at(0), size_needed, nullptr, nullptr);
return result;
}
const wchar_t* GetWC(const char* c)
{
size_t cSize = strlen(c) + 1;
wchar_t* wc = new wchar_t[cSize];
wchar_t* wc2 = wc;
delete[] wc;
size_t outSize;
mbstowcs_s(&outSize, wc2, cSize, c, cSize - 1);
return wc2;
}
std::string convertToPath(std::string x)
{
std::string s = x;
for (uint64_t it = 0; it < s.size(); it++)
{
if (s.at(it) == '\\')
{
s.replace(it, 2, 2, '\\');
}
}
return s;
}