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
1 changed files with 7 additions and 1 deletions

View File

@ -78,7 +78,13 @@ local function toupper(str)
end
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
local function get_bag_description(data, stack)