Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save amigojapan/6a86bf7f3e1a9d115669ff9e96b4b875 to your computer and use it in GitHub Desktop.

Select an option

Save amigojapan/6a86bf7f3e1a9d115669ff9e96b4b875 to your computer and use it in GitHub Desktop.
converts single width latin to doubel width latin
function replaceStringOfRomajiWithDoubleWidthCHaracters2(str)
-- Define a mapping of single-width to double-width characters
local mapping = {
["!"] = "", ["\""] = "", ["#"] = "", ["$"] = "", ["%"] = "",
["&"] = "", ["'"] = "", ["("] = "", [")"] = "", ["*"] = "",
["+"] = "", [","] = "", ["-"] = "", ["."] = "", ["/"] = "",
["0"] = "", ["1"] = "", ["2"] = "", ["3"] = "", ["4"] = "",
["5"] = "", ["6"] = "", ["7"] = "", ["8"] = "", ["9"] = "",
[":"] = "", [";"] = "", ["<"] = "", ["="] = "", [">"] = "",
["?"] = "", ["@"] = "", ["["] = "", ["\\"] = "", ["]"] = "",
["_"] = "_", ["`"] = "", ["{"] = "", ["|"] = "", ["}"] = "",
["~"] = "", ["¥"] = "",
["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"] = "",
["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"] = ""
}
-- Replace each character using the mapping
return (str:gsub(".", function(c) return mapping[c] or c end))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment