From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- Src/Wasabi/bfc/string/bigstring.cpp | 95 +++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 Src/Wasabi/bfc/string/bigstring.cpp (limited to 'Src/Wasabi/bfc/string/bigstring.cpp') diff --git a/Src/Wasabi/bfc/string/bigstring.cpp b/Src/Wasabi/bfc/string/bigstring.cpp new file mode 100644 index 00000000..20c7c09f --- /dev/null +++ b/Src/Wasabi/bfc/string/bigstring.cpp @@ -0,0 +1,95 @@ +#include "precomp_wasabi_bfc.h" +#include "bigstring.h" + +BigString::BigString() { + mem = NULL; + m_linecount = 0; +} + +BigString::~BigString() { + if (mem != NULL) { + FREE(mem); + } + strings.deleteAll(); +} + +const char *BigString::getValue() /*const*/ { + if (mem != NULL) return mem; + size_t l = 0; + foreach(strings) + l += strings.getfor()->len(); + endfor; + mem = (char *)MALLOC(l+1); + char *p = mem; + String *s = NULL; + size_t sl = 0; + foreach(strings) + s = strings.getfor(); + sl = s->len(); + if (sl > 0) MEMCPY((void *)p, (void *)s->getValue(), sl); + p += sl; + endfor; + *p = 0; + return mem; +} + +void BigString::setValue(const char *val) { + if (mem != NULL) { + FREE(mem); + mem = NULL; + } + strings.deleteAll(); + cat(val); +} + +int BigString::isempty() { + if (strings.getNumItems() == 0) return 1; + foreach(strings) + if (!strings.getfor()->isempty()) return 0; + endfor; + return 1; +} + +void BigString::reset() { + if (mem != NULL) { + FREE(mem); + mem = NULL; + } + strings.deleteAll(); + m_linecount = 0; +} + +void BigString::catn(const char *s, int n) { + String *str = new String(); + str->catn(s, n); + cat(str->getValue()); +} + +void BigString::cat(const char *s) { + if (mem != NULL) { + FREE(mem); + mem = NULL; + } + char *p = (char *)s; + while (p && *p) { + if (*p == '\r' || *p == '\n') { + if (*(p+1) == '\n' && *p == '\r') p++; + m_linecount++; + } + p++; + } + strings.addItem(new String(s)); +} + +char BigString::lastChar() { + return strings.getLast()->lastChar(); +} + +char BigString::firstChar() { + const char *s = strings.getFirst()->getValue(); + return s ? *s : 0; +} + +int BigString::getLineCount() { + return m_linecount; +} -- cgit