A simple parser for parsing XML-like tagged text.
More...
#include "nn/nlib/TaggedTextParser.h"
A simple parser for parsing XML-like tagged text.
- Description
- Use this function for parsing tagged text. It is suitable for reading the information from files such as those for simple settings, which are guaranteed to be correct.
- After instantiating the object, advance through the path using the
Next
function, and get the element names and the text using the GetText
function.
- The
TaggedTextParser
class has the following features.
-
The implementation is extremely compact and coded in just a header file of around 200 lines.
-
Rewrites the input text in memory as it runs. As a result, no additional memory is required.
-
Coding is simpler than a SAX format parser for a PULL-type parser.
-
Fast, because it does not construct DOM-like data.
- Note the following.
-
The parts corresponding to XML declarations, PI, and comments are skipped, but if the text is complicated the parser may fail.
-
The parts corresponding to XML attributes are skipped.
-
No support for escapes and the like.
-
Almost no checking of syntax is performed.
- For specification details, see the implementation of the header file. Sample code is provided below.
char text[] = "<doc > my text </toc >";
SUCCEED_IF(parser.Next() == nlib_ns::TaggedTextParser::kStartElement);
SUCCEED_IF(parser.Next() == nlib_ns::TaggedTextParser::kCharacters);
SUCCEED_IF(parser.Next() == nlib_ns::TaggedTextParser::kEndElement);
SUCCEED_IF(parser.Next() == nlib_ns::TaggedTextParser::kEndDocument);
Definition at line 23 of file TaggedTextParser.h.
◆ TaggedTextParser()
nn::nlib::TaggedTextParser::TaggedTextParser |
( |
char * |
tagged_text | ) |
|
|
inlineexplicit |
Instantiates the object.
- Parameters
-
[in,out] | tagged_text | The text string being parsed. |
- Description
- Note that the input text can be rewritten during the parsing process.
Definition at line 33 of file TaggedTextParser.h.
◆ GetText()
nn::nlib::TaggedTextParser::GetText |
( |
| ) |
const |
|
inline |
Returns the pointer to the character data obtained by the GetNext
function.
- Returns
- The obtained text string (element name and character data).
- Description
- Note that the pointer points to inside the input text. Also note that if the data is character data, any leading and trailing white spaces are removed from the text that is returned.
Definition at line 41 of file TaggedTextParser.h.
◆ Next()
nn::nlib::TaggedTextParser::Next |
( |
| ) |
|
|
inline |
Gets the next element or text.
- Return values
-
TaggedTextParser::kStartElement | Indicates a start tag. |
TaggedTextParser::kEndElement | Indicates an end tag. |
TaggedTextParser::kCharacters | Indicates character data. |
TaggedTextParser::kEndDocument | Indicates that the document has ended. |
TaggedTextParser::kSyntaxError | An error occurred. |
Definition at line 46 of file TaggedTextParser.h.
The documentation for this class was generated from the following files: