Crossfire Server, Trunk  R20513
Data Structures | Functions
stringbuffer.c File Reference
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "global.h"
#include "libproto.h"
#include "stringbuffer.h"
Include dependency graph for stringbuffer.c:

Go to the source code of this file.

Data Structures

struct  StringBuffer
 A buffer that will be expanded as content is added to it. More...
 

Functions

void stringbuffer_append_printf (StringBuffer *sb, const char *format,...)
 Append a formatted string to a string buffer instance. More...
 
void stringbuffer_append_string (StringBuffer *sb, const char *str)
 Append a string to a string buffer instance. More...
 
void stringbuffer_append_stringbuffer (StringBuffer *sb, const StringBuffer *sb2)
 Append the contents of a string buffer instance to another string buffer instance. More...
 
void stringbuffer_delete (StringBuffer *sb)
 Totally delete a string buffer. More...
 
static void stringbuffer_ensure (StringBuffer *sb, size_t len)
 Make sure that at least len bytes are available in the passed string buffer. More...
 
char * stringbuffer_finish (StringBuffer *sb)
 Deallocate the string buffer instance and return the string. More...
 
sstring stringbuffer_finish_shared (StringBuffer *sb)
 Deallocate the string buffer instance and return the string as a shared string. More...
 
size_t stringbuffer_length (StringBuffer *sb)
 Return the current length of the buffer. More...
 
StringBufferstringbuffer_new (void)
 Create a new string buffer. More...
 

Function Documentation

void stringbuffer_append_printf ( StringBuffer sb,
const char *  format,
  ... 
)
void stringbuffer_append_string ( StringBuffer sb,
const char *  str 
)
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 131 of file stringbuffer.c.

References StringBuffer::buf, StringBuffer::pos, and stringbuffer_ensure().

Referenced by artifact_describe(), artifact_msg(), describe_god(), and mon_info_msg().

Here is the call graph for this function:

Here is the caller graph for this function:

void stringbuffer_delete ( StringBuffer sb)

Totally delete a string buffer.

Parameters
sbString to delete, pointer becomes invalid after the call.

Definition at line 71 of file stringbuffer.c.

References StringBuffer::buf.

Referenced by artifact_msg(), cost_approx_str(), god_info_msg(), and mon_info_msg().

Here is the caller graph for this function:

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 137 of file stringbuffer.c.

References StringBuffer::buf, fatal(), OUT_OF_MEMORY, StringBuffer::pos, and StringBuffer::size.

Referenced by stringbuffer_append_printf(), stringbuffer_append_string(), and stringbuffer_append_stringbuffer().

Here is the call graph for this function:

Here is the caller graph for this function:

char* stringbuffer_finish ( StringBuffer sb)
sstring 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, call free_string() on it.

Definition at line 85 of file stringbuffer.c.

References add_string(), and stringbuffer_finish().

Referenced by knowledge_god_add(), make_formula_book(), mon_info_msg(), monster_do_talk_npc(), and object_set_msg().

Here is the call graph for this function:

Here is the caller graph for this function:

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 154 of file stringbuffer.c.

References StringBuffer::pos.

Referenced by artifact_describe(), artifact_msg(), describe_god(), god_info_msg(), mon_info_msg(), ring_desc(), and spellpath_msg().

Here is the caller graph for this function:

StringBuffer* stringbuffer_new ( void  )