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
|
#ifndef NULLSOFT_AUTOCHARH
#define NULLSOFT_AUTOCHARH
class AutoChar
{
public:
AutoChar(const wchar_t *convert) : allocated(false), narrow(0)
{
// review maybe CP_UTF8?
int size = WideCharToMultiByte(CP_ACP, 0, convert, -1, 0, 0, NULL, NULL);
if (!size)
return;
narrow = new char[size];
allocated=true;
if (!WideCharToMultiByte(CP_ACP, 0, convert, -1, narrow, size, NULL, NULL))
{
delete [] narrow;
narrow=0;
allocated=false;
}
}
~AutoChar()
{
if (allocated)
{
delete [] narrow;
narrow=0;
allocated=false;
}
}
operator char *()
{
return narrow;
}
private:
bool allocated;
char *narrow;
};
#endif
|