Quantcast

Fixed regexes in damageRange and validateNumber

Kevin Lyles [03-10-10 - 23:50]
Fixed regexes in damageRange and validateNumber
Filename
Regexps.lua
weights.lua
diff --git a/Regexps.lua b/Regexps.lua
index 34f9a00..c65bb34 100644
--- a/Regexps.lua
+++ b/Regexps.lua
@@ -178,7 +178,7 @@ end
 function WeightsWatcher:damageRange(textL, textR)
 	local speed
 	local stats = setmetatable({}, ww_normalStatsMetatable)
-	local start, _, added, minVal, maxVal, name = string.find(textL, "^(%+?)(%d+) %- (%d+) (%a* ?Damage)")
+	local start, _, added, minVal, maxVal, name = string.find(textL, "^(%+?)(%d+) %- (%d+) (%a* ?Damage)$")
 	if start then
 		if added == "+" then
 			added = "Added "
@@ -187,7 +187,7 @@ function WeightsWatcher:damageRange(textL, textR)
 		stats["Maximum " .. added .. name] = tonumber(maxVal)
 	end
 	if textR then
-		start, _, speed = string.find(textR, "^Speed (%d[%d.]+)$")
+		start, _, speed = string.find(textR, "^Speed (%d+%.?%d*)$")
 		if start then
 			stats["Speed"] = tonumber(speed)
 		end
diff --git a/weights.lua b/weights.lua
index 47200f7..025554a 100644
--- a/weights.lua
+++ b/weights.lua
@@ -72,16 +72,16 @@ function initializeWeightsConfig()
 end

 function validateNumber(newChar, newText)
-	if string.find(newChar, "^[0-9]$") then
+	if string.find(newChar, "^%d$") then
 		return true
 	elseif newChar == '.' then
-		local first = newText:find(".", 1, true)
-		local second = newText:find(".", first + 1, true)
+		local first = newText:find("%.", 1, true)
+		local second = newText:find("%.", first + 1, true)
 		if not second then
 			return true
 		end
 	elseif newChar == '-' then
-		if not string.find(newText, "-", 2) then
+		if not string.find(newText, "%-", 2) then
 			return true
 		end
 	end