#include "mem/mem.c"
#include "str/str.c"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
StrView header =
SV(
" Title: Crime and Punishment\r\n");
printf(
"%%s on key prints [%s]\n", key.
data);
}
if (at !=
SV_NPOS) printf(
"Punishment starts at byte %zu\n", at);
for (int i = 1; i < argc; i++) {
if (
str_eq(arg,
SV(
"--verbose"))) puts(
"verbose on");
}
return EXIT_SUCCESS;
}
size_t len
Number of bytes in the view.
const char * data
First byte.
size_t sv_find(StrView v, StrView needle)
Index of the first needle in v.
StrView sv_from_cstr(const char *cstr)
View of cstr, measured with strlen.
#define SV(lit)
View of a string literal, with its length computed at compile time.
#define STR_FMT(s)
printf helper: printf("%.*s", STR_FMT(s)) prints exactly len bytes.
#define SV_NPOS
Returned by the find functions when there is no match.
StrView sv_trim(StrView v)
v without leading and trailing ASCII whitespace: space, \t, \n, \v, \f and \r.
bool sv_ends_with(StrView v, StrView suffix)
True when v ends with suffix.
bool sv_starts_with(StrView v, StrView prefix)
True when v begins with prefix.
bool str_eq(StrView a, StrView b)
True when a and b hold the same bytes.
StrView sv_slice(StrView v, size_t from, size_t to)
Bytes from up to but not including to.
size_t sv_find_byte(StrView v, char c)
Index of the first c in v.
Non-owning view of bytes; handy for passing slices and literals around.