ox 2.14.13 → 2.14.15

Sign up to get free protection for your applications and to get access to all the features.
data/ext/ox/sax_hint.c CHANGED
@@ -3,169 +3,162 @@
3
3
  * All rights reserved.
4
4
  */
5
5
 
6
- #include <string.h>
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
- #include "sax_hint.h"
13
-
14
- static const char *audio_video_0[] = { "audio", "video", 0 };
15
- static const char *colgroup_0[] = { "colgroup", 0 };
16
- static const char *details_0[] = { "details", 0 };
17
- static const char *dl_0[] = { "dl", 0 };
18
- static const char *dt_th_0[] = { "dt", "th", 0 };
19
- static const char *fieldset_0[] = { "fieldset", 0 };
20
- static const char *figure_0[] = { "figure", 0 };
21
- static const char *frameset_0[] = { "frameset", 0 };
22
- static const char *head_0[] = { "head", 0 };
23
- static const char *html_0[] = { "html", 0 };
24
- static const char *map_0[] = { "map", 0 };
25
- static const char *ol_ul_menu_0[] = { "ol", "ul", "menu", 0 };
26
- static const char *optgroup_select_datalist_0[] = { "optgroup", "select", "datalist", 0 };
27
- static const char *ruby_0[] = { "ruby", 0 };
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 html_hint_array[] = {
32
- { "!--", false, false, false, ActiveOverlay, NULL }, // comment
33
- { "a", false, false, false, ActiveOverlay, NULL },
34
- { "abbr", false, false, false, ActiveOverlay, NULL },
35
- { "acronym", false, false, false, ActiveOverlay, NULL },
36
- { "address", false, false, false, ActiveOverlay, NULL },
37
- { "applet", false, false, false, ActiveOverlay, NULL },
38
- { "area", true, false, false, ActiveOverlay, map_0 },
39
- { "article", false, false, false, ActiveOverlay, NULL },
40
- { "aside", false, false, false, ActiveOverlay, NULL },
41
- { "audio", false, false, false, ActiveOverlay, NULL },
42
- { "b", false, false, false, ActiveOverlay, NULL },
43
- { "base", true, false, false, ActiveOverlay, head_0 },
44
- { "basefont", true, false, false, ActiveOverlay, head_0 },
45
- { "bdi", false, false, false, ActiveOverlay, NULL },
46
- { "bdo", false, true, false, ActiveOverlay, NULL },
47
- { "big", false, false, false, ActiveOverlay, NULL },
48
- { "blockquote", false, false, false, ActiveOverlay, NULL },
49
- { "body", false, false, false, ActiveOverlay, html_0 },
50
- { "br", true, false, false, ActiveOverlay, NULL },
51
- { "button", false, false, false, ActiveOverlay, NULL },
52
- { "canvas", false, false, false, ActiveOverlay, NULL },
53
- { "caption", false, false, false, ActiveOverlay, table_0 },
54
- { "center", false, false, false, ActiveOverlay, NULL },
55
- { "cite", false, false, false, ActiveOverlay, NULL },
56
- { "code", false, false, false, ActiveOverlay, NULL },
57
- { "col", true, false, false, ActiveOverlay, colgroup_0 },
58
- { "colgroup", false, false, false, ActiveOverlay, NULL },
59
- { "command", true, false, false, ActiveOverlay, NULL },
60
- { "datalist", false, false, false, ActiveOverlay, NULL },
61
- { "dd", false, false, false, ActiveOverlay, dl_0 },
62
- { "del", false, false, false, ActiveOverlay, NULL },
63
- { "details", false, false, false, ActiveOverlay, NULL },
64
- { "dfn", false, false, false, ActiveOverlay, NULL },
65
- { "dialog", false, false, false, ActiveOverlay, dt_th_0 },
66
- { "dir", false, false, false, ActiveOverlay, NULL },
67
- { "div", false, true, false, ActiveOverlay, NULL },
68
- { "dl", false, false, false, ActiveOverlay, NULL },
69
- { "dt", false, true, false, ActiveOverlay, dl_0 },
70
- { "em", false, false, false, ActiveOverlay, NULL },
71
- { "embed", true, false, false, ActiveOverlay, NULL },
72
- { "fieldset", false, false, false, ActiveOverlay, NULL },
73
- { "figcaption", false, false, false, ActiveOverlay, figure_0 },
74
- { "figure", false, false, false, ActiveOverlay, NULL },
75
- { "font", false, true, false, ActiveOverlay, NULL },
76
- { "footer", false, false, false, ActiveOverlay, NULL },
77
- { "form", false, false, false, ActiveOverlay, NULL },
78
- { "frame", true, false, false, ActiveOverlay, frameset_0 },
79
- { "frameset", false, false, false, ActiveOverlay, NULL },
80
- { "h1", false, false, false, ActiveOverlay, NULL },
81
- { "h2", false, false, false, ActiveOverlay, NULL },
82
- { "h3", false, false, false, ActiveOverlay, NULL },
83
- { "h4", false, false, false, ActiveOverlay, NULL },
84
- { "h5", false, false, false, ActiveOverlay, NULL },
85
- { "h6", false, false, false, ActiveOverlay, NULL },
86
- { "head", false, false, false, ActiveOverlay, html_0 },
87
- { "header", false, false, false, ActiveOverlay, NULL },
88
- { "hgroup", false, false, false, ActiveOverlay, NULL },
89
- { "hr", true, false, false, ActiveOverlay, NULL },
90
- { "html", false, false, false, ActiveOverlay, NULL },
91
- { "i", false, false, false, ActiveOverlay, NULL },
92
- { "iframe", true, false, false, ActiveOverlay, NULL },
93
- { "img", true, false, false, ActiveOverlay, NULL },
94
- { "input", true, false, false, ActiveOverlay, NULL }, // somewhere under a form_0
95
- { "ins", false, false, false, ActiveOverlay, NULL },
96
- { "kbd", false, false, false, ActiveOverlay, NULL },
97
- { "keygen", true, false, false, ActiveOverlay, NULL },
98
- { "label", false, false, false, ActiveOverlay, NULL }, // somewhere under a form_0
99
- { "legend", false, false, false, ActiveOverlay, fieldset_0 },
100
- { "li", false, false, false, ActiveOverlay, ol_ul_menu_0 },
101
- { "link", true, false, false, ActiveOverlay, head_0 },
102
- { "map", false, false, false, ActiveOverlay, NULL },
103
- { "mark", false, false, false, ActiveOverlay, NULL },
104
- { "menu", false, false, false, ActiveOverlay, NULL },
105
- { "meta", true, false, false, ActiveOverlay, head_0 },
106
- { "meter", false, false, false, ActiveOverlay, NULL },
107
- { "nav", false, false, false, ActiveOverlay, NULL },
108
- { "noframes", false, false, false, ActiveOverlay, NULL },
109
- { "noscript", false, false, false, ActiveOverlay, NULL },
110
- { "object", false, false, false, ActiveOverlay, NULL },
111
- { "ol", false, true, false, ActiveOverlay, NULL },
112
- { "optgroup", false, false, false, ActiveOverlay, NULL },
113
- { "option", false, false, false, ActiveOverlay, optgroup_select_datalist_0 },
114
- { "output", false, false, false, ActiveOverlay, NULL },
115
- { "p", false, false, false, ActiveOverlay, NULL },
116
- { "param", true, false, false, ActiveOverlay, NULL },
117
- { "pre", false, false, false, ActiveOverlay, NULL },
118
- { "progress", false, false, false, ActiveOverlay, NULL },
119
- { "q", false, false, false, ActiveOverlay, NULL },
120
- { "rp", false, false, false, ActiveOverlay, ruby_0 },
121
- { "rt", false, false, false, ActiveOverlay, ruby_0 },
122
- { "ruby", false, false, false, ActiveOverlay, NULL },
123
- { "s", false, false, false, ActiveOverlay, NULL },
124
- { "samp", false, false, false, ActiveOverlay, NULL },
125
- { "script", false, false, true, ActiveOverlay, NULL },
126
- { "section", false, true, false, ActiveOverlay, NULL },
127
- { "select", false, false, false, ActiveOverlay, NULL },
128
- { "small", false, false, false, ActiveOverlay, NULL },
129
- { "source", false, false, false, ActiveOverlay, audio_video_0 },
130
- { "span", false, true, false, ActiveOverlay, NULL },
131
- { "strike", false, false, false, ActiveOverlay, NULL },
132
- { "strong", false, false, false, ActiveOverlay, NULL },
133
- { "style", false, false, false, ActiveOverlay, NULL },
134
- { "sub", false, false, false, ActiveOverlay, NULL },
135
- { "summary", false, false, false, ActiveOverlay, details_0 },
136
- { "sup", false, false, false, ActiveOverlay, NULL },
137
- { "table", false, false, false, ActiveOverlay, NULL },
138
- { "tbody", false, false, false, ActiveOverlay, table_0 },
139
- { "td", false, false, false, ActiveOverlay, tr_0 },
140
- { "textarea", false, false, false, ActiveOverlay, NULL },
141
- { "tfoot", false, false, false, ActiveOverlay, table_0 },
142
- { "th", false, false, false, ActiveOverlay, tr_0 },
143
- { "thead", false, false, false, ActiveOverlay, table_0 },
144
- { "time", false, false, false, ActiveOverlay, NULL },
145
- { "title", false, false, false, ActiveOverlay, head_0 },
146
- { "tr", false, false, false, ActiveOverlay, table_0 },
147
- { "track", true, false, false, ActiveOverlay, audio_video_0 },
148
- { "tt", false, false, false, ActiveOverlay, NULL },
149
- { "u", false, false, false, ActiveOverlay, NULL },
150
- { "ul", false, false, false, ActiveOverlay, NULL },
151
- { "var", false, false, false, ActiveOverlay, NULL },
152
- { "video", false, false, false, ActiveOverlay, NULL },
153
- { "wbr", true, false, false, ActiveOverlay, NULL },
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
- ox_hints_dup(Hints h) {
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
- xfree(h->hints);
182
- xfree(h);
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
- Hint lo = hints->hints;
190
- Hint hi = hints->hints + hints->size - 1;
191
- Hint mid;
192
- int res;
180
+ Hint lo = hints->hints;
181
+ Hint hi = hints->hints + hints->size - 1;
182
+ Hint mid;
183
+ int res;
193
184
 
194
- if (0 == (res = strcasecmp(name, lo->name))) {
195
- return lo;
196
- } else if (0 > res) {
197
- return 0;
198
- }
199
- if (0 == (res = strcasecmp(name, hi->name))) {
200
- return hi;
201
- } else if (0 < res) {
202
- return 0;
203
- }
204
- while (1 < hi - lo) {
205
- mid = lo + (hi - lo) / 2;
206
- if (0 == (res = strcasecmp(name, mid->name))) {
207
- return mid;
208
- } else if (0 < res) {
209
- lo = mid;
210
- } else {
211
- hi = mid;
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 = 0,
13
- InactiveOverlay = 'i',
14
- BlockOverlay = 'b',
15
- OffOverlay = 'o',
16
- AbortOverlay = 'a',
17
- NestOverlay = 'n', // nest flag is ignored
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 *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;
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 *name;
31
- Hint hints; // array of hints
32
- int size;
30
+ const char *name;
31
+ Hint hints; // array of hints
32
+ int size;
33
33
  } *Hints;
34
34
 
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);
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 32
15
- #define NV_BUF_MAX 64
14
+ #define STACK_INC 32
15
+ #define NV_BUF_MAX 64
16
16
 
17
17
  typedef struct _nv {
18
- char name_buf[NV_BUF_MAX];
19
- const char *name;
20
- VALUE val;
21
- int childCnt;
22
- Hint 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 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 */
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 = stack->base + sizeof(stack->base) / sizeof(struct _nv);
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
- size_t len = stack->end - stack->head;
55
- size_t toff = stack->tail - stack->head;
56
-
57
- if (stack->base == stack->head) {
58
- stack->head = ALLOC_N(struct _nv, len + STACK_INC);
59
- memcpy(stack->head, stack->base, sizeof(struct _nv) * len);
60
- } else {
61
- REALLOC_N(stack->head, struct _nv, len + STACK_INC);
62
- }
63
- stack->tail = stack->head + toff;
64
- stack->end = stack->head + len + STACK_INC;
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 = stack->tail->name_buf;
67
+ stack->tail->name = NULL;
72
68
  }
73
- stack->tail->val = val;
74
- stack->tail->hint = 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
- return stack->tail - 1;
77
+ return stack->tail - 1;
83
78
  }
84
- return 0;
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
- stack->tail--;
91
- if (stack->tail->name != stack->tail->name_buf) {
92
- free((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
- return stack->tail;
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 { /* not exact match but on the path */
86
- if (0 != cache->key) { /* there is a key/value here already */
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;
data/ext/ox/slotcache.h CHANGED
@@ -8,12 +8,12 @@
8
8
 
9
9
  #include "ruby.h"
10
10
 
11
- typedef struct _slotCache *SlotCache;
11
+ typedef struct _slotCache *SlotCache;
12
12
 
13
- extern void slot_cache_new(SlotCache *cache);
13
+ extern void slot_cache_new(SlotCache *cache);
14
14
 
15
- extern VALUE slot_cache_get(SlotCache cache, const char *key, VALUE **slot, const char **keyp);
15
+ extern VALUE slot_cache_get(SlotCache cache, const char *key, VALUE **slot, const char **keyp);
16
16
 
17
- extern void slot_cache_print(SlotCache cache);
17
+ extern void slot_cache_print(SlotCache cache);
18
18
 
19
19
  #endif /* SLOT_CACHE_H */