libcommonc++
0.7
|
A utility class for constructing C-style strings. More...
#include <CStringBuilder.h++>
Public Member Functions | |
CStringBuilder (char *buf, size_t size) | |
Construct a new CStringBuilder for the specified character buffer. More... | |
~CStringBuilder () | |
Destructor. More... | |
CStringBuilder & | clear () |
Clear the buffer. More... | |
CStringBuilder & | append (const char *s, size_t length=0) |
Append a C string to the buffer. More... | |
CStringBuilder & | append (const CString &s, size_t length=0) |
Append a CString to the buffer. More... | |
CStringBuilder & | append (char c) |
Append a character to the buffer. More... | |
CStringBuilder & | append (int val, size_t width, bool zeroPad=true) |
Append the string representation of a signed integer to the buffer. More... | |
CStringBuilder & | append (uint_t val, size_t width, bool zeroPad=true) |
Append the string representation of an unsigned integer to the buffer. More... | |
char * | getPosition () const |
Get a pointer to the current write position for the buffer. More... | |
size_t | getRemaining () const |
Get the remaining capacity of the buffer, that is, the number of characters that can still be written. More... | |
bool | hasRemaining () const |
Determine if the buffer has space remaining for additional characters. More... | |
size_t | getLength () const |
Get the current length of the buffer, that is, the number of characters currently in the buffer. More... | |
size_t | length () const |
Get the current length of the buffer, that is, the number of characters currently in the buffer. More... | |
char * | c_str () const |
Get a pointer to the beginning of the buffer. More... | |
bool | bump (size_t delta) |
Bump the write position by the given number of characters. More... | |
void | terminate () |
NUL-terminate the buffer. More... | |
CStringBuilder & | operator+= (const char *s) |
Append operator. More... | |
CStringBuilder & | operator+= (char c) |
Append operator. More... | |
A utility class for constructing C-style strings.
CStringBuilder is a simple wrapper around a raw character buffer and provides some basic append operations which write strings and integer values into the buffer, but which will never write past the end of the buffer. When append operations have been completed, a call to the terminate() method should be made to write the final NUL terminator character, for which the final byte in the buffer is always reserved.
CStringBuilder | ( | char * | buf, |
size_t | size | ||
) |
Construct a new CStringBuilder for the specified character buffer.
buf | The buffer. |
size | The size of the buffer. |
~CStringBuilder | ( | ) |
Destructor.
CStringBuilder & append | ( | const char * | s, |
size_t | length = 0 |
||
) |
Append a C string to the buffer.
s | The string to append. |
length | The number of bytes to append, or 0 to append the entire string. If the buffer cannot accommodate the requested number of characters, the method appends as many characters as possible. |
CStringBuilder & append | ( | const CString & | s, |
size_t | length = 0 |
||
) |
Append a CString to the buffer.
s | The string to append. |
length | The number of bytes to append, or 0 to append the entire string. If the buffer cannot accommodate the requested number of characters, the method appends as many characters as possible. |
CStringBuilder & append | ( | char | c | ) |
Append a character to the buffer.
CStringBuilder & append | ( | int | val, |
size_t | width, | ||
bool | zeroPad = true |
||
) |
Append the string representation of a signed integer to the buffer.
If the buffer cannot accommodate the data, the request is ignored.
val | The value to append. |
width | The formatting width for the value. |
zeroPad | A flag indicating whether the value should be padded on the right with zeroes (true) or spaces (false). |
CStringBuilder & append | ( | uint_t | val, |
size_t | width, | ||
bool | zeroPad = true |
||
) |
Append the string representation of an unsigned integer to the buffer.
If the buffer cannot accommodate the data, the request is ignored.
val | The value to append. |
width | The formatting width for the value. |
zeroPad | A flag indicating whether the value should be padded on the right with zeroes (true) or spaces (false). |
bool bump | ( | size_t | delta | ) |
Bump the write position by the given number of characters.
delta | The number of characters by which to bump the write position. If the delta would move the write position past the end of the buffer, the request is ignored. |
|
inline |
Get a pointer to the beginning of the buffer.
CStringBuilder & clear | ( | ) |
Clear the buffer.
This method resets the write position to the beginning of the buffer.
|
inline |
Get the current length of the buffer, that is, the number of characters currently in the buffer.
|
inline |
Get a pointer to the current write position for the buffer.
|
inline |
Get the remaining capacity of the buffer, that is, the number of characters that can still be written.
|
inline |
Determine if the buffer has space remaining for additional characters.
|
inline |
Get the current length of the buffer, that is, the number of characters currently in the buffer.
|
inline |
Append operator.
|
inline |
Append operator.
void terminate | ( | ) |
NUL-terminate the buffer.