nokogiri 1.13.8 → 1.15.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +40 -0
- data/LICENSE-DEPENDENCIES.md +830 -509
- data/LICENSE.md +1 -1
- data/README.md +18 -11
- data/dependencies.yml +33 -15
- data/ext/nokogiri/extconf.rb +164 -46
- data/ext/nokogiri/gumbo.c +20 -10
- data/ext/nokogiri/html4_document.c +3 -4
- data/ext/nokogiri/html4_element_description.c +20 -15
- data/ext/nokogiri/html4_entity_lookup.c +2 -2
- data/ext/nokogiri/html4_sax_parser_context.c +11 -22
- data/ext/nokogiri/html4_sax_push_parser.c +3 -3
- data/ext/nokogiri/nokogiri.c +84 -75
- data/ext/nokogiri/nokogiri.h +31 -16
- data/ext/nokogiri/test_global_handlers.c +1 -1
- data/ext/nokogiri/xml_attr.c +2 -2
- data/ext/nokogiri/xml_attribute_decl.c +2 -2
- data/ext/nokogiri/xml_cdata.c +32 -18
- data/ext/nokogiri/xml_comment.c +2 -2
- data/ext/nokogiri/xml_document.c +127 -34
- data/ext/nokogiri/xml_document_fragment.c +2 -2
- data/ext/nokogiri/xml_dtd.c +2 -2
- data/ext/nokogiri/xml_element_content.c +34 -31
- data/ext/nokogiri/xml_element_decl.c +7 -7
- data/ext/nokogiri/xml_encoding_handler.c +15 -7
- data/ext/nokogiri/xml_entity_decl.c +1 -1
- data/ext/nokogiri/xml_entity_reference.c +2 -2
- data/ext/nokogiri/xml_namespace.c +79 -14
- data/ext/nokogiri/xml_node.c +300 -34
- data/ext/nokogiri/xml_node_set.c +125 -107
- data/ext/nokogiri/xml_processing_instruction.c +2 -2
- data/ext/nokogiri/xml_reader.c +81 -48
- data/ext/nokogiri/xml_relax_ng.c +66 -81
- data/ext/nokogiri/xml_sax_parser.c +45 -20
- data/ext/nokogiri/xml_sax_parser_context.c +46 -30
- data/ext/nokogiri/xml_sax_push_parser.c +30 -11
- data/ext/nokogiri/xml_schema.c +95 -117
- data/ext/nokogiri/xml_syntax_error.c +1 -1
- data/ext/nokogiri/xml_text.c +28 -14
- data/ext/nokogiri/xml_xpath_context.c +216 -136
- data/ext/nokogiri/xslt_stylesheet.c +118 -64
- data/gumbo-parser/Makefile +10 -0
- data/gumbo-parser/src/attribute.h +1 -1
- data/gumbo-parser/src/error.c +10 -6
- data/gumbo-parser/src/error.h +1 -1
- data/gumbo-parser/src/foreign_attrs.c +15 -16
- data/gumbo-parser/src/foreign_attrs.gperf +1 -1
- data/gumbo-parser/src/{gumbo.h → nokogiri_gumbo.h} +1 -0
- data/gumbo-parser/src/parser.c +21 -5
- data/gumbo-parser/src/replacement.h +1 -1
- data/gumbo-parser/src/string_buffer.h +1 -1
- data/gumbo-parser/src/string_piece.c +1 -1
- data/gumbo-parser/src/svg_attrs.c +2 -2
- data/gumbo-parser/src/svg_tags.c +2 -2
- data/gumbo-parser/src/tag.c +2 -1
- data/gumbo-parser/src/tag_lookup.c +7 -7
- data/gumbo-parser/src/tag_lookup.gperf +1 -0
- data/gumbo-parser/src/tag_lookup.h +1 -1
- data/gumbo-parser/src/token_buffer.h +1 -1
- data/gumbo-parser/src/tokenizer.c +1 -1
- data/gumbo-parser/src/tokenizer.h +1 -1
- data/gumbo-parser/src/utf8.c +1 -1
- data/gumbo-parser/src/utf8.h +1 -1
- data/gumbo-parser/src/util.c +1 -3
- data/gumbo-parser/src/util.h +4 -0
- data/gumbo-parser/src/vector.h +1 -1
- data/lib/nokogiri/css/node.rb +2 -2
- data/lib/nokogiri/css/xpath_visitor.rb +7 -5
- data/lib/nokogiri/css.rb +6 -0
- data/lib/nokogiri/decorators/slop.rb +1 -1
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +4 -3
- data/lib/nokogiri/html4/document.rb +2 -121
- data/lib/nokogiri/html4/document_fragment.rb +1 -1
- data/lib/nokogiri/html4/element_description_defaults.rb +1827 -365
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/html4.rb +1 -0
- data/lib/nokogiri/html5/document.rb +113 -36
- data/lib/nokogiri/html5/document_fragment.rb +10 -3
- data/lib/nokogiri/html5/node.rb +8 -5
- data/lib/nokogiri/html5.rb +130 -216
- data/lib/nokogiri/jruby/dependencies.rb +1 -19
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +11 -10
- data/lib/nokogiri/xml/attr.rb +49 -0
- data/lib/nokogiri/xml/attribute_decl.rb +4 -2
- data/lib/nokogiri/xml/builder.rb +1 -1
- data/lib/nokogiri/xml/document.rb +102 -55
- data/lib/nokogiri/xml/document_fragment.rb +50 -7
- data/lib/nokogiri/xml/element_content.rb +10 -2
- data/lib/nokogiri/xml/element_decl.rb +4 -2
- data/lib/nokogiri/xml/entity_decl.rb +4 -2
- data/lib/nokogiri/xml/namespace.rb +42 -0
- data/lib/nokogiri/xml/node/save_options.rb +14 -4
- data/lib/nokogiri/xml/node.rb +212 -48
- data/lib/nokogiri/xml/node_set.rb +88 -9
- data/lib/nokogiri/xml/parse_options.rb +129 -50
- data/lib/nokogiri/xml/pp/node.rb +28 -15
- data/lib/nokogiri/xml/processing_instruction.rb +2 -1
- data/lib/nokogiri/xml/sax/document.rb +1 -1
- data/lib/nokogiri/xml/sax/parser.rb +2 -3
- data/lib/nokogiri/xml/searchable.rb +18 -10
- data/lib/nokogiri/xslt.rb +74 -4
- data/lib/nokogiri.rb +15 -15
- data/lib/xsd/xmlparser/nokogiri.rb +4 -2
- data/patches/libxml2/0010-update-config.guess-and-config.sub-for-libxml2.patch +224 -0
- data/patches/libxml2/0011-rip-out-libxml2-s-libc_single_threaded-support.patch +30 -0
- data/patches/libxslt/0001-update-config.guess-and-config.sub-for-libxslt.patch +224 -0
- data/ports/archives/libxml2-2.11.7.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.39.tar.xz +0 -0
- metadata +19 -242
- data/patches/libxml2/0004-use-glibc-strlen.patch +0 -53
- data/patches/libxml2/0005-avoid-isnan-isinf.patch +0 -81
- data/patches/libxml2/0006-update-automake-files-for-arm64.patch +0 -3040
- data/patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch +0 -61
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +0 -3037
- data/ports/archives/libxml2-2.9.14.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.35.tar.xz +0 -0
data/ext/nokogiri/xml_node_set.c
CHANGED
@@ -39,8 +39,9 @@ ruby_object_get(xmlNodePtr c_node)
|
|
39
39
|
|
40
40
|
|
41
41
|
static void
|
42
|
-
|
42
|
+
xml_node_set_mark(void *data)
|
43
43
|
{
|
44
|
+
xmlNodeSetPtr node_set = data;
|
44
45
|
VALUE rb_node;
|
45
46
|
int jnode;
|
46
47
|
|
@@ -52,6 +53,37 @@ mark(xmlNodeSetPtr node_set)
|
|
52
53
|
}
|
53
54
|
}
|
54
55
|
|
56
|
+
static void
|
57
|
+
xml_node_set_deallocate(void *data)
|
58
|
+
{
|
59
|
+
xmlNodeSetPtr node_set = data;
|
60
|
+
/*
|
61
|
+
* For reasons outlined in xml_namespace.c, here we reproduce xmlXPathFreeNodeSet() except for the
|
62
|
+
* offending call to xmlXPathNodeSetFreeNs().
|
63
|
+
*/
|
64
|
+
if (node_set->nodeTab != NULL) {
|
65
|
+
xmlFree(node_set->nodeTab);
|
66
|
+
}
|
67
|
+
|
68
|
+
xmlFree(node_set);
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
static VALUE
|
73
|
+
xml_node_set_allocate(VALUE klass)
|
74
|
+
{
|
75
|
+
return noko_xml_node_set_wrap(xmlXPathNodeSetCreate(NULL), Qnil);
|
76
|
+
}
|
77
|
+
|
78
|
+
static const rb_data_type_t xml_node_set_type = {
|
79
|
+
.wrap_struct_name = "Nokogiri::XML::NodeSet",
|
80
|
+
.function = {
|
81
|
+
.dmark = xml_node_set_mark,
|
82
|
+
.dfree = xml_node_set_deallocate,
|
83
|
+
},
|
84
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
85
|
+
};
|
86
|
+
|
55
87
|
static void
|
56
88
|
xpath_node_set_del(xmlNodeSetPtr cur, xmlNodePtr val)
|
57
89
|
{
|
@@ -81,30 +113,6 @@ xpath_node_set_del(xmlNodeSetPtr cur, xmlNodePtr val)
|
|
81
113
|
}
|
82
114
|
|
83
115
|
|
84
|
-
static void
|
85
|
-
deallocate(xmlNodeSetPtr node_set)
|
86
|
-
{
|
87
|
-
/*
|
88
|
-
* For reasons outlined in xml_namespace.c, here we reproduce xmlXPathFreeNodeSet() except for the
|
89
|
-
* offending call to xmlXPathNodeSetFreeNs().
|
90
|
-
*/
|
91
|
-
NOKOGIRI_DEBUG_START(node_set) ;
|
92
|
-
if (node_set->nodeTab != NULL) {
|
93
|
-
xmlFree(node_set->nodeTab);
|
94
|
-
}
|
95
|
-
|
96
|
-
xmlFree(node_set);
|
97
|
-
NOKOGIRI_DEBUG_END(node_set) ;
|
98
|
-
}
|
99
|
-
|
100
|
-
|
101
|
-
static VALUE
|
102
|
-
allocate(VALUE klass)
|
103
|
-
{
|
104
|
-
return noko_xml_node_set_wrap(xmlXPathNodeSetCreate(NULL), Qnil);
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
116
|
/*
|
109
117
|
* call-seq:
|
110
118
|
* dup
|
@@ -113,16 +121,16 @@ allocate(VALUE klass)
|
|
113
121
|
* duplicated (similar to how Array and other Enumerable classes work).
|
114
122
|
*/
|
115
123
|
static VALUE
|
116
|
-
duplicate(VALUE
|
124
|
+
duplicate(VALUE rb_self)
|
117
125
|
{
|
118
|
-
xmlNodeSetPtr
|
126
|
+
xmlNodeSetPtr c_self;
|
119
127
|
xmlNodeSetPtr dupl;
|
120
128
|
|
121
|
-
|
129
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
122
130
|
|
123
|
-
dupl = xmlXPathNodeSetMerge(NULL,
|
131
|
+
dupl = xmlXPathNodeSetMerge(NULL, c_self);
|
124
132
|
|
125
|
-
return noko_xml_node_set_wrap(dupl, rb_iv_get(
|
133
|
+
return noko_xml_node_set_wrap(dupl, rb_iv_get(rb_self, "@document"));
|
126
134
|
}
|
127
135
|
|
128
136
|
/*
|
@@ -132,13 +140,13 @@ duplicate(VALUE self)
|
|
132
140
|
* Get the length of the node set
|
133
141
|
*/
|
134
142
|
static VALUE
|
135
|
-
length(VALUE
|
143
|
+
length(VALUE rb_self)
|
136
144
|
{
|
137
|
-
xmlNodeSetPtr
|
145
|
+
xmlNodeSetPtr c_self;
|
138
146
|
|
139
|
-
|
147
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
140
148
|
|
141
|
-
return
|
149
|
+
return c_self ? INT2NUM(c_self->nodeNr) : INT2NUM(0);
|
142
150
|
}
|
143
151
|
|
144
152
|
/*
|
@@ -148,19 +156,19 @@ length(VALUE self)
|
|
148
156
|
* Append +node+ to the NodeSet.
|
149
157
|
*/
|
150
158
|
static VALUE
|
151
|
-
push(VALUE
|
159
|
+
push(VALUE rb_self, VALUE rb_node)
|
152
160
|
{
|
153
|
-
xmlNodeSetPtr
|
161
|
+
xmlNodeSetPtr c_self;
|
154
162
|
xmlNodePtr node;
|
155
163
|
|
156
164
|
Check_Node_Set_Node_Type(rb_node);
|
157
165
|
|
158
|
-
|
166
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
159
167
|
Noko_Node_Get_Struct(rb_node, xmlNode, node);
|
160
168
|
|
161
|
-
xmlXPathNodeSetAdd(
|
169
|
+
xmlXPathNodeSetAdd(c_self, node);
|
162
170
|
|
163
|
-
return
|
171
|
+
return rb_self;
|
164
172
|
}
|
165
173
|
|
166
174
|
/*
|
@@ -171,18 +179,18 @@ push(VALUE self, VALUE rb_node)
|
|
171
179
|
* if found, otherwise returns nil.
|
172
180
|
*/
|
173
181
|
static VALUE
|
174
|
-
delete (VALUE
|
182
|
+
delete (VALUE rb_self, VALUE rb_node)
|
175
183
|
{
|
176
|
-
xmlNodeSetPtr
|
184
|
+
xmlNodeSetPtr c_self;
|
177
185
|
xmlNodePtr node;
|
178
186
|
|
179
187
|
Check_Node_Set_Node_Type(rb_node);
|
180
188
|
|
181
|
-
|
189
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
182
190
|
Noko_Node_Get_Struct(rb_node, xmlNode, node);
|
183
191
|
|
184
|
-
if (xmlXPathNodeSetContains(
|
185
|
-
xpath_node_set_del(
|
192
|
+
if (xmlXPathNodeSetContains(c_self, node)) {
|
193
|
+
xpath_node_set_del(c_self, node);
|
186
194
|
return rb_node;
|
187
195
|
}
|
188
196
|
return Qnil ;
|
@@ -196,20 +204,20 @@ delete (VALUE self, VALUE rb_node)
|
|
196
204
|
* Set Intersection — Returns a new NodeSet containing nodes common to the two NodeSets.
|
197
205
|
*/
|
198
206
|
static VALUE
|
199
|
-
intersection(VALUE
|
207
|
+
intersection(VALUE rb_self, VALUE rb_other)
|
200
208
|
{
|
201
|
-
xmlNodeSetPtr
|
209
|
+
xmlNodeSetPtr c_self, c_other ;
|
202
210
|
xmlNodeSetPtr intersection;
|
203
211
|
|
204
212
|
if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet)) {
|
205
213
|
rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
|
206
214
|
}
|
207
215
|
|
208
|
-
|
209
|
-
|
216
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
217
|
+
TypedData_Get_Struct(rb_other, xmlNodeSet, &xml_node_set_type, c_other);
|
210
218
|
|
211
|
-
intersection = xmlXPathIntersection(
|
212
|
-
return noko_xml_node_set_wrap(intersection, rb_iv_get(
|
219
|
+
intersection = xmlXPathIntersection(c_self, c_other);
|
220
|
+
return noko_xml_node_set_wrap(intersection, rb_iv_get(rb_self, "@document"));
|
213
221
|
}
|
214
222
|
|
215
223
|
|
@@ -220,17 +228,17 @@ intersection(VALUE self, VALUE rb_other)
|
|
220
228
|
* Returns true if any member of node set equals +node+.
|
221
229
|
*/
|
222
230
|
static VALUE
|
223
|
-
include_eh(VALUE
|
231
|
+
include_eh(VALUE rb_self, VALUE rb_node)
|
224
232
|
{
|
225
|
-
xmlNodeSetPtr
|
233
|
+
xmlNodeSetPtr c_self;
|
226
234
|
xmlNodePtr node;
|
227
235
|
|
228
236
|
Check_Node_Set_Node_Type(rb_node);
|
229
237
|
|
230
|
-
|
238
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
231
239
|
Noko_Node_Get_Struct(rb_node, xmlNode, node);
|
232
240
|
|
233
|
-
return (xmlXPathNodeSetContains(
|
241
|
+
return (xmlXPathNodeSetContains(c_self, node) ? Qtrue : Qfalse);
|
234
242
|
}
|
235
243
|
|
236
244
|
|
@@ -242,22 +250,22 @@ include_eh(VALUE self, VALUE rb_node)
|
|
242
250
|
* set.
|
243
251
|
*/
|
244
252
|
static VALUE
|
245
|
-
rb_xml_node_set_union(VALUE
|
253
|
+
rb_xml_node_set_union(VALUE rb_self, VALUE rb_other)
|
246
254
|
{
|
247
|
-
xmlNodeSetPtr
|
255
|
+
xmlNodeSetPtr c_self, c_other;
|
248
256
|
xmlNodeSetPtr c_new_node_set;
|
249
257
|
|
250
258
|
if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet)) {
|
251
259
|
rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
|
252
260
|
}
|
253
261
|
|
254
|
-
|
255
|
-
|
262
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
263
|
+
TypedData_Get_Struct(rb_other, xmlNodeSet, &xml_node_set_type, c_other);
|
256
264
|
|
257
|
-
c_new_node_set = xmlXPathNodeSetMerge(NULL,
|
265
|
+
c_new_node_set = xmlXPathNodeSetMerge(NULL, c_self);
|
258
266
|
c_new_node_set = xmlXPathNodeSetMerge(c_new_node_set, c_other);
|
259
267
|
|
260
|
-
return noko_xml_node_set_wrap(c_new_node_set, rb_iv_get(
|
268
|
+
return noko_xml_node_set_wrap(c_new_node_set, rb_iv_get(rb_self, "@document"));
|
261
269
|
}
|
262
270
|
|
263
271
|
/*
|
@@ -268,9 +276,9 @@ rb_xml_node_set_union(VALUE rb_node_set, VALUE rb_other)
|
|
268
276
|
* each item that also appears in +node_set+
|
269
277
|
*/
|
270
278
|
static VALUE
|
271
|
-
minus(VALUE
|
279
|
+
minus(VALUE rb_self, VALUE rb_other)
|
272
280
|
{
|
273
|
-
xmlNodeSetPtr
|
281
|
+
xmlNodeSetPtr c_self, c_other;
|
274
282
|
xmlNodeSetPtr new;
|
275
283
|
int j ;
|
276
284
|
|
@@ -278,55 +286,55 @@ minus(VALUE self, VALUE rb_other)
|
|
278
286
|
rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
|
279
287
|
}
|
280
288
|
|
281
|
-
|
282
|
-
|
289
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
290
|
+
TypedData_Get_Struct(rb_other, xmlNodeSet, &xml_node_set_type, c_other);
|
283
291
|
|
284
|
-
new = xmlXPathNodeSetMerge(NULL,
|
285
|
-
for (j = 0 ; j <
|
286
|
-
xpath_node_set_del(new,
|
292
|
+
new = xmlXPathNodeSetMerge(NULL, c_self);
|
293
|
+
for (j = 0 ; j < c_other->nodeNr ; ++j) {
|
294
|
+
xpath_node_set_del(new, c_other->nodeTab[j]);
|
287
295
|
}
|
288
296
|
|
289
|
-
return noko_xml_node_set_wrap(new, rb_iv_get(
|
297
|
+
return noko_xml_node_set_wrap(new, rb_iv_get(rb_self, "@document"));
|
290
298
|
}
|
291
299
|
|
292
300
|
|
293
301
|
static VALUE
|
294
|
-
index_at(VALUE
|
302
|
+
index_at(VALUE rb_self, long offset)
|
295
303
|
{
|
296
|
-
xmlNodeSetPtr
|
304
|
+
xmlNodeSetPtr c_self;
|
297
305
|
|
298
|
-
|
306
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
299
307
|
|
300
|
-
if (offset >=
|
308
|
+
if (offset >= c_self->nodeNr || abs((int)offset) > c_self->nodeNr) {
|
301
309
|
return Qnil;
|
302
310
|
}
|
303
311
|
|
304
|
-
if (offset < 0) { offset +=
|
312
|
+
if (offset < 0) { offset += c_self->nodeNr ; }
|
305
313
|
|
306
|
-
return noko_xml_node_wrap_node_set_result(
|
314
|
+
return noko_xml_node_wrap_node_set_result(c_self->nodeTab[offset], rb_self);
|
307
315
|
}
|
308
316
|
|
309
317
|
static VALUE
|
310
|
-
subseq(VALUE
|
318
|
+
subseq(VALUE rb_self, long beg, long len)
|
311
319
|
{
|
312
320
|
long j;
|
313
|
-
xmlNodeSetPtr
|
321
|
+
xmlNodeSetPtr c_self;
|
314
322
|
xmlNodeSetPtr new_set ;
|
315
323
|
|
316
|
-
|
324
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
317
325
|
|
318
|
-
if (beg >
|
326
|
+
if (beg > c_self->nodeNr) { return Qnil ; }
|
319
327
|
if (beg < 0 || len < 0) { return Qnil ; }
|
320
328
|
|
321
|
-
if ((beg + len) >
|
322
|
-
len =
|
329
|
+
if ((beg + len) > c_self->nodeNr) {
|
330
|
+
len = c_self->nodeNr - beg ;
|
323
331
|
}
|
324
332
|
|
325
333
|
new_set = xmlXPathNodeSetCreate(NULL);
|
326
334
|
for (j = beg ; j < beg + len ; ++j) {
|
327
|
-
xmlXPathNodeSetAddUnique(new_set,
|
335
|
+
xmlXPathNodeSetAddUnique(new_set, c_self->nodeTab[j]);
|
328
336
|
}
|
329
|
-
return noko_xml_node_set_wrap(new_set, rb_iv_get(
|
337
|
+
return noko_xml_node_set_wrap(new_set, rb_iv_get(rb_self, "@document"));
|
330
338
|
}
|
331
339
|
|
332
340
|
/*
|
@@ -345,21 +353,21 @@ subseq(VALUE self, long beg, long len)
|
|
345
353
|
* nil if the +index+ (or +start+) are out of range.
|
346
354
|
*/
|
347
355
|
static VALUE
|
348
|
-
slice(int argc, VALUE *argv, VALUE
|
356
|
+
slice(int argc, VALUE *argv, VALUE rb_self)
|
349
357
|
{
|
350
358
|
VALUE arg ;
|
351
359
|
long beg, len ;
|
352
|
-
xmlNodeSetPtr
|
360
|
+
xmlNodeSetPtr c_self;
|
353
361
|
|
354
|
-
|
362
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
355
363
|
|
356
364
|
if (argc == 2) {
|
357
365
|
beg = NUM2LONG(argv[0]);
|
358
366
|
len = NUM2LONG(argv[1]);
|
359
367
|
if (beg < 0) {
|
360
|
-
beg +=
|
368
|
+
beg += c_self->nodeNr ;
|
361
369
|
}
|
362
|
-
return subseq(
|
370
|
+
return subseq(rb_self, beg, len);
|
363
371
|
}
|
364
372
|
|
365
373
|
if (argc != 1) {
|
@@ -368,20 +376,20 @@ slice(int argc, VALUE *argv, VALUE self)
|
|
368
376
|
arg = argv[0];
|
369
377
|
|
370
378
|
if (FIXNUM_P(arg)) {
|
371
|
-
return index_at(
|
379
|
+
return index_at(rb_self, FIX2LONG(arg));
|
372
380
|
}
|
373
381
|
|
374
382
|
/* if arg is Range */
|
375
|
-
switch (rb_range_beg_len(arg, &beg, &len, (long)
|
383
|
+
switch (rb_range_beg_len(arg, &beg, &len, (long)c_self->nodeNr, 0)) {
|
376
384
|
case Qfalse:
|
377
385
|
break;
|
378
386
|
case Qnil:
|
379
387
|
return Qnil;
|
380
388
|
default:
|
381
|
-
return subseq(
|
389
|
+
return subseq(rb_self, beg, len);
|
382
390
|
}
|
383
391
|
|
384
|
-
return index_at(
|
392
|
+
return index_at(rb_self, NUM2LONG(arg));
|
385
393
|
}
|
386
394
|
|
387
395
|
|
@@ -392,17 +400,17 @@ slice(int argc, VALUE *argv, VALUE self)
|
|
392
400
|
* Return this list as an Array
|
393
401
|
*/
|
394
402
|
static VALUE
|
395
|
-
to_array(VALUE
|
403
|
+
to_array(VALUE rb_self)
|
396
404
|
{
|
397
|
-
xmlNodeSetPtr
|
405
|
+
xmlNodeSetPtr c_self ;
|
398
406
|
VALUE list;
|
399
407
|
int i;
|
400
408
|
|
401
|
-
|
409
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
402
410
|
|
403
|
-
list = rb_ary_new2(
|
404
|
-
for (i = 0; i <
|
405
|
-
VALUE elt = noko_xml_node_wrap_node_set_result(
|
411
|
+
list = rb_ary_new2(c_self->nodeNr);
|
412
|
+
for (i = 0; i < c_self->nodeNr; i++) {
|
413
|
+
VALUE elt = noko_xml_node_wrap_node_set_result(c_self->nodeTab[i], rb_self);
|
406
414
|
rb_ary_push(list, elt);
|
407
415
|
}
|
408
416
|
|
@@ -416,25 +424,25 @@ to_array(VALUE self)
|
|
416
424
|
* Unlink this NodeSet and all Node objects it contains from their current context.
|
417
425
|
*/
|
418
426
|
static VALUE
|
419
|
-
unlink_nodeset(VALUE
|
427
|
+
unlink_nodeset(VALUE rb_self)
|
420
428
|
{
|
421
|
-
xmlNodeSetPtr
|
429
|
+
xmlNodeSetPtr c_self;
|
422
430
|
int j, nodeNr ;
|
423
431
|
|
424
|
-
|
432
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
425
433
|
|
426
|
-
nodeNr =
|
434
|
+
nodeNr = c_self->nodeNr ;
|
427
435
|
for (j = 0 ; j < nodeNr ; j++) {
|
428
|
-
if (! NOKOGIRI_NAMESPACE_EH(
|
436
|
+
if (! NOKOGIRI_NAMESPACE_EH(c_self->nodeTab[j])) {
|
429
437
|
VALUE node ;
|
430
438
|
xmlNodePtr node_ptr;
|
431
|
-
node = noko_xml_node_wrap(Qnil,
|
439
|
+
node = noko_xml_node_wrap(Qnil, c_self->nodeTab[j]);
|
432
440
|
rb_funcall(node, rb_intern("unlink"), 0); /* modifies the C struct out from under the object */
|
433
441
|
Noko_Node_Get_Struct(node, xmlNode, node_ptr);
|
434
|
-
|
442
|
+
c_self->nodeTab[j] = node_ptr ;
|
435
443
|
}
|
436
444
|
}
|
437
|
-
return
|
445
|
+
return rb_self ;
|
438
446
|
}
|
439
447
|
|
440
448
|
|
@@ -448,7 +456,7 @@ noko_xml_node_set_wrap(xmlNodeSetPtr c_node_set, VALUE document)
|
|
448
456
|
c_node_set = xmlXPathNodeSetCreate(NULL);
|
449
457
|
}
|
450
458
|
|
451
|
-
rb_node_set =
|
459
|
+
rb_node_set = TypedData_Wrap_Struct(cNokogiriXmlNodeSet, &xml_node_set_type, c_node_set);
|
452
460
|
|
453
461
|
if (!NIL_P(document)) {
|
454
462
|
rb_iv_set(rb_node_set, "@document", document);
|
@@ -463,6 +471,7 @@ noko_xml_node_set_wrap(xmlNodeSetPtr c_node_set, VALUE document)
|
|
463
471
|
return rb_node_set ;
|
464
472
|
}
|
465
473
|
|
474
|
+
|
466
475
|
VALUE
|
467
476
|
noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set)
|
468
477
|
{
|
@@ -474,12 +483,21 @@ noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set)
|
|
474
483
|
}
|
475
484
|
|
476
485
|
|
486
|
+
xmlNodeSetPtr
|
487
|
+
noko_xml_node_set_unwrap(VALUE rb_node_set)
|
488
|
+
{
|
489
|
+
xmlNodeSetPtr c_node_set;
|
490
|
+
TypedData_Get_Struct(rb_node_set, xmlNodeSet, &xml_node_set_type, c_node_set);
|
491
|
+
return c_node_set;
|
492
|
+
}
|
493
|
+
|
494
|
+
|
477
495
|
void
|
478
496
|
noko_init_xml_node_set(void)
|
479
497
|
{
|
480
498
|
cNokogiriXmlNodeSet = rb_define_class_under(mNokogiriXml, "NodeSet", rb_cObject);
|
481
499
|
|
482
|
-
rb_define_alloc_func(cNokogiriXmlNodeSet,
|
500
|
+
rb_define_alloc_func(cNokogiriXmlNodeSet, xml_node_set_allocate);
|
483
501
|
|
484
502
|
rb_define_method(cNokogiriXmlNodeSet, "length", length, 0);
|
485
503
|
rb_define_method(cNokogiriXmlNodeSet, "[]", slice, -1);
|
@@ -22,7 +22,7 @@ new (int argc, VALUE *argv, VALUE klass)
|
|
22
22
|
|
23
23
|
rb_scan_args(argc, argv, "3*", &document, &name, &content, &rest);
|
24
24
|
|
25
|
-
|
25
|
+
xml_doc = noko_xml_document_unwrap(document);
|
26
26
|
|
27
27
|
node = xmlNewDocPI(
|
28
28
|
xml_doc,
|
@@ -41,7 +41,7 @@ new (int argc, VALUE *argv, VALUE klass)
|
|
41
41
|
}
|
42
42
|
|
43
43
|
void
|
44
|
-
noko_init_xml_processing_instruction()
|
44
|
+
noko_init_xml_processing_instruction(void)
|
45
45
|
{
|
46
46
|
assert(cNokogiriXmlNode);
|
47
47
|
/*
|