#pragma once #include #include #include struct string_view { const char *s; // if NULL, len must be 0 size_t len; }; struct string_view string_view(const char *s, size_t len); bool sv_equals(const struct string_view s, const char *cmp); bool sv_is_empty(const struct string_view s); // If 's' is not NULL, writes a newly allocated copy to *output and returns // true. Otherwise, stores NULL in *output and returns false. bool sv_copy(const struct string_view s, char **output); // If 's' is not NULL and fully parses as a decimal integer, writes that // integer to *output and returns true. Otherwise, returns false. bool sv_parse_i64(const struct string_view s, int64_t *output); // Returns the word starting at the beginning of 'line', and modifies 'line' to // point to the start of the next word. If there is no next word, sets line to // NULL. // If 'line' is empty or NULL, returns NULL. struct string_view sv_tokenise_word(struct string_view *line); // Skips all isspace() at the beginning of the string void sv_skip_whitespace(struct string_view *line); // Skips the given number of characters void sv_skip(struct string_view *line, size_t num);