diff options
| author | WormHeamer | 2025-12-29 07:58:52 -0500 |
|---|---|---|
| committer | WormHeamer | 2025-12-29 07:58:52 -0500 |
| commit | c96e6adc7b06b23b63391b93fcfbac4268c4ba89 (patch) | |
| tree | f44c91c39e9d665b6060eafa381ae359a66dcdf6 /txt.c | |
| parent | 6c6b24aa308f24629899faf416e20c90a6ce21a8 (diff) | |
add txt_range_equal()
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) { |
