-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.hpp
More file actions
77 lines (64 loc) · 2.09 KB
/
Copy pathutils.hpp
File metadata and controls
77 lines (64 loc) · 2.09 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
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <string>
namespace utils {
namespace string {
inline std::string ConvertWideToANSI(const std::wstring& wstr)
{
int count = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), (int)wstr.length(), NULL, 0, NULL, NULL);
std::string str(count, 0);
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, &str[0], count, NULL, NULL);
return str;
}
inline std::wstring ConvertAnsiToWide(const std::string& str)
{
int count = MultiByteToWideChar(CP_ACP, 0, str.c_str(), (int)str.length(), NULL, 0);
std::wstring wstr(count, 0);
MultiByteToWideChar(CP_ACP, 0, str.c_str(), (int)str.length(), &wstr[0], count);
return wstr;
}
inline std::string ConvertWideToUtf8(const std::wstring& wstr)
{
int count = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), (int)wstr.length(), NULL, 0, NULL, NULL);
std::string str(count, 0);
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &str[0], count, NULL, NULL);
return str;
}
inline std::wstring ConvertUtf8ToWide(const std::string& str)
{
int count = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.length(), NULL, 0);
std::wstring wstr(count, 0);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.length(), &wstr[0], count);
return wstr;
}
inline void ltrim(std::string& str) {
str.erase(0, str.find_first_not_of(" \n\r\t"));
}
inline void rtrim(std::string& str) {
str.erase(str.find_last_not_of(" \n\r\t") + 1);
}
inline void trim(std::string& str) {
ltrim(str);
rtrim(str);
}
inline void ltrim(std::wstring& wstr) {
wstr.erase(0, wstr.find_first_not_of(L" \n\r\t"));
}
inline void rtrim(std::wstring& wstr) {
wstr.erase(wstr.find_last_not_of(L" \n\r\t") + 1);
}
inline void trim(std::wstring& wstr) {
ltrim(wstr);
rtrim(wstr);
}
} // string
namespace process {
inline void raise_process_priority(void) {
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
}
inline void lower_process_priority(void) {
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
}
} // process
} // utils