#include "mem/mem.c"
#include "str/str.c"
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE *f = fopen("data/pg2554.txt", "rb");
if (f == NULL) {
perror("data/pg2554.txt");
return EXIT_FAILURE;
}
fclose(f);
if (!ok) return EXIT_FAILURE;
size_t lines = 0, chapters = 0, mentions = 0;
lines++;
}
size_t at;
mentions++;
}
}
printf("%zu lines, %zu chapters, %zu mentions of Raskolnikov\n", lines,
chapters, mentions);
return EXIT_SUCCESS;
}
size_t len
Number of bytes in the view.
size_t sv_find(StrView v, StrView needle)
Index of the first needle in v.
#define SV(lit)
View of a string literal, with its length computed at compile time.
StrView str_view(const Str *s)
Borrow the whole of s.
#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.
void str_free(Str *s)
Free the buffer and reset s to the zero state.
bool str_append_file(Str *s, FILE *f)
Append everything left to read from f.
StrView sv_trim(StrView v)
v without leading and trailing ASCII whitespace: space, \t, \n, \v, \f and \r.
bool sv_starts_with(StrView v, StrView prefix)
True when v begins with prefix.
bool sv_split_next(StrView *rest, StrView sep, StrView *piece)
Cut the piece before sep off rest.
StrView sv_slice(StrView v, size_t from, size_t to)
Bytes from up to but not including to.
Owned, growable byte string.
Non-owning view of bytes; handy for passing slices and literals around.