diff options
author | Nicholas <nbnoll@eml.cc> | 2021-11-12 09:22:01 -0800 |
---|---|---|
committer | Nicholas <nbnoll@eml.cc> | 2021-11-12 09:22:01 -0800 |
commit | ce05175372a9ddca1a225db0765ace1127a39293 (patch) | |
tree | 5988b4d4f6b402e4953945886fc90aae11203df6 /src/base/bufio/dump.c | |
parent | b375f3cdedb5b0e08745d100b40e38d2f8396a58 (diff) |
chore: simplified organizational structurelaptop
Diffstat (limited to 'src/base/bufio/dump.c')
-rw-r--r-- | src/base/bufio/dump.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/base/bufio/dump.c b/src/base/bufio/dump.c new file mode 100644 index 0000000..0b527e2 --- /dev/null +++ b/src/base/bufio/dump.c @@ -0,0 +1,66 @@ +// ----------------------------------------------------------------------- +// reader + +#if 0 +rune +bufio·getrune(io·Buffer *buf) +{ + ubyte b; + int i; + byte str[UTFmax+1]; + rune r; + + // NOTE: I'm worried about the sign here... + b = bufio·getbyte(buf); + if (b < RuneSelf) { + buf->runesize = 1; + return b; + } + + i = 0; + str[i++] = b; + +nextbyte: + b = bufio·getbyte(buf); + if (b < 0) return b; + if (i >= arrlen(str)) return RuneErr; + str[i++] = b; + if (!utf8·fullrune(str, i)) + goto nextbyte; + + buf->runesize = utf8·bytetorune(&r, str); + if (r == RuneErr && b == 1) { + errorf("illegal UTF-8 sequence"); + for (; i >= 0; i--) + errorf("%s%.2x", i > 0 ? " " : "", *(ubyte*)(str+i)); + errorf("\n"); + + buf->runesize = 0; + } else + for (; i > buf->runesize; i--) + bufio·ungetbyte(buf, str[i]); + + return r; +} + +// TODO: Check that we are given the correct rune! +error +bufio·ungetrune(io·Buffer *buf, rune r) +{ + if (buf->state & bufio·rdr) { + errorf("attempted to unget on non-active reader"); + return bufio·err; + } + + if (buf->pos == buf->buf) { + errorf("attempted to unget past end of buffer"); + return bufio·err; + } + + buf->pos -= buf->runesize; + return 0; +} +#endif + +// ----------------------------------------------------------------------- +// writer |