diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-09-18 19:48:58 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-09-18 19:49:29 -0700 |
| commit | 79d4bd5125de7ff220fbf8a8a5493d437ed16963 (patch) | |
| tree | fa09e1a5ccb384373b50e27067a7cc3a25669550 /string2.lua | |
| parent | d11f9bc5d3971a68dd78cdaca0b046a40a329000 (diff) | |
Got rid of repr() use and replaced with :as_lua() or :as_nomsu() in as
many places as possible.
Diffstat (limited to 'string2.lua')
| -rw-r--r-- | string2.lua | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/string2.lua b/string2.lua index 5995de2..2cdfefc 100644 --- a/string2.lua +++ b/string2.lua @@ -119,6 +119,24 @@ local string2 = { end return table.concat(lines, "\n") end, + as_lua = function(self) + local escaped = gsub(self, "\\", "\\\\") + escaped = gsub(escaped, "\n", "\\n") + escaped = gsub(escaped, '"', '\\"') + escaped = gsub(escaped, "[^ %g]", function(c) + return format("\\%03d", byte(c, 1)) + end) + return '"' .. escaped .. '"' + end, + as_nomsu = function(self) + local escaped = gsub(self, "\\", "\\\\") + escaped = gsub(escaped, "\n", "\\n") + escaped = gsub(escaped, '"', '\\"') + escaped = gsub(escaped, "[^ %g]", function(c) + return format("\\%03d", byte(c, 1)) + end) + return '"' .. escaped .. '"' + end, as_lua_id = function(str) local orig = str str = gsub(str, "^ *$", "%1 ") |
