Improve UTF-8 string length counting

This commit is contained in:
Jean-Patrick Guerrero 2022-06-30 15:18:32 +02:00
parent c635343c9b
commit 9ab47fc0f0

View File

@ -78,7 +78,13 @@ local function toupper(str)
end end
local function utf8_len(str) local function utf8_len(str)
return #str:gsub("[\128-\191]", "") -- Arguably working duct-tape code local c = 0
for _ in str:gmatch"([%z\1-\127\194-\244][\128-\191]*)" do -- Arguably working duct-tape code
c++
end
return c
end end
local function get_bag_description(data, stack) local function get_bag_description(data, stack)