CStringBuilder Class Reference

A utility class for constructing C-style strings. More...

#include <CStringBuilder.h++>

List of all members.

Public Member Functions

 CStringBuilder (char *buf, size_t size)
 Construct a new CStringBuilder for the specified character buffer.
 ~CStringBuilder ()
 Destructor.
CStringBuilderclear ()
 Clear the buffer.
CStringBuilderappend (const char *s, size_t length=0)
 Append a C string to the buffer.
CStringBuilderappend (char c)
 Append a character to the buffer.
CStringBuilderappend (int val, size_t width, bool zeroPad=true)
 Append the string representation of a signed integer to the buffer.
CStringBuilderappend (uint_t val, size_t width, bool zeroPad=true)
 Append the string representation of an unsigned integer to the buffer.
char * getPosition () const
 Get a pointer to the current write position for the buffer.
size_t getRemaining () const
 Get the remaining capacity of the buffer, that is, the number of characters that can still be written.
bool hasRemaining () const
 Determine if the buffer has space remaining for additional characters.
size_t getLength () const
 Get the current length of the buffer, that is, the number of characters currently in the buffer.
size_t length () const
 Get the current length of the buffer, that is, the number of characters currently in the buffer.
char * c_str () const
 Get a pointer to the beginning of the buffer.
bool bump (size_t delta)
 Bump the write position by the given number of characters.
void terminate ()
 NUL-terminate the buffer.
CStringBuilderoperator+= (const char *s)
 Append operator.
CStringBuilderoperator+= (char c)
 Append operator.

Detailed Description

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.

Author:
Mark Lindner

Constructor & Destructor Documentation

CStringBuilder ( char *  buf,
size_t  size 
)

Construct a new CStringBuilder for the specified character buffer.

Parameters:
buf The buffer.
size The size of the buffer.
~CStringBuilder (  ) 

Destructor.


Member Function Documentation

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.

Parameters:
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 ( 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.

Parameters:
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 ( char  c  ) 

Append a character to the buffer.

CStringBuilder & append ( const char *  s,
size_t  length = 0 
)

Append a C string to the buffer.

Parameters:
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.
bool bump ( size_t  delta  ) 

Bump the write position by the given number of characters.

Parameters:
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.
char* c_str (  )  const [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.

size_t getLength (  )  const [inline]

Get the current length of the buffer, that is, the number of characters currently in the buffer.

char* getPosition (  )  const [inline]

Get a pointer to the current write position for the buffer.

size_t getRemaining (  )  const [inline]

Get the remaining capacity of the buffer, that is, the number of characters that can still be written.

bool hasRemaining (  )  const [inline]

Determine if the buffer has space remaining for additional characters.

size_t length (  )  const [inline]

Get the current length of the buffer, that is, the number of characters currently in the buffer.

CStringBuilder& operator+= ( char  c  )  [inline]

Append operator.

CStringBuilder& operator+= ( const char *  s  )  [inline]

Append operator.

void terminate (  ) 

NUL-terminate the buffer.


The documentation for this class was generated from the following files:
Generated on Sat Nov 26 16:49:08 2011 for libcommonc++ by  doxygen 1.6.3