StringBufferFormatter Class Reference
[Utils - String formatting]

A StringFormatter which stores the output text in a specified buffer. More...

#include <stringf.h>

Inheritance diagram for StringBufferFormatter:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 StringBufferFormatter (char *buffer, size_t size)
virtual void Out (const char *text, size_t textSize)
virtual void Out (char character, size_t repeatCount)
char * End ()

Protected Attributes

char * BufferStart
 Start of buffer used to store text.
char * BufferEnd
 End of buffer used to store text. (The address immediately after the last byte.).
char * BufferPtr
 Address to store the next byte of text to be 'output'.

Detailed Description

A StringFormatter which stores the output text in a specified buffer.

Example useage:

    char buffer[100];
    StringBufferFormatter formatter(buffer,sizeof(buffer));
    formatter.Format("Part %d,",1);
    formatter.Format("and append a %s part","second");
    char* end = formatter.End(); // appends NUL (if room) and resets formatter for new string
    size_t stringLength = end-buffer;

Important note: the produced string will only have a terminating null character if the produced text has a size less than the size of the buffer.

Definition at line 366 of file stringf.h.


Constructor & Destructor Documentation

StringBufferFormatter::StringBufferFormatter ( char *  buffer,
size_t  size 
)
Parameters:
buffer Address of the buffer to store the generated text in.
size Size of buffer.

Definition at line 633 of file stringf.cpp.


Member Function Documentation

void StringBufferFormatter::Out ( const char *  text,
size_t  textSize 
) [virtual]

Called to 'output' generated text.

Parameters:
text Pointer to text.
textSize Size of text.

Implements StringFormatter.

Definition at line 644 of file stringf.cpp.

void StringBufferFormatter::Out ( char  character,
size_t  repeatCount 
) [virtual]

Called to 'output' a repeated single character.

Parameters:
character The character to output.
repeatCount Number of times character should be output.

Implements StringFormatter.

Definition at line 656 of file stringf.cpp.

char * StringBufferFormatter::End (  ) 

Terminate text generation.

This appends a null character after the end of the generated text (if there is space in the buffer) and sets the buffer state to be empty.

Returns:
End of generated text. This is the address of the terminating null character, or the address immediately after the end of the buffer if the buffer was full.

Definition at line 668 of file stringf.cpp.


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.1