Skip to content
This repository
Browse code

Merge pull request #2 from PeterScott/master

Some relatively minor changes
  • Loading branch information...
commit dde2b12e8eb7d7cd39e9c1398dd9222a71f10ba4 2 parents fb2e321 + 46b4339
James McLaughlin authored February 12, 2012

Showing 1 changed file with 13 additions and 15 deletions. Show diff stats Hide diff stats

  1. 28  json.c
28  json.c
@@ -45,19 +45,12 @@ typedef unsigned short json_uchar;
45 45
 #define numeric(b) \
46 46
    ((b) >= '0' && (b) <= '9')
47 47
 
48  
-static const unsigned char hex_table [] =
49  
-{
50  
-   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
51  
-   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
52  
-   -1, -1, -1, -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1, -1, -1, -1, -1, -1, 10,
53  
-   11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
54  
-   -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1,
55  
-   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 
56  
-};
57  
-
58 48
 static unsigned char hex_value (json_char c)
59 49
 {
60  
-   return c > 127 ? 0xFF : hex_table [c];
  50
+   if (c >= 48 && c <= 57)  return c - 48;
  51
+   if (c >= 65 && c <= 70)  return c - 55;
  52
+   if (c >= 97 && c <= 102) return c - 87;
  53
+   return 0xFF;
61 54
 }
62 55
 
63 56
 typedef struct
@@ -134,6 +127,7 @@ static int new_value
134 127
             }
135 128
 
136 129
             break;
  130
+         default: break;
137 131
       };
138 132
 
139 133
       value->u.array.length = 0;
@@ -184,7 +178,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
184 178
    json_state state;
185 179
    int flags;
186 180
 
187  
-   *error = 0;
  181
+   error[0] = '\0';
188 182
 
189 183
    memset (&state, 0, sizeof (json_state));
190 184
    memcpy (&state.settings, settings, sizeof (json_settings));
@@ -231,7 +225,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
231 225
                     if ((uc_b1 = hex_value (*++ i)) == 0xFF || (uc_b2 = hex_value (*++ i)) == 0xFF
232 226
                           || (uc_b3 = hex_value (*++ i)) == 0xFF || (uc_b4 = hex_value (*++ i)) == 0xFF)
233 227
                     {
234  
-                        sprintf (error, "Invalid character value (at %d:%d)", b, cur_line, e_off);
  228
+                        sprintf (error, "Invalid character value `%c` (at %d:%d)", b, cur_line, e_off);
235 229
                         goto e_failed;
236 230
                     }
237 231
 
@@ -312,6 +306,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
312 306
 
313 307
                      flags |= flag_seek_value | flag_need_colon;
314 308
                      continue;
  309
+                  default: break;
315 310
                };
316 311
             }
317 312
             else
@@ -552,6 +547,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
552 547
 
553 548
             flags |= flag_next | flag_reproc;
554 549
             break;
  550
+         default: break;
555 551
          };
556 552
 
557 553
          if (flags & flag_reproc)
@@ -589,6 +585,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
589 585
                            [parent->u.array.length] = top;
590 586
 
591 587
                      break;
  588
+                  default: break;
592 589
                };
593 590
             }
594 591
 
@@ -616,8 +613,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
616 613
 
617 614
 e_failed:
618 615
 
619  
-   if (error)
620  
-      strcpy (error_buf, *error ? error : "Unknown error");
  616
+   strcpy (error_buf, *error ? error : "Unknown error");
621 617
 
622 618
    if (state.first_pass)
623 619
       alloc = root;
@@ -682,6 +678,8 @@ void json_value_free (json_value * value)
682 678
 
683 679
             free (value->u.string.ptr);
684 680
             break;
  681
+
  682
+         default: break;
685 683
       };
686 684
 
687 685
       cur_value = value;

0 notes on commit dde2b12

Please sign in to comment.
Something went wrong with that request. Please try again.