nokogiri 1.14.2 → 1.16.6
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 +19 -15
- data/README.md +4 -1
- data/dependencies.yml +9 -8
- data/ext/nokogiri/extconf.rb +69 -26
- data/ext/nokogiri/html4_document.c +1 -2
- data/ext/nokogiri/html4_element_description.c +19 -14
- data/ext/nokogiri/html4_sax_parser_context.c +10 -16
- data/ext/nokogiri/html4_sax_push_parser.c +3 -3
- data/ext/nokogiri/nokogiri.c +46 -24
- data/ext/nokogiri/nokogiri.h +23 -5
- data/ext/nokogiri/test_global_handlers.c +1 -1
- data/ext/nokogiri/xml_attr.c +1 -1
- data/ext/nokogiri/xml_cdata.c +30 -17
- data/ext/nokogiri/xml_comment.c +1 -1
- data/ext/nokogiri/xml_document.c +113 -25
- data/ext/nokogiri/xml_document_fragment.c +1 -1
- data/ext/nokogiri/xml_dtd.c +1 -1
- data/ext/nokogiri/xml_element_content.c +32 -29
- data/ext/nokogiri/xml_element_decl.c +5 -5
- data/ext/nokogiri/xml_encoding_handler.c +12 -4
- data/ext/nokogiri/xml_entity_reference.c +1 -1
- data/ext/nokogiri/xml_namespace.c +11 -16
- data/ext/nokogiri/xml_node.c +13 -16
- data/ext/nokogiri/xml_node_set.c +125 -105
- data/ext/nokogiri/xml_processing_instruction.c +1 -1
- data/ext/nokogiri/xml_reader.c +61 -74
- data/ext/nokogiri/xml_relax_ng.c +66 -79
- data/ext/nokogiri/xml_sax_parser.c +24 -5
- data/ext/nokogiri/xml_sax_parser_context.c +50 -25
- data/ext/nokogiri/xml_sax_push_parser.c +30 -9
- data/ext/nokogiri/xml_schema.c +94 -115
- data/ext/nokogiri/xml_syntax_error.c +3 -3
- data/ext/nokogiri/xml_text.c +26 -13
- data/ext/nokogiri/xml_xpath_context.c +153 -83
- data/ext/nokogiri/xslt_stylesheet.c +111 -53
- data/gumbo-parser/Makefile +18 -0
- data/gumbo-parser/src/error.c +8 -4
- data/gumbo-parser/src/foreign_attrs.c +13 -14
- data/gumbo-parser/src/foreign_attrs.gperf +1 -1
- data/gumbo-parser/src/parser.c +21 -5
- data/gumbo-parser/src/tokenizer.c +1 -0
- data/lib/nokogiri/css/parser_extras.rb +1 -1
- data/lib/nokogiri/css/xpath_visitor.rb +3 -23
- data/lib/nokogiri/extension.rb +1 -1
- data/lib/nokogiri/html4/document.rb +1 -1
- data/lib/nokogiri/html4/document_fragment.rb +1 -1
- data/lib/nokogiri/html4/element_description_defaults.rb +1821 -353
- data/lib/nokogiri/html4/encoding_reader.rb +1 -1
- data/lib/nokogiri/html5/document_fragment.rb +1 -1
- data/lib/nokogiri/html5/node.rb +5 -0
- data/lib/nokogiri/html5.rb +0 -63
- data/lib/nokogiri/jruby/nokogiri_jars.rb +9 -9
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +6 -5
- data/lib/nokogiri/xml/attr.rb +2 -2
- data/lib/nokogiri/xml/attribute_decl.rb +4 -2
- data/lib/nokogiri/xml/document.rb +4 -5
- data/lib/nokogiri/xml/document_fragment.rb +3 -3
- 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 +1 -2
- data/lib/nokogiri/xml/node/save_options.rb +8 -0
- data/lib/nokogiri/xml/node.rb +53 -37
- data/lib/nokogiri/xml/node_set.rb +3 -3
- data/lib/nokogiri/xml/pp/node.rb +23 -12
- data/lib/nokogiri/xml/reader.rb +10 -9
- data/lib/nokogiri/xml/sax/document.rb +1 -1
- data/lib/nokogiri/xml/searchable.rb +21 -13
- data/lib/nokogiri/xml/syntax_error.rb +1 -1
- data/lib/nokogiri/xml.rb +1 -1
- data/lib/nokogiri/xslt/stylesheet.rb +29 -7
- data/lib/nokogiri/xslt.rb +74 -4
- data/lib/nokogiri.rb +13 -5
- data/lib/xsd/xmlparser/nokogiri.rb +1 -1
- 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.12.8.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.39.tar.xz +0 -0
- metadata +16 -12
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +0 -3037
- data/ports/archives/libxml2-2.10.3.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.37.tar.xz +0 -0
@@ -42,7 +42,6 @@ _xml_namespace_dealloc(void *ptr)
|
|
42
42
|
xmlFree(ns);
|
43
43
|
}
|
44
44
|
|
45
|
-
#ifdef HAVE_RB_GC_LOCATION
|
46
45
|
static void
|
47
46
|
_xml_namespace_update_references(void *ptr)
|
48
47
|
{
|
@@ -51,26 +50,22 @@ _xml_namespace_update_references(void *ptr)
|
|
51
50
|
ns->_private = (void *)rb_gc_location((VALUE)ns->_private);
|
52
51
|
}
|
53
52
|
}
|
54
|
-
#else
|
55
|
-
# define _xml_namespace_update_references 0
|
56
|
-
#endif
|
57
53
|
|
58
54
|
static const rb_data_type_t nokogiri_xml_namespace_type_with_dealloc = {
|
59
|
-
"Nokogiri
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
55
|
+
.wrap_struct_name = "Nokogiri::XML::Namespace#with_dealloc",
|
56
|
+
.function = {
|
57
|
+
.dfree = _xml_namespace_dealloc,
|
58
|
+
.dcompact = _xml_namespace_update_references,
|
59
|
+
},
|
60
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
65
61
|
};
|
66
62
|
|
67
63
|
static const rb_data_type_t nokogiri_xml_namespace_type_without_dealloc = {
|
68
|
-
"Nokogiri
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
RUBY_TYPED_FREE_IMMEDIATELY,
|
73
|
-
#endif
|
64
|
+
.wrap_struct_name = "Nokogiri::XML::Namespace#without_dealloc",
|
65
|
+
.function = {
|
66
|
+
.dcompact = _xml_namespace_update_references,
|
67
|
+
},
|
68
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
74
69
|
};
|
75
70
|
|
76
71
|
/*
|
data/ext/nokogiri/xml_node.c
CHANGED
@@ -28,7 +28,6 @@ _xml_node_mark(void *ptr)
|
|
28
28
|
}
|
29
29
|
}
|
30
30
|
|
31
|
-
#ifdef HAVE_RB_GC_LOCATION
|
32
31
|
static void
|
33
32
|
_xml_node_update_references(void *ptr)
|
34
33
|
{
|
@@ -38,17 +37,14 @@ _xml_node_update_references(void *ptr)
|
|
38
37
|
node->_private = (void *)rb_gc_location((VALUE)node->_private);
|
39
38
|
}
|
40
39
|
}
|
41
|
-
#else
|
42
|
-
# define _xml_node_update_references 0
|
43
|
-
#endif
|
44
40
|
|
45
41
|
static const rb_data_type_t nokogiri_node_type = {
|
46
|
-
"Nokogiri
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
42
|
+
.wrap_struct_name = "Nokogiri::XML::Node",
|
43
|
+
.function = {
|
44
|
+
.dmark = _xml_node_mark,
|
45
|
+
.dcompact = _xml_node_update_references,
|
46
|
+
},
|
47
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
52
48
|
};
|
53
49
|
|
54
50
|
static void
|
@@ -350,7 +346,7 @@ ok:
|
|
350
346
|
|
351
347
|
xmlUnlinkNode(original_reparentee);
|
352
348
|
|
353
|
-
if (prf != xmlAddPrevSibling && prf != xmlAddNextSibling
|
349
|
+
if (prf != xmlAddPrevSibling && prf != xmlAddNextSibling && prf != xmlAddChild
|
354
350
|
&& reparentee->type == XML_TEXT_NODE && pivot->next && pivot->next->type == XML_TEXT_NODE) {
|
355
351
|
/*
|
356
352
|
* libxml merges text nodes in a right-to-left fashion, meaning that if
|
@@ -961,7 +957,7 @@ internal_subset(VALUE self)
|
|
961
957
|
* - +new_parent_doc+
|
962
958
|
* The new node's parent Document. Defaults to the this node's document.
|
963
959
|
*
|
964
|
-
* [Returns] The new
|
960
|
+
* [Returns] The new Nokogiri::XML::Node
|
965
961
|
*/
|
966
962
|
static VALUE
|
967
963
|
duplicate_node(int argc, VALUE *argv, VALUE self)
|
@@ -984,7 +980,7 @@ duplicate_node(int argc, VALUE *argv, VALUE self)
|
|
984
980
|
if (n_args < 2) {
|
985
981
|
new_parent_doc = node->doc;
|
986
982
|
} else {
|
987
|
-
|
983
|
+
new_parent_doc = noko_xml_document_unwrap(r_new_parent_doc);
|
988
984
|
}
|
989
985
|
|
990
986
|
dup = xmlDocCopyNode(node, new_parent_doc, level);
|
@@ -2058,8 +2054,7 @@ rb_xml_node_new(int argc, VALUE *argv, VALUE klass)
|
|
2058
2054
|
rb_raise(rb_eArgError, "document must be a Nokogiri::XML::Node");
|
2059
2055
|
}
|
2060
2056
|
if (!rb_obj_is_kind_of(rb_document_node, cNokogiriXmlDocument)) {
|
2061
|
-
// TODO:
|
2062
|
-
NOKO_WARN_DEPRECATION("Passing a Node as the second parameter to Node.new is deprecated. Please pass a Document instead, or prefer an alternative constructor like Node#add_child. This will become an error in a future release of Nokogiri.");
|
2057
|
+
NOKO_WARN_DEPRECATION("Passing a Node as the second parameter to Node.new is deprecated. Please pass a Document instead, or prefer an alternative constructor like Node#add_child. This will become an error in Nokogiri v1.17.0."); // TODO: deprecated in v1.13.0, remove in v1.17.0
|
2063
2058
|
}
|
2064
2059
|
Noko_Node_Get_Struct(rb_document_node, xmlNode, c_document_node);
|
2065
2060
|
|
@@ -2138,7 +2133,7 @@ process_xincludes(VALUE self, VALUE options)
|
|
2138
2133
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
2139
2134
|
|
2140
2135
|
if (rcode < 0) {
|
2141
|
-
|
2136
|
+
xmlErrorConstPtr error;
|
2142
2137
|
|
2143
2138
|
error = xmlGetLastError();
|
2144
2139
|
if (error) {
|
@@ -2174,6 +2169,8 @@ in_context(VALUE self, VALUE _str, VALUE _options)
|
|
2174
2169
|
|
2175
2170
|
/* Twiddle global variable because of a bug in libxml2.
|
2176
2171
|
* http://git.gnome.org/browse/libxml2/commit/?id=e20fb5a72c83cbfc8e4a8aa3943c6be8febadab7
|
2172
|
+
*
|
2173
|
+
* TODO: this is fixed, and HTML_PARSE_NOIMPLIED is defined, in libxml2 2.7.7
|
2177
2174
|
*/
|
2178
2175
|
#ifndef HTML_PARSE_NOIMPLIED
|
2179
2176
|
htmlHandleOmittedElem(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,28 +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
|
-
if (node_set->nodeTab != NULL) {
|
92
|
-
xmlFree(node_set->nodeTab);
|
93
|
-
}
|
94
|
-
|
95
|
-
xmlFree(node_set);
|
96
|
-
}
|
97
|
-
|
98
|
-
|
99
|
-
static VALUE
|
100
|
-
allocate(VALUE klass)
|
101
|
-
{
|
102
|
-
return noko_xml_node_set_wrap(xmlXPathNodeSetCreate(NULL), Qnil);
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
116
|
/*
|
107
117
|
* call-seq:
|
108
118
|
* dup
|
@@ -111,16 +121,16 @@ allocate(VALUE klass)
|
|
111
121
|
* duplicated (similar to how Array and other Enumerable classes work).
|
112
122
|
*/
|
113
123
|
static VALUE
|
114
|
-
duplicate(VALUE
|
124
|
+
duplicate(VALUE rb_self)
|
115
125
|
{
|
116
|
-
xmlNodeSetPtr
|
126
|
+
xmlNodeSetPtr c_self;
|
117
127
|
xmlNodeSetPtr dupl;
|
118
128
|
|
119
|
-
|
129
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
120
130
|
|
121
|
-
dupl = xmlXPathNodeSetMerge(NULL,
|
131
|
+
dupl = xmlXPathNodeSetMerge(NULL, c_self);
|
122
132
|
|
123
|
-
return noko_xml_node_set_wrap(dupl, rb_iv_get(
|
133
|
+
return noko_xml_node_set_wrap(dupl, rb_iv_get(rb_self, "@document"));
|
124
134
|
}
|
125
135
|
|
126
136
|
/*
|
@@ -130,13 +140,13 @@ duplicate(VALUE self)
|
|
130
140
|
* Get the length of the node set
|
131
141
|
*/
|
132
142
|
static VALUE
|
133
|
-
length(VALUE
|
143
|
+
length(VALUE rb_self)
|
134
144
|
{
|
135
|
-
xmlNodeSetPtr
|
145
|
+
xmlNodeSetPtr c_self;
|
136
146
|
|
137
|
-
|
147
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
138
148
|
|
139
|
-
return
|
149
|
+
return c_self ? INT2NUM(c_self->nodeNr) : INT2NUM(0);
|
140
150
|
}
|
141
151
|
|
142
152
|
/*
|
@@ -146,19 +156,19 @@ length(VALUE self)
|
|
146
156
|
* Append +node+ to the NodeSet.
|
147
157
|
*/
|
148
158
|
static VALUE
|
149
|
-
push(VALUE
|
159
|
+
push(VALUE rb_self, VALUE rb_node)
|
150
160
|
{
|
151
|
-
xmlNodeSetPtr
|
161
|
+
xmlNodeSetPtr c_self;
|
152
162
|
xmlNodePtr node;
|
153
163
|
|
154
164
|
Check_Node_Set_Node_Type(rb_node);
|
155
165
|
|
156
|
-
|
166
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
157
167
|
Noko_Node_Get_Struct(rb_node, xmlNode, node);
|
158
168
|
|
159
|
-
xmlXPathNodeSetAdd(
|
169
|
+
xmlXPathNodeSetAdd(c_self, node);
|
160
170
|
|
161
|
-
return
|
171
|
+
return rb_self;
|
162
172
|
}
|
163
173
|
|
164
174
|
/*
|
@@ -169,18 +179,18 @@ push(VALUE self, VALUE rb_node)
|
|
169
179
|
* if found, otherwise returns nil.
|
170
180
|
*/
|
171
181
|
static VALUE
|
172
|
-
delete (VALUE
|
182
|
+
delete (VALUE rb_self, VALUE rb_node)
|
173
183
|
{
|
174
|
-
xmlNodeSetPtr
|
184
|
+
xmlNodeSetPtr c_self;
|
175
185
|
xmlNodePtr node;
|
176
186
|
|
177
187
|
Check_Node_Set_Node_Type(rb_node);
|
178
188
|
|
179
|
-
|
189
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
180
190
|
Noko_Node_Get_Struct(rb_node, xmlNode, node);
|
181
191
|
|
182
|
-
if (xmlXPathNodeSetContains(
|
183
|
-
xpath_node_set_del(
|
192
|
+
if (xmlXPathNodeSetContains(c_self, node)) {
|
193
|
+
xpath_node_set_del(c_self, node);
|
184
194
|
return rb_node;
|
185
195
|
}
|
186
196
|
return Qnil ;
|
@@ -194,20 +204,20 @@ delete (VALUE self, VALUE rb_node)
|
|
194
204
|
* Set Intersection — Returns a new NodeSet containing nodes common to the two NodeSets.
|
195
205
|
*/
|
196
206
|
static VALUE
|
197
|
-
intersection(VALUE
|
207
|
+
intersection(VALUE rb_self, VALUE rb_other)
|
198
208
|
{
|
199
|
-
xmlNodeSetPtr
|
209
|
+
xmlNodeSetPtr c_self, c_other ;
|
200
210
|
xmlNodeSetPtr intersection;
|
201
211
|
|
202
212
|
if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet)) {
|
203
213
|
rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
|
204
214
|
}
|
205
215
|
|
206
|
-
|
207
|
-
|
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);
|
208
218
|
|
209
|
-
intersection = xmlXPathIntersection(
|
210
|
-
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"));
|
211
221
|
}
|
212
222
|
|
213
223
|
|
@@ -218,17 +228,17 @@ intersection(VALUE self, VALUE rb_other)
|
|
218
228
|
* Returns true if any member of node set equals +node+.
|
219
229
|
*/
|
220
230
|
static VALUE
|
221
|
-
include_eh(VALUE
|
231
|
+
include_eh(VALUE rb_self, VALUE rb_node)
|
222
232
|
{
|
223
|
-
xmlNodeSetPtr
|
233
|
+
xmlNodeSetPtr c_self;
|
224
234
|
xmlNodePtr node;
|
225
235
|
|
226
236
|
Check_Node_Set_Node_Type(rb_node);
|
227
237
|
|
228
|
-
|
238
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
229
239
|
Noko_Node_Get_Struct(rb_node, xmlNode, node);
|
230
240
|
|
231
|
-
return (xmlXPathNodeSetContains(
|
241
|
+
return (xmlXPathNodeSetContains(c_self, node) ? Qtrue : Qfalse);
|
232
242
|
}
|
233
243
|
|
234
244
|
|
@@ -240,22 +250,22 @@ include_eh(VALUE self, VALUE rb_node)
|
|
240
250
|
* set.
|
241
251
|
*/
|
242
252
|
static VALUE
|
243
|
-
rb_xml_node_set_union(VALUE
|
253
|
+
rb_xml_node_set_union(VALUE rb_self, VALUE rb_other)
|
244
254
|
{
|
245
|
-
xmlNodeSetPtr
|
255
|
+
xmlNodeSetPtr c_self, c_other;
|
246
256
|
xmlNodeSetPtr c_new_node_set;
|
247
257
|
|
248
258
|
if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet)) {
|
249
259
|
rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
|
250
260
|
}
|
251
261
|
|
252
|
-
|
253
|
-
|
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);
|
254
264
|
|
255
|
-
c_new_node_set = xmlXPathNodeSetMerge(NULL,
|
265
|
+
c_new_node_set = xmlXPathNodeSetMerge(NULL, c_self);
|
256
266
|
c_new_node_set = xmlXPathNodeSetMerge(c_new_node_set, c_other);
|
257
267
|
|
258
|
-
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"));
|
259
269
|
}
|
260
270
|
|
261
271
|
/*
|
@@ -266,9 +276,9 @@ rb_xml_node_set_union(VALUE rb_node_set, VALUE rb_other)
|
|
266
276
|
* each item that also appears in +node_set+
|
267
277
|
*/
|
268
278
|
static VALUE
|
269
|
-
minus(VALUE
|
279
|
+
minus(VALUE rb_self, VALUE rb_other)
|
270
280
|
{
|
271
|
-
xmlNodeSetPtr
|
281
|
+
xmlNodeSetPtr c_self, c_other;
|
272
282
|
xmlNodeSetPtr new;
|
273
283
|
int j ;
|
274
284
|
|
@@ -276,55 +286,55 @@ minus(VALUE self, VALUE rb_other)
|
|
276
286
|
rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
|
277
287
|
}
|
278
288
|
|
279
|
-
|
280
|
-
|
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);
|
281
291
|
|
282
|
-
new = xmlXPathNodeSetMerge(NULL,
|
283
|
-
for (j = 0 ; j <
|
284
|
-
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]);
|
285
295
|
}
|
286
296
|
|
287
|
-
return noko_xml_node_set_wrap(new, rb_iv_get(
|
297
|
+
return noko_xml_node_set_wrap(new, rb_iv_get(rb_self, "@document"));
|
288
298
|
}
|
289
299
|
|
290
300
|
|
291
301
|
static VALUE
|
292
|
-
index_at(VALUE
|
302
|
+
index_at(VALUE rb_self, long offset)
|
293
303
|
{
|
294
|
-
xmlNodeSetPtr
|
304
|
+
xmlNodeSetPtr c_self;
|
295
305
|
|
296
|
-
|
306
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
297
307
|
|
298
|
-
if (offset >=
|
308
|
+
if (offset >= c_self->nodeNr || abs((int)offset) > c_self->nodeNr) {
|
299
309
|
return Qnil;
|
300
310
|
}
|
301
311
|
|
302
|
-
if (offset < 0) { offset +=
|
312
|
+
if (offset < 0) { offset += c_self->nodeNr ; }
|
303
313
|
|
304
|
-
return noko_xml_node_wrap_node_set_result(
|
314
|
+
return noko_xml_node_wrap_node_set_result(c_self->nodeTab[offset], rb_self);
|
305
315
|
}
|
306
316
|
|
307
317
|
static VALUE
|
308
|
-
subseq(VALUE
|
318
|
+
subseq(VALUE rb_self, long beg, long len)
|
309
319
|
{
|
310
320
|
long j;
|
311
|
-
xmlNodeSetPtr
|
321
|
+
xmlNodeSetPtr c_self;
|
312
322
|
xmlNodeSetPtr new_set ;
|
313
323
|
|
314
|
-
|
324
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
315
325
|
|
316
|
-
if (beg >
|
326
|
+
if (beg > c_self->nodeNr) { return Qnil ; }
|
317
327
|
if (beg < 0 || len < 0) { return Qnil ; }
|
318
328
|
|
319
|
-
if ((beg + len) >
|
320
|
-
len =
|
329
|
+
if ((beg + len) > c_self->nodeNr) {
|
330
|
+
len = c_self->nodeNr - beg ;
|
321
331
|
}
|
322
332
|
|
323
333
|
new_set = xmlXPathNodeSetCreate(NULL);
|
324
334
|
for (j = beg ; j < beg + len ; ++j) {
|
325
|
-
xmlXPathNodeSetAddUnique(new_set,
|
335
|
+
xmlXPathNodeSetAddUnique(new_set, c_self->nodeTab[j]);
|
326
336
|
}
|
327
|
-
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"));
|
328
338
|
}
|
329
339
|
|
330
340
|
/*
|
@@ -343,21 +353,21 @@ subseq(VALUE self, long beg, long len)
|
|
343
353
|
* nil if the +index+ (or +start+) are out of range.
|
344
354
|
*/
|
345
355
|
static VALUE
|
346
|
-
slice(int argc, VALUE *argv, VALUE
|
356
|
+
slice(int argc, VALUE *argv, VALUE rb_self)
|
347
357
|
{
|
348
358
|
VALUE arg ;
|
349
359
|
long beg, len ;
|
350
|
-
xmlNodeSetPtr
|
360
|
+
xmlNodeSetPtr c_self;
|
351
361
|
|
352
|
-
|
362
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
353
363
|
|
354
364
|
if (argc == 2) {
|
355
365
|
beg = NUM2LONG(argv[0]);
|
356
366
|
len = NUM2LONG(argv[1]);
|
357
367
|
if (beg < 0) {
|
358
|
-
beg +=
|
368
|
+
beg += c_self->nodeNr ;
|
359
369
|
}
|
360
|
-
return subseq(
|
370
|
+
return subseq(rb_self, beg, len);
|
361
371
|
}
|
362
372
|
|
363
373
|
if (argc != 1) {
|
@@ -366,20 +376,20 @@ slice(int argc, VALUE *argv, VALUE self)
|
|
366
376
|
arg = argv[0];
|
367
377
|
|
368
378
|
if (FIXNUM_P(arg)) {
|
369
|
-
return index_at(
|
379
|
+
return index_at(rb_self, FIX2LONG(arg));
|
370
380
|
}
|
371
381
|
|
372
382
|
/* if arg is Range */
|
373
|
-
switch (rb_range_beg_len(arg, &beg, &len, (long)
|
383
|
+
switch (rb_range_beg_len(arg, &beg, &len, (long)c_self->nodeNr, 0)) {
|
374
384
|
case Qfalse:
|
375
385
|
break;
|
376
386
|
case Qnil:
|
377
387
|
return Qnil;
|
378
388
|
default:
|
379
|
-
return subseq(
|
389
|
+
return subseq(rb_self, beg, len);
|
380
390
|
}
|
381
391
|
|
382
|
-
return index_at(
|
392
|
+
return index_at(rb_self, NUM2LONG(arg));
|
383
393
|
}
|
384
394
|
|
385
395
|
|
@@ -390,17 +400,17 @@ slice(int argc, VALUE *argv, VALUE self)
|
|
390
400
|
* Return this list as an Array
|
391
401
|
*/
|
392
402
|
static VALUE
|
393
|
-
to_array(VALUE
|
403
|
+
to_array(VALUE rb_self)
|
394
404
|
{
|
395
|
-
xmlNodeSetPtr
|
405
|
+
xmlNodeSetPtr c_self ;
|
396
406
|
VALUE list;
|
397
407
|
int i;
|
398
408
|
|
399
|
-
|
409
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
400
410
|
|
401
|
-
list = rb_ary_new2(
|
402
|
-
for (i = 0; i <
|
403
|
-
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);
|
404
414
|
rb_ary_push(list, elt);
|
405
415
|
}
|
406
416
|
|
@@ -414,25 +424,25 @@ to_array(VALUE self)
|
|
414
424
|
* Unlink this NodeSet and all Node objects it contains from their current context.
|
415
425
|
*/
|
416
426
|
static VALUE
|
417
|
-
unlink_nodeset(VALUE
|
427
|
+
unlink_nodeset(VALUE rb_self)
|
418
428
|
{
|
419
|
-
xmlNodeSetPtr
|
429
|
+
xmlNodeSetPtr c_self;
|
420
430
|
int j, nodeNr ;
|
421
431
|
|
422
|
-
|
432
|
+
TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
|
423
433
|
|
424
|
-
nodeNr =
|
434
|
+
nodeNr = c_self->nodeNr ;
|
425
435
|
for (j = 0 ; j < nodeNr ; j++) {
|
426
|
-
if (! NOKOGIRI_NAMESPACE_EH(
|
436
|
+
if (! NOKOGIRI_NAMESPACE_EH(c_self->nodeTab[j])) {
|
427
437
|
VALUE node ;
|
428
438
|
xmlNodePtr node_ptr;
|
429
|
-
node = noko_xml_node_wrap(Qnil,
|
439
|
+
node = noko_xml_node_wrap(Qnil, c_self->nodeTab[j]);
|
430
440
|
rb_funcall(node, rb_intern("unlink"), 0); /* modifies the C struct out from under the object */
|
431
441
|
Noko_Node_Get_Struct(node, xmlNode, node_ptr);
|
432
|
-
|
442
|
+
c_self->nodeTab[j] = node_ptr ;
|
433
443
|
}
|
434
444
|
}
|
435
|
-
return
|
445
|
+
return rb_self ;
|
436
446
|
}
|
437
447
|
|
438
448
|
|
@@ -446,7 +456,7 @@ noko_xml_node_set_wrap(xmlNodeSetPtr c_node_set, VALUE document)
|
|
446
456
|
c_node_set = xmlXPathNodeSetCreate(NULL);
|
447
457
|
}
|
448
458
|
|
449
|
-
rb_node_set =
|
459
|
+
rb_node_set = TypedData_Wrap_Struct(cNokogiriXmlNodeSet, &xml_node_set_type, c_node_set);
|
450
460
|
|
451
461
|
if (!NIL_P(document)) {
|
452
462
|
rb_iv_set(rb_node_set, "@document", document);
|
@@ -461,6 +471,7 @@ noko_xml_node_set_wrap(xmlNodeSetPtr c_node_set, VALUE document)
|
|
461
471
|
return rb_node_set ;
|
462
472
|
}
|
463
473
|
|
474
|
+
|
464
475
|
VALUE
|
465
476
|
noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set)
|
466
477
|
{
|
@@ -472,12 +483,21 @@ noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set)
|
|
472
483
|
}
|
473
484
|
|
474
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
|
+
|
475
495
|
void
|
476
496
|
noko_init_xml_node_set(void)
|
477
497
|
{
|
478
498
|
cNokogiriXmlNodeSet = rb_define_class_under(mNokogiriXml, "NodeSet", rb_cObject);
|
479
499
|
|
480
|
-
rb_define_alloc_func(cNokogiriXmlNodeSet,
|
500
|
+
rb_define_alloc_func(cNokogiriXmlNodeSet, xml_node_set_allocate);
|
481
501
|
|
482
502
|
rb_define_method(cNokogiriXmlNodeSet, "length", length, 0);
|
483
503
|
rb_define_method(cNokogiriXmlNodeSet, "[]", slice, -1);
|