Crossfire Server, Trunk  R20513
Typedefs | Functions
stringbuffer.h File Reference

Implements a general string buffer: it builds a string by concatenating. More...

#include "global.h"
Include dependency graph for stringbuffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct StringBuffer StringBuffer
 The string buffer state. 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...
 
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...
 

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 availabl, fatal() is called.

Definition in file stringbuffer.h.

Typedef Documentation

typedef struct StringBuffer StringBuffer

The string buffer state.

Definition at line 31 of file stringbuffer.h.

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:

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  )