summaryrefslogtreecommitdiff
path: root/src/str.cpp
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-01-31 17:16:27 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-01-31 17:16:27 +0300
commit0be032c6998e712dc2c9f2ed97c3491d89eb05af (patch)
treef762d884147d2f0a9a115edd0b5e0de554a3ec1b /src/str.cpp
downloadxift-0be032c6998e712dc2c9f2ed97c3491d89eb05af.tar
xift-0be032c6998e712dc2c9f2ed97c3491d89eb05af.tar.xz
xift-0be032c6998e712dc2c9f2ed97c3491d89eb05af.zip
[xift] Almost done.
Diffstat (limited to 'src/str.cpp')
-rw-r--r--src/str.cpp32
1 files changed, 32 insertions, 0 deletions
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 <stdlib.h>
+#include <string.h>
+
+
+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;
+ }
+}