MeatAxe: Dynamic Strings

MeatAxe 2.4

- Main Page
- Related Pages
- Modules
- Data Structures

Data Structures | Functions
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.
void | StrFree (String *s)
| Free a string.
void | StrAppend (String *s, const char *text)
| Appends text to the end of a string.
void | StrAppendF (String *s, const char *fmt,...)
| snprintf() replacement.
void | StrPrintF (String *s, const char *fmt,...)
| snprintf() replacement.
void | StrVAppendF (String *s, const char *fmt, va_list args)
| vsnprintf() replacement.
void | StrVPrintF (String *s, const char *fmt, va_list args)
| vsnprintf() replacement.

## Function Documentation

String StrAlloc | ( | size_t | initial_capacity | ) |

Create a string.

This function creates an empty string.

See also:
  StrFree()

Parameters:

  initial_capacity | Number 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:

  s | The string to be modified.
  text | Text 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:

  s | The string to be modified.
  fmt | Format
  args | Arguments 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:

  s | The string to be modified.
  fmt | Format
  args | Arguments for the % placeholders in fmt.