Debian Codegraph @

Xpjproject/pjlib/src/pj/unicode_win32.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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