diff --git a/doc/precompiled/string_buffer b/doc/precompiled/string_buffer new file mode 100644 index 0000000000000000000000000000000000000000..ff0ea9030759372995abbb6567d852288cb521a4 --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/lib/include/string.pre.pike b/lib/include/string.pre.pike new file mode 100644 index 0000000000000000000000000000000000000000..573e19b14295bf82b7f42c97c58d1cbea2e547e6 --- /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; + } + }); +}