Advertisement
C0BRA

quotify (GNU needs this)

Jan 16th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.56 KB | None | 0 0
  1. #!/usr/bin/env lua
  2.  
  3. local first = true
  4. local function escape(input)
  5.     input = input:gsub(" ", "\\ ")        
  6.         input = input:gsub("'", "\\'")
  7.         input = input:gsub("\"", "\\\"")
  8.         input = input:gsub("\n", "\\n")
  9.         input = input:gsub("\r", "\\r")
  10.         input = input:gsub("\b", "\\b")
  11.         input = input:gsub("\t", "\\t")
  12.  
  13.     if first then
  14.         first = false
  15.     else
  16.         input = " " .. input
  17.     end
  18.  
  19.  
  20.     return input
  21. end
  22.  
  23. while true do
  24.     local line = io.stdin:read("*l")
  25.     if not line then return end
  26.  
  27.     io.stdout:write(escape(line))
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement