Rizin
unix-like reverse engineering framework and cli tools
rz_str.h
Go to the documentation of this file.
1 #ifndef RZ_STR_H
2 #define RZ_STR_H
3 
4 #include <wchar.h>
5 #include "rz_str_util.h"
6 #include "rz_list.h"
7 #include "rz_types.h"
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 typedef enum {
17 } RzStrType;
18 
19 typedef enum {
20  RZ_STRING_ENC_8BIT = 'b', // unknown 8bit encoding but with ASCII from 0 to 0x7f
22  RZ_STRING_ENC_MUTF8 = 'm', // modified utf8
34 } RzStrEnc;
35 
39 typedef struct {
41  bool esc_bslash;
43  bool dot_nl;
45 
59 #define rz_strf(buf, ...) ( \
60  snprintf(buf, sizeof(buf), __VA_ARGS__) < 0 \
61  ? rz_assert_log(RZ_LOGLVL_FATAL, "rz_strf error while using snprintf"), \
62  NULL \
63  : buf)
64 
65 typedef int (*RzStrRangeCallback)(void *, int);
66 
67 #define RZ_STR_ISEMPTY(x) (!(x) || !*(x))
68 #define RZ_STR_ISNOTEMPTY(x) ((x) && *(x))
69 #define RZ_STR_DUP(x) ((x) ? strdup((x)) : NULL)
70 #define rz_str_array(x, y) ((y >= 0 && y < (sizeof(x) / sizeof(*x))) ? x[y] : "")
71 RZ_API const char *rz_str_enc_as_string(RzStrEnc enc);
73 RZ_API char *rz_str_repeat(const char *ch, int sz);
74 RZ_API const char *rz_str_pad(const char ch, int len);
75 RZ_API const char *rz_str_rstr(const char *base, const char *p);
76 RZ_API const char *rz_strstr_ansi(const char *a, const char *b);
77 RZ_API const char *rz_str_rchr(const char *base, const char *p, int ch);
78 RZ_API const char *rz_str_closer_chr(const char *b, const char *s);
79 RZ_API int rz_str_bounds(const char *str, int *h);
80 RZ_API char *rz_str_crop(const char *str, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2);
81 RZ_API char *rz_str_scale(const char *r, int w, int h);
82 RZ_API bool rz_str_range_in(const char *r, ut64 addr);
83 RZ_API size_t rz_str_len_utf8(const char *s);
84 RZ_API size_t rz_str_len_utf8_ansi(const char *str);
85 RZ_API size_t rz_str_len_utf8char(const char *s, int left);
86 RZ_API size_t rz_str_utf8_charsize(const char *str);
87 RZ_API size_t rz_str_utf8_charsize_prev(const char *str, int prev_len);
88 RZ_API size_t rz_str_utf8_charsize_last(const char *str);
89 RZ_API void rz_str_filter_zeroline(char *str, int len);
90 RZ_API size_t rz_str_utf8_codepoint(const char *s, size_t left);
91 RZ_API bool rz_str_char_fullwidth(const char *s, size_t left);
92 RZ_API int rz_str_write(int fd, const char *b);
93 RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t n);
94 RZ_API void rz_str_sanitize(char *c);
95 RZ_API char *rz_str_sanitize_sdb_key(const char *s);
96 RZ_API const char *rz_str_casestr(const char *a, const char *b);
97 RZ_API const char *rz_str_firstbut(const char *s, char ch, const char *but);
98 RZ_API const char *rz_str_lastbut(const char *s, char ch, const char *but);
99 RZ_API size_t rz_str_split(char *str, char ch);
100 RZ_API RzList *rz_str_split_list(char *str, const char *c, int n);
102 RZ_API RzList *rz_str_split_duplist(const char *str, const char *c, bool trim);
103 RZ_API RzList *rz_str_split_duplist_n(const char *str, const char *c, int n, bool trim);
104 RZ_API RZ_OWN RzList *rz_str_split_duplist_n_regex(RZ_NONNULL const char *_str, RZ_NONNULL const char *r, int n, bool trim);
105 RZ_API size_t *rz_str_split_lines(char *str, size_t *count);
106 RZ_API char *rz_str_replace(char *str, const char *key, const char *val, int g);
107 RZ_API char *rz_str_replace_icase(char *str, const char *key, const char *val, int g, int keep_case);
108 RZ_API char *rz_str_replace_in(char *str, ut32 sz, const char *key, const char *val, int g);
109 #define rz_str_cpy(x, y) memmove((x), (y), strlen(y) + 1);
110 #define rz_str_cat(x, y) memmove((x) + strlen(x), (y), strlen(y) + 1);
111 RZ_API int rz_str_bits(char *strout, const ut8 *buf, int len, const char *bitz);
112 RZ_API int rz_str_bits64(char *strout, ut64 in);
113 RZ_API ut64 rz_str_bits_from_string(const char *buf, const char *bitz);
114 RZ_API int rz_str_rwx(const char *str);
115 RZ_API int rz_str_replace_ch(char *s, char a, char b, bool g);
116 RZ_API int rz_str_replace_char(char *s, int a, int b);
117 RZ_API int rz_str_replace_char_once(char *s, int a, int b);
118 RZ_API void rz_str_remove_char(char *str, char c);
119 RZ_API const char *rz_str_rwx_i(int rwx);
120 RZ_API int rz_str_fmtargs(const char *fmt);
121 RZ_API char *rz_str_arg_escape(const char *arg);
122 RZ_API int rz_str_arg_unescape(char *arg);
123 RZ_API char **rz_str_argv(const char *str, int *_argc);
124 RZ_API void rz_str_argv_free(char **argv);
125 RZ_API char *rz_str_new(const char *str);
126 RZ_API int rz_snprintf(char *string, int len, const char *fmt, ...) RZ_PRINTF_CHECK(3, 4);
128 RZ_API bool rz_str_is_ascii(const char *str);
130 RZ_API char *rz_str_nextword(char *s, char ch);
131 RZ_API bool rz_str_is_printable(const char *str);
134 RZ_API char *rz_str_appendlen(char *ptr, const char *string, int slen);
135 RZ_API char *rz_str_newf(const char *fmt, ...) RZ_PRINTF_CHECK(1, 2);
136 RZ_API char *rz_str_newlen(const char *str, int len);
137 RZ_API const char *rz_str_sysbits(const int v);
138 RZ_API char *rz_str_trunc_ellipsis(const char *str, int len);
139 RZ_API const char *rz_str_bool(int b);
140 RZ_API bool rz_str_is_true(const char *s);
141 RZ_API bool rz_str_is_false(const char *s);
142 RZ_API bool rz_str_is_bool(const char *val);
143 RZ_API const char *rz_str_ansi_chrn(const char *str, size_t n);
144 RZ_API size_t rz_str_ansi_len(const char *str);
145 RZ_API size_t rz_str_ansi_nlen(const char *str, size_t len);
146 RZ_API int rz_str_ansi_trim(char *str, int str_len, int n);
147 RZ_API int rz_str_ansi_filter(char *str, char **out, int **cposs, int len);
148 RZ_API char *rz_str_ansi_crop(const char *str, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2);
149 RZ_API int rz_str_word_count(const char *string);
150 RZ_API int rz_str_char_count(const char *string, char ch);
151 RZ_API char *rz_str_word_get0set(char *stra, int stralen, int idx, const char *newstr, int *newlen);
152 RZ_API int rz_str_word_set0(char *str);
155  return str + strlen(str) + 1;
156 }
157 RZ_API const char *rz_str_word_get0(const char *str, int idx);
158 RZ_API char *rz_str_word_get_first(const char *string);
160 RZ_API void rz_str_trim_char(RZ_NONNULL RZ_INOUT char *str, const char c);
161 RZ_API char *rz_str_trim_dup(const char *str);
162 RZ_API char *rz_str_trim_lines(char *str);
164 RZ_API void rz_str_trim_head_char(RZ_NONNULL RZ_INOUT char *str, const char c);
165 RZ_API const char *rz_str_trim_head_ro(const char *str);
166 RZ_API const char *rz_str_trim_head_wp(const char *str);
168 RZ_API void rz_str_trim_tail_char(RZ_NONNULL RZ_INOUT char *str, const char c);
169 RZ_API ut64 rz_str_djb2_hash(const char *str);
170 RZ_API char *rz_str_trim_nc(char *str);
171 RZ_API bool rz_str_is2utf8(RZ_NONNULL const char *c);
172 RZ_API bool rz_str_is3utf8(RZ_NONNULL const char *c);
173 RZ_API bool rz_str_is4utf8(RZ_NONNULL const char *c);
174 RZ_API bool rz_str_isXutf8(RZ_NONNULL const char *c, ut8 x);
175 RZ_API const char *rz_str_strchr(RZ_NONNULL const char *str, RZ_NONNULL const char *c);
176 RZ_API const char *rz_str_nstr(const char *from, const char *to, int size);
177 RZ_API const char *rz_str_lchr(const char *str, char chr);
178 RZ_API const char *rz_sub_str_lchr(const char *str, int start, int end, char chr);
179 RZ_API const char *rz_sub_str_rchr(const char *str, int start, int end, char chr);
180 RZ_API char *rz_str_ichr(char *str, char chr);
181 RZ_API bool rz_str_ccmp(const char *dst, const char *orig, int ch);
182 RZ_API bool rz_str_cmp_list(const char *list, const char *item, char sep);
183 RZ_API int rz_str_cmp(const char *dst, const char *orig, int len);
184 RZ_API int rz_str_casecmp(const char *dst, const char *orig);
185 RZ_API int rz_str_ncasecmp(const char *dst, const char *orig, size_t n);
186 RZ_API int rz_str_ccpy(char *dst, char *orig, int ch);
187 static inline const char *rz_str_get(const char *str) {
188  return str ? str : "";
189 }
190 static inline const char *rz_str_get_null(const char *str) {
191  return str ? str : "(null)";
192 }
193 RZ_API char *rz_str_ndup(RZ_NULLABLE const char *ptr, int len);
194 RZ_API char *rz_str_dup(char *ptr, const char *string);
195 RZ_API int rz_str_delta(char *p, char a, char b);
196 RZ_API void rz_str_filter(char *str);
197 RZ_API const char *rz_str_tok(const char *str1, const char b, size_t len);
198 RZ_API wchar_t *rz_str_mb_to_wc(const char *buf);
199 RZ_API char *rz_str_wc_to_mb(const wchar_t *buf);
200 RZ_API wchar_t *rz_str_mb_to_wc_l(const char *buf, int len);
201 RZ_API char *rz_str_wc_to_mb_l(const wchar_t *buf, int len);
202 RZ_API const char *rz_str_str_xy(const char *s, const char *word, const char *prev, int *x, int *y);
203 
204 typedef void (*str_operation)(char *c);
205 
206 RZ_API int rz_str_do_until_token(str_operation op, char *str, const char tok);
207 
208 RZ_API void rz_str_reverse(char *str);
209 RZ_API int rz_str_path_unescape(char *path);
210 RZ_API char *rz_str_path_escape(const char *path);
211 RZ_API int rz_str_unescape(char *buf);
212 RZ_API RZ_OWN char *rz_str_escape(RZ_NONNULL const char *buf);
213 RZ_API char *rz_str_escape_sh(const char *buf);
214 RZ_API char *rz_str_escape_dot(const char *buf);
215 RZ_API char *rz_str_escape_8bit(const char *buf, bool colors, RzStrEscOptions *opt);
216 RZ_API char *rz_str_escape_utf8(const char *buf, RzStrEscOptions *opt);
217 RZ_API char *rz_str_escape_utf8_keep_printable(const char *buf, RzStrEscOptions *opt); // like escape_utf8 but leaves valid \uXXXX chars directly in utf-8
218 RZ_API char *rz_str_escape_utf16le(const char *buf, int buf_size, RzStrEscOptions *opt);
219 RZ_API char *rz_str_escape_utf32le(const char *buf, int buf_size, RzStrEscOptions *opt);
220 RZ_API char *rz_str_escape_utf16be(const char *buf, int buf_size, RzStrEscOptions *opt);
221 RZ_API char *rz_str_escape_utf32be(const char *buf, int buf_size, RzStrEscOptions *opt);
222 RZ_API void rz_str_byte_escape(const char *p, char **dst, RzStrEscOptions *opt);
223 RZ_API char *rz_str_format_msvc_argv(size_t argc, const char **argv);
224 RZ_API void rz_str_uri_decode(char *buf);
225 RZ_API char *rz_str_uri_encode(const char *buf);
226 RZ_API char *rz_str_utf16_decode(const ut8 *s, int len);
227 RZ_API int rz_str_utf16_to_utf8(ut8 *dst, int len_dst, const ut8 *src, int len_src, bool little_endian);
228 RZ_API char *rz_str_utf16_encode(const char *s, int len);
229 RZ_API char *rz_str_escape_utf8_for_json(const char *s, int len);
230 RZ_API char *rz_str_escape_mutf8_for_json(const char *s, int len);
231 RZ_API char *rz_str_home(const char *str);
232 RZ_API size_t rz_str_nlen(const char *s, size_t n);
233 RZ_API size_t rz_str_nlen_w(const char *s, int n);
234 RZ_API size_t rz_wstr_clen(const char *s);
235 RZ_API char *rz_str_prepend(char *ptr, const char *string);
236 RZ_API char *rz_str_prefix_all(const char *s, const char *pfx);
237 RZ_API char *rz_str_append(char *ptr, const char *string);
238 RZ_API char *rz_str_append_owned(char *ptr, char *string);
239 RZ_API char *rz_str_appendf(char *ptr, const char *fmt, ...) RZ_PRINTF_CHECK(2, 3);
240 RZ_API char *rz_str_appendch(char *x, char y);
241 RZ_API void rz_str_case(char *str, bool up);
242 RZ_API void rz_str_trim_path(char *s);
243 RZ_API ut8 rz_str_contains_macro(const char *input_value);
244 RZ_API void rz_str_truncate_cmd(char *string);
245 RZ_API char *rz_str_replace_thunked(char *str, char *clean, int *thunk, int clen,
246  const char *key, const char *val, int g);
247 RZ_API bool rz_str_glob(const char *str, const char *glob);
248 RZ_API int rz_str_binstr2bin(const char *str, ut8 *out, int outlen);
249 RZ_API char *rz_str_between(const char *str, const char *prefix, const char *suffix);
250 RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle);
252 RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle);
254 RZ_API bool rz_str_isnumber(const char *str);
255 RZ_API const char *rz_str_last(const char *in, const char *ch);
256 RZ_API char *rz_str_highlight(char *str, const char *word, const char *color, const char *color_reset);
258 RZ_API void rz_str_stripLine(char *str, const char *key);
259 RZ_API char *rz_str_list_join(RzList *str, const char *sep);
260 RZ_API char *rz_str_array_join(const char **a, size_t n, const char *sep);
261 RZ_API RzList *rz_str_wrap(char *str, size_t width);
262 
263 RZ_API const char *rz_str_sep(const char *base, const char *sep);
264 RZ_API const char *rz_str_rsep(const char *base, const char *p, const char *sep);
265 RZ_API char *rz_str_version(const char *program);
266 
267 typedef struct rz_str_stringify_opt_t {
268  const ut8 *buffer;
272  bool escape_nl;
273  bool json;
274  bool stop_at_nil;
275  bool urlencode;
277 
280 
281 #ifdef __cplusplus
282 }
283 #endif
284 
285 #endif // RZ_STR_H
size_t len
Definition: 6502dis.c:15
lzma_index * src
Definition: index.h:567
ut16 val
Definition: armass64_const.h:6
static RASN1String * newstr(const char *string)
Definition: astr.c:23
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define RZ_API
#define r
Definition: crypto_rc6.c:12
#define w
Definition: crypto_rc6.c:13
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
Definition: sflib.h:133
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
static int buf_size
Definition: debug_qnx.c:35
uint32_t ut32
const char * v
Definition: dsignal.c:12
struct @667 g
void trim(string &s, string characters)
Definition: gen_manual.cpp:43
unsigned char suffix[65536]
Definition: gun.c:164
unsigned short prefix[65536]
Definition: gun.c:163
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
#define inline
Definition: ansidecl.h:243
#define const
Definition: ansidecl.h:240
static void list(RzEgg *egg)
Definition: rz-gg.c:52
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
char * dst
Definition: lz4.h:724
int x
Definition: mipsasm.c:20
int n
Definition: mipsasm.c:19
int idx
Definition: setup.py:197
struct @219 colors[]
static RzSocket * s
Definition: rtr.c:28
RZ_API int rz_str_utf16_to_utf8(ut8 *dst, int len_dst, const ut8 *src, int len_src, bool little_endian)
Definition: str.c:2884
RZ_API RzStrEnc rz_str_enc_string_as_type(RZ_NULLABLE const char *enc)
converts an encoding name to RzStrEnc
Definition: str.c:86
RZ_API void rz_str_byte_escape(const char *p, char **dst, RzStrEscOptions *opt)
Converts unprintable characters to C-like backslash representation.
Definition: str.c:1436
RZ_API void rz_str_truncate_cmd(char *string)
Definition: str.c:3089
RZ_API char * rz_str_uri_encode(const char *buf)
Definition: str.c:2860
RZ_API int rz_str_char_count(const char *string, char ch)
Definition: str.c:611
RZ_API char * rz_str_append_owned(char *ptr, char *string)
Definition: str.c:1050
RZ_API char * rz_str_escape_dot(const char *buf)
Definition: str.c:1587
RZ_API void rz_str_trim_char(RZ_NONNULL RZ_INOUT char *str, const char c)
Removes the character c from the beginning and end of a string.
Definition: str_trim.c:179
RZ_API char * rz_str_trim_lines(char *str)
Definition: str_trim.c:60
RZ_API bool rz_str_is_false(const char *s)
Definition: str.c:3904
RZ_API const char * rz_str_lchr(const char *str, char chr)
Definition: str.c:669
RZ_API ut8 rz_str_contains_macro(const char *input_value)
Definition: str.c:3076
RZ_API char * rz_str_between(const char *str, const char *prefix, const char *suffix)
Definition: str.c:3264
RZ_API bool rz_str_char_fullwidth(const char *s, size_t left)
Definition: str.c:2277
RZ_API void rz_str_trim_head_char(RZ_NONNULL RZ_INOUT char *str, const char c)
Removes the the character c from the beginning of a string.
Definition: str_trim.c:144
RZ_API char * rz_str_crop(const char *str, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2)
Definition: str.c:3157
RZ_API const char * rz_str_rwx_i(int rwx)
Definition: str.c:332
RZ_API bool rz_str_range_in(const char *r, ut64 addr)
Definition: str.c:2807
RZ_API const char * rz_str_str_xy(const char *s, const char *word, const char *prev, int *x, int *y)
Definition: str.c:3964
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API size_t rz_str_utf8_charsize_prev(const char *str, int prev_len)
Definition: str.c:2317
RZ_API RZ_OWN RzList * rz_str_split_duplist_n_regex(RZ_NONNULL const char *_str, RZ_NONNULL const char *r, int n, bool trim)
Split the string str according to the regex r and returns a RzList with the result.
Definition: str.c:3506
RZ_API ut64 rz_str_bits_from_string(const char *buf, const char *bitz)
Definition: str.c:266
RZ_API int rz_str_casecmp(const char *dst, const char *orig)
Definition: str.c:121
RZ_API char * rz_str_replace_icase(char *str, const char *key, const char *val, int g, int keep_case)
Definition: str.c:1160
RZ_API bool rz_str_cmp_list(const char *list, const char *item, char sep)
Definition: str.c:953
RZ_API char * rz_str_repeat(const char *ch, int sz)
Definition: str.c:3249
static const char * rz_str_get(const char *str)
Definition: rz_str.h:187
RZ_API bool rz_str_is4utf8(RZ_NONNULL const char *c)
Checks if the given character string is a four byte UTF-8 character.
Definition: str.c:731
RZ_API size_t rz_str_utf8_charsize_last(const char *str)
Definition: str.c:2335
RZ_API const char * rz_str_sep(const char *base, const char *sep)
Definition: str.c:788
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_append(char *ptr, const char *string)
Definition: str.c:1063
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
RZ_API char * rz_str_escape_utf16be(const char *buf, int buf_size, RzStrEscOptions *opt)
Definition: str.c:1715
RZ_API bool rz_str_is_true(const char *s)
Definition: str.c:3900
RZ_API RZ_OWN char * rz_str_escape(RZ_NONNULL const char *buf)
Definition: str.c:1550
RZ_API int rz_str_word_set0_stack(char *str)
Definition: str.c:471
RZ_API char * rz_str_sanitize_sdb_key(const char *s)
Definition: str.c:1405
RZ_API ut64 rz_str_djb2_hash(const char *str)
Definition: str.c:383
RZ_API char * rz_str_new(const char *str)
Definition: str.c:865
RZ_API int rz_str_rwx(const char *str)
Definition: str.c:318
RZ_API char * rz_str_replace_in(char *str, ut32 sz, const char *key, const char *val, int g)
Definition: str.c:1288
RZ_API char RZ_API char * rz_str_newlen(const char *str, int len)
Definition: str.c:871
RZ_API RZ_BORROW char * rz_str_trim_tail(RZ_NONNULL char *str)
Removes whitespace characters (space, tab, newline etc.) from the end of a string and replaces them w...
Definition: str_trim.c:125
RzStrType
Definition: rz_str.h:13
@ RZ_STRING_TYPE_ZERO
C-style strings (ASCII or UTF-8) with zero as the end marker.
Definition: rz_str.h:15
@ RZ_STRING_TYPE_SIZED
Pascal-style strings with the first byte marking the size of the string.
Definition: rz_str.h:16
@ RZ_STRING_TYPE_RAW
The raw sequence of bytes without any marker of beginning or end.
Definition: rz_str.h:14
RZ_API size_t rz_str_ansi_len(const char *str)
Definition: str.c:1945
RZ_API char * rz_str_escape_utf8_keep_printable(const char *buf, RzStrEscOptions *opt)
Definition: str.c:1703
RZ_API int rz_str_arg_unescape(char *arg)
Definition: str.c:2443
RZ_API const char * rz_str_trim_head_wp(const char *str)
Definition: str_trim.c:95
RZ_API char * rz_str_wc_to_mb_l(const wchar_t *buf, int len)
Definition: str.c:3750
RZ_API int RZ_API bool rz_str_is_whitespace(RZ_NONNULL const char *str)
Checks if the whole string is composed of whitespace.
Definition: str.c:2004
RZ_API void rz_str_stripLine(char *str, const char *key)
Definition: str.c:3814
RZ_API const char * rz_str_rchr(const char *base, const char *p, int ch)
Definition: str.c:829
RZ_API int rz_str_path_unescape(char *path)
Definition: str.c:2493
RZ_API int rz_str_fmtargs(const char *fmt)
Definition: str.c:3877
RZ_API const char * rz_str_bool(int b)
Definition: str.c:3896
RZ_API char * rz_str_scale(const char *r, int w, int h)
Definition: str.c:3921
RZ_API char * rz_str_appendlen(char *ptr, const char *string, int slen)
Definition: str.c:1043
RZ_API char * rz_str_ichr(char *str, char chr)
Definition: str.c:660
RZ_API int rz_str_word_count(const char *string)
Definition: str.c:643
RZ_API int rz_str_ansi_filter(char *str, char **out, int **cposs, int len)
Definition: str.c:2124
RZ_API char * rz_str_dup(char *ptr, const char *string)
Definition: str.c:1021
RZ_API char * rz_str_trim_dup(const char *str)
Definition: str_trim.c:78
RZ_API char * rz_str_format_msvc_argv(size_t argc, const char **argv)
Definition: str.c:1844
RZ_API bool rz_str_is_utf8(RZ_NONNULL const char *str)
Returns true if the input string is correctly UTF-8-encoded.
Definition: str.c:2023
RZ_API void rz_str_case(char *str, bool up)
Definition: str.c:341
RZ_API int rz_str_ccpy(char *dst, char *orig, int ch)
Definition: str.c:991
RZ_API const char * rz_str_enc_as_string(RzStrEnc enc)
Definition: str.c:44
RZ_API void rz_str_trim_head(RZ_NONNULL char *str)
Removes whitespace characters (space, tab, newline etc.) from the end of a string....
Definition: str_trim.c:110
RZ_API RZ_OWN RzList * rz_str_split_list_regex(RZ_NONNULL char *str, RZ_NONNULL const char *r, int n)
Split the string str according to the regex r and returns a RzList with the result.
Definition: str.c:3445
RZ_API const char * rz_str_ansi_chrn(const char *str, size_t n)
Definition: str.c:2098
RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t n)
Secure string copy with null terminator.
Definition: str.c:923
RZ_API int rz_str_binstr2bin(const char *str, ut8 *out, int outlen)
Definition: str.c:284
RZ_API char * rz_str_wc_to_mb(const wchar_t *buf)
Definition: str.c:3777
RZ_API bool rz_str_startswith_icase(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case insensitive)
Definition: str.c:3301
static const char * rz_str_get_null(const char *str)
Definition: rz_str.h:190
RZ_API int rz_snprintf(char *string, int len, const char *fmt,...) RZ_PRINTF_CHECK(3
RZ_API size_t rz_str_utf8_codepoint(const char *s, size_t left)
Definition: str.c:2264
RZ_API char * rz_str_array_join(const char **a, size_t n, const char *sep)
Definition: str.c:3861
RZ_API void rz_str_trim_tail_char(RZ_NONNULL RZ_INOUT char *str, const char c)
Removes the the character c from the end of a string.
Definition: str_trim.c:161
RZ_API int rz_str_do_until_token(str_operation op, char *str, const char tok)
Definition: str.c:3219
RZ_API char * rz_str_home(const char *str)
Definition: str.c:354
RZ_API const char * rz_str_rstr(const char *base, const char *p)
Definition: str.c:814
RZ_API int rz_str_replace_char_once(char *s, int a, int b)
Definition: str.c:165
RZ_API size_t rz_str_ansi_nlen(const char *str, size_t len)
Definition: str.c:1923
RZ_API char * rz_str_utf16_encode(const char *s, int len)
Definition: str.c:2993
RZ_API char * rz_str_escape_mutf8_for_json(const char *s, int len)
Definition: str.c:1838
RZ_API RzList * rz_str_split_duplist(const char *str, const char *c, bool trim)
Split the string str according to the substring c and returns a RzList with the result.
Definition: str.c:3464
RZ_API int rz_str_bits64(char *strout, ut64 in)
Definition: str.c:244
RZ_API char * rz_str_escape_utf32le(const char *buf, int buf_size, RzStrEscOptions *opt)
Definition: str.c:1711
RZ_API bool rz_str_is_printable_limited(const char *str, int size)
Definition: str.c:2053
RZ_API bool rz_str_glob(const char *str, const char *glob)
Definition: str.c:2368
RzStrEnc
Definition: rz_str.h:19
@ RZ_STRING_ENC_UTF32LE
Definition: rz_str.h:24
@ RZ_STRING_ENC_8BIT
Definition: rz_str.h:20
@ RZ_STRING_ENC_BASE64
Definition: rz_str.h:27
@ RZ_STRING_ENC_EBCDIC_US
Definition: rz_str.h:31
@ RZ_STRING_ENC_MUTF8
Definition: rz_str.h:22
@ RZ_STRING_ENC_UTF32BE
Definition: rz_str.h:26
@ RZ_STRING_ENC_UTF8
Definition: rz_str.h:21
@ RZ_STRING_ENC_GUESS
Definition: rz_str.h:33
@ RZ_STRING_ENC_UTF16LE
Definition: rz_str.h:23
@ RZ_STRING_ENC_UTF16BE
Definition: rz_str.h:25
@ RZ_STRING_ENC_EBCDIC_UK
Definition: rz_str.h:30
@ RZ_STRING_ENC_IBM037
Definition: rz_str.h:28
@ RZ_STRING_ENC_IBM290
Definition: rz_str.h:29
@ RZ_STRING_ENC_EBCDIC_ES
Definition: rz_str.h:32
RZ_API const char * rz_str_last(const char *in, const char *ch)
Definition: str.c:3565
RZ_API int rz_str_delta(char *p, char a, char b)
Definition: str.c:394
RZ_API void rz_str_filter(char *str)
Convert all non-printable characters in str with '.'.
Definition: str.c:2359
RZ_API int rz_str_ansi_trim(char *str, int str_len, int n)
Definition: str_trim.c:204
RZ_API char * rz_str_prepend(char *ptr, const char *string)
Definition: str.c:1027
RZ_API RzList * rz_str_wrap(char *str, size_t width)
Definition: str.c:3996
RZ_API char RZ_API char * rz_str_appendch(char *x, char y)
Definition: str.c:1105
RZ_API char * rz_str_escape_8bit(const char *buf, bool colors, RzStrEscOptions *opt)
Definition: str.c:1595
RZ_API char * rz_str_escape_utf8(const char *buf, RzStrEscOptions *opt)
Definition: str.c:1699
RZ_API bool rz_str_isnumber(const char *str)
Definition: str.c:3550
RZ_API size_t rz_str_len_utf8(const char *s)
Definition: str.c:2709
RZ_API const char * rz_str_tok(const char *str1, const char b, size_t len)
Definition: str.c:3199
RZ_API int rz_str_bits(char *strout, const ut8 *buf, int len, const char *bitz)
Definition: str.c:195
RZ_API char * rz_str_prefix_all(const char *s, const char *pfx)
Definition: str.c:3038
RZ_API char * rz_str_ansi_crop(const char *str, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2)
Definition: str.c:2174
RZ_API bool rz_str_is2utf8(RZ_NONNULL const char *c)
Checks if the given character string is a two byte UTF-8 character.
Definition: str.c:703
RZ_API size_t rz_str_nlen(const char *s, size_t n)
Definition: str.c:1949
RZ_API char * rz_str_escape_utf8_for_json(const char *s, int len)
Definition: str.c:1834
RZ_API char * rz_str_utf16_decode(const ut8 *s, int len)
Definition: str.c:2961
struct rz_str_stringify_opt_t RzStrStringifyOpt
RZ_API const char * rz_str_nstr(const char *from, const char *to, int size)
Definition: str.c:842
RZ_API const char * rz_str_trim_head_ro(const char *str)
Definition: str_trim.c:86
RZ_API const char * rz_str_rsep(const char *base, const char *p, const char *sep)
Definition: str.c:801
RZ_API char * rz_str_replace_thunked(char *str, char *clean, int *thunk, int clen, const char *key, const char *val, int g)
Definition: str.c:1233
RZ_API size_t rz_wstr_clen(const char *s)
Definition: str.c:2087
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
Definition: str.c:1110
int(* RzStrRangeCallback)(void *, int)
Definition: rz_str.h:65
RZ_API int rz_str_replace_ch(char *s, char a, char b, bool g)
Definition: str.c:139
RZ_API const char * rz_sub_str_rchr(const char *str, int start, int end, char chr)
Definition: str.c:690
RZ_API bool rz_str_ccmp(const char *dst, const char *orig, int ch)
Definition: str.c:941
RZ_API char * rz_str_word_get_first(const char *string)
Definition: str.c:637
RZ_API bool rz_str_is_printable_incl_newlines(const char *str)
Definition: str.c:2069
RZ_API bool rz_str_is3utf8(RZ_NONNULL const char *c)
Checks if the given character string is a three byte UTF-8 character.
Definition: str.c:717
RZ_API size_t rz_str_nlen_w(const char *s, int n)
Definition: str.c:1966
RZ_API const char * rz_str_firstbut(const char *s, char ch, const char *but)
Definition: str.c:2644
RZ_API char * rz_str_escape_utf32be(const char *buf, int buf_size, RzStrEscOptions *opt)
Definition: str.c:1719
RZ_API const char * rz_str_strchr(RZ_NONNULL const char *str, RZ_NONNULL const char *c)
Returns a pointer to the first occurrence of UTF-8 character c in the string s.
Definition: str.c:768
RZ_API char ** rz_str_argv(const char *str, int *_argc)
Definition: str.c:2509
RZ_API bool rz_str_is_printable(const char *str)
Definition: str.c:2038
RZ_API char * rz_str_trunc_ellipsis(const char *str, int len)
Definition: str.c:883
RZ_API int rz_str_word_set0(char *str)
Definition: str.c:423
RZ_API char * rz_str_path_escape(const char *path)
Definition: str.c:2463
RZ_API bool rz_str_is_bool(const char *val)
Definition: str.c:3908
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
Definition: str_trim.c:190
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
Definition: str.c:3286
RZ_API char * rz_str_highlight(char *str, const char *word, const char *color, const char *color_reset)
Definition: str.c:3657
RZ_API bool rz_str_isXutf8(RZ_NONNULL const char *c, ut8 x)
Checks if the byte string matches the criteria of a UTF-8 character of length x.
Definition: str.c:745
RZ_API wchar_t * rz_str_mb_to_wc(const char *buf)
Definition: str.c:3784
RZ_API const char * rz_strstr_ansi(const char *a, const char *b)
Definition: str.c:2742
RZ_API char * rz_str_escape_utf16le(const char *buf, int buf_size, RzStrEscOptions *opt)
Definition: str.c:1707
RZ_API size_t rz_str_len_utf8char(const char *s, int left)
Definition: str.c:2697
RZ_API int rz_str_replace_char(char *s, int a, int b)
Definition: str.c:169
void(* str_operation)(char *c)
Definition: rz_str.h:204
RZ_API const char * rz_str_casestr(const char *a, const char *b)
Definition: str.c:2757
static const char * rz_str_word_get_next0(const char *str)
Definition: rz_str.h:154
RZ_API const char * rz_str_pad(const char ch, int len)
Definition: str.c:3236
RZ_API const char * rz_sub_str_lchr(const char *str, int start, int end, char chr)
Definition: str.c:682
RZ_API size_t rz_str_utf8_charsize(const char *str)
Definition: str.c:2298
RZ_API size_t rz_str_len_utf8_ansi(const char *str)
Definition: str.c:2723
RZ_API int rz_str_cmp(const char *dst, const char *orig, int len)
Definition: str.c:974
RZ_API size_t * rz_str_split_lines(char *str, size_t *count)
Split the string str in lines and returns the result in an array.
Definition: str.c:3526
RZ_API void rz_str_trim_path(char *s)
Definition: str_trim.c:15
RZ_API char * rz_str_version(const char *program)
Definition: str.c:4051
RZ_API char * rz_str_word_get0set(char *stra, int stralen, int idx, const char *newstr, int *newlen)
Definition: str.c:548
RZ_API RzStrEnc rz_str_guess_encoding_from_buffer(RZ_NONNULL const ut8 *buffer, ut32 length)
Tries to guess the string encoding method from the buffer.
Definition: str.c:4089
RZ_API RzList * rz_str_split_list(char *str, const char *c, int n)
Split the string str according to the substring c and returns a RzList with the result.
Definition: str.c:3429
RZ_API int rz_str_unescape(char *buf)
Definition: str.c:1300
RZ_API void rz_str_filter_zeroline(char *str, int len)
Definition: str.c:2341
RZ_API const char * rz_str_word_get0(const char *str, int idx)
Definition: str.c:598
RZ_API bool rz_str_is_ascii(const char *str)
Definition: str.c:1988
RZ_API void rz_str_remove_char(char *str, char c)
Definition: str.c:173
RZ_API const char * rz_str_lastbut(const char *s, char ch, const char *but)
Definition: str.c:2670
RZ_API int rz_str_ncasecmp(const char *dst, const char *orig, size_t n)
Definition: str.c:129
RZ_API bool rz_str_endswith_icase(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case insensitive)
Definition: str.c:3340
RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
Definition: str.c:3329
RZ_API int rz_str_bounds(const char *str, int *h)
Definition: str.c:3124
RZ_API char * rz_str_trim_nc(char *str)
Definition: str_trim.c:197
RZ_API wchar_t * rz_str_mb_to_wc_l(const char *buf, int len)
Definition: str.c:3722
RZ_API RzList * rz_str_split_duplist_n(const char *str, const char *c, int n, bool trim)
Split the string str according to the substring c and returns a RzList with the result.
Definition: str.c:3485
RZ_API void rz_str_argv_free(char **argv)
Definition: str.c:2633
RZ_API char * rz_str_list_join(RzList *str, const char *sep)
Definition: str.c:3849
RZ_API void rz_str_reverse(char *str)
Definition: str.c:183
RZ_API void rz_str_sanitize(char *c)
Definition: str.c:1381
RZ_API char * rz_str_nextword(char *s, char ch)
Definition: str.c:3912
RZ_API const char * rz_str_sysbits(const int v)
Definition: str.c:217
RZ_API void rz_str_uri_decode(char *buf)
Definition: str.c:2845
RZ_API char * rz_str_from_ut64(ut64 val)
Definition: str.c:3791
RZ_API const char * rz_str_closer_chr(const char *b, const char *s)
Definition: str.c:3111
RZ_API RZ_OWN char * rz_str_stringify_raw_buffer(RzStrStringifyOpt *option, RZ_NULLABLE RZ_OUT ut32 *length)
Converts a raw buffer to a printable string based on the selected options.
Definition: str.c:4141
RZ_API size_t rz_str_split(char *str, char ch)
Split string str in place by using ch as a delimiter.
Definition: str.c:406
RZ_API int rz_str_write(int fd, const char *b)
Definition: str.c:2775
RZ_API char * rz_str_arg_escape(const char *arg)
Definition: str.c:2413
RZ_API char * rz_str_escape_sh(const char *buf)
Definition: str.c:1560
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_OUT
Definition: rz_types.h:51
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_PRINTF_CHECK(fmt, dots)
Definition: rz_types.h:192
#define RZ_INOUT
Definition: rz_types.h:52
#define RZ_BORROW
Definition: rz_types.h:63
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125
static int
Definition: sfsocketcall.h:114
#define b(i)
Definition: sha256.c:42
#define c(i)
Definition: sha256.c:43
#define a(i)
Definition: sha256.c:41
#define h(i)
Definition: sha256.c:48
Group together some common options used by string escaping functions.
Definition: rz_str.h:39
bool esc_bslash
When true, backslashes \ are quoted with \\
Definition: rz_str.h:41
bool show_asciidot
When true, dots . are placed instead of unprintable characters.
Definition: rz_str.h:40
bool esc_double_quotes
When true, double quotes "</tt> are quoted with <tt>\\"
Definition: rz_str.h:42
bool dot_nl
When true, is converted into the graphiz-compatible newline \l.
Definition: rz_str.h:43
Definition: buffer.h:15
Definition: getopt.h:84
bool urlencode
Encodes the output following RFC 3986.
Definition: rz_str.h:275
bool escape_nl
When enabled escapes new lines ( ).
Definition: rz_str.h:272
bool stop_at_nil
When enabled stops printing when '\0' is found.
Definition: rz_str.h:274
bool json
Encodes the output as a JSON string.
Definition: rz_str.h:273
ut32 wrap_at
Adds a new line the output when it exeeds this value.
Definition: rz_str.h:271
const ut8 * buffer
String buffer (cannot be NULL).
Definition: rz_str.h:268
RzStrEnc encoding
String encoding type (cannot be RZ_STRING_ENC_GUESS)
Definition: rz_str.h:270
ut32 length
String buffer length.
Definition: rz_str.h:269
int width
Definition: main.c:10
Definition: dis.c:32
static int color
Definition: visual.c:20
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
Definition: z80_tab.h:997
static int addr
Definition: z80asm.c:58