Showing the changes to interface/src/ScriptHighlighting.cpp (1 of 6 files). Show all
Unified · Split
| @@ -15,16 +15,16 @@ · 14 unmodified lines | ||
| 15 | 15 | ScriptHighlighting::ScriptHighlighting(QTextDocument* parent) : |
| 16 | 16 | QSyntaxHighlighter(parent) |
| 17 | 17 | { |
| 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"); | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | −void ScriptHighlighting::highlightBlock(const QString &text) { | |
| 27 | +void ScriptHighlighting::highlightBlock(const QString& text) { | |
| 28 | 28 | this->highlightKeywords(text); |
| 29 | 29 | this->formatNumbers(text); |
| 30 | 30 | this->formatTrueFalse(text); |
| @@ -32,62 +32,64 @@ void ScriptHighlighting::highlightBlock(const QString &text) { · 1 unmodified line | ||
| 32 | 32 | this->formatComments(text); |
| 33 | 33 | } |
| 34 | 34 | |
| 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); | |
| 37 | 37 | while (index >= 0) { |
| 38 | − int length = keywordRegex.matchedLength(); | |
| 38 | + int length = _keywordRegex.matchedLength(); | |
| 39 | 39 | setFormat(index, length, Qt::blue); |
| 40 | − index = keywordRegex.indexIn(text, index + length); | |
| 40 | + index = _keywordRegex.indexIn(text, index + length); | |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | −void ScriptHighlighting::formatComments(const QString &text) { | |
| 44 | +void ScriptHighlighting::formatComments(const QString& text) { | |
| 45 | 45 | |
| 46 | 46 | setCurrentBlockState(BlockStateClean); |
| 47 | 47 | |
| 48 | − int start = (previousBlockState() != BlockStateInMultiComment) ? text.indexOf(multiLineCommentBegin) : 0; | |
| 48 | + int start = (previousBlockState() != BlockStateInMultiComment) ? text.indexOf(_multiLineCommentBegin) : 0; | |
| 49 | 49 | |
| 50 | 50 | 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; | |
| 53 | 53 | 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 | + } | |
| 56 | 58 | } |
| 57 | 59 | |
| 58 | − int index = singleLineComment.indexIn(text); | |
| 60 | + int index = _singleLineComment.indexIn(text); | |
| 59 | 61 | while (index >= 0) { |
| 60 | − int length = singleLineComment.matchedLength(); | |
| 62 | + int length = _singleLineComment.matchedLength(); | |
| 61 | 63 | setFormat(index, length, Qt::lightGray); |
| 62 | − index = singleLineComment.indexIn(text, index + length); | |
| 64 | + index = _singleLineComment.indexIn(text, index + length); | |
| 63 | 65 | } |
| 64 | 66 | } |
| 65 | 67 | |
| 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); | |
| 68 | 70 | while (index >= 0) { |
| 69 | − int length = qoutedTextRegex.matchedLength(); | |
| 71 | + int length = _qoutedTextRegex.matchedLength(); | |
| 70 | 72 | setFormat(index, length, Qt::red); |
| 71 | − index = qoutedTextRegex.indexIn(text, index + length); | |
| 73 | + index = _qoutedTextRegex.indexIn(text, index + length); | |
| 72 | 74 | } |
| 73 | 75 | } |
| 74 | 76 | |
| 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); | |
| 77 | 79 | while (index >= 0) { |
| 78 | − int length = numberRegex.matchedLength(); | |
| 80 | + int length = _numberRegex.matchedLength(); | |
| 79 | 81 | setFormat(index, length, Qt::green); |
| 80 | − index = numberRegex.indexIn(text, index + length); | |
| 82 | + index = _numberRegex.indexIn(text, index + length); | |
| 81 | 83 | } |
| 82 | 84 | } |
| 83 | 85 | |
| 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); | |
| 86 | 88 | while (index >= 0) { |
| 87 | − int length = truefalseRegex.matchedLength(); | |
| 89 | + int length = _truefalseRegex.matchedLength(); | |
| 88 | 90 | QFont* font = new QFont(this->document()->defaultFont()); |
| 89 | 91 | font->setBold(true); |
| 90 | 92 | setFormat(index, length, *font); |
| 91 | − index = truefalseRegex.indexIn(text, index + length); | |
| 93 | + index = _truefalseRegex.indexIn(text, index + length); | |
| 92 | 94 | } |
| 93 | 95 | } |