| 1 |
|
| #include "jsonsl.h" |
| 2 |
|
| #include <assert.h> |
| 3 |
|
| #include <limits.h> |
| 4 |
|
| #include <ctype.h> |
| 5 |
|
| |
| 6 |
|
| #ifdef JSONSL_USE_METRICS |
| 7 |
|
| #define XMETRICS \ |
| 8 |
|
| X(STRINGY_INSIGNIFICANT) \ |
| 9 |
|
| X(STRINGY_SLOWPATH) \ |
| 10 |
|
| X(ALLOWED_WHITESPACE) \ |
| 11 |
|
| X(QUOTE_FASTPATH) \ |
| 12 |
|
| X(SPECIAL_FASTPATH) \ |
| 13 |
|
| X(SPECIAL_WSPOP) \ |
| 14 |
|
| X(SPECIAL_SLOWPATH) \ |
| 15 |
|
| X(GENERIC) \ |
| 16 |
|
| X(STRUCTURAL_TOKEN) \ |
| 17 |
|
| X(SPECIAL_SWITCHFIRST) \ |
| 18 |
|
| X(STRINGY_CATCH) \ |
| 19 |
|
| X(ESCAPES) \ |
| 20 |
|
| X(TOTAL) \ |
| 21 |
|
| |
| 22 |
|
| struct jsonsl_metrics_st { |
| 23 |
|
| #define X(m) \ |
| 24 |
|
| unsigned long metric_##m; |
| 25 |
|
| XMETRICS |
| 26 |
|
| #undef X |
| 27 |
|
| }; |
| 28 |
|
| |
| 29 |
|
| static struct jsonsl_metrics_st GlobalMetrics = { 0 }; |
| 30 |
|
| static unsigned long GenericCounter[0x100] = { 0 }; |
| 31 |
|
| static unsigned long StringyCatchCounter[0x100] = { 0 }; |
| 32 |
|
| |
| 33 |
|
| #define INCR_METRIC(m) \ |
| 34 |
|
| GlobalMetrics.metric_##m++; |
| 35 |
|
| |
| 36 |
|
| #define INCR_GENERIC(c) \ |
| 37 |
|
| INCR_METRIC(GENERIC); \ |
| 38 |
|
| GenericCounter[c]++; \ |
| 39 |
|
| |
| 40 |
|
| #define INCR_STRINGY_CATCH(c) \ |
| 41 |
|
| INCR_METRIC(STRINGY_CATCH); \ |
| 42 |
|
| StringyCatchCounter[c]++; |
| 43 |
|
| |
| 44 |
|
| JSONSL_API |
| 45 |
|
| void jsonsl_dump_global_metrics(void) |
| 46 |
|
| { |
| 47 |
|
| int ii; |
| 48 |
|
| printf("JSONSL Metrics:\n"); |
| 49 |
|
| #define X(m) \ |
| 50 |
|
| printf("\t%-30s %20lu (%0.2f%%)\n", #m, GlobalMetrics.metric_##m, \ |
| 51 |
|
| (float)((float)(GlobalMetrics.metric_##m/(float)GlobalMetrics.metric_TOTAL)) * 100); |
| 52 |
|
| XMETRICS |
| 53 |
|
| #undef X |
| 54 |
|
| printf("Generic Characters:\n"); |
| 55 |
|
| for (ii = 0; ii < 0xff; ii++) { |
| 56 |
|
| if (GenericCounter[ii]) { |
| 57 |
|
| printf("\t[ %c ] %lu\n", ii, GenericCounter[ii]); |
| 58 |
|
| } |
| 59 |
|
| } |
| 60 |
|
| printf("Weird string loop\n"); |
| 61 |
|
| for (ii = 0; ii < 0xff; ii++) { |
| 62 |
|
| if (StringyCatchCounter[ii]) { |
| 63 |
|
| printf("\t[ %c ] %lu\n", ii, StringyCatchCounter[ii]); |
| 64 |
|
| } |
| 65 |
|
| } |
| 66 |
|
| } |
| 67 |
|
| |
| 68 |
|
| #else |
| 69 |
|
| #define INCR_METRIC(m) |
| 70 |
|
| #define INCR_GENERIC(c) |
| 71 |
|
| #define INCR_STRINGY_CATCH(c) |
| 72 |
|
| JSONSL_API |
| 73 |
0 |
| void jsonsl_dump_global_metrics(void) { } |
| 74 |
|
| #endif /* JSONSL_USE_METRICS */ |
| 75 |
|
| |
| 76 |
|
| #define CASE_DIGITS \ |
| 77 |
|
| case '1': \ |
| 78 |
|
| case '2': \ |
| 79 |
|
| case '3': \ |
| 80 |
|
| case '4': \ |
| 81 |
|
| case '5': \ |
| 82 |
|
| case '6': \ |
| 83 |
|
| case '7': \ |
| 84 |
|
| case '8': \ |
| 85 |
|
| case '9': \ |
| 86 |
|
| case '0': |
| 87 |
|
| |
| 88 |
|
| |
| 89 |
|
| |
| 90 |
|
| /** |
| 91 |
|
| * This table (predeclared) contains characters which are recognized |
| 92 |
|
| * non-string values. |
| 93 |
|
| */ |
| 94 |
|
| static jsonsl_special_t *Special_table; |
| 95 |
|
| #define extract_special(c) \ |
| 96 |
|
| Special_table[(unsigned int)(c & 0xff)] |
| 97 |
|
| |
| 98 |
|
| /** |
| 99 |
|
| * This table (predeclared) contains the tokens and other characters |
| 100 |
|
| * which signal the termination of the non-string values. |
| 101 |
|
| */ |
| 102 |
|
| static int *Special_Endings; |
| 103 |
|
| #define is_special_end(c) \ |
| 104 |
|
| Special_Endings[(unsigned int)c & 0xff] |
| 105 |
|
| |
| 106 |
|
| /** |
| 107 |
|
| * This table contains entries for the allowed whitespace |
| 108 |
|
| * as per RFC 4627 |
| 109 |
|
| */ |
| 110 |
|
| static int *Allowed_Whitespace; |
| 111 |
|
| #define is_allowed_whitespace(c) \ |
| 112 |
|
| (c == ' ' || Allowed_Whitespace[(unsigned int)c & 0xff]) |
| 113 |
|
| |
| 114 |
|
| |
| 115 |
|
| /** |
| 116 |
|
| * This table contains allowed two-character escapes |
| 117 |
|
| * as per the RFC |
| 118 |
|
| */ |
| 119 |
|
| static int *Allowed_Escapes; |
| 120 |
|
| #define is_allowed_escape(c) \ |
| 121 |
|
| Allowed_Escapes[(unsigned int)c & 0xff] |
| 122 |
|
| |
| 123 |
|
| JSONSL_API |
| 124 |
33 |
| jsonsl_t jsonsl_new(int nlevels) |
| 125 |
|
| { |
| 126 |
|
| struct jsonsl_st *jsn = |
| 127 |
33 |
| calloc(1, sizeof (*jsn) + |
| 128 |
33 |
| ( (nlevels-1) * sizeof (struct jsonsl_state_st) ) |
| 129 |
|
| ); |
| 130 |
|
| |
| 131 |
33 |
| jsn->levels_max = nlevels; |
| 132 |
33 |
| jsn->max_callback_level = -1; |
| 133 |
33 |
| jsonsl_reset(jsn); |
| 134 |
33 |
| return jsn; |
| 135 |
|
| } |
| 136 |
|
| |
| 137 |
|
| JSONSL_API |
| 138 |
67 |
| void jsonsl_reset(jsonsl_t jsn) |
| 139 |
|
| { |
| 140 |
|
| unsigned int ii; |
| 141 |
67 |
| jsn->tok_last = 0; |
| 142 |
67 |
| jsn->can_insert = 1; |
| 143 |
67 |
| jsn->pos = 0; |
| 144 |
67 |
| jsn->level = 0; |
| 145 |
67 |
| jsn->in_escape = 0; |
| 146 |
67 |
| jsn->expecting = 0; |
| 147 |
|
| |
| 148 |
67 |
| memset(jsn->stack, 0, (jsn->levels_max * sizeof (struct jsonsl_state_st))); |
| 149 |
|
| |
| 150 |
33026 |
▶ | for (ii = 0; ii < jsn->levels_max; ii++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ii = 0; ii < jsn->levels_max; ii++) { |
32959 |
67 |
33026 |
|
| 151 |
32959 |
| jsn->stack[ii].level = ii; |
| 152 |
|
| } |
| 153 |
67 |
| } |
| 154 |
|
| |
| 155 |
|
| JSONSL_API |
| 156 |
26 |
| void jsonsl_destroy(jsonsl_t jsn) |
| 157 |
|
| { |
| 158 |
26 |
▶ | if (jsn) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (jsn) { |
26 |
0 |
26 |
|
| 159 |
26 |
| free(jsn); |
| 160 |
|
| } |
| 161 |
26 |
| } |
| 162 |
|
| |
| 163 |
|
| JSONSL_API |
| 164 |
|
| void |
| 165 |
57 |
| jsonsl_feed(jsonsl_t jsn, const jsonsl_char_t *bytes, size_t nbytes) |
| 166 |
|
| { |
| 167 |
|
| |
| 168 |
|
| #define INVOKE_ERROR(eb) \ |
| 169 |
|
| if (jsn->error_callback(jsn, JSONSL_ERROR_##eb, state, (char*)c)) { \ |
| 170 |
|
| goto GT_AGAIN; \ |
| 171 |
|
| } \ |
| 172 |
|
| return; |
| 173 |
|
| |
| 174 |
|
| #define STACK_PUSH \ |
| 175 |
|
| if (jsn->level >= (levels_max-1)) { \ |
| 176 |
|
| jsn->error_callback(jsn, JSONSL_ERROR_LEVELS_EXCEEDED, state, (char*)c); \ |
| 177 |
|
| return; \ |
| 178 |
|
| } \ |
| 179 |
|
| state = jsn->stack + (++jsn->level); \ |
| 180 |
|
| state->ignore_callback = jsn->stack[jsn->level-1].ignore_callback; \ |
| 181 |
|
| state->pos_begin = jsn->pos; |
| 182 |
|
| |
| 183 |
|
| #define STACK_POP_NOPOS \ |
| 184 |
|
| state->pos_cur = jsn->pos; \ |
| 185 |
|
| state = jsn->stack + (--jsn->level); |
| 186 |
|
| |
| 187 |
|
| |
| 188 |
|
| #define STACK_POP \ |
| 189 |
|
| STACK_POP_NOPOS; \ |
| 190 |
|
| state->pos_cur = jsn->pos; |
| 191 |
|
| |
| 192 |
|
| #define CALLBACK_AND_POP_NOPOS(T) \ |
| 193 |
|
| state->pos_cur = jsn->pos; \ |
| 194 |
|
| DO_CALLBACK(T, POP); \ |
| 195 |
|
| state->nescapes = 0; \ |
| 196 |
|
| state = jsn->stack + (--jsn->level); |
| 197 |
|
| |
| 198 |
|
| #define CALLBACK_AND_POP(T) \ |
| 199 |
|
| CALLBACK_AND_POP_NOPOS(T); \ |
| 200 |
|
| state->pos_cur = jsn->pos; |
| 201 |
|
| |
| 202 |
|
| #define SPECIAL_POP \ |
| 203 |
|
| CALLBACK_AND_POP(SPECIAL); \ |
| 204 |
|
| jsn->expecting = 0; \ |
| 205 |
|
| jsn->tok_last = 0; \ |
| 206 |
|
| |
| 207 |
|
| #define CUR_CHAR (*(jsonsl_uchar_t*)c) |
| 208 |
|
| |
| 209 |
|
| #define DO_CALLBACK(T, action) \ |
| 210 |
|
| if (jsn->call_##T && \ |
| 211 |
|
| jsn->max_callback_level > state->level && \ |
| 212 |
|
| state->ignore_callback == 0) { \ |
| 213 |
|
| \ |
| 214 |
|
| if (jsn->action_callback_##action) { \ |
| 215 |
|
| jsn->action_callback_##action(jsn, JSONSL_ACTION_##action, state, (jsonsl_char_t*)c); \ |
| 216 |
|
| } else if (jsn->action_callback) { \ |
| 217 |
|
| jsn->action_callback(jsn, JSONSL_ACTION_##action, state, (jsonsl_char_t*)c); \ |
| 218 |
|
| } \ |
| 219 |
|
| } |
| 220 |
|
| |
| 221 |
|
| /** |
| 222 |
|
| * Verifies that we are able to insert the (non-string) item into a hash. |
| 223 |
|
| */ |
| 224 |
|
| #define ENSURE_HVAL \ |
| 225 |
|
| if (state->nelem % 2 == 0 && state->type == JSONSL_T_OBJECT) { \ |
| 226 |
|
| INVOKE_ERROR(HKEY_EXPECTED); \ |
| 227 |
|
| } |
| 228 |
|
| |
| 229 |
|
| #define VERIFY_SPECIAL(lit) \ |
| 230 |
|
| if (CUR_CHAR != (lit)[jsn->pos - state->pos_begin]) { \ |
| 231 |
|
| INVOKE_ERROR(SPECIAL_EXPECTED); \ |
| 232 |
|
| } |
| 233 |
|
| |
| 234 |
57 |
| const jsonsl_uchar_t *c = (jsonsl_uchar_t*)bytes; |
| 235 |
57 |
| size_t levels_max = jsn->levels_max; |
| 236 |
57 |
| struct jsonsl_state_st *state = jsn->stack + jsn->level; |
| 237 |
|
| static int chrt_string_nopass[0x100] = { JSONSL_CHARTABLE_string_nopass }; |
| 238 |
57 |
| jsn->base = bytes; |
| 239 |
|
| |
| 240 |
7550 |
▶ | for (; nbytes; nbytes--, jsn->pos++, c++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (; nbytes; nbytes--, jsn->pos++, c++) { |
7507 |
43 |
7550 |
|
| 241 |
|
| register jsonsl_type_t state_type; |
| 242 |
|
| INCR_METRIC(TOTAL); |
| 243 |
|
| /* Special escape handling for some stuff */ |
| 244 |
7507 |
▶ | if (jsn->in_escape) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (jsn->in_escape) { |
7494 |
13 |
7507 |
|
| 245 |
13 |
| jsn->in_escape = 0; |
| 246 |
13 |
▶ | if (!is_allowed_escape(CUR_CHAR)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_allowed_escape(CUR_CHAR)) { |
0 |
13 |
13 |
|
| 247 |
0 |
▶ | INVOKE_ERROR(ESCAPE_INVALID); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(ESCAPE_INVALID); |
0 |
0 |
0 |
|
| 248 |
13 |
▶ | } else if (CUR_CHAR == 'u') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (CUR_CHAR == 'u') { |
4 |
9 |
13 |
|
| 249 |
4 |
▶ | DO_CALLBACK(UESCAPE, UESCAPE); |
Branch: 5 branches
| Branch | True | False | Total |
| DO_CALLBACK(UESCAPE, UESCAPE); |
0 |
4 |
4 |
| DO_CALLBACK(UESCAPE, UESCAPE); |
0 |
0 |
0 |
| DO_CALLBACK(UESCAPE, UESCAPE); |
0 |
0 |
0 |
| DO_CALLBACK(UESCAPE, UESCAPE); |
0 |
0 |
0 |
| DO_CALLBACK(UESCAPE, UESCAPE); |
0 |
0 |
0 |
|
| 250 |
4 |
▶ | if (jsn->return_UESCAPE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (jsn->return_UESCAPE) { |
0 |
4 |
4 |
|
| 251 |
0 |
| return; |
| 252 |
|
| } |
| 253 |
|
| } |
| 254 |
13 |
| goto GT_NEXT; |
| 255 |
|
| } |
| 256 |
7494 |
| GT_AGAIN: |
| 257 |
|
| /** |
| 258 |
|
| * Several fast-tracks for common cases: |
| 259 |
|
| */ |
| 260 |
7494 |
| state_type = state->type; |
| 261 |
7494 |
▶ | if (state_type & JSONSL_Tf_STRINGY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (state_type & JSONSL_Tf_STRINGY) { |
1615 |
5879 |
7494 |
|
| 262 |
|
| /* check if our character cannot ever change our current string state |
| 263 |
|
| * or throw an error |
| 264 |
|
| */ |
| 265 |
1615 |
| if ( |
| 266 |
|
| #ifdef JSONSL_USE_WCHAR |
| 267 |
|
| CUR_CHAR >= 0x100 || |
| 268 |
|
| #endif /* JSONSL_USE_WCHAR */ |
| 269 |
1615 |
▶ | (!chrt_string_nopass[CUR_CHAR & 0xff])) { |
Branch: 1 branch
| Branch | True | False | Total |
| (!chrt_string_nopass[CUR_CHAR & 0xff])) { |
489 |
1126 |
1615 |
|
| 270 |
|
| INCR_METRIC(STRINGY_INSIGNIFICANT); |
| 271 |
489 |
| goto GT_NEXT; |
| 272 |
1126 |
▶ | } else if (CUR_CHAR == '"') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (CUR_CHAR == '"') { |
1112 |
14 |
1126 |
|
| 273 |
1112 |
| goto GT_QUOTE; |
| 274 |
14 |
▶ | } else if (CUR_CHAR == '\\') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (CUR_CHAR == '\\') { |
13 |
1 |
14 |
|
| 275 |
13 |
| goto GT_ESCAPE; |
| 276 |
|
| } else { |
| 277 |
1 |
▶ | INVOKE_ERROR(WEIRD_WHITESPACE); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(WEIRD_WHITESPACE); |
0 |
0 |
0 |
|
| 278 |
|
| } |
| 279 |
|
| INCR_METRIC(STRINGY_SLOWPATH); |
| 280 |
|
| |
| 281 |
5879 |
▶ | } else if (state_type == JSONSL_T_SPECIAL) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (state_type == JSONSL_T_SPECIAL) { |
139 |
5740 |
5879 |
|
| 282 |
139 |
▶ | if (state->special_flags & JSONSL_SPECIALf_NUMERIC) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (state->special_flags & JSONSL_SPECIALf_NUMERIC) { |
108 |
31 |
139 |
|
| 283 |
108 |
| switch (CUR_CHAR) { |
| 284 |
51 |
| CASE_DIGITS |
| 285 |
51 |
| state->nelem = (state->nelem*10) + (CUR_CHAR-0x30); |
| 286 |
51 |
| goto GT_NEXT; |
| 287 |
|
| |
| 288 |
15 |
| case 'e': |
| 289 |
|
| case 'E': |
| 290 |
|
| case '-': |
| 291 |
|
| case '+': |
| 292 |
15 |
| state->special_flags |= JSONSL_SPECIALf_EXPONENT; |
| 293 |
15 |
| goto GT_NEXT; |
| 294 |
9 |
| case '.': |
| 295 |
9 |
| state->special_flags |= JSONSL_SPECIALf_FLOAT; |
| 296 |
9 |
| goto GT_NEXT; |
| 297 |
33 |
| default: |
| 298 |
33 |
▶ | if (is_special_end(CUR_CHAR)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_special_end(CUR_CHAR)) { |
33 |
0 |
33 |
|
| 299 |
33 |
| goto GT_SPECIAL_POP; |
| 300 |
|
| } |
| 301 |
0 |
▶ | INVOKE_ERROR(INVALID_NUMBER); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(INVALID_NUMBER); |
0 |
0 |
0 |
|
| 302 |
|
| break; |
| 303 |
|
| } |
| 304 |
|
| } |
| 305 |
|
| /* else if (!NUMERIC) */ |
| 306 |
31 |
▶ | if (!is_special_end(CUR_CHAR)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_special_end(CUR_CHAR)) { |
24 |
7 |
31 |
|
| 307 |
|
| /* Verify TRUE, FALSE, NULL */ |
| 308 |
24 |
▶ | if (state->special_flags == JSONSL_SPECIALf_TRUE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (state->special_flags == JSONSL_SPECIALf_TRUE) { |
6 |
18 |
24 |
|
| 309 |
6 |
▶ | VERIFY_SPECIAL("true"); |
Branch: 2 branches
| Branch | True | False | Total |
| VERIFY_SPECIAL("true"); |
0 |
6 |
6 |
| VERIFY_SPECIAL("true"); |
0 |
0 |
0 |
|
| 310 |
18 |
▶ | } else if (state->special_flags == JSONSL_SPECIALf_FALSE) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (state->special_flags == JSONSL_SPECIALf_FALSE) { |
8 |
10 |
18 |
|
| 311 |
8 |
▶ | VERIFY_SPECIAL("false"); |
Branch: 2 branches
| Branch | True | False | Total |
| VERIFY_SPECIAL("false"); |
0 |
8 |
8 |
| VERIFY_SPECIAL("false"); |
0 |
0 |
0 |
|
| 312 |
10 |
▶ | } else if (state->special_flags == JSONSL_SPECIALf_NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (state->special_flags == JSONSL_SPECIALf_NULL) { |
10 |
0 |
10 |
|
| 313 |
10 |
▶ | VERIFY_SPECIAL("null"); |
Branch: 2 branches
| Branch | True | False | Total |
| VERIFY_SPECIAL("null"); |
1 |
9 |
10 |
| VERIFY_SPECIAL("null"); |
0 |
0 |
0 |
|
| 314 |
|
| } |
| 315 |
|
| INCR_METRIC(SPECIAL_FASTPATH); |
| 316 |
23 |
| goto GT_NEXT; |
| 317 |
|
| } |
| 318 |
|
| |
| 319 |
7 |
| GT_SPECIAL_POP: |
| 320 |
40 |
▶ | SPECIAL_POP; |
Branch: 5 branches
| Branch | True | False | Total |
| SPECIAL_POP; |
40 |
0 |
40 |
| SPECIAL_POP; |
40 |
0 |
40 |
| SPECIAL_POP; |
40 |
0 |
40 |
| SPECIAL_POP; |
40 |
0 |
40 |
| SPECIAL_POP; |
0 |
0 |
0 |
|
| 321 |
35 |
| jsn->expecting = ','; |
| 322 |
35 |
▶ | if (is_allowed_whitespace(CUR_CHAR)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (is_allowed_whitespace(CUR_CHAR)) { |
33 |
2 |
35 |
| if (is_allowed_whitespace(CUR_CHAR)) { |
0 |
33 |
33 |
|
| 323 |
2 |
| goto GT_NEXT; |
| 324 |
|
| } |
| 325 |
|
| /** |
| 326 |
|
| * This works because we have a non-whitespace token |
| 327 |
|
| * which is not a special token. If this is a structural |
| 328 |
|
| * character then it will be gracefully handled by the |
| 329 |
|
| * switch statement. Otherwise it will default to the 'special' |
| 330 |
|
| * state again, |
| 331 |
|
| */ |
| 332 |
33 |
| goto GT_STRUCTURAL_TOKEN; |
| 333 |
5740 |
▶ | } else if (is_allowed_whitespace(CUR_CHAR)) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (is_allowed_whitespace(CUR_CHAR)) { |
5532 |
208 |
5740 |
| } else if (is_allowed_whitespace(CUR_CHAR)) { |
32 |
5500 |
5532 |
|
| 334 |
|
| INCR_METRIC(ALLOWED_WHITESPACE); |
| 335 |
|
| /* So we're not special. Harmless insignificant whitespace |
| 336 |
|
| * passthrough |
| 337 |
|
| */ |
| 338 |
240 |
| goto GT_NEXT; |
| 339 |
5500 |
▶ | } else if (extract_special(CUR_CHAR)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (extract_special(CUR_CHAR)) { |
41 |
5459 |
5500 |
|
| 340 |
|
| /* not a string, whitespace, or structural token. must be special */ |
| 341 |
41 |
| goto GT_SPECIAL_BEGIN; |
| 342 |
|
| } |
| 343 |
|
| |
| 344 |
|
| INCR_GENERIC(CUR_CHAR); |
| 345 |
|
| |
| 346 |
5459 |
▶ | if (CUR_CHAR == '"') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (CUR_CHAR == '"') { |
1115 |
4344 |
5459 |
|
| 347 |
1115 |
| GT_QUOTE: |
| 348 |
2227 |
| jsn->can_insert = 0; |
| 349 |
2227 |
| switch (state_type) { |
| 350 |
|
| |
| 351 |
|
| /* the end of a string or hash key */ |
| 352 |
31 |
| case JSONSL_T_STRING: |
| 353 |
31 |
▶ | CALLBACK_AND_POP(STRING); |
Branch: 5 branches
| Branch | True | False | Total |
| CALLBACK_AND_POP(STRING); |
31 |
0 |
31 |
| CALLBACK_AND_POP(STRING); |
31 |
0 |
31 |
| CALLBACK_AND_POP(STRING); |
31 |
0 |
31 |
| CALLBACK_AND_POP(STRING); |
31 |
0 |
31 |
| CALLBACK_AND_POP(STRING); |
0 |
0 |
0 |
|
| 354 |
31 |
| goto GT_NEXT; |
| 355 |
1081 |
| case JSONSL_T_HKEY: |
| 356 |
1081 |
▶ | CALLBACK_AND_POP(HKEY); |
Branch: 5 branches
| Branch | True | False | Total |
| CALLBACK_AND_POP(HKEY); |
1081 |
0 |
1081 |
| CALLBACK_AND_POP(HKEY); |
1081 |
0 |
1081 |
| CALLBACK_AND_POP(HKEY); |
1081 |
0 |
1081 |
| CALLBACK_AND_POP(HKEY); |
1081 |
0 |
1081 |
| CALLBACK_AND_POP(HKEY); |
0 |
0 |
0 |
|
| 357 |
1081 |
| goto GT_NEXT; |
| 358 |
|
| |
| 359 |
1106 |
| case JSONSL_T_OBJECT: |
| 360 |
1106 |
| state->nelem++; |
| 361 |
1106 |
▶ | if ( (state->nelem-1) % 2 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( (state->nelem-1) % 2 ) { |
24 |
1082 |
1106 |
|
| 362 |
|
| /* Odd, this must be a hash value */ |
| 363 |
24 |
▶ | if (jsn->tok_last != ':') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (jsn->tok_last != ':') { |
0 |
24 |
24 |
|
| 364 |
0 |
▶ | INVOKE_ERROR(MISSING_TOKEN); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(MISSING_TOKEN); |
0 |
0 |
0 |
|
| 365 |
|
| } |
| 366 |
24 |
| jsn->expecting = ','; /* Can't figure out what to expect next */ |
| 367 |
24 |
| jsn->tok_last = 0; |
| 368 |
|
| |
| 369 |
24 |
▶ | STACK_PUSH; |
Branch: 1 branch
| Branch | True | False | Total |
| STACK_PUSH; |
0 |
24 |
24 |
|
| 370 |
24 |
| state->type = JSONSL_T_STRING; |
| 371 |
24 |
▶ | DO_CALLBACK(STRING, PUSH); |
Branch: 5 branches
| Branch | True | False | Total |
| DO_CALLBACK(STRING, PUSH); |
24 |
0 |
24 |
| DO_CALLBACK(STRING, PUSH); |
24 |
0 |
24 |
| DO_CALLBACK(STRING, PUSH); |
24 |
0 |
24 |
| DO_CALLBACK(STRING, PUSH); |
24 |
0 |
24 |
| DO_CALLBACK(STRING, PUSH); |
0 |
0 |
0 |
|
| 372 |
|
| |
| 373 |
|
| } else { |
| 374 |
|
| /* hash key */ |
| 375 |
1082 |
▶ | if (jsn->expecting != '"') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (jsn->expecting != '"') { |
0 |
1082 |
1082 |
|
| 376 |
0 |
▶ | INVOKE_ERROR(STRAY_TOKEN); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(STRAY_TOKEN); |
0 |
0 |
0 |
|
| 377 |
|
| } |
| 378 |
1082 |
| jsn->tok_last = 0; |
| 379 |
1082 |
| jsn->expecting = ':'; |
| 380 |
|
| |
| 381 |
1082 |
▶ | STACK_PUSH; |
Branch: 1 branch
| Branch | True | False | Total |
| STACK_PUSH; |
1 |
1081 |
1082 |
|
| 382 |
1081 |
| state->type = JSONSL_T_HKEY; |
| 383 |
1081 |
▶ | DO_CALLBACK(HKEY, PUSH); |
Branch: 5 branches
| Branch | True | False | Total |
| DO_CALLBACK(HKEY, PUSH); |
1081 |
0 |
1081 |
| DO_CALLBACK(HKEY, PUSH); |
1081 |
0 |
1081 |
| DO_CALLBACK(HKEY, PUSH); |
1081 |
0 |
1081 |
| DO_CALLBACK(HKEY, PUSH); |
1081 |
0 |
1081 |
| DO_CALLBACK(HKEY, PUSH); |
0 |
0 |
0 |
|
| 384 |
|
| } |
| 385 |
1105 |
| goto GT_NEXT; |
| 386 |
|
| |
| 387 |
9 |
| case JSONSL_T_LIST: |
| 388 |
9 |
| state->nelem++; |
| 389 |
9 |
▶ | STACK_PUSH; |
Branch: 1 branch
| Branch | True | False | Total |
| STACK_PUSH; |
0 |
9 |
9 |
|
| 390 |
9 |
| state->type = JSONSL_T_STRING; |
| 391 |
9 |
| jsn->expecting = ','; |
| 392 |
9 |
| jsn->tok_last = 0; |
| 393 |
9 |
▶ | DO_CALLBACK(STRING, PUSH); |
Branch: 5 branches
| Branch | True | False | Total |
| DO_CALLBACK(STRING, PUSH); |
9 |
0 |
9 |
| DO_CALLBACK(STRING, PUSH); |
9 |
0 |
9 |
| DO_CALLBACK(STRING, PUSH); |
9 |
0 |
9 |
| DO_CALLBACK(STRING, PUSH); |
9 |
0 |
9 |
| DO_CALLBACK(STRING, PUSH); |
0 |
0 |
0 |
|
| 394 |
9 |
| goto GT_NEXT; |
| 395 |
|
| |
| 396 |
0 |
| case JSONSL_T_SPECIAL: |
| 397 |
0 |
▶ | INVOKE_ERROR(STRAY_TOKEN); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(STRAY_TOKEN); |
0 |
0 |
0 |
|
| 398 |
|
| break; |
| 399 |
|
| |
| 400 |
0 |
| default: |
| 401 |
0 |
▶ | INVOKE_ERROR(STRING_OUTSIDE_CONTAINER); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(STRING_OUTSIDE_CONTAINER); |
0 |
0 |
0 |
|
| 402 |
|
| break; |
| 403 |
|
| } /* switch(state->type) */ |
| 404 |
4344 |
▶ | } else if (CUR_CHAR == '\\') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (CUR_CHAR == '\\') { |
0 |
4344 |
4344 |
|
| 405 |
0 |
| GT_ESCAPE: |
| 406 |
|
| INCR_METRIC(ESCAPES); |
| 407 |
|
| /* Escape */ |
| 408 |
13 |
▶ | if ( (state->type & JSONSL_Tf_STRINGY) == 0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( (state->type & JSONSL_Tf_STRINGY) == 0 ) { |
0 |
13 |
13 |
|
| 409 |
0 |
▶ | INVOKE_ERROR(ESCAPE_OUTSIDE_STRING); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(ESCAPE_OUTSIDE_STRING); |
0 |
0 |
0 |
|
| 410 |
|
| } |
| 411 |
13 |
| state->nescapes++; |
| 412 |
13 |
| jsn->in_escape = 1; |
| 413 |
13 |
| goto GT_NEXT; |
| 414 |
|
| } /* " or \ */ |
| 415 |
|
| |
| 416 |
4344 |
| GT_STRUCTURAL_TOKEN: |
| 417 |
4377 |
| switch (CUR_CHAR) { |
| 418 |
1081 |
| case ':': |
| 419 |
|
| INCR_METRIC(STRUCTURAL_TOKEN); |
| 420 |
1081 |
▶ | if (jsn->expecting != CUR_CHAR) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (jsn->expecting != CUR_CHAR) { |
0 |
1081 |
1081 |
|
| 421 |
0 |
▶ | INVOKE_ERROR(STRAY_TOKEN); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(STRAY_TOKEN); |
0 |
0 |
0 |
|
| 422 |
|
| } |
| 423 |
1081 |
| jsn->tok_last = ':'; |
| 424 |
1081 |
| jsn->can_insert = 1; |
| 425 |
1081 |
| jsn->expecting = '"'; |
| 426 |
1081 |
| goto GT_NEXT; |
| 427 |
|
| |
| 428 |
28 |
| case ',': |
| 429 |
|
| INCR_METRIC(STRUCTURAL_TOKEN); |
| 430 |
|
| /** |
| 431 |
|
| * The comma is one of the more generic tokens. |
| 432 |
|
| * In the context of an OBJECT, the can_insert flag |
| 433 |
|
| * should never be set, and no other action is |
| 434 |
|
| * necessary. |
| 435 |
|
| */ |
| 436 |
28 |
▶ | if (jsn->expecting != CUR_CHAR) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (jsn->expecting != CUR_CHAR) { |
0 |
28 |
28 |
|
| 437 |
|
| /* make this branch execute only when we haven't manually |
| 438 |
|
| * just placed the ',' in the expecting register. |
| 439 |
|
| */ |
| 440 |
0 |
▶ | INVOKE_ERROR(STRAY_TOKEN); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(STRAY_TOKEN); |
0 |
0 |
0 |
|
| 441 |
|
| } |
| 442 |
|
| |
| 443 |
28 |
▶ | if (state->type == JSONSL_T_OBJECT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (state->type == JSONSL_T_OBJECT) { |
16 |
12 |
28 |
|
| 444 |
|
| /* end of hash value, expect a string as a hash key */ |
| 445 |
16 |
| jsn->expecting = '"'; |
| 446 |
|
| } else { |
| 447 |
12 |
| jsn->can_insert = 1; |
| 448 |
|
| } |
| 449 |
|
| |
| 450 |
28 |
| jsn->tok_last = ','; |
| 451 |
28 |
| jsn->expecting = '"'; |
| 452 |
28 |
| goto GT_NEXT; |
| 453 |
|
| |
| 454 |
|
| /* new list or object */ |
| 455 |
|
| /* hashes are more common */ |
| 456 |
2152 |
| case '{': |
| 457 |
|
| case '[': |
| 458 |
|
| INCR_METRIC(STRUCTURAL_TOKEN); |
| 459 |
2152 |
▶ | if (!jsn->can_insert) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!jsn->can_insert) { |
0 |
2152 |
2152 |
|
| 460 |
0 |
▶ | INVOKE_ERROR(CANT_INSERT); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(CANT_INSERT); |
0 |
0 |
0 |
|
| 461 |
|
| } |
| 462 |
|
| |
| 463 |
2152 |
▶ | ENSURE_HVAL; |
Branch: 3 branches
| Branch | True | False | Total |
| ENSURE_HVAL; |
1117 |
1035 |
2152 |
| ENSURE_HVAL; |
0 |
1117 |
1117 |
| ENSURE_HVAL; |
0 |
0 |
0 |
|
| 464 |
2152 |
| state->nelem++; |
| 465 |
|
| |
| 466 |
2152 |
▶ | STACK_PUSH; |
Branch: 1 branch
| Branch | True | False | Total |
| STACK_PUSH; |
1 |
2151 |
2152 |
|
| 467 |
|
| /* because the constants match the opening delimiters, we can do this: */ |
| 468 |
2151 |
| state->type = CUR_CHAR; |
| 469 |
2151 |
| state->nelem = 0; |
| 470 |
2151 |
| jsn->can_insert = 1; |
| 471 |
2151 |
▶ | if (CUR_CHAR == '{') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (CUR_CHAR == '{') { |
1066 |
1085 |
2151 |
|
| 472 |
|
| /* If we're a hash, we expect a key first, which is quouted */ |
| 473 |
1066 |
| jsn->expecting = '"'; |
| 474 |
|
| } |
| 475 |
2151 |
▶ | if (CUR_CHAR == JSONSL_T_OBJECT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (CUR_CHAR == JSONSL_T_OBJECT) { |
1066 |
1085 |
2151 |
|
| 476 |
1066 |
▶ | DO_CALLBACK(OBJECT, PUSH); |
Branch: 5 branches
| Branch | True | False | Total |
| DO_CALLBACK(OBJECT, PUSH); |
1066 |
0 |
1066 |
| DO_CALLBACK(OBJECT, PUSH); |
1066 |
0 |
1066 |
| DO_CALLBACK(OBJECT, PUSH); |
1066 |
0 |
1066 |
| DO_CALLBACK(OBJECT, PUSH); |
1051 |
15 |
1066 |
| DO_CALLBACK(OBJECT, PUSH); |
15 |
0 |
15 |
|
| 477 |
|
| } else { |
| 478 |
1085 |
▶ | DO_CALLBACK(LIST, PUSH); |
Branch: 5 branches
| Branch | True | False | Total |
| DO_CALLBACK(LIST, PUSH); |
1085 |
0 |
1085 |
| DO_CALLBACK(LIST, PUSH); |
1085 |
0 |
1085 |
| DO_CALLBACK(LIST, PUSH); |
1085 |
0 |
1085 |
| DO_CALLBACK(LIST, PUSH); |
1078 |
7 |
1085 |
| DO_CALLBACK(LIST, PUSH); |
7 |
0 |
7 |
|
| 479 |
|
| } |
| 480 |
2151 |
| jsn->tok_last = 0; |
| 481 |
2151 |
| goto GT_NEXT; |
| 482 |
|
| |
| 483 |
|
| /* closing of list or object */ |
| 484 |
1111 |
| case '}': |
| 485 |
|
| case ']': |
| 486 |
|
| INCR_METRIC(STRUCTURAL_TOKEN); |
| 487 |
1111 |
▶ | if (jsn->tok_last == ',' && jsn->options.allow_trailing_comma == 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (jsn->tok_last == ',' && jsn->options.allow_trailing_comma == 0) { |
0 |
1111 |
1111 |
| if (jsn->tok_last == ',' && jsn->options.allow_trailing_comma == 0) { |
0 |
0 |
0 |
|
| 488 |
0 |
▶ | INVOKE_ERROR(TRAILING_COMMA); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(TRAILING_COMMA); |
0 |
0 |
0 |
|
| 489 |
|
| } |
| 490 |
|
| |
| 491 |
1111 |
| jsn->can_insert = 0; |
| 492 |
1111 |
| jsn->level--; |
| 493 |
1111 |
| jsn->expecting = ','; |
| 494 |
1111 |
| jsn->tok_last = 0; |
| 495 |
1111 |
▶ | if (CUR_CHAR == ']') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (CUR_CHAR == ']') { |
572 |
539 |
1111 |
|
| 496 |
572 |
▶ | if (state->type != '[') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (state->type != '[') { |
0 |
572 |
572 |
|
| 497 |
0 |
▶ | INVOKE_ERROR(BRACKET_MISMATCH); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(BRACKET_MISMATCH); |
0 |
0 |
0 |
|
| 498 |
|
| } |
| 499 |
572 |
▶ | DO_CALLBACK(LIST, POP); |
Branch: 5 branches
| Branch | True | False | Total |
| DO_CALLBACK(LIST, POP); |
572 |
0 |
572 |
| DO_CALLBACK(LIST, POP); |
572 |
0 |
572 |
| DO_CALLBACK(LIST, POP); |
572 |
0 |
572 |
| DO_CALLBACK(LIST, POP); |
572 |
0 |
572 |
| DO_CALLBACK(LIST, POP); |
0 |
0 |
0 |
|
| 500 |
|
| } else { |
| 501 |
539 |
▶ | if (state->type != '{') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (state->type != '{') { |
0 |
539 |
539 |
|
| 502 |
0 |
▶ | INVOKE_ERROR(BRACKET_MISMATCH); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(BRACKET_MISMATCH); |
0 |
0 |
0 |
|
| 503 |
|
| } |
| 504 |
539 |
▶ | DO_CALLBACK(OBJECT, POP); |
Branch: 5 branches
| Branch | True | False | Total |
| DO_CALLBACK(OBJECT, POP); |
539 |
0 |
539 |
| DO_CALLBACK(OBJECT, POP); |
539 |
0 |
539 |
| DO_CALLBACK(OBJECT, POP); |
539 |
0 |
539 |
| DO_CALLBACK(OBJECT, POP); |
539 |
0 |
539 |
| DO_CALLBACK(OBJECT, POP); |
0 |
0 |
0 |
|
| 505 |
|
| } |
| 506 |
1111 |
| state = jsn->stack + jsn->level; |
| 507 |
1111 |
| state->pos_cur = jsn->pos; |
| 508 |
1111 |
| goto GT_NEXT; |
| 509 |
|
| |
| 510 |
|
| default: |
| 511 |
46 |
| GT_SPECIAL_BEGIN: |
| 512 |
|
| /** |
| 513 |
|
| * Not a string, not a structural token, and not benign whitespace. |
| 514 |
|
| * Technically we should iterate over the character always, but since |
| 515 |
|
| * we are not doing full numerical/value decoding anyway (but only hinting), |
| 516 |
|
| * we only check upon entry. |
| 517 |
|
| */ |
| 518 |
46 |
▶ | if (state->type != JSONSL_T_SPECIAL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (state->type != JSONSL_T_SPECIAL) { |
46 |
0 |
46 |
|
| 519 |
46 |
| int special_flags = extract_special(CUR_CHAR); |
| 520 |
46 |
▶ | if (!special_flags) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!special_flags) { |
5 |
41 |
46 |
|
| 521 |
|
| /** |
| 522 |
|
| * Try to do some heuristics here anyway to figure out what kind of |
| 523 |
|
| * error this is. The 'special' case is a fallback scenario anyway. |
| 524 |
|
| */ |
| 525 |
5 |
▶ | if (CUR_CHAR == '\0') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (CUR_CHAR == '\0') { |
0 |
5 |
5 |
|
| 526 |
0 |
▶ | INVOKE_ERROR(FOUND_NULL_BYTE); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(FOUND_NULL_BYTE); |
0 |
0 |
0 |
|
| 527 |
5 |
▶ | } else if (CUR_CHAR < 0x20) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (CUR_CHAR < 0x20) { |
1 |
4 |
5 |
|
| 528 |
1 |
▶ | INVOKE_ERROR(WEIRD_WHITESPACE); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(WEIRD_WHITESPACE); |
0 |
0 |
0 |
|
| 529 |
|
| } else { |
| 530 |
4 |
▶ | INVOKE_ERROR(SPECIAL_EXPECTED); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(SPECIAL_EXPECTED); |
0 |
0 |
0 |
|
| 531 |
|
| } |
| 532 |
|
| } |
| 533 |
41 |
▶ | ENSURE_HVAL; |
Branch: 3 branches
| Branch | True | False | Total |
| ENSURE_HVAL; |
18 |
23 |
41 |
| ENSURE_HVAL; |
0 |
18 |
18 |
| ENSURE_HVAL; |
0 |
0 |
0 |
|
| 534 |
41 |
| state->nelem++; |
| 535 |
41 |
▶ | if (!jsn->can_insert) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!jsn->can_insert) { |
0 |
41 |
41 |
|
| 536 |
0 |
▶ | INVOKE_ERROR(CANT_INSERT); |
Branch: 1 branch
| Branch | True | False | Total |
| INVOKE_ERROR(CANT_INSERT); |
0 |
0 |
0 |
|
| 537 |
|
| } |
| 538 |
41 |
▶ | STACK_PUSH; |
Branch: 1 branch
| Branch | True | False | Total |
| STACK_PUSH; |
0 |
41 |
41 |
|
| 539 |
41 |
| state->type = JSONSL_T_SPECIAL; |
| 540 |
41 |
| state->special_flags = special_flags; |
| 541 |
41 |
▶ | if (special_flags == JSONSL_SPECIALf_UNSIGNED) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (special_flags == JSONSL_SPECIALf_UNSIGNED) { |
27 |
14 |
41 |
|
| 542 |
27 |
| state->nelem = CUR_CHAR - 0x30; |
| 543 |
|
| } else { |
| 544 |
14 |
| state->nelem = 0; |
| 545 |
|
| } |
| 546 |
41 |
▶ | DO_CALLBACK(SPECIAL, PUSH); |
Branch: 5 branches
| Branch | True | False | Total |
| DO_CALLBACK(SPECIAL, PUSH); |
41 |
0 |
41 |
| DO_CALLBACK(SPECIAL, PUSH); |
41 |
0 |
41 |
| DO_CALLBACK(SPECIAL, PUSH); |
41 |
0 |
41 |
| DO_CALLBACK(SPECIAL, PUSH); |
41 |
0 |
41 |
| DO_CALLBACK(SPECIAL, PUSH); |
0 |
0 |
0 |
|
| 547 |
|
| } |
| 548 |
41 |
| goto GT_NEXT; |
| 549 |
|
| } |
| 550 |
|
| |
| 551 |
7493 |
| GT_NEXT: |
| 552 |
7493 |
| continue; |
| 553 |
|
| } |
| 554 |
|
| } |
| 555 |
|
| |
| 556 |
|
| JSONSL_API |
| 557 |
10 |
| const char* jsonsl_strerror(jsonsl_error_t err) |
| 558 |
|
| { |
| 559 |
|
| #define X(t) \ |
| 560 |
|
| if (err == JSONSL_ERROR_##t) \ |
| 561 |
|
| return #t; |
| 562 |
10 |
▶ | JSONSL_XERR; |
Branch: 22 branches
| Branch | True | False | Total |
| JSONSL_XERR; |
0 |
10 |
10 |
| JSONSL_XERR; |
0 |
10 |
10 |
| JSONSL_XERR; |
5 |
5 |
10 |
| JSONSL_XERR; |
0 |
5 |
5 |
| JSONSL_XERR; |
0 |
5 |
5 |
| JSONSL_XERR; |
0 |
5 |
5 |
| JSONSL_XERR; |
0 |
5 |
5 |
| JSONSL_XERR; |
0 |
5 |
5 |
| JSONSL_XERR; |
0 |
5 |
5 |
| JSONSL_XERR; |
0 |
5 |
5 |
| JSONSL_XERR; |
2 |
3 |
5 |
| JSONSL_XERR; |
0 |
3 |
3 |
| JSONSL_XERR; |
0 |
3 |
3 |
| JSONSL_XERR; |
2 |
1 |
3 |
| JSONSL_XERR; |
0 |
1 |
1 |
| JSONSL_XERR; |
1 |
0 |
1 |
| JSONSL_XERR; |
0 |
0 |
0 |
| JSONSL_XERR; |
0 |
0 |
0 |
| JSONSL_XERR; |
0 |
0 |
0 |
| JSONSL_XERR; |
0 |
0 |
0 |
| JSONSL_XERR; |
0 |
0 |
0 |
| JSONSL_XERR; |
0 |
0 |
0 |
|
| 563 |
|
| #undef X |
| 564 |
0 |
| return "<UNKNOWN_ERROR>"; |
| 565 |
|
| } |
| 566 |
|
| |
| 567 |
|
| JSONSL_API |
| 568 |
0 |
| const char *jsonsl_strtype(jsonsl_type_t type) |
| 569 |
|
| { |
| 570 |
|
| #define X(o,c) \ |
| 571 |
|
| if (type == JSONSL_T_##o) \ |
| 572 |
|
| return #o; |
| 573 |
0 |
▶ | JSONSL_XTYPE |
Branch: 6 branches
| Branch | True | False | Total |
| JSONSL_XTYPE |
0 |
0 |
0 |
| JSONSL_XTYPE |
0 |
0 |
0 |
| JSONSL_XTYPE |
0 |
0 |
0 |
| JSONSL_XTYPE |
0 |
0 |
0 |
| JSONSL_XTYPE |
0 |
0 |
0 |
| JSONSL_XTYPE |
0 |
0 |
0 |
|
| 574 |
|
| #undef X |
| 575 |
0 |
| return "UNKNOWN TYPE"; |
| 576 |
|
| |
| 577 |
|
| } |
| 578 |
|
| |
| 579 |
|
| /* |
| 580 |
|
| * |
| 581 |
|
| * JPR/JSONPointer functions |
| 582 |
|
| * |
| 583 |
|
| * |
| 584 |
|
| */ |
| 585 |
|
| #ifndef JSONSL_NO_JPR |
| 586 |
|
| static |
| 587 |
|
| jsonsl_jpr_type_t |
| 588 |
5 |
| populate_component(char *in, |
| 589 |
|
| struct jsonsl_jpr_component_st *component, |
| 590 |
|
| char **next, |
| 591 |
|
| jsonsl_error_t *errp) |
| 592 |
|
| { |
| 593 |
|
| unsigned long pctval; |
| 594 |
5 |
| char *c = NULL, *outp = NULL, *end = NULL; |
| 595 |
|
| size_t input_len; |
| 596 |
5 |
| jsonsl_jpr_type_t ret = JSONSL_PATH_NONE; |
| 597 |
|
| |
| 598 |
5 |
▶ | if (*next == NULL || *(*next) == '\0') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (*next == NULL || *(*next) == '\0') { |
5 |
0 |
5 |
| if (*next == NULL || *(*next) == '\0') { |
0 |
5 |
5 |
|
| 599 |
0 |
| return JSONSL_PATH_NONE; |
| 600 |
|
| } |
| 601 |
|
| |
| 602 |
|
| /* Replace the next / with a NULL */ |
| 603 |
5 |
| *next = strstr(in, "/"); |
| 604 |
5 |
▶ | if (*next != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*next != NULL) { |
1 |
4 |
5 |
|
| 605 |
1 |
| *(*next) = '\0'; /* drop the forward slash */ |
| 606 |
1 |
| input_len = *next - in; |
| 607 |
1 |
| end = *next; |
| 608 |
1 |
| *next += 1; /* next character after the '/' */ |
| 609 |
|
| } else { |
| 610 |
4 |
| input_len = strlen(in); |
| 611 |
4 |
| end = in + input_len + 1; |
| 612 |
|
| } |
| 613 |
|
| |
| 614 |
5 |
| component->pstr = in; |
| 615 |
|
| |
| 616 |
|
| /* Check for special components of interest */ |
| 617 |
5 |
▶ | if (*in == JSONSL_PATH_WILDCARD_CHAR && input_len == 1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (*in == JSONSL_PATH_WILDCARD_CHAR && input_len == 1) { |
4 |
1 |
5 |
| if (*in == JSONSL_PATH_WILDCARD_CHAR && input_len == 1) { |
4 |
0 |
4 |
|
| 618 |
|
| /* Lone wildcard */ |
| 619 |
4 |
| ret = JSONSL_PATH_WILDCARD; |
| 620 |
4 |
| goto GT_RET; |
| 621 |
1 |
▶ | } else if (isdigit(*in)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (isdigit(*in)) { |
0 |
1 |
1 |
|
| 622 |
|
| /* ASCII Numeric */ |
| 623 |
|
| char *endptr; |
| 624 |
0 |
| component->idx = strtoul(in, &endptr, 10); |
| 625 |
0 |
▶ | if (endptr && *endptr == '\0') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (endptr && *endptr == '\0') { |
0 |
0 |
0 |
| if (endptr && *endptr == '\0') { |
0 |
0 |
0 |
|
| 626 |
0 |
| ret = JSONSL_PATH_NUMERIC; |
| 627 |
0 |
| goto GT_RET; |
| 628 |
|
| } |
| 629 |
|
| } |
| 630 |
|
| |
| 631 |
|
| /* Default, it's a string */ |
| 632 |
1 |
| ret = JSONSL_PATH_STRING; |
| 633 |
9 |
▶ | for (c = outp = in; c < end; c++, outp++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (c = outp = in; c < end; c++, outp++) { |
8 |
1 |
9 |
|
| 634 |
|
| char origc; |
| 635 |
8 |
▶ | if (*c != '%') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*c != '%') { |
8 |
0 |
8 |
|
| 636 |
8 |
| goto GT_ASSIGN; |
| 637 |
|
| } |
| 638 |
|
| /* |
| 639 |
|
| * c = { [+0] = '%', [+1] = 'b', [+2] = 'e', [+3] = '\0' } |
| 640 |
|
| */ |
| 641 |
|
| |
| 642 |
|
| /* Need %XX */ |
| 643 |
0 |
▶ | if (c+2 >= end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (c+2 >= end) { |
0 |
0 |
0 |
|
| 644 |
0 |
| *errp = JSONSL_ERROR_PERCENT_BADHEX; |
| 645 |
0 |
| return JSONSL_PATH_INVALID; |
| 646 |
|
| } |
| 647 |
0 |
▶ | if (! (isxdigit(*(c+1)) && isxdigit(*(c+2))) ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (! (isxdigit(*(c+1)) && isxdigit(*(c+2))) ) { |
0 |
0 |
0 |
| if (! (isxdigit(*(c+1)) && isxdigit(*(c+2))) ) { |
0 |
0 |
0 |
|
| 648 |
0 |
| *errp = JSONSL_ERROR_PERCENT_BADHEX; |
| 649 |
0 |
| return JSONSL_PATH_INVALID; |
| 650 |
|
| } |
| 651 |
|
| |
| 652 |
|
| /* Temporarily null-terminate the characters */ |
| 653 |
0 |
| origc = *(c+3); |
| 654 |
0 |
| *(c+3) = '\0'; |
| 655 |
0 |
| pctval = strtoul(c+1, NULL, 16); |
| 656 |
0 |
| *(c+3) = origc; |
| 657 |
|
| |
| 658 |
0 |
| *outp = (char) pctval; |
| 659 |
0 |
| c += 2; |
| 660 |
0 |
| continue; |
| 661 |
|
| |
| 662 |
8 |
| GT_ASSIGN: |
| 663 |
8 |
| *outp = *c; |
| 664 |
|
| } |
| 665 |
|
| /* Null-terminate the string */ |
| 666 |
1 |
▶ | for (; outp < c; outp++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (; outp < c; outp++) { |
0 |
1 |
1 |
|
| 667 |
0 |
| *outp = '\0'; |
| 668 |
|
| } |
| 669 |
|
| |
| 670 |
1 |
| GT_RET: |
| 671 |
5 |
| component->ptype = ret; |
| 672 |
5 |
▶ | if (ret != JSONSL_PATH_WILDCARD) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ret != JSONSL_PATH_WILDCARD) { |
1 |
4 |
5 |
|
| 673 |
1 |
| component->len = strlen(component->pstr); |
| 674 |
|
| } |
| 675 |
5 |
| return ret; |
| 676 |
|
| } |
| 677 |
|
| |
| 678 |
|
| JSONSL_API |
| 679 |
|
| jsonsl_jpr_t |
| 680 |
4 |
| jsonsl_jpr_new(const char *path, jsonsl_error_t *errp) |
| 681 |
|
| { |
| 682 |
|
| char *my_copy; |
| 683 |
|
| int count, curidx; |
| 684 |
|
| struct jsonsl_jpr_st *ret; |
| 685 |
|
| struct jsonsl_jpr_component_st *components; |
| 686 |
|
| size_t origlen; |
| 687 |
|
| jsonsl_error_t errstacked; |
| 688 |
|
| |
| 689 |
4 |
▶ | if (errp == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (errp == NULL) { |
0 |
4 |
4 |
|
| 690 |
0 |
| errp = &errstacked; |
| 691 |
|
| } |
| 692 |
|
| |
| 693 |
4 |
▶ | if (path == NULL || *path != '/') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (path == NULL || *path != '/') { |
4 |
0 |
4 |
| if (path == NULL || *path != '/') { |
0 |
4 |
4 |
|
| 694 |
0 |
| *errp = JSONSL_ERROR_JPR_NOROOT; |
| 695 |
0 |
| return NULL; |
| 696 |
|
| } |
| 697 |
|
| |
| 698 |
4 |
| count = 1; |
| 699 |
4 |
| path++; |
| 700 |
|
| { |
| 701 |
4 |
| const char *c = path; |
| 702 |
16 |
▶ | for (; *c; c++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (; *c; c++) { |
12 |
4 |
16 |
|
| 703 |
12 |
▶ | if (*c == '/') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*c == '/') { |
1 |
11 |
12 |
|
| 704 |
1 |
| count++; |
| 705 |
1 |
▶ | if (*(c+1) == '/') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*(c+1) == '/') { |
0 |
1 |
1 |
|
| 706 |
0 |
| *errp = JSONSL_ERROR_JPR_DUPSLASH; |
| 707 |
0 |
| return NULL; |
| 708 |
|
| } |
| 709 |
|
| } |
| 710 |
|
| } |
| 711 |
|
| } |
| 712 |
4 |
▶ | if(*path) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(*path) { |
4 |
0 |
4 |
|
| 713 |
4 |
| count++; |
| 714 |
|
| } |
| 715 |
|
| |
| 716 |
4 |
| components = malloc(sizeof(*components) * count); |
| 717 |
4 |
| my_copy = malloc(strlen(path) + 1); |
| 718 |
4 |
| strcpy(my_copy, path); |
| 719 |
|
| |
| 720 |
4 |
| components[0].ptype = JSONSL_PATH_ROOT; |
| 721 |
|
| |
| 722 |
4 |
▶ | if (*my_copy) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*my_copy) { |
4 |
0 |
4 |
|
| 723 |
4 |
| char *cur = my_copy; |
| 724 |
4 |
| int pathret = JSONSL_PATH_STRING; |
| 725 |
4 |
| curidx = 1; |
| 726 |
9 |
▶ | while (pathret > 0 && curidx < count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (pathret > 0 && curidx < count) { |
9 |
0 |
9 |
| while (pathret > 0 && curidx < count) { |
5 |
4 |
9 |
|
| 727 |
5 |
| pathret = populate_component(cur, components + curidx, &cur, errp); |
| 728 |
5 |
▶ | if (pathret > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (pathret > 0) { |
5 |
0 |
5 |
|
| 729 |
5 |
| curidx++; |
| 730 |
|
| } else { |
| 731 |
0 |
| break; |
| 732 |
|
| } |
| 733 |
|
| } |
| 734 |
|
| |
| 735 |
4 |
▶ | if (pathret == JSONSL_PATH_INVALID) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (pathret == JSONSL_PATH_INVALID) { |
0 |
4 |
4 |
|
| 736 |
0 |
| free(components); |
| 737 |
0 |
| free(my_copy); |
| 738 |
0 |
| return NULL; |
| 739 |
|
| } |
| 740 |
|
| } else { |
| 741 |
0 |
| curidx = 1; |
| 742 |
|
| } |
| 743 |
|
| |
| 744 |
4 |
| path--; /*revert path to leading '/' */ |
| 745 |
4 |
| origlen = strlen(path) + 1; |
| 746 |
4 |
| ret = malloc(sizeof(*ret)); |
| 747 |
4 |
| ret->components = components; |
| 748 |
4 |
| ret->ncomponents = curidx; |
| 749 |
4 |
| ret->basestr = my_copy; |
| 750 |
4 |
| ret->orig = malloc(origlen); |
| 751 |
4 |
| ret->norig = origlen-1; |
| 752 |
4 |
| strcpy(ret->orig, path); |
| 753 |
|
| |
| 754 |
4 |
| return ret; |
| 755 |
|
| } |
| 756 |
|
| |
| 757 |
4 |
| void jsonsl_jpr_destroy(jsonsl_jpr_t jpr) |
| 758 |
|
| { |
| 759 |
4 |
| free(jpr->components); |
| 760 |
4 |
| free(jpr->basestr); |
| 761 |
4 |
| free(jpr->orig); |
| 762 |
4 |
| free(jpr); |
| 763 |
4 |
| } |
| 764 |
|
| |
| 765 |
|
| JSONSL_API |
| 766 |
|
| jsonsl_jpr_match_t |
| 767 |
18 |
| jsonsl_jpr_match(jsonsl_jpr_t jpr, |
| 768 |
|
| jsonsl_type_t parent_type, |
| 769 |
|
| unsigned int parent_level, |
| 770 |
|
| const char *key, |
| 771 |
|
| size_t nkey) |
| 772 |
|
| { |
| 773 |
|
| /* find our current component. This is the child level */ |
| 774 |
|
| int cmpret; |
| 775 |
|
| struct jsonsl_jpr_component_st *p_component; |
| 776 |
18 |
| p_component = jpr->components + parent_level; |
| 777 |
|
| |
| 778 |
18 |
▶ | if (parent_level >= jpr->ncomponents) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (parent_level >= jpr->ncomponents) { |
0 |
18 |
18 |
|
| 779 |
0 |
| return JSONSL_MATCH_NOMATCH; |
| 780 |
|
| } |
| 781 |
|
| |
| 782 |
|
| /* Lone query for 'root' element. Always matches */ |
| 783 |
18 |
▶ | if (parent_level == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (parent_level == 0) { |
6 |
12 |
18 |
|
| 784 |
6 |
▶ | if (jpr->ncomponents == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (jpr->ncomponents == 1) { |
0 |
6 |
6 |
|
| 785 |
0 |
| return JSONSL_MATCH_COMPLETE; |
| 786 |
|
| } else { |
| 787 |
6 |
| return JSONSL_MATCH_POSSIBLE; |
| 788 |
|
| } |
| 789 |
|
| } |
| 790 |
|
| |
| 791 |
|
| /* Wildcard, always matches */ |
| 792 |
12 |
▶ | if (p_component->ptype == JSONSL_PATH_WILDCARD) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_component->ptype == JSONSL_PATH_WILDCARD) { |
9 |
3 |
12 |
|
| 793 |
9 |
▶ | if (parent_level == jpr->ncomponents-1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (parent_level == jpr->ncomponents-1) { |
6 |
3 |
9 |
|
| 794 |
6 |
| return JSONSL_MATCH_COMPLETE; |
| 795 |
|
| } else { |
| 796 |
3 |
| return JSONSL_MATCH_POSSIBLE; |
| 797 |
|
| } |
| 798 |
|
| } |
| 799 |
|
| |
| 800 |
|
| /* Check numeric array index */ |
| 801 |
3 |
▶ | if (p_component->ptype == JSONSL_PATH_NUMERIC |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_component->ptype == JSONSL_PATH_NUMERIC |
0 |
3 |
3 |
|
| 802 |
0 |
▶ | && parent_type == JSONSL_T_LIST) { |
Branch: 1 branch
| Branch | True | False | Total |
| && parent_type == JSONSL_T_LIST) { |
0 |
0 |
0 |
|
| 803 |
0 |
▶ | if (p_component->idx != nkey) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_component->idx != nkey) { |
0 |
0 |
0 |
|
| 804 |
0 |
| return JSONSL_MATCH_NOMATCH; |
| 805 |
|
| } else { |
| 806 |
0 |
▶ | if (parent_level == jpr->ncomponents-1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (parent_level == jpr->ncomponents-1) { |
0 |
0 |
0 |
|
| 807 |
0 |
| return JSONSL_MATCH_COMPLETE; |
| 808 |
|
| } else { |
| 809 |
0 |
| return JSONSL_MATCH_POSSIBLE; |
| 810 |
|
| } |
| 811 |
|
| } |
| 812 |
|
| } |
| 813 |
|
| |
| 814 |
|
| /* Check lengths */ |
| 815 |
3 |
▶ | if (p_component->len != nkey) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_component->len != nkey) { |
1 |
2 |
3 |
|
| 816 |
1 |
| return JSONSL_MATCH_NOMATCH; |
| 817 |
|
| } |
| 818 |
|
| |
| 819 |
|
| /* Check string comparison */ |
| 820 |
2 |
| cmpret = strncmp(p_component->pstr, key, nkey); |
| 821 |
2 |
▶ | if (cmpret == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cmpret == 0) { |
2 |
0 |
2 |
|
| 822 |
2 |
▶ | if (parent_level == jpr->ncomponents-1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (parent_level == jpr->ncomponents-1) { |
2 |
0 |
2 |
|
| 823 |
2 |
| return JSONSL_MATCH_COMPLETE; |
| 824 |
|
| } else { |
| 825 |
0 |
| return JSONSL_MATCH_POSSIBLE; |
| 826 |
|
| } |
| 827 |
|
| } |
| 828 |
|
| |
| 829 |
0 |
| return JSONSL_MATCH_NOMATCH; |
| 830 |
|
| } |
| 831 |
|
| |
| 832 |
|
| JSONSL_API |
| 833 |
4 |
| void jsonsl_jpr_match_state_init(jsonsl_t jsn, |
| 834 |
|
| jsonsl_jpr_t *jprs, |
| 835 |
|
| size_t njprs) |
| 836 |
|
| { |
| 837 |
|
| size_t ii, *firstjmp; |
| 838 |
4 |
▶ | if (njprs == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (njprs == 0) { |
0 |
4 |
4 |
|
| 839 |
0 |
| return; |
| 840 |
|
| } |
| 841 |
4 |
| jsn->jprs = malloc(sizeof(jsonsl_jpr_t) * njprs); |
| 842 |
4 |
| jsn->jpr_count = njprs; |
| 843 |
4 |
| jsn->jpr_root = calloc(1, sizeof(size_t) * njprs * jsn->levels_max); |
| 844 |
4 |
| memcpy(jsn->jprs, jprs, sizeof(jsonsl_jpr_t) * njprs); |
| 845 |
|
| /* Set the initial jump table values */ |
| 846 |
|
| |
| 847 |
4 |
| firstjmp = jsn->jpr_root; |
| 848 |
8 |
▶ | for (ii = 0; ii < njprs; ii++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ii = 0; ii < njprs; ii++) { |
4 |
4 |
8 |
|
| 849 |
4 |
| firstjmp[ii] = ii+1; |
| 850 |
|
| } |
| 851 |
|
| } |
| 852 |
|
| |
| 853 |
|
| JSONSL_API |
| 854 |
24 |
| void jsonsl_jpr_match_state_cleanup(jsonsl_t jsn) |
| 855 |
|
| { |
| 856 |
24 |
▶ | if (jsn->jpr_count == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (jsn->jpr_count == 0) { |
20 |
4 |
24 |
|
| 857 |
20 |
| return; |
| 858 |
|
| } |
| 859 |
|
| |
| 860 |
4 |
| free(jsn->jpr_root); |
| 861 |
4 |
| free(jsn->jprs); |
| 862 |
4 |
| jsn->jprs = NULL; |
| 863 |
4 |
| jsn->jpr_root = NULL; |
| 864 |
4 |
| jsn->jpr_count = 0; |
| 865 |
|
| } |
| 866 |
|
| |
| 867 |
|
| /** |
| 868 |
|
| * This function should be called exactly once on each element... |
| 869 |
|
| * This should also be called in recursive order, since we rely |
| 870 |
|
| * on the parent having been initalized for a match. |
| 871 |
|
| * |
| 872 |
|
| * Since the parent is checked for a match as well, we maintain a 'serial' counter. |
| 873 |
|
| * Whenever we traverse an element, we expect the serial to be the same as a global |
| 874 |
|
| * integer. If they do not match, we re-initialize the context, and set the serial. |
| 875 |
|
| * |
| 876 |
|
| * This ensures a type of consistency without having a proactive reset by the |
| 877 |
|
| * main lexer itself. |
| 878 |
|
| * |
| 879 |
|
| */ |
| 880 |
|
| JSONSL_API |
| 881 |
72 |
| jsonsl_jpr_t jsonsl_jpr_match_state(jsonsl_t jsn, |
| 882 |
|
| struct jsonsl_state_st *state, |
| 883 |
|
| const char *key, |
| 884 |
|
| size_t nkey, |
| 885 |
|
| jsonsl_jpr_match_t *out) |
| 886 |
|
| { |
| 887 |
|
| struct jsonsl_state_st *parent_state; |
| 888 |
72 |
| jsonsl_jpr_t ret = NULL; |
| 889 |
|
| |
| 890 |
|
| /* Jump and JPR tables for our own state and the parent state */ |
| 891 |
|
| size_t *jmptable, *pjmptable; |
| 892 |
|
| size_t jmp_cur, ii, ourjmpidx; |
| 893 |
|
| |
| 894 |
72 |
▶ | if (!jsn->jpr_root) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!jsn->jpr_root) { |
54 |
18 |
72 |
|
| 895 |
54 |
| *out = JSONSL_MATCH_NOMATCH; |
| 896 |
54 |
| return NULL; |
| 897 |
|
| } |
| 898 |
|
| |
| 899 |
18 |
| pjmptable = jsn->jpr_root + (jsn->jpr_count * (state->level-1)); |
| 900 |
18 |
| jmptable = pjmptable + jsn->jpr_count; |
| 901 |
|
| |
| 902 |
|
| /* If the parent cannot match, then invalidate it */ |
| 903 |
18 |
▶ | if (*pjmptable == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*pjmptable == 0) { |
0 |
18 |
18 |
|
| 904 |
0 |
| *jmptable = 0; |
| 905 |
0 |
| *out = JSONSL_MATCH_NOMATCH; |
| 906 |
0 |
| return NULL; |
| 907 |
|
| } |
| 908 |
|
| |
| 909 |
18 |
| parent_state = jsn->stack + state->level - 1; |
| 910 |
|
| |
| 911 |
18 |
▶ | if (parent_state->type == JSONSL_T_LIST) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (parent_state->type == JSONSL_T_LIST) { |
5 |
13 |
18 |
|
| 912 |
5 |
| nkey = (size_t) parent_state->nelem; |
| 913 |
|
| } |
| 914 |
|
| |
| 915 |
18 |
| *jmptable = 0; |
| 916 |
18 |
| ourjmpidx = 0; |
| 917 |
18 |
| memset(jmptable, 0, sizeof(int) * jsn->jpr_count); |
| 918 |
|
| |
| 919 |
28 |
▶ | for (ii = 0; ii < jsn->jpr_count; ii++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ii = 0; ii < jsn->jpr_count; ii++) { |
18 |
10 |
28 |
|
| 920 |
18 |
| jmp_cur = pjmptable[ii]; |
| 921 |
18 |
▶ | if (jmp_cur) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (jmp_cur) { |
18 |
0 |
18 |
|
| 922 |
18 |
| jsonsl_jpr_t jpr = jsn->jprs[jmp_cur-1]; |
| 923 |
18 |
| *out = jsonsl_jpr_match(jpr, |
| 924 |
|
| parent_state->type, |
| 925 |
|
| parent_state->level, |
| 926 |
|
| key, nkey); |
| 927 |
18 |
▶ | if (*out == JSONSL_MATCH_COMPLETE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*out == JSONSL_MATCH_COMPLETE) { |
8 |
10 |
18 |
|
| 928 |
8 |
| ret = jpr; |
| 929 |
8 |
| *jmptable = 0; |
| 930 |
8 |
| return ret; |
| 931 |
10 |
▶ | } else if (*out == JSONSL_MATCH_POSSIBLE) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (*out == JSONSL_MATCH_POSSIBLE) { |
9 |
1 |
10 |
|
| 932 |
9 |
| jmptable[ourjmpidx] = ii+1; |
| 933 |
9 |
| ourjmpidx++; |
| 934 |
|
| } |
| 935 |
|
| } else { |
| 936 |
0 |
| break; |
| 937 |
|
| } |
| 938 |
|
| } |
| 939 |
10 |
▶ | if (!*jmptable) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!*jmptable) { |
1 |
9 |
10 |
|
| 940 |
1 |
| *out = JSONSL_MATCH_NOMATCH; |
| 941 |
|
| } |
| 942 |
10 |
| return NULL; |
| 943 |
|
| } |
| 944 |
|
| |
| 945 |
|
| JSONSL_API |
| 946 |
0 |
| const char *jsonsl_strmatchtype(jsonsl_jpr_match_t match) |
| 947 |
|
| { |
| 948 |
|
| #define X(T,v) \ |
| 949 |
|
| if ( match == JSONSL_MATCH_##T ) \ |
| 950 |
|
| return #T; |
| 951 |
0 |
▶ | JSONSL_XMATCH |
Branch: 3 branches
| Branch | True | False | Total |
| JSONSL_XMATCH |
0 |
0 |
0 |
| JSONSL_XMATCH |
0 |
0 |
0 |
| JSONSL_XMATCH |
0 |
0 |
0 |
|
| 952 |
|
| #undef X |
| 953 |
0 |
| return "<UNKNOWN>"; |
| 954 |
|
| } |
| 955 |
|
| |
| 956 |
|
| #endif /* JSONSL_WITH_JPR */ |
| 957 |
|
| |
| 958 |
|
| /** |
| 959 |
|
| * Maps literal escape sequences with special meaning to their |
| 960 |
|
| * actual control codes (e.g.\n => 0x20) |
| 961 |
|
| */ |
| 962 |
|
| static unsigned char *Escape_Maps; |
| 963 |
|
| /** |
| 964 |
|
| * Utility function to convert escape sequences |
| 965 |
|
| */ |
| 966 |
|
| JSONSL_API |
| 967 |
14 |
| size_t jsonsl_util_unescape_ex(const char *in, |
| 968 |
|
| char *out, |
| 969 |
|
| size_t len, |
| 970 |
|
| const int toEscape[128], |
| 971 |
|
| jsonsl_special_t *oflags, |
| 972 |
|
| jsonsl_error_t *err, |
| 973 |
|
| const char **errat) |
| 974 |
|
| { |
| 975 |
14 |
| const unsigned char *c = (const unsigned char*)in; |
| 976 |
14 |
| int in_escape = 0; |
| 977 |
14 |
| size_t origlen = len; |
| 978 |
|
| /* difference between the length of the input buffer and the output buffer */ |
| 979 |
14 |
| size_t ndiff = 0; |
| 980 |
14 |
▶ | if (oflags) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (oflags) { |
14 |
0 |
14 |
|
| 981 |
14 |
| *oflags = 0; |
| 982 |
|
| } |
| 983 |
|
| #define UNESCAPE_BAIL(e,offset) \ |
| 984 |
|
| *err = JSONSL_ERROR_##e; \ |
| 985 |
|
| if (errat) { \ |
| 986 |
|
| *errat = (const char*)(c+ (ptrdiff_t)(offset)); \ |
| 987 |
|
| } \ |
| 988 |
|
| return 0; |
| 989 |
|
| |
| 990 |
106 |
▶ | for (; len; len--, c++, out++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (; len; len--, c++, out++) { |
93 |
13 |
106 |
|
| 991 |
|
| unsigned int uesc_val[2]; |
| 992 |
93 |
▶ | if (in_escape) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (in_escape) { |
2 |
91 |
93 |
|
| 993 |
|
| /* inside a previously ignored escape. Ignore */ |
| 994 |
2 |
| in_escape = 0; |
| 995 |
2 |
| goto GT_ASSIGN; |
| 996 |
|
| } |
| 997 |
|
| |
| 998 |
91 |
▶ | if (*c != '\\') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*c != '\\') { |
75 |
16 |
91 |
|
| 999 |
|
| /* Not an escape, so we don't care about this */ |
| 1000 |
75 |
| goto GT_ASSIGN; |
| 1001 |
|
| } |
| 1002 |
|
| |
| 1003 |
16 |
▶ | if (len < 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len < 2) { |
0 |
16 |
16 |
|
| 1004 |
1 |
▶ | UNESCAPE_BAIL(ESCAPE_INVALID, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| UNESCAPE_BAIL(ESCAPE_INVALID, 0); |
0 |
0 |
0 |
|
| 1005 |
|
| } |
| 1006 |
16 |
▶ | if (!is_allowed_escape(c[1])) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_allowed_escape(c[1])) { |
1 |
15 |
16 |
|
| 1007 |
1 |
▶ | UNESCAPE_BAIL(ESCAPE_INVALID, 1) |
Branch: 1 branch
| Branch | True | False | Total |
| UNESCAPE_BAIL(ESCAPE_INVALID, 1) |
1 |
0 |
1 |
|
| 1008 |
|
| } |
| 1009 |
15 |
▶ | if ((toEscape[(unsigned char)c[1] & 0x7f] == 0 && |
Branch: 1 branch
| Branch | True | False | Total |
| if ((toEscape[(unsigned char)c[1] & 0x7f] == 0 && |
2 |
13 |
15 |
|
| 1010 |
2 |
▶ | c[1] != '\\' && c[1] != '"')) { |
Branch: 2 branches
| Branch | True | False | Total |
| c[1] != '\\' && c[1] != '"')) { |
2 |
0 |
2 |
| c[1] != '\\' && c[1] != '"')) { |
2 |
0 |
2 |
|
| 1011 |
|
| /* if we don't want to unescape this string, just continue with |
| 1012 |
|
| * the escape flag set |
| 1013 |
|
| */ |
| 1014 |
2 |
| in_escape = 1; |
| 1015 |
2 |
| goto GT_ASSIGN; |
| 1016 |
|
| } |
| 1017 |
|
| |
| 1018 |
13 |
▶ | if (c[1] != 'u') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (c[1] != 'u') { |
7 |
6 |
13 |
|
| 1019 |
|
| /* simple skip-and-replace using pre-defined maps. |
| 1020 |
|
| * TODO: should the maps actually reflect the desired |
| 1021 |
|
| * replacement character in toEscape? |
| 1022 |
|
| */ |
| 1023 |
7 |
▶ | if (Escape_Maps[c[1]]) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (Escape_Maps[c[1]]) { |
5 |
2 |
7 |
|
| 1024 |
|
| /* Check if there is a corresponding replacement */ |
| 1025 |
5 |
| *out = Escape_Maps[c[1]]; |
| 1026 |
|
| } else { |
| 1027 |
|
| /* Just gobble up the 'reverse-solidus' */ |
| 1028 |
2 |
| *out = c[1]; |
| 1029 |
|
| } |
| 1030 |
7 |
| len--; |
| 1031 |
7 |
| ndiff++; |
| 1032 |
7 |
| c++; |
| 1033 |
|
| /* do not assign, just continue */ |
| 1034 |
13 |
| continue; |
| 1035 |
|
| } |
| 1036 |
|
| |
| 1037 |
|
| /* next == 'u' */ |
| 1038 |
6 |
▶ | if (len < 6) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len < 6) { |
0 |
6 |
6 |
|
| 1039 |
|
| /* Need at least six characters: |
| 1040 |
|
| * { [0] = '\\', [1] = 'u', [2] = 'f', [3] = 'f', [4] = 'f', [5] = 'f' } |
| 1041 |
|
| */ |
| 1042 |
0 |
▶ | UNESCAPE_BAIL(UESCAPE_TOOSHORT, -1); |
Branch: 1 branch
| Branch | True | False | Total |
| UNESCAPE_BAIL(UESCAPE_TOOSHORT, -1); |
0 |
0 |
0 |
|
| 1043 |
|
| } |
| 1044 |
|
| |
| 1045 |
6 |
▶ | if (sscanf((const char*)(c+2), "%02x%02x", uesc_val, uesc_val+1) != 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sscanf((const char*)(c+2), "%02x%02x", uesc_val, uesc_val+1) != 2) { |
0 |
6 |
6 |
|
| 1046 |
|
| /* We treat the sequence as two octets */ |
| 1047 |
0 |
▶ | UNESCAPE_BAIL(UESCAPE_TOOSHORT, -1); |
Branch: 1 branch
| Branch | True | False | Total |
| UNESCAPE_BAIL(UESCAPE_TOOSHORT, -1); |
0 |
0 |
0 |
|
| 1048 |
|
| } |
| 1049 |
|
| |
| 1050 |
|
| /* By now, we gobble up all the six bytes (current implied + 5 next |
| 1051 |
|
| * characters), and have at least four missing bytes from the output |
| 1052 |
|
| * buffer. |
| 1053 |
|
| */ |
| 1054 |
6 |
| len -= 5; |
| 1055 |
6 |
| c += 5; |
| 1056 |
|
| |
| 1057 |
6 |
| ndiff += 4; |
| 1058 |
6 |
▶ | if (uesc_val[0] == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (uesc_val[0] == 0) { |
5 |
1 |
6 |
|
| 1059 |
|
| /* only one byte is extracted from the two |
| 1060 |
|
| * possible octets. Increment the diff counter by one. |
| 1061 |
|
| */ |
| 1062 |
5 |
| *out = uesc_val[1]; |
| 1063 |
5 |
▶ | if (oflags && *(unsigned char*)out > 0x7f) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (oflags && *(unsigned char*)out > 0x7f) { |
5 |
0 |
5 |
| if (oflags && *(unsigned char*)out > 0x7f) { |
0 |
5 |
5 |
|
| 1064 |
0 |
| *oflags |= JSONSL_SPECIALf_NONASCII; |
| 1065 |
|
| } |
| 1066 |
5 |
| ndiff++; |
| 1067 |
|
| } else { |
| 1068 |
1 |
| *(out++) = uesc_val[0]; |
| 1069 |
1 |
| *out = uesc_val[1]; |
| 1070 |
1 |
▶ | if (oflags && (uesc_val[0] > 0x7f || uesc_val[1] > 0x7f)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (oflags && (uesc_val[0] > 0x7f || uesc_val[1] > 0x7f)) { |
1 |
0 |
1 |
| if (oflags && (uesc_val[0] > 0x7f || uesc_val[1] > 0x7f)) { |
0 |
1 |
1 |
| if (oflags && (uesc_val[0] > 0x7f || uesc_val[1] > 0x7f)) { |
0 |
0 |
0 |
|
| 1071 |
1 |
| *oflags |= JSONSL_SPECIALf_NONASCII; |
| 1072 |
|
| } |
| 1073 |
|
| } |
| 1074 |
6 |
| continue; |
| 1075 |
|
| |
| 1076 |
|
| /* Only reached by previous branches */ |
| 1077 |
79 |
| GT_ASSIGN: |
| 1078 |
79 |
| *out = *c; |
| 1079 |
|
| } |
| 1080 |
13 |
| *err = JSONSL_ERROR_SUCCESS; |
| 1081 |
13 |
| return origlen - ndiff; |
| 1082 |
|
| } |
| 1083 |
|
| |
| 1084 |
|
| /** |
| 1085 |
|
| * Character Table definitions. |
| 1086 |
|
| * These were all generated via srcutil/genchartables.pl |
| 1087 |
|
| */ |
| 1088 |
|
| |
| 1089 |
|
| /** |
| 1090 |
|
| * This table contains the beginnings of non-string |
| 1091 |
|
| * allowable (bareword) values. |
| 1092 |
|
| */ |
| 1093 |
|
| static jsonsl_special_t _special_table[0x100] = { |
| 1094 |
|
| /* 0x00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x1f */ |
| 1095 |
|
| /* 0x20 */ 0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x2c */ |
| 1096 |
|
| /* 0x2d */ JSONSL_SPECIALf_SIGNED /* - */, /* 0x2d */ |
| 1097 |
|
| /* 0x2e */ 0,0, /* 0x2f */ |
| 1098 |
|
| /* 0x30 */ JSONSL_SPECIALf_UNSIGNED /* 0 */, /* 0x30 */ |
| 1099 |
|
| /* 0x31 */ JSONSL_SPECIALf_UNSIGNED /* 1 */, /* 0x31 */ |
| 1100 |
|
| /* 0x32 */ JSONSL_SPECIALf_UNSIGNED /* 2 */, /* 0x32 */ |
| 1101 |
|
| /* 0x33 */ JSONSL_SPECIALf_UNSIGNED /* 3 */, /* 0x33 */ |
| 1102 |
|
| /* 0x34 */ JSONSL_SPECIALf_UNSIGNED /* 4 */, /* 0x34 */ |
| 1103 |
|
| /* 0x35 */ JSONSL_SPECIALf_UNSIGNED /* 5 */, /* 0x35 */ |
| 1104 |
|
| /* 0x36 */ JSONSL_SPECIALf_UNSIGNED /* 6 */, /* 0x36 */ |
| 1105 |
|
| /* 0x37 */ JSONSL_SPECIALf_UNSIGNED /* 7 */, /* 0x37 */ |
| 1106 |
|
| /* 0x38 */ JSONSL_SPECIALf_UNSIGNED /* 8 */, /* 0x38 */ |
| 1107 |
|
| /* 0x39 */ JSONSL_SPECIALf_UNSIGNED /* 9 */, /* 0x39 */ |
| 1108 |
|
| /* 0x3a */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x59 */ |
| 1109 |
|
| /* 0x5a */ 0,0,0,0,0,0,0,0,0,0,0,0, /* 0x65 */ |
| 1110 |
|
| /* 0x66 */ JSONSL_SPECIALf_FALSE /* f */, /* 0x66 */ |
| 1111 |
|
| /* 0x67 */ 0,0,0,0,0,0,0, /* 0x6d */ |
| 1112 |
|
| /* 0x6e */ JSONSL_SPECIALf_NULL /* n */, /* 0x6e */ |
| 1113 |
|
| /* 0x6f */ 0,0,0,0,0, /* 0x73 */ |
| 1114 |
|
| /* 0x74 */ JSONSL_SPECIALf_TRUE /* t */, /* 0x74 */ |
| 1115 |
|
| /* 0x75 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x94 */ |
| 1116 |
|
| /* 0x95 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xb4 */ |
| 1117 |
|
| /* 0xb5 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xd4 */ |
| 1118 |
|
| /* 0xd5 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xf4 */ |
| 1119 |
|
| /* 0xf5 */ 0,0,0,0,0,0,0,0,0,0 /* 0xfe */ |
| 1120 |
|
| }; |
| 1121 |
|
| static jsonsl_special_t *Special_table = _special_table; |
| 1122 |
|
| |
| 1123 |
|
| /** |
| 1124 |
|
| * Contains characters which signal the termination of any of the 'special' bareword |
| 1125 |
|
| * values. |
| 1126 |
|
| */ |
| 1127 |
|
| static int _special_endings[0x100] = { |
| 1128 |
|
| /* 0x00 */ 0,0,0,0,0,0,0,0,0, /* 0x08 */ |
| 1129 |
|
| /* 0x09 */ 1 /* <TAB> */, /* 0x09 */ |
| 1130 |
|
| /* 0x0a */ 1 /* <LF> */, /* 0x0a */ |
| 1131 |
|
| /* 0x0b */ 0,0, /* 0x0c */ |
| 1132 |
|
| /* 0x0d */ 1 /* <CR> */, /* 0x0d */ |
| 1133 |
|
| /* 0x0e */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x1f */ |
| 1134 |
|
| /* 0x20 */ 1 /* <SP> */, /* 0x20 */ |
| 1135 |
|
| /* 0x21 */ 0, /* 0x21 */ |
| 1136 |
|
| /* 0x22 */ 1 /* " */, /* 0x22 */ |
| 1137 |
|
| /* 0x23 */ 0,0,0,0,0,0,0,0,0, /* 0x2b */ |
| 1138 |
|
| /* 0x2c */ 1 /* , */, /* 0x2c */ |
| 1139 |
|
| /* 0x2d */ 0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x39 */ |
| 1140 |
|
| /* 0x3a */ 1 /* : */, /* 0x3a */ |
| 1141 |
|
| /* 0x3b */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x5a */ |
| 1142 |
|
| /* 0x5b */ 1 /* [ */, /* 0x5b */ |
| 1143 |
|
| /* 0x5c */ 1 /* \ */, /* 0x5c */ |
| 1144 |
|
| /* 0x5d */ 1 /* ] */, /* 0x5d */ |
| 1145 |
|
| /* 0x5e */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x7a */ |
| 1146 |
|
| /* 0x7b */ 1 /* { */, /* 0x7b */ |
| 1147 |
|
| /* 0x7c */ 0, /* 0x7c */ |
| 1148 |
|
| /* 0x7d */ 1 /* } */, /* 0x7d */ |
| 1149 |
|
| /* 0x7e */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x9d */ |
| 1150 |
|
| /* 0x9e */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xbd */ |
| 1151 |
|
| /* 0xbe */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xdd */ |
| 1152 |
|
| /* 0xde */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xfd */ |
| 1153 |
|
| /* 0xfe */ 0 /* 0xfe */ |
| 1154 |
|
| }; |
| 1155 |
|
| static int *Special_Endings = _special_endings; |
| 1156 |
|
| |
| 1157 |
|
| /** |
| 1158 |
|
| * Contains allowable whitespace. |
| 1159 |
|
| */ |
| 1160 |
|
| static int _allowed_whitespace[0x100] = { |
| 1161 |
|
| /* 0x00 */ 0,0,0,0,0,0,0,0,0, /* 0x08 */ |
| 1162 |
|
| /* 0x09 */ 1 /* <TAB> */, /* 0x09 */ |
| 1163 |
|
| /* 0x0a */ 1 /* <LF> */, /* 0x0a */ |
| 1164 |
|
| /* 0x0b */ 0,0, /* 0x0c */ |
| 1165 |
|
| /* 0x0d */ 1 /* <CR> */, /* 0x0d */ |
| 1166 |
|
| /* 0x0e */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x1f */ |
| 1167 |
|
| /* 0x20 */ 1 /* <SP> */, /* 0x20 */ |
| 1168 |
|
| /* 0x21 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x40 */ |
| 1169 |
|
| /* 0x41 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x60 */ |
| 1170 |
|
| /* 0x61 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x80 */ |
| 1171 |
|
| /* 0x81 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xa0 */ |
| 1172 |
|
| /* 0xa1 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xc0 */ |
| 1173 |
|
| /* 0xc1 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xe0 */ |
| 1174 |
|
| /* 0xe1 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* 0xfe */ |
| 1175 |
|
| }; |
| 1176 |
|
| static int *Allowed_Whitespace = _allowed_whitespace; |
| 1177 |
|
| |
| 1178 |
|
| /** |
| 1179 |
|
| * Allowable two-character 'common' escapes: |
| 1180 |
|
| */ |
| 1181 |
|
| static int _allowed_escapes[0x100] = { |
| 1182 |
|
| /* 0x00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x1f */ |
| 1183 |
|
| /* 0x20 */ 0,0, /* 0x21 */ |
| 1184 |
|
| /* 0x22 */ 1 /* <"> */, /* 0x22 */ |
| 1185 |
|
| /* 0x23 */ 0,0,0,0,0,0,0,0,0,0,0,0, /* 0x2e */ |
| 1186 |
|
| /* 0x2f */ 1 /* </> */, /* 0x2f */ |
| 1187 |
|
| /* 0x30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f */ |
| 1188 |
|
| /* 0x50 */ 0,0,0,0,0,0,0,0,0,0,0,0, /* 0x5b */ |
| 1189 |
|
| /* 0x5c */ 1 /* <\> */, /* 0x5c */ |
| 1190 |
|
| /* 0x5d */ 0,0,0,0,0, /* 0x61 */ |
| 1191 |
|
| /* 0x62 */ 1 /* <b> */, /* 0x62 */ |
| 1192 |
|
| /* 0x63 */ 0,0,0, /* 0x65 */ |
| 1193 |
|
| /* 0x66 */ 1 /* <f> */, /* 0x66 */ |
| 1194 |
|
| /* 0x67 */ 0,0,0,0,0,0,0, /* 0x6d */ |
| 1195 |
|
| /* 0x6e */ 1 /* <n> */, /* 0x6e */ |
| 1196 |
|
| /* 0x6f */ 0,0,0, /* 0x71 */ |
| 1197 |
|
| /* 0x72 */ 1 /* <r> */, /* 0x72 */ |
| 1198 |
|
| /* 0x73 */ 0, /* 0x73 */ |
| 1199 |
|
| /* 0x74 */ 1 /* <t> */, /* 0x74 */ |
| 1200 |
|
| /* 0x75 */ 1 /* <u> */, /* 0x75 */ |
| 1201 |
|
| /* 0x76 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x95 */ |
| 1202 |
|
| /* 0x96 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xb5 */ |
| 1203 |
|
| /* 0xb6 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xd5 */ |
| 1204 |
|
| /* 0xd6 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xf5 */ |
| 1205 |
|
| /* 0xf6 */ 0,0,0,0,0,0,0,0,0, /* 0xfe */ |
| 1206 |
|
| }; |
| 1207 |
|
| |
| 1208 |
|
| static int *Allowed_Escapes = _allowed_escapes; |
| 1209 |
|
| |
| 1210 |
|
| |
| 1211 |
|
| static unsigned char _escape_maps[0x100] = { |
| 1212 |
|
| /* 0x00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x1f */ |
| 1213 |
|
| /* 0x20 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x3f */ |
| 1214 |
|
| /* 0x40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x5f */ |
| 1215 |
|
| /* 0x60 */ 0,0, /* 0x61 */ |
| 1216 |
|
| /* 0x62 */ 8 /* <b> */, /* 0x62 */ |
| 1217 |
|
| /* 0x63 */ 0,0,0, /* 0x65 */ |
| 1218 |
|
| /* 0x66 */ 12 /* <f> */, /* 0x66 */ |
| 1219 |
|
| /* 0x67 */ 0,0,0,0,0,0,0, /* 0x6d */ |
| 1220 |
|
| /* 0x6e */ 10 /* <n> */, /* 0x6e */ |
| 1221 |
|
| /* 0x6f */ 0,0,0, /* 0x71 */ |
| 1222 |
|
| /* 0x72 */ 13 /* <r> */, /* 0x72 */ |
| 1223 |
|
| /* 0x73 */ 0, /* 0x73 */ |
| 1224 |
|
| /* 0x74 */ 9 /* <t> */, /* 0x74 */ |
| 1225 |
|
| /* 0x75 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x94 */ |
| 1226 |
|
| /* 0x95 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xb4 */ |
| 1227 |
|
| /* 0xb5 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xd4 */ |
| 1228 |
|
| /* 0xd5 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xf4 */ |
| 1229 |
|
| /* 0xf5 */ 0,0,0,0,0,0,0,0,0,0 /* 0xfe */ |
| 1230 |
|
| }; |
| 1231 |
|
| |
| 1232 |
|
| static unsigned char *Escape_Maps = _escape_maps; |
| 1233 |
|
| |
| 1234 |
|
| |