blob: 21efb548a0d8d7721ab419dac5e5949c7d81cab8 [file] [log] [blame]
Benny Prijono37e8d332006-01-20 21:03:36 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono37e8d332006-01-20 21:03:36 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#ifndef __PJ_UNICODE_H__
21#define __PJ_UNICODE_H__
22
23#include <pj/types.h>
24
Benny Prijono61396412006-02-14 21:03:15 +000025
Benny Prijono294c2532006-06-16 16:52:51 +000026/**
27 * @defgroup PJ_UNICODE Unicode Support
28 * @ingroup PJ_MISC
29 * @{
30 */
31
Benny Prijono61396412006-02-14 21:03:15 +000032PJ_BEGIN_DECL
33
34
Benny Prijono37e8d332006-01-20 21:03:36 +000035/**
36 * @file unicode.h
37 * @brief Provides Unicode conversion for Unicode OSes
38 */
39
40/**
41 * Convert ANSI strings to Unicode strings.
42 *
43 * @param str The ANSI string to be converted.
44 * @param len The length of the input string.
45 * @param wbuf Buffer to hold the Unicode string output.
46 * @param wbuf_count Buffer size, in number of elements (not bytes).
47 *
48 * @return The Unicode string, NULL terminated.
49 */
50PJ_DECL(wchar_t*) pj_ansi_to_unicode(const char *str, pj_size_t len,
51 wchar_t *wbuf, pj_size_t wbuf_count);
52
53
54/**
55 * Convert Unicode string to ANSI string.
56 *
57 * @param wstr The Unicode string to be converted.
58 * @param len The length of the input string.
59 * @param buf Buffer to hold the ANSI string output.
60 * @param buf_size Size of the output buffer.
61 *
62 * @return The ANSI string, NULL terminated.
63 */
64PJ_DECL(char*) pj_unicode_to_ansi(const wchar_t *wstr, pj_size_t len,
65 char *buf, pj_size_t buf_size);
66
67
68#if defined(PJ_NATIVE_STRING_IS_UNICODE) && PJ_NATIVE_STRING_IS_UNICODE!=0
69
Benny Prijono294c2532006-06-16 16:52:51 +000070/**
71 * This macro is used to declare temporary Unicode buffer for ANSI to
72 * Unicode conversion, and should be put in declaration section of a block.
73 * When PJ_NATIVE_STRING_IS_UNICODE macro is not defined, this
74 * macro will expand to nothing.
75 */
Benny Prijono61396412006-02-14 21:03:15 +000076# define PJ_DECL_UNICODE_TEMP_BUF(buf,size) wchar_t buf[size];
Benny Prijono294c2532006-06-16 16:52:51 +000077
78/**
79 * This macro will convert ANSI string to native, when the platform's
80 * native string is Unicode (PJ_NATIVE_STRING_IS_UNICODE is non-zero).
81 */
Benny Prijono61396412006-02-14 21:03:15 +000082# define PJ_STRING_TO_NATIVE(s,buf,max) pj_ansi_to_unicode( \
Benny Prijono37e8d332006-01-20 21:03:36 +000083 s, strlen(s), \
Benny Prijono61396412006-02-14 21:03:15 +000084 buf, max)
Benny Prijono294c2532006-06-16 16:52:51 +000085
86/**
87 * This macro is used to declare temporary ANSI buffer for Unicode to
88 * ANSI conversion, and should be put in declaration section of a block.
89 * When PJ_NATIVE_STRING_IS_UNICODE macro is not defined, this
90 * macro will expand to nothing.
91 */
Benny Prijono61396412006-02-14 21:03:15 +000092# define PJ_DECL_ANSI_TEMP_BUF(buf,size) char buf[size];
Benny Prijono294c2532006-06-16 16:52:51 +000093
94
95/**
96 * This macro will convert Unicode string to ANSI, when the platform's
97 * native string is Unicode (PJ_NATIVE_STRING_IS_UNICODE is non-zero).
98 */
Benny Prijono61396412006-02-14 21:03:15 +000099# define PJ_NATIVE_TO_STRING(cs,buf,max) pj_unicode_to_ansi( \
100 cs, wcslen(cs), \
101 buf, max)
Benny Prijono37e8d332006-01-20 21:03:36 +0000102
103#else
104
Benny Prijono294c2532006-06-16 16:52:51 +0000105/**
106 * This macro is used to declare temporary Unicode buffer for ANSI to
107 * Unicode conversion, and should be put in declaration section of a block.
108 * When PJ_NATIVE_STRING_IS_UNICODE macro is not defined, this
109 * macro will expand to nothing.
110 */
Benny Prijono37e8d332006-01-20 21:03:36 +0000111# define PJ_DECL_UNICODE_TEMP_BUF(var,size)
Benny Prijono294c2532006-06-16 16:52:51 +0000112/**
113 * This macro will convert ANSI string to native, when the platform's
114 * native string is Unicode (PJ_NATIVE_STRING_IS_UNICODE is non-zero).
115 */
Benny Prijono61396412006-02-14 21:03:15 +0000116# define PJ_STRING_TO_NATIVE(s,buf,max) ((char*)s)
Benny Prijono294c2532006-06-16 16:52:51 +0000117/**
118 * This macro is used to declare temporary ANSI buffer for Unicode to
119 * ANSI conversion, and should be put in declaration section of a block.
120 * When PJ_NATIVE_STRING_IS_UNICODE macro is not defined, this
121 * macro will expand to nothing.
122 */
Benny Prijono61396412006-02-14 21:03:15 +0000123# define PJ_DECL_ANSI_TEMP_BUF(buf,size)
Benny Prijono294c2532006-06-16 16:52:51 +0000124/**
125 * This macro will convert Unicode string to ANSI, when the platform's
126 * native string is Unicode (PJ_NATIVE_STRING_IS_UNICODE is non-zero).
127 */
Benny Prijono61396412006-02-14 21:03:15 +0000128# define PJ_NATIVE_TO_STRING(cs,buf,max) ((char*)(const char*)cs)
Benny Prijono37e8d332006-01-20 21:03:36 +0000129
130#endif
131
132
133
Benny Prijono61396412006-02-14 21:03:15 +0000134PJ_END_DECL
135
Benny Prijono294c2532006-06-16 16:52:51 +0000136/*
137 * @}
138 */
139
Benny Prijono61396412006-02-14 21:03:15 +0000140
Benny Prijono37e8d332006-01-20 21:03:36 +0000141#endif /* __PJ_UNICODE_H__ */