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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
#include "common.h"
#include "str_utils.h"
int code_page = CP_ACP;
void set_codepage() {
if(ServiceExists(MS_LANGPACK_GETCODEPAGE))
code_page = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
}
bool a2w(const char *as, wchar_t *buff, int bufflen){
if(as) MultiByteToWideChar(code_page, 0, as, -1, buff, bufflen);
return true;
}
bool w2a(const wchar_t *ws, char *buff, int bufflen) {
if(ws) WideCharToMultiByte(code_page, 0, ws, -1, buff, bufflen, 0, 0);
return true;
}
bool u2w(const char *us, wchar_t *buff, int bufflen) {
if(us) MultiByteToWideChar(CP_UTF8, 0, us, -1, buff, bufflen);
return true;
}
bool w2u(const wchar_t *ws, char *buff, int bufflen) {
if(ws) WideCharToMultiByte(CP_UTF8, 0, ws, -1, buff, bufflen, 0, 0);
return true;
}
bool a2u(const char *as, char *buff, int bufflen) {
if(!as) return false;
wchar_t *ws = a2w(as);
if(ws) WideCharToMultiByte(CP_UTF8, 0, ws, -1, buff, bufflen, 0, 0);
free(ws);
return true;
}
bool u2a(const char *us, char *buff, int bufflen) {
if(!us) return false;
wchar_t *ws = u2w(us);
if(ws) WideCharToMultiByte(code_page, 0, ws, -1, buff, bufflen, 0, 0);
free(ws);
return true;
}
bool t2w(const TCHAR *ts, wchar_t *buff, int bufflen) {
#ifdef _UNICODE
wcsncpy(buff, ts, bufflen);
return true;
#else
return a2w(ts, buff, bufflen);
#endif
}
bool w2t(const wchar_t *ws, TCHAR *buff, int bufflen) {
#ifdef _UNICODE
wcsncpy(buff, ws, bufflen);
return true;
#else
return w2a(ws, buff, bufflen);
#endif
}
bool t2a(const TCHAR *ts, char *buff, int bufflen) {
#ifdef _UNICODE
return w2a(ts, buff, bufflen);
#else
strncpy(buff, ts, bufflen);
return true;
#endif
}
bool a2t(const char *as, TCHAR *buff, int bufflen) {
#ifdef _UNICODE
return a2w(as, buff, bufflen);
#else
strncpy(buff, as, bufflen);
return true;
#endif
}
bool t2u(const TCHAR *ts, char *buff, int bufflen) {
#ifdef _UNICODE
return w2u(ts, buff, bufflen);
#else
return a2u(ts, buff, bufflen);
#endif
}
bool u2t(const char *us, TCHAR *buff, int bufflen) {
#ifdef _UNICODE
return u2w(us, buff, bufflen);
#else
return u2a(us, buff, bufflen);
#endif
}
wchar_t *u2w(const char *us) {
if(us) {
int size = MultiByteToWideChar(CP_UTF8, 0, us, -1, 0, 0);
wchar_t *buff = (wchar_t *)malloc(size * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, us, -1, buff, size);
return buff;
} else
return 0;
}
char *w2u(const wchar_t *ws) {
if(ws) {
int size = WideCharToMultiByte(CP_UTF8, 0, ws, -1, 0, 0, 0, 0);
char *buff = (char *)malloc(size);
WideCharToMultiByte(CP_UTF8, 0, ws, -1, buff, size, 0, 0);
return buff;
} else
return 0;
}
wchar_t *a2w(const char *as) {
int size = MultiByteToWideChar(code_page, 0, as, -1, 0, 0);
wchar_t *buff = (wchar_t *)malloc(size * sizeof(wchar_t));
MultiByteToWideChar(code_page, 0, as, -1, buff, size);
return buff;
}
char *w2a(const wchar_t *ws) {
int size = WideCharToMultiByte(code_page, 0, ws, -1, 0, 0, 0, 0);
char *buff = (char *)malloc(size);
WideCharToMultiByte(code_page, 0, ws, -1, buff, size, 0, 0);
return buff;
}
char *u2a(const char *utfs) {
wchar_t *ws = u2w(utfs);
char *ret = w2a(ws);
free(ws);
return ret;
}
char *a2u(const char *as) {
wchar_t *ws = a2w(as);
char *ret = w2u(ws);
free(ws);
return ret;
}
TCHAR *w2t(const wchar_t *ws) {
#ifdef _UNICODE
return wcsdup(ws);
#else
return w2a(ws);
#endif
}
wchar_t *t2w(const TCHAR *ts) {
#ifdef _UNICODE
return _tcsdup(ts);
#else
return a2w(ts);
#endif
}
char *t2a(const TCHAR *ts) {
#ifdef _UNICODE
return w2a(ts);
#else
return _strdup(ts);
#endif
}
TCHAR *a2t(const char *as) {
#ifdef _UNICODE
return a2w(as);
#else
return _strdup(as);
#endif
}
TCHAR *u2t(const char *utfs) {
#ifdef _UNICODE
return u2w(utfs);
#else
wchar_t *ws = u2w(utfs);
char *ret = w2a(ws);
free(ws);
return ret;
#endif
}
char *t2u(const TCHAR *ts) {
#ifdef _UNICODE
return w2u(ts);
#else
wchar_t *ws = a2w(ts);
char *ret = w2u(ws);
free(ws);
return ret;
#endif
}
|