@@ -2,6 +2,7 @@ package com.tool.tree.ui
22
33import android.graphics.Typeface
44import android.text.Editable
5+ import android.text.Spanned
56import android.text.TextWatcher
67import android.text.style.ForegroundColorSpan
78import android.text.style.StyleSpan
@@ -115,7 +116,7 @@ abstract class BaseSyntaxHighlighter(
115116 ForegroundColorSpan (color),
116117 start,
117118 safeEnd,
118- Editable .SPAN_EXCLUSIVE_EXCLUSIVE
119+ Spanned .SPAN_EXCLUSIVE_EXCLUSIVE
119120 )
120121 }
121122
@@ -126,7 +127,7 @@ abstract class BaseSyntaxHighlighter(
126127 StyleSpan (Typeface .BOLD ),
127128 start,
128129 safeEnd,
129- Editable .SPAN_EXCLUSIVE_EXCLUSIVE
130+ Spanned .SPAN_EXCLUSIVE_EXCLUSIVE
130131 )
131132 }
132133
@@ -167,41 +168,41 @@ class ShellSyntaxHighlighter(editText: EditText) : BaseSyntaxHighlighter(
167168 val s = text.toString()
168169
169170 // Comments
170- Regex (" (?m)#.*$" ).findAll(s).forEach {
171+ Regex (""" (?m)#.*$"" " ).findAll(s).forEach {
171172 color(text, it.range.first, it.range.last + 1 , commentColor())
172173 }
173174
174175 // Strings: double quotes, single quotes, backticks
175- Regex (" \" (?:\\ .|[^\ " ])*\ "" ).findAll(s).forEach {
176+ Regex (""" " (?:\\.|[^"])*" " "" ).findAll(s).forEach {
176177 color(text, it.range.first, it.range.last + 1 , stringColor())
177178 }
178- Regex (" '(?:[^']*)'" ).findAll(s).forEach {
179+ Regex (""" '(?:[^']*)'"" " ).findAll(s).forEach {
179180 color(text, it.range.first, it.range.last + 1 , stringColor())
180181 }
181- Regex (" `(?:\\ .|[^`])*`" ).findAll(s).forEach {
182+ Regex (""" `(?:\\.|[^`])*`"" " ).findAll(s).forEach {
182183 color(text, it.range.first, it.range.last + 1 , stringColor())
183184 }
184185
185186 // Command substitution
186- Regex (" \\ $ \\ ((?:[^()]*|\\ ([^()]*\\ ))*\\ ) " ).findAll(s).forEach {
187+ Regex (""" \$\ ((?:[^()]*|\([^()]*\))*\) "" " ).findAll(s).forEach {
187188 color(text, it.range.first, it.range.last + 1 , builtinColor())
188189 }
189190
190191 // Variables
191- Regex (" \\ $\{ [A-Za-z_][A-Za-z0-9_]*[^}]*}" ).findAll(s).forEach {
192+ Regex (""" \ $\{[A-Za-z_][A-Za-z0-9_]*[^}]*}"" " ).findAll(s).forEach {
192193 color(text, it.range.first, it.range.last + 1 , numberColor())
193194 }
194- Regex (" \\ $[A-Za-z_][A-Za-z0-9_]*" ).findAll(s).forEach {
195+ Regex (""" \ $[A-Za-z_][A-Za-z0-9_]*"" " ).findAll(s).forEach {
195196 color(text, it.range.first, it.range.last + 1 , numberColor())
196197 }
197198
198199 // Numbers
199- Regex (" (?<![A-Za-z0-9_])(?:0x[0-9A-Fa-f]+|[0-9]+)(?![A-Za-z0-9_])" ).findAll(s).forEach {
200+ Regex (""" (?<![A-Za-z0-9_])(?:0x[0-9A-Fa-f]+|[0-9]+)(?![A-Za-z0-9_])"" " ).findAll(s).forEach {
200201 color(text, it.range.first, it.range.last + 1 , numberColor())
201202 }
202203
203204 // Keywords / builtins
204- Regex (" (?<![A-Za-z0-9_])([A-Za-z_][A-Za-z0-9_]*)(?![A-Za-z0-9_])" ).findAll(s).forEach {
205+ Regex (""" (?<![A-Za-z0-9_])([A-Za-z_][A-Za-z0-9_]*)(?![A-Za-z0-9_])"" " ).findAll(s).forEach {
205206 val word = it.value
206207 when {
207208 keywords.contains(word) -> {
@@ -213,7 +214,7 @@ class ShellSyntaxHighlighter(editText: EditText) : BaseSyntaxHighlighter(
213214 }
214215
215216 // Punctuation/operators
216- Regex (" &&|\|\| |\\ ||;|\\ (|\\ )|\\ {|\\ }|\\ [ \\ [|\\ ] \\ ]|<|>" ).findAll(s).forEach {
217+ Regex (""" &&|\|\||\||;|\(|\)|\{|\}|\[\ [|\]\ ]|<|>"" " ).findAll(s).forEach {
217218 color(text, it.range.first, it.range.last + 1 , punctuationColor())
218219 }
219220 }
@@ -233,38 +234,38 @@ class XmlSyntaxHighlighter(editText: EditText) : BaseSyntaxHighlighter(
233234 val s = text.toString()
234235
235236 // XML comments
236- Regex (" (?s)<!--.*?-->" ).findAll(s).forEach {
237+ Regex (""" (?s)<!--.*?-->"" " ).findAll(s).forEach {
237238 color(text, it.range.first, it.range.last + 1 , commentColor())
238239 }
239240
240241 // CDATA
241- Regex (" (?s)<!\[ CDATA\[ .*?\]\] >" ).findAll(s).forEach {
242+ Regex (""" (?s)<!\[CDATA\[.*?\]\]>"" " ).findAll(s).forEach {
242243 color(text, it.range.first, it.range.last + 1 , stringColor())
243244 }
244245
245246 // Tags
246- Regex (" </?[A-Za-z_][A-Za-z0-9_:\\ -\. ]*" ).findAll(s).forEach {
247+ Regex (""" </?[A-Za-z_][A-Za-z0-9_:\-\.]*"" " ).findAll(s).forEach {
247248 color(text, it.range.first, it.range.last + 1 , keywordColor())
248249 bold(text, it.range.first, it.range.last + 1 )
249250 }
250251
251- // Attribute names
252- Regex (" \b [A-Za-z_][A-Za-z0-9_:\\ -\. ]*= (?=\" ) " ).findAll(s).forEach {
253- color(text, it.range.first, it.range.last, builtinColor())
252+ // Attribute names (the part before =")
253+ Regex (""" \b[A-Za-z_][A-Za-z0-9_:\-\.]*(?=\s*=) "" " ).findAll(s).forEach {
254+ color(text, it.range.first, it.range.last + 1 , builtinColor())
254255 }
255256
256257 // Attribute values
257- Regex (" \" (?:\\ .|[^\ " ])*\ "" ).findAll(s).forEach {
258+ Regex (""" " (?:\\.|[^"])*" " "" ).findAll(s).forEach {
258259 color(text, it.range.first, it.range.last + 1 , stringColor())
259260 }
260261
261262 // Entities
262- Regex (" &(?:amp|lt|gt|apos|quot|#x?[0-9A-Fa-f]+);" ).findAll(s).forEach {
263+ Regex (""" &(?:amp|lt|gt|apos|quot|#x?[0-9A-Fa-f]+);"" " ).findAll(s).forEach {
263264 color(text, it.range.first, it.range.last + 1 , numberColor())
264265 }
265266
266267 // Angle brackets / punctuation
267- Regex (" </?|/>|>" ).findAll(s).forEach {
268+ Regex (""" </?|/>|>"" " ).findAll(s).forEach {
268269 color(text, it.range.first, it.range.last + 1 , punctuationColor())
269270 }
270271 }
@@ -284,12 +285,12 @@ class PropSyntaxHighlighter(editText: EditText) : BaseSyntaxHighlighter(
284285 val s = text.toString()
285286
286287 // Comments
287- Regex (" (?m)^\s *[#!].*$" ).findAll(s).forEach {
288+ Regex (""" (?m)^\s*[#!].*$"" " ).findAll(s).forEach {
288289 color(text, it.range.first, it.range.last + 1 , commentColor())
289290 }
290291
291292 // Key = value
292- Regex (" (?m)^\s *([A-Za-z0-9_.-]+)(\s *=)" ).findAll(s).forEach {
293+ Regex (""" (?m)^\s*([A-Za-z0-9_.-]+)(\s*=)"" " ).findAll(s).forEach {
293294 val line = it.value
294295 val keyEnd = line.indexOf(' =' )
295296 if (keyEnd > 0 ) {
@@ -300,17 +301,17 @@ class PropSyntaxHighlighter(editText: EditText) : BaseSyntaxHighlighter(
300301 }
301302
302303 // Quoted values
303- Regex (" \" (?:\\ .|[^\ " ])*\ "" ).findAll(s).forEach {
304+ Regex (""" " (?:\\.|[^"])*" " "" ).findAll(s).forEach {
304305 color(text, it.range.first, it.range.last + 1 , stringColor())
305306 }
306307
307308 // Numbers
308- Regex (" (?<![A-Za-z0-9_])(?:0x[0-9A-Fa-f]+|[0-9]+)(?![A-Za-z0-9_])" ).findAll(s).forEach {
309+ Regex (""" (?<![A-Za-z0-9_])(?:0x[0-9A-Fa-f]+|[0-9]+)(?![A-Za-z0-9_])"" " ).findAll(s).forEach {
309310 color(text, it.range.first, it.range.last + 1 , numberColor())
310311 }
311312
312313 // Separators
313- Regex (" = " ).findAll(s).forEach {
314+ Regex (""" = "" " ).findAll(s).forEach {
314315 color(text, it.range.first, it.range.last + 1 , punctuationColor())
315316 }
316317 }
0 commit comments