-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not parsing new line correctly? #5
Comments
Sorry for the delay, barely saw this. Thanks for bringing it to my attention. If you want to get this behavior, you can modify the code a bit, which gives me the same result as local concat, tostring, format, pairs, type, gsub = table.concat, tostring, string.format, pairs, type, string.gsub
local function isarray(t, len)
for k in pairs(t) do
if len == 0 or type(k) ~= "number" then
return false
else
len = len - 1
end
end
return true
end
local ESCAPE = { ["\b"] = "\\b", ["\f"] = "\\f", ["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t" }
local _encode
local function value(v, buffer, nbuffer)
local t = type(v)
if t == "table" then
return _encode(v, buffer, nbuffer)
elseif t == "string" then
buffer[nbuffer + 1] = "\"" .. gsub(v, "[\b\f\n\r\t]", ESCAPE) .. "\""
else
buffer[nbuffer + 1] = tostring(v)
end
return nbuffer + 1
end Changes +local concat, tostring, format, pairs, type, gsub = table.concat, tostring, string.format, pairs, type, string.gsub
+ local ESCAPE = { ["\b"] = "\\b", ["\f"] = "\\f", ["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t", ['"'] = "\\\"" }
+ buffer[nbuffer + 1] = "\"" .. gsub(v, "[\b\f\n\r\t\"]", ESCAPE) .. "\"" edit: fixed quote escape Problem is the current implementation relies on Would like to benchmark before replacing the inner implementation with this -- but even if it is a little slower it's probably best to merge since |
100% agree. I like your library, it's very easy to read and small code. great job! |
Hi,
Here is the lua file:
Running it on bash shows 2 lines while it should be one line.
lua s.lua | nl
output:
1 ["v=spf1 include:_netblocks.viacom.com include:_spf.salesforce.com include:spf.protection.outlook.com include:servers.mcsv.net include:stspg-customer.com
2 include:_spf.google.com include:_spf-customer.tbxnet.com ~all"]
The problem is that it breaks the line into two lines which I think it's not the normal behavior of the JSON.
what do you think?
Thanks,
The text was updated successfully, but these errors were encountered: