-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConversionWchar.cpp
More file actions
executable file
·140 lines (101 loc) · 3.18 KB
/
ConversionWchar.cpp
File metadata and controls
executable file
·140 lines (101 loc) · 3.18 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
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
#include "stdafx.h"
#include "ConversionWchar.h"
#include <wchar.h>
#if defined(__APPLE__) && !defined(BUILD_DYNAMIC_LIBRARY)
namespace COM_1C_SHARE_COMPONENT
{
#endif //__APPLE__ && !BUILD_DYNAMIC_LIBRARY
//---------------------------------------------------------------------------//
uint32_t convToShortWchar(WCHAR_T** Dest, const wchar_t* Source, uint32_t len)
{
if (!len)
len = static_cast<uint32_t>(::wcslen(Source) + 1);
if (!*Dest)
*Dest = new WCHAR_T[len];
WCHAR_T* tmpShort = *Dest;
wchar_t* tmpWChar = (wchar_t*)Source;
uint32_t res = 0;
for (; len; --len, ++res, ++tmpWChar, ++tmpShort)
{
*tmpShort = (WCHAR_T)*tmpWChar;
}
return res;
}
//---------------------------------------------------------------------------//
uint32_t convFromShortWchar(wchar_t** Dest, const WCHAR_T* Source, uint32_t len)
{
if (!len)
len = getLenShortWcharStr(Source) + 1;
if (!*Dest)
*Dest = new wchar_t[len];
wchar_t* tmpWChar = *Dest;
WCHAR_T* tmpShort = (WCHAR_T*)Source;
uint32_t res = 0;
for (; len; --len, ++res, ++tmpWChar, ++tmpShort)
{
*tmpWChar = (wchar_t)*tmpShort;
}
return res;
}
//---------------------------------------------------------------------------//
uint32_t getLenShortWcharStr(const WCHAR_T* Source)
{
uint32_t res = 0;
WCHAR_T *tmpShort = (WCHAR_T*)Source;
while (*tmpShort++)
++res;
return res;
}
//---------------------------------------------------------------------------//
//---------------------------------------------------------------------------//
WcharWrapper::WcharWrapper(const wchar_t* str) :
#if defined(__APPLE__) || defined(__ANDROID__)
m_str_WCHAR(NULL),
#endif //__APPLE__ || __ANDROID__
m_str_wchar(NULL)
{
if (str)
{
int len = static_cast<int>(wcslen(str));
m_str_wchar = new wchar_t[len + 1];
memset(m_str_wchar, 0, sizeof(wchar_t)* (len + 1));
memcpy(m_str_wchar, str, sizeof(wchar_t)* len);
#if defined(__APPLE__) || defined(__ANDROID__)
convToShortWchar(&m_str_WCHAR, m_str_wchar, len + 1);
#endif //__APPLE__ || __ANDROID__
}
}
//---------------------------------------------------------------------------//
#if defined(__APPLE__) || defined(__ANDROID__)
WcharWrapper::WcharWrapper(const WCHAR_T* str) : m_str_WCHAR(NULL),
m_str_wchar(NULL)
{
if (str)
{
int len = getLenShortWcharStr(str);
m_str_WCHAR = new WCHAR_T[len + 1];
memset(m_str_WCHAR, 0, sizeof(WCHAR_T) * (len + 1));
memcpy(m_str_WCHAR, str, sizeof(WCHAR_T) * len);
convFromShortWchar(&m_str_wchar, m_str_WCHAR);
}
}
#endif //__APPLE__ || __ANDROID__
//---------------------------------------------------------------------------//
WcharWrapper::~WcharWrapper()
{
#if defined(__APPLE__) || defined(__ANDROID__)
if (m_str_WCHAR)
{
delete[] m_str_WCHAR;
m_str_WCHAR = NULL;
}
#endif //__APPLE__ || __ANDROID__
if (m_str_wchar)
{
delete[] m_str_wchar;
m_str_wchar = NULL;
}
}
#if defined(__APPLE__) && !defined(BUILD_DYNAMIC_LIBRARY)
}
#endif //__APPLE__ && !BUILD_DYNAMIC_LIBRARY