-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrCtrl.cpp
More file actions
76 lines (62 loc) · 1.89 KB
/
StrCtrl.cpp
File metadata and controls
76 lines (62 loc) · 1.89 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
#include "StrCtrl.h"
CStrCtrl StrCtrl;
CStrCtrl::CStrCtrl()
{
}
CStrCtrl::~CStrCtrl()
{
}
std::wstring CStrCtrl::AnsiStringToWideString(std::string str)
{
int size = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, nullptr, 0);
std::wstring result(size, 0);
MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, &result[0], size);
return result;
}
std::string CStrCtrl::WideStringToAnsiString(std::wstring str)
{
int size = WideCharToMultiByte(CP_ACP, 0, str.c_str(), -1, nullptr, 0, nullptr, nullptr);
std::string result(size, 0);
WideCharToMultiByte(CP_ACP, 0, str.c_str(), -1, &result[0], size, nullptr, nullptr);
return result;
}
std::wstring CStrCtrl::UTF8ToUTF16(const std::string& str)
{
int size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
std::wstring result(size, 0);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &result[0], size);
return result;
}
std::string CStrCtrl::UTF16ToUTF8(const std::wstring& str)
{
int size = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), -1, nullptr, 0, nullptr, nullptr);
std::string result(size, 0);
WideCharToMultiByte(CP_UTF8, 0, str.c_str(), -1, &result[0], size, nullptr, nullptr);
return result;
}
int CStrCtrl::GetStringParsing(WCHAR* pString, WCHAR* pDelimiter, std::vector<std::wstring>* pVecString)
{
if (pString == NULL || pDelimiter == NULL || pVecString == NULL)
{
return ERROR_INVALID_PARAMETER;
}
WCHAR* token;
WCHAR* next_token = NULL;
token = wcstok_s(pString, pDelimiter, &next_token);
while (token != NULL)
{
pVecString->push_back(token);
token = wcstok_s(NULL, pDelimiter, &next_token);
}
return ERROR_SUCCESS;
}
std::string CStrCtrl::GetRandomString(int length)
{
std::string randomString = "";
srand(time(NULL)); // 랜덤 시드 초기화
for (int i = 0; i < length; i++) {
char randomChar = 'A' + rand() % 26; // 알파벳 대문자 랜덤 생성
randomString += randomChar;
}
return randomString;
}