aboutsummaryrefslogtreecommitdiffstats
path: root/src/string_view.c
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-10-29 15:37:28 +0200
committerBad Diode <bd@badd10de.dev>2021-10-29 15:37:28 +0200
commite73a4c16a2269cdb2f5e7d66fb9839e4c44e14de (patch)
treec44721b005b7a0623e7acc7103ca8e21a25ff422 /src/string_view.c
parentfcc131afdd029c606ea39f3557bc3d33a075b1de (diff)
downloadbdl-e73a4c16a2269cdb2f5e7d66fb9839e4c44e14de.tar.gz
bdl-e73a4c16a2269cdb2f5e7d66fb9839e4c44e14de.zip
Prepare third compiler implementation
Diffstat (limited to 'src/string_view.c')
-rwxr-xr-xsrc/string_view.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/string_view.c b/src/string_view.c
new file mode 100755
index 0000000..8247bd4
--- /dev/null
+++ b/src/string_view.c
@@ -0,0 +1,40 @@
1#include "string_view.h"
2
3char
4sv_next(StringView *sv) {
5 if (sv->n == 0) {
6 return '\0';
7 }
8 char c = sv->start[0];
9 sv->start++;
10 sv->n--;
11 return c;
12}
13
14char
15sv_peek(const StringView *sv) {
16 if (sv->n == 0) {
17 return '\0';
18 }
19 return sv->start[0];
20}
21
22bool
23sv_equal(const StringView *a, const StringView *b) {
24 if (a->n != b->n) {
25 return false;
26 }
27 for (size_t i = 0; i < a->n; i++) {
28 if (a->start[i] != b->start[i]) {
29 return false;
30 }
31 }
32 return true;
33}
34
35void
36sv_write(const StringView *sv) {
37 for (size_t i = 0; i < sv->n; i++) {
38 putchar(sv->start[i]);
39 }
40}