Files
spp/tests/01_basic_example.c
2026-04-08 19:39:59 -05:00

35 lines
663 B
C

#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;
}