Try this:
Code:
for _,v in pairs{"Joereallylongnamewithoutspaces", "Billy Bob", "Green Naked Oversized Mechanical Elf Punter"} do
local n = string.gsub(v, "%s?(.)%S+%s", "%1. ")
print(n)
end
Also, try to simplify down your logic in the tag, and string together multiple tags when you set up the string:
Code:
oUF.Tags['[afk]'] = function(unit) if UnitIsAFK(unit) then return "AFK" end end
oUF.TagEvents['[abbrevname]'] = 'UNIT_HEALTH UNIT_MAXHEALTH PLAYER_FLAGS_CHANGED'
oUF.Tags['[abbrevname]'] = function(unit)
if UnitIsDead(unit) or not UnitIsConnected(unit) or UnitIsAFK(unit) or UnitIsGhost(unit) then return end
local name = UnitName(unit)
return (string.len(name) > 10) and string.gsub(name, "%s?(.)%S+%s", "%1. ") or name
end
Then you just register your fontstring with something like "[status][afk][raidcolor][abbrevname]"
Note that I don't know what event fires for AFK changes, so you'll have to figure that one out on your own.
Lastly, you don't need to manually truncate your string if it's too long. Set up anchors for both ends of the fontstring and the game will truncate it automatically if needed.