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.moon | |
| 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.moon')
| -rw-r--r-- | string2.moon | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/string2.moon b/string2.moon index 2259272..662cd0d 100644 --- a/string2.moon +++ b/string2.moon @@ -45,6 +45,20 @@ string2 = { lines[#lines+1] = line return table.concat(lines, "\n") + as_lua: => + escaped = gsub(@, "\\", "\\\\") + escaped = gsub(escaped, "\n", "\\n") + escaped = gsub(escaped, '"', '\\"') + escaped = gsub(escaped, "[^ %g]", (c)-> format("\\%03d", byte(c, 1))) + return '"'..escaped..'"' + + as_nomsu: => + escaped = gsub(@, "\\", "\\\\") + escaped = gsub(escaped, "\n", "\\n") + escaped = gsub(escaped, '"', '\\"') + escaped = gsub(escaped, "[^ %g]", (c)-> format("\\%03d", byte(c, 1))) + return '"'..escaped..'"' + -- Convert an arbitrary text into a valid Lua identifier. This function is injective, -- but not idempotent. In logic terms: (x != y) => (as_lua_id(x) != as_lua_id(y)), -- but not (as_lua_id(a) == b) => (as_lua_id(b) == b). |
