| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
unicode-utils.h
Go to the documentation of this file.
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 <wireshark.h>
15
16#ifdef _WIN32
17#include <windows.h>
18#include <tchar.h>
19#include <wchar.h>
20#endif
21
27#ifdef __cplusplus
28 extern "C" {
29#endif
30
31#ifdef WS_DEBUG_UTF_8
32#define DEBUG_UTF_8_ENABLED true
33#else
34#define DEBUG_UTF_8_ENABLED false
35#endif
36
37#define _CHECK_UTF_8(level, str, len) \
38 do { \
39 const char *__uni_endptr; \
40 if (DEBUG_UTF_8_ENABLED && (str) != NULL && \
41 !g_utf8_validate(str, len, &__uni_endptr)) { \
42 ws_log_utf8(str, len, __uni_endptr); \
43 } \
44 } while (0)
45
46#define WS_UTF_8_CHECK(str, len) \
47 _CHECK_UTF_8(LOG_LEVEL_DEBUG, str, len)
48
49#define WS_UTF_8_DEBUG_HERE(str, len) \
50 _CHECK_UTF_8(LOG_LEVEL_ECHO, str, len)
51
52WSUTIL_EXPORT
53 const int ws_utf8_seqlen[256];
54
64#define ws_utf8_char_len(ch) (ws_utf8_seqlen[(ch)])
65
78WS_DLL_PUBLIC uint8_t *
79 ws_utf8_make_valid(wmem_allocator_t *scope, const uint8_t *ptr, ssize_t length);
80
93WS_DLL_PUBLIC wmem_strbuf_t *
94 ws_utf8_make_valid_strbuf(wmem_allocator_t *scope, const uint8_t *ptr, ssize_t length);
95
96#ifdef _WIN32
97
106WS_DLL_PUBLIC
107 const wchar_t * utf_8to16(const char *utf8str);
108
116WS_DLL_PUBLIC
117 void utf_8to16_snprintf(TCHAR *utf16buf, int utf16buf_len, const char* fmt, ...)
118G_GNUC_PRINTF(3, 4);
119
128WS_DLL_PUBLIC
129 char * utf_16to8(const wchar_t *utf16str);
130
145WS_DLL_PUBLIC
146 char **arg_list_utf_16to8(int argc, wchar_t *wc_argv[]);
147
148#endif /* _WIN32 */
149
150/*
151 * defines for helping with UTF-16 surrogate pairs
152 */
153
154#define IS_LEAD_SURROGATE(uchar2) \
155 ((uchar2) >= 0xd800 && (uchar2) < 0xdc00)
156#define IS_TRAIL_SURROGATE(uchar2) \
157 ((uchar2) >= 0xdc00 && (uchar2) < 0xe000)
158#define SURROGATE_VALUE(lead, trail) \
159 (((((lead) - 0xd800) << 10) | ((trail) - 0xdc00)) + 0x10000)
160
161#ifdef __cplusplus
162}
163#endif
164
165#endif /* __UNICODEUTIL_H__ */
_wmem_allocator_t
Internal memory allocator interface used by the wmem subsystem.
Definition wmem_allocator.h:34
_wmem_strbuf_t
Internal structure representing a wmem-allocated string buffer.
Definition wmem_strbuf.h:38
ws_utf8_make_valid
WS_DLL_PUBLIC uint8_t * ws_utf8_make_valid(wmem_allocator_t *scope, const uint8_t *ptr, ssize_t length)
Validates and sanitizes a UTF-8 byte sequence.
Definition unicode-utils.c:222
ws_utf8_make_valid_strbuf
WS_DLL_PUBLIC wmem_strbuf_t * ws_utf8_make_valid_strbuf(wmem_allocator_t *scope, const uint8_t *ptr, ssize_t length)
Validates a UTF-8 byte sequence and returns a string buffer.
Definition unicode-utils.c:193