diff --git a/autotests/folding/delimiters_WordDetect.delWordDetect.fold b/autotests/folding/delimiters_WordDetect.delWordDetect.fold new file mode 100644 --- /dev/null +++ b/autotests/folding/delimiters_WordDetect.delWordDetect.fold @@ -0,0 +1,47 @@ +# Highlight words +word1 +_word2 +/word3 +word4+ + +& +;;; +w w-word8- + +normal word1 +normal _word2 +normal /word3 +normal word4+ +normal +normal & +normal ;;; +normal w w-word8- + +....word1.... +...._word2.... +..../word3.... +....word4+.... +........ +....&.... +....;;;.... +....w w-word8-.... + +normal_word2 <-- _word2 +normal/word3 <-- /word3 +word4+normal <-- word4+ +normalnormal <-- +normal&normal <-- & +normal;;;normal <-- ;;; +w w-word8-normal <-- w w-word8- + +aaa_word2_aaa <-- _word2 +aaa/word3/aaa <-- /word3 +aaa+word4+aaa <-- word4+ +aaa-w w-word8-aaa <-- w w-word8- + +# Normal text +aaaword1aaa +aaa_word2aaa +aaa/word3aaa +aaaword4+aaa +aaaw w-word8-aaa diff --git a/autotests/html/delimiters_WordDetect.delWordDetect.html b/autotests/html/delimiters_WordDetect.delWordDetect.html new file mode 100644 --- /dev/null +++ b/autotests/html/delimiters_WordDetect.delWordDetect.html @@ -0,0 +1,54 @@ + + + +delimiters_WordDetect.delWordDetect + +
+# Highlight words
+word1
+_word2
+/word3
+word4+
+<word5>
+&
+;;;
+w w-word8-
+
+normal word1
+normal _word2
+normal /word3
+normal word4+
+normal <word5>
+normal &
+normal ;;;
+normal w w-word8-
+
+....word1....
+...._word2....
+..../word3....
+....word4+....
+....<word5>....
+....&....
+....;;;....
+....w w-word8-....
+
+normal_word2 <-- _word2
+normal/word3 <-- /word3
+word4+normal <-- word4+
+normal<word5>normal <-- <word5>
+normal&normal <-- &
+normal;;;normal <-- ;;;
+w w-word8-normal <-- w w-word8-
+
+aaa_word2_aaa <-- _word2
+aaa/word3/aaa <-- /word3
+aaa+word4+aaa <-- word4+
+aaa-w w-word8-aaa <-- w w-word8-
+
+# Normal text
+aaaword1aaa
+aaa_word2aaa
+aaa/word3aaa
+aaaword4+aaa
+aaaw w-word8-aaa
+
diff --git a/autotests/input/delimiters_WordDetect.delWordDetect b/autotests/input/delimiters_WordDetect.delWordDetect new file mode 100644 --- /dev/null +++ b/autotests/input/delimiters_WordDetect.delWordDetect @@ -0,0 +1,47 @@ +# Highlight words +word1 +_word2 +/word3 +word4+ + +& +;;; +w w-word8- + +normal word1 +normal _word2 +normal /word3 +normal word4+ +normal +normal & +normal ;;; +normal w w-word8- + +....word1.... +...._word2.... +..../word3.... +....word4+.... +........ +....&.... +....;;;.... +....w w-word8-.... + +normal_word2 <-- _word2 +normal/word3 <-- /word3 +word4+normal <-- word4+ +normalnormal <-- +normal&normal <-- & +normal;;;normal <-- ;;; +w w-word8-normal <-- w w-word8- + +aaa_word2_aaa <-- _word2 +aaa/word3/aaa <-- /word3 +aaa+word4+aaa <-- word4+ +aaa-w w-word8-aaa <-- w w-word8- + +# Normal text +aaaword1aaa +aaa_word2aaa +aaa/word3aaa +aaaword4+aaa +aaaw w-word8-aaa diff --git a/autotests/input/syntax/delimiters_WordDetect.xml b/autotests/input/syntax/delimiters_WordDetect.xml new file mode 100644 --- /dev/null +++ b/autotests/input/syntax/delimiters_WordDetect.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/autotests/reference/delimiters_WordDetect.delWordDetect.ref b/autotests/reference/delimiters_WordDetect.delWordDetect.ref new file mode 100644 --- /dev/null +++ b/autotests/reference/delimiters_WordDetect.delWordDetect.ref @@ -0,0 +1,47 @@ +# Highlight words
+word1
+_word2
+/word3
+word4+
+
+&
+;;;
+w w-word8-
+
+normal word1
+normal _word2
+normal /word3
+normal word4+
+normal
+normal &
+normal ;;;
+normal w w-word8-
+
+....word1....
+...._word2....
+..../word3....
+....word4+....
+........
+....&....
+....;;;....
+....w w-word8-....
+
+normal_word2 <-- _word2
+normal/word3 <-- /word3
+word4+normal <-- word4+
+normalnormal <--
+normal&normal <-- &
+normal;;;normal <-- ;;;
+w w-word8-normal <-- w w-word8-
+
+aaa_word2_aaa <-- _word2
+aaa/word3/aaa <-- /word3
+aaa+word4+aaa <-- word4+
+aaa-w w-word8-aaa <-- w w-word8-
+
+# Normal text
+aaaword1aaa
+aaa_word2aaa
+aaa/word3aaa
+aaaword4+aaa
+aaaw w-word8-aaa
diff --git a/data/syntax/elm.xml b/data/syntax/elm.xml --- a/data/syntax/elm.xml +++ b/data/syntax/elm.xml @@ -1,6 +1,6 @@ - + type @@ -40,7 +40,7 @@ - + diff --git a/data/syntax/selinux-cil.xml b/data/syntax/selinux-cil.xml --- a/data/syntax/selinux-cil.xml +++ b/data/syntax/selinux-cil.xml @@ -41,6 +41,7 @@ https://github.com/SELinuxProject/selinux/tree/master/secilc/docs Change log: + * Version 4 [03-Oct-2019]: Replace unnecessary WordDetect rules. * Version 3 [02-Apr-2019]: Remove one indentation. * Version 2 [28-Aug-2018]: - Implement "selinux.xml": some rules and keywords are moved there. Improve RegExp @@ -53,7 +54,7 @@ --> - - - - - + + + + + diff --git a/data/syntax/selinux-fc.xml b/data/syntax/selinux-fc.xml --- a/data/syntax/selinux-fc.xml +++ b/data/syntax/selinux-fc.xml @@ -42,6 +42,7 @@ - Policy Build Files: initial_sid_contexts, genfs_contexts, fs_use Change log: + * Version 5 [03-Oct-2019]: Replace unnecessary WordDetect rules. * Version 4 [02-Apr-2019]: Remove one indentation. * Version 3 [09-Sep-2018]: - Update itemData's style for the new Solarized color schemes. @@ -53,7 +54,7 @@ --> - + diff --git a/src/lib/rule.cpp b/src/lib/rule.cpp --- a/src/lib/rule.cpp +++ b/src/lib/rule.cpp @@ -652,13 +652,17 @@ if (text.size() - offset < m_word.size()) return offset; - if (offset > 0 && !isWordDelimiter(text.at(offset - 1))) + /** + * detect delimiter characters on the inner and outer boundaries of the string + * NOTE: m_word isn't empty + */ + if (offset > 0 && !isWordDelimiter(text.at(offset - 1)) && !isWordDelimiter(text.at(offset))) return offset; if (text.midRef(offset, m_word.size()).compare(m_word, m_caseSensitivity) != 0) return offset; - if (text.size() == offset + m_word.size() || isWordDelimiter(text.at(offset + m_word.size()))) + if (text.size() == offset + m_word.size() || isWordDelimiter(text.at(offset + m_word.size())) || isWordDelimiter(text.at(offset + m_word.size() - 1))) return offset + m_word.size(); return offset;