diff options
| author | Tyge Løvset <[email protected]> | 2022-08-10 14:55:01 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-08-10 14:55:01 +0200 |
| commit | 4fe41778b4429c4974166e5ae531577dba22bed5 (patch) | |
| tree | 5f47a376aec6d1fb0b1c5da7cf109623b7d3ed98 | |
| parent | 8eea6dfb61e9922de5940be975f4a51dcf4a62a3 (diff) | |
| download | STC-modified-4fe41778b4429c4974166e5ae531577dba22bed5.tar.gz STC-modified-4fe41778b4429c4974166e5ae531577dba22bed5.zip | |
Fixed iters for carr2/carr3 and cstr/csview.
| -rw-r--r-- | include/stc/carr2.h | 8 | ||||
| -rw-r--r-- | include/stc/carr3.h | 8 | ||||
| -rw-r--r-- | include/stc/cstr.h | 8 | ||||
| -rw-r--r-- | include/stc/csview.h | 20 |
4 files changed, 26 insertions, 18 deletions
diff --git a/include/stc/carr2.h b/include/stc/carr2.h index 66a98f58..f15c6034 100644 --- a/include/stc/carr2.h +++ b/include/stc/carr2.h @@ -89,13 +89,13 @@ STC_INLINE size_t _cx_memb(_idx)(const _cx_self* self, size_t x, size_t y) { } STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) - { return c_make(_cx_iter){*self->data}; } + { size_t n = self->xdim*self->ydim; return c_make(_cx_iter){n ? *self->data : NULL, *self->data + n}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter){*self->data + self->xdim*self->ydim}; } + { return c_make(_cx_iter){NULL, *self->data + self->xdim*self->ydim}; } + +STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->_end) it->ref = NULL; } -STC_INLINE void _cx_memb(_next)(_cx_iter* it) - { ++it->ref; } /* -------------------------- IMPLEMENTATION ------------------------- */ #if defined(i_implement) diff --git a/include/stc/carr3.h b/include/stc/carr3.h index 8ff1670e..ec67645c 100644 --- a/include/stc/carr3.h +++ b/include/stc/carr3.h @@ -92,13 +92,13 @@ STC_INLINE size_t _cx_memb(_idx)(const _cx_self* self, size_t x, size_t y, size_ } STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) - { return c_make(_cx_iter){**self->data}; } + { size_t n = _cx_memb(_size)(self); return c_make(_cx_iter){n ? **self->data : NULL, **self->data + n}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter){**self->data + _cx_memb(_size)(self)}; } + { return c_make(_cx_iter){NULL, **self->data + _cx_memb(_size)(self)}; } + +STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->_end) it->ref = NULL; } -STC_INLINE void _cx_memb(_next)(_cx_iter* it) - { ++it->ref; } /* -------------------------- IMPLEMENTATION ------------------------- */ #if defined(i_implement) diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 2dbea85a..509811eb 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -223,16 +223,18 @@ STC_INLINE csview cstr_u8_chr(const cstr* self, size_t u8idx) { // utf8 iterator STC_INLINE cstr_iter cstr_begin(const cstr* self) { - const char* str = cstr_str(self); - return c_make(cstr_iter){.u8 = {{str, utf8_chr_size(str)}}}; + 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}}; } STC_INLINE cstr_iter cstr_end(const cstr* self) { csview sv = cstr_sv(self); - return c_make(cstr_iter){sv.str + sv.size}; + return c_make(cstr_iter){.u8 = {{NULL}, sv.str + sv.size}}; } 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; } diff --git a/include/stc/csview.h b/include/stc/csview.h index ef545bf2..c48c6ae6 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -69,15 +69,21 @@ STC_INLINE csview csview_slice(csview sv, size_t p1, size_t p2) { return sv; } -/* iterator */ -STC_INLINE csview_iter csview_begin(const csview* self) - { return c_make(csview_iter){.u8 = {{self->str, utf8_chr_size(self->str)}}}; } +/* utf8 iterator */ +STC_INLINE csview_iter csview_begin(const csview* self) { + if (!self->size) return c_make(csview_iter){NULL}; + return c_make(csview_iter){.u8 = {{self->str, utf8_chr_size(self->str)}, self->str + self->size}}; +} + +STC_INLINE csview_iter csview_end(const csview* self) + { return c_make(csview_iter){.u8 = {{NULL}, self->str + self->size}}; } -STC_INLINE csview_iter csview_end(const csview* self) - { return c_make(csview_iter){self->str + self->size}; } +STC_INLINE void csview_next(csview_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; +} -STC_INLINE void csview_next(csview_iter* it) - { it->ref += it->u8.chr.size; it->u8.chr.size = utf8_chr_size(it->ref); } /* utf8 */ STC_INLINE size_t csview_u8_size(csview sv) |
