Skip to content

Instantly share code, notes, and snippets.

@tiansh
Created January 25, 2016 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiansh/ddb7fce994cce3428b69 to your computer and use it in GitHub Desktop.
Save tiansh/ddb7fce994cce3428b69 to your computer and use it in GitHub Desktop.
莫尔斯电码输入 - 谷歌拼音输入法扩展
function Morse(ori)
MorseMapping = {
["a"] = ".−",
["b"] = "−...",
["c"] = "−.−.",
["d"] = "−..",
["e"] = ".",
["f"] = "..−.",
["g"] = "−−.",
["h"] = "....",
["i"] = "..",
["j"] = ".−−−",
["k"] = "−.−",
["l"] = ".−..",
["m"] = "−−",
["n"] = "−.",
["o"] = "−−−",
["p"] = ".−−.",
["q"] = "−−.−",
["r"] = ".−.",
["s"] = "...",
["t"] = "−",
["u"] = "..−",
["v"] = "...−",
["w"] = ".−−",
["x"] = "−..−",
["y"] = "−.−−",
["z"] = "−−..",
["0"] = "−−−−−",
["1"] = ".−−−−",
["2"] = "..−−−",
["3"] = "...−−",
["4"] = "....−",
["5"] = ".....",
["6"] = "−....",
["7"] = "−−...",
["8"] = "−−−..",
["9"] = "−−−−.",
["."] = ".−.−.−",
[","] = "−−..−−",
["?"] = "..−−..",
["'"] = ".−−−−.",
["!"] = "−.−.−−",
["/"] = "−..−.",
["("] = "−.−−.",
[")"] = "−.−−.−",
["&"] = ".−...",
[":"] = "−−−...",
[";"] = "−.−.−.",
["="] = "−...−",
["+"] = ".−.−.",
["-"] = "−....−",
["_"] = "..−−.−",
["\""] = ".−..−.",
["$"] = "...−..−",
["@"] = ".−−.−.",
["_"] = "/"
}
if #ori == 0 then return end
local result = ""
ori = string.lower(ori)
for c in ori:gmatch"." do
result = result .. MorseMapping[c] .. " "
end
result = result .. "/ "
return {result, string.sub(result, 0, string.len(result) - 3)}
end
ime.register_command("mo", "Morse", "摩尔斯电码", "none")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment