| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <pj/unicode.h> |
| 20 |
#include <pj/assert.h> |
| 21 |
#include <pj/string.h> |
| 22 |
#include <windows.h> |
| 23 |
|
| 24 |
|
| 25 |
PJ_DEF(wchar_t*) pj_ansi_to_unicode(const char *s, int len, |
| 26 |
wchar_t *buf, int buf_count) |
| 27 |
{ |
| 28 |
PJ_ASSERT_RETURN(s && buf, NULL); |
| 29 |
|
| 30 |
len = MultiByteToWideChar(CP_ACP, 0, s, len, |
| 31 |
buf, buf_count); |
| 32 |
if (buf_count) { |
| 33 |
if (len < buf_count) |
| 34 |
buf[len] = 0; |
| 35 |
else |
| 36 |
buf[len-1] = 0; |
| 37 |
} |
| 38 |
|
| 39 |
return buf; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
PJ_DEF(char*) pj_unicode_to_ansi( const wchar_t *wstr, pj_ssize_t len, |
| 44 |
char *buf, int buf_size) |
| 45 |
{ |
| 46 |
PJ_ASSERT_RETURN(wstr && buf, NULL); |
| 47 |
|
| 48 |
len = WideCharToMultiByte(CP_ACP, 0, wstr, (int)len, buf, buf_size, |
| 49 |
NULL, NULL); |
| 50 |
if (buf_size) { |
| 51 |
if (len < buf_size) |
| 52 |
buf[len] = '\0'; |
| 53 |
else |
| 54 |
buf[len-1] = '\0'; |
| 55 |
} |
| 56 |
|
| 57 |
return buf; |
| 58 |
} |
| 59 |
|