aboutsummaryrefslogtreecommitdiff
path: root/ssh/string_view.h
blob: 659dad4873511a9075adc411d7de7990baaadbc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);