Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
str_util.h
Go to the documentation of this file.
1
10
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
18extern "C" {
19#endif /* __cplusplus */
20
34WS_DLL_PUBLIC
35char *
36wmem_strconcat(wmem_allocator_t *allocator, const char *first, ...)
37G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
38
52WS_DLL_PUBLIC
53char *
54wmem_strjoin(wmem_allocator_t *allocator,
55 const char *separator, const char *first, ...)
56G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
57
58
73WS_DLL_PUBLIC
74char *
75wmem_strjoinv(wmem_allocator_t *allocator,
76 const char *separator, char **str_array)
77G_GNUC_MALLOC;
78
92WS_DLL_PUBLIC
93char **
94wmem_strsplit(wmem_allocator_t *allocator, const char *src,
95 const char *delimiter, int max_tokens);
96
111WS_DLL_PUBLIC
112char*
113wmem_ascii_strdown(wmem_allocator_t *allocator, const char *str, ssize_t len);
114
133WS_DLL_PUBLIC
134char *ascii_strdown_inplace(char *str);
135
154WS_DLL_PUBLIC
155char *ascii_strup_inplace(char *str);
156
163WS_DLL_PUBLIC
164bool isprint_string(const char *str);
165
192WS_DLL_PUBLIC
193bool isprint_utf8_string(const char *str, const unsigned length);
194
201WS_DLL_PUBLIC
202bool 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
241WS_DLL_PUBLIC
242char *ws_strchrnul(const char *str, int ch);
243
256WS_DLL_PUBLIC
257char *ws_escape_string(wmem_allocator_t *alloc, const char *string, bool add_quotes);
258
271WS_DLL_PUBLIC
272char *ws_escape_string_len(wmem_allocator_t *alloc, const char *string, ssize_t len, bool add_quotes);
273
290WS_DLL_PUBLIC
291char *ws_escape_null(wmem_allocator_t *alloc, const char *string, size_t len, bool add_quotes);
292
313WS_DLL_PUBLIC
314char *ws_escape_csv(wmem_allocator_t *alloc, const char *string, bool add_quotes, char quote_char, bool double_quote, bool escape_whitespace);
315
331WS_DLL_PUBLIC
332wmem_strbuf_t *ws_unescape_string_len(wmem_allocator_t *alloc, const uint8_t *string, ssize_t len, GError **err);
333
350WS_DLL_PUBLIC
351bool ws_csv_value_is_formula(const char *string);
352
362WS_DLL_PUBLIC
363int ws_xton(char ch);
364
375typedef enum {
377 /* XXX - This does not append a trailing space if there is no prefix.
378 * That's good if you intend to list the unit somewhere else, e.g. in a
379 * legend, header, or other column, but doesn't work well if intending
380 * to append your own unit. You can test whether there's a prefix or
381 * not with g_ascii_isdigit() (plus special handling for inf and NaN).
382 */
395
396#define FORMAT_SIZE_PREFIX_SI (1 << 0)
397#define FORMAT_SIZE_PREFIX_IEC (1 << 1)
398
415WS_DLL_PUBLIC
416char *format_units(wmem_allocator_t *allocator, double size,
417 format_size_units_e unit, uint16_t flags,
418 int precision);
419
431WS_DLL_PUBLIC
432char *format_size_wmem(wmem_allocator_t *allocator, int64_t size,
433 format_size_units_e unit, uint16_t flags);
434
445#define format_size(size, unit, flags) \
446 format_size_wmem(NULL, size, unit, flags)
447
457WS_DLL_PUBLIC
458char printable_char_or_period(char c);
459
473WS_DLL_PUBLIC WS_RETNONNULL
474const char *ws_strerrorname_r(int errnum, char *buf, size_t buf_size);
475
489WS_DLL_PUBLIC
490char *ws_strdup_underline(wmem_allocator_t *allocator, long offset, size_t len);
491
517WS_DLL_PUBLIC
518char *format_text(wmem_allocator_t* allocator, const char *string, size_t len);
519
528WS_DLL_PUBLIC
529char *format_text_string(wmem_allocator_t* allocator, const char *string);
530
542WS_DLL_PUBLIC
543char *format_text_wsp(wmem_allocator_t* allocator, const char *line, size_t len);
544
563WS_DLL_PUBLIC
564char *format_text_chr(wmem_allocator_t *allocator,
565 const char *string, size_t len, char chr);
566
582WS_DLL_PUBLIC
583char *format_char(wmem_allocator_t *allocator, char c);
584
605WS_DLL_PUBLIC
606char* ws_utf8_truncate(char *string, size_t len);
607
617WS_DLL_PUBLIC
618void EBCDIC_to_ASCII(uint8_t *buf, unsigned bytes);
619
626WS_DLL_PUBLIC
627uint8_t EBCDIC_to_ASCII1(uint8_t c);
628
640
641/*
642 * Hexdump options for ASCII:
643 */
644
648#define HEXDUMP_ASCII_MASK (0x0003U)
649
656#define HEXDUMP_ASCII_OPTION(option) ((option) & HEXDUMP_ASCII_MASK)
657
664#define HEXDUMP_ASCII_INCLUDE (0x0000U)
665
671#define HEXDUMP_ASCII_DELIMIT (0x0001U)
672
678#define HEXDUMP_ASCII_EXCLUDE (0x0002U)
679
698WS_DLL_PUBLIC
699bool hex_dump_buffer(bool (*print_line)(void *, const char *), void *fp,
700 const unsigned char *cp, unsigned length,
701 hex_dump_enc encoding,
702 unsigned ascii_option);
703
714#define plurality(d,s,p) ((d) == 1 ? (s) : (p))
715
722#define true_or_false(val) ((val) ? "TRUE" : "FALSE")
723
730#define string_or_null(val) ((val) ? (val) : "[NULL]")
731
732#ifdef __cplusplus
733}
734#endif /* __cplusplus */
735
736#endif /* __STR_UTIL_H__ */
struct _wmem_allocator_t wmem_allocator_t
Definition wmem_core.h:44
WS_DLL_PUBLIC char * format_text_string(wmem_allocator_t *allocator, const char *string)
Definition str_util.c:1524
WS_DLL_PUBLIC char * ws_utf8_truncate(char *string, size_t len)
Definition str_util.c:1601
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:1058
hex_dump_enc
Character encoding types supported by hex dump formatting.
Definition str_util.h:636
@ HEXDUMP_ENC_EBCDIC
Definition str_util.h:638
@ HEXDUMP_ENC_ASCII
Definition str_util.h:637
format_size_units_e
Unit types used by format_size_wmem() for formatting size values.
Definition str_util.h:375
@ FORMAT_SIZE_UNIT_BITS_S
Definition str_util.h:385
@ FORMAT_SIZE_UNIT_EVENTS
Definition str_util.h:389
@ FORMAT_SIZE_UNIT_BYTES
Definition str_util.h:383
@ FORMAT_SIZE_UNIT_PACKETS
Definition str_util.h:387
@ FORMAT_SIZE_UNIT_BYTES_S
Definition str_util.h:386
@ FORMAT_SIZE_UNIT_SECONDS
Definition str_util.h:392
@ FORMAT_SIZE_UNIT_NONE
Definition str_util.h:376
@ FORMAT_SIZE_UNIT_FIELDS
Definition str_util.h:391
@ FORMAT_SIZE_UNIT_EVENTS_S
Definition str_util.h:390
@ FORMAT_SIZE_UNIT_ERLANGS
Definition str_util.h:393
@ FORMAT_SIZE_UNIT_PACKETS_S
Definition str_util.h:388
@ FORMAT_SIZE_UNIT_BITS
Definition str_util.h:384
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:1723
WS_DLL_PUBLIC char * format_text_chr(wmem_allocator_t *allocator, const char *string, size_t len, char chr)
Definition str_util.c:1553
WS_DLL_PUBLIC char * format_text_wsp(wmem_allocator_t *allocator, const char *line, size_t len)
Definition str_util.c:1536
WS_DLL_PUBLIC char * format_units(wmem_allocator_t *allocator, double size, format_size_units_e unit, uint16_t flags, int precision)
Definition str_util.c:486
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:1752
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:1072
WS_DLL_PUBLIC char * format_text(wmem_allocator_t *allocator, const char *string, size_t len)
Definition str_util.c:1499
WS_DLL_PUBLIC char * format_char(wmem_allocator_t *allocator, char c)
Definition str_util.c:1573
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:631
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:1710
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:49
WS_DLL_PUBLIC char printable_char_or_period(char c)
Return a printable character or '.' if non-printable.
Definition str_util.c:698