From d52e80e652722f71fbff5cc8f6d444624dd1da43 Mon Sep 17 00:00:00 2001 From: funkydude Date: Mon, 13 Feb 2017 03:40:23 +0000 Subject: [PATCH] urlcopy: Optimize and better document pattern matching. --- urlcopy.lua | 58 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/urlcopy.lua b/urlcopy.lua index 38177b3..ec375f7 100644 --- a/urlcopy.lua +++ b/urlcopy.lua @@ -18,23 +18,73 @@ BCM.modules[#BCM.modules+1] = function() -- valid (but invalid in their location) things ".", "/", "," to prevent words like "lol...", "true./" and "yes.," becoming a URL. -- As of the introduction of the S.E.L.F.I.E camera we now require at least 2 valid letters e.g. yo.hi local filterFunc = function(_, _, msg, ...) + -- [ ]a.b.c.d/e local newMsg, found = gsub(msg, - "( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]*%.?[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~%d]*%.?[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+)", + "( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~%d]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+)", "%1|cffffffff|Hbcmurl~%2|h[%2]|h|r" ) if found > 0 then return false, newMsg, ... end + -- ^a.b.c.d/e newMsg, found = gsub(msg, - "^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]*%.?[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]*%.?[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+", + "^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+", "|cffffffff|Hbcmurl~%1|h[%1]|h|r" ) if found > 0 then return false, newMsg, ... end + -- [ ]a.b.c/d newMsg, found = gsub(msg, - "( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]*%.?[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]*%.?[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+)", + "( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~%d]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+)", "%1|cffffffff|Hbcmurl~%2|h[%2]|h|r" ) if found > 0 then return false, newMsg, ... end + -- ^a.b.c/d newMsg, found = gsub(msg, - "^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]*%.?[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]*%.?[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+", + "^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+", + "|cffffffff|Hbcmurl~%1|h[%1]|h|r" + ) + if found > 0 then return false, newMsg, ... end + -- [ ]a.b/c + newMsg, found = gsub(msg, + "( )([^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+)", + "%1|cffffffff|Hbcmurl~%2|h[%2]|h|r" + ) + if found > 0 then return false, newMsg, ... end + -- ^a.b/c + newMsg, found = gsub(msg, + "^[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+", + "|cffffffff|Hbcmurl~%1|h[%1]|h|r" + ) + if found > 0 then return false, newMsg, ... end + -- [ ]a.b.c.d + newMsg, found = gsub(msg, + "( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+)", + "%1|cffffffff|Hbcmurl~%2|h[%2]|h|r" + ) + if found > 0 then return false, newMsg, ... end + -- ^a.b.c.d + newMsg, found = gsub(msg, + "^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+", + "|cffffffff|Hbcmurl~%1|h[%1]|h|r" + ) + -- [ ]a.b.c + newMsg, found = gsub(msg, + "( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+)", + "%1|cffffffff|Hbcmurl~%2|h[%2]|h|r" + ) + if found > 0 then return false, newMsg, ... end + -- ^a.b.c + newMsg, found = gsub(msg, + "^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+", + "|cffffffff|Hbcmurl~%1|h[%1]|h|r" + ) + -- [ ]a.b + newMsg, found = gsub(msg, + "( )([^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+)", + "%1|cffffffff|Hbcmurl~%2|h[%2]|h|r" + ) + if found > 0 then return false, newMsg, ... end + -- ^a.b + newMsg, found = gsub(msg, + "^[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+", "|cffffffff|Hbcmurl~%1|h[%1]|h|r" ) if found > 0 then return false, newMsg, ... end