From 0be032c6998e712dc2c9f2ed97c3491d89eb05af Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Fri, 31 Jan 2020 17:16:27 +0300 Subject: [xift] Almost done. --- src/str.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/str.cpp (limited to 'src/str.cpp') diff --git a/src/str.cpp b/src/str.cpp new file mode 100644 index 0000000..a0792c8 --- /dev/null +++ b/src/str.cpp @@ -0,0 +1,32 @@ +#include "str.hpp" + +#include "utils.hpp" +#include +#include + + +XiftString::XiftString(char *&str): str(str) +{ + str = (char *)malloc(1); + *str = 0; + len = 0; + size = 1; +} + +void XiftString::Put(char c) +{ + xift_str_add(str, len, size, c); +} + +void XiftString::Put(const char *addon) +{ + int alen = strlen(addon); + if (len + alen >= size) { + size = len + alen + 1; + str = (char *)realloc(str, size); + } + if (str) { + memcpy(str + len, addon, alen + 1); + len += alen; + } +} -- cgit v1.2.3