blob: eec3d51ebbadf68c03f1665bc4f11e2824b70d94 [file] [log] [blame]
Benny Prijono37e8d332006-01-20 21:03:36 +00001/* $Id$ */
2/*
Benny Prijonoa771a512007-02-19 01:13:53 +00003 * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org>
Benny Prijono37e8d332006-01-20 21:03:36 +00004 *
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#ifndef __PJ_UNICODE_H__
20#define __PJ_UNICODE_H__
21
22#include <pj/types.h>
23
Benny Prijono61396412006-02-14 21:03:15 +000024
Benny Prijono294c2532006-06-16 16:52:51 +000025/**
26 * @defgroup PJ_UNICODE Unicode Support
27 * @ingroup PJ_MISC
28 * @{
29 */
30
Benny Prijono61396412006-02-14 21:03:15 +000031PJ_BEGIN_DECL
32
33
Benny Prijono37e8d332006-01-20 21:03:36 +000034/**
35 * @file unicode.h
36 * @brief Provides Unicode conversion for Unicode OSes
37 */
38
39/**
40 * Convert ANSI strings to Unicode strings.
41 *
42 * @param str The ANSI string to be converted.
43 * @param len The length of the input string.
44 * @param wbuf Buffer to hold the Unicode string output.
45 * @param wbuf_count Buffer size, in number of elements (not bytes).
46 *
47 * @return The Unicode string, NULL terminated.
48 */
49PJ_DECL(wchar_t*) pj_ansi_to_unicode(const char *str, pj_size_t len,
50 wchar_t *wbuf, pj_size_t wbuf_count);
51
52
53/**
54 * Convert Unicode string to ANSI string.
55 *
56 * @param wstr The Unicode string to be converted.
57 * @param len The length of the input string.
58 * @param buf Buffer to hold the ANSI string output.
59 * @param buf_size Size of the output buffer.
60 *
61 * @return The ANSI string, NULL terminated.
62 */
63PJ_DECL(char*) pj_unicode_to_ansi(const wchar_t *wstr, pj_size_t len,
64 char *buf, pj_size_t buf_size);
65
66
67#if defined(PJ_NATIVE_STRING_IS_UNICODE) && PJ_NATIVE_STRING_IS_UNICODE!=0
68
Benny Prijono294c2532006-06-16 16:52:51 +000069/**
70 * This macro is used to declare temporary Unicode buffer for ANSI to
71 * Unicode conversion, and should be put in declaration section of a block.
72 * When PJ_NATIVE_STRING_IS_UNICODE macro is not defined, this
73 * macro will expand to nothing.
74 */
Benny Prijono61396412006-02-14 21:03:15 +000075# define PJ_DECL_UNICODE_TEMP_BUF(buf,size) wchar_t buf[size];
Benny Prijono294c2532006-06-16 16:52:51 +000076
77/**
78 * This macro will convert ANSI string to native, when the platform's
79 * native string is Unicode (PJ_NATIVE_STRING_IS_UNICODE is non-zero).
80 */
Benny Prijono61396412006-02-14 21:03:15 +000081# define PJ_STRING_TO_NATIVE(s,buf,max) pj_ansi_to_unicode( \
Benny Prijono37e8d332006-01-20 21:03:36 +000082 s, strlen(s), \
Benny Prijono61396412006-02-14 21:03:15 +000083 buf, max)
Benny Prijono294c2532006-06-16 16:52:51 +000084
85/**
86 * This macro is used to declare temporary ANSI buffer for Unicode to
87 * ANSI conversion, and should be put in declaration section of a block.
88 * When PJ_NATIVE_STRING_IS_UNICODE macro is not defined, this
89 * macro will expand to nothing.
90 */
Benny Prijono61396412006-02-14 21:03:15 +000091# define PJ_DECL_ANSI_TEMP_BUF(buf,size) char buf[size];
Benny Prijono294c2532006-06-16 16:52:51 +000092
93
94/**
95 * This macro will convert Unicode string to ANSI, when the platform's
96 * native string is Unicode (PJ_NATIVE_STRING_IS_UNICODE is non-zero).
97 */
Benny Prijono61396412006-02-14 21:03:15 +000098# define PJ_NATIVE_TO_STRING(cs,buf,max) pj_unicode_to_ansi( \
99 cs, wcslen(cs), \
100 buf, max)
Benny Prijono37e8d332006-01-20 21:03:36 +0000101
102#else
103
Benny Prijono294c2532006-06-16 16:52:51 +0000104/**
105 * This macro is used to declare temporary Unicode buffer for ANSI to
106 * Unicode conversion, and should be put in declaration section of a block.
107 * When PJ_NATIVE_STRING_IS_UNICODE macro is not defined, this
108 * macro will expand to nothing.
109 */
Benny Prijono37e8d332006-01-20 21:03:36 +0000110# define PJ_DECL_UNICODE_TEMP_BUF(var,size)
Benny Prijono294c2532006-06-16 16:52:51 +0000111/**
112 * This macro will convert ANSI string to native, when the platform's
113 * native string is Unicode (PJ_NATIVE_STRING_IS_UNICODE is non-zero).
114 */
Benny Prijono61396412006-02-14 21:03:15 +0000115# define PJ_STRING_TO_NATIVE(s,buf,max) ((char*)s)
Benny Prijono294c2532006-06-16 16:52:51 +0000116/**
117 * This macro is used to declare temporary ANSI buffer for Unicode to
118 * ANSI conversion, and should be put in declaration section of a block.
119 * When PJ_NATIVE_STRING_IS_UNICODE macro is not defined, this
120 * macro will expand to nothing.
121 */
Benny Prijono61396412006-02-14 21:03:15 +0000122# define PJ_DECL_ANSI_TEMP_BUF(buf,size)
Benny Prijono294c2532006-06-16 16:52:51 +0000123/**
124 * This macro will convert Unicode string to ANSI, when the platform's
125 * native string is Unicode (PJ_NATIVE_STRING_IS_UNICODE is non-zero).
126 */
Benny Prijono61396412006-02-14 21:03:15 +0000127# define PJ_NATIVE_TO_STRING(cs,buf,max) ((char*)(const char*)cs)
Benny Prijono37e8d332006-01-20 21:03:36 +0000128
129#endif
130
131
132
Benny Prijono61396412006-02-14 21:03:15 +0000133PJ_END_DECL
134
Benny Prijono294c2532006-06-16 16:52:51 +0000135/*
136 * @}
137 */
138
Benny Prijono61396412006-02-14 21:03:15 +0000139
Benny Prijono37e8d332006-01-20 21:03:36 +0000140#endif /* __PJ_UNICODE_H__ */