smarter string quoting

This commit is contained in:
Connor Olding 2014-08-25 22:51:45 -07:00
parent 124ec51da3
commit 051265ea3a
3 changed files with 66 additions and 65 deletions

View File

@ -1,22 +1,22 @@
__root__: &t0x8ec478
_VERSION: "Lua 5.2"
add_zeros: f0x8ec3f0
__root__: &t0x6f478
_VERSION: Lua 5.2
add_zeros: f0x73838
assert: f0x1fefc
collectgarbage: f0x1f930
dofile: f0x1fe7c
dump: f0x8f1410
dump: f0x78770
error: f0x1f8c0
getaddr: f0x8f4c30
getaddr: f0x74c40
getmetatable: f0x1fe2c
ipairs: f0x1fd24
load: f0x1ff54
loadfile: f0x1fd80
loadstring: f0x1ff54
mixed_sorter: f0x8f1c28
module: f0x8ece20
mixed_sorter: f0x76c28
module: f0x6fe20
next: f0x1f7ac
opairs: f0x8f4da0
order_keys: f0x8f4cc0
opairs: f0x74c88
order_keys: f0x74cd0
pairs: f0x1fd04
pcall: f0x1fb50
print: f0x1f66c
@ -24,21 +24,21 @@ __root__: &t0x8ec478
rawget: f0x1f598
rawlen: f0x1f5d8
rawset: f0x1f54c
rawstr: f0x8f4c78
require: f0x8edb00
rawstr: f0x76460
require: f0x70b00
select: f0x1f444
setmetatable: f0x1fbc0
strpad: f0x8f34e8
strpad: f0x73e60
tonumber: f0x1f25c
tostring: f0x1f234
type: f0x1f1f8
unpack: f0x26598
xpcall: f0x1fa84
_G: *t0x8ec478
arg: &t0x8f06b8
"-1": "/usr/bin/lua"
0: "./run.lua"
bit32: &t0x8ed190
_G: *t0x6f478
arg: &t0x736b8
"-1": /usr/bin/lua
0: ./run.lua
bit32: &t0x70190
arshift: f0x2022c
band: f0x20458
bnot: f0x20208
@ -51,14 +51,14 @@ __root__: &t0x8ec478
replace: f0x20338
rrotate: f0x201c4
rshift: f0x2015c
coroutine: &t0x8ec998
coroutine: &t0x6f998
create: f0x20844
resume: f0x20934
running: f0x20824
status: f0x206cc
wrap: f0x20888
yield: f0x20584
debug: &t0x8ee7c8
debug: &t0x717c8
debug: f0x20e44
gethook: f0x21470
getinfo: f0x21674
@ -75,7 +75,7 @@ __root__: &t0x8ec478
traceback: f0x20ff8
upvalueid: f0x20ca0
upvaluejoin: f0x20cd8
io: &t0x8edfe8
io: &t0x70fe8
close: f0x21c94
flush: f0x22328
input: f0x22a28
@ -84,13 +84,13 @@ __root__: &t0x8ec478
output: f0x22a0c
popen: f0x2238c
read: f0x222dc
stderr: "file (0x76e559d8)"
stdin: "file (0x76e55c98)"
stdout: "file (0x76e55b38)"
stderr: file (0x76e4f9d8)
stdin: file (0x76e4fc98)
stdout: file (0x76e4fb38)
tmpfile: f0x22c70
type: f0x22890
write: f0x21ba8
math: &t0x8efa10
math: &t0x72a10
abs: f0x22e48
acos: f0x234c8
asin: f0x234a4
@ -121,7 +121,7 @@ __root__: &t0x8ec478
sqrt: f0x22eb4
tan: f0x22e6c
tanh: f0x22e90
os: &t0x8edd90
os: &t0x70d90
clock: f0x237d8
date: f0x23ac0
difftime: f0x23758
@ -133,7 +133,7 @@ __root__: &t0x8ec478
setlocale: f0x23580
time: f0x23930
tmpname: f0x23810
package: &t0x8ece90
package: &t0x6fe90
config: "\
/\
;\
@ -141,40 +141,40 @@ __root__: &t0x8ec478
!\
-\
"
cpath: "/usr/lib/lua/5.2/?.so;/usr/lib/lua/5.2/loadall.so;./?.so"
cpath: /usr/lib/lua/5.2/?.so;/usr/lib/lua/5.2/loadall.so;./?.so
loadlib: f0x27808
path: "/usr/share/lua/5.2/?.lua;/usr/share/lua/5.2/?/init.lua;/usr/lib/lua/5.2/?.lua;/usr/lib/lua/5.2/?/init.lua;./?.lua"
path: /usr/share/lua/5.2/?.lua;/usr/share/lua/5.2/?/init.lua;/usr/lib/lua/5.2/?.lua;/usr/lib/lua/5.2/?/init.lua;./?.lua
searchpath: f0x27ad4
seeall: f0x273e0
searchers: *t0x8ed5b0
loaded: &t0x8ec948
searchers: *t0x705b0
loaded: &t0x6f948
extra: true
_G: *t0x8ec478
bit32: *t0x8ed190
coroutine: *t0x8ec998
debug: *t0x8ee7c8
io: *t0x8edfe8
math: *t0x8efa10
os: *t0x8edd90
package: *t0x8ece90
string: *t0x8ed340
table: *t0x8edb68
pt: &t0x8f5be8
__call: f0x8f12a0
inner: f0x8f5a10
outer: f0x8f4de0
safekey: f0x8f1dc0
safeval: f0x8ec230
write: f0x8f3890
__index: *t0x8f5be8
__metatable: *t0x8f5be8
loaders: &t0x8ed5b0
1: f0x8ed620
2: f0x8ed648
3: f0x8ed670
4: f0x8ed698
preload: &t0x8ed720
string: &t0x8ed340
_G: *t0x6f478
bit32: *t0x70190
coroutine: *t0x6f998
debug: *t0x717c8
io: *t0x70fe8
math: *t0x72a10
os: *t0x70d90
package: *t0x6fe90
string: *t0x70340
table: *t0x70b68
pt: &t0x78948
__call: f0x75128
inner: f0x76d00
outer: f0x74410
safekey: f0x77de8
safeval: f0x6f2d0
write: f0x6f360
__index: *t0x78948
__metatable: *t0x78948
loaders: &t0x705b0
1: f0x70620
2: f0x70648
3: f0x70670
4: f0x70698
preload: &t0x70720
string: &t0x70340
byte: f0x25234
char: f0x24768
dump: f0x254d4
@ -189,20 +189,20 @@ __root__: &t0x8ec478
reverse: f0x23fb8
sub: f0x2518c
upper: f0x23ed8
t: &t0x8f1bd0
t: &t0x74a30
C: hello
D: *t0x8f1bd0
A: &t0x8f1d98
D: *t0x74a30
A: &t0x74b78
a: beep
b: boop
c: burp
d: *t0x8f5f90
B: &t0x8f5f90
d: *t0x786c0
B: &t0x786c0
a: nude
b: dude
c: lewd
d: *t0x8f1d98
table: &t0x8edb68
d: *t0x74b78
table: &t0x70b68
concat: f0x2691c
insert: f0x26688
maxn: f0x26818

3
pt.lua
View File

@ -53,7 +53,8 @@ function pt.safeval(v, indent)
return s
end
s = s:find('[\r\n]') and ('\n'..s):gsub('[\r\n]', '\n'..indent..' ') or s
return s:find('[^%w_]') and ('%q'):format(s) or s
local safe = ('%q'):format(s)
return s == safe:sub(2, -2) and s or safe
end
function pt:inner(k, v, indent)

View File

@ -37,4 +37,4 @@ function dump(t, fn, seen)
end
pt(t)
dump(_G, '!_G.yml')
dump(_G, '_G.yml')