diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2021-01-10 11:14:02 +0100 |
---|---|---|
committer | Christian Göttsche <cgzones@googlemail.com> | 2021-01-10 16:51:25 +0100 |
commit | 3bb731c645d1bcde6ecf6ca23e44eb6655da8726 (patch) | |
tree | 20b0f7d09c12ff15d9526670b82a9ae9eccfab61 /RichString.c | |
parent | a076488809b2f4a05a1aa19d6599a9cfc9a97018 (diff) |
RichString_setAttrn: refactor to take a length instead of a stop index
Fixes: #459
Diffstat (limited to 'RichString.c')
-rw-r--r-- | RichString.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/RichString.c b/RichString.c index 3e3d3703..9b69e98c 100644 --- a/RichString.c +++ b/RichString.c @@ -73,12 +73,10 @@ static inline int RichString_writeFromAscii(RichString* this, int attrs, const c return len; } -inline void RichString_setAttrn(RichString* this, int attrs, int start, int finish) { - cchar_t* ch = this->chptr + start; - finish = CLAMP(finish, 0, this->chlen - 1); - for (int i = start; i <= finish; i++) { - ch->attr = attrs; - ch++; +inline void RichString_setAttrn(RichString* this, int attrs, int start, int charcount) { + int end = CLAMP(start + charcount, 0, this->chlen); + for (int i = start; i < end; i++) { + this->chptr[i].attr = attrs; } } @@ -110,12 +108,10 @@ static inline int RichString_writeFromAscii(RichString* this, int attrs, const c return RichString_writeFromWide(this, attrs, data_c, from, len); } -void RichString_setAttrn(RichString* this, int attrs, int start, int finish) { - chtype* ch = this->chptr + start; - finish = CLAMP(finish, 0, this->chlen - 1); - for (int i = start; i <= finish; i++) { - *ch = (*ch & 0xff) | attrs; - ch++; +void RichString_setAttrn(RichString* this, int attrs, int start, int charcount) { + int end = CLAMP(start + charcount, 0, this->chlen); + for (int i = start; i < end; i++) { + this->chptr[i] = (this->chptr[i] & 0xff) | attrs; } } @@ -148,7 +144,7 @@ void RichString_appendChr(RichString* this, char c, int count) { } void RichString_setAttr(RichString* this, int attrs) { - RichString_setAttrn(this, attrs, 0, this->chlen - 1); + RichString_setAttrn(this, attrs, 0, this->chlen); } int RichString_appendWide(RichString* this, int attrs, const char* data) { |