ShadowedUnitFrames icon indicating copy to clipboard operation
ShadowedUnitFrames copied to clipboard

feat(modules): Add name abbreviation fix for multibyte names

Open DelaneDiamon opened this issue 1 year ago • 5 comments

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

DelaneDiamon avatar May 09 '24 23:05 DelaneDiamon

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

DelaneDiamon avatar May 09 '24 23:05 DelaneDiamon

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

Nevcairiel avatar Aug 16 '24 08:08 Nevcairiel

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?

DelaneDiamon avatar Aug 16 '24 17:08 DelaneDiamon

You aren't on classic by any chance?

Nevcairiel avatar Aug 17 '24 05:08 Nevcairiel

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: @.***>

DelaneDiamon avatar Aug 17 '24 15:08 DelaneDiamon