str.h (1469B)
1 #pragma once 2 3 #include <stdarg.h> 4 #include <stdbool.h> 5 6 #include "def.h" 7 8 /* TODO: Don't delete this module, as was originally planned. Instead, rename 9 * it to "zstr.h" (for zero-terminated string) and rename "string.h" to 10 * "rstr.h". Then both modules should provide approximately the same operations 11 * for their respective string representations. */ 12 13 char *r_str_dup(char *s); 14 char *r_str_edup(char *s); 15 16 char *r_str_cat(char *buf, usize len, ...); 17 char *r_str_ecat(char *buf, usize len, ...); 18 19 bool r_str_starts_with(char *s, char *sub); 20 bool r_str_ends_with(char *s, char *sub); 21 22 /* Return the number of the nonoverlapping occurences of sub in s. */ 23 usize r_str_count(char *s, char *sub); 24 25 /* Split s into substrings separated by sep (which must be nonempty) and return 26 * the number of separated substrings found. If n > 0, then fields must point 27 * to an array of at least n strings; in this case, place at most n substrings 28 * in fields, with the last substring being the unsplit remainder. Otherwise, 29 * set *fields to an allocated array containing every separated substring in s. 30 * If there is an allocation failure, set *fields to NULL and return 0. In 31 * either case, the elements of *fields are pointers into s, and s will be 32 * modified in order to null-terminate the substrings. */ 33 usize r_str_split(char ***fields, char *s, char *sep, usize n); 34 35 int r_vaprintf(char **s, const char *fmt, va_list args); 36 int r_aprintf(char **s, const char *fmt, ...);