ox 2.10.0 → 2.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -2
- data/ext/ox/attr.h +10 -10
- data/ext/ox/base64.h +3 -3
- data/ext/ox/buf.h +10 -10
- data/ext/ox/builder.c +7 -7
- data/ext/ox/cache.c +6 -6
- data/ext/ox/cache.h +4 -4
- data/ext/ox/cache8.c +5 -5
- data/ext/ox/cache8.h +4 -4
- data/ext/ox/dump.c +25 -25
- data/ext/ox/encode.h +26 -0
- data/ext/ox/err.h +4 -4
- data/ext/ox/gen_load.c +5 -5
- data/ext/ox/hash_load.c +3 -3
- data/ext/ox/helper.h +10 -10
- data/ext/ox/obj_load.c +18 -18
- data/ext/ox/ox.c +36 -36
- data/ext/ox/ox.h +12 -12
- data/ext/ox/parse.c +15 -15
- data/ext/ox/sax.c +6 -6
- data/ext/ox/sax.h +9 -9
- data/ext/ox/sax_as.c +4 -4
- data/ext/ox/sax_buf.h +7 -7
- data/ext/ox/sax_has.h +4 -4
- data/ext/ox/sax_hint.c +6 -6
- data/ext/ox/sax_hint.h +5 -5
- data/ext/ox/sax_stack.h +10 -10
- data/ext/ox/special.h +3 -3
- data/ext/ox/type.h +3 -3
- data/lib/ox/element.rb +117 -1
- data/lib/ox/version.rb +1 -1
- metadata +4 -4
data/ext/ox/ox.h
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
* All rights reserved.
|
4
4
|
*/
|
5
5
|
|
6
|
-
#ifndef
|
7
|
-
#define
|
6
|
+
#ifndef OX_H
|
7
|
+
#define OX_H
|
8
8
|
|
9
9
|
#if defined(__cplusplus)
|
10
10
|
extern "C" {
|
@@ -102,9 +102,9 @@ typedef enum {
|
|
102
102
|
SpcSkip = 's',
|
103
103
|
} SkipMode;
|
104
104
|
|
105
|
-
typedef struct
|
105
|
+
typedef struct _pInfo *PInfo;
|
106
106
|
|
107
|
-
typedef struct
|
107
|
+
typedef struct _parseCallbacks {
|
108
108
|
void (*instruct)(PInfo pi, const char *target, Attr attrs, const char *content);
|
109
109
|
void (*add_doctype)(PInfo pi, const char *docType);
|
110
110
|
void (*add_comment)(PInfo pi, const char *comment);
|
@@ -115,14 +115,14 @@ typedef struct _ParseCallbacks {
|
|
115
115
|
void (*finish)(PInfo pi);
|
116
116
|
} *ParseCallbacks;
|
117
117
|
|
118
|
-
typedef struct
|
118
|
+
typedef struct _circArray {
|
119
119
|
VALUE obj_array[1024];
|
120
120
|
VALUE *objs;
|
121
121
|
unsigned long size; /* allocated size or initial array size */
|
122
122
|
unsigned long cnt;
|
123
123
|
} *CircArray;
|
124
124
|
|
125
|
-
typedef struct
|
125
|
+
typedef struct _options {
|
126
126
|
char encoding[64]; /* encoding, stored in the option to avoid GC invalidation in default values */
|
127
127
|
char margin[128]; /* left margin for dumping */
|
128
128
|
int indent; /* indention for dump, default 2 */
|
@@ -142,7 +142,7 @@ typedef struct _Options {
|
|
142
142
|
char allow_invalid; /* YesNo */
|
143
143
|
char inv_repl[12]; /* max 10 valid characters, first character is the length */
|
144
144
|
char strip_ns[64]; /* namespace to strip, \0 is no-strip, \* is all, else only matches */
|
145
|
-
struct
|
145
|
+
struct _hints *html_hints; /* html hints */
|
146
146
|
VALUE attr_key_mod;
|
147
147
|
VALUE element_key_mod;
|
148
148
|
#if HAS_ENCODING_SUPPORT
|
@@ -155,9 +155,9 @@ typedef struct _Options {
|
|
155
155
|
} *Options;
|
156
156
|
|
157
157
|
/* parse information structure */
|
158
|
-
struct
|
159
|
-
struct
|
160
|
-
struct
|
158
|
+
struct _pInfo {
|
159
|
+
struct _helperStack helpers;
|
160
|
+
struct _err err;
|
161
161
|
char *str; //buffer being read from
|
162
162
|
char *end; // end of original string
|
163
163
|
char *s; // current position in buffer
|
@@ -177,7 +177,7 @@ extern void ox_sax_define(void);
|
|
177
177
|
extern char* ox_write_obj_to_str(VALUE obj, Options copts);
|
178
178
|
extern void ox_write_obj_to_file(VALUE obj, const char *path, Options copts);
|
179
179
|
|
180
|
-
extern struct
|
180
|
+
extern struct _options ox_default_options;
|
181
181
|
|
182
182
|
extern VALUE Ox;
|
183
183
|
|
@@ -276,4 +276,4 @@ extern void ox_init_builder(VALUE ox);
|
|
276
276
|
#endif
|
277
277
|
} /* extern "C" { */
|
278
278
|
#endif
|
279
|
-
#endif /*
|
279
|
+
#endif /* OX_H */
|
data/ext/ox/parse.c
CHANGED
@@ -109,11 +109,11 @@ mark_pi_cb(void *ptr) {
|
|
109
109
|
|
110
110
|
VALUE
|
111
111
|
ox_parse(char *xml, size_t len, ParseCallbacks pcb, char **endp, Options options, Err err) {
|
112
|
-
struct
|
112
|
+
struct _pInfo pi;
|
113
113
|
int body_read = 0;
|
114
114
|
int block_given = rb_block_given_p();
|
115
115
|
volatile VALUE wrap;
|
116
|
-
|
116
|
+
|
117
117
|
if (0 == xml) {
|
118
118
|
set_error(err, "Invalid arg, xml string can not be null", xml, 0);
|
119
119
|
return Qnil;
|
@@ -234,7 +234,7 @@ gather_content(const char *src, char *content, size_t len) {
|
|
234
234
|
static void
|
235
235
|
read_instruction(PInfo pi) {
|
236
236
|
char content[1024];
|
237
|
-
struct
|
237
|
+
struct _attrStack attrs;
|
238
238
|
char *attr_name;
|
239
239
|
char *attr_value;
|
240
240
|
char *target;
|
@@ -384,7 +384,7 @@ read_comment(PInfo pi) {
|
|
384
384
|
char *s;
|
385
385
|
char *comment;
|
386
386
|
int done = 0;
|
387
|
-
|
387
|
+
|
388
388
|
next_non_white(pi);
|
389
389
|
comment = pi->s;
|
390
390
|
end = strstr(pi->s, "-->");
|
@@ -418,7 +418,7 @@ read_comment(PInfo pi) {
|
|
418
418
|
*/
|
419
419
|
static char*
|
420
420
|
read_element(PInfo pi) {
|
421
|
-
struct
|
421
|
+
struct _attrStack attrs;
|
422
422
|
const char *attr_name;
|
423
423
|
const char *attr_value;
|
424
424
|
char *name;
|
@@ -489,7 +489,7 @@ read_element(PInfo pi) {
|
|
489
489
|
hasChildren = 1;
|
490
490
|
done = 1;
|
491
491
|
pi->pcb->add_element(pi, ename, attrs.head, hasChildren);
|
492
|
-
|
492
|
+
|
493
493
|
break;
|
494
494
|
default:
|
495
495
|
/* Attribute name so it's an element and the attribute will be */
|
@@ -539,7 +539,7 @@ read_element(PInfo pi) {
|
|
539
539
|
if (hasChildren) {
|
540
540
|
char *start;
|
541
541
|
int first = 1;
|
542
|
-
|
542
|
+
|
543
543
|
done = 0;
|
544
544
|
/* read children */
|
545
545
|
while (!done) {
|
@@ -609,7 +609,7 @@ read_element(PInfo pi) {
|
|
609
609
|
case CrSkip: {
|
610
610
|
char *s = start;
|
611
611
|
char *e = start;
|
612
|
-
|
612
|
+
|
613
613
|
for (; '\0' != *e; e++) {
|
614
614
|
if ('\r' != *e) {
|
615
615
|
*s++ = *e;
|
@@ -708,7 +708,7 @@ read_text(PInfo pi) {
|
|
708
708
|
default:
|
709
709
|
if (end <= (b + (('&' == c) ? 7 : 0))) { /* extra 8 for special just in case it is sequence of bytes */
|
710
710
|
unsigned long size;
|
711
|
-
|
711
|
+
|
712
712
|
if (0 == alloc_buf) {
|
713
713
|
size = sizeof(buf) * 2;
|
714
714
|
alloc_buf = ALLOC_N(char, size);
|
@@ -748,7 +748,7 @@ read_text(PInfo pi) {
|
|
748
748
|
}
|
749
749
|
} else {
|
750
750
|
*b++ = c;
|
751
|
-
}
|
751
|
+
}
|
752
752
|
break;
|
753
753
|
case NoSkip:
|
754
754
|
case OffSkip:
|
@@ -803,7 +803,7 @@ read_reduced_text(PInfo pi) {
|
|
803
803
|
default:
|
804
804
|
if (end <= (b + spc + (('&' == c) ? 7 : 0))) { /* extra 8 for special just in case it is sequence of bytes */
|
805
805
|
unsigned long size;
|
806
|
-
|
806
|
+
|
807
807
|
if (0 == alloc_buf) {
|
808
808
|
size = sizeof(buf) * 2;
|
809
809
|
alloc_buf = ALLOC_N(char, size);
|
@@ -905,10 +905,10 @@ read_cdata(PInfo pi) {
|
|
905
905
|
static char*
|
906
906
|
read_quoted_value(PInfo pi) {
|
907
907
|
char *value = 0;
|
908
|
-
|
908
|
+
|
909
909
|
if ('"' == *pi->s || '\'' == *pi->s) {
|
910
910
|
char term = *pi->s;
|
911
|
-
|
911
|
+
|
912
912
|
pi->s++; /* skip quote character */
|
913
913
|
value = pi->s;
|
914
914
|
for (; *pi->s != term; pi->s++) {
|
@@ -1014,7 +1014,7 @@ read_coded_chars(PInfo pi, char *text) {
|
|
1014
1014
|
*text++ = '&';
|
1015
1015
|
} else if ('#' == *buf) {
|
1016
1016
|
uint64_t u = 0;
|
1017
|
-
|
1017
|
+
|
1018
1018
|
b = buf + 1;
|
1019
1019
|
if ('x' == *b || 'X' == *b) {
|
1020
1020
|
b = read_hex_uint64(b + 1, &u);
|
@@ -1085,7 +1085,7 @@ collapse_special(PInfo pi, char *str) {
|
|
1085
1085
|
if ('&' == *s) {
|
1086
1086
|
int c;
|
1087
1087
|
char *end;
|
1088
|
-
|
1088
|
+
|
1089
1089
|
s++;
|
1090
1090
|
if ('#' == *s) {
|
1091
1091
|
uint64_t u = 0;
|
data/ext/ox/sax.c
CHANGED
@@ -138,7 +138,7 @@ str2sym(SaxDrive dr, const char *str, const char **strp) {
|
|
138
138
|
|
139
139
|
void
|
140
140
|
ox_sax_parse(VALUE handler, VALUE io, SaxOptions options) {
|
141
|
-
struct
|
141
|
+
struct _saxDrive dr;
|
142
142
|
int line = 0;
|
143
143
|
|
144
144
|
sax_drive_init(&dr, handler, io, options);
|
@@ -676,7 +676,7 @@ read_cdata(SaxDrive dr) {
|
|
676
676
|
int pos = dr->buf.pos - 9;
|
677
677
|
int line = dr->buf.line;
|
678
678
|
int col = dr->buf.col - 9;
|
679
|
-
struct
|
679
|
+
struct _checkPt cp = CHECK_PT_INIT;
|
680
680
|
Nv parent = stack_peek(&dr->stack);
|
681
681
|
|
682
682
|
// TBD check parent overlay
|
@@ -771,7 +771,7 @@ read_comment(SaxDrive dr) {
|
|
771
771
|
int pos = dr->buf.pos - 4;
|
772
772
|
int line = dr->buf.line;
|
773
773
|
int col = dr->buf.col - 4;
|
774
|
-
struct
|
774
|
+
struct _checkPt cp = CHECK_PT_INIT;
|
775
775
|
|
776
776
|
buf_backup(&dr->buf); /* back up to the start in case the cdata is empty */
|
777
777
|
buf_protect(&dr->buf);
|
@@ -821,7 +821,7 @@ read_comment(SaxDrive dr) {
|
|
821
821
|
VALUE args[1];
|
822
822
|
Nv parent = stack_peek(&dr->stack);
|
823
823
|
Hint h = ox_hint_find(dr->options.hints, "!--");
|
824
|
-
|
824
|
+
|
825
825
|
if (NULL == parent || NULL == parent->hint || OffOverlay != parent->hint->overlay ||
|
826
826
|
(NULL != h && (ActiveOverlay == h->overlay || ActiveOverlay == h->overlay))) {
|
827
827
|
|
@@ -1025,7 +1025,7 @@ read_element_end(SaxDrive dr) {
|
|
1025
1025
|
int col = dr->buf.col - 1;
|
1026
1026
|
Nv nv;
|
1027
1027
|
Hint h = NULL;
|
1028
|
-
|
1028
|
+
|
1029
1029
|
if ('\0' == (c = read_name_token(dr))) {
|
1030
1030
|
return '\0';
|
1031
1031
|
}
|
@@ -1241,7 +1241,7 @@ read_text(SaxDrive dr) {
|
|
1241
1241
|
|
1242
1242
|
static int
|
1243
1243
|
read_jump_term(Buf buf, const char *pat) {
|
1244
|
-
struct
|
1244
|
+
struct _checkPt cp;
|
1245
1245
|
|
1246
1246
|
buf_checkpoint(buf, &cp); // right after <
|
1247
1247
|
if ('/' != buf_next_non_white(buf)) {
|
data/ext/ox/sax.h
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
* All rights reserved.
|
4
4
|
*/
|
5
5
|
|
6
|
-
#ifndef
|
7
|
-
#define
|
6
|
+
#ifndef OX_SAX_H
|
7
|
+
#define OX_SAX_H
|
8
8
|
|
9
9
|
#include <stdbool.h>
|
10
10
|
|
@@ -14,7 +14,7 @@
|
|
14
14
|
#include "sax_hint.h"
|
15
15
|
#include "ox.h"
|
16
16
|
|
17
|
-
typedef struct
|
17
|
+
typedef struct _saxOptions {
|
18
18
|
int symbolize;
|
19
19
|
int convert_special;
|
20
20
|
int smart;
|
@@ -23,16 +23,16 @@ typedef struct _SaxOptions {
|
|
23
23
|
Hints hints;
|
24
24
|
} *SaxOptions;
|
25
25
|
|
26
|
-
typedef struct
|
27
|
-
struct
|
28
|
-
struct
|
26
|
+
typedef struct _saxDrive {
|
27
|
+
struct _buf buf;
|
28
|
+
struct _nStack stack; /* element name stack */
|
29
29
|
VALUE handler;
|
30
30
|
VALUE value_obj;
|
31
|
-
struct
|
31
|
+
struct _saxOptions options;
|
32
32
|
int err;
|
33
33
|
int blocked;
|
34
34
|
bool abort;
|
35
|
-
struct
|
35
|
+
struct _has has;
|
36
36
|
#if HAS_ENCODING_SUPPORT
|
37
37
|
rb_encoding *encoding;
|
38
38
|
#elif HAS_PRIVATE_ENCODING
|
@@ -52,4 +52,4 @@ extern VALUE ox_sax_value_class;
|
|
52
52
|
|
53
53
|
extern VALUE str2sym(SaxDrive dr, const char *str, const char **strp);
|
54
54
|
|
55
|
-
#endif /*
|
55
|
+
#endif /* OX_SAX_H */
|
data/ext/ox/sax_as.c
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
#include <strings.h>
|
10
10
|
#include <sys/types.h>
|
11
11
|
#if NEEDS_UIO
|
12
|
-
#include <sys/uio.h>
|
12
|
+
#include <sys/uio.h>
|
13
13
|
#endif
|
14
14
|
#include <unistd.h>
|
15
15
|
#include <time.h>
|
@@ -24,7 +24,7 @@ parse_double_time(const char *text) {
|
|
24
24
|
long v2 = 0;
|
25
25
|
const char *dot = 0;
|
26
26
|
char c;
|
27
|
-
|
27
|
+
|
28
28
|
for (; '.' != *text; text++) {
|
29
29
|
c = *text;
|
30
30
|
if (c < '0' || '9' < c) {
|
@@ -50,7 +50,7 @@ parse_double_time(const char *text) {
|
|
50
50
|
#endif
|
51
51
|
}
|
52
52
|
|
53
|
-
typedef struct
|
53
|
+
typedef struct _tp {
|
54
54
|
int cnt;
|
55
55
|
char end;
|
56
56
|
char alt;
|
@@ -63,7 +63,7 @@ parse_xsd_time(const char *text) {
|
|
63
63
|
long v;
|
64
64
|
int i;
|
65
65
|
char c = '\0';
|
66
|
-
struct
|
66
|
+
struct _tp tpa[10] = { { 4, '-', '-' },
|
67
67
|
{ 2, '-', '-' },
|
68
68
|
{ 2, 'T', ' ' },
|
69
69
|
{ 2, ':', ':' },
|
data/ext/ox/sax_buf.h
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
* All rights reserved.
|
4
4
|
*/
|
5
5
|
|
6
|
-
#ifndef
|
7
|
-
#define
|
6
|
+
#ifndef OX_SAX_BUF_H
|
7
|
+
#define OX_SAX_BUF_H
|
8
8
|
|
9
|
-
typedef struct
|
9
|
+
typedef struct _buf {
|
10
10
|
char base[0x00001000];
|
11
11
|
char *head;
|
12
12
|
char *end;
|
@@ -20,16 +20,16 @@ typedef struct _Buf {
|
|
20
20
|
int pro_pos;
|
21
21
|
int pro_line;
|
22
22
|
int pro_col;
|
23
|
-
int (*read_func)(struct
|
23
|
+
int (*read_func)(struct _buf *buf);
|
24
24
|
union {
|
25
25
|
int fd;
|
26
26
|
VALUE io;
|
27
27
|
const char *str;
|
28
28
|
} in;
|
29
|
-
struct
|
29
|
+
struct _saxDrive *dr;
|
30
30
|
} *Buf;
|
31
31
|
|
32
|
-
typedef struct
|
32
|
+
typedef struct _checkPt {
|
33
33
|
int pro_dif;
|
34
34
|
int pos;
|
35
35
|
int line;
|
@@ -219,4 +219,4 @@ buf_collapse_white(char *str) {
|
|
219
219
|
*back = '\0';
|
220
220
|
}
|
221
221
|
|
222
|
-
#endif /*
|
222
|
+
#endif /* OX_SAX_BUF_H */
|
data/ext/ox/sax_has.h
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
* All rights reserved.
|
4
4
|
*/
|
5
5
|
|
6
|
-
#ifndef
|
7
|
-
#define
|
6
|
+
#ifndef OX_SAX_HAS_H
|
7
|
+
#define OX_SAX_HAS_H
|
8
8
|
|
9
|
-
typedef struct
|
9
|
+
typedef struct _has {
|
10
10
|
int instruct;
|
11
11
|
int end_instruct;
|
12
12
|
int attr;
|
@@ -50,4 +50,4 @@ has_init(Has has, VALUE handler) {
|
|
50
50
|
has->column = (Qtrue == rb_ivar_defined(handler, ox_at_column_id));
|
51
51
|
}
|
52
52
|
|
53
|
-
#endif /*
|
53
|
+
#endif /* OX_SAX_HAS_H */
|
data/ext/ox/sax_hint.c
CHANGED
@@ -28,7 +28,7 @@ static const char *ruby_0[] = { "ruby", 0 };
|
|
28
28
|
static const char *table_0[] = { "table", 0 };
|
29
29
|
static const char *tr_0[] = { "tr", 0 };
|
30
30
|
|
31
|
-
static struct
|
31
|
+
static struct _hint html_hint_array[] = {
|
32
32
|
{ "!--", false, false, false, ActiveOverlay, NULL }, // comment
|
33
33
|
{ "a", false, false, false, ActiveOverlay, NULL },
|
34
34
|
{ "abbr", false, false, false, ActiveOverlay, NULL },
|
@@ -152,7 +152,7 @@ static struct _Hint html_hint_array[] = {
|
|
152
152
|
{ "video", false, false, false, ActiveOverlay, NULL },
|
153
153
|
{ "wbr", true, false, false, ActiveOverlay, NULL },
|
154
154
|
};
|
155
|
-
static struct
|
155
|
+
static struct _hints html_hints = {
|
156
156
|
"HTML",
|
157
157
|
html_hint_array,
|
158
158
|
sizeof(html_hint_array) / sizeof(*html_hint_array)
|
@@ -165,13 +165,13 @@ ox_hints_html() {
|
|
165
165
|
|
166
166
|
Hints
|
167
167
|
ox_hints_dup(Hints h) {
|
168
|
-
Hints nh = ALLOC(struct
|
168
|
+
Hints nh = ALLOC(struct _hints);
|
169
169
|
|
170
|
-
nh->hints = ALLOC_N(struct
|
171
|
-
memcpy(nh->hints, h->hints, sizeof(struct
|
170
|
+
nh->hints = ALLOC_N(struct _hint, h->size);
|
171
|
+
memcpy(nh->hints, h->hints, sizeof(struct _hint) * h->size);
|
172
172
|
nh->size = h->size;
|
173
173
|
nh->name = h->name;
|
174
|
-
|
174
|
+
|
175
175
|
return nh;
|
176
176
|
}
|
177
177
|
|
data/ext/ox/sax_hint.h
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
* All rights reserved.
|
4
4
|
*/
|
5
5
|
|
6
|
-
#ifndef
|
7
|
-
#define
|
6
|
+
#ifndef OX_HINT_H
|
7
|
+
#define OX_HINT_H
|
8
8
|
|
9
9
|
#include <stdbool.h>
|
10
10
|
|
@@ -17,7 +17,7 @@ typedef enum {
|
|
17
17
|
NestOverlay = 'n', // nest flag is ignored
|
18
18
|
} Overlay;
|
19
19
|
|
20
|
-
typedef struct
|
20
|
+
typedef struct _hint {
|
21
21
|
const char *name;
|
22
22
|
char empty; // must be closed or close auto it, not error
|
23
23
|
char nest; // nesting allowed
|
@@ -26,7 +26,7 @@ typedef struct _Hint {
|
|
26
26
|
const char **parents;
|
27
27
|
} *Hint;
|
28
28
|
|
29
|
-
typedef struct
|
29
|
+
typedef struct _hints {
|
30
30
|
const char *name;
|
31
31
|
Hint hints; // array of hints
|
32
32
|
int size;
|
@@ -37,4 +37,4 @@ extern Hint ox_hint_find(Hints hints, const char *name);
|
|
37
37
|
extern Hints ox_hints_dup(Hints h);
|
38
38
|
extern void ox_hints_destroy(Hints h);
|
39
39
|
|
40
|
-
#endif /*
|
40
|
+
#endif /* OX_HINT_H */
|