strbuf.h

This interface defines a class that allows strings to grow by concatentation.
Type
StringBuffer This type provides an efficient, memory-safe mechanism for strings that grow by the addition of characters.
Functions
newStringBuffer() Creates a new string buffer that expands dynamically if needed.
freeStringBuffer(sb) Frees the storage associated with the string buffer.
pushChar(sb, ch) Appends (pushes) the character ch onto the end of the string buffer.
popChar(sb) Pops and removes the last character from the string buffer.
appendString(sb, str) Appends the string str to the end of the string buffer.
sbprintf(sb, format, ...) Expands a printf-style format string and arguments onto the end of the string buffer.
isEmpty(sb) Returns true if the string buffer is empty.
size(sb) Returns the number of characters in the string buffer.
clear(sb) Removes all characters from the string buffer.
getString(sb) Returns the string stored inside the buffer.

Type detail


typedef struct StringBufferCDT *StringBuffer;
This type provides an efficient, memory-safe mechanism for strings that grow by the addition of characters.

Function detail


StringBuffer newStringBuffer();
Creates a new string buffer that expands dynamically if needed. The buffer is initially empty.

Usage:

sb = newStringBuffer();

void freeStringBuffer(StringBuffer sb);
Frees the storage associated with the string buffer.

Usage:

freeStringBuffer(sb);

void pushChar(StringBuffer sb, char ch);
Appends (pushes) the character ch onto the end of the string buffer.

Usage:

pushChar(sb, ch);

char popChar(StringBuffer sb);
Pops and removes the last character from the string buffer.

Usage:

ch = popChar(sb);

void appendString(StringBuffer sb, string str);
Appends the string str to the end of the string buffer.

Usage:

appendString(sb, str);

void sbprintf(StringBuffer sb, string format, ...);
Expands a printf-style format string and arguments onto the end of the string buffer.

Usage:

sbprintf(sb, format, ...);

bool isEmpty(StringBuffer vec);
Returns true if the string buffer is empty.

Usage:

if (isEmpty(sb)) . . .

int size(StringBuffer vector);
Returns the number of characters in the string buffer.

Usage:

n = size(sb);

void clear(StringBuffer sb);
Removes all characters from the string buffer.

Usage:

clear(sb);

string getString(StringBuffer sb);
Returns the string stored inside the buffer. Clients must copy this string if they need to retain it.

Usage:

str = getString(sb);