From f75ab6d2c11e8a8e18191b087564aedebbeb96c5 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Apr 2016 13:00:33 +0200 Subject: Imported Upstream version 1.0.3 --- RichString.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'RichString.c') diff --git a/RichString.c b/RichString.c index eca2293..34720c1 100644 --- a/RichString.c +++ b/RichString.c @@ -21,6 +21,8 @@ in the source distribution for its full text. #include #elif HAVE_NCURSES_NCURSES_H #include +#elif HAVE_NCURSES_CURSES_H +#include #elif HAVE_NCURSES_H #include #elif HAVE_CURSES_H @@ -83,16 +85,15 @@ static inline void RichString_setLen(RichString* this, int len) { #ifdef HAVE_LIBNCURSESW -inline void RichString_appendn(RichString* this, int attrs, const char* data_c, int len) { +static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { wchar_t data[len+1]; len = mbstowcs(data, data_c, len); if (len<0) return; - int oldLen = this->chlen; - int newLen = len + oldLen; + int newLen = from + len; RichString_setLen(this, newLen); - for (int i = oldLen, j = 0; i < newLen; i++, j++) { - memset(&this->chptr[i], 0, sizeof(this->chptr[i])); + memset(&this->chptr[from], 0, sizeof(CharType) * (newLen - from)); + for (int i = from, j = 0; i < newLen; i++, j++) { this->chptr[i].chars[0] = data[j]; this->chptr[i].attr = attrs; } @@ -120,11 +121,10 @@ int RichString_findChar(RichString* this, char c, int start) { #else -inline void RichString_appendn(RichString* this, int attrs, const char* data_c, int len) { - int oldLen = this->chlen; - int newLen = len + oldLen; +static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { + int newLen = from + len; RichString_setLen(this, newLen); - for (int i = oldLen, j = 0; i < newLen; i++, j++) + for (int i = from, j = 0; i < newLen; i++, j++) this->chptr[i] = (isprint(data_c[j]) ? data_c[j] : '?') | attrs; this->chptr[newLen] = 0; } @@ -154,17 +154,21 @@ void RichString_prune(RichString* this) { free(this->chptr); this->chptr = this->chstr; this->chlen = 0; + RichString_setChar(this, 0, 0); } void RichString_setAttr(RichString* this, int attrs) { RichString_setAttrn(this, attrs, 0, this->chlen - 1); } -inline void RichString_append(RichString* this, int attrs, const char* data) { - RichString_appendn(this, attrs, data, strlen(data)); +void RichString_append(RichString* this, int attrs, const char* data) { + RichString_writeFrom(this, attrs, data, this->chlen, strlen(data)); +} + +void RichString_appendn(RichString* this, int attrs, const char* data, int len) { + RichString_writeFrom(this, attrs, data, this->chlen, len); } void RichString_write(RichString* this, int attrs, const char* data) { - RichString_setLen(this, 0); - RichString_appendn(this, attrs, data, strlen(data)); + RichString_writeFrom(this, attrs, data, 0, strlen(data)); } -- cgit v1.2.3