From 9ab47fc0f0fe0c82052a424c383b8a773ba65d84 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Thu, 30 Jun 2022 15:18:32 +0200 Subject: [PATCH] Improve UTF-8 string length counting --- src/common.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common.lua b/src/common.lua index edd64f5..a86aba4 100644 --- a/src/common.lua +++ b/src/common.lua @@ -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)