| 1 |
|
| #include "xh_config.h" |
| 2 |
|
| #include "xh_core.h" |
| 3 |
|
| |
| 4 |
|
| SV * |
| 5 |
56 |
| xh_h2x(xh_h2x_ctx_t *ctx) |
| 6 |
|
| { |
| 7 |
|
| SV *result; |
| 8 |
|
| |
| 9 |
|
| /* run */ |
| 10 |
56 |
| dXCPT; |
| 11 |
56 |
▶ | XCPT_TRY_START |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_TRY_START |
56 |
2 |
58 |
|
| 12 |
|
| { |
| 13 |
56 |
| xh_stack_init(&ctx->stash, XH_H2X_STASH_SIZE, sizeof(SV *)); |
| 14 |
56 |
| xh_writer_init(&ctx->writer, ctx->opts.encoding, ctx->opts.output, ctx->opts.output_cb, ctx->opts.buf_size, ctx->opts.indent, ctx->opts.trim, ctx->opts.utf8); |
| 15 |
|
| |
| 16 |
56 |
▶ | if (ctx->opts.xml_decl) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->opts.xml_decl) { |
45 |
11 |
56 |
|
| 17 |
45 |
| xh_xml_write_xml_declaration(&ctx->writer, ctx->opts.version, ctx->opts.encoding); |
| 18 |
|
| } |
| 19 |
|
| |
| 20 |
56 |
| switch (ctx->opts.method) { |
| 21 |
36 |
| case XH_METHOD_NATIVE: |
| 22 |
36 |
▶ | if (ctx->opts.keep_root) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->opts.keep_root) { |
35 |
1 |
36 |
|
| 23 |
35 |
| xh_h2x_native(ctx, ctx->opts.root, xh_strlen(ctx->opts.root), SvRV(ctx->hash)); |
| 24 |
|
| } |
| 25 |
|
| else |
| 26 |
|
| { |
| 27 |
1 |
| xh_h2x_native(ctx, NULL, 0, SvRV(ctx->hash)); |
| 28 |
|
| } |
| 29 |
34 |
| break; |
| 30 |
5 |
| case XH_METHOD_NATIVE_ATTR_MODE: |
| 31 |
5 |
| (void) xh_h2x_native_attr(ctx, ctx->opts.root, xh_strlen(ctx->opts.root), SvRV(ctx->hash), XH_H2X_F_COMPLEX); |
| 32 |
5 |
| break; |
| 33 |
15 |
| case XH_METHOD_LX: |
| 34 |
15 |
| xh_h2x_lx(ctx, ctx->hash, NULL, 0, XH_H2X_F_NONE); |
| 35 |
15 |
| break; |
| 36 |
0 |
| default: |
| 37 |
0 |
| croak("Invalid method"); |
| 38 |
|
| } |
| 39 |
|
| |
| 40 |
54 |
| result = xh_writer_flush(&ctx->writer); |
| 41 |
56 |
| } XCPT_TRY_END |
| 42 |
|
| |
| 43 |
56 |
▶ | XCPT_CATCH |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_CATCH |
2 |
54 |
56 |
|
| 44 |
|
| { |
| 45 |
2 |
| xh_stash_clean(&ctx->stash); |
| 46 |
2 |
▶ | if (ctx->opts.output_cb == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->opts.output_cb == NULL) { |
0 |
2 |
2 |
|
| 47 |
0 |
| result = xh_writer_flush(&ctx->writer); |
| 48 |
0 |
▶ | if (result != NULL && result != &PL_sv_undef) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (result != NULL && result != &PL_sv_undef) { |
0 |
0 |
0 |
| if (result != NULL && result != &PL_sv_undef) { |
0 |
0 |
0 |
|
| 49 |
0 |
| SvREFCNT_dec(result); |
| 50 |
|
| } |
| 51 |
|
| } |
| 52 |
2 |
| xh_writer_destroy(&ctx->writer); |
| 53 |
2 |
▶ | XCPT_RETHROW; |
Branch: 2 branches
| Branch | True | False | Total |
| XCPT_RETHROW; |
2 |
0 |
2 |
| XCPT_RETHROW; |
0 |
0 |
0 |
|
| 54 |
|
| } |
| 55 |
|
| |
| 56 |
54 |
| xh_stash_clean(&ctx->stash); |
| 57 |
54 |
▶ | if (result != NULL && result != &PL_sv_undef && ctx->opts.utf8) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (result != NULL && result != &PL_sv_undef && ctx->opts.utf8) { |
54 |
0 |
54 |
| if (result != NULL && result != &PL_sv_undef && ctx->opts.utf8) { |
42 |
12 |
54 |
| if (result != NULL && result != &PL_sv_undef && ctx->opts.utf8) { |
41 |
1 |
42 |
|
| 58 |
|
| #ifdef XH_HAVE_ENCODER |
| 59 |
41 |
▶ | if (ctx->writer.encoder == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->writer.encoder == NULL) { |
39 |
2 |
41 |
|
| 60 |
39 |
| SvUTF8_on(result); |
| 61 |
|
| } |
| 62 |
|
| #else |
| 63 |
|
| SvUTF8_on(result); |
| 64 |
|
| #endif |
| 65 |
|
| } |
| 66 |
54 |
| xh_writer_destroy(&ctx->writer); |
| 67 |
|
| |
| 68 |
54 |
| return result; |
| 69 |
|
| } |
| 70 |
|
| |
| 71 |
|
| #ifdef XH_HAVE_DOM |
| 72 |
|
| SV * |
| 73 |
|
| xh_h2d(xh_h2x_ctx_t *ctx) |
| 74 |
|
| { |
| 75 |
|
| dXCPT; |
| 76 |
|
| |
| 77 |
|
| xmlDocPtr doc = xmlNewDoc(BAD_CAST ctx->opts.version); |
| 78 |
|
| if (doc == NULL) { |
| 79 |
|
| croak("Can't create new document"); |
| 80 |
|
| } |
| 81 |
|
| if (ctx->opts.encoding[0] == '\0') { |
| 82 |
|
| doc->encoding = (const xmlChar*) xmlStrdup((const xmlChar*) XH_INTERNAL_ENCODING); |
| 83 |
|
| } |
| 84 |
|
| else { |
| 85 |
|
| doc->encoding = (const xmlChar*) xmlStrdup((const xmlChar*) ctx->opts.encoding); |
| 86 |
|
| } |
| 87 |
|
| |
| 88 |
|
| XCPT_TRY_START |
| 89 |
|
| { |
| 90 |
|
| xh_stack_init(&ctx->stash, XH_H2X_STASH_SIZE, sizeof(SV *)); |
| 91 |
|
| switch (ctx->opts.method) { |
| 92 |
|
| case XH_METHOD_NATIVE: |
| 93 |
|
| xh_h2d_native(ctx, (xmlNodePtr) doc, ctx->opts.root, xh_strlen(ctx->opts.root), SvRV(ctx->hash)); |
| 94 |
|
| break; |
| 95 |
|
| case XH_METHOD_NATIVE_ATTR_MODE: |
| 96 |
|
| (void) xh_h2d_native_attr(ctx, (xmlNodePtr) doc, ctx->opts.root, xh_strlen(ctx->opts.root), SvRV(ctx->hash), XH_H2X_F_COMPLEX); |
| 97 |
|
| break; |
| 98 |
|
| case XH_METHOD_LX: |
| 99 |
|
| xh_h2d_lx(ctx, (xmlNodePtr) doc, ctx->hash, NULL, 0, XH_H2X_F_NONE); |
| 100 |
|
| break; |
| 101 |
|
| default: |
| 102 |
|
| croak("Invalid method"); |
| 103 |
|
| } |
| 104 |
|
| } XCPT_TRY_END |
| 105 |
|
| |
| 106 |
|
| XCPT_CATCH |
| 107 |
|
| { |
| 108 |
|
| xh_stash_clean(&ctx->stash); |
| 109 |
|
| XCPT_RETHROW; |
| 110 |
|
| } |
| 111 |
|
| |
| 112 |
|
| xh_stash_clean(&ctx->stash); |
| 113 |
|
| |
| 114 |
|
| return x_PmmNodeToSv((xmlNodePtr) doc, NULL); |
| 115 |
|
| } |
| 116 |
|
| #endif |