Wireshark  4.3.0
The Wireshark network protocol analyzer
str_util.h
Go to the documentation of this file.
1 
11 #ifndef __STR_UTIL_H__
12 #define __STR_UTIL_H__
13 
14 #include <wireshark.h>
15 #include <wsutil/wmem/wmem.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif /* __cplusplus */
20 
21 WS_DLL_PUBLIC
22 char *
23 wmem_strconcat(wmem_allocator_t *allocator, const char *first, ...)
24 G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
25 
26 WS_DLL_PUBLIC
27 char *
28 wmem_strjoin(wmem_allocator_t *allocator,
29  const char *separator, const char *first, ...)
30 G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
31 
32 WS_DLL_PUBLIC
33 char *
34 wmem_strjoinv(wmem_allocator_t *allocator,
35  const char *separator, char **str_array)
36 G_GNUC_MALLOC;
37 
49 WS_DLL_PUBLIC
50 char **
51 wmem_strsplit(wmem_allocator_t *allocator, const char *src,
52  const char *delimiter, int max_tokens);
53 
69 WS_DLL_PUBLIC
70 char*
71 wmem_ascii_strdown(wmem_allocator_t *allocator, const char *str, ssize_t len);
72 
88 WS_DLL_PUBLIC
89 char *ascii_strdown_inplace(char *str);
90 
106 WS_DLL_PUBLIC
107 char *ascii_strup_inplace(char *str);
108 
114 WS_DLL_PUBLIC
115 bool isprint_string(const char *str);
116 
143 WS_DLL_PUBLIC
144 bool isprint_utf8_string(const char *str, const unsigned length);
145 
151 WS_DLL_PUBLIC
152 bool isdigit_string(const unsigned char *str);
153 
169 WS_DLL_PUBLIC
170 const char *ws_ascii_strcasestr(const char *haystack, const char *needle);
171 
172 WS_DLL_PUBLIC
173 char *ws_escape_string(wmem_allocator_t *alloc, const char *string, bool add_quotes);
174 
175 WS_DLL_PUBLIC
176 char *ws_escape_string_len(wmem_allocator_t *alloc, const char *string, ssize_t len, bool add_quotes);
177 
178 /* Replace null bytes with "\0". */
179 WS_DLL_PUBLIC
180 char *ws_escape_null(wmem_allocator_t *alloc, const char *string, size_t len, bool add_quotes);
181 
182 WS_DLL_PUBLIC
183 int ws_xton(char ch);
184 
185 typedef enum {
194 
195 #define FORMAT_SIZE_PREFIX_SI (1 << 0)
196 #define FORMAT_SIZE_PREFIX_IEC (1 << 1)
207 WS_DLL_PUBLIC
208 char *format_size_wmem(wmem_allocator_t *allocator, int64_t size,
209  format_size_units_e unit, uint16_t flags);
210 
211 #define format_size(size, unit, flags) \
212  format_size_wmem(NULL, size, unit, flags)
213 
214 WS_DLL_PUBLIC
215 char printable_char_or_period(char c);
216 
217 WS_DLL_PUBLIC WS_RETNONNULL
218 const char *ws_strerrorname_r(int errnum, char *buf, size_t buf_size);
219 
220 WS_DLL_PUBLIC
221 char *ws_strdup_underline(wmem_allocator_t *allocator, long offset, size_t len);
222 
248 WS_DLL_PUBLIC
249 char *format_text(wmem_allocator_t* allocator, const char *string, size_t len);
250 
259 WS_DLL_PUBLIC
260 char *format_text_string(wmem_allocator_t* allocator, const char *string);
261 
273 WS_DLL_PUBLIC
274 char *format_text_wsp(wmem_allocator_t* allocator, const char *line, size_t len);
275 
294 WS_DLL_PUBLIC
295 char *format_text_chr(wmem_allocator_t *allocator,
296  const char *string, size_t len, char chr);
297 
313 WS_DLL_PUBLIC
314 char *format_char(wmem_allocator_t *allocator, char c);
315 
336 WS_DLL_PUBLIC
337 char* ws_utf8_truncate(char *string, size_t len);
338 
339 WS_DLL_PUBLIC
340 void EBCDIC_to_ASCII(uint8_t *buf, unsigned bytes);
341 
342 WS_DLL_PUBLIC
343 uint8_t EBCDIC_to_ASCII1(uint8_t c);
344 
345 /* Types of character encodings */
346 typedef enum {
347  HEXDUMP_ENC_ASCII = 0, /* ASCII */
348  HEXDUMP_ENC_EBCDIC = 1 /* EBCDIC */
349 } hex_dump_enc;
350 
351 /*
352  * Hexdump options for ASCII:
353  */
354 
355 #define HEXDUMP_ASCII_MASK (0x0003U)
356 #define HEXDUMP_ASCII_OPTION(option) ((option) & HEXDUMP_ASCII_MASK)
357 
358 #define HEXDUMP_ASCII_INCLUDE (0x0000U) /* include ASCII section no delimiters (legacy tshark behavior) */
359 #define HEXDUMP_ASCII_DELIMIT (0x0001U) /* include ASCII section with delimiters, useful for reliable detection of last hexdata */
360 #define HEXDUMP_ASCII_EXCLUDE (0x0002U) /* exclude ASCII section from hexdump reports, if we really don't want or need it */
361 
362 WS_DLL_PUBLIC
363 bool hex_dump_buffer(bool (*print_line)(void *, const char *), void *fp,
364  const unsigned char *cp, unsigned length,
365  hex_dump_enc encoding,
366  unsigned ascii_option);
367 
368 /* To pass one of two strings, singular or plural */
369 #define plurality(d,s,p) ((d) == 1 ? (s) : (p))
370 
371 #define true_or_false(val) ((val) ? "TRUE" : "FALSE")
372 
373 #define string_or_null(val) ((val) ? (val) : "[NULL]")
374 
375 #ifdef __cplusplus
376 }
377 #endif /* __cplusplus */
378 
379 #endif /* __STR_UTIL_H__ */
WS_DLL_PUBLIC char * ascii_strup_inplace(char *str)
Definition: str_util.c:251
WS_DLL_PUBLIC const char * ws_ascii_strcasestr(const char *haystack, const char *needle)
Definition: str_util.c:324
WS_DLL_PUBLIC bool isprint_string(const char *str)
Definition: str_util.c:264
WS_DLL_PUBLIC char * format_text_chr(wmem_allocator_t *allocator, const char *string, size_t len, char chr)
Definition: str_util.c:1004
WS_DLL_PUBLIC bool isprint_utf8_string(const char *str, const unsigned length)
Definition: str_util.c:282
WS_DLL_PUBLIC char * wmem_ascii_strdown(wmem_allocator_t *allocator, const char *str, ssize_t len)
Definition: str_util.c:196
WS_DLL_PUBLIC char * format_char(wmem_allocator_t *allocator, char c)
Definition: str_util.c:1024
format_size_units_e
Definition: str_util.h:185
@ FORMAT_SIZE_UNIT_BITS_S
Definition: str_util.h:189
@ FORMAT_SIZE_UNIT_BYTES
Definition: str_util.h:187
@ FORMAT_SIZE_UNIT_PACKETS
Definition: str_util.h:191
@ FORMAT_SIZE_UNIT_BYTES_S
Definition: str_util.h:190
@ FORMAT_SIZE_UNIT_NONE
Definition: str_util.h:186
@ FORMAT_SIZE_UNIT_PACKETS_S
Definition: str_util.h:192
@ FORMAT_SIZE_UNIT_BITS
Definition: str_util.h:188
WS_DLL_PUBLIC char * format_text_string(wmem_allocator_t *allocator, const char *string)
Definition: str_util.c:975
WS_DLL_PUBLIC char * format_text_wsp(wmem_allocator_t *allocator, const char *line, size_t len)
Definition: str_util.c:987
WS_DLL_PUBLIC char * ascii_strdown_inplace(char *str)
Definition: str_util.c:238
WS_DLL_PUBLIC char * format_text(wmem_allocator_t *allocator, const char *string, size_t len)
Definition: str_util.c:950
WS_DLL_PUBLIC char * ws_utf8_truncate(char *string, size_t len)
Definition: str_util.c:1052
WS_DLL_PUBLIC char ** wmem_strsplit(wmem_allocator_t *allocator, const char *src, const char *delimiter, int max_tokens)
Definition: str_util.c:138
WS_DLL_PUBLIC bool isdigit_string(const unsigned char *str)
Definition: str_util.c:307
WS_DLL_PUBLIC char * format_size_wmem(wmem_allocator_t *allocator, int64_t size, format_size_units_e unit, uint16_t flags)
Definition: str_util.c:364
Definition: wmem_allocator.h:27