Skip to content

Instantly share code, notes, and snippets.

@badcc
Last active August 29, 2015 14:18
Show Gist options
  • Save badcc/de667359e2f8c6fa8725 to your computer and use it in GitHub Desktop.
Save badcc/de667359e2f8c6fa8725 to your computer and use it in GitHub Desktop.
Toolbar Shortcut Key Algorithm
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