Atrinik Server 2.5
Functions
server/stringbuffer.c File Reference
#include <global.h>
#include <stdarg.h>

Go to the source code of this file.

Functions

static void stringbuffer_ensure (StringBuffer *sb, size_t len)
StringBufferstringbuffer_new ()
char * stringbuffer_finish (StringBuffer *sb)
const char * stringbuffer_finish_shared (StringBuffer *sb)
void stringbuffer_append_string (StringBuffer *sb, const char *str)
void stringbuffer_append_printf (StringBuffer *sb, const char *format,...)
void stringbuffer_append_stringbuffer (StringBuffer *sb, const StringBuffer *sb2)
size_t stringbuffer_length (StringBuffer *sb)

Detailed Description

Implements a general string buffer: it builds a string by concatenating. It allocates enough memory to hold the whole string; there is no upper limit for the total string length.

Usage is:

 StringBuffer *sb = stringbuffer_new();
 stringbuffer_append_string(sb, "abc");
 stringbuffer_append_string(sb, "def");
 ... more calls to stringbuffer_append_xxx()
 char *str = stringbuffer_finish(sb);
 ... use str
 free(str);

No function ever fails. In case not enough memory is available, the program exits.

Definition in file stringbuffer.c.


Function Documentation

void stringbuffer_append_printf ( StringBuffer sb,
const char *  format,
  ... 
)

Append a formatted string to a string buffer instance.

Parameters:
sbThe string buffer to modify.
formatThe format string to append.

Definition at line 119 of file stringbuffer.c.

void stringbuffer_append_string ( StringBuffer sb,
const char *  str 
)

Append a string to a string buffer instance.

Parameters:
sbThe string buffer to modify.
strThe string to append.

Definition at line 106 of file stringbuffer.c.

void stringbuffer_append_stringbuffer ( StringBuffer sb,
const StringBuffer sb2 
)

Append the contents of a string buffer instance to another string buffer instance.

Parameters:
sbThe string buffer to modify.
sb2The string buffer to append; it must be different from sb.

Definition at line 158 of file stringbuffer.c.

static void stringbuffer_ensure ( StringBuffer sb,
size_t  len 
) [static]

Make sure that at least len bytes are available in the passed string buffer.

Parameters:
sbThe string buffer to modify.
lenThe number of bytes to allocate.

Definition at line 170 of file stringbuffer.c.

char* stringbuffer_finish ( StringBuffer sb)

Deallocate the string buffer instance and return the string.

The passed string buffer must not be accessed afterwards.

Parameters:
sbThe string buffer to deallocate.
Returns:
The result string; to free it, call free() on it.

Definition at line 75 of file stringbuffer.c.

const char* stringbuffer_finish_shared ( StringBuffer sb)

Deallocate the string buffer instance and return the string as a shared string.

The passed string buffer must not be accessed afterwards.

Parameters:
sbThe string buffer to deallocate.
Returns:
The result shared string; to free it, use FREE_AND_CLEAR_HASH().

Definition at line 93 of file stringbuffer.c.

size_t stringbuffer_length ( StringBuffer sb)

Return the current length of the buffer.

Parameters:
sbThe string buffer to check.
Returns:
Current length of 'sb'.

Definition at line 196 of file stringbuffer.c.

StringBuffer* stringbuffer_new ( )

Create a new string buffer.

Returns:
The newly allocated string buffer.

Definition at line 54 of file stringbuffer.c.