Use ":"-notation for strings manipulation

This commit is contained in:
Shy 2024-08-29 10:01:42 +02:00
parent 418215d4a6
commit 9dd2a8fc59

10
c4mate
View file

@ -12,16 +12,16 @@ HOST = "http://mate.labor.koeln.ccc.de"
local function utf8_decode(str)
-- Replace JSON Unicode escape sequences with chars.
if str == nil then return "" end
str = string.gsub(str, "\\\"", "\"")
str = str:gsub("\\\"", "\"")
if utf8 == nil then return str end -- Only available in Lua >= 5.3.
return string.gsub(str, "\\u(%x%x%x%x)",
return str:gsub("\\u(%x%x%x%x)",
function (s) return utf8.char(tonumber(s, 16)) end)
end
local function url_encode(str)
-- URL-encode string. Used only for usernames.
-- Todo: make this more sophisticated.
return string.gsub(str, " ", "%%20")
return str:gsub(" ", "%%20")
end
MatePad = {
@ -421,12 +421,12 @@ else
-- Find and buy item.
local roster, query, input, ok
roster = pad:get_roster()
query = string.lower(table.concat(arg, " "))
query = table.concat(arg, " "):lower()
local menu = {}
for i = 1, #roster do
local item = roster[i]
if string.match(string.lower(item.name), query) then
if item.name:lower():match(query) then
table.insert(menu, item)
end
end