aboutsummaryrefslogtreecommitdiff
path: root/ssh/string_view.h
diff options
context:
space:
mode:
Diffstat (limited to 'ssh/string_view.h')
-rw-r--r--ssh/string_view.h35
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);