Initial commit
This commit is contained in:
34
tests/01_basic_example.c
Normal file
34
tests/01_basic_example.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "../include/spp.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
bool parse_word(struct Stream s, const char **start, ptrdiff_t *len) {
|
||||
spp_skip(s, WS);
|
||||
|
||||
const char *begin = spp_cursor(s);
|
||||
uintptr_t l = spp_skip(s, ALNUM);
|
||||
|
||||
if (l == 0)
|
||||
return false;
|
||||
|
||||
*start = begin;
|
||||
*len = (ptrdiff_t)l;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
const char *input = "hello world 123 test";
|
||||
struct Stream s = { &input };
|
||||
|
||||
const char *buf[16];
|
||||
ptrdiff_t len[16];
|
||||
|
||||
uintptr_t n = spp_parse(s, parse_word, buf, len, 16);
|
||||
|
||||
for (uintptr_t i = 0; i < n; i++) {
|
||||
printf("Token: %.*s\n", (int)len[i], buf[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user