diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-07-12 21:36:48 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-07-12 21:37:29 +0200 |
commit | 535aaf7e3c4145df815916e1449818d52f357987 (patch) | |
tree | 36ecc9624845880f8c8de5e798df63c0058273ea /ssh/string_view.h | |
parent | e539ab7a082854892c8f7722d2ec5b6b14d3cf24 (diff) |
Add tomsg client lib for C
Diffstat (limited to 'ssh/string_view.h')
-rw-r--r-- | ssh/string_view.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/ssh/string_view.h b/ssh/string_view.h new file mode 100644 index 0000000..659dad4 --- /dev/null +++ b/ssh/string_view.h @@ -0,0 +1,35 @@ +#pragma once + +#include <stddef.h> +#include <stdbool.h> +#include <stdint.h> + + +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); |