Benny Prijono | f260e46 | 2007-04-30 21:03:32 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org> |
| 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 | wbuf[len] = 0; |
| 41 | } |
| 42 | |
| 43 | return wbuf; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | /* |
| 48 | * Convert Unicode string to ANSI string. |
| 49 | */ |
| 50 | PJ_DEF(char*) pj_unicode_to_ansi( const wchar_t *wstr, pj_size_t len, |
| 51 | char *buf, pj_size_t buf_size) |
| 52 | { |
| 53 | TPtrC16 aUnicode((const TUint16*)wstr, (TInt)len); |
| 54 | TPtr8 aForeign((TUint8*)buf, (TInt)(buf_size-1)); |
| 55 | TInt left; |
| 56 | |
| 57 | left = PjSymbianOS::Instance()->ConvertFromUnicode(aForeign, aUnicode); |
| 58 | |
| 59 | if (left != 0) { |
| 60 | // Error, or there are unconvertable characters |
| 61 | buf[0] = '\0'; |
| 62 | } else { |
| 63 | buf[len] = '\0'; |
| 64 | } |
| 65 | |
| 66 | return buf; |
| 67 | } |
| 68 | |
| 69 | |