From 24cdcb9385f54f1539fff7707201a8d3b812cc7b Mon Sep 17 00:00:00 2001 From: Ksaper Date: Fri, 24 Feb 2023 20:39:21 +0200 Subject: [PATCH] No need for the case_insensitive function, can just :lower() the string + use plain matching --- widget/app_launcher/init.lua | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/widget/app_launcher/init.lua b/widget/app_launcher/init.lua index 61a7f40..53a1901 100644 --- a/widget/app_launcher/init.lua +++ b/widget/app_launcher/init.lua @@ -71,24 +71,9 @@ local function string_levenshtein(str1, str2) return matrix[len1][len2] end -local function case_insensitive_pattern(pattern) - -- find an optional '%' (group 1) followed by any character (group 2) - local p = pattern:gsub("(%%?)(.)", function(percent, letter) - if percent ~= "" or not letter:match("%a") then - -- if the '%' matched, or `letter` is not a letter, return "as is" - return percent .. letter - else - -- else, return a case-insensitive character class of the matched letter - return string.format("[%s%s]", letter:lower(), letter:upper()) - end - end) - - return p -end - local function has_value(tab, val) - for index, value in pairs(tab) do - if val:find(case_insensitive_pattern(value)) then + for _, value in ipairs(tab) do + if val:lower():find(value:lower(), 1, true) then return true end end