Skip to content

Commit

Permalink
Merge pull request #2 from PeterScott/master
Browse files Browse the repository at this point in the history
Some relatively minor changes
  • Loading branch information
James McLaughlin committed Feb 12, 2012
2 parents fb2e321 + 46b4339 commit dde2b12
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions json.c
Expand Up @@ -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
Expand Down Expand Up @@ -134,6 +127,7 @@ static int new_value
}

break;
default: break;
};

value->u.array.length = 0;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
};
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -682,6 +678,8 @@ void json_value_free (json_value * value)

free (value->u.string.ptr);
break;

default: break;
};

cur_value = value;
Expand Down

0 comments on commit dde2b12

Please sign in to comment.