| 1 |
|
| #include "xh_config.h" |
| 2 |
|
| #include "xh_core.h" |
| 3 |
|
| |
| 4 |
|
| void |
| 5 |
163 |
| xh_h2x_native(xh_h2x_ctx_t *ctx, xh_char_t *key, I32 key_len, SV *value) |
| 6 |
|
| { |
| 7 |
|
| xh_uint_t type; |
| 8 |
|
| size_t i, len; |
| 9 |
|
| SV *item_value; |
| 10 |
|
| xh_char_t *item; |
| 11 |
|
| I32 item_len; |
| 12 |
|
| xh_sort_hash_t *sorted_hash; |
| 13 |
|
| GV *method; |
| 14 |
|
| |
| 15 |
163 |
| value = xh_h2x_resolve_value(ctx, value, &type); |
| 16 |
|
| |
| 17 |
163 |
▶ | if (type & XH_H2X_T_BLESSED && (method = gv_fetchmethod_autoload(SvSTASH(value), "iternext", 0)) != NULL) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (type & XH_H2X_T_BLESSED && (method = gv_fetchmethod_autoload(SvSTASH(value), "iternext", 0)) != NULL) { |
1 |
162 |
163 |
| if (type & XH_H2X_T_BLESSED && (method = gv_fetchmethod_autoload(SvSTASH(value), "iternext", 0)) != NULL) { |
1 |
0 |
1 |
|
| 18 |
|
| while (1) { |
| 19 |
5 |
| item_value = xh_h2x_call_method(value, method); |
| 20 |
5 |
▶ | if (!SvOK(item_value)) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(item_value)) break; |
1 |
4 |
5 |
|
| 21 |
4 |
| (void) xh_h2x_native(ctx, key, key_len, item_value); |
| 22 |
4 |
| SvREFCNT_dec(item_value); |
| 23 |
|
| } |
| 24 |
1 |
| goto FINISH; |
| 25 |
|
| } |
| 26 |
|
| |
| 27 |
162 |
▶ | if (type & XH_H2X_T_SCALAR) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (type & XH_H2X_T_SCALAR) { |
110 |
52 |
162 |
|
| 28 |
110 |
| xh_xml_write_node(&ctx->writer, key, key_len, value, type & XH_H2X_T_RAW); |
| 29 |
|
| } |
| 30 |
52 |
▶ | else if (type & XH_H2X_T_HASH) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (type & XH_H2X_T_HASH) { |
40 |
12 |
52 |
|
| 31 |
40 |
▶ | len = HvUSEDKEYS((HV *) value); |
Branch: 1 branch
| Branch | True | False | Total |
| len = HvUSEDKEYS((HV *) value); |
0 |
40 |
40 |
|
| 32 |
40 |
▶ | if (len == 0) goto ADD_EMPTY_NODE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) goto ADD_EMPTY_NODE; |
0 |
40 |
40 |
|
| 33 |
|
| |
| 34 |
40 |
▶ | if (key != NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (key != NULL) |
39 |
1 |
40 |
|
| 35 |
39 |
| xh_xml_write_start_node(&ctx->writer, key, key_len); |
| 36 |
|
| |
| 37 |
40 |
▶ | if (len > 1 && ctx->opts.canonical) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (len > 1 && ctx->opts.canonical) { |
7 |
33 |
40 |
| if (len > 1 && ctx->opts.canonical) { |
7 |
0 |
7 |
|
| 38 |
7 |
| ENTER; |
| 39 |
7 |
| sorted_hash = xh_sort_hash((HV *) value, len); |
| 40 |
7 |
| SAVEDESTRUCTOR_X(xh_sort_hash_free, sorted_hash); |
| 41 |
20 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
15 |
5 |
20 |
|
| 42 |
15 |
| xh_h2x_native(ctx, sorted_hash[i].key, sorted_hash[i].key_len, sorted_hash[i].value); |
| 43 |
|
| } |
| 44 |
5 |
| LEAVE; |
| 45 |
|
| } |
| 46 |
|
| else { |
| 47 |
33 |
| hv_iterinit((HV *) value); |
| 48 |
66 |
▶ | while ((item_value = hv_iternextsv((HV *) value, (char **) &item, &item_len))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((item_value = hv_iternextsv((HV *) value, (char **) &item, &item_len))) { |
33 |
33 |
66 |
|
| 49 |
33 |
| xh_h2x_native(ctx, item, item_len, item_value); |
| 50 |
|
| } |
| 51 |
|
| } |
| 52 |
|
| |
| 53 |
38 |
▶ | if (key != NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (key != NULL) |
37 |
1 |
38 |
|
| 54 |
37 |
| xh_xml_write_end_node(&ctx->writer, key, key_len); |
| 55 |
|
| } |
| 56 |
12 |
▶ | else if (type & XH_H2X_T_ARRAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (type & XH_H2X_T_ARRAY) { |
11 |
1 |
12 |
|
| 57 |
11 |
| len = av_len((AV *) value) + 1; |
| 58 |
84 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
75 |
9 |
84 |
|
| 59 |
75 |
| xh_h2x_native(ctx, key, key_len, *av_fetch((AV *) value, i, 0)); |
| 60 |
|
| } |
| 61 |
|
| } |
| 62 |
|
| else { |
| 63 |
1 |
| ADD_EMPTY_NODE: |
| 64 |
1 |
▶ | if (key != NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (key != NULL) |
0 |
1 |
1 |
|
| 65 |
1 |
| xh_xml_write_empty_node(&ctx->writer, key, key_len); |
| 66 |
|
| } |
| 67 |
|
| |
| 68 |
0 |
| FINISH: |
| 69 |
157 |
| ctx->depth--; |
| 70 |
157 |
| } |
| 71 |
|
| |
| 72 |
|
| #ifdef XH_HAVE_DOM |
| 73 |
|
| void |
| 74 |
|
| xh_h2d_native(xh_h2x_ctx_t *ctx, xmlNodePtr rootNode, xh_char_t *key, I32 key_len, SV *value) |
| 75 |
|
| { |
| 76 |
|
| xh_uint_t type; |
| 77 |
|
| size_t i, len; |
| 78 |
|
| SV *item_value; |
| 79 |
|
| xh_char_t *item; |
| 80 |
|
| I32 item_len; |
| 81 |
|
| xh_sort_hash_t *sorted_hash; |
| 82 |
|
| GV *method; |
| 83 |
|
| |
| 84 |
|
| value = xh_h2x_resolve_value(ctx, value, &type); |
| 85 |
|
| |
| 86 |
|
| if (type & XH_H2X_T_BLESSED && (method = gv_fetchmethod_autoload(SvSTASH(value), "iternext", 0)) != NULL) { |
| 87 |
|
| while (1) { |
| 88 |
|
| item_value = xh_h2x_call_method(value, method); |
| 89 |
|
| if (!SvOK(item_value)) break; |
| 90 |
|
| (void) xh_h2d_native(ctx, rootNode, key, key_len, item_value); |
| 91 |
|
| SvREFCNT_dec(item_value); |
| 92 |
|
| } |
| 93 |
|
| goto FINISH; |
| 94 |
|
| } |
| 95 |
|
| |
| 96 |
|
| if (type & XH_H2X_T_SCALAR) { |
| 97 |
|
| (void) xh_dom_new_node(ctx, rootNode, key, key_len, value, type & XH_H2X_T_RAW); |
| 98 |
|
| } |
| 99 |
|
| else if (type & XH_H2X_T_HASH) { |
| 100 |
|
| len = HvUSEDKEYS((HV *) value); |
| 101 |
|
| if (len == 0) goto ADD_EMPTY_NODE; |
| 102 |
|
| |
| 103 |
|
| rootNode = xh_dom_new_node(ctx, rootNode, key, key_len, NULL, FALSE); |
| 104 |
|
| |
| 105 |
|
| if (len > 1 && ctx->opts.canonical) { |
| 106 |
|
| ENTER; |
| 107 |
|
| sorted_hash = xh_sort_hash((HV *) value, len); |
| 108 |
|
| SAVEDESTRUCTOR_X(xh_sort_hash_free, sorted_hash); |
| 109 |
|
| for (i = 0; i < len; i++) { |
| 110 |
|
| xh_h2d_native(ctx, rootNode, sorted_hash[i].key, sorted_hash[i].key_len, sorted_hash[i].value); |
| 111 |
|
| } |
| 112 |
|
| LEAVE; |
| 113 |
|
| } |
| 114 |
|
| else { |
| 115 |
|
| hv_iterinit((HV *) value); |
| 116 |
|
| while ((item_value = hv_iternextsv((HV *) value, (char **) &item, &item_len))) { |
| 117 |
|
| xh_h2d_native(ctx, rootNode, item, item_len, item_value); |
| 118 |
|
| } |
| 119 |
|
| } |
| 120 |
|
| } |
| 121 |
|
| else if (type & XH_H2X_T_ARRAY) { |
| 122 |
|
| len = av_len((AV *) value) + 1; |
| 123 |
|
| for (i = 0; i < len; i++) { |
| 124 |
|
| (void) xh_h2d_native(ctx, rootNode, key, key_len, *av_fetch((AV *) value, i, 0)); |
| 125 |
|
| } |
| 126 |
|
| } |
| 127 |
|
| else { |
| 128 |
|
| ADD_EMPTY_NODE: |
| 129 |
|
| xh_dom_new_node(ctx, rootNode, key, key_len, NULL, FALSE); |
| 130 |
|
| } |
| 131 |
|
| |
| 132 |
|
| FINISH: |
| 133 |
|
| ctx->depth--; |
| 134 |
|
| } |
| 135 |
|
| #endif |