vttp
An HTTP backed Virtual Table extension for SQLite
Loading...
Searching...
No Matches
pyc.h
Go to the documentation of this file.
1
5#pragma once
6#include <stdbool.h>
7#include <stdlib.h>
8
12int min(int a, int b);
13
17int max(int a, int b);
18
19/* STRING */
20
24struct str {
25 char *hd;
26 size_t length;
27};
28
32#define STR(__s) ((struct str) {.hd=__s, .length=sizeof(__s) - 1})
33
37struct str str(const char *fmt, ...);
38
42struct str strn(char *hd, size_t length);
43
47extern const struct str STR_EMPTY;
48
52struct str __str_next(struct str s);
53
60size_t __str_len(struct str s);
61
65char *__str_get(struct str s);
66
70bool __str_done(struct str s);
71
75bool __str_insert(struct str s, char ch);
76
80struct str __str_filter(struct str s, bool f (int c, uint i));
81
85struct str __str_map(struct str s, int f (int c));
86
90struct str *__str_split(struct str s, struct str m, size_t *n);
91
95struct str __str_slice(const struct str s, uint start, uint end);
96
97char *__str_to_string(const struct str s);
98
99/* LIST */
100
104struct list;
105
109struct list *__list_next(struct list *ls);
110
114size_t __list_len(struct list *ls);
115
119struct str __list_get(struct list *ls);
120
126bool __list_done(struct list *ls);
127
131bool __list_insert(struct list *ls, struct str s);
132
141struct list *__list_filter(struct list **ls, bool f (struct str s, uint i));
142
143/* QUEUE */
144
148struct queue;
149
153struct str __queue_next(struct queue *q);
154
158size_t __queue_len(struct queue *q);
159
163struct str __queue_get(struct queue *q);
164
168bool __queue_done(struct queue *q);
169
173bool __queue_insert(struct queue *q, struct str s);
174
178#define empty(T) \
179 _Generic((T *)0, \
180 struct str *: STR_EMPTY, \
181 struct list **: NULL, \
182 struct queue **: NULL \
183 )
184
188#define next(iter) \
189 _Generic((iter), \
190 struct str: __str_next, \
191 struct list *: __list_next, \
192 struct queue *: __queue_next \
193 )(iter)
194
198#define len(iter) \
199 _Generic((iter), \
200 struct str: __str_len, \
201 struct list *: __list_len, \
202 struct queue *: __queue_len \
203 )(iter)
204
208#define hd(iter) \
209 _Generic((iter), \
210 struct str: __str_get, \
211 struct list *: __list_get, \
212 struct queue *: __queue_get \
213 )(iter)
214
218#define done(iter) \
219 _Generic((iter), \
220 struct str: __str_done, \
221 struct list *: __list_done, \
222 struct queue *: __queue_done \
223 )(iter)
224
228#define insert(iter, value) \
229 _Generic((iter), \
230 struct str: __str_insert, \
231 struct list *: __list_insert, \
232 struct queue *: __queue_insert \
233 )((iter), (value))
234
238#define filter(iter, f) \
239 _Generic((iter), \
240 struct str: __str_filter, \
241 struct list **: __list_filter \
242 )((iter), (f))
243
247#define map(iter, f) \
248 _Generic((iter), \
249 struct str: __str_map \
250 )((iter), (f))
251
255#define split(iter, match, f) \
256 _Generic((iter), \
257 struct str: __str_split \
258 )((iter), (match), (f))
259
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