Skip to content

Conversation

@DelaneDiamon
Copy link

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
Copy link
Author

DelaneDiamon commented May 9, 2024

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

@Nevcairiel
Copy link
Owner

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

@DelaneDiamon
Copy link
Author

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?

@Nevcairiel
Copy link
Owner

You aren't on classic by any chance?

@DelaneDiamon
Copy link
Author

DelaneDiamon commented Aug 17, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants