Class for generating formatted strings in a similar way to the C standard library function sprintf. More...
#include <stringf.h>

Classes | |
| class | ConversionSpec |
| Information about a single conversion specification. More... | |
Public Member Functions | |
| size_t | VFormat (const char *formatString, va_list args) |
| size_t | Format (const char *formatString,...) |
| size_t | HexDumpLine (const void *data, size_t size, ptrdiff_t addressOffset=0) |
Static Public Member Functions | |
| static char * | PushHex (ulonglong val, char *dst, int precision=-1, int x='x', int prefix=false) |
| static char * | PushOctal (ulonglong val, char *dst, int precision=-1, int prefix=false) |
| static char * | PushDecimal (ulonglong val, char *dst, int precision=-1) |
Static Public Attributes | |
| static const size_t | FormatTextBufferSize = 130 |
| static const size_t | HexDumpLineSize |
Protected Types | |
| enum | Flags { FlagMinus = 1<<0, FlagPlus = 1<<1, FlagSpace = 1<<2, FlagHash = 1<<3, FlagZero = 1<<4, LengthMod_hh = 1<<8, LengthMod_h = 1<<9, LengthMod_l = 1<<10, LengthMod_ll = 1<<11, LengthMod_L = 1<<12, LengthMod_unknown = 1<<13, SignedInt = 1<<15 } |
Protected Member Functions | |
| virtual void | Out (const char *text, size_t textSize)=0 |
| virtual void | Out (char character, size_t repeatCount)=0 |
| virtual char * | UnkownFormat (char *&dstEnd, ConversionSpec &spec) |
| char * | DefaultUnkownFormat (char *&dstEnd, ConversionSpec &spec) |
Friends | |
| class | StringFormatter::ConversionSpec |
Class for generating formatted strings in a similar way to the C standard library function sprintf.
The produced text is passed to the pure virtual Out(const char*,size_t) and Out(char,size_t) methods which are responsible for storing or outputing the string. For an example see StringBufferFormatter.
Supported conversion specifiers are:
Valid length modifiers are:
The default implementation correctly parses the following conversion specifiers (but produces no output)
Definition at line 79 of file stringf.h.
enum StringFormatter::Flags [protected] |
Flags indicating the format of a single conversion specification. See StringFormatter::ConversionSpec.
| size_t StringFormatter::VFormat | ( | const char * | formatString, | |
| va_list | args | |||
| ) |
Produce a formatted string.
| formatString | A string specifying the format of the string. This is specified in the same way as the C standard library sprintf function. | |
| args | The arguments for the formatted string. |
Definition at line 405 of file stringf.cpp.
| size_t StringFormatter::Format | ( | const char * | formatString, | |
| ... | ||||
| ) |
Produce a formatted string.
| formatString | A string specifying the format of the string. This is specified in the same way as the C standard library sprintf function. | |
| ... | The arguments for the formatted string. |
Definition at line 580 of file stringf.cpp.
Produce a single line of a hex dump. Each line represents the contents of up to 16 bytes.
The format of the text is like:
12345678 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 abcdefghijklmnop
| data | Address of data to be dumped. | |
| size | Size of data to be dumped. If >16 then only 16 bytes are dumped. | |
| addressOffset | Value to add to data for the address value to display in the dump. |
Definition at line 592 of file stringf.cpp.
| virtual void StringFormatter::Out | ( | const char * | text, | |
| size_t | textSize | |||
| ) | [protected, pure virtual] |
Called to 'output' generated text.
| text | Pointer to text. | |
| textSize | Size of text. |
Implemented in StringBufferFormatter.
| virtual void StringFormatter::Out | ( | char | character, | |
| size_t | repeatCount | |||
| ) | [protected, pure virtual] |
Called to 'output' a repeated single character.
| character | The character to output. | |
| repeatCount | Number of times character should be output. |
Implemented in StringBufferFormatter.
| char * StringFormatter::UnkownFormat | ( | char *& | dstEnd, | |
| ConversionSpec & | spec | |||
| ) | [protected, virtual] |
Called when an conversion specification is found which is not recognised.
The implementation of this method should produce text corresponding to the specified format, or handle it as an error in an implementation specific manner.
The default implementation of this method just calls DefaultUnkownFormat. If you wish to provide your own implementation, define the macro STRINGFORMATTER_UNKOWNFORMAT_DEFINED when compiling stringf.cpp, this will omit the implementation defined in that file.
| [in,out] | dstEnd | End of buffer where any generated text is stored. This is initialise to the end of a buffer of FormatTextBufferSize bytes which this function can optionally make use of. |
| spec | The decoded conversion specification which is to be handed. |
Definition at line 397 of file stringf.cpp.
| char * StringFormatter::DefaultUnkownFormat | ( | char *& | dstEnd, | |
| ConversionSpec & | spec | |||
| ) | [protected] |
Default implemenation for UnkownFormat.
This returns an empty sting and also discards any float type argument from args if the conversion specifier is any of 'a', 'A', 'e', 'E', 'f', 'F', 'g' or 'G'.
| [in,out] | dstEnd | End of buffer where any generated text is stored. This is left unchanged. |
| spec | The decoded conversion specification which is to be handed. |
Definition at line 372 of file stringf.cpp.
| char * StringFormatter::PushHex | ( | ulonglong | val, | |
| char * | dst, | |||
| int | precision = -1, |
|||
| int | x = 'x', |
|||
| int | prefix = false | |||
| ) | [static] |
Convert an unsigned integer into a hexadecimal numeric string.
The number is left padded with zeros if it contains less that precision digits, and is optionally prefixed by "0x".
| val | The value to convert. | |
| dst | The address of the character immediately after where the string is to be stored. I.e. this specifies where the string will end, not where it starts. | |
| precision | Minimum number of digits to store. A -ve value signifies 'use as many as required'. | |
| x | This must be either 'x' or 'X'. If 'x', all alphabetic characters are coverted in lower case, if 'X', they are coverted in upper case, | |
| prefix | If true, the converted value is prefixed with "0x". |
Definition at line 222 of file stringf.cpp.
| char * StringFormatter::PushOctal | ( | ulonglong | val, | |
| char * | dst, | |||
| int | precision = -1, |
|||
| int | prefix = false | |||
| ) | [static] |
Convert an unsigned integer into a octal numeric string.
The number is left padded with zeros if it contains less that precision digits.
| val | The value to convert. | |
| dst | The address of the character immediately after where the string is to be stored. I.e. this specifies where the string will end, not where it starts. | |
| precision | Minimum number of digits to store. A -ve value signifies 'use as many as required'. | |
| prefix | If true, the converted value is prefixed "0" if it doesn't already start with one. |
Definition at line 261 of file stringf.cpp.
| char * StringFormatter::PushDecimal | ( | ulonglong | val, | |
| char * | dst, | |||
| int | precision = -1 | |||
| ) | [static] |
Convert an unsigned integer into a decimal numeric string.
The number is left padded with zeros if it contains less that precision digits.
| val | The value to convert. | |
| dst | The address of the character immediately after where the string is to be stored. I.e. this specifies where the string will end, not where it starts. | |
| precision | Minimum number of digits to store. A -ve value signifies 'use as many as required'. |
Definition at line 289 of file stringf.cpp.
const size_t StringFormatter::FormatTextBufferSize = 130 [static] |
const size_t StringFormatter::HexDumpLineSize [static] |
Size of buffer required for HexDumpLine.
1.6.1