2 * Unicode utility definitions
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 2006 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
11 #ifndef __UNICODEUTIL_H__
12 #define __UNICODEUTIL_H__
14 #include "ws_symbol_export.h"
20 * Unicode convenience routines.
28 int ws_utf8_char_len(guint8 ch);
36 /** Given a UTF-8 string, convert it to UTF-16. This is meant to be used
37 * to convert between GTK+ 2.x (UTF-8) to Windows (UTF-16).
39 * @param utf8str The string to convert. May be NULL.
40 * @return The string converted to UTF-16. If utf8str is NULL, returns
41 * NULL. The return value should NOT be freed by the caller.
44 const wchar_t * utf_8to16(const char *utf8str);
46 /** Create a UTF-16 string (in place) according to the format string.
48 * @param utf16buf The buffer to return the UTF-16 string in.
49 * @param utf16buf_len The size of the 'utf16buf' parameter
50 * @param fmt A standard g_printf() format string
53 void utf_8to16_snprintf(TCHAR *utf16buf, gint utf16buf_len, const gchar* fmt,
54 ...) G_GNUC_PRINTF(3, 4);
56 /** Given a UTF-16 string, convert it to UTF-8. This is meant to be used
57 * to convert between GTK+ 2.x (UTF-8) to Windows (UTF-16).
59 * @param utf16str The string to convert. May be NULL.
60 * @return The string converted to UTF-8. If utf16str is NULL, returns
61 * NULL. The return value should NOT be freed by the caller.
64 gchar * utf_16to8(const wchar_t *utf16str);
66 /** Convert the supplied program argument list from UTF-16 to UTF-8
67 * return a pointer to the array of UTF-8 arguments. This is intended
68 * to be used to normalize command line arguments at program startup.
70 * @param argc The number of arguments.
71 * @param argv The argument values (vector).
74 char ** arg_list_utf_16to8(int argc, wchar_t *wc_argv[]);
79 * defines for helping with UTF-16 surrogate pairs
82 #define IS_LEAD_SURROGATE(uchar2) \
83 ((uchar2) >= 0xd800 && (uchar2) < 0xdc00)
84 #define IS_TRAIL_SURROGATE(uchar2) \
85 ((uchar2) >= 0xdc00 && (uchar2) < 0xe000)
86 #define SURROGATE_VALUE(lead, trail) \
87 (((((lead) - 0xd800) << 10) | ((trail) - 0xdc00)) + 0x10000)
93 #endif /* __UNICODEUTIL_H__ */