licensecheck: fix detection of multiple licenses
[metze/wireshark/wip.git] / wsutil / unicode-utils.h
1 /* unicode-utils.h
2  * Unicode utility definitions
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 2006 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #ifndef __UNICODEUTIL_H__
12 #define __UNICODEUTIL_H__
13
14 #include "ws_symbol_export.h"
15
16 #include <glib.h>
17
18 /**
19  * @file
20  * Unicode convenience routines.
21  */
22
23 #ifdef  __cplusplus
24 extern "C" {
25 #endif
26
27 WS_DLL_PUBLIC
28 int ws_utf8_char_len(guint8 ch);
29
30 #ifdef _WIN32
31
32 #include <windows.h>
33 #include <tchar.h>
34 #include <wchar.h>
35
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).
38  *
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.
42  */
43 WS_DLL_PUBLIC
44 const wchar_t * utf_8to16(const char *utf8str);
45
46 /** Create a UTF-16 string (in place) according to the format string.
47  *
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
51  */
52 WS_DLL_PUBLIC
53 void utf_8to16_snprintf(TCHAR *utf16buf, gint utf16buf_len, const gchar* fmt,
54         ...) G_GNUC_PRINTF(3, 4);
55
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).
58  *
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.
62  */
63 WS_DLL_PUBLIC
64 gchar * utf_16to8(const wchar_t *utf16str);
65
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.
69  *
70  * @param argc The number of arguments.
71  * @param argv The argument values (vector).
72  */
73 WS_DLL_PUBLIC
74 char ** arg_list_utf_16to8(int argc, wchar_t *wc_argv[]);
75
76 #endif /* _WIN32 */
77
78 /*
79  * defines for helping with UTF-16 surrogate pairs
80  */
81
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)
88
89 #ifdef  __cplusplus
90 }
91 #endif
92
93 #endif /* __UNICODEUTIL_H__ */