1 |
/* wptUTF8.cpp - UTF8 conversation |
/* wptUTF8.cpp - UTF8 conversation |
2 |
* Copyright (C) 2002, 2004, 2005, 2006 Timo Schulz |
* Copyright (C) 2002, 2004, 2005, 2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
15 |
*/ |
*/ |
|
|
|
16 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
17 |
#include <config.h> |
#include <config.h> |
18 |
#endif |
#endif |
38 |
if (n < 0) |
if (n < 0) |
39 |
return NULL; |
return NULL; |
40 |
|
|
41 |
result = (wchar_t*)malloc ((n+1) * sizeof *result); |
result = new wchar_t[n+1]; |
42 |
if (!result) |
if (!result) |
43 |
BUG (0); |
BUG (0); |
44 |
|
|
45 |
n = MultiByteToWideChar (GetACP (), 0, string, -1, result, n); |
n = MultiByteToWideChar (GetACP (), 0, string, -1, result, n); |
46 |
if (n < 0) { |
if (n < 0) { |
47 |
free (result); |
free_if_alloc (result); |
48 |
return NULL; |
return NULL; |
49 |
} |
} |
50 |
|
|
52 |
if (n < 0) |
if (n < 0) |
53 |
return NULL; |
return NULL; |
54 |
|
|
55 |
native = (char*)malloc (n+1); |
native = new char[n+1]; |
56 |
if (!native) |
if (!native) |
57 |
BUG (0); |
BUG (0); |
58 |
|
|
59 |
n = WideCharToMultiByte (CP_UTF8, 0, result, -1, native, n, NULL, NULL); |
n = WideCharToMultiByte (CP_UTF8, 0, result, -1, native, n, NULL, NULL); |
60 |
if (n < 0) { |
if (n < 0) { |
61 |
free (result); |
free_if_alloc (result); |
62 |
return NULL; |
return NULL; |
63 |
} |
} |
64 |
|
|
65 |
free (result); |
free_if_alloc (result); |
66 |
return native; |
return native; |
67 |
} |
} |
68 |
|
|
108 |
} |
} |
109 |
|
|
110 |
|
|
111 |
|
/* Return -1 if the string contains any 8-bit characters. */ |
112 |
int |
int |
113 |
is_8bit_string (const char * str) |
is_8bit_string (const char *str) |
114 |
{ |
{ |
115 |
size_t i; |
size_t i; |
116 |
|
|