Files
spp/include/spp.h
2026-04-08 19:39:59 -05:00

38 lines
1.2 KiB
C

#ifndef SPP_INCLUDED
#define SPP_INCLUDED
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
// Character sets as strings
#define WS "\t\n\v\f\r "
#define NUM "0123456789"
#define ALPHA "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define ALNUM "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
// Macros to check if a character belongs to a set
#define IS_WS(c) (strchr(WS, (c)) != NULL)
#define IS_DIGIT(c) (strchr(NUM, (c)) != NULL)
#define IS_ALPHA(c) (strchr(ALPHA, (c)) != NULL)
#define IS_ALNUM(c) (strchr(ALNUM, (c)) != NULL)
struct Stream {
const char **content;
};
typedef struct Stream Stream;
extern bool spp_is(struct Stream s, const char *list);
extern bool spp_eof(struct Stream s);
extern char spp_take(struct Stream s, const char *list);
extern uintptr_t spp_skip(struct Stream s, const char *list);
extern uintptr_t spp_until(struct Stream s, const char *list);
extern const char *spp_cursor(struct Stream s);
typedef bool (*parse)(struct Stream s, const char **start, ptrdiff_t *len);
extern uintptr_t spp_parse(struct Stream s, parse fn, const char *buf[], ptrdiff_t cnt[], uintptr_t cap );
#endif //spp.h