summaryrefslogtreecommitdiffhomepage
path: root/include/stc/cstr.h
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-09-24 11:48:07 +0200
committerTyge Løvset <[email protected]>2022-09-24 11:48:07 +0200
commit756120e349a892ef1b7655fc777f28ec13845300 (patch)
tree34d39e739f94ff52419ac431e1de26e1c431f2c0 /include/stc/cstr.h
parent26bc208248a0dd0f303d5b80bd298f5100b56e82 (diff)
downloadSTC-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.h10
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;
}