]> www.ginac.de Git - cln.git/blobdiff - src/base/string/cl_spushstring_append.cc
Initial revision
[cln.git] / src / base / string / cl_spushstring_append.cc
diff --git a/src/base/string/cl_spushstring_append.cc b/src/base/string/cl_spushstring_append.cc
new file mode 100644 (file)
index 0000000..245d7a2
--- /dev/null
@@ -0,0 +1,28 @@
+// class cl_spushstring.
+
+// General includes.
+#include "cl_sysdep.h"
+
+// Specification.
+#include "cl_spushstring.h"
+
+
+// Implementation.
+
+#include <string.h> // declares memcpy()
+
+void cl_spushstring::append (const char * ptr, uintL len)
+{
+       if (index + len > alloc) {
+               var uintL newalloc = index+2*len;
+               if (newalloc < 2*alloc) { newalloc = 2*alloc; }
+               var char* newbuffer = (char *) cl_malloc_hook(newalloc);
+               memcpy(newbuffer,buffer,alloc);
+               cl_free_hook(buffer);
+               buffer = newbuffer;
+               alloc = newalloc;
+       }
+       // Now index+len <= alloc.
+       for (uintL count = len; count > 0; count--)
+               buffer[index++] = *ptr++;
+}