| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
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
34WS_DLL_PUBLIC
35 char *
36 wmem_strconcat(wmem_allocator_t *allocator, const char *first, ...)
37G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
38
52WS_DLL_PUBLIC
53 char *
54 wmem_strjoin(wmem_allocator_t *allocator,
55 const char *separator, const char *first, ...)
56G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
57
58
73WS_DLL_PUBLIC
74 char *
75 wmem_strjoinv(wmem_allocator_t *allocator,
76 const char *separator, char **str_array)
77G_GNUC_MALLOC;
78
92WS_DLL_PUBLIC
93 char **
94 wmem_strsplit(wmem_allocator_t *allocator, const char *src,
95 const char *delimiter, int max_tokens);
96
111WS_DLL_PUBLIC
112 char*
113 wmem_ascii_strdown(wmem_allocator_t *allocator, const char *str, ssize_t len);
114
133WS_DLL_PUBLIC
134 char *ascii_strdown_inplace(char *str);
135
154WS_DLL_PUBLIC
155 char *ascii_strup_inplace(char *str);
156
163WS_DLL_PUBLIC
164 bool isprint_string(const char *str);
165
192WS_DLL_PUBLIC
193 bool isprint_utf8_string(const char *str, const unsigned length);
194
201WS_DLL_PUBLIC
202 bool isdigit_string(const char *str);
203
219WS_DLL_PUBLIC
220const char *ws_ascii_strcasestr(const char *haystack, const char *needle);
221
230WS_DLL_PUBLIC
231const uint8_t *ws_memrchr(const void *haystack, int ch, size_t n);
232
245WS_DLL_PUBLIC
246 char *ws_escape_string(wmem_allocator_t *alloc, const char *string, bool add_quotes);
247
260WS_DLL_PUBLIC
261 char *ws_escape_string_len(wmem_allocator_t *alloc, const char *string, ssize_t len, bool add_quotes);
262
279WS_DLL_PUBLIC
280 char *ws_escape_null(wmem_allocator_t *alloc, const char *string, size_t len, bool add_quotes);
281
302WS_DLL_PUBLIC
303 char *ws_escape_csv(wmem_allocator_t *alloc, const char *string, bool add_quotes, char quote_char, bool double_quote, bool escape_whitespace);
304
314WS_DLL_PUBLIC
315 int ws_xton(char ch);
316
327typedef enum {
328 FORMAT_SIZE_UNIT_NONE,
329 /* XXX - This does not append a trailing space if there is no prefix.
330 * That's good if you intend to list the unit somewhere else, e.g. in a
331 * legend, header, or other column, but doesn't work well if intending
332 * to append your own unit. You can test whether there's a prefix or
333 * not with g_ascii_isdigit() (plus special handling for inf and NaN).
334 */
335 FORMAT_SIZE_UNIT_BYTES,
336 FORMAT_SIZE_UNIT_BITS,
337 FORMAT_SIZE_UNIT_BITS_S,
338 FORMAT_SIZE_UNIT_BYTES_S,
339 FORMAT_SIZE_UNIT_PACKETS,
340 FORMAT_SIZE_UNIT_PACKETS_S,
341 FORMAT_SIZE_UNIT_EVENTS,
342 FORMAT_SIZE_UNIT_EVENTS_S,
343 FORMAT_SIZE_UNIT_FIELDS,
344 FORMAT_SIZE_UNIT_SECONDS,
345 FORMAT_SIZE_UNIT_ERLANGS,
346} format_size_units_e;
347
348#define FORMAT_SIZE_PREFIX_SI (1 << 0)
349#define FORMAT_SIZE_PREFIX_IEC (1 << 1)
367WS_DLL_PUBLIC
368 char *format_units(wmem_allocator_t *allocator, double size,
369 format_size_units_e unit, uint16_t flags,
370 int precision);
371
383WS_DLL_PUBLIC
384 char *format_size_wmem(wmem_allocator_t *allocator, int64_t size,
385 format_size_units_e unit, uint16_t flags);
386
397#define format_size(size, unit, flags) \
398 format_size_wmem(NULL, size, unit, flags)
399
409WS_DLL_PUBLIC
410 char printable_char_or_period(char c);
411
425WS_DLL_PUBLIC WS_RETNONNULL
426 const char *ws_strerrorname_r(int errnum, char *buf, size_t buf_size);
427
441WS_DLL_PUBLIC
442 char *ws_strdup_underline(wmem_allocator_t *allocator, long offset, size_t len);
443
469WS_DLL_PUBLIC
470 char *format_text(wmem_allocator_t* allocator, const char *string, size_t len);
471
480WS_DLL_PUBLIC
481 char *format_text_string(wmem_allocator_t* allocator, const char *string);
482
494WS_DLL_PUBLIC
495 char *format_text_wsp(wmem_allocator_t* allocator, const char *line, size_t len);
496
515WS_DLL_PUBLIC
516 char *format_text_chr(wmem_allocator_t *allocator,
517 const char *string, size_t len, char chr);
518
534WS_DLL_PUBLIC
535 char *format_char(wmem_allocator_t *allocator, char c);
536
557WS_DLL_PUBLIC
558 char* ws_utf8_truncate(char *string, size_t len);
559
569WS_DLL_PUBLIC
570 void EBCDIC_to_ASCII(uint8_t *buf, unsigned bytes);
571
578WS_DLL_PUBLIC
579uint8_t EBCDIC_to_ASCII1(uint8_t c);
580
588 typedef enum {
589 HEXDUMP_ENC_ASCII = 0,
590 HEXDUMP_ENC_EBCDIC = 1
591} hex_dump_enc;
592
593/*
594 * Hexdump options for ASCII:
595 */
596
600#define HEXDUMP_ASCII_MASK (0x0003U)
601
608#define HEXDUMP_ASCII_OPTION(option) ((option) & HEXDUMP_ASCII_MASK)
609
616#define HEXDUMP_ASCII_INCLUDE (0x0000U)
617
623#define HEXDUMP_ASCII_DELIMIT (0x0001U)
624
630#define HEXDUMP_ASCII_EXCLUDE (0x0002U)
631
650WS_DLL_PUBLIC
651 bool hex_dump_buffer(bool (*print_line)(void *, const char *), void *fp,
652 const unsigned char *cp, unsigned length,
653 hex_dump_enc encoding,
654 unsigned ascii_option);
655
666#define plurality(d,s,p) ((d) == 1 ? (s) : (p))
667
674#define true_or_false(val) ((val) ? "TRUE" : "FALSE")
675
682#define string_or_null(val) ((val) ? (val) : "[NULL]")
683
684#ifdef __cplusplus
685}
686#endif /* __cplusplus */
687
688#endif /* __STR_UTIL_H__ */
wmem_strjoin
WS_DLL_PUBLIC char * wmem_strjoin(wmem_allocator_t *allocator, const char *separator, const char *first,...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED
Join multiple strings using a separator into a single newly allocated string.
Definition str_util.c:79
ws_memrchr
WS_DLL_PUBLIC const uint8_t * ws_memrchr(const void *haystack, int ch, size_t n)
Definition str_util.c:367
format_text_string
WS_DLL_PUBLIC char * format_text_string(wmem_allocator_t *allocator, const char *string)
Definition str_util.c:1241
isprint_string
WS_DLL_PUBLIC bool isprint_string(const char *str)
Check if an entire string consists of printable characters.
Definition str_util.c:287
ws_escape_string_len
WS_DLL_PUBLIC char * ws_escape_string_len(wmem_allocator_t *alloc, const char *string, ssize_t len, bool add_quotes)
Escape a string of specified length for safe display or output.
Definition str_util.c:770
ws_utf8_truncate
WS_DLL_PUBLIC char * ws_utf8_truncate(char *string, size_t len)
Definition str_util.c:1318
isprint_utf8_string
WS_DLL_PUBLIC bool isprint_utf8_string(const char *str, const unsigned length)
Definition str_util.c:305
ws_strerrorname_r
WS_DLL_PUBLIC WS_RETNONNULL const char * ws_strerrorname_r(int errnum, char *buf, size_t buf_size)
Return the symbolic name of an error code.
Definition str_util.c:798
hex_dump_enc
hex_dump_enc
Character encoding types supported by hex dump formatting.
Definition str_util.h:588
HEXDUMP_ENC_EBCDIC
@ HEXDUMP_ENC_EBCDIC
Definition str_util.h:590
HEXDUMP_ENC_ASCII
@ HEXDUMP_ENC_ASCII
Definition str_util.h:589
ascii_strup_inplace
WS_DLL_PUBLIC char * ascii_strup_inplace(char *str)
In-place conversion of lower-case ASCII letters to upper-case.
Definition str_util.c:274
format_size_units_e
format_size_units_e
Unit types used by format_size_wmem() for formatting size values.
Definition str_util.h:327
FORMAT_SIZE_UNIT_BITS_S
@ FORMAT_SIZE_UNIT_BITS_S
Definition str_util.h:337
FORMAT_SIZE_UNIT_EVENTS
@ FORMAT_SIZE_UNIT_EVENTS
Definition str_util.h:341
FORMAT_SIZE_UNIT_BYTES
@ FORMAT_SIZE_UNIT_BYTES
Definition str_util.h:335
FORMAT_SIZE_UNIT_PACKETS
@ FORMAT_SIZE_UNIT_PACKETS
Definition str_util.h:339
FORMAT_SIZE_UNIT_BYTES_S
@ FORMAT_SIZE_UNIT_BYTES_S
Definition str_util.h:338
FORMAT_SIZE_UNIT_SECONDS
@ FORMAT_SIZE_UNIT_SECONDS
Definition str_util.h:344
FORMAT_SIZE_UNIT_NONE
@ FORMAT_SIZE_UNIT_NONE
Definition str_util.h:328
FORMAT_SIZE_UNIT_FIELDS
@ FORMAT_SIZE_UNIT_FIELDS
Definition str_util.h:343
FORMAT_SIZE_UNIT_EVENTS_S
@ FORMAT_SIZE_UNIT_EVENTS_S
Definition str_util.h:342
FORMAT_SIZE_UNIT_ERLANGS
@ FORMAT_SIZE_UNIT_ERLANGS
Definition str_util.h:345
FORMAT_SIZE_UNIT_PACKETS_S
@ FORMAT_SIZE_UNIT_PACKETS_S
Definition str_util.h:340
FORMAT_SIZE_UNIT_BITS
@ FORMAT_SIZE_UNIT_BITS
Definition str_util.h:336
ascii_strdown_inplace
WS_DLL_PUBLIC char * ascii_strdown_inplace(char *str)
In-place conversion of upper-case ASCII letters to lower-case.
Definition str_util.c:261
EBCDIC_to_ASCII1
WS_DLL_PUBLIC uint8_t EBCDIC_to_ASCII1(uint8_t c)
Convert a single EBCDIC-encoded byte to its ASCII equivalent.
Definition str_util.c:1440
format_text_chr
WS_DLL_PUBLIC char * format_text_chr(wmem_allocator_t *allocator, const char *string, size_t len, char chr)
Definition str_util.c:1270
ws_escape_csv
WS_DLL_PUBLIC char * ws_escape_csv(wmem_allocator_t *alloc, const char *string, bool add_quotes, char quote_char, bool double_quote, bool escape_whitespace)
Escape as in a number of CSV dialects.
Definition str_util.c:789
format_text_wsp
WS_DLL_PUBLIC char * format_text_wsp(wmem_allocator_t *allocator, const char *line, size_t len)
Definition str_util.c:1253
ws_xton
WS_DLL_PUBLIC int ws_xton(char ch)
Convert a hexadecimal character to its numeric value.
Definition str_util.c:236
isdigit_string
WS_DLL_PUBLIC bool isdigit_string(const char *str)
Check if an entire string consists of digits.
Definition str_util.c:330
ws_ascii_strcasestr
WS_DLL_PUBLIC const char * ws_ascii_strcasestr(const char *haystack, const char *needle)
Definition str_util.c:347
wmem_strsplit
WS_DLL_PUBLIC char ** wmem_strsplit(wmem_allocator_t *allocator, const char *src, const char *delimiter, int max_tokens)
Splits a string into a maximum of max_tokens pieces, using the given delimiter.
Definition str_util.c:161
hex_dump_buffer
WS_DLL_PUBLIC bool hex_dump_buffer(bool(*print_line)(void *, const char *), void *fp, const unsigned char *cp, unsigned length, hex_dump_enc encoding, unsigned ascii_option)
Generate a formatted hex dump of a byte buffer.
Definition str_util.c:1469
ws_strdup_underline
WS_DLL_PUBLIC char * ws_strdup_underline(wmem_allocator_t *allocator, long offset, size_t len)
Create a string of underscores for visual alignment or highlighting.
Definition str_util.c:812
format_text
WS_DLL_PUBLIC char * format_text(wmem_allocator_t *allocator, const char *string, size_t len)
Definition str_util.c:1216
format_char
WS_DLL_PUBLIC char * format_char(wmem_allocator_t *allocator, char c)
Definition str_util.c:1290
format_size_wmem
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:598
wmem_strjoinv
WS_DLL_PUBLIC char * wmem_strjoinv(wmem_allocator_t *allocator, const char *separator, char **str_array) G_GNUC_MALLOC
Joins a number of strings together to form one long string, with the optional separator inserted betw...
Definition str_util.c:119
wmem_ascii_strdown
WS_DLL_PUBLIC char * wmem_ascii_strdown(wmem_allocator_t *allocator, const char *str, ssize_t len)
Converts all upper case ASCII letters to lower case ASCII letters.
Definition str_util.c:219
EBCDIC_to_ASCII
WS_DLL_PUBLIC void EBCDIC_to_ASCII(uint8_t *buf, unsigned bytes)
Convert a buffer of EBCDIC-encoded bytes to ASCII in-place.
Definition str_util.c:1427
wmem_strconcat
WS_DLL_PUBLIC char * wmem_strconcat(wmem_allocator_t *allocator, const char *first,...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED
Concatenate multiple strings into a single newly allocated string.
Definition str_util.c:48
printable_char_or_period
WS_DLL_PUBLIC char printable_char_or_period(char c)
Return a printable character or '.' if non-printable.
Definition str_util.c:665
ws_escape_null
WS_DLL_PUBLIC char * ws_escape_null(wmem_allocator_t *alloc, const char *string, size_t len, bool add_quotes)
Escape null bytes in a string for safe display or logging.
Definition str_util.c:781
ws_escape_string
WS_DLL_PUBLIC char * ws_escape_string(wmem_allocator_t *alloc, const char *string, bool add_quotes)
Escape a null-terminated string for safe display or output.
Definition str_util.c:776
_wmem_allocator_t
Internal memory allocator interface used by the wmem subsystem.
Definition wmem_allocator.h:34
wmem.h