fast-xml 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +145 -37
- data/ext/fastxml/ccan/build_assert/build_assert.h +40 -0
- data/ext/fastxml/ccan/check_type/check_type.h +63 -0
- data/ext/fastxml/ccan/container_of/container_of.h +142 -0
- data/ext/fastxml/ccan/list/list.h +773 -0
- data/ext/fastxml/ccan/str/str.h +16 -0
- data/ext/fastxml/fastxml.c +35 -2
- data/ext/fastxml/xh.c +19 -8
- data/ext/fastxml/xh.h +2 -1
- data/ext/fastxml/xh_config.h +3 -0
- data/ext/fastxml/xh_core.h +1 -5
- data/ext/fastxml/xh_log.h +37 -27
- data/ext/fastxml/xh_param.c +3 -11
- data/ext/fastxml/xh_param.h +1 -1
- data/ext/fastxml/xh_reader.c +528 -0
- data/ext/fastxml/xh_reader.h +43 -0
- data/ext/fastxml/xh_ruby_hash.h +384 -0
- data/ext/fastxml/xh_x2h.c +1002 -0
- data/ext/fastxml/xh_x2h.h +133 -0
- data/lib/fastxml/version.rb +1 -1
- metadata +13 -3
@@ -0,0 +1,16 @@
|
|
1
|
+
/* CC0 (Public domain) - see ccan/licenses/CC0 file for details */
|
2
|
+
#ifndef CCAN_STR_H
|
3
|
+
#define CCAN_STR_H
|
4
|
+
/**
|
5
|
+
* stringify - Turn expression into a string literal
|
6
|
+
* @expr: any C expression
|
7
|
+
*
|
8
|
+
* Example:
|
9
|
+
* #define PRINT_COND_IF_FALSE(cond) \
|
10
|
+
* ((cond) || printf("%s is false!", stringify(cond)))
|
11
|
+
*/
|
12
|
+
#define stringify(expr) stringify_1(expr)
|
13
|
+
/* Double-indirection required to stringify expansions */
|
14
|
+
#define stringify_1(expr) #expr
|
15
|
+
|
16
|
+
#endif /* CCAN_STR_H */
|
data/ext/fastxml/fastxml.c
CHANGED
@@ -8,6 +8,7 @@ void Init_fastxml();
|
|
8
8
|
VALUE xh_module;
|
9
9
|
VALUE xh_parse_error_class;
|
10
10
|
ID xh_id_next;
|
11
|
+
ID xh_id_initialize;
|
11
12
|
|
12
13
|
typedef struct {
|
13
14
|
int argc;
|
@@ -15,6 +16,12 @@ typedef struct {
|
|
15
16
|
xh_h2x_ctx_t *ctx;
|
16
17
|
} xh_h2x_arg_t;
|
17
18
|
|
19
|
+
typedef struct {
|
20
|
+
int argc;
|
21
|
+
VALUE *argv;
|
22
|
+
xh_x2h_ctx_t *ctx;
|
23
|
+
} xh_x2h_arg_t;
|
24
|
+
|
18
25
|
static VALUE
|
19
26
|
hash2xml_exec(VALUE a) {
|
20
27
|
xh_h2x_arg_t *arg = (xh_h2x_arg_t *) a;
|
@@ -49,11 +56,36 @@ hash2xml(int argc, VALUE *argv, VALUE self) {
|
|
49
56
|
return result;
|
50
57
|
}
|
51
58
|
|
59
|
+
static VALUE
|
60
|
+
xml2hash_exec(VALUE a) {
|
61
|
+
xh_x2h_arg_t *arg = (xh_x2h_arg_t *) a;
|
62
|
+
|
63
|
+
xh_x2h_init_ctx(arg->ctx, arg->argc, arg->argv);
|
64
|
+
|
65
|
+
return xh_x2h(arg->ctx);
|
66
|
+
}
|
67
|
+
|
52
68
|
static VALUE
|
53
69
|
xml2hash(int argc, VALUE *argv, VALUE self) {
|
54
|
-
|
70
|
+
xh_x2h_ctx_t ctx;
|
71
|
+
VALUE result;
|
72
|
+
int state;
|
73
|
+
xh_x2h_arg_t arg;
|
55
74
|
|
56
|
-
|
75
|
+
arg.argc = argc;
|
76
|
+
arg.argv = argv;
|
77
|
+
arg.ctx = &ctx;
|
78
|
+
|
79
|
+
result = rb_protect(xml2hash_exec, (VALUE) &arg, &state);
|
80
|
+
|
81
|
+
if (state) {
|
82
|
+
xh_x2h_destroy_ctx(&ctx);
|
83
|
+
rb_exc_raise(rb_errinfo());
|
84
|
+
}
|
85
|
+
|
86
|
+
xh_x2h_destroy_ctx(&ctx);
|
87
|
+
|
88
|
+
return result;
|
57
89
|
}
|
58
90
|
|
59
91
|
void Init_fastxml(void) {
|
@@ -64,4 +96,5 @@ void Init_fastxml(void) {
|
|
64
96
|
rb_define_module_function(xh_module, "xml2hash", xml2hash, -1);
|
65
97
|
|
66
98
|
xh_id_next = rb_intern("next");
|
99
|
+
xh_id_initialize = rb_intern("initialize");
|
67
100
|
}
|
data/ext/fastxml/xh.c
CHANGED
@@ -96,14 +96,6 @@ xh_parse_arg(VALUE key, VALUE value, VALUE ctx)
|
|
96
96
|
keylen = RSTRING_LEN(key);
|
97
97
|
|
98
98
|
switch (keylen) {
|
99
|
-
case 2:
|
100
|
-
if (xh_str_equal2(keyptr, 'c', 'b')) {
|
101
|
-
VALUE v = rb_inspect(value);
|
102
|
-
rb_warn("cb: %s\n", StringValueCStr(v));
|
103
|
-
opts->cb = xh_param_assign_cb(value);
|
104
|
-
break;
|
105
|
-
}
|
106
|
-
goto error;
|
107
99
|
#ifdef XH_HAVE_DOM
|
108
100
|
case 3:
|
109
101
|
if (xh_str_equal3(keyptr, 'd', 'o', 'c')) {
|
@@ -278,6 +270,8 @@ xh_parse_args(xh_opts_t *opts, xh_int_t *nparam, xh_int_t argc, VALUE *argv)
|
|
278
270
|
(*nparam)++;
|
279
271
|
|
280
272
|
rb_hash_foreach(hash, xh_parse_arg, (VALUE) opts);
|
273
|
+
|
274
|
+
opts->block_given = xh_param_assign_block();
|
281
275
|
}
|
282
276
|
|
283
277
|
void *
|
@@ -320,6 +314,23 @@ xh_get_hash_param(xh_int_t *nparam, xh_int_t argc, VALUE *argv)
|
|
320
314
|
return param;
|
321
315
|
}
|
322
316
|
|
317
|
+
VALUE
|
318
|
+
xh_get_str_param(xh_int_t *nparam, xh_int_t argc, VALUE *argv)
|
319
|
+
{
|
320
|
+
VALUE param;
|
321
|
+
|
322
|
+
if (*nparam >= argc)
|
323
|
+
rb_raise(rb_eArgError, "Invalid parameters");
|
324
|
+
|
325
|
+
param = argv[*nparam];
|
326
|
+
if (!RB_TYPE_P(param, RUBY_T_STRING))
|
327
|
+
rb_raise(rb_eArgError, "Parameter is not a string");
|
328
|
+
|
329
|
+
(*nparam)++;
|
330
|
+
|
331
|
+
return param;
|
332
|
+
}
|
333
|
+
|
323
334
|
void
|
324
335
|
xh_merge_opts(xh_opts_t *ctx_opts, xh_opts_t *opts, xh_int_t *nparam, xh_int_t argc, VALUE *argv)
|
325
336
|
{
|
data/ext/fastxml/xh.h
CHANGED
@@ -35,7 +35,7 @@ typedef struct {
|
|
35
35
|
xh_bool_t force_content;
|
36
36
|
xh_bool_t merge_text;
|
37
37
|
xh_pattern_t filter;
|
38
|
-
|
38
|
+
xh_bool_t block_given;
|
39
39
|
|
40
40
|
/* LX options */
|
41
41
|
xh_char_t attr[XH_PARAM_LEN];
|
@@ -53,6 +53,7 @@ void xh_parse_args(xh_opts_t *opts, xh_int_t *nparam, xh_int_t argc, VALUE *argv
|
|
53
53
|
void xh_copy_opts(xh_opts_t *dst, xh_opts_t *src);
|
54
54
|
void *xh_get_obj_param(xh_int_t *nparam, xh_int_t argc, VALUE *argv, const char *class);
|
55
55
|
VALUE xh_get_hash_param(xh_int_t *nparam, xh_int_t argc, VALUE *argv);
|
56
|
+
VALUE xh_get_str_param(xh_int_t *nparam, xh_int_t argc, VALUE *argv);
|
56
57
|
void xh_merge_opts(xh_opts_t *ctx_opts, xh_opts_t *opts, xh_int_t *nparam, xh_int_t argc, VALUE *argv);
|
57
58
|
|
58
59
|
#endif /* _XH_H_ */
|
data/ext/fastxml/xh_config.h
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
#define _XH_CONFIG_H_
|
3
3
|
|
4
4
|
#include "ruby.h"
|
5
|
+
#include "ruby/io.h"
|
6
|
+
#include "ruby/re.h"
|
5
7
|
#if HAVE_RUBY_ENCODING_H
|
6
8
|
#include "ruby/encoding.h"
|
7
9
|
#endif
|
@@ -70,5 +72,6 @@ typedef u_char xh_char_t;
|
|
70
72
|
extern VALUE xh_module;
|
71
73
|
extern VALUE xh_parse_error_class;
|
72
74
|
extern ID xh_id_next;
|
75
|
+
extern ID xh_id_initialize;
|
73
76
|
|
74
77
|
#endif /* _XH_CONFIG_H_ */
|
data/ext/fastxml/xh_core.h
CHANGED
@@ -35,19 +35,15 @@
|
|
35
35
|
#include "xh_string.h"
|
36
36
|
#include "xh_sort.h"
|
37
37
|
#include "xh_stack.h"
|
38
|
-
//#include "xh_stash.h"
|
39
38
|
#include "xh_param.h"
|
40
39
|
#include "xh_buffer_helper.h"
|
41
40
|
#include "xh_buffer.h"
|
42
41
|
#include "xh_ruby_buffer.h"
|
43
42
|
#include "xh_encoder.h"
|
44
|
-
|
43
|
+
#include "xh_reader.h"
|
45
44
|
#include "xh_writer.h"
|
46
45
|
#include "xh.h"
|
47
46
|
#include "xh_h2x.h"
|
48
47
|
#include "xh_xml.h"
|
49
|
-
/*
|
50
48
|
#include "xh_x2h.h"
|
51
|
-
#include "xh_dom.h"
|
52
|
-
*/
|
53
49
|
#endif /* _XH_CORE_H_ */
|
data/ext/fastxml/xh_log.h
CHANGED
@@ -14,25 +14,35 @@ typedef enum {
|
|
14
14
|
XH_LOG_TRACE
|
15
15
|
} xh_log_level_t;
|
16
16
|
|
17
|
+
#if __STDC_VERSION__ < 199901L
|
18
|
+
# if __GNUC__ >= 2
|
19
|
+
# define XH_CURRENT_FUNCTION __FUNCTION__
|
20
|
+
# else
|
21
|
+
# define XH_CURRENT_FUNCTION "<unknown>"
|
22
|
+
# endif
|
23
|
+
#else
|
24
|
+
# define XH_CURRENT_FUNCTION __func__
|
25
|
+
#endif
|
26
|
+
|
17
27
|
#ifdef WITH_TRACE
|
18
28
|
#define xh_log_debug0(msg) \
|
19
|
-
xh_log(XH_LOG_DEBUG,
|
29
|
+
xh_log(XH_LOG_DEBUG, XH_CURRENT_FUNCTION, __LINE__, msg)
|
20
30
|
#define xh_log_debug1(msg, arg1) \
|
21
|
-
xh_log(XH_LOG_DEBUG,
|
31
|
+
xh_log(XH_LOG_DEBUG, XH_CURRENT_FUNCTION, __LINE__, msg, arg1)
|
22
32
|
#define xh_log_debug2(msg, arg1, arg2) \
|
23
|
-
xh_log(XH_LOG_DEBUG,
|
33
|
+
xh_log(XH_LOG_DEBUG, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2)
|
24
34
|
#define xh_log_debug3(msg, arg1, arg2, arg3) \
|
25
|
-
xh_log(XH_LOG_DEBUG,
|
35
|
+
xh_log(XH_LOG_DEBUG, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3)
|
26
36
|
#define xh_log_debug4(msg, arg1, arg2, arg3, arg4) \
|
27
|
-
xh_log(XH_LOG_DEBUG,
|
37
|
+
xh_log(XH_LOG_DEBUG, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4)
|
28
38
|
#define xh_log_debug5(msg, arg1, arg2, arg3, arg4, arg5) \
|
29
|
-
xh_log(XH_LOG_DEBUG,
|
39
|
+
xh_log(XH_LOG_DEBUG, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4, arg5)
|
30
40
|
#define xh_log_debug6(msg, arg1, arg2, arg3, arg4, arg5, arg6) \
|
31
|
-
xh_log(XH_LOG_DEBUG,
|
41
|
+
xh_log(XH_LOG_DEBUG, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4, arg5, arg6)
|
32
42
|
#define xh_log_debug7(msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
|
33
|
-
xh_log(XH_LOG_DEBUG,
|
43
|
+
xh_log(XH_LOG_DEBUG, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
|
34
44
|
#define xh_log_debug8(msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
|
35
|
-
xh_log(XH_LOG_DEBUG,
|
45
|
+
xh_log(XH_LOG_DEBUG, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
|
36
46
|
#else
|
37
47
|
#define xh_log_debug0(msg)
|
38
48
|
#define xh_log_debug1(msg, arg1)
|
@@ -47,23 +57,23 @@ typedef enum {
|
|
47
57
|
|
48
58
|
#ifdef WITH_TRACE
|
49
59
|
#define xh_log_trace0(msg) \
|
50
|
-
xh_log(XH_LOG_TRACE,
|
60
|
+
xh_log(XH_LOG_TRACE, XH_CURRENT_FUNCTION, __LINE__, msg)
|
51
61
|
#define xh_log_trace1(msg, arg1) \
|
52
|
-
xh_log(XH_LOG_TRACE,
|
62
|
+
xh_log(XH_LOG_TRACE, XH_CURRENT_FUNCTION, __LINE__, msg, arg1)
|
53
63
|
#define xh_log_trace2(msg, arg1, arg2) \
|
54
|
-
xh_log(XH_LOG_TRACE,
|
64
|
+
xh_log(XH_LOG_TRACE, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2)
|
55
65
|
#define xh_log_trace3(msg, arg1, arg2, arg3) \
|
56
|
-
xh_log(XH_LOG_TRACE,
|
66
|
+
xh_log(XH_LOG_TRACE, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3)
|
57
67
|
#define xh_log_trace4(msg, arg1, arg2, arg3, arg4) \
|
58
|
-
xh_log(XH_LOG_TRACE,
|
68
|
+
xh_log(XH_LOG_TRACE, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4)
|
59
69
|
#define xh_log_trace5(msg, arg1, arg2, arg3, arg4, arg5) \
|
60
|
-
xh_log(XH_LOG_TRACE,
|
70
|
+
xh_log(XH_LOG_TRACE, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4, arg5)
|
61
71
|
#define xh_log_trace6(msg, arg1, arg2, arg3, arg4, arg5, arg6) \
|
62
|
-
xh_log(XH_LOG_TRACE,
|
72
|
+
xh_log(XH_LOG_TRACE, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4, arg5, arg6)
|
63
73
|
#define xh_log_trace7(msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
|
64
|
-
xh_log(XH_LOG_TRACE,
|
74
|
+
xh_log(XH_LOG_TRACE, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
|
65
75
|
#define xh_log_trace8(msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
|
66
|
-
xh_log(XH_LOG_TRACE,
|
76
|
+
xh_log(XH_LOG_TRACE, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
|
67
77
|
#else
|
68
78
|
#define xh_log_trace0(msg)
|
69
79
|
#define xh_log_trace1(msg, arg1)
|
@@ -77,23 +87,23 @@ typedef enum {
|
|
77
87
|
#endif
|
78
88
|
|
79
89
|
#define xh_log_error0(msg) \
|
80
|
-
xh_log(XH_LOG_ERROR,
|
90
|
+
xh_log(XH_LOG_ERROR, XH_CURRENT_FUNCTION, __LINE__, msg)
|
81
91
|
#define xh_log_error1(msg, arg1) \
|
82
|
-
xh_log(XH_LOG_ERROR,
|
92
|
+
xh_log(XH_LOG_ERROR, XH_CURRENT_FUNCTION, __LINE__, msg, arg1)
|
83
93
|
#define xh_log_error2(msg, arg1, arg2) \
|
84
|
-
xh_log(XH_LOG_ERROR,
|
94
|
+
xh_log(XH_LOG_ERROR, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2)
|
85
95
|
#define xh_log_error3(msg, arg1, arg2, arg3) \
|
86
|
-
xh_log(XH_LOG_ERROR,
|
96
|
+
xh_log(XH_LOG_ERROR, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3)
|
87
97
|
#define xh_log_error4(msg, arg1, arg2, arg3, arg4) \
|
88
|
-
xh_log(XH_LOG_ERROR,
|
98
|
+
xh_log(XH_LOG_ERROR, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4)
|
89
99
|
#define xh_log_error5(msg, arg1, arg2, arg3, arg4, arg5) \
|
90
|
-
xh_log(XH_LOG_ERROR,
|
100
|
+
xh_log(XH_LOG_ERROR, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4, arg5)
|
91
101
|
#define xh_log_error6(msg, arg1, arg2, arg3, arg4, arg5, arg6) \
|
92
|
-
xh_log(XH_LOG_ERROR,
|
102
|
+
xh_log(XH_LOG_ERROR, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4, arg5, arg6)
|
93
103
|
#define xh_log_error7(msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
|
94
|
-
xh_log(XH_LOG_ERROR,
|
104
|
+
xh_log(XH_LOG_ERROR, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
|
95
105
|
#define xh_log_error8(msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
|
96
|
-
xh_log(XH_LOG_ERROR,
|
106
|
+
xh_log(XH_LOG_ERROR, XH_CURRENT_FUNCTION, __LINE__, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
|
97
107
|
|
98
108
|
void xh_log(xh_log_level_t log_level, const char *func, xh_int_t line, const char *msg, ...);
|
99
109
|
|
data/ext/fastxml/xh_param.c
CHANGED
@@ -62,16 +62,8 @@ xh_param_assign_filter(xh_pattern_t *patt, VALUE value)
|
|
62
62
|
}
|
63
63
|
}
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
xh_bool_t
|
66
|
+
xh_param_assign_block(void)
|
67
67
|
{
|
68
|
-
|
69
|
-
return Qnil;
|
70
|
-
|
71
|
-
if (rb_cProc != rb_class_of(value) && rb_cMethod != rb_class_of(value))
|
72
|
-
rb_raise(rb_eArgError, "Expected Proc or Method callback");
|
73
|
-
|
74
|
-
//rb_funcall(value, rb_intern("call"), 0);
|
75
|
-
|
76
|
-
return value;
|
68
|
+
return rb_block_given_p() ? TRUE : FALSE;
|
77
69
|
}
|
data/ext/fastxml/xh_param.h
CHANGED
@@ -15,7 +15,7 @@ void xh_param_assign_int(xh_char_t *name, xh_int_t *param, VALUE value);
|
|
15
15
|
xh_bool_t xh_param_assign_bool(VALUE value);
|
16
16
|
void xh_param_assign_pattern(xh_pattern_t *param, VALUE value);
|
17
17
|
void xh_param_assign_filter(xh_pattern_t *param, VALUE value);
|
18
|
-
VALUE
|
18
|
+
VALUE xh_param_assign_block(void);
|
19
19
|
|
20
20
|
#define XH_PARAM_LEN 32
|
21
21
|
|