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. |
43 |
if (n < 0) |
if (n < 0) |
44 |
return NULL; |
return NULL; |
45 |
|
|
46 |
result = (wchar_t*)malloc ((n+1) * sizeof *result); |
result = new wchar_t[n+1]; |
47 |
if (!result) |
if (!result) |
48 |
BUG (0); |
BUG (0); |
49 |
|
|
50 |
n = MultiByteToWideChar (GetACP (), 0, string, -1, result, n); |
n = MultiByteToWideChar (GetACP (), 0, string, -1, result, n); |
51 |
if (n < 0) { |
if (n < 0) { |
52 |
free (result); |
free_if_alloc (result); |
53 |
return NULL; |
return NULL; |
54 |
} |
} |
55 |
|
|
57 |
if (n < 0) |
if (n < 0) |
58 |
return NULL; |
return NULL; |
59 |
|
|
60 |
native = (char*)malloc (n+1); |
native = new char[n+1]; |
61 |
if (!native) |
if (!native) |
62 |
BUG (0); |
BUG (0); |
63 |
|
|
64 |
n = WideCharToMultiByte (CP_UTF8, 0, result, -1, native, n, NULL, NULL); |
n = WideCharToMultiByte (CP_UTF8, 0, result, -1, native, n, NULL, NULL); |
65 |
if (n < 0) { |
if (n < 0) { |
66 |
free (result); |
free_if_alloc (result); |
67 |
return NULL; |
return NULL; |
68 |
} |
} |
69 |
|
|
70 |
free (result); |
free_if_alloc (result); |
71 |
return native; |
return native; |
72 |
} |
} |
73 |
|
|
113 |
} |
} |
114 |
|
|
115 |
|
|
116 |
|
/* Return -1 if the string contains any 8-bit characters. */ |
117 |
int |
int |
118 |
is_8bit_string (const char * str) |
is_8bit_string (const char *str) |
119 |
{ |
{ |
120 |
size_t i; |
size_t i; |
121 |
|
|