Partially fix unicode name truncation.
This fix ensures that name truncation always happens on codepoint boundaries and that a name has exactly 5 visible codepoints. This should cover all possible cases unless names can have grapheme clusters, afaik this is not the case.
This commit is contained in:
@@ -53,6 +53,21 @@ local colors = {
|
|||||||
white = { 1.0, 1.0, 1.0 }
|
white = { 1.0, 1.0, 1.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- This trucates _codepoints_ not graphemes. If combination codepoints are
|
||||||
|
-- contained in the string, it will not properly truncate and may return
|
||||||
|
-- incorrect graphemes
|
||||||
|
local function utf8_truncate(s, n)
|
||||||
|
local init = 0
|
||||||
|
for _ = 1, n do
|
||||||
|
local _, last = string.find(s, ".[\128-\191]*", init + 1)
|
||||||
|
if not last then
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
init = last
|
||||||
|
end
|
||||||
|
return string.sub(s, 1, init)
|
||||||
|
end
|
||||||
|
|
||||||
---@param unit string
|
---@param unit string
|
||||||
---@param config table
|
---@param config table
|
||||||
function UnitFrame:Init(unit, config)
|
function UnitFrame:Init(unit, config)
|
||||||
@@ -585,20 +600,5 @@ function UnitFrame:UpdateName()
|
|||||||
else
|
else
|
||||||
self.name:SetTextColor(1, 1, 1)
|
self.name:SetTextColor(1, 1, 1)
|
||||||
end
|
end
|
||||||
self.name:SetText(UnitName(self.unit):sub(1, 5))
|
self.name:SetText(utf8_truncate((UnitName(self.unit)), 5))
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
|
||||||
-- UNIT_AURA
|
|
||||||
-- UNIT_CLASSIFICATION_CHANGED
|
|
||||||
-- UNIT_COMBAT
|
|
||||||
-- UNIT_CONNECTION
|
|
||||||
-- UNIT_DISPLAYPOWER
|
|
||||||
-- UNIT_FACTION
|
|
||||||
-- UNIT_FLAGS
|
|
||||||
-- UNIT_LEVEL
|
|
||||||
-- UNIT_MANA
|
|
||||||
-- UNIT_HEALTH_PREDICTION
|
|
||||||
-- UNIT_PHASE
|
|
||||||
]]--
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user