Ver Fonte

Fix captures not begin zeroed when haystack length is 0

James Duran há 7 meses atrás
pai
commit
13640620ce
1 ficheiros alterados com 6 adições e 6 exclusões
  1. 6 6
      core/text/match/strlib.odin

+ 6 - 6
core/text/match/strlib.odin

@@ -698,11 +698,11 @@ gmatch :: proc(
 			first := length > 1 ? 1 : 0
 			cap := captures[first]
 			res = haystack[cap.byte_start:cap.byte_end]
-		} else {
-			captures^ = {}
 		}
 	} 
-
+	if !ok {
+		captures^ = {}
+	}
 	return
 }
 
@@ -813,11 +813,11 @@ gfind :: proc(
 			ok = true
 			cap := captures[0]
 			res = haystack[cap.byte_start:cap.byte_end]
-		} else {
-			captures^ = {}
 		}
 	} 
-
+	if !ok {
+		captures^ = {}
+	}
 	return
 }