From 7bc0d4a65022f8477efc9dc0ce15254be75f3ad4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Wed, 9 Oct 1996 09:34:45 +0200
Subject: [PATCH] /precompiled/string_buffer added

Rev: doc/precompiled/string_buffer:1.1
Rev: lib/include/string.h:1.1
Rev: lib/include/string.pre.pike:1.1
---
 doc/precompiled/string_buffer | 56 +++++++++++++++++++++++++++++++++++
 lib/include/string.h          |  0
 lib/include/string.pre.pike   | 40 +++++++++++++++++++++++++
 3 files changed, 96 insertions(+)
 create mode 100644 doc/precompiled/string_buffer
 create mode 100644 lib/include/string.h
 create mode 100644 lib/include/string.pre.pike

diff --git a/doc/precompiled/string_buffer b/doc/precompiled/string_buffer
new file mode 100644
index 0000000000..ff0ea90307
--- /dev/null
+++ b/doc/precompiled/string_buffer
@@ -0,0 +1,56 @@
+NAME
+	/precompiled/string_buffer - incremental string buffer
+
+DESCRIPTION
+	string_buffer implements a fast way to build strings by appending
+	strings or chars to the end of the buffer.
+
+BUGS
+	This object is not thread-safe, if several threads access the same
+	buffer they have to protect the accesses with mutex locks.
+
+============================================================================
+NAME
+	create - initielize the buffer
+
+SYNTAX
+	#include <string.h>
+
+	void string_buffer->create();
+	or
+	object clone(String_buffer);
+
+DESCRIPTION
+	This function initializes the string buffer. You can call this
+	function to clear the contents of the buffer once it has been
+	used.
+
+============================================================================
+NAME
+	append - append a string to the buffer
+
+SYNTAX
+	#include <string.h>
+
+	void string_buffer->append(string s);
+
+DESCRIPTION
+	This function appends the string s to the end of the buffer.
+
+============================================================================
+NAME
+	get_buffer - get the contents of the buffer as a string.
+
+SYNTAX
+	#include <string.h>
+
+	mixed string_buffer->get_buffer();
+	or
+	(string)string_buffer;
+
+DESCRIPTION
+	This function retreives the content of the buffer. Note that it does
+	not clear the contents of the buffer. You have to do that yourself
+	with create().
+
+============================================================================
diff --git a/lib/include/string.h b/lib/include/string.h
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/lib/include/string.pre.pike b/lib/include/string.pre.pike
new file mode 100644
index 0000000000..573e19b142
--- /dev/null
+++ b/lib/include/string.pre.pike
@@ -0,0 +1,40 @@
+#define BEGIN 32
+void create()
+{
+  master()->add_precompiled_program("/precompiled/string_buffer", class {
+    string *buffer;
+    int ptr;
+    
+    static void fix()
+    {
+      string tmp=buffer*"";
+      buffer=allocate(strlen(tmp)/128+BEGIN);
+      buffer[0]=tmp;
+      ptr=1;
+    }
+    
+    string get_buffer()
+    {
+      if(ptr != 1) fix();
+      return buffer[0];
+    }
+    
+    void append(string s)
+    {
+      if(ptr==sizeof(buffer)) fix();
+      buffer[ptr++]=s;
+    }
+    
+    mixed cast(string to)
+    {
+      if(to=="string") return get_buffer();
+      return 0;
+    }
+
+    void create()
+    {
+      buffer=allocate(BEGIN);
+      ptr=0;
+    }
+  });
+}
-- 
GitLab