diff options
author | Mark Pulford <mark@kyne.com.au> | 2011-05-09 00:19:28 +0930 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2011-05-09 00:19:28 +0930 |
commit | 0c0196aad87812695b286ca1555b868ad3a50a5e (patch) | |
tree | 102bc97f3c6441ae87eaa36195b9ceaef90ff4a2 | |
parent | 17cb9b7433bfebaef2205ca01f82708bdc5913ff (diff) | |
download | lua-cjson-0c0196aad87812695b286ca1555b868ad3a50a5e.tar.gz lua-cjson-0c0196aad87812695b286ca1555b868ad3a50a5e.tar.bz2 lua-cjson-0c0196aad87812695b286ca1555b868ad3a50a5e.zip |
Tidy and reformat lua_cjson.c (minor)
-rw-r--r-- | lua_cjson.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/lua_cjson.c b/lua_cjson.c index 179c830..fa2d6a7 100644 --- a/lua_cjson.c +++ b/lua_cjson.c | |||
@@ -552,8 +552,6 @@ static void json_append_object(lua_State *l, json_config_t *cfg, | |||
552 | /* table, key, value */ | 552 | /* table, key, value */ |
553 | keytype = lua_type(l, -2); | 553 | keytype = lua_type(l, -2); |
554 | if (keytype == LUA_TNUMBER) { | 554 | if (keytype == LUA_TNUMBER) { |
555 | /* Can't just use json_append_string() below since it would | ||
556 | * convert the value in the callers data structure. */ | ||
557 | strbuf_append_char(json, '"'); | 555 | strbuf_append_char(json, '"'); |
558 | json_append_number(l, json, -2, cfg->encode_refuse_badnum); | 556 | json_append_number(l, json, -2, cfg->encode_refuse_badnum); |
559 | strbuf_append_mem(json, "\": ", 3); | 557 | strbuf_append_mem(json, "\": ", 3); |
@@ -644,9 +642,10 @@ static int json_encode(lua_State *l) | |||
644 | 642 | ||
645 | /* ===== DECODING ===== */ | 643 | /* ===== DECODING ===== */ |
646 | 644 | ||
647 | static void json_process_value(lua_State *l, json_parse_t *json, json_token_t *token); | 645 | static void json_process_value(lua_State *l, json_parse_t *json, |
646 | json_token_t *token); | ||
648 | 647 | ||
649 | static inline int hexdigit2int(char hex) | 648 | static int hexdigit2int(char hex) |
650 | { | 649 | { |
651 | if ('0' <= hex && hex <= '9') | 650 | if ('0' <= hex && hex <= '9') |
652 | return hex - '0'; | 651 | return hex - '0'; |
@@ -952,7 +951,7 @@ static void json_next_token(json_parse_t *json, json_token_t *token) | |||
952 | /* Process characters which triggered T_UNKNOWN */ | 951 | /* Process characters which triggered T_UNKNOWN */ |
953 | ch = json->data[json->index]; | 952 | ch = json->data[json->index]; |
954 | 953 | ||
955 | /* Must use strncmp() to match the front of the JSON string | 954 | /* Must use strncmp() to match the front of the JSON string. |
956 | * JSON identifier must be lowercase. | 955 | * JSON identifier must be lowercase. |
957 | * When strict_numbers if disabled, either case is allowed for | 956 | * When strict_numbers if disabled, either case is allowed for |
958 | * Infinity/NaN (since we are no longer following the spec..) */ | 957 | * Infinity/NaN (since we are no longer following the spec..) */ |
@@ -1055,9 +1054,8 @@ static void json_parse_object_context(lua_State *l, json_parse_t *json) | |||
1055 | 1054 | ||
1056 | json_next_token(json, &token); | 1055 | json_next_token(json, &token); |
1057 | 1056 | ||
1058 | if (token.type == T_OBJ_END) { | 1057 | if (token.type == T_OBJ_END) |
1059 | return; | 1058 | return; |
1060 | } | ||
1061 | 1059 | ||
1062 | if (token.type != T_COMMA) | 1060 | if (token.type != T_COMMA) |
1063 | json_throw_parse_error(l, json, "comma or object end", &token); | 1061 | json_throw_parse_error(l, json, "comma or object end", &token); |
@@ -1081,9 +1079,8 @@ static void json_parse_array_context(lua_State *l, json_parse_t *json) | |||
1081 | json_next_token(json, &token); | 1079 | json_next_token(json, &token); |
1082 | 1080 | ||
1083 | /* Handle empty arrays */ | 1081 | /* Handle empty arrays */ |
1084 | if (token.type == T_ARR_END) { | 1082 | if (token.type == T_ARR_END) |
1085 | return; | 1083 | return; |
1086 | } | ||
1087 | 1084 | ||
1088 | for (i = 1; ; i++) { | 1085 | for (i = 1; ; i++) { |
1089 | json_process_value(l, json, &token); | 1086 | json_process_value(l, json, &token); |
@@ -1091,9 +1088,8 @@ static void json_parse_array_context(lua_State *l, json_parse_t *json) | |||
1091 | 1088 | ||
1092 | json_next_token(json, &token); | 1089 | json_next_token(json, &token); |
1093 | 1090 | ||
1094 | if (token.type == T_ARR_END) { | 1091 | if (token.type == T_ARR_END) |
1095 | return; | 1092 | return; |
1096 | } | ||
1097 | 1093 | ||
1098 | if (token.type != T_COMMA) | 1094 | if (token.type != T_COMMA) |
1099 | json_throw_parse_error(l, json, "comma or array end", &token); | 1095 | json_throw_parse_error(l, json, "comma or array end", &token); |
@@ -1103,7 +1099,8 @@ static void json_parse_array_context(lua_State *l, json_parse_t *json) | |||
1103 | } | 1099 | } |
1104 | 1100 | ||
1105 | /* Handle the "value" context */ | 1101 | /* Handle the "value" context */ |
1106 | static void json_process_value(lua_State *l, json_parse_t *json, json_token_t *token) | 1102 | static void json_process_value(lua_State *l, json_parse_t *json, |
1103 | json_token_t *token) | ||
1107 | { | 1104 | { |
1108 | switch (token->type) { | 1105 | switch (token->type) { |
1109 | case T_STRING: | 1106 | case T_STRING: |