Permalink
Browse files

Merge pull request #2 from PeterScott/master

Some relatively minor changes
  • Loading branch information...
2 parents fb2e321 + 46b4339 commit dde2b12e8eb7d7cd39e9c1398dd9222a71f10ba4 James McLaughlin committed Feb 12, 2012
Showing with 13 additions and 15 deletions.
  1. +13 −15 json.c
View
28 json.c
@@ -45,19 +45,12 @@ typedef unsigned short json_uchar;
#define numeric(b) \
((b) >= '0' && (b) <= '9')
-static const unsigned char hex_table [] =
-{
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10,
- 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
-};
-
static unsigned char hex_value (json_char c)
{
- return c > 127 ? 0xFF : hex_table [c];
+ if (c >= 48 && c <= 57) return c - 48;
+ if (c >= 65 && c <= 70) return c - 55;
+ if (c >= 97 && c <= 102) return c - 87;
+ return 0xFF;
}
typedef struct
@@ -134,6 +127,7 @@ static int new_value
}
break;
+ default: break;
};
value->u.array.length = 0;
@@ -184,7 +178,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
json_state state;
int flags;
- *error = 0;
+ error[0] = '\0';
memset (&state, 0, sizeof (json_state));
memcpy (&state.settings, settings, sizeof (json_settings));
@@ -231,7 +225,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
if ((uc_b1 = hex_value (*++ i)) == 0xFF || (uc_b2 = hex_value (*++ i)) == 0xFF
|| (uc_b3 = hex_value (*++ i)) == 0xFF || (uc_b4 = hex_value (*++ i)) == 0xFF)
{
- sprintf (error, "Invalid character value (at %d:%d)", b, cur_line, e_off);
+ sprintf (error, "Invalid character value `%c` (at %d:%d)", b, cur_line, e_off);
goto e_failed;
}
@@ -312,6 +306,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
flags |= flag_seek_value | flag_need_colon;
continue;
+ default: break;
};
}
else
@@ -552,6 +547,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
flags |= flag_next | flag_reproc;
break;
+ default: break;
};
if (flags & flag_reproc)
@@ -589,6 +585,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
[parent->u.array.length] = top;
break;
+ default: break;
};
}
@@ -616,8 +613,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
e_failed:
- if (error)
- strcpy (error_buf, *error ? error : "Unknown error");
+ strcpy (error_buf, *error ? error : "Unknown error");
if (state.first_pass)
alloc = root;
@@ -682,6 +678,8 @@ void json_value_free (json_value * value)
free (value->u.string.ptr);
break;
+
+ default: break;
};
cur_value = value;

0 comments on commit dde2b12

Please sign in to comment.