aboutsummaryrefslogtreecommitdiffstats
path: root/src/string_view.h
blob: cb0f48821fb48007cd08a26834fb220286faca81 (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
#ifndef BDL_STRINGVIEW_H
#define BDL_STRINGVIEW_H

#include "common.h"

typedef struct StringView {
    char *start;
    size_t n;
} StringView;

// Consume a character in the stream.
char sv_next(StringView *sv);

// Rewind a character in the stream.
void sv_rewind(StringView *sv);

// Check what is the current character in the stream.
char sv_peek(const StringView *sv);

// Compare if the arguments are the same.
bool sv_equal(const StringView *a, const StringView *b);

// Write a character to the given output stream.
void sv_write(const StringView *sv);

#define STRING(STR) (StringView){(STR), sizeof(STR) - 1}

#endif // BDL_STRINGVIEW_H