feisty meow concerns codebase
2.140
|
Supports simple XML output with consistency checking. More...
#include <xml_generator.h>
Public Types | |
enum | behavioral_mods { HUMAN_READABLE = 0x1 , CLEAN_ILLEGAL_CHARS = 0x2 } |
enum | outcomes { OKAY = basis::common::OKAY , NOT_FOUND = basis::common::NOT_FOUND , ERRONEOUS_TAG = basis::common::INVALID } |
the possible ways that operations here can complete. More... | |
Public Member Functions | |
xml_generator (int modifiers=HUMAN_READABLE|CLEAN_ILLEGAL_CHARS) | |
creates an xml generator with the specified behavior. More... | |
virtual | ~xml_generator () |
DEFINE_CLASS_NAME ("xml_generator") | |
void | reset () |
throws out all accumulated information. More... | |
basis::astring | generate () |
writes the current state into a string and returns it. More... | |
void | generate (basis::astring &generated) |
synonym method, writes the current state into "generated". More... | |
basis::outcome | add_header (const basis::astring &tag_name, const structures::string_table &attributes) |
adds an xml style header with the "tag_name" and "attributes". More... | |
basis::outcome | open_tag (const basis::astring &tag_name, const structures::string_table &attributes) |
adds a tag with "tag_name" and the "attributes", if any. More... | |
basis::outcome | open_tag (const basis::astring &tag_name) |
adds a tag with "tag_name" without any attributes. More... | |
basis::outcome | close_tag (const basis::astring &tag_name) |
closes a previously added "tag_name". More... | |
void | close_all_tags () |
a wide-bore method that closes all outstanding tags. More... | |
basis::outcome | add_content (const basis::astring &content) |
stores content into the currently opened tag. More... | |
void | set_indentation (int to_indent) |
sets the number of spaces to indent for the human readable form. More... | |
Static Public Member Functions | |
static const char * | outcome_name (const basis::outcome &to_name) |
reports the string version of "to_name". More... | |
static basis::astring | clean_reserved (const basis::astring &to_modify, bool replace_spaces=false) |
returns a cleaned version of "to_modify" to make it XML appropriate. More... | |
static void | clean_reserved_mod (basis::astring &to_modify, bool replace_spaces=false) |
ensures that "to_modify" contains only characters valid for XML. More... | |
Supports simple XML output with consistency checking.
Definition at line 29 of file xml_generator.h.
Enumerator | |
---|---|
HUMAN_READABLE | |
CLEAN_ILLEGAL_CHARS |
Definition at line 32 of file xml_generator.h.
the possible ways that operations here can complete.
Enumerator | |
---|---|
OKAY | |
NOT_FOUND | |
ERRONEOUS_TAG |
Definition at line 45 of file xml_generator.h.
textual::xml_generator::xml_generator | ( | int | modifiers = HUMAN_READABLE | CLEAN_ILLEGAL_CHARS | ) |
creates an xml generator with the specified behavior.
Definition at line 55 of file xml_generator.cpp.
|
virtual |
Definition at line 64 of file xml_generator.cpp.
References basis::WHACK().
outcome textual::xml_generator::add_content | ( | const basis::astring & | content | ) |
stores content into the currently opened tag.
it is an error to add content when no tag is open.
Definition at line 145 of file xml_generator.cpp.
References clean_reserved(), textual::string_manipulation::indentation(), OKAY, and textual::parser_bits::platform_eol_to_chars().
outcome textual::xml_generator::add_header | ( | const basis::astring & | tag_name, |
const structures::string_table & | attributes | ||
) |
adds an xml style header with the "tag_name" and "attributes".
headers can be located anywhere in the file.
Definition at line 112 of file xml_generator.cpp.
References OKAY.
|
static |
returns a cleaned version of "to_modify" to make it XML appropriate.
if "replace_spaces" is true, then any spaces will be turned into their html code equivalent; this helps in attribute names.
Definition at line 251 of file xml_generator.cpp.
References clean_reserved_mod().
Referenced by add_content().
|
static |
ensures that "to_modify" contains only characters valid for XML.
this is only different from the other clean method because this one modifies the string in place.
Definition at line 226 of file xml_generator.cpp.
References basis::astring::length(), and PLUGIN_REPLACEMENT.
Referenced by clean_reserved().
void textual::xml_generator::close_all_tags | ( | ) |
a wide-bore method that closes all outstanding tags.
Definition at line 138 of file xml_generator.cpp.
References close_tag().
Referenced by generate().
outcome textual::xml_generator::close_tag | ( | const basis::astring & | tag_name | ) |
closes a previously added "tag_name".
this will generate xml code like so:
note that it is an error to try to close any tag but the most recently opened one.
Definition at line 128 of file xml_generator.cpp.
References ERRONEOUS_TAG, NOT_FOUND, and OKAY.
Referenced by close_all_tags().
textual::xml_generator::DEFINE_CLASS_NAME | ( | "xml_generator" | ) |
astring textual::xml_generator::generate | ( | ) |
writes the current state into a string and returns it.
if there was an error during generation, the string will be empty. note that unclosed tags are not considered an error; they will simply be closed. note that the accumulated string is not cleared after the generate() invocation. use reset() to clear out all prior state.
Definition at line 91 of file xml_generator.cpp.
void textual::xml_generator::generate | ( | basis::astring & | generated | ) |
synonym method, writes the current state into "generated".
Definition at line 98 of file xml_generator.cpp.
References close_all_tags(), and textual::parser_bits::platform_eol_to_chars().
outcome textual::xml_generator::open_tag | ( | const basis::astring & | tag_name | ) |
adds a tag with "tag_name" without any attributes.
Definition at line 106 of file xml_generator.cpp.
References open_tag().
outcome textual::xml_generator::open_tag | ( | const basis::astring & | tag_name, |
const structures::string_table & | attributes | ||
) |
adds a tag with "tag_name" and the "attributes", if any.
this adds an item into the output string in the form:
it is required that you close the tag later on, after the tag's contents have been added.
Definition at line 120 of file xml_generator.cpp.
References OKAY.
Referenced by open_tag().
|
static |
reports the string version of "to_name".
Definition at line 70 of file xml_generator.cpp.
References ERRONEOUS_TAG, and basis::outcome::value().
void textual::xml_generator::reset | ( | ) |
throws out all accumulated information.
Definition at line 84 of file xml_generator.cpp.
References basis::astring::reset().
void textual::xml_generator::set_indentation | ( | int | to_indent | ) |
sets the number of spaces to indent for the human readable form.
Definition at line 78 of file xml_generator.cpp.