nlib
nn::nlib::TaggedTextParser Class Referencefinal

A simple parser for parsing XML-like tagged text. More...

#include "nn/nlib/TaggedTextParser.h"

Public Member Functions

 TaggedTextParser (char *tagged_text)
 Instantiates the object. More...
 
const char * GetText () const
 Returns the pointer to the character data obtained by the GetNext function. More...
 
Event Next ()
 Gets the next element or text. More...
 

Detailed Description

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.
// Strings are rewritten, so you cannot make them const char.
char text[] = "<doc > my text </toc >";
TaggedTextParser parser(text);
parser.Next(); // TaggedTextParser::START_ELEMENT
parser.GetText(); // "doc"
parser.Next(); // TaggedTextParser::CHARACTERS
parser.GetText(); // "my text"
parser.Next(); // TaggedTextParser::END_ELEMENT
parser.GetText(); // "toc"
parser.Next(); // TaggedTextParser::END_DOCUMENT

Definition at line 10 of file TaggedTextParser.h.

Constructor & Destructor Documentation

§ TaggedTextParser()

nn::nlib::TaggedTextParser::TaggedTextParser ( char *  tagged_text)
inlineexplicit

Instantiates the object.

Parameters
[in,out]tagged_textThe text string being parsed.
Description
Note that the input text can be rewritten during the parsing process.

Definition at line 20 of file TaggedTextParser.h.

Member Function Documentation

§ 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 28 of file TaggedTextParser.h.

§ Next()

nn::nlib::TaggedTextParser::Next ( )
inline

Gets the next element or text.

Return values
TaggedTextParser::START_ELEMENTIndicates a start tag.
TaggedTextParser::END_ELEMENTIndicates an end tag.
TaggedTextParser::CHARACTERSIndicates character data.
TaggedTextParser::END_DOCUMENTIndicates that the document has ended.
TaggedTextParser::SYNTAX_ERRORAn error occurred.

Definition at line 33 of file TaggedTextParser.h.


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