forked from VenoMKO/TMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
92 lines (81 loc) · 1.8 KB
/
Utils.cpp
File metadata and controls
92 lines (81 loc) · 1.8 KB
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
#include "Utils.h"
#include <algorithm>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
bool IncompletePathsEqual(const std::string& a, const std::string& b)
{
auto pos = a.find('.');
if (pos == std::string::npos)
{
return false;
}
const std::string_view objPathA(&a[pos + 1]);
pos = a.rfind('_', pos);
if (pos == std::string::npos)
{
return false;
}
const std::string_view compositeA(&a[0], pos);
pos = b.find('.');
if (pos == std::string::npos)
{
return false;
}
const std::string_view objPathB(&b[pos + 1]);
pos = b.rfind('_', pos);
if (pos == std::string::npos)
{
return false;
}
const std::string_view compositeB(&b[0], pos);
return compositeA == compositeB && objPathA == objPathB;
}
std::string W2A(const wchar_t* str, int len)
{
if (len == -1)
{
len = lstrlenW(str);
}
int size = WideCharToMultiByte(CP_UTF8, 0, str, len, NULL, 0, NULL, NULL);
std::string result(size, 0);
WideCharToMultiByte(CP_UTF8, 0, str, len, &result[0], size, NULL, NULL);
return result;
}
std::string W2A(const std::wstring& str)
{
return W2A(&str[0], (int)str.length());
}
std::wstring A2W(const char* str, int len)
{
if (len == -1)
{
len = (int)strlen(str);
}
int size = MultiByteToWideChar(CP_UTF8, 0, str, len, NULL, 0);
std::wstring result(size, 0);
MultiByteToWideChar(CP_UTF8, 0, str, len, &result[0], size);
return result;
}
std::wstring A2W(const std::string& str)
{
return A2W(&str[0], (int)str.length());
}
std::string ToUpper(const std::string& data)
{
std::string result = data;
std::for_each(result.begin(), result.end(), [](char& c) {
c = ::toupper(c);
});
return result;
}
bool IsAnsi(const std::string& str)
{
for (const unsigned char& ch : str)
{
if (ch > 127)
{
return false;
}
}
return true;
}