Debian Codegraph @

Xpjproject/pjlib/src/pj/unicode_symbian.cpp

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
21 #include "os_symbian.h"
22
23
24 /*
25 * Convert ANSI strings to Unicode strings.
26 */
27 PJ_DEF(wchar_t*) pj_ansi_to_unicode( const char *str, pj_size_t len,
28 wchar_t *wbuf, pj_size_t wbuf_count)
29 {
30 TPtrC8 aForeign((const TUint8*)str, (TInt)len);
31 TPtr16 aUnicode((TUint16*)wbuf, (TInt)(wbuf_count-1));
32 TInt left;
33
34 left = PjSymbianOS::Instance()->ConvertToUnicode(aUnicode, aForeign);
35
36 if (left != 0) {
37 // Error, or there are unconvertable characters
38 *wbuf = 0;
39 } else {
40 if (len < wbuf_count)
41 wbuf[len] = 0;
42 else
43 wbuf[len-1] = 0;
44 }
45
46 return wbuf;
47 }
48
49
50 /*
51 * Convert Unicode string to ANSI string.
52 */
53 PJ_DEF(char*) pj_unicode_to_ansi( const wchar_t *wstr, pj_size_t len,
54 char *buf, pj_size_t buf_size)
55 {
56 TPtrC16 aUnicode((const TUint16*)wstr, (TInt)len);
57 TPtr8 aForeign((TUint8*)buf, (TInt)(buf_size-1));
58 TInt left;
59
60 left = PjSymbianOS::Instance()->ConvertFromUnicode(aForeign, aUnicode);
61
62 if (left != 0) {
63 // Error, or there are unconvertable characters
64 buf[0] = '\0';
65 } else {
66 if (len < buf_size)
67 buf[len] = '\0';
68 else
69 buf[len-1] = '\0';
70 }
71
72 return buf;
73 }
74
75