Replace "svn" with "git" all over the place.
[metze/wireshark/wip.git] / wsutil / unicode-utils.h
1 /* unicode-utils.h
2  * Unicode utility definitions
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 2006 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #ifndef __UNICODEUTIL_H__
26 #define __UNICODEUTIL_H__
27
28 #include "config.h"
29
30 #include "ws_symbol_export.h"
31
32 #include <glib.h>
33
34 /**
35  * @file Unicode convenience routines.
36  */
37
38 WS_DLL_PUBLIC
39 int ws_utf8_char_len(guint8 ch);
40
41 #ifdef _WIN32
42
43 #include <windows.h>
44 #include <tchar.h>
45 #include <wchar.h>
46
47 /** Given a UTF-8 string, convert it to UTF-16.  This is meant to be used
48  * to convert between GTK+ 2.x (UTF-8) to Windows (UTF-16).
49  *
50  * @param utf8str The string to convert.  May be NULL.
51  * @return The string converted to UTF-16.  If utf8str is NULL, returns
52  * NULL.  The return value should NOT be freed by the caller.
53  */
54 WS_DLL_PUBLIC
55 wchar_t * utf_8to16(const char *utf8str);
56
57 /** Create a UTF-16 string (in place) according to the format string.
58  *
59  * @param utf16buf The buffer to return the UTF-16 string in.
60  * @param utf16buf_len The size of the 'utf16buf' parameter
61  * @param fmt A standard g_printf() format string
62  */
63 WS_DLL_PUBLIC
64 void utf_8to16_snprintf(TCHAR *utf16buf, gint utf16buf_len, const gchar* fmt, ...);
65
66 /** Given a UTF-16 string, convert it to UTF-8.  This is meant to be used
67  * to convert between GTK+ 2.x (UTF-8) to Windows (UTF-16).
68  *
69  * @param utf16str The string to convert.  May be NULL.
70  * @return The string converted to UTF-8.  If utf16str is NULL, returns
71  * NULL.  The return value should NOT be freed by the caller.
72  */
73 WS_DLL_PUBLIC
74 gchar * utf_16to8(const wchar_t *utf16str);
75
76 /** Convert the program argument list from UTF-16 to UTF-8 and
77  * store it in the supplied array. This is intended to be used
78  * to normalize command line arguments at program startup.
79  *
80  * @param argc The number of arguments. You should simply pass the
81  * first argument from main().
82  * @param argv The argument values (vector). You should simply pass
83  * the second argument from main().
84  */
85 WS_DLL_PUBLIC
86 void arg_list_utf_16to8(int argc, char *argv[]);
87
88
89 #endif /* _WIN32 */
90
91 /*
92  * defines for helping with UTF-16 surrogate pairs
93  */
94
95 #define IS_LEAD_SURROGATE(uchar2) \
96         ((uchar2) >= 0xd800 && (uchar2) < 0xdc00)
97 #define IS_TRAIL_SURROGATE(uchar2) \
98         ((uchar2) >= 0xdc00 && (uchar2) < 0xe000)
99 #define SURROGATE_VALUE(lead, trail) \
100         (((((lead) - 0xd800) << 10) | ((trail) - 0xdc00)) + 0x100000)
101
102 #endif /* __UNICODEUTIL_H__ */