From 535aaf7e3c4145df815916e1449818d52f357987 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 12 Jul 2020 21:36:48 +0200 Subject: Add tomsg client lib for C --- ssh/string_view.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ssh/string_view.h (limited to 'ssh/string_view.h') 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 +#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); -- cgit v1.2.3-54-g00ecf