strbuf.h
Type | |
This type provides an efficient, memory-safe mechanism for strings that grow by the addition of characters. | |
Functions | |
Creates a new string buffer that expands dynamically if needed. | |
Frees the storage associated with the string buffer. | |
Appends (pushes) the character ch onto the end of the string buffer. | |
Pops and removes the last character from the string buffer. | |
Appends the string str to the end of the string buffer. | |
Expands a printf -style format string and arguments onto the end of the string buffer. | |
Returns true if the string buffer is empty. | |
Returns the number of characters in the string buffer. | |
Removes all characters from the string buffer. | |
Returns the string stored inside the buffer. |
typedef struct StringBufferCDT *StringBuffer;
StringBuffer newStringBuffer();
Usage:
sb = newStringBuffer();
void freeStringBuffer(StringBuffer sb);
Usage:
freeStringBuffer(sb);
void pushChar(StringBuffer sb, char ch);
ch
onto the end of the
string buffer.
Usage:
pushChar(sb, ch);
char popChar(StringBuffer sb);
Usage:
ch = popChar(sb);
void appendString(StringBuffer sb, string str);
str
to the end of the string buffer.
Usage:
appendString(sb, str);
void sbprintf(StringBuffer sb, string format, ...);
printf
-style format string and arguments onto
the end of the string buffer.
Usage:
sbprintf(sb, format, ...);
bool isEmpty(StringBuffer vec);
true
if the string buffer is empty.
Usage:
if (isEmpty(sb)) . . .
int size(StringBuffer vector);
Usage:
n = size(sb);
void clear(StringBuffer sb);
Usage:
clear(sb);
string getString(StringBuffer sb);
Usage:
str = getString(sb);