lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Comments, improvements and bug reports are welcome.

A simpler way to write 'escapestring':

escapetable = {
  ['\a'] = '\\a', ['\b'] = '\\b', ['\f'] = '\\f',
  ['\n'] = '\\n', ['\r'] = '\\r', ['\t'] = '\\t',
  ['\v'] = '\\v',
  ['"'] = '\\"', ["'"] = "\\'", ['\\'] = '\\\\',
}

function escapestring(s)
  s = gsub(s,"([%c\\'\"%z])", function(l)   -- convert special characters
        return escapetable[l] or format("\\%03d", strbyte(l))
      end)
  return s
end


-- Roberto