From 917732ef8aa7e014e1c8814f1a76c5967e6f326e Mon Sep 17 00:00:00 2001 From: James Whitehead II Date: Thu, 27 Jan 2011 10:02:15 +0000 Subject: [PATCH] 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. --- TomTom.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 -- 1.7.9.5