diff options
author | Mark Pulford <mark@kyne.com.au> | 2012-01-19 23:36:16 +1030 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2012-03-04 18:54:35 +1030 |
commit | 31bf122c1d1d9e3812b9ef2555d537f509ae3f05 (patch) | |
tree | b382fa3fecb784598ff8b0c64c1360c3bc24db2a /lua | |
parent | a0961903e3ff846a2bde6faa6d390435cd9937ef (diff) | |
download | lua-cjson-31bf122c1d1d9e3812b9ef2555d537f509ae3f05.tar.gz lua-cjson-31bf122c1d1d9e3812b9ef2555d537f509ae3f05.tar.bz2 lua-cjson-31bf122c1d1d9e3812b9ef2555d537f509ae3f05.zip |
Simplify string.format() calls
Simply string.format() calls with OO method notation.
Diffstat (limited to 'lua')
-rw-r--r-- | lua/cjson/util.lua | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lua/cjson/util.lua b/lua/cjson/util.lua index 5b1eba0..79245b5 100644 --- a/lua/cjson/util.lua +++ b/lua/cjson/util.lua | |||
@@ -63,10 +63,9 @@ local function serialise_table(value, indent, depth) | |||
63 | if comma then | 63 | if comma then |
64 | table.insert(fragment, "," .. spacing2) | 64 | table.insert(fragment, "," .. spacing2) |
65 | end | 65 | end |
66 | table.insert(fragment, string.format( | 66 | table.insert(fragment, |
67 | "[%s] = %s", serialise_value(k, indent2, depth), | 67 | ("[%s] = %s"):format(serialise_value(k, indent2, depth), |
68 | serialise_value(v, indent2, depth)) | 68 | serialise_value(v, indent2, depth))) |
69 | ) | ||
70 | comma = true | 69 | comma = true |
71 | end | 70 | end |
72 | end | 71 | end |
@@ -82,7 +81,7 @@ function serialise_value(value, indent, depth) | |||
82 | if value == json.null then | 81 | if value == json.null then |
83 | return "json.null" | 82 | return "json.null" |
84 | elseif type(value) == "string" then | 83 | elseif type(value) == "string" then |
85 | return string.format("%q", value) | 84 | return ("%q"):format(value) |
86 | elseif type(value) == "nil" or type(value) == "number" or | 85 | elseif type(value) == "nil" or type(value) == "number" or |
87 | type(value) == "boolean" then | 86 | type(value) == "boolean" then |
88 | return tostring(value) | 87 | return tostring(value) |
@@ -101,7 +100,7 @@ local function file_load(filename) | |||
101 | local err | 100 | local err |
102 | file, err = io.open(filename) | 101 | file, err = io.open(filename) |
103 | if file == nil then | 102 | if file == nil then |
104 | error(string.format("Unable to read '%s': %s", filename, err)) | 103 | error(("Unable to read '%s': %s"):format(filename, err)) |
105 | end | 104 | end |
106 | end | 105 | end |
107 | local data = file:read("*a") | 106 | local data = file:read("*a") |
@@ -125,7 +124,7 @@ local function file_save(filename, data) | |||
125 | local err | 124 | local err |
126 | file, err = io.open(filename, "w") | 125 | file, err = io.open(filename, "w") |
127 | if file == nil then | 126 | if file == nil then |
128 | error(string.format("Unable to write '%s': %s", filename, err)) | 127 | error(("Unable to write '%s': %s"):format(filename, err)) |
129 | end | 128 | end |
130 | end | 129 | end |
131 | file:write(data) | 130 | file:write(data) |
@@ -187,7 +186,7 @@ local function run_test(testname, func, input, should_work, output) | |||
187 | if status ~= nil then | 186 | if status ~= nil then |
188 | name = name .. statusmap[status] | 187 | name = name .. statusmap[status] |
189 | end | 188 | end |
190 | print(string.format("[%s] %s", name, serialise_value(value, false))) | 189 | print(("[%s] %s"):format(name, serialise_value(value, false))) |
191 | end | 190 | end |
192 | 191 | ||
193 | local result = { pcall(func, unpack(input)) } | 192 | local result = { pcall(func, unpack(input)) } |
@@ -201,8 +200,8 @@ local function run_test(testname, func, input, should_work, output) | |||
201 | test_count_total = test_count_total + 1 | 200 | test_count_total = test_count_total + 1 |
202 | 201 | ||
203 | local teststatus = { [true] = "PASS", [false] = "FAIL" } | 202 | local teststatus = { [true] = "PASS", [false] = "FAIL" } |
204 | print(string.format("==> Test [%d] %s: %s", | 203 | print(("==> Test [%d] %s: %s"):format(test_count_total, testname, |
205 | test_count_total, testname, teststatus[correct])) | 204 | teststatus[correct])) |
206 | 205 | ||
207 | status_line("Input", nil, input) | 206 | status_line("Input", nil, input) |
208 | if not correct then | 207 | if not correct then |