blob: 8da448a70643222c2f857a1d09344cbd9a2f74f4 [file] [log] [blame]
Alexandre Lision8af73cb2013-12-10 14:11:20 -05001/* $Id: unicode.h 4537 2013-06-19 06:47:43Z riza $ */
Tristan Matthews0a329cc2013-07-17 13:20:14 -04002/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
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
25
26/**
27 * @defgroup PJ_UNICODE Unicode Support
28 * @ingroup PJ_MISC
29 * @{
30 */
31
32PJ_BEGIN_DECL
33
34
35/**
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, int len,
51 wchar_t *wbuf, int 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_ssize_t len,
65 char *buf, int buf_size);
66
67
68#if defined(PJ_NATIVE_STRING_IS_UNICODE) && PJ_NATIVE_STRING_IS_UNICODE!=0
69
70/**
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 */
76# define PJ_DECL_UNICODE_TEMP_BUF(buf,size) wchar_t buf[size];
77
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 */
82# define PJ_STRING_TO_NATIVE(s,buf,max) pj_ansi_to_unicode( \
83 s, strlen(s), \
84 buf, max)
85
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 */
92# define PJ_DECL_ANSI_TEMP_BUF(buf,size) char buf[size];
93
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 */
99# define PJ_NATIVE_TO_STRING(cs,buf,max) pj_unicode_to_ansi( \
100 cs, wcslen(cs), \
101 buf, max)
102
103#else
104
105/**
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 */
111# define PJ_DECL_UNICODE_TEMP_BUF(var,size)
112/**
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 */
116# define PJ_STRING_TO_NATIVE(s,buf,max) ((char*)s)
117/**
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 */
123# define PJ_DECL_ANSI_TEMP_BUF(buf,size)
124/**
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 */
128# define PJ_NATIVE_TO_STRING(cs,buf,max) ((char*)(const char*)cs)
129
130#endif
131
132
133
134PJ_END_DECL
135
136/*
137 * @}
138 */
139
140
141#endif /* __PJ_UNICODE_H__ */