32#define STR(__s) ((struct str) {.hd=__s, .length=sizeof(__s) - 1})
37struct str str(const char *fmt, ...);
97char *__str_to_string(
const struct str s);
180 struct str *: STR_EMPTY, \
181 struct list **: NULL, \
182 struct queue **: NULL \
190 struct str: __str_next, \
191 struct list *: __list_next, \
192 struct queue *: __queue_next \
200 struct str: __str_len, \
201 struct list *: __list_len, \
202 struct queue *: __queue_len \
210 struct str: __str_get, \
211 struct list *: __list_get, \
212 struct queue *: __queue_get \
220 struct str: __str_done, \
221 struct list *: __list_done, \
222 struct queue *: __queue_done \
228#define insert(iter, value) \
230 struct str: __str_insert, \
231 struct list *: __list_insert, \
232 struct queue *: __queue_insert \
238#define filter(iter, f) \
240 struct str: __str_filter, \
241 struct list **: __list_filter \
247#define map(iter, f) \
249 struct str: __str_map \
255#define split(iter, match, f) \
257 struct str: __str_split \
258 )((iter), (match), (f))
260char *dsnprintf(
size_t *n,
const char *fmt, ...);
bool __queue_insert(struct queue *q, struct str s)
Enqueue S in Q.
Definition pyc.c:438
struct str __str_map(struct str s, int f(int c))
Map each char C in S to new char F(C).
const struct str STR_EMPTY
Definition pyc.c:16
bool __str_insert(struct str s, char ch)
Appends char CH directly to S's buffer if IS_MUTABLE. Otherwise, return a copy of S.
Definition pyc.c:150
struct str __queue_get(struct queue *q)
Peek the front string of Q.
Definition pyc.c:414
bool __list_insert(struct list *ls, struct str s)
Appends S to the tail end of LS dynamically.
Definition pyc.c:326
struct str __str_slice(const struct str s, uint start, uint end)
Get back S[START:END] (end is exclusive index)
Definition pyc.c:253
bool __list_done(struct list *ls)
Cleanup dynamically allocated list LS. This does NOT free the str buffers from the nodes,...
Definition pyc.c:301
size_t __list_len(struct list *ls)
Compute number of element in list LS.
Definition pyc.c:274
struct str __str_next(struct str s)
Offset string S buffer pointer by 1.
Definition pyc.c:103
struct list * __list_filter(struct list **ls, bool f(struct str s, uint i))
Returns the filtered list head for all nodes that pass F and writes out the head of the reject list t...
Definition pyc.c:342
bool __str_done(struct str s)
Cleanup dynamically allocated string S.
Definition pyc.c:125
char * __str_get(struct str s)
Get the pointer to the backing byte buffer in S. This is optional for callers because you can just ac...
Definition pyc.c:121
struct str __queue_next(struct queue *q)
Pops the front string of Q.
Definition pyc.c:394
bool __queue_done(struct queue *q)
Cleanup dynamically allocated Q.
Definition pyc.c:422
struct str __list_get(struct list *ls)
Read underlying of node LS.
Definition pyc.c:294
struct str __str_filter(struct str s, bool f(int c, uint i))
For each char C at index I in S, include C in the returned S if F(C, I) = true.
Definition pyc.c:135
struct str * __str_split(struct str s, struct str m, size_t *n)
Split S against matches of M into N elements.
Definition pyc.c:174
size_t __str_len(struct str s)
Read S string length.
Definition pyc.c:117
struct list * __list_next(struct list *ls)
Get the next node in the list in LS, if it exists.
Definition pyc.c:267
#define hd(iter)
Get the underyling "value" of ITER.
Definition pyc.h:208
int min(int a, int b)
Get min of A, B, ...
Definition pyc.c:8
size_t __queue_len(struct queue *q)
Read size of Q;.
Definition pyc.c:405
struct str strn(char *hd, size_t length)
Move HD of length LENGTH into a struct str.
Definition pyc.c:99
int max(int a, int b)
max function
Definition pyc.c:12
Buffer pointer + length.
Definition pyc.h:24