@@ -30,22 +30,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
30
30
#include < map>
31
31
32
32
#ifndef _WIN32
33
- #include < iconv.h>
33
+ #include < iconv.h>
34
34
#else
35
- #define _WIN32_WINNT 0x0501
36
- #include < windows.h>
35
+ #define _WIN32_WINNT 0x0501
36
+ #include < windows.h>
37
+ #endif
38
+
39
+ #if defined(_ICONV_H_) && (defined(__FreeBSD__) || defined(__NetBSD__) || \
40
+ defined (__OpenBSD__) || defined(__DragonFly__))
41
+ #define BSD_ICONV_USED
37
42
#endif
38
43
39
44
static bool parseHexColorString (const std::string &value, video::SColor &color);
40
45
static bool parseNamedColorString (const std::string &value, video::SColor &color);
41
46
42
47
#ifndef _WIN32
48
+
43
49
bool convert (const char *to, const char *from, char *outbuf,
44
50
size_t outbuf_size, char *inbuf, size_t inbuf_size)
45
51
{
46
52
iconv_t cd = iconv_open (to, from);
47
53
48
- #if defined(__FreeBSD__) || defined(__FreeBSD)
54
+ #ifdef BSD_ICONV_USED
49
55
const char *inbuf_ptr = inbuf;
50
56
#else
51
57
char *inbuf_ptr = inbuf;
@@ -88,7 +94,7 @@ std::wstring utf8_to_wide(const std::string &input)
88
94
delete[] outbuf;
89
95
return L" <invalid UTF-8 string>" ;
90
96
}
91
- std::wstring out ((wchar_t *)outbuf);
97
+ std::wstring out ((wchar_t *)outbuf);
92
98
93
99
delete[] inbuf;
94
100
delete[] outbuf;
@@ -97,12 +103,15 @@ std::wstring utf8_to_wide(const std::string &input)
97
103
}
98
104
99
105
#ifdef __ANDROID__
106
+
100
107
// TODO: this is an ugly fix for wide_to_utf8 somehow not working on android
101
108
std::string wide_to_utf8 (const std::wstring &input)
102
109
{
103
110
return wide_to_narrow (input);
104
111
}
105
- #else
112
+
113
+ #else // __ANDROID__
114
+
106
115
std::string wide_to_utf8 (const std::wstring &input)
107
116
{
108
117
size_t inbuf_size = (input.length () + 1 ) * sizeof (wchar_t );
@@ -128,14 +137,18 @@ std::string wide_to_utf8(const std::wstring &input)
128
137
129
138
return out;
130
139
}
131
- #endif
132
- #else
140
+
141
+ #endif // __ANDROID__
142
+
143
+ #else // _WIN32
144
+
133
145
std::wstring utf8_to_wide (const std::string &input)
134
146
{
135
147
size_t outbuf_size = input.size () + 1 ;
136
148
wchar_t *outbuf = new wchar_t [outbuf_size];
137
149
memset (outbuf, 0 , outbuf_size * sizeof (wchar_t ));
138
- MultiByteToWideChar (CP_UTF8, 0 , input.c_str (), input.size (), outbuf, outbuf_size);
150
+ MultiByteToWideChar (CP_UTF8, 0 , input.c_str (), input.size (),
151
+ outbuf, outbuf_size);
139
152
std::wstring out (outbuf);
140
153
delete[] outbuf;
141
154
return out;
@@ -146,18 +159,20 @@ std::string wide_to_utf8(const std::wstring &input)
146
159
size_t outbuf_size = (input.size () + 1 ) * 6 ;
147
160
char *outbuf = new char [outbuf_size];
148
161
memset (outbuf, 0 , outbuf_size);
149
- WideCharToMultiByte (CP_UTF8, 0 , input.c_str (), input.size (), outbuf, outbuf_size, NULL , NULL );
162
+ WideCharToMultiByte (CP_UTF8, 0 , input.c_str (), input.size (),
163
+ outbuf, outbuf_size, NULL , NULL );
150
164
std::string out (outbuf);
151
165
delete[] outbuf;
152
166
return out;
153
167
}
154
- #endif
168
+
169
+ #endif // _WIN32
155
170
156
171
// You must free the returned string!
157
172
// The returned string is allocated using new
158
173
wchar_t *narrow_to_wide_c (const char *str)
159
174
{
160
- wchar_t * nstr = 0 ;
175
+ wchar_t * nstr = NULL ;
161
176
#if defined(_WIN32)
162
177
int nResult = MultiByteToWideChar (CP_UTF8, 0 , (LPCSTR) str, -1 , 0 , 0 );
163
178
if (nResult == 0 ) {
@@ -168,7 +183,7 @@ wchar_t *narrow_to_wide_c(const char *str)
168
183
}
169
184
#else
170
185
size_t len = strlen (str);
171
- nstr = new wchar_t [len+ 1 ];
186
+ nstr = new wchar_t [len + 1 ];
172
187
173
188
std::wstring intermediate = narrow_to_wide (str);
174
189
memset (nstr, 0 , (len + 1 ) * sizeof (wchar_t ));
0 commit comments