2 * Unicode utility definitions
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 2006 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef __UNICODEUTIL_H__
24 #define __UNICODEUTIL_H__
28 #include "ws_symbol_export.h"
34 * Unicode convenience routines.
42 int ws_utf8_char_len(guint8 ch);
50 /** Given a UTF-8 string, convert it to UTF-16. This is meant to be used
51 * to convert between GTK+ 2.x (UTF-8) to Windows (UTF-16).
53 * @param utf8str The string to convert. May be NULL.
54 * @return The string converted to UTF-16. If utf8str is NULL, returns
55 * NULL. The return value should NOT be freed by the caller.
58 const wchar_t * utf_8to16(const char *utf8str);
60 /** Create a UTF-16 string (in place) according to the format string.
62 * @param utf16buf The buffer to return the UTF-16 string in.
63 * @param utf16buf_len The size of the 'utf16buf' parameter
64 * @param fmt A standard g_printf() format string
67 void utf_8to16_snprintf(TCHAR *utf16buf, gint utf16buf_len, const gchar* fmt,
68 ...) G_GNUC_PRINTF(3, 4);
70 /** Given a UTF-16 string, convert it to UTF-8. This is meant to be used
71 * to convert between GTK+ 2.x (UTF-8) to Windows (UTF-16).
73 * @param utf16str The string to convert. May be NULL.
74 * @return The string converted to UTF-8. If utf16str is NULL, returns
75 * NULL. The return value should NOT be freed by the caller.
78 gchar * utf_16to8(const wchar_t *utf16str);
80 /** Convert the program argument list from UTF-16 to UTF-8 and
81 * store it in the supplied array. This is intended to be used
82 * to normalize command line arguments at program startup.
84 * @param argc The number of arguments. You should simply pass the
85 * first argument from main().
86 * @param argv The argument values (vector). You should simply pass
87 * the second argument from main().
90 void arg_list_utf_16to8(int argc, char *argv[]);
96 * defines for helping with UTF-16 surrogate pairs
99 #define IS_LEAD_SURROGATE(uchar2) \
100 ((uchar2) >= 0xd800 && (uchar2) < 0xdc00)
101 #define IS_TRAIL_SURROGATE(uchar2) \
102 ((uchar2) >= 0xdc00 && (uchar2) < 0xe000)
103 #define SURROGATE_VALUE(lead, trail) \
104 (((((lead) - 0xd800) << 10) | ((trail) - 0xdc00)) + 0x100000)
110 #endif /* __UNICODEUTIL_H__ */