Crossfire Server, Trunk
stringbuffer.cpp 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.cpp:

Go to the source code of this file.

Data Structures

struct  StringBuffer
 

Functions

void stringbuffer_append_char (StringBuffer *sb, const char c)
 
void stringbuffer_append_int64 (StringBuffer *sb, int64_t x)
 
void stringbuffer_append_multiline_block (StringBuffer *sb, const char *start, const char *content, const char *end)
 
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)
 
void stringbuffer_delete (StringBuffer *sb)
 
static void stringbuffer_ensure (StringBuffer *sb, size_t len)
 
char * stringbuffer_finish (StringBuffer *sb)
 
sstring stringbuffer_finish_shared (StringBuffer *sb)
 
size_t stringbuffer_length (StringBuffer *sb)
 
StringBufferstringbuffer_new (void)
 
void stringbuffer_trim_whitespace (StringBuffer *sb)
 

Function Documentation

◆ stringbuffer_append_char()

void stringbuffer_append_char ( StringBuffer sb,
const char  c 
)

Append a character to a string buffer instance.

Parameters
sbThe string buffer to modify.
cThe string to append.

Definition at line 104 of file stringbuffer.cpp.

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

Referenced by FAST_SAVE_LONG(), and stringbuffer_append_int64().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stringbuffer_append_int64()

void stringbuffer_append_int64 ( StringBuffer sb,
int64_t  x 
)

Append a signed integer to a string buffer instance. This is intended to be faster than using stringbuffer_append_printf().

Parameters
sbThe string buffer to modify.
xThe signed integer to append.

Definition at line 111 of file stringbuffer.cpp.

References buf, stringbuffer_append_char(), and diamondslots::x.

Referenced by FAST_SAVE_LONG(), and START_TEST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stringbuffer_append_multiline_block()

void stringbuffer_append_multiline_block ( StringBuffer sb,
const char *  start,
const char *  content,
const char *  end 
)

Append the specified content in a multiline block, starting with "start" and ending with "end". "start" and "end" must not end with a newline.

Parameters
sbThe string buffer to modify.
startThe text to write to signify the start of the contents.
contentThe actual content, which may contain multilines. If NULL of empty string, nothing is written.
endThe text to write to signify the end of the contents. If NULL then "end_<start>" will be used.

Definition at line 196 of file stringbuffer.cpp.

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

Referenced by QuestWriter::write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stringbuffer_append_printf()

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

◆ stringbuffer_append_string()

◆ stringbuffer_append_stringbuffer()

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 165 of file stringbuffer.cpp.

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:

◆ stringbuffer_delete()

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.cpp.

References StringBuffer::buf.

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

+ Here is the caller graph for this function:

◆ stringbuffer_ensure()

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.

Ensure sb can hold at least len more characters, growing the sb if not.

Definition at line 174 of file stringbuffer.cpp.

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

Referenced by stringbuffer_append_char(), stringbuffer_append_multiline_block(), 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:

◆ stringbuffer_finish()

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 76 of file stringbuffer.cpp.

References StringBuffer::buf, StringBuffer::pos, and rotate-tower::result.

Referenced by add_one_item(), animate_object(), ArchetypeWrapper::ArchetypeWrapper(), artifact_describe(), ArtifactPanel::artifactChanged(), assets_pack(), cfapi_object_describe(), check_sb_equals(), command_bowmode(), command_diff(), command_dump(), common_ob_describe(), cost_approx_str(), cost_string_from_value(), describe_god(), do_dump(), dump_abilities(), dump_all_archetypes(), dump_gods(), examine_fluff(), gate_type_process(), generate_random_map(), knowledge_add_probe_monster(), knowledge_do_display(), knowledge_item_can_be_used_alchemy(), knowledge_process_incremental(), knowledge_show(), lamp_type_describe(), QuestLoader::load(), make_formula_book(), monster_npc_say(), object_dump_all(), object_free(), object_insert_in_map(), object_insert_in_ob(), object_remove(), perceive_self(), place_exits(), place_special_exit(), power_crystal_describe(), power_crystal_type_apply(), process_events(), query_base_name(), query_short_name(), Archetypes::recursive_update(), save_object(), save_objects(), shop_inventory_type_apply(), SockList_AddStringBuffer(), spellbook_type_apply(), spellbook_type_describe(), START_TEST(), CREMapInformationManager::storeCache(), stringbuffer_finish_shared(), tailor_readable_ob(), CRERandomMapPanel::updateItem(), ArtifactPanel::updateItem(), ModifiedAssetsManager< Animations >::write(), and write_load().

◆ stringbuffer_finish_shared()

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.cpp.

References add_string(), rotate-tower::result, sstring, make_face_from_files::str, and stringbuffer_finish().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stringbuffer_length()

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 218 of file stringbuffer.cpp.

References StringBuffer::pos.

Referenced by artifact_describe(), artifact_msg(), assets_pack(), describe_god(), do_spellpath_msg(), god_info_msg(), mon_info_msg(), ring_desc(), ModifiedAssetsManager< Animations >::write(), and write_load().

+ Here is the caller graph for this function:

◆ stringbuffer_new()

StringBuffer* stringbuffer_new ( void  )

Create a new string buffer.

Returns
The newly allocated string buffer.

Definition at line 57 of file stringbuffer.cpp.

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

Referenced by add_one_item(), animate_object(), ArchetypeWrapper::ArchetypeWrapper(), artifact_describe(), artifact_msg(), assets_pack(), command_bowmode(), command_diff(), command_dump(), cost_approx_str(), cost_string_from_value(), describe_attacktype(), describe_god(), describe_item(), describe_monster(), describe_resistance(), describe_spellpath_attenuation(), do_dump(), dump_all_archetypes(), examine_fluff(), gate_type_process(), god_info_msg(), knowledge_add_probe_monster(), knowledge_alchemy_can_use_item(), knowledge_do_display(), knowledge_god_add(), knowledge_process_incremental(), knowledge_show(), lamp_type_describe(), QuestLoader::load(), make_formula_book(), mon_desc(), mon_info_msg(), monster_format_say(), msgfile_msg(), object_dump_all(), object_free(), object_insert_in_map(), object_insert_in_ob(), object_remove(), object_set_msg(), perceive_self(), power_crystal_describe(), power_crystal_type_apply(), process_events(), Archetypes::recursive_update(), ring_desc(), save_object(), save_objects(), shop_inventory_type_apply(), spellbook_type_apply(), spellbook_type_describe(), spellpath_msg(), START_TEST(), ArtifactPanel::updateItem(), ModifiedAssetsManager< Animations >::write(), write_load(), and write_map_parameters_to_string().

+ Here is the call graph for this function:

◆ stringbuffer_trim_whitespace()

void stringbuffer_trim_whitespace ( StringBuffer sb)

Trim trailing whitespace from a stringbuffer.

Parameters
sbThe stringbuffer.

Definition at line 222 of file stringbuffer.cpp.

References StringBuffer::buf, and StringBuffer::pos.

Referenced by examine_fluff(), and spellbook_type_apply().

+ Here is the caller graph for this function: