|
|
A small and hopefully pretty efficient parser of HTML tags. No attempt what so ever is made trying to check the validity of the text so if you forget a closing > you will probably end up with an exception.
A simple traverser counting the number of paragraphs might look like this.
int paragraphs++; toHtml count("Paragraphs<P>And some</P><P>Dobedoo"); while(!count.eof()) { count.nextToken(); if (count.isTag()&&count.open()&&QString(count.tag())=="p") paragraphs++; } |
toHtml (const QCString &data)
| toHtml |
Create a HTML parser.
Parameters:
data | Data to parse. |
~toHtml ()
| ~toHtml |
void nextToken (void)
| nextToken |
Read the next token which can be either a open tag, close tag or text.
Observe that nextToken destroys the data it has parsed, so you can't search it later. Searhing must be done on an new toHtml, several serches can be made though on the same toHtml.
const char * value (const QCString &name)
| value |
Get value of a qualifier.
Parameters:
name | Name of qualifier in lowercase. |
Returns: Value of qualifier or NULL.
bool isTag (void)
| isTag |
Return true if current token is a tag.
Returns: True if tag.
bool open (void)
| open |
Return true if open tag. Only valid if isTag is true.
Returns: True if open tag.
QCString text (void)
| text |
Get bread text if available. Expands &# characters are expanded before returned. Only valid if isTag returns false.
Returns: The parsed text.
const char * tag (void)
| tag |
Get name of tag in lowercase. Only valid if isTag returns true.
Returns: Name of tag (Excluding / if close tag).
bool eof (void)
| eof |
Check if at end of data
Returns: True if at end of data.
bool search (const QCString &data,const QString &str)
| search |
[static]
Search data for a simple text.
Parameters:
data | Data to search. |
str | Substring to search for in data. |
QString escape (const QString &html)
| escape |
[static]
Escape text to be HTML.