What is expected input just a giant string of characters that you need to split up?
a program code on specific (not widely known) programming language placed inside QPlainTextEdit
highlighted keywords of this language, they are placed inside wordsQStringList - this is mandatory and cannot be changed (the most important reason is - number of keywords can be different and they can be written on different human languages, not only by Latin characters and can include not only letters or digits, it is imported from outside highlighter and must be used inside highlighter)
highlighting is implemented as
void Syntaxer
::highlightBlock(const QString &text
) {
foreach( HighRule rule, highlightRules )
{
QRegExp expression
( rule.
pattern );
int index = expression.indexIn( text );
while( index >= 0 )
{ // probably there is bug in indexIn, it returns zero even if text not found
int length = expression.matchedLength();
if( !length )
break;
setFormat( index, length, rule.format );
index = expression.indexIn( text, index + length );
}
}
}
void Syntaxer::highlightBlock(const QString &text)
{
foreach( HighRule rule, highlightRules )
{
QRegExp expression( rule.pattern );
int index = expression.indexIn( text );
while( index >= 0 )
{ // probably there is bug in indexIn, it returns zero even if text not found
int length = expression.matchedLength();
if( !length )
break;
setFormat( index, length, rule.format );
index = expression.indexIn( text, index + length );
}
}
}
To copy to clipboard, switch view to plain text mode
as recommended in Qt examples. The exactMatch cannot be used cause text can contain different number of keywords.
all other things work fine, they are debugged and cannot be changed - I only need create a rule to highlight those keywords, but I'm not a keen in Regular Expressions
Bookmarks