ox 2.14.14 → 2.14.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +1 -1
- data/ext/ox/attr.h +33 -39
- data/ext/ox/base64.c +48 -42
- data/ext/ox/base64.h +4 -4
- data/ext/ox/buf.h +80 -86
- data/ext/ox/builder.c +377 -456
- data/ext/ox/cache.c +2 -2
- data/ext/ox/cache8.c +37 -40
- data/ext/ox/cache8.h +7 -7
- data/ext/ox/dump.c +811 -889
- data/ext/ox/err.c +16 -13
- data/ext/ox/err.h +11 -12
- data/ext/ox/extconf.rb +5 -10
- data/ext/ox/gen_load.c +135 -139
- data/ext/ox/hash_load.c +130 -148
- data/ext/ox/helper.h +32 -39
- data/ext/ox/intern.c +1 -2
- data/ext/ox/obj_load.c +586 -662
- data/ext/ox/ox.c +93 -132
- data/ext/ox/ox.h +5 -10
- data/ext/ox/parse.c +836 -874
- data/ext/ox/sax.c +56 -31
- data/ext/ox/sax.h +2 -2
- data/ext/ox/sax_as.c +78 -102
- data/ext/ox/sax_buf.c +85 -94
- data/ext/ox/sax_buf.h +101 -120
- data/ext/ox/sax_hint.c +175 -184
- data/ext/ox/sax_hint.h +19 -19
- data/ext/ox/sax_stack.h +59 -45
- data/ext/ox/slotcache.c +3 -3
- data/ext/ox/slotcache.h +4 -4
- data/ext/ox/special.c +320 -327
- data/ext/ox/special.h +2 -2
- data/ext/ox/type.h +19 -19
- data/lib/ox/bag.rb +13 -9
- data/lib/ox/cdata.rb +0 -2
- data/lib/ox/comment.rb +0 -2
- data/lib/ox/doctype.rb +0 -2
- data/lib/ox/document.rb +3 -5
- data/lib/ox/element.rb +41 -26
- data/lib/ox/error.rb +0 -3
- data/lib/ox/hasattrs.rb +7 -8
- data/lib/ox/instruct.rb +4 -6
- data/lib/ox/node.rb +3 -4
- data/lib/ox/raw.rb +0 -2
- data/lib/ox/sax.rb +20 -36
- data/lib/ox/version.rb +1 -2
- data/lib/ox/xmlrpc_adapter.rb +5 -6
- data/lib/ox.rb +15 -16
- metadata +27 -6
data/ext/ox/sax_hint.c
CHANGED
@@ -3,169 +3,162 @@
|
|
3
3
|
* All rights reserved.
|
4
4
|
*/
|
5
5
|
|
6
|
-
#include
|
7
|
-
#include <stdio.h>
|
8
|
-
#include <stdbool.h>
|
6
|
+
#include "sax_hint.h"
|
9
7
|
|
10
8
|
#include <ruby.h>
|
9
|
+
#include <stdbool.h>
|
10
|
+
#include <stdio.h>
|
11
|
+
#include <string.h>
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
static const char
|
15
|
-
static const char
|
16
|
-
static const char
|
17
|
-
static const char
|
18
|
-
static const char
|
19
|
-
static const char
|
20
|
-
static const char
|
21
|
-
static const char
|
22
|
-
static const char
|
23
|
-
static const char
|
24
|
-
static const char
|
25
|
-
static const char
|
26
|
-
static const char
|
27
|
-
static const char
|
28
|
-
static const char *table_0[] = { "table", 0 };
|
29
|
-
static const char *tr_0[] = { "tr", 0 };
|
13
|
+
static const char *audio_video_0[] = {"audio", "video", 0};
|
14
|
+
static const char *colgroup_0[] = {"colgroup", 0};
|
15
|
+
static const char *details_0[] = {"details", 0};
|
16
|
+
static const char *dl_0[] = {"dl", 0};
|
17
|
+
static const char *dt_th_0[] = {"dt", "th", 0};
|
18
|
+
static const char *fieldset_0[] = {"fieldset", 0};
|
19
|
+
static const char *figure_0[] = {"figure", 0};
|
20
|
+
static const char *frameset_0[] = {"frameset", 0};
|
21
|
+
static const char *head_0[] = {"head", 0};
|
22
|
+
static const char *html_0[] = {"html", 0};
|
23
|
+
static const char *map_0[] = {"map", 0};
|
24
|
+
static const char *ol_ul_menu_0[] = {"ol", "ul", "menu", 0};
|
25
|
+
static const char *optgroup_select_datalist_0[] = {"optgroup", "select", "datalist", 0};
|
26
|
+
static const char *ruby_0[] = {"ruby", 0};
|
27
|
+
static const char *table_0[] = {"table", 0};
|
28
|
+
static const char *tr_0[] = {"tr", 0};
|
30
29
|
|
31
|
-
static struct _hint
|
32
|
-
{
|
33
|
-
{
|
34
|
-
{
|
35
|
-
{
|
36
|
-
{
|
37
|
-
{
|
38
|
-
{
|
39
|
-
{
|
40
|
-
{
|
41
|
-
{
|
42
|
-
{
|
43
|
-
{
|
44
|
-
{
|
45
|
-
{
|
46
|
-
{
|
47
|
-
{
|
48
|
-
{
|
49
|
-
{
|
50
|
-
{
|
51
|
-
{
|
52
|
-
{
|
53
|
-
{
|
54
|
-
{
|
55
|
-
{
|
56
|
-
{
|
57
|
-
{
|
58
|
-
{
|
59
|
-
{
|
60
|
-
{
|
61
|
-
{
|
62
|
-
{
|
63
|
-
{
|
64
|
-
{
|
65
|
-
{
|
66
|
-
{
|
67
|
-
{
|
68
|
-
{
|
69
|
-
{
|
70
|
-
{
|
71
|
-
{
|
72
|
-
{
|
73
|
-
{
|
74
|
-
{
|
75
|
-
{
|
76
|
-
{
|
77
|
-
{
|
78
|
-
{
|
79
|
-
{
|
80
|
-
{
|
81
|
-
{
|
82
|
-
{
|
83
|
-
{
|
84
|
-
{
|
85
|
-
{
|
86
|
-
{
|
87
|
-
{
|
88
|
-
{
|
89
|
-
{
|
90
|
-
{
|
91
|
-
{
|
92
|
-
{
|
93
|
-
{
|
94
|
-
{
|
95
|
-
{
|
96
|
-
{
|
97
|
-
{
|
98
|
-
{
|
99
|
-
{
|
100
|
-
{
|
101
|
-
{
|
102
|
-
{
|
103
|
-
{
|
104
|
-
{
|
105
|
-
{
|
106
|
-
{
|
107
|
-
{
|
108
|
-
{
|
109
|
-
{
|
110
|
-
{
|
111
|
-
{
|
112
|
-
{
|
113
|
-
{
|
114
|
-
{
|
115
|
-
{
|
116
|
-
{
|
117
|
-
{
|
118
|
-
{
|
119
|
-
{
|
120
|
-
{
|
121
|
-
{
|
122
|
-
{
|
123
|
-
{
|
124
|
-
{
|
125
|
-
{
|
126
|
-
{
|
127
|
-
{
|
128
|
-
{
|
129
|
-
{
|
130
|
-
{
|
131
|
-
{
|
132
|
-
{
|
133
|
-
{
|
134
|
-
{
|
135
|
-
{
|
136
|
-
{
|
137
|
-
{
|
138
|
-
{
|
139
|
-
{
|
140
|
-
{
|
141
|
-
{
|
142
|
-
{
|
143
|
-
{
|
144
|
-
{
|
145
|
-
{
|
146
|
-
{
|
147
|
-
{
|
148
|
-
{
|
149
|
-
{
|
150
|
-
{
|
151
|
-
{
|
152
|
-
{
|
153
|
-
{
|
154
|
-
};
|
155
|
-
static struct _hints html_hints = {
|
156
|
-
"HTML",
|
157
|
-
html_hint_array,
|
158
|
-
sizeof(html_hint_array) / sizeof(*html_hint_array)
|
30
|
+
static struct _hint html_hint_array[] = {
|
31
|
+
{"!--", false, false, false, ActiveOverlay, NULL}, // comment
|
32
|
+
{"a", false, false, false, ActiveOverlay, NULL},
|
33
|
+
{"abbr", false, false, false, ActiveOverlay, NULL},
|
34
|
+
{"acronym", false, false, false, ActiveOverlay, NULL},
|
35
|
+
{"address", false, false, false, ActiveOverlay, NULL},
|
36
|
+
{"applet", false, false, false, ActiveOverlay, NULL},
|
37
|
+
{"area", true, false, false, ActiveOverlay, map_0},
|
38
|
+
{"article", false, false, false, ActiveOverlay, NULL},
|
39
|
+
{"aside", false, false, false, ActiveOverlay, NULL},
|
40
|
+
{"audio", false, false, false, ActiveOverlay, NULL},
|
41
|
+
{"b", false, false, false, ActiveOverlay, NULL},
|
42
|
+
{"base", true, false, false, ActiveOverlay, head_0},
|
43
|
+
{"basefont", true, false, false, ActiveOverlay, head_0},
|
44
|
+
{"bdi", false, false, false, ActiveOverlay, NULL},
|
45
|
+
{"bdo", false, true, false, ActiveOverlay, NULL},
|
46
|
+
{"big", false, false, false, ActiveOverlay, NULL},
|
47
|
+
{"blockquote", false, false, false, ActiveOverlay, NULL},
|
48
|
+
{"body", false, false, false, ActiveOverlay, html_0},
|
49
|
+
{"br", true, false, false, ActiveOverlay, NULL},
|
50
|
+
{"button", false, false, false, ActiveOverlay, NULL},
|
51
|
+
{"canvas", false, false, false, ActiveOverlay, NULL},
|
52
|
+
{"caption", false, false, false, ActiveOverlay, table_0},
|
53
|
+
{"center", false, false, false, ActiveOverlay, NULL},
|
54
|
+
{"cite", false, false, false, ActiveOverlay, NULL},
|
55
|
+
{"code", false, false, false, ActiveOverlay, NULL},
|
56
|
+
{"col", true, false, false, ActiveOverlay, colgroup_0},
|
57
|
+
{"colgroup", false, false, false, ActiveOverlay, NULL},
|
58
|
+
{"command", true, false, false, ActiveOverlay, NULL},
|
59
|
+
{"datalist", false, false, false, ActiveOverlay, NULL},
|
60
|
+
{"dd", false, false, false, ActiveOverlay, dl_0},
|
61
|
+
{"del", false, false, false, ActiveOverlay, NULL},
|
62
|
+
{"details", false, false, false, ActiveOverlay, NULL},
|
63
|
+
{"dfn", false, false, false, ActiveOverlay, NULL},
|
64
|
+
{"dialog", false, false, false, ActiveOverlay, dt_th_0},
|
65
|
+
{"dir", false, false, false, ActiveOverlay, NULL},
|
66
|
+
{"div", false, true, false, ActiveOverlay, NULL},
|
67
|
+
{"dl", false, false, false, ActiveOverlay, NULL},
|
68
|
+
{"dt", false, true, false, ActiveOverlay, dl_0},
|
69
|
+
{"em", false, false, false, ActiveOverlay, NULL},
|
70
|
+
{"embed", true, false, false, ActiveOverlay, NULL},
|
71
|
+
{"fieldset", false, false, false, ActiveOverlay, NULL},
|
72
|
+
{"figcaption", false, false, false, ActiveOverlay, figure_0},
|
73
|
+
{"figure", false, false, false, ActiveOverlay, NULL},
|
74
|
+
{"font", false, true, false, ActiveOverlay, NULL},
|
75
|
+
{"footer", false, false, false, ActiveOverlay, NULL},
|
76
|
+
{"form", false, false, false, ActiveOverlay, NULL},
|
77
|
+
{"frame", true, false, false, ActiveOverlay, frameset_0},
|
78
|
+
{"frameset", false, false, false, ActiveOverlay, NULL},
|
79
|
+
{"h1", false, false, false, ActiveOverlay, NULL},
|
80
|
+
{"h2", false, false, false, ActiveOverlay, NULL},
|
81
|
+
{"h3", false, false, false, ActiveOverlay, NULL},
|
82
|
+
{"h4", false, false, false, ActiveOverlay, NULL},
|
83
|
+
{"h5", false, false, false, ActiveOverlay, NULL},
|
84
|
+
{"h6", false, false, false, ActiveOverlay, NULL},
|
85
|
+
{"head", false, false, false, ActiveOverlay, html_0},
|
86
|
+
{"header", false, false, false, ActiveOverlay, NULL},
|
87
|
+
{"hgroup", false, false, false, ActiveOverlay, NULL},
|
88
|
+
{"hr", true, false, false, ActiveOverlay, NULL},
|
89
|
+
{"html", false, false, false, ActiveOverlay, NULL},
|
90
|
+
{"i", false, false, false, ActiveOverlay, NULL},
|
91
|
+
{"iframe", true, false, false, ActiveOverlay, NULL},
|
92
|
+
{"img", true, false, false, ActiveOverlay, NULL},
|
93
|
+
{"input", true, false, false, ActiveOverlay, NULL}, // somewhere under a form_0
|
94
|
+
{"ins", false, false, false, ActiveOverlay, NULL},
|
95
|
+
{"kbd", false, false, false, ActiveOverlay, NULL},
|
96
|
+
{"keygen", true, false, false, ActiveOverlay, NULL},
|
97
|
+
{"label", false, false, false, ActiveOverlay, NULL}, // somewhere under a form_0
|
98
|
+
{"legend", false, false, false, ActiveOverlay, fieldset_0},
|
99
|
+
{"li", false, false, false, ActiveOverlay, ol_ul_menu_0},
|
100
|
+
{"link", true, false, false, ActiveOverlay, head_0},
|
101
|
+
{"map", false, false, false, ActiveOverlay, NULL},
|
102
|
+
{"mark", false, false, false, ActiveOverlay, NULL},
|
103
|
+
{"menu", false, false, false, ActiveOverlay, NULL},
|
104
|
+
{"meta", true, false, false, ActiveOverlay, head_0},
|
105
|
+
{"meter", false, false, false, ActiveOverlay, NULL},
|
106
|
+
{"nav", false, false, false, ActiveOverlay, NULL},
|
107
|
+
{"noframes", false, false, false, ActiveOverlay, NULL},
|
108
|
+
{"noscript", false, false, false, ActiveOverlay, NULL},
|
109
|
+
{"object", false, false, false, ActiveOverlay, NULL},
|
110
|
+
{"ol", false, true, false, ActiveOverlay, NULL},
|
111
|
+
{"optgroup", false, false, false, ActiveOverlay, NULL},
|
112
|
+
{"option", false, false, false, ActiveOverlay, optgroup_select_datalist_0},
|
113
|
+
{"output", false, false, false, ActiveOverlay, NULL},
|
114
|
+
{"p", false, false, false, ActiveOverlay, NULL},
|
115
|
+
{"param", true, false, false, ActiveOverlay, NULL},
|
116
|
+
{"pre", false, false, false, ActiveOverlay, NULL},
|
117
|
+
{"progress", false, false, false, ActiveOverlay, NULL},
|
118
|
+
{"q", false, false, false, ActiveOverlay, NULL},
|
119
|
+
{"rp", false, false, false, ActiveOverlay, ruby_0},
|
120
|
+
{"rt", false, false, false, ActiveOverlay, ruby_0},
|
121
|
+
{"ruby", false, false, false, ActiveOverlay, NULL},
|
122
|
+
{"s", false, false, false, ActiveOverlay, NULL},
|
123
|
+
{"samp", false, false, false, ActiveOverlay, NULL},
|
124
|
+
{"script", false, false, true, ActiveOverlay, NULL},
|
125
|
+
{"section", false, true, false, ActiveOverlay, NULL},
|
126
|
+
{"select", false, false, false, ActiveOverlay, NULL},
|
127
|
+
{"small", false, false, false, ActiveOverlay, NULL},
|
128
|
+
{"source", false, false, false, ActiveOverlay, audio_video_0},
|
129
|
+
{"span", false, true, false, ActiveOverlay, NULL},
|
130
|
+
{"strike", false, false, false, ActiveOverlay, NULL},
|
131
|
+
{"strong", false, false, false, ActiveOverlay, NULL},
|
132
|
+
{"style", false, false, false, ActiveOverlay, NULL},
|
133
|
+
{"sub", false, false, false, ActiveOverlay, NULL},
|
134
|
+
{"summary", false, false, false, ActiveOverlay, details_0},
|
135
|
+
{"sup", false, false, false, ActiveOverlay, NULL},
|
136
|
+
{"table", false, false, false, ActiveOverlay, NULL},
|
137
|
+
{"tbody", false, false, false, ActiveOverlay, table_0},
|
138
|
+
{"td", false, false, false, ActiveOverlay, tr_0},
|
139
|
+
{"textarea", false, false, false, ActiveOverlay, NULL},
|
140
|
+
{"tfoot", false, false, false, ActiveOverlay, table_0},
|
141
|
+
{"th", false, false, false, ActiveOverlay, tr_0},
|
142
|
+
{"thead", false, false, false, ActiveOverlay, table_0},
|
143
|
+
{"time", false, false, false, ActiveOverlay, NULL},
|
144
|
+
{"title", false, false, false, ActiveOverlay, head_0},
|
145
|
+
{"tr", false, false, false, ActiveOverlay, table_0},
|
146
|
+
{"track", true, false, false, ActiveOverlay, audio_video_0},
|
147
|
+
{"tt", false, false, false, ActiveOverlay, NULL},
|
148
|
+
{"u", false, false, false, ActiveOverlay, NULL},
|
149
|
+
{"ul", false, false, false, ActiveOverlay, NULL},
|
150
|
+
{"var", false, false, false, ActiveOverlay, NULL},
|
151
|
+
{"video", false, false, false, ActiveOverlay, NULL},
|
152
|
+
{"wbr", true, false, false, ActiveOverlay, NULL},
|
159
153
|
};
|
154
|
+
static struct _hints html_hints = {"HTML", html_hint_array, sizeof(html_hint_array) / sizeof(*html_hint_array)};
|
160
155
|
|
161
|
-
Hints
|
162
|
-
ox_hints_html() {
|
156
|
+
Hints ox_hints_html() {
|
163
157
|
return &html_hints;
|
164
158
|
}
|
165
159
|
|
166
|
-
Hints
|
167
|
-
|
168
|
-
Hints nh = ALLOC(struct _hints);
|
160
|
+
Hints ox_hints_dup(Hints h) {
|
161
|
+
Hints nh = ALLOC(struct _hints);
|
169
162
|
|
170
163
|
nh->hints = ALLOC_N(struct _hint, h->size);
|
171
164
|
memcpy(nh->hints, h->hints, sizeof(struct _hint) * h->size);
|
@@ -175,42 +168,40 @@ ox_hints_dup(Hints h) {
|
|
175
168
|
return nh;
|
176
169
|
}
|
177
170
|
|
178
|
-
void
|
179
|
-
ox_hints_destroy(Hints h) {
|
171
|
+
void ox_hints_destroy(Hints h) {
|
180
172
|
if (NULL != h && &html_hints != h) {
|
181
|
-
|
182
|
-
|
173
|
+
xfree(h->hints);
|
174
|
+
xfree(h);
|
183
175
|
}
|
184
176
|
}
|
185
177
|
|
186
|
-
Hint
|
187
|
-
ox_hint_find(Hints hints, const char *name) {
|
178
|
+
Hint ox_hint_find(Hints hints, const char *name) {
|
188
179
|
if (0 != hints) {
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
180
|
+
Hint lo = hints->hints;
|
181
|
+
Hint hi = hints->hints + hints->size - 1;
|
182
|
+
Hint mid;
|
183
|
+
int res;
|
193
184
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
185
|
+
if (0 == (res = strcasecmp(name, lo->name))) {
|
186
|
+
return lo;
|
187
|
+
} else if (0 > res) {
|
188
|
+
return 0;
|
189
|
+
}
|
190
|
+
if (0 == (res = strcasecmp(name, hi->name))) {
|
191
|
+
return hi;
|
192
|
+
} else if (0 < res) {
|
193
|
+
return 0;
|
194
|
+
}
|
195
|
+
while (1 < hi - lo) {
|
196
|
+
mid = lo + (hi - lo) / 2;
|
197
|
+
if (0 == (res = strcasecmp(name, mid->name))) {
|
198
|
+
return mid;
|
199
|
+
} else if (0 < res) {
|
200
|
+
lo = mid;
|
201
|
+
} else {
|
202
|
+
hi = mid;
|
203
|
+
}
|
204
|
+
}
|
214
205
|
}
|
215
206
|
return 0;
|
216
207
|
}
|
data/ext/ox/sax_hint.h
CHANGED
@@ -9,32 +9,32 @@
|
|
9
9
|
#include <stdbool.h>
|
10
10
|
|
11
11
|
typedef enum {
|
12
|
-
ActiveOverlay
|
13
|
-
InactiveOverlay
|
14
|
-
BlockOverlay
|
15
|
-
OffOverlay
|
16
|
-
AbortOverlay
|
17
|
-
NestOverlay
|
12
|
+
ActiveOverlay = 0,
|
13
|
+
InactiveOverlay = 'i',
|
14
|
+
BlockOverlay = 'b',
|
15
|
+
OffOverlay = 'o',
|
16
|
+
AbortOverlay = 'a',
|
17
|
+
NestOverlay = 'n', // nest flag is ignored
|
18
18
|
} Overlay;
|
19
19
|
|
20
20
|
typedef struct _hint {
|
21
|
-
const char
|
22
|
-
char
|
23
|
-
char
|
24
|
-
char
|
25
|
-
char
|
26
|
-
const char
|
21
|
+
const char *name;
|
22
|
+
char empty; // must be closed or close auto it, not error
|
23
|
+
char nest; // nesting allowed
|
24
|
+
char jump; // jump to end <script> ... </script>
|
25
|
+
char overlay; // Overlay
|
26
|
+
const char **parents;
|
27
27
|
} *Hint;
|
28
28
|
|
29
29
|
typedef struct _hints {
|
30
|
-
const char
|
31
|
-
Hint
|
32
|
-
int
|
30
|
+
const char *name;
|
31
|
+
Hint hints; // array of hints
|
32
|
+
int size;
|
33
33
|
} *Hints;
|
34
34
|
|
35
|
-
extern Hints
|
36
|
-
extern Hint
|
37
|
-
extern Hints
|
38
|
-
extern void
|
35
|
+
extern Hints ox_hints_html(void);
|
36
|
+
extern Hint ox_hint_find(Hints hints, const char *name);
|
37
|
+
extern Hints ox_hints_dup(Hints h);
|
38
|
+
extern void ox_hints_destroy(Hints h);
|
39
39
|
|
40
40
|
#endif /* OX_HINT_H */
|
data/ext/ox/sax_stack.h
CHANGED
@@ -11,89 +11,103 @@
|
|
11
11
|
#include "intern.h"
|
12
12
|
#include "sax_hint.h"
|
13
13
|
|
14
|
-
#define STACK_INC
|
15
|
-
#define NV_BUF_MAX
|
14
|
+
#define STACK_INC 32
|
15
|
+
#define NV_BUF_MAX 64
|
16
16
|
|
17
17
|
typedef struct _nv {
|
18
|
-
char
|
19
|
-
const char
|
20
|
-
VALUE
|
21
|
-
int
|
22
|
-
Hint
|
18
|
+
char name_buf[NV_BUF_MAX];
|
19
|
+
const char *name;
|
20
|
+
VALUE val;
|
21
|
+
int childCnt;
|
22
|
+
Hint hint;
|
23
23
|
} *Nv;
|
24
24
|
|
25
25
|
typedef struct _nStack {
|
26
|
-
struct _nv
|
27
|
-
Nv
|
28
|
-
Nv
|
29
|
-
Nv
|
26
|
+
struct _nv base[STACK_INC];
|
27
|
+
Nv head; /* current stack */
|
28
|
+
Nv end; /* stack end */
|
29
|
+
Nv tail; /* pointer to one past last element name on stack */
|
30
30
|
} *NStack;
|
31
31
|
|
32
|
-
inline static void
|
33
|
-
stack_init(NStack stack) {
|
32
|
+
inline static void stack_init(NStack stack) {
|
34
33
|
stack->head = stack->base;
|
35
|
-
stack->end
|
34
|
+
stack->end = stack->base + sizeof(stack->base) / sizeof(struct _nv);
|
36
35
|
stack->tail = stack->head;
|
37
36
|
}
|
38
37
|
|
39
|
-
inline static int
|
40
|
-
stack_empty(NStack stack) {
|
38
|
+
inline static int stack_empty(NStack stack) {
|
41
39
|
return (stack->head == stack->tail);
|
42
40
|
}
|
43
41
|
|
44
|
-
inline static void
|
45
|
-
stack_cleanup(NStack stack) {
|
42
|
+
inline static void stack_cleanup(NStack stack) {
|
46
43
|
if (stack->base != stack->head) {
|
47
44
|
xfree(stack->head);
|
48
45
|
}
|
49
46
|
}
|
50
47
|
|
51
|
-
inline static void
|
52
|
-
stack_push(NStack stack, const char *name, size_t nlen, VALUE val, Hint hint) {
|
48
|
+
inline static void stack_push(NStack stack, const char *name, size_t nlen, VALUE val, Hint hint) {
|
53
49
|
if (stack->end <= stack->tail) {
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
50
|
+
size_t len = stack->end - stack->head;
|
51
|
+
size_t toff = stack->tail - stack->head;
|
52
|
+
|
53
|
+
if (stack->base == stack->head) {
|
54
|
+
stack->head = ALLOC_N(struct _nv, len + STACK_INC);
|
55
|
+
memcpy(stack->head, stack->base, sizeof(struct _nv) * len);
|
56
|
+
} else {
|
57
|
+
REALLOC_N(stack->head, struct _nv, len + STACK_INC);
|
58
|
+
}
|
59
|
+
stack->tail = stack->head + toff;
|
60
|
+
stack->end = stack->head + len + STACK_INC;
|
65
61
|
}
|
66
62
|
if (NV_BUF_MAX <= nlen) {
|
67
63
|
stack->tail->name = ox_strndup(name, nlen);
|
68
64
|
} else {
|
69
65
|
strncpy(stack->tail->name_buf, name, nlen);
|
70
66
|
stack->tail->name_buf[nlen] = '\0';
|
71
|
-
stack->tail->name
|
67
|
+
stack->tail->name = NULL;
|
72
68
|
}
|
73
|
-
stack->tail->val
|
74
|
-
stack->tail->hint
|
69
|
+
stack->tail->val = val;
|
70
|
+
stack->tail->hint = hint;
|
75
71
|
stack->tail->childCnt = 0;
|
76
72
|
stack->tail++;
|
77
73
|
}
|
78
74
|
|
79
|
-
inline static Nv
|
80
|
-
stack_peek(NStack stack) {
|
75
|
+
inline static Nv stack_peek(NStack stack) {
|
81
76
|
if (stack->head < stack->tail) {
|
82
|
-
|
77
|
+
return stack->tail - 1;
|
83
78
|
}
|
84
|
-
return
|
79
|
+
return NULL;
|
85
80
|
}
|
86
81
|
|
87
|
-
inline static Nv
|
88
|
-
stack_pop(NStack stack) {
|
82
|
+
inline static Nv stack_pop(NStack stack) {
|
89
83
|
if (stack->head < stack->tail) {
|
90
|
-
|
91
|
-
if (
|
92
|
-
xfree((char*)(stack->tail->name));
|
84
|
+
stack->tail--;
|
85
|
+
if (NULL != stack->tail->name) {
|
86
|
+
xfree((char *)(stack->tail->name));
|
87
|
+
}
|
88
|
+
return stack->tail;
|
89
|
+
}
|
90
|
+
return NULL;
|
91
|
+
}
|
92
|
+
|
93
|
+
inline static const char *nv_name(Nv nv) {
|
94
|
+
if (NULL == nv->name) {
|
95
|
+
return nv->name_buf;
|
96
|
+
}
|
97
|
+
return nv->name;
|
98
|
+
}
|
99
|
+
|
100
|
+
inline static int nv_same_name(Nv nv, const char *name, bool smart) {
|
101
|
+
if (smart) {
|
102
|
+
if (NULL == nv->name) {
|
103
|
+
return (0 == strcasecmp(name, nv->name_buf));
|
93
104
|
}
|
94
|
-
|
105
|
+
return (0 == strcasecmp(name, nv->name));
|
106
|
+
}
|
107
|
+
if (NULL == nv->name) {
|
108
|
+
return (0 == strcmp(name, nv->name_buf));
|
95
109
|
}
|
96
|
-
return 0;
|
110
|
+
return (0 == strcmp(name, nv->name));
|
97
111
|
}
|
98
112
|
|
99
113
|
#endif /* OX_SAX_STACK_H */
|
data/ext/ox/slotcache.c
CHANGED
@@ -82,8 +82,8 @@ slot_cache_get(SlotCache cache, const char *key, VALUE **slot, const char **keyp
|
|
82
82
|
orig->key = form_key(key);
|
83
83
|
orig->value = Qundef;
|
84
84
|
}
|
85
|
-
} else {
|
86
|
-
if (0 != cache->key) {
|
85
|
+
} else { /* not exact match but on the path */
|
86
|
+
if (0 != cache->key) { /* there is a key/value here already */
|
87
87
|
if (depth == *cache->key || (255 <= depth && 0 == strncmp(cache->key, key, depth) &&
|
88
88
|
'\0' == cache->key[depth])) { /* key belongs here */
|
89
89
|
continue;
|
@@ -145,7 +145,7 @@ static void slot_print(SlotCache c, unsigned int depth) {
|
|
145
145
|
vs = "undefined";
|
146
146
|
clas = "";
|
147
147
|
} else {
|
148
|
-
VALUE rs =
|
148
|
+
VALUE rs = rb_String((*cp)->value);
|
149
149
|
|
150
150
|
vs = StringValuePtr(rs);
|
151
151
|
clas = rb_class2name(rb_obj_class((*cp)->value));
|
data/ext/ox/slotcache.h
CHANGED
@@ -8,12 +8,12 @@
|
|
8
8
|
|
9
9
|
#include "ruby.h"
|
10
10
|
|
11
|
-
typedef struct _slotCache
|
11
|
+
typedef struct _slotCache *SlotCache;
|
12
12
|
|
13
|
-
extern void
|
13
|
+
extern void slot_cache_new(SlotCache *cache);
|
14
14
|
|
15
|
-
extern VALUE
|
15
|
+
extern VALUE slot_cache_get(SlotCache cache, const char *key, VALUE **slot, const char **keyp);
|
16
16
|
|
17
|
-
extern void
|
17
|
+
extern void slot_cache_print(SlotCache cache);
|
18
18
|
|
19
19
|
#endif /* SLOT_CACHE_H */
|