diff options
| author | Tyge Løvset <[email protected]> | 2022-09-24 11:48:07 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-09-24 11:48:07 +0200 |
| commit | 756120e349a892ef1b7655fc777f28ec13845300 (patch) | |
| tree | 34d39e739f94ff52419ac431e1de26e1c431f2c0 /include/stc/cstr.h | |
| parent | 26bc208248a0dd0f303d5b80bd298f5100b56e82 (diff) | |
| download | STC-modified-756120e349a892ef1b7655fc777f28ec13845300.tar.gz STC-modified-756120e349a892ef1b7655fc777f28ec13845300.zip | |
Fixes for csview and cstr sub-types (_value and _iter).
Diffstat (limited to 'include/stc/cstr.h')
| -rw-r--r-- | include/stc/cstr.h | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 54d55d4c..961ca344 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -227,22 +227,22 @@ STC_INLINE csview cstr_u8_chr(const cstr* self, size_t u8idx) { STC_INLINE cstr_iter cstr_begin(const cstr* self) { csview sv = cstr_sv(self); if (!sv.size) return c_make(cstr_iter){NULL}; - return c_make(cstr_iter){.u8 = {{sv.str, utf8_chr_size(sv.str)}, sv.str + sv.size}}; + return c_make(cstr_iter){.u8 = {{sv.str, utf8_chr_size(sv.str)}}}; } STC_INLINE cstr_iter cstr_end(const cstr* self) { - csview sv = cstr_sv(self); - return c_make(cstr_iter){.u8 = {{NULL}, sv.str + sv.size}}; + return c_make(cstr_iter){NULL}; } STC_INLINE void cstr_next(cstr_iter* it) { it->ref += it->u8.chr.size; it->u8.chr.size = utf8_chr_size(it->ref); - if (it->ref == it->u8.end) it->ref = NULL; + if (!*it->ref) it->ref = NULL; } STC_INLINE cstr_iter cstr_advance(cstr_iter it, isize_t pos) { int inc = -1; if (pos > 0) pos = -pos, inc = 1; - while (pos && it.ref != it.u8.end) pos += (*(it.ref += inc) & 0xC0) != 0x80; + while (pos && *it.ref) pos += (*(it.ref += inc) & 0xC0) != 0x80; it.u8.chr.size = utf8_chr_size(it.ref); + if (!*it.ref) it.ref = NULL; return it; } |
