Post#272 » Wed Jun 01, 2022 12:23 pm
			
			
			
			Omegus wrote: Wed Jun 01, 2022 11:45 am
Testing on 
https://www.lua.org/cgi-bin/demo which doesn't have wstring support (that's a LuaPlus thing):
Code: Select all
local function title_case_helper(first, rest)
  return first:upper()..rest:lower()
end
function title_case(text)
    -- gsub returns multiple values, we just want the first.
    local result = string.gsub(text, "(%a)([%w_']*)", title_case_helper)
    return result
end
print (title_case("foo"))
print (title_case("foo bar"))
Prints out:
I assume the wstring version is just: 
Code: Select all
local function title_case_helper(first, rest)
  return first:upper()..rest:lower()
end
function title_case(text)
    -- gsub returns multiple values, we just want the first.
    local result = wstring.gsub(text, L"(%a)([%w_']*)", title_case_helper)
    return result
end
So if that first wstring.gsub returns nil then call "ShortGName = title_case (ShortGName)", and then try to shorten the name again.
100% untested in the context of the SoR addon.
 
Hey, thanks for the reply. I gave it a quick shot and i think it is still not correct, here the full code of the SOR addon (replaced all wstring with string, as you mentioned wstring is some sort of extension):
Code: Select all
local function title_case_helper(first, rest)
  return first:upper()..rest:lower()
end
function title_case(text)
    -- gsub returns multiple values, we just want the first.
    local result = string.gsub(text, "(%a)([%w_']*)", title_case_helper)
    return result
end
local ShortGName = "foo bar"
ShortGName = string.gsub(ShortGName, " of ", "O")
ShortGName = string.gsub(ShortGName, "%s", "")
local ShortGName2 = string.gsub(ShortGName, "%l*", "")
if ShortGName2 ~= nil then
 ShortGName = title_case(ShortGName)
end
ShortGName = string.match(ShortGName, "([^^]+)^?.*")
print (ShortGName)
update: 
https://pastebin.com/6ds8DdUC  used your method on the initial KeepClaim Text and now it produces something.
example: 
https://imgur.com/a/TRRwv1WDestro: Chosen 85+, Zealot 80+, Sorceress 80+, Dok 80+, BG 80+, Magus 80+, Choppa 80+, WitchElf 80+
Order: SM 64, Warrior Priest 47, AM, BrightWizard, ShadowWarrior, Kotbs