From 8d4981fcc1c545396df3eac87a3c1a67f3d30038 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Mon, 3 Feb 2020 15:53:56 +0300 Subject: [texo] Abolished dependency on ScriptPP. --- src/script.cpp | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'src/script.cpp') diff --git a/src/script.cpp b/src/script.cpp index 2892723..cf87bc2 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -1,21 +1,47 @@ #include "script.hpp" +#include +#include + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Texo String Exporter */ -TexoExporterString::TexoExporterString(ScriptVariable & str): str(str) -{} +TexoString::TexoString(char *&str): str(str) +{ + str = (char *)malloc(1); + *str = 0; + len = 0; + size = 1; +} -bool TexoExporterString::Put(char c) +bool TexoString::Put(char c) { - str += c; + if (len + 1 == size) { + size *= 2; + str = (char *)realloc(str, size); + } + if (!str) { + return false; + } + str[len] = c; + ++len; + str[len] = 0; return true; } -bool TexoExporterString::Put(const ScriptVariable & addon) +bool TexoString::Put(const char *addon) { - str += addon; + int alen = strlen(addon); + if (len + alen >= size) { + size = len + alen + 1; + str = (char *)realloc(str, size); + } + if (!str) { + return false; + } + memcpy(str + len, addon, alen + 1); + len += alen; return true; } -- cgit v1.2.3