mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Rename ParseJson() to DecodeJson() for consistency
This commit is contained in:
parent
28f0104330
commit
e4d6e263d4
5 changed files with 52 additions and 52 deletions
|
@ -13,48 +13,48 @@
|
|||
-- TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
-- PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
assert(EncodeLua(ParseJson[[ ]]) == 'nil')
|
||||
assert(EncodeLua(ParseJson[[ 0 ]]) == '0' )
|
||||
assert(EncodeLua(ParseJson[[ [1] ]]) == '{1}')
|
||||
assert(EncodeLua(ParseJson[[ 2.3 ]]) == '2.3')
|
||||
assert(EncodeLua(ParseJson[[ [1,3,2] ]]) == '{1, 3, 2}')
|
||||
assert(EncodeLua(ParseJson[[ {1: 2, 3: 4} ]]) == '{[1]=2, [3]=4}')
|
||||
assert(EncodeLua(ParseJson[[ {"foo": 2, "bar": 4} ]]) == '{bar=4, foo=2}')
|
||||
assert(EncodeLua(ParseJson[[ null ]]) == 'nil')
|
||||
assert(EncodeLua(ParseJson[[ -123 ]]) == '-123')
|
||||
assert(EncodeLua(ParseJson[[ 1e6 ]]) == '1000000.')
|
||||
assert(EncodeLua(ParseJson[[ 1.e-6 ]]) == '0.000001')
|
||||
assert(EncodeLua(ParseJson[[ 1e-06 ]]) == '0.000001')
|
||||
assert(EncodeLua(ParseJson[[ 9.123e6 ]]) == '9123000.')
|
||||
assert(EncodeLua(ParseJson[[ [{"heh": [1,3,2]}] ]]) == '{{heh={1, 3, 2}}}')
|
||||
assert(EncodeLua(ParseJson[[ 3.14159 ]]) == '3.14159')
|
||||
assert(EncodeLua(ParseJson[[ {3=4} ]]) == '{[3]=4}')
|
||||
assert(EncodeLua(ParseJson[[ 1e-12 ]]) == '1e-12')
|
||||
assert(EncodeLua(DecodeJson[[ ]]) == 'nil')
|
||||
assert(EncodeLua(DecodeJson[[ 0 ]]) == '0' )
|
||||
assert(EncodeLua(DecodeJson[[ [1] ]]) == '{1}')
|
||||
assert(EncodeLua(DecodeJson[[ 2.3 ]]) == '2.3')
|
||||
assert(EncodeLua(DecodeJson[[ [1,3,2] ]]) == '{1, 3, 2}')
|
||||
assert(EncodeLua(DecodeJson[[ {1: 2, 3: 4} ]]) == '{[1]=2, [3]=4}')
|
||||
assert(EncodeLua(DecodeJson[[ {"foo": 2, "bar": 4} ]]) == '{bar=4, foo=2}')
|
||||
assert(EncodeLua(DecodeJson[[ null ]]) == 'nil')
|
||||
assert(EncodeLua(DecodeJson[[ -123 ]]) == '-123')
|
||||
assert(EncodeLua(DecodeJson[[ 1e6 ]]) == '1000000.')
|
||||
assert(EncodeLua(DecodeJson[[ 1.e-6 ]]) == '0.000001')
|
||||
assert(EncodeLua(DecodeJson[[ 1e-06 ]]) == '0.000001')
|
||||
assert(EncodeLua(DecodeJson[[ 9.123e6 ]]) == '9123000.')
|
||||
assert(EncodeLua(DecodeJson[[ [{"heh": [1,3,2]}] ]]) == '{{heh={1, 3, 2}}}')
|
||||
assert(EncodeLua(DecodeJson[[ 3.14159 ]]) == '3.14159')
|
||||
assert(EncodeLua(DecodeJson[[ {3=4} ]]) == '{[3]=4}')
|
||||
assert(EncodeLua(DecodeJson[[ 1e-12 ]]) == '1e-12')
|
||||
|
||||
assert(EncodeJson(ParseJson[[ 1e-12 ]]) == '1e-12')
|
||||
assert(EncodeJson(ParseJson[[ true ]]) == 'true')
|
||||
assert(EncodeJson(ParseJson[[ false ]]) == 'false')
|
||||
assert(EncodeJson(ParseJson[[ null ]]) == 'null')
|
||||
assert(EncodeJson(ParseJson[[ [] ]]) == '[]')
|
||||
assert(EncodeJson(ParseJson[[ {} ]]) == '{}')
|
||||
assert(EncodeJson(DecodeJson[[ 1e-12 ]]) == '1e-12')
|
||||
assert(EncodeJson(DecodeJson[[ true ]]) == 'true')
|
||||
assert(EncodeJson(DecodeJson[[ false ]]) == 'false')
|
||||
assert(EncodeJson(DecodeJson[[ null ]]) == 'null')
|
||||
assert(EncodeJson(DecodeJson[[ [] ]]) == '[]')
|
||||
assert(EncodeJson(DecodeJson[[ {} ]]) == '{}')
|
||||
|
||||
assert(ParseJson[["\f"]] == '\f') -- c0
|
||||
assert(ParseJson[["\t"]] == '\t') -- c0
|
||||
assert(ParseJson[["\n"]] == '\n') -- c0
|
||||
assert(ParseJson[["\r"]] == '\r') -- c0
|
||||
assert(ParseJson[["\\"]] == '\\') -- c0
|
||||
assert(ParseJson[["\""]] == '\"') -- c0
|
||||
assert(ParseJson[["\u0100"]] == 'Ā') -- latin-1
|
||||
assert(ParseJson[["\ud800\udf30\ud800\udf30"]] == '𐌰𐌰') -- utf-16 astral planes gothic
|
||||
assert(ParseJson[["\uD800"]] == '\\uD800') -- utf-16 invalid (keep utf-8 well-formed)
|
||||
assert(DecodeJson[["\f"]] == '\f') -- c0
|
||||
assert(DecodeJson[["\t"]] == '\t') -- c0
|
||||
assert(DecodeJson[["\n"]] == '\n') -- c0
|
||||
assert(DecodeJson[["\r"]] == '\r') -- c0
|
||||
assert(DecodeJson[["\\"]] == '\\') -- c0
|
||||
assert(DecodeJson[["\""]] == '\"') -- c0
|
||||
assert(DecodeJson[["\u0100"]] == 'Ā') -- latin-1
|
||||
assert(DecodeJson[["\ud800\udf30\ud800\udf30"]] == '𐌰𐌰') -- utf-16 astral planes gothic
|
||||
assert(DecodeJson[["\uD800"]] == '\\uD800') -- utf-16 invalid (keep utf-8 well-formed)
|
||||
|
||||
assert(EncodeJson(ParseJson[[ -9223372036854775808 ]]) == '-9223372036854775808') -- minimum 64-bit integer
|
||||
assert(EncodeJson(ParseJson[[ 9223372036854775807 ]]) == '9223372036854775807') -- maximum 64-bit integer
|
||||
assert(EncodeJson(ParseJson[[ 9223372036854775808 ]]) == '9223372036854776000') -- switches to double due to integer overflow
|
||||
assert(EncodeJson(ParseJson[[ -9223372036854775809 ]]) == '-9223372036854776000') -- switches to double due to integer underflow
|
||||
assert(EncodeJson(ParseJson[[ 9223372036854775807.0 ]]) == '9223372036854776000') -- switches to double due to period mark
|
||||
assert(EncodeJson(ParseJson[[ 2.7182818284590452354 ]]) == '2.718281828459045') -- euler constant w/ 17 digit precision
|
||||
assert( EncodeLua(ParseJson[[ 2.7182818284590452354 ]]) == '2.718281828459045') -- euler constant w/ 17 digit precision
|
||||
assert(EncodeJson(DecodeJson[[ -9223372036854775808 ]]) == '-9223372036854775808') -- minimum 64-bit integer
|
||||
assert(EncodeJson(DecodeJson[[ 9223372036854775807 ]]) == '9223372036854775807') -- maximum 64-bit integer
|
||||
assert(EncodeJson(DecodeJson[[ 9223372036854775808 ]]) == '9223372036854776000') -- switches to double due to integer overflow
|
||||
assert(EncodeJson(DecodeJson[[ -9223372036854775809 ]]) == '-9223372036854776000') -- switches to double due to integer underflow
|
||||
assert(EncodeJson(DecodeJson[[ 9223372036854775807.0 ]]) == '9223372036854776000') -- switches to double due to period mark
|
||||
assert(EncodeJson(DecodeJson[[ 2.7182818284590452354 ]]) == '2.718281828459045') -- euler constant w/ 17 digit precision
|
||||
assert( EncodeLua(DecodeJson[[ 2.7182818284590452354 ]]) == '2.718281828459045') -- euler constant w/ 17 digit precision
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- benchmark nanos ticks
|
||||
|
@ -67,27 +67,27 @@ assert( EncodeLua(ParseJson[[ 2.7182818284590452354 ]]) == '2.718281828459045')
|
|||
-- JsonParseObject 523 1622
|
||||
|
||||
function JsonParseEmpty()
|
||||
ParseJson[[]]
|
||||
DecodeJson[[]]
|
||||
end
|
||||
|
||||
function JsonParseInteger()
|
||||
ParseJson[[ -9223372036854775808 ]]
|
||||
DecodeJson[[ -9223372036854775808 ]]
|
||||
end
|
||||
|
||||
function JsonParseDouble()
|
||||
ParseJson[[ 2.7182818284590452354 ]]
|
||||
DecodeJson[[ 2.7182818284590452354 ]]
|
||||
end
|
||||
|
||||
function JsonParseString()
|
||||
ParseJson[[ "\ud800\udf30 he𐌰𐌰o \ud800\udf30" ]]
|
||||
DecodeJson[[ "\ud800\udf30 he𐌰𐌰o \ud800\udf30" ]]
|
||||
end
|
||||
|
||||
function JsonParseArray()
|
||||
ParseJson[[ [123,456,789] ]]
|
||||
DecodeJson[[ [123,456,789] ]]
|
||||
end
|
||||
|
||||
function JsonParseObject()
|
||||
ParseJson[[ {"3":"1", "4":"1", "5":"9"} ]]
|
||||
DecodeJson[[ {"3":"1", "4":"1", "5":"9"} ]]
|
||||
end
|
||||
|
||||
print('JsonParseEmpty', Benchmark(JsonParseEmpty))
|
||||
|
|
|
@ -673,7 +673,7 @@ FUNCTIONS
|
|||
URIs that do things like embed a PNG file in a web page. See
|
||||
encodebase64.c.
|
||||
|
||||
ParseJson(input:str)
|
||||
DecodeJson(input:str)
|
||||
├─→ value:*
|
||||
└─→ nil, error:str
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ static struct Rc Parse(struct lua_State *L, const char *p, const char *e) {
|
|||
* @param n is byte length of `p` or -1 for automatic strlen()
|
||||
* @return 1 if value was pushed, 0 on end, or -1 on error
|
||||
*/
|
||||
int ParseJson(struct lua_State *L, const char *p, size_t n) {
|
||||
int DecodeJson(struct lua_State *L, const char *p, size_t n) {
|
||||
if (n == -1) n = p ? strlen(p) : 0;
|
||||
return Parse(L, p, p + n).t;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int ParseJson(struct lua_State *, const char *, size_t);
|
||||
int DecodeJson(struct lua_State *, const char *, size_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -146,7 +146,7 @@ STATIC_YOINK("ShowCrashReportsEarly");
|
|||
#define REDBEAN "redbean"
|
||||
#endif
|
||||
|
||||
#define VERSION 0x02000a
|
||||
#define VERSION 0x02000b
|
||||
#define HEARTBEAT 5000 /*ms*/
|
||||
#define HASH_LOAD_FACTOR /* 1. / */ 4
|
||||
#define MONITOR_MICROS 150000
|
||||
|
@ -4259,11 +4259,11 @@ static int LuaEncodeLua(lua_State *L) {
|
|||
return LuaEncodeSmth(L, LuaEncodeLuaData);
|
||||
}
|
||||
|
||||
static int LuaParseJson(lua_State *L) {
|
||||
static int LuaDecodeJson(lua_State *L) {
|
||||
size_t n;
|
||||
const char *p;
|
||||
p = luaL_checklstring(L, 1, &n);
|
||||
return ParseJson(L, p, n);
|
||||
return DecodeJson(L, p, n);
|
||||
}
|
||||
|
||||
static int LuaGetUrl(lua_State *L) {
|
||||
|
@ -5072,6 +5072,7 @@ static const luaL_Reg kLuaFuncs[] = {
|
|||
{"Crc32c", LuaCrc32c}, //
|
||||
{"Decimate", LuaDecimate}, //
|
||||
{"DecodeBase64", LuaDecodeBase64}, //
|
||||
{"DecodeJson", LuaDecodeJson}, //
|
||||
{"DecodeLatin1", LuaDecodeLatin1}, //
|
||||
{"Deflate", LuaDeflate}, //
|
||||
{"EncodeBase64", LuaEncodeBase64}, //
|
||||
|
@ -5158,7 +5159,6 @@ static const luaL_Reg kLuaFuncs[] = {
|
|||
{"ParseHost", LuaParseHost}, //
|
||||
{"ParseHttpDateTime", LuaParseHttpDateTime}, //
|
||||
{"ParseIp", LuaParseIp}, //
|
||||
{"ParseJson", LuaParseJson}, //
|
||||
{"ParseParams", LuaParseParams}, //
|
||||
{"ParseUrl", LuaParseUrl}, //
|
||||
{"Popcnt", LuaPopcnt}, //
|
||||
|
|
Loading…
Reference in a new issue