Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpx/lua-cjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2012-01-19 17:06:16 +0400
committerMark Pulford <mark@kyne.com.au>2012-03-04 12:24:35 +0400
commit31bf122c1d1d9e3812b9ef2555d537f509ae3f05 (patch)
treeb382fa3fecb784598ff8b0c64c1360c3bc24db2a
parenta0961903e3ff846a2bde6faa6d390435cd9937ef (diff)
Simplify string.format() calls
Simply string.format() calls with OO method notation.
-rw-r--r--lua/cjson/util.lua19
-rwxr-xr-xtests/bench.lua4
-rwxr-xr-xtests/test.lua6
3 files changed, 14 insertions, 15 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)
if comma then
table.insert(fragment, "," .. spacing2)
end
- table.insert(fragment, string.format(
- "[%s] = %s", serialise_value(k, indent2, depth),
- serialise_value(v, indent2, depth))
- )
+ table.insert(fragment,
+ ("[%s] = %s"):format(serialise_value(k, indent2, depth),
+ serialise_value(v, indent2, depth)))
comma = true
end
end
@@ -82,7 +81,7 @@ function serialise_value(value, indent, depth)
if value == json.null then
return "json.null"
elseif type(value) == "string" then
- return string.format("%q", value)
+ return ("%q"):format(value)
elseif type(value) == "nil" or type(value) == "number" or
type(value) == "boolean" then
return tostring(value)
@@ -101,7 +100,7 @@ local function file_load(filename)
local err
file, err = io.open(filename)
if file == nil then
- error(string.format("Unable to read '%s': %s", filename, err))
+ error(("Unable to read '%s': %s"):format(filename, err))
end
end
local data = file:read("*a")
@@ -125,7 +124,7 @@ local function file_save(filename, data)
local err
file, err = io.open(filename, "w")
if file == nil then
- error(string.format("Unable to write '%s': %s", filename, err))
+ error(("Unable to write '%s': %s"):format(filename, err))
end
end
file:write(data)
@@ -187,7 +186,7 @@ local function run_test(testname, func, input, should_work, output)
if status ~= nil then
name = name .. statusmap[status]
end
- print(string.format("[%s] %s", name, serialise_value(value, false)))
+ print(("[%s] %s"):format(name, serialise_value(value, false)))
end
local result = { pcall(func, unpack(input)) }
@@ -201,8 +200,8 @@ local function run_test(testname, func, input, should_work, output)
test_count_total = test_count_total + 1
local teststatus = { [true] = "PASS", [false] = "FAIL" }
- print(string.format("==> Test [%d] %s: %s",
- test_count_total, testname, teststatus[correct]))
+ print(("==> Test [%d] %s: %s"):format(test_count_total, testname,
+ teststatus[correct]))
status_line("Input", nil, input)
if not correct then
diff --git a/tests/bench.lua b/tests/bench.lua
index cae4902..648020b 100755
--- a/tests/bench.lua
+++ b/tests/bench.lua
@@ -115,7 +115,7 @@ function bench_file(filename)
end
-- Optionally load any custom configuration required for this module
-local success, data = pcall(util.file_load, string.format("bench-%s.lua", json_module))
+local success, data = pcall(util.file_load, ("bench-%s.lua"):format(json_module))
if success then
util.run_script(data, _G)
configure(json)
@@ -124,7 +124,7 @@ end
for i = 1, #arg do
local results = bench_file(arg[i])
for k, v in pairs(results) do
- print(string.format("%s\t%s\t%d", arg[i], k, v))
+ print(("%s\t%s\t%d"):format(arg[i], k, v))
end
end
diff --git a/tests/test.lua b/tests/test.lua
index e0f99f6..8c50b02 100755
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -22,7 +22,7 @@ local function gen_utf16_escaped()
local count = 0
local function append_escape(code)
- local esc = string.format('\\u%04X', code)
+ local esc = ('\\u%04X'):format(code)
table.insert(utf16_escaped, esc)
end
@@ -388,7 +388,7 @@ local cjson_tests = {
true, { false, 2, 10 } },
}
-print(string.format("==> Testing Lua CJSON version %s\n", json._VERSION))
+print(("==> Testing Lua CJSON version %s\n"):format(json._VERSION))
util.run_test_group(cjson_tests)
@@ -402,7 +402,7 @@ local pass, total = util.run_test_summary()
if pass == total then
print("==> Summary: all tests succeeded")
else
- print(string.format("==> Summary: %d/%d tests failed", total - pass, total))
+ print(("==> Summary: %d/%d tests failed"):format(total - pass, total))
os.exit(1)
end