diff options
Diffstat (limited to 'txt.c')
| -rw-r--r-- | txt.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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) { |
