TSDuck v3.46-4930
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::TextParser Class Reference

#include <tsTextParser.h>

Classes

class  Position

Public Member Functions

 TextParser (const UString &text, Report &report)
 TextParser (const UStringList &lines, Report &report)
 TextParser (Report &report)
virtual ~TextParser ()
virtual void clear ()
bool eof () const
bool eol () const
virtual bool isAtNumberStart () const
bool isAtPosition (const Position &pos) const
virtual bool isAtXMLNameStart () const
virtual bool isXMLNameChar (UChar c) const
virtual bool isXMLNameStartChar (UChar c) const
size_t lineNumber () const
void loadDocument (const UString &text)
void loadDocument (const UStringList &lines)
bool loadFile (const fs::path &fileName)
bool loadStream (std::istream &strm)
bool match (const UString &str, bool skipIfMatch, CaseSensitivity cs=CASE_SENSITIVE)
virtual bool parseJSONStringLiteral (UString &str)
virtual bool parseNumericLiteral (UString &str, bool allowHexa=false, bool allowFloat=true)
virtual bool parseStringLiteral (UString &str, UChar requiredQuote=CHAR_NULL)
virtual bool parseText (UString &result, const UString &endToken, bool skipIfMatch, bool translateEntities)
virtual bool parseXMLName (UString &name)
const Position & position () const
void rewind ()
bool saveFile (const fs::path &fileName)
bool saveStream (std::ostream &strm)
bool seek (const Position &pos)
bool skipLine ()
bool skipWhiteSpace ()

Detailed Description

A support class for applications which parse various text formats.

Constructor & Destructor Documentation

◆ TextParser() [1/3]

ts::TextParser::TextParser ( Report & report)

Constructor. The document to parse is empty.

Parameters
[in,out]reportWhere to report errors.

◆ TextParser() [2/3]

ts::TextParser::TextParser ( const UStringList & lines,
Report & report )

Constructor.

Parameters
[in]linesReference to a list of text lines forming the document. The lifetime of the referenced list must equals or exceeds the lifetime of the parser.
[in,out]reportWhere to report errors.

◆ TextParser() [3/3]

ts::TextParser::TextParser ( const UString & text,
Report & report )

Constructor.

Parameters
[in]textDocument text to parse with embedded new-line characters.
[in,out]reportWhere to report errors.

◆ ~TextParser()

virtual ts::TextParser::~TextParser ( )
virtual

Destructor.

Member Function Documentation

◆ clear()

virtual void ts::TextParser::clear ( )
virtual

Clear the document in the parser.

◆ loadDocument() [1/2]

void ts::TextParser::loadDocument ( const UStringList & lines)

Load the document to parse from a list of lines.

Parameters
[in]linesReference to a list of text lines forming the document. The lifetime of the referenced list must equals or exceeds the lifetime of the parser.

◆ loadDocument() [2/2]

void ts::TextParser::loadDocument ( const UString & text)

Load the document to parse.

Parameters
[in]textDocument text to parse with embedded new-line characters.

◆ loadFile()

bool ts::TextParser::loadFile ( const fs::path & fileName)

Load the document to parse from a text file.

Parameters
[in]fileNameName of the file to load.
Returns
True on success, false on failure.

◆ loadStream()

bool ts::TextParser::loadStream ( std::istream & strm)

Load the document to parse from a text stream.

Parameters
[in,out]strmA standard text stream in input mode.
Returns
True on success, false on error.

◆ saveFile()

bool ts::TextParser::saveFile ( const fs::path & fileName)

Save the document to parse to a text file.

Parameters
[in]fileNameName of the file to save.
Returns
True on success, false on failure.

◆ saveStream()

bool ts::TextParser::saveStream ( std::ostream & strm)

Save the document to parse to a text stream.

Parameters
[in,out]strmA standard text stream in output mode.
Returns
True on success, false on error.

◆ eof()

bool ts::TextParser::eof ( ) const

Check end of file.

Returns
True if the parser reached the end of file.

◆ eol()

bool ts::TextParser::eol ( ) const

Check end of line.

Returns
True if the parser reached the end of line.

◆ rewind()

void ts::TextParser::rewind ( )

Rewind to start of document.

◆ position()

const Position & ts::TextParser::position ( ) const
inline

Save the position in the document.

Returns
A constant reference to the current position in the document.

◆ seek()

bool ts::TextParser::seek ( const Position & pos)

Restore a previous position in the document.

Parameters
[in]posPrevious position to restore.
Returns
True on success, false on error.

◆ isAtPosition()

bool ts::TextParser::isAtPosition ( const Position & pos) const

Check if we are at the specified position in the document.

Parameters
[in]posPrevious position to check.
Returns
True if still at this position.

◆ lineNumber()

size_t ts::TextParser::lineNumber ( ) const
inline

Get the current line number.

Returns
The current line number.

◆ skipWhiteSpace()

bool ts::TextParser::skipWhiteSpace ( )

Skip all whitespaces, including end of lines. Note that the optional BOM at start of an UTF-8 file has already been removed by the UTF-16 conversion.

Returns
Always true.

◆ skipLine()

bool ts::TextParser::skipLine ( )

Skip to next line.

Returns
Always true.

◆ match()

bool ts::TextParser::match ( const UString & str,
bool skipIfMatch,
CaseSensitivity cs = CASE_SENSITIVE )

Check if the current position in the document matches a string.

Parameters
[in]strA string to check at the current position in the document.
[in]skipIfMatchIf true and str matches the current position, skip it in the document.
[in]csCase sensitivity of the comparision.
Returns
True if str matches the current position in the document.

◆ parseText()

virtual bool ts::TextParser::parseText ( UString & result,
const UString & endToken,
bool skipIfMatch,
bool translateEntities )
virtual

Parse text up to a given token.

Parameters
[out]resultReturned parsed text.
[in]endTokenStop when this token is found. Do not include endToken in returned string.
[in]skipIfMatchIf true, skip endToken in the parser.
[in]translateEntitiesIf true, translate HTML entities in the text.
Returns
True on success, false if endToken was not found.

◆ isXMLNameStartChar()

virtual bool ts::TextParser::isXMLNameStartChar ( UChar c) const
virtual

Check if a character is suitable for starting an XML name. An XML name starts with a letter, underscore or colon.

Parameters
[in]cThe character to check.
Returns
True if c is suitable for starting an XML name.

◆ isXMLNameChar()

virtual bool ts::TextParser::isXMLNameChar ( UChar c) const
virtual

Check if a character is suitable in the middle of an XML name. An XML name contains letters, digits, underscores, colons, dots and dashes.

Parameters
[in]cThe character to check.
Returns
True if c is suitable in the middle of an XML name.

◆ isAtXMLNameStart()

virtual bool ts::TextParser::isAtXMLNameStart ( ) const
virtual

Check if the parser is at the start of an XML name.

Returns
True if the parser is at the start of a name.

◆ parseXMLName()

virtual bool ts::TextParser::parseXMLName ( UString & name)
virtual

Parse an XML name.

Parameters
[out]nameReturned parsed name.
Returns
True on success, false if no name was not found.

◆ isAtNumberStart()

virtual bool ts::TextParser::isAtNumberStart ( ) const
virtual

Check if the parser is at the start of a number (digit or minus sign).

Returns
True if the parser is at the start of a number.

◆ parseNumericLiteral()

virtual bool ts::TextParser::parseNumericLiteral ( UString & str,
bool allowHexa = false,
bool allowFloat = true )
virtual

Parse a numeric literal.

Parameters
[out]strReturned numeric literal
[in]allowHexaIf true, hexadecimal integers "0x..." are allowed.
[in]allowFloatIt true, floating point values "[-]digits[.digits][e|E[+|-]digits]" are allowed.
Returns
True on success, false if no string literal was not found.

◆ parseStringLiteral()

virtual bool ts::TextParser::parseStringLiteral ( UString & str,
UChar requiredQuote = CHAR_NULL )
virtual

Parse a string literal. A string literal is enclosed in simple or double quotes. Any similar quotation mark is considered part of the string when it is preceded by a backslash character.

Parameters
[out]strReturned string literal, including the first and last quote. When the method returns true (success), it is consequently guaranteed that the length of the returned string is greater than or equal to 2.
[in]requiredQuoteIf defined as single or double quote, accept only that type of quote. Otherwise, accept any of the two.
Returns
True on success, false if no string literal was not found.

◆ parseJSONStringLiteral()

virtual bool ts::TextParser::parseJSONStringLiteral ( UString & str)
virtual

Parse a JSON string literal.

Parameters
[out]strReturned decoded value of the string literal.
Returns
True on success, false if no string literal was not found.

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