TrinityCore
|
#include <TextOutput.h>
Classes | |
class | Settings |
Public Member Functions | |
TextOutput (const std::string &filename, const Settings &options=Settings()) | |
TextOutput (const Settings &options=Settings()) | |
int | line () const |
void | commit (bool flush=true) |
void | commitString (std::string &string) |
void | pushIndent () |
void | popIndent () |
std::string | commitString () |
void | writeString (const std::string &string) |
void | writeBoolean (bool b) |
void | writeNumber (double n) |
void | writeNumber (int n) |
void | writeNewline () |
void | writeNewlines (int numLines) |
bool | deleteSpace () |
void | writeSymbol (const std::string &string) |
void | writeSymbol (char s) |
void | writeSymbols (const std::string &a, const std::string &b="", const std::string &c="", const std::string &d="", const std::string &e="", const std::string &f="") |
void __cdecl | printf (const char *fmt,...) G3D_CHECK_PRINTF_METHOD_ARGS |
void __cdecl | printf (const std::string fmt,...) |
void __cdecl | vprintf (const char *fmt, va_list argPtr) G3D_CHECK_VPRINTF_METHOD_ARGS |
Private Member Functions | |
void | setIndentLevel (int i) |
void | setOptions (const Settings &_opt) |
void | convertNewlines (const std::string &in, std::string &out) |
void | wordWrapIndentAppend (const std::string &str) |
void | indentAppend (char c) |
Private Attributes | |
bool | startingNewLine |
int | currentColumn |
bool | inDQuote |
std::string | filename |
Array< char > | data |
Settings | option |
int | indentLevel |
int | indentSpaces |
std::string | newline |
int | m_currentLine |
Convenient formatting of ASCII text written to a file.
The core writeString, writeNumber, and writeSymbol methods map to TextInput's methods. Number and Symbol each print an additional space that is used to separate adjacent tokens.
TextOutput::printf allows arbitrary text to be conveniently dumped en-masse. Use [de]serialize(bool, TextOutput) and other overloads to read/write primitive types in a standardized manner and
When a word-wrap line break occurs, all whitespace between words is replaced with a single newline (the newline may be two characters– see G3D::TextOutput::Options::NewlineStyle). Word wrapping occurs against the number of columns specified by Options::numColumns, minus the current indent level.
Indenting adds the specified number of spaces immediately after a newline. If a newline was followed by spaces in the original string, these are added to the indent spaces. Indenting will indent blank lines and will leave indents after the last newline of a file (if the indent level is non-zero at the end).
Serialization/Marshalling
Text serialization is accomplished using TextOutput by defining the pair of methods:
void serialize(TextOutput& to) const; void deserialize(TextInput& ti);
See also G3D::TextInput.
BETA API
This API is subject to change in future versions.
|
explicit |
Constructs a text output that can later be commited to a string instead of a file.
Commit to the filename specified on the constructor. Not called from the destructor; you must call it yourself.
flush | If true (default) the file is ready for reading when the method returns, otherwise the method returns immediately and writes the file in the background. |
void G3D::TextOutput::commitString | ( | std::string & | string | ) |
Commits to this string
std::string G3D::TextOutput::commitString | ( | ) |
Produces a new string that contains the output
|
private |
Converts to the desired newlines. Called from vprintf
bool G3D::TextOutput::deleteSpace | ( | ) |
If the most recently written character was a space, remove it and return true. Can be called repeatedly to back up over multiple spaces.
|
private |
Appends the character to data, indenting whenever a newline is encountered. Called from wordWrapIndentAppend
|
inline |
Returns one plus the number of newlines written since the output was created.
void G3D::TextOutput::popIndent | ( | ) |
void G3D::TextOutput::printf | ( | const char * | fmt, |
... | |||
) |
Normal printf conventions. Note that the output will be reformatted for word-wrapping and newlines
void G3D::TextOutput::printf | ( | const std::string | fmt, |
... | |||
) |
void G3D::TextOutput::pushIndent | ( | ) |
Increase indent level by 1
|
private |
void G3D::TextOutput::vprintf | ( | const char * | fmt, |
va_list | argPtr | ||
) |
|
private |
Called from vprintf
void G3D::TextOutput::writeBoolean | ( | bool | b | ) |
void G3D::TextOutput::writeNewline | ( | ) |
void G3D::TextOutput::writeNewlines | ( | int | numLines | ) |
void G3D::TextOutput::writeNumber | ( | double | n | ) |
void G3D::TextOutput::writeNumber | ( | int | n | ) |
void G3D::TextOutput::writeString | ( | const std::string & | string | ) |
Writes a quoted string. Special characters in the string (e.g., \, \t, \n) are escaped so that TextInput will produce the identical string on reading.
void G3D::TextOutput::writeSymbol | ( | const std::string & | string | ) |
The symbol is written without quotes. Symbols are required to begin with a letter or underscore and contain only letters, underscores, and numbers or be a C++ symbol (e.g. "{", "(", "++", etc.) so that they may be properly parsed by TextInput::readSymbol. Symbols are printed with a trailing space.
void G3D::TextOutput::writeSymbol | ( | char | s | ) |
void G3D::TextOutput::writeSymbols | ( | const std::string & | a, |
const std::string & | b = "" , |
||
const std::string & | c = "" , |
||
const std::string & | d = "" , |
||
const std::string & | e = "" , |
||
const std::string & | f = "" |
||
) |
Convenient idiom for writing multiple symbols in a row, e.g. writeSymbols("name", "="); The empty symbols are not written.
|
private |
Number of characters at the end of the buffer since the last newline
|
private |
|
private |
Empty if there is none
|
private |
Number of indents to prepend before each line. Always set using setIndentLevel.
|
private |
Actual number of spaces to indent.
|
private |
True if we have seen an open " and no close ".
|
private |
Starts at 1
|
private |
the newline character(s)
|
private |
|
private |
Used by indentAndAppend to tell when we are writing the first character of a new line.
So that push/popIndent work correctly, we cannot indent immediately after writing a newline. Instead we must indent on writing the first character after that newline.