MeatAxe  2.4
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

◆ StrAlloc()

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.

◆ StrAppend()

void StrAppend ( String s,
const char *  text 
)

Appends text to the end of a string.

Parameters
sThe string to be modified.
textText to append.

◆ StrAppendF()

void StrAppendF ( String s,
const char *  fmt,
  ... 
)

snprintf() replacement.

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

◆ StrFree()

void StrFree ( String s)

Free a string.

This function frees a dynamic string.

See also
StrAlloc()

◆ StrPrintF()

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

snprintf() replacement.

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

◆ StrVAppendF()

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.

◆ StrVPrintF()

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.

MeatAxe 2.4 documentation, generated on Mon Jun 7 2021 11:42:24