Last active
August 29, 2015 14:18
-
-
Save badcc/de667359e2f8c6fa8725 to your computer and use it in GitHub Desktop.
Toolbar Shortcut Key Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ToolbarMenuStrings = {"Hello", "World", "Menu", "Bar", "Has", "Awesome", "MenubarSupport"} | |
local Used = {} | |
function Eval(Str) | |
local Index = 0 | |
local Current = Str:gsub('%U', '') | |
if (#Current == 0) then | |
Current = Str:gsub('%u', '') | |
end | |
while (Index < #Current+1) do | |
Index = Index + 1 | |
local Char = Current:sub(1, 1):lower() | |
if (not Used[Char]) then | |
Used[Char] = true | |
print('Using ' .. Char .. ' for word ' .. Str .. ' (dbg.cindex ' .. Index .. ')') | |
break | |
else | |
Current = Current:sub(2) | |
end | |
if (#Current == 0) then | |
Current = Str:gsub('%u', '') | |
end | |
end | |
end | |
for _,String in next,ToolbarMenuStrings do | |
Eval(String) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment