diff options
Diffstat (limited to 'src/script.cpp')
-rw-r--r-- | src/script.cpp | 38 |
1 files changed, 32 insertions, 6 deletions
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 <stdlib.h> +#include <string.h> + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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; } |