Better handle zone names with spaces and special
James Whitehead II [01-27-11 - 10:02]
Better handle zone names with spaces and special
The comparison of user input to zone name is made more relaxed by this
commit which forces both strings to be forced to lowercase, and have all
non-alphanumeric characters removed. In short, it should work much
better now.
diff --git a/TomTom.lua b/TomTom.lua
index ae9ab47..cbb7583 100755
--- a/TomTom.lua
+++ b/TomTom.lua
@@ -1093,6 +1093,9 @@ end
local wrongseparator = "(%d)" .. (tonumber("1.1") and "," or ".") .. "(%d)"
local rightseparator = "%1" .. (tonumber("1.1") and "." or ",") .. "%2"
+-- Make comparison only lowercase letters and numbers
+local function lowergsub(s) return s:lower():gsub("^[%a%d]", "") end
+
SlashCmdList["TOMTOM_WAY"] = function(msg)
msg = msg:gsub("(%d)[%.,] (%d)", "%1 %2"):gsub(wrongseparator, rightseparator)
local tokens = {}
@@ -1117,10 +1120,10 @@ SlashCmdList["TOMTOM_WAY"] = function(msg)
-- Find a fuzzy match for the zone
local matches = {}
- lzone = zone:lower():gsub("^[%l%s%d]", "")
+ lzone = lowergsub(zone)
for name, mapId in pairs(nameToMapId) do
- local lname = name:lower()
+ local lname = lowergsub(name)
if lname:match(lzone) then
table.insert(matches, name)
end
@@ -1180,10 +1183,10 @@ SlashCmdList["TOMTOM_WAY"] = function(msg)
-- Find a fuzzy match for the zone
local matches = {}
- lzone = zone:lower():gsub("[^%l%s%d]", "")
+ lzone = lowergsub(zone)
for name,mapId in pairs(nameToMapId) do
- local lname = name:lower()
+ local lname = lowergsub(name)
if lname:match(lzone) then
table.insert(matches, name)
end