TSDuck v3.40-3963
MPEG Transport Stream Toolkit
|
A support class for applications which parse various text formats. More...
#include <tsTextParser.h>
Classes | |
class | Position |
A class which describes a position in the document. More... | |
Public Member Functions | |
TextParser (const UString &text, Report &report) | |
Constructor. | |
TextParser (const UStringList &lines, Report &report) | |
Constructor. | |
TextParser (Report &report) | |
Constructor. | |
virtual | ~TextParser () |
Destructor. | |
virtual void | clear () |
Clear the document in the parser. | |
bool | eof () const |
Check end of file. | |
bool | eol () const |
Check end of line. | |
virtual bool | isAtNumberStart () const |
Check if the parser is at the start of a number (digit or minus sign). | |
bool | isAtPosition (const Position &pos) const |
Check if we are at the specified position in the document. | |
virtual bool | isAtXMLNameStart () const |
Check if the parser is at the start of an XML name. | |
virtual bool | isXMLNameChar (UChar c) const |
Check if a character is suitable in the middle of an XML name. | |
virtual bool | isXMLNameStartChar (UChar c) const |
Check if a character is suitable for starting an XML name. | |
size_t | lineNumber () const |
Get the current line number. | |
void | loadDocument (const UString &text) |
Load the document to parse. | |
void | loadDocument (const UStringList &lines) |
Load the document to parse from a list of lines. | |
bool | loadFile (const fs::path &fileName) |
Load the document to parse from a text file. | |
bool | loadStream (std::istream &strm) |
Load the document to parse from a text stream. | |
bool | match (const UString &str, bool skipIfMatch, CaseSensitivity cs=CASE_SENSITIVE) |
Check if the current position in the document matches a string. | |
virtual bool | parseJSONStringLiteral (UString &str) |
Parse a JSON string literal. | |
virtual bool | parseNumericLiteral (UString &str, bool allowHexa=false, bool allowFloat=true) |
Parse a numeric literal. | |
virtual bool | parseStringLiteral (UString &str, UChar requiredQuote=CHAR_NULL) |
Parse a string literal. | |
virtual bool | parseText (UString &result, const UString &endToken, bool skipIfMatch, bool translateEntities) |
Parse text up to a given token. | |
virtual bool | parseXMLName (UString &name) |
Parse an XML name. | |
Position | position () const |
Save the position in the document. | |
void | rewind () |
Rewind to start of document. | |
bool | saveFile (const fs::path &fileName) |
Save the document to parse to a text file. | |
bool | saveStream (std::ostream &strm) |
Save the document to parse to a text stream. | |
bool | seek (const Position &pos) |
Restore a previous position in the document. | |
bool | skipLine () |
Skip to next line. | |
bool | skipWhiteSpace () |
Skip all whitespaces, including end of lines. | |
A support class for applications which parse various text formats.
ts::TextParser::TextParser | ( | Report & | report | ) |
Constructor.
The document to parse is empty.
[in,out] | report | Where to report errors. |
ts::TextParser::TextParser | ( | const UStringList & | lines, |
Report & | report | ||
) |
Constructor.
[in] | lines | Reference 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] | report | Where to report errors. |
Constructor.
[in] | text | Document text to parse with embedded new-line characters. |
[in,out] | report | Where to report errors. |
void ts::TextParser::loadDocument | ( | const UStringList & | lines | ) |
Load the document to parse from a list of lines.
[in] | lines | Reference to a list of text lines forming the document. The lifetime of the referenced list must equals or exceeds the lifetime of the parser. |
void ts::TextParser::loadDocument | ( | const UString & | text | ) |
Load the document to parse.
[in] | text | Document text to parse with embedded new-line characters. |
bool ts::TextParser::loadFile | ( | const fs::path & | fileName | ) |
Load the document to parse from a text file.
[in] | fileName | Name of the file to load. |
bool ts::TextParser::loadStream | ( | std::istream & | strm | ) |
Load the document to parse from a text stream.
[in,out] | strm | A standard text stream in input mode. |
bool ts::TextParser::saveFile | ( | const fs::path & | fileName | ) |
Save the document to parse to a text file.
[in] | fileName | Name of the file to save. |
bool ts::TextParser::saveStream | ( | std::ostream & | strm | ) |
Save the document to parse to a text stream.
[in,out] | strm | A standard text stream in output mode. |
bool ts::TextParser::eof | ( | ) | const |
Check end of file.
bool ts::TextParser::eol | ( | ) | const |
Check end of line.
|
inline |
Save the position in the document.
bool ts::TextParser::seek | ( | const Position & | pos | ) |
Restore a previous position in the document.
[in] | pos | Previous position to restore. |
bool ts::TextParser::isAtPosition | ( | const Position & | pos | ) | const |
Check if we are at the specified position in the document.
[in] | pos | Previous position to check. |
|
inline |
Get the current line number.
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.
bool ts::TextParser::skipLine | ( | ) |
Skip to next line.
bool ts::TextParser::match | ( | const UString & | str, |
bool | skipIfMatch, | ||
CaseSensitivity | cs = CASE_SENSITIVE |
||
) |
Check if the current position in the document matches a string.
[in] | str | A string to check at the current position in the document. |
[in] | skipIfMatch | If true and str matches the current position, skip it in the document. |
[in] | cs | Case sensitivity of the comparision. |
|
virtual |
Parse text up to a given token.
[out] | result | Returned parsed text. |
[in] | endToken | Stop when this token is found. Do not include endToken in returned string. |
[in] | skipIfMatch | If true, skip endToken in the parser. |
[in] | translateEntities | If true, translate HTML entities in the text. |
|
virtual |
Check if a character is suitable for starting an XML name.
An XML name starts with a letter, underscore or colon.
[in] | c | The character to check. |
|
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.
[in] | c | The character to check. |
|
virtual |
Check if the parser is at the start of an XML name.
|
virtual |
Parse an XML name.
[out] | name | Returned parsed name. |
|
virtual |
Check if the parser is at the start of a number (digit or minus sign).
|
virtual |
Parse a numeric literal.
[out] | str | Returned numeric literal |
[in] | allowHexa | If true, hexadecimal integers "0x..." are allowed. |
[in] | allowFloat | It true, floating point values "[-]digits[.digits][e|E[+|-]digits]" are allowed. |
|
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.
[out] | str | Returned 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] | requiredQuote | If defined as single or double quote, accept only that type of quote. Otherwise, accept any of the two. |
|
virtual |
Parse a JSON string literal.
[out] | str | Returned decoded value of the string literal. |