Commit 307ed227 authored by Nikita Sirgienko's avatar Nikita Sirgienko
Browse files

Merge branch 'l-scilab' into 'master'

[SciLab Backend] Port QRegExp to QRegularExpression

See merge request kde/cantor!10
parents 52a98c85 f3723197
......@@ -42,8 +42,8 @@ ScilabHighlighter::ScilabHighlighter(QObject* parent, Cantor::Session* session)
addRule(QRegularExpression(QStringLiteral("'[^']*'")), stringFormat());
addRule(QRegularExpression(QStringLiteral("//[^\n]*")), commentFormat());
commentStartExpression = QRegExp(QLatin1String("/\\*"));
commentEndExpression = QRegExp(QLatin1String("\\*/"));
commentStartExpression = QRegularExpression(QStringLiteral("/\\*"));
commentEndExpression = QRegularExpression(QStringLiteral("\\*/"));
}
void ScilabHighlighter::highlightBlock(const QString& text)
......@@ -59,22 +59,21 @@ void ScilabHighlighter::highlightBlock(const QString& text)
int startIndex = 0;
if (previousBlockState() != 1)
startIndex = commentStartExpression.indexIn(text);
startIndex = text.indexOf(commentStartExpression);
while (startIndex >= 0){
int endIndex = commentEndExpression.indexIn(text, startIndex);
QRegularExpressionMatch endMatch;
const int endIndex = text.indexOf(commentEndExpression, startIndex, &endMatch);
int commentLength;
if (endIndex == -1){
if (endIndex == -1) { // no match found
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex
+ commentEndExpression.matchedLength();
} else { // match found
// endMatch.catpuredEnd(0) is endIndex + endMatch.capturedLength(0)
commentLength = endMatch.capturedEnd(0) - startIndex;
}
setFormat(startIndex, commentLength, commentFormat());
startIndex = commentStartExpression.indexIn(text, startIndex + commentLength);
startIndex = text.indexOf(commentStartExpression, startIndex + commentLength);
}
}
......
......@@ -21,6 +21,8 @@
#ifndef _SCILABHIGHLIGHTER_H
#define _SCILABHIGHLIGHTER_H
#include <QRegularExpression>
#include "defaulthighlighter.h"
#include "scilabexpression.h"
......@@ -38,8 +40,8 @@ class ScilabHighlighter : public Cantor::DefaultHighlighter
private:
Cantor::Session* m_session;
QRegExp commentStartExpression;
QRegExp commentEndExpression;
QRegularExpression commentStartExpression;
QRegularExpression commentEndExpression;
};
#endif /* _SCILABHIGHLIGHTER_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment