File Coverage

json_kind.c
Criterion Covered Total %
statement 20 22 90.9
branch 36 46 78.2
condition n/a
subroutine n/a
pod n/a
total 56 68 82.3


line stmt bran cond sub pod time code
1             #define PERL_NO_GET_CONTEXT
2             #include "EXTERN.h"
3             #include "perl.h"
4             #include "XSUB.h"
5              
6             #include
7              
8             #include "json_kind.h"
9              
10             const int json_kind_to_lex_pos[JV_KIND_COUNT] = {
11             /* JV_ARRAY_BOOL */ 0,
12             /* JV_ARRAY_FLOAT64 */ 1,
13             /* JV_ARRAY_INT64 */ 2,
14             /* JV_ARRAY_STRING */ 3,
15             /* JV_BOOL */ 4,
16             /* JV_FLOAT64 */ 5,
17             /* JV_INT64 */ 6,
18             /* JV_STRING */ 8
19             };
20              
21             const char * const json_kind_type_name[JV_KIND_COUNT] = {
22             "Array(Bool)", "Array(Float64)", "Array(Int64)", "Array(String)",
23             "Bool", "Float64", "Int64", "String"
24             };
25              
26 2693           int json_build_lex_table(unsigned mask, int slots[JSON_LEX_SLOTS]) {
27 2693           int n = 0, lex;
28 26930 100         for (lex = 0; lex < JSON_LEX_SLOTS; lex++) {
29 24237 100         if (lex == JSON_SHAREDVARIANT_LEX_POS) { slots[n++] = -1; continue; }
30             int k;
31 182904 100         for (k = 0; k < JV_KIND_COUNT; k++) {
32 164363 100         if (json_kind_to_lex_pos[k] == lex && (mask & (1u << k))) {
    100          
33 3003           slots[n++] = k;
34 3003           break;
35             }
36             }
37             }
38 2693           return n;
39             }
40              
41 2633           int json_kind_disc_in(int kind, const int slots[JSON_LEX_SLOTS], int n) {
42             int i;
43 3727 100         for (i = 0; i < n; i++) if (slots[i] == kind) return i;
    50          
44 0           return -1; /* unreachable when kind is in mask */
45             }
46              
47 661           int json_kind_from_type_name(const char *ts, STRLEN tl) {
48 661 100         if (tl == 4 && memcmp(ts, "Bool", 4) == 0) return JV_BOOL;
    50          
49 573 100         if (tl == 7 && memcmp(ts, "Float64", 7) == 0) return JV_FLOAT64;
    50          
50 504 100         if (tl == 5 && memcmp(ts, "Int64", 5) == 0) return JV_INT64;
    50          
51 376 100         if (tl == 6 && memcmp(ts, "String", 6) == 0) return JV_STRING;
    50          
52 290 100         if (tl == 11 && memcmp(ts, "Array(Bool)", 11) == 0) return JV_ARRAY_BOOL;
    50          
53 232 100         if (tl == 14 && memcmp(ts, "Array(Float64)", 14) == 0) return JV_ARRAY_FLOAT64;
    50          
54 171 100         if (tl == 12 && memcmp(ts, "Array(Int64)", 12) == 0) return JV_ARRAY_INT64;
    50          
55 53 50         if (tl == 13 && memcmp(ts, "Array(String)", 13) == 0) return JV_ARRAY_STRING;
    50          
56 0           return -1;
57             }