Update jsedit.cpp

* Highlight hexadecimal numbers
This commit is contained in:
jogo-
2021-07-02 15:32:37 +02:00
committed by GitHub
parent 44de49af22
commit 59e387aad8
+15 -1
View File
@@ -266,7 +266,8 @@ void JSHighlighter::highlightBlock(const QString &text)
Identifier = 2,
String = 3,
Comment = 4,
Regex = 5
Regex = 5,
HexNumber = 6
};
QList<int> bracketPositions;
@@ -291,6 +292,10 @@ void JSHighlighter::highlightBlock(const QString &text)
start = i;
if (ch.isSpace()) {
++i;
} else if (ch == '0' && (next == 'x' || next == 'X')) {
++i;
++i;
state = HexNumber;
} else if (ch.isDigit()) {
++i;
state = Number;
@@ -334,6 +339,15 @@ void JSHighlighter::highlightBlock(const QString &text)
}
break;
case HexNumber:
if (ch.isSpace() || !(ch.isDigit() || QString("ABCDEF").contains(ch.toUpper()))) {
setFormat(start, i - start, m_colors[JSEdit::Number]);
state = Start;
} else {
++i;
}
break;
case Identifier:
if (ch.isSpace() || !(ch.isDigit() || ch.isLetter() || ch == '_')) {
QString token = text.mid(start, i - start).trimmed();