summaryrefslogtreecommitdiff
path: root/txt.c
diff options
context:
space:
mode:
Diffstat (limited to 'txt.c')
-rw-r--r--txt.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/txt.c b/txt.c
index 038140d..b4b4f54 100644
--- a/txt.c
+++ b/txt.c
@@ -323,6 +323,32 @@ u32 txt_read_chunk(TxtLoc *lo, TxtLoc hi, char *buf, u32 sz) {
return n;
}
+Str txt_next_chunk(TxtLoc *l) {
+ TxtPiece *p = &l->t->ptbl.v[l->p];
+ Str s = { l->t->buf[p->buf].s + p->ofs + l->i, p->n - l->i };
+ if (l->p + 1 < l->t->ptbl.n) {
+ l->p++;
+ l->i = 0;
+ } else {
+ l->i = p->n;
+ }
+ return s;
+}
+
+int txt_range_equal(TxtLoc lo, TxtLoc hi, Str cmp) {
+ u32 i = 0;
+ while (txt_before(lo, hi)) {
+ Str s = txt_next_chunk(&lo);
+ u32 n = cmp.n - i;
+ if (s.n < n) n = s.n;
+ if (memcmp(s.s, cmp.s + i, n)) {
+ return 0;
+ }
+ i += s.n;
+ }
+ return 1;
+}
+
/* navigation */
int txt_valid_loc(TxtLoc l) {