Skip to content
Snippets Groups Projects
Commit 7bc0d4a6 authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

/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
parent 45c4efa4
No related branches found
No related tags found
No related merge requests found
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().
============================================================================
#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;
}
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment