Browse Source

refactor SPECIALS_TABLE

skytrias 2 years ago
parent
commit
63a0395a79
1 changed files with 13 additions and 3 deletions
  1. 13 3
      core/text/match/strlib.odin

+ 13 - 3
core/text/match/strlib.odin

@@ -558,13 +558,23 @@ push_captures :: proc(
 
 // SPECIALS := "^$*+?.([%-"
 // all special characters inside a small ascii array
-SPECIALS_TABLE := [256]u8 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+SPECIALS_TABLE := [256]bool {
+	'^' = true,
+	'$' = true,
+	'*' = true,
+	'+' = true,
+	'?' = true,
+	'.' = true,
+	'(' = true,
+	'[' = true,
+	'%' = true,
+	'-' = true,
+}
 
 // helper call to quick search for special characters
 index_special :: proc(text: string) -> int {
-	// TODO is this utf8 safe?
 	for i in 0..<len(text) {
-		if SPECIALS_TABLE[text[i]] == 1 {
+		if SPECIALS_TABLE[text[i]] {
 			return i
 		}
 	}