History

Style

Thijs Wenker committed 12 years ago

Commit c1ed38f1 parent 0e28ff26 files · +147 −131Browse files

Showing the changes to interface/src/ScriptHighlighting.cpp (1 of 6 files). Show all

Unified · Split

interface/src/ScriptHighlighting.cpp+35−33
@@ -15,16 +15,16 @@ · 14 unmodified lines
1515 ScriptHighlighting::ScriptHighlighting(QTextDocument* parent) :
1616 QSyntaxHighlighter(parent)
1717 {
18− keywordRegex = QRegExp("\\b(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with)\\b");
19− qoutedTextRegex = QRegExp("\".*\"");
20− multiLineCommentBegin = QRegExp("/\\*");
21− multiLineCommentEnd = QRegExp("\\*/");
22− numberRegex = QRegExp("[0-9]+(\\.[0-9]+){0,1}");
23− singleLineComment = QRegExp("//[^\n]*");
24− truefalseRegex = QRegExp("\\b(true|false)\\b");
18+ _keywordRegex = QRegExp("\\b(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with)\\b");
19+ _qoutedTextRegex = QRegExp("\".*\"");
20+ _multiLineCommentBegin = QRegExp("/\\*");
21+ _multiLineCommentEnd = QRegExp("\\*/");
22+ _numberRegex = QRegExp("[0-9]+(\\.[0-9]+){0,1}");
23+ _singleLineComment = QRegExp("//[^\n]*");
24+ _truefalseRegex = QRegExp("\\b(true|false)\\b");
2525 }
2626
27−void ScriptHighlighting::highlightBlock(const QString &text) {
27+void ScriptHighlighting::highlightBlock(const QString& text) {
2828 this->highlightKeywords(text);
2929 this->formatNumbers(text);
3030 this->formatTrueFalse(text);
@@ -32,62 +32,64 @@ void ScriptHighlighting::highlightBlock(const QString &text) { · 1 unmodified line
3232 this->formatComments(text);
3333 }
3434
35−void ScriptHighlighting::highlightKeywords(const QString &text) {
36− int index = keywordRegex.indexIn(text);
35+void ScriptHighlighting::highlightKeywords(const QString& text) {
36+ int index = _keywordRegex.indexIn(text);
3737 while (index >= 0) {
38− int length = keywordRegex.matchedLength();
38+ int length = _keywordRegex.matchedLength();
3939 setFormat(index, length, Qt::blue);
40− index = keywordRegex.indexIn(text, index + length);
40+ index = _keywordRegex.indexIn(text, index + length);
4141 }
4242 }
4343
44−void ScriptHighlighting::formatComments(const QString &text) {
44+void ScriptHighlighting::formatComments(const QString& text) {
4545
4646 setCurrentBlockState(BlockStateClean);
4747
48− int start = (previousBlockState() != BlockStateInMultiComment) ? text.indexOf(multiLineCommentBegin) : 0;
48+ int start = (previousBlockState() != BlockStateInMultiComment) ? text.indexOf(_multiLineCommentBegin) : 0;
4949
5050 while (start > -1) {
51− int end = text.indexOf(multiLineCommentEnd, start);
52− int length = (end == -1 ? text.length() : (end + multiLineCommentEnd.matchedLength())) - start;
51+ int end = text.indexOf(_multiLineCommentEnd, start);
52+ int length = (end == -1 ? text.length() : (end + _multiLineCommentEnd.matchedLength())) - start;
5353 setFormat(start, length, Qt::lightGray);
54− start = text.indexOf(multiLineCommentBegin, start + length);
55− if (end == -1) setCurrentBlockState(BlockStateInMultiComment);
54+ start = text.indexOf(_multiLineCommentBegin, start + length);
55+ if (end == -1) {
56+ setCurrentBlockState(BlockStateInMultiComment);
57+ }
5658 }
5759
58− int index = singleLineComment.indexIn(text);
60+ int index = _singleLineComment.indexIn(text);
5961 while (index >= 0) {
60− int length = singleLineComment.matchedLength();
62+ int length = _singleLineComment.matchedLength();
6163 setFormat(index, length, Qt::lightGray);
62− index = singleLineComment.indexIn(text, index + length);
64+ index = _singleLineComment.indexIn(text, index + length);
6365 }
6466 }
6567
66−void ScriptHighlighting::formatQoutedText(const QString &text){
67− int index = qoutedTextRegex.indexIn(text);
68+void ScriptHighlighting::formatQoutedText(const QString& text){
69+ int index = _qoutedTextRegex.indexIn(text);
6870 while (index >= 0) {
69− int length = qoutedTextRegex.matchedLength();
71+ int length = _qoutedTextRegex.matchedLength();
7072 setFormat(index, length, Qt::red);
71− index = qoutedTextRegex.indexIn(text, index + length);
73+ index = _qoutedTextRegex.indexIn(text, index + length);
7274 }
7375 }
7476
75−void ScriptHighlighting::formatNumbers(const QString &text){
76− int index = numberRegex.indexIn(text);
77+void ScriptHighlighting::formatNumbers(const QString& text){
78+ int index = _numberRegex.indexIn(text);
7779 while (index >= 0) {
78− int length = numberRegex.matchedLength();
80+ int length = _numberRegex.matchedLength();
7981 setFormat(index, length, Qt::green);
80− index = numberRegex.indexIn(text, index + length);
82+ index = _numberRegex.indexIn(text, index + length);
8183 }
8284 }
8385
84−void ScriptHighlighting::formatTrueFalse(const QString text){
85− int index = truefalseRegex.indexIn(text);
86+void ScriptHighlighting::formatTrueFalse(const QString& text){
87+ int index = _truefalseRegex.indexIn(text);
8688 while (index >= 0) {
87− int length = truefalseRegex.matchedLength();
89+ int length = _truefalseRegex.matchedLength();
8890 QFont* font = new QFont(this->document()->defaultFont());
8991 font->setBold(true);
9092 setFormat(index, length, *font);
91− index = truefalseRegex.indexIn(text, index + length);
93+ index = _truefalseRegex.indexIn(text, index + length);
9294 }
9395 }