diff options
author | Neil <nyamatongwe@gmail.com> | 2020-04-13 08:06:56 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2020-04-13 08:06:56 +1000 |
commit | 98fba9dcdd0b734e0788de4d731bd3dcf5ee9fc0 (patch) | |
tree | c3a81410095a73a45756f6b26f6b7ea3a24e797e | |
parent | 1769cc3907d3f06254053ab76bd9e827417f07cf (diff) | |
download | scintilla-mirror-98fba9dcdd0b734e0788de4d731bd3dcf5ee9fc0.tar.gz |
Hide implementation of EscapeSequence and use const. Add tests for escape
sequences.
-rw-r--r-- | lexers/LexCPP.cxx | 25 | ||||
-rw-r--r-- | lexilla/test/examples/cpp/x.cxx | 7 | ||||
-rw-r--r-- | lexilla/test/examples/cpp/x.cxx.styled | 7 |
3 files changed, 26 insertions, 13 deletions
diff --git a/lexers/LexCPP.cxx b/lexers/LexCPP.cxx index af60dce3a..09e5b1cb4 100644 --- a/lexers/LexCPP.cxx +++ b/lexers/LexCPP.cxx @@ -163,18 +163,14 @@ void highlightTaskMarker(StyleContext &sc, LexAccessor &styler, } } -struct EscapeSequence { - int digitsLeft; - CharacterSet setHexDigits; - CharacterSet setOctDigits; - CharacterSet setNoneNumeric; - CharacterSet *escapeSetValid; - EscapeSequence() { - digitsLeft = 0; - escapeSetValid = nullptr; - setHexDigits = CharacterSet(CharacterSet::setDigits, "ABCDEFabcdef"); - setOctDigits = CharacterSet(CharacterSet::setNone, "01234567"); - } +class EscapeSequence { + const CharacterSet setHexDigits = CharacterSet(CharacterSet::setDigits, "ABCDEFabcdef"); + const CharacterSet setOctDigits = CharacterSet(CharacterSet::setNone, "01234567"); + const CharacterSet setNoneNumeric; + const CharacterSet *escapeSetValid = nullptr; + int digitsLeft = 0; +public: + EscapeSequence() = default; void resetEscapeState(int nextChar) { digitsLeft = 0; escapeSetValid = &setNoneNumeric; @@ -195,6 +191,9 @@ struct EscapeSequence { bool atEscapeEnd(int currChar) const { return (digitsLeft <= 0) || !escapeSetValid->Contains(currChar); } + void consumeDigit() noexcept { + digitsLeft--; + } }; std::string GetRestOfLine(LexAccessor &styler, Sci_Position start, bool allowSpace) { @@ -1107,7 +1106,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i } break; case SCE_C_ESCAPESEQUENCE: - escapeSeq.digitsLeft--; + escapeSeq.consumeDigit(); if (!escapeSeq.atEscapeEnd(sc.ch)) { break; } diff --git a/lexilla/test/examples/cpp/x.cxx b/lexilla/test/examples/cpp/x.cxx index 8e42167b2..c1f052882 100644 --- a/lexilla/test/examples/cpp/x.cxx +++ b/lexilla/test/examples/cpp/x.cxx @@ -17,4 +17,11 @@ int main() { // JavaScript regular expression (14) tests let a = /a/; let b = /[a-z]+/gi; + + // Escape sequence (27) tests + printf("\'\"\?\\\a\b\f\n\r\t\v \P"); + printf("\0a \013a \019"); + printf("\x013ac \xdz"); + printf("\ua34df \uz"); + printf("\Ua34df7833 \Uz"); } diff --git a/lexilla/test/examples/cpp/x.cxx.styled b/lexilla/test/examples/cpp/x.cxx.styled index c269ed1b4..e4241eba2 100644 --- a/lexilla/test/examples/cpp/x.cxx.styled +++ b/lexilla/test/examples/cpp/x.cxx.styled @@ -17,4 +17,11 @@ {2}// JavaScript regular expression (14) tests {0} {5}let{0} {11}a{0} {10}={0} {14}/a/{10};{0} {5}let{0} {11}b{0} {10}={0} {14}/[a-z]+/gi{10};{0} + + {2}// Escape sequence (27) tests +{0} {11}printf{10}({6}"{27}\'\"\?\\\a\b\f\n\r\t\v{6} {27}\P{6}"{10});{0} + {11}printf{10}({6}"{27}\0{6}a {27}\013{6}a {27}\01{6}9"{10});{0} + {11}printf{10}({6}"{27}\x013a{6}c {27}\xd{6}z"{10});{0} + {11}printf{10}({6}"{27}\ua34d{6}f {27}\u{6}z"{10});{0} + {11}printf{10}({6}"{27}\Ua34df783{6}3 {27}\U{6}z"{10});{0} {10}}{0} |