From 85bb4ad9cb820ac3b8e935a930084a06cbfd2847 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Apr 2016 13:00:20 +0200 Subject: Imported Upstream version 0.6.3 --- RichString.c | 52 ++++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) (limited to 'RichString.c') diff --git a/RichString.c b/RichString.c index 7a92e08..3bdc82b 100644 --- a/RichString.c +++ b/RichString.c @@ -12,6 +12,9 @@ /*{ +#define RichString_init(this) (this)->len = 0 +#define RichString_initVal(this) (this).len = 0 + typedef struct RichString_ { int len; chtype chstr[RICHSTRING_MAXLEN+1]; @@ -23,24 +26,8 @@ typedef struct RichString_ { #define MIN(a,b) ((a)<(b)?(a):(b)) #endif -/* private property */ -WINDOW* workArea = NULL; - -RichString RichString_new() { - RichString this; - this.len = 0; - return this; -} - -void RichString_delete(RichString this) { -} - -void RichString_prune(RichString* this) { - this->len = 0; -} - void RichString_write(RichString* this, int attrs, char* data) { - this->len = 0; + RichString_init(this); RichString_append(this, attrs, data); } @@ -49,35 +36,32 @@ inline void RichString_append(RichString* this, int attrs, char* data) { } inline void RichString_appendn(RichString* this, int attrs, char* data, int len) { - if (!workArea) { - workArea = newpad(1, RICHSTRING_MAXLEN); - } - assert(workArea); - wattrset(workArea, attrs); - int maxToWrite = (RICHSTRING_MAXLEN - 1) - this->len; - int wrote = MIN(maxToWrite, len); - mvwaddnstr(workArea, 0, 0, data, maxToWrite); - int oldstrlen = this->len; - this->len += wrote; - mvwinchnstr(workArea, 0, 0, this->chstr + oldstrlen, wrote); - wattroff(workArea, attrs); + int last = MIN(RICHSTRING_MAXLEN - 1, len + this->len); + for (int i = this->len, j = 0; i < last; i++, j++) + this->chstr[i] = data[j] | attrs; + this->chstr[last] = 0; + this->len = last; } void RichString_setAttr(RichString *this, int attrs) { + chtype* ch = this->chstr; for (int i = 0; i < this->len; i++) { - char c = this->chstr[i]; - this->chstr[i] = c | attrs; + *ch = (*ch & 0xff) | attrs; + ch++; } } void RichString_applyAttr(RichString *this, int attrs) { - for (int i = 0; i < this->len - 1; i++) { - this->chstr[i] |= attrs; + chtype* ch = this->chstr; + for (int i = 0; i < this->len; i++) { + *ch |= attrs; + ch++; } } RichString RichString_quickString(int attrs, char* data) { - RichString str = RichString_new(); + RichString str; + RichString_initVal(str); RichString_write(&str, attrs, data); return str; } -- cgit v1.2.3