SharedMeatAxe  1.0
Dynamic Strings

Detailed Description

These functions are used to work with dynamically allocated strings.

A dynamic string contains a normal «char*» pointing to a NUL terminated text. Note however, that dynamic strings use their own memory management which cannot be mixed with the standard C library memory functions. Unused strings must be freed with StrFree(), and you must never use free() or realloc() on a dynamic string.

Data Structures

struct  String
 A dynamic string. More...
 

Functions

String StrAlloc (size_t initial_capacity)
 Create a string. More...
 
void StrFree (String *s)
 Free a string. More...
 
void StrAppend (String *s, const char *text)
 Appends text to the end of a string. More...
 
void StrAppendF (String *s, const char *fmt,...)
 snprintf() replacement. More...
 
void StrPrintF (String *s, const char *fmt,...)
 snprintf() replacement. More...
 
void StrVAppendF (String *s, const char *fmt, va_list args)
 vsnprintf() replacement. More...
 
void StrVPrintF (String *s, const char *fmt, va_list args)
 vsnprintf() replacement. More...
 

Function Documentation

String StrAlloc ( size_t  initial_capacity)

Create a string.

This function creates an empty string.

See also
StrFree()
Parameters
initial_capacityNumber of bytes to reserve on allocation.
Returns
The new string.
void StrAppend ( String s,
const char *  text 
)

Appends text to the end of a string.

Parameters
sThe string to be modified.
textText to append.
void StrAppendF ( String s,
const char *  fmt,
  ... 
)

snprintf() replacement.

Works like StrVAppendF() but expects a variable argument list.

void StrFree ( String s)

Free a string.

This function frees a dynamic string.

See also
StrAlloc()
void StrPrintF ( String s,
const char *  fmt,
  ... 
)

snprintf() replacement.

Works like StrVPrintF() but expects a variable argument list.

void StrVAppendF ( String s,
const char *  fmt,
va_list  args 
)

vsnprintf() replacement.

Formats a string with vsnprintf() and appends the resulting text to «s».

Parameters
sThe string to be modified.
fmtFormat
argsArguments for the % placeholders in fmt.
void StrVPrintF ( String s,
const char *  fmt,
va_list  args 
)

vsnprintf() replacement.

Works like StrVAppendF() but overwrites the string with the formatted text.

Parameters
sThe string to be modified.
fmtFormat
argsArguments for the % placeholders in fmt.

SharedMeatAxe 1.0 documentation, generated on Sat Dec 30 2017 12:13:21