inputor

Evdev remapping utility in lua
git clone https://git.neptards.moe/u3shit/inputor.git
Log | Files | Refs

string.lua (406B)


      1 local byte, format = string.byte, string.format
      2 
      3 local builtins = {
      4   ["\a"] = "\\a", ["\b"] = "\\b", ["\f"] = "\\f", ["\n"] = "\\n", ["\r"] = "\\r",
      5   ["\t"] = "\\t", ["\v"] = "\\v", ["\\"] = "\\\\", ['"'] = '\\"',
      6 }
      7 
      8 function string:escape()
      9   local repl = self:gsub("[\"%\\%c\x80-\xff]", function(m)
     10     return builtins[m] or format("\\x%02x", byte(m))
     11   end)
     12   return '"'..repl..'"'
     13 end
     14 
     15 return string