Wireshark 4.5.0
The Wireshark network protocol analyzer
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
wmem_strbuf.h
Go to the documentation of this file.
1
12#ifndef __WMEM_STRBUF_H__
13#define __WMEM_STRBUF_H__
14
15#include <ws_codepoints.h>
16
17#include "wmem_core.h"
18
19#ifdef __cplusplus
20extern "C" {
21#endif /* __cplusplus */
22
32/* Holds a wmem-allocated string-buffer.
33 * len is the length of the string (not counting the null-terminator) and
34 * should be the same as strlen(str) unless the string contains embedded
35 * nulls.
36 * alloc_size is the size of the raw buffer pointed to by str, regardless of
37 * what string is actually being stored (i.e. the buffer contents)
38 */
40 /* read-only fields */
41 wmem_allocator_t *allocator;
42 char *str;
43 size_t len;
44
45 /* private fields */
46 size_t alloc_size;
47};
48
49typedef struct _wmem_strbuf_t wmem_strbuf_t;
50
51WS_DLL_PUBLIC
53wmem_strbuf_new_sized(wmem_allocator_t *allocator, size_t alloc_size)
54G_GNUC_MALLOC;
55
56WS_DLL_PUBLIC
58wmem_strbuf_new(wmem_allocator_t *allocator, const char *str)
59G_GNUC_MALLOC;
60
61#define wmem_strbuf_create(allocator) \
62 wmem_strbuf_new(allocator, "")
63
64WS_DLL_PUBLIC
66wmem_strbuf_new_len(wmem_allocator_t *allocator, const char *str, size_t len)
67G_GNUC_MALLOC;
68
69WS_DLL_PUBLIC
71wmem_strbuf_dup(wmem_allocator_t *allocator, const wmem_strbuf_t *strbuf)
72G_GNUC_MALLOC;
73
74WS_DLL_PUBLIC
75void
76wmem_strbuf_append(wmem_strbuf_t *strbuf, const char *str);
77
78/* Appends up to append_len bytes from str. Ensures that strbuf
79 * is null terminated afterwards but will copy embedded nulls. */
80WS_DLL_PUBLIC
81void
82wmem_strbuf_append_len(wmem_strbuf_t *strbuf, const char *str, size_t append_len);
83
84WS_DLL_PUBLIC
85void
86wmem_strbuf_append_printf(wmem_strbuf_t *strbuf, const char *format, ...)
87G_GNUC_PRINTF(2, 3);
88
89WS_DLL_PUBLIC
90void
91wmem_strbuf_append_vprintf(wmem_strbuf_t *strbuf, const char *fmt, va_list ap);
92
93WS_DLL_PUBLIC
94void
95wmem_strbuf_append_c(wmem_strbuf_t *strbuf, const char c);
96
97WS_DLL_PUBLIC
98void
99wmem_strbuf_append_c_count(wmem_strbuf_t *strbuf, const char c, size_t count);
100
101WS_DLL_PUBLIC
102void
103wmem_strbuf_append_unichar(wmem_strbuf_t *strbuf, const gunichar c);
104
105#define wmem_strbuf_append_unichar_repl(buf) \
106 wmem_strbuf_append_unichar(buf, UNICODE_REPLACEMENT_CHARACTER)
107
108/* As wmem_strbuf_append_unichar but appends a REPLACEMENT CHARACTER
109 * instead for any invalid Unicode codepoints.
110 */
111WS_DLL_PUBLIC
112void
113wmem_strbuf_append_unichar_validated(wmem_strbuf_t *strbuf, const gunichar c);
114
115WS_DLL_PUBLIC
116void
117wmem_strbuf_append_hex(wmem_strbuf_t *strbuf, uint8_t);
118
119/* Returns the number of characters written (4, 6 or 10). */
120WS_DLL_PUBLIC
121size_t
122wmem_strbuf_append_hex_unichar(wmem_strbuf_t *strbuf, gunichar);
123
124WS_DLL_PUBLIC
125void
126wmem_strbuf_truncate(wmem_strbuf_t *strbuf, const size_t len);
127
128WS_DLL_PUBLIC
129const char *
130wmem_strbuf_get_str(const wmem_strbuf_t *strbuf);
131
132WS_DLL_PUBLIC
133size_t
134wmem_strbuf_get_len(const wmem_strbuf_t *strbuf);
135
136WS_DLL_PUBLIC
137int
138wmem_strbuf_strcmp(const wmem_strbuf_t *sb1, const wmem_strbuf_t *sb2);
139
140WS_DLL_PUBLIC
141const char *
142wmem_strbuf_strstr(const wmem_strbuf_t *haystack, const wmem_strbuf_t *needle);
143
149WS_DLL_PUBLIC
150char *
152
153WS_DLL_PUBLIC
154void
155wmem_strbuf_destroy(wmem_strbuf_t *strbuf);
156
157/* Validates the string buffer as UTF-8.
158 * Unlike g_utf8_validate(), accepts embedded NUL bytes as valid UTF-8.
159 * If endpptr is non-NULL, then the end of the valid range is stored there
160 * (i.e. the first invalid character, or the end of the buffer otherwise).
161 */
162WS_DLL_PUBLIC
163bool
164wmem_strbuf_utf8_validate(wmem_strbuf_t *strbuf, const char **endptr);
165
166WS_DLL_PUBLIC
167void
168wmem_strbuf_utf8_make_valid(wmem_strbuf_t *strbuf);
169
173#ifdef __cplusplus
174}
175#endif /* __cplusplus */
176
177#endif /* __WMEM_STRBUF_H__ */
178
179/*
180 * Editor modelines - https://www.wireshark.org/tools/modelines.html
181 *
182 * Local variables:
183 * c-basic-offset: 4
184 * tab-width: 8
185 * indent-tabs-mode: nil
186 * End:
187 *
188 * vi: set shiftwidth=4 tabstop=8 expandtab:
189 * :indentSize=4:tabSize=8:noTabs=true:
190 */
WS_DLL_PUBLIC char * wmem_strbuf_finalize(wmem_strbuf_t *strbuf)
Definition wmem_strbuf.c:382
Definition wmem_allocator.h:27
Definition wmem_strbuf.h:39