feat(modules): Add name abbreviation fix for multibyte names
Add a function to identify the number of bytes used for current unit name to abbreviate correctly with string.sub:
local function utf8len1stchar(str)
local byte = str:byte(1)
if byte < 128 then return 1 end -- 1-byte character
if byte < 224 then return 2 end -- continue of multi-byte character
if byte < 240 then return 3 end -- start of 2-byte character
if byte < 248 then return 4 end -- start of 3-byte character
return 1 -- invalid
end
-- Name abbreviation
local function abbreviateName(text)
local lengthOfFirstChar = utf8len1stchar(text)
return string.sub(text, 1, lengthOfFirstChar) .. "."
end
Hey @Nevcairiel, I have realized this fix might be helpful for users with multibyte characters in different locales.
I have also created an issue on Curse: https://www.wowace.com/projects/shadowed-unit-frames/issues/2070
SUF uses string.utf8sub from the UTF-8 library, and this issue should not actually happen with that, as it should cut actual multibyte characters, and not just bytes
ok, so could it be then that utf8sub method is unavailable for some reason in this case and it uses default sub which cannot handle multibyte characters?
You aren't on classic by any chance?
On classic Cataclysm, yes.
On Fri, Aug 16, 2024, 22:51 Hendrik Leppkes @.***> wrote:
You aren't on classic by any chance?
— Reply to this email directly, view it on GitHub https://github.com/Nevcairiel/ShadowedUnitFrames/pull/46#issuecomment-2294649422, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIPL5T4XKRNHVOHXNNAOVDLZR3QFFAVCNFSM6AAAAABHPT446CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJUGY2DSNBSGI . You are receiving this because you authored the thread.Message ID: @.***>