nokogiri 1.13.0-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/LICENSE-DEPENDENCIES.md +1903 -0
- data/LICENSE.md +9 -0
- data/README.md +280 -0
- data/bin/nokogiri +131 -0
- data/dependencies.yml +73 -0
- data/ext/nokogiri/depend +38 -0
- data/ext/nokogiri/extconf.rb +1000 -0
- data/ext/nokogiri/gumbo.c +584 -0
- data/ext/nokogiri/html4_document.c +166 -0
- data/ext/nokogiri/html4_element_description.c +294 -0
- data/ext/nokogiri/html4_entity_lookup.c +37 -0
- data/ext/nokogiri/html4_sax_parser_context.c +120 -0
- data/ext/nokogiri/html4_sax_push_parser.c +95 -0
- data/ext/nokogiri/include/libexslt/exslt.h +102 -0
- data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
- data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +128 -0
- data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
- data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
- data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
- data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
- data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
- data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1243 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
- data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
- data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
- data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
- data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +368 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +946 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +77 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +564 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
- data/ext/nokogiri/include/libxslt/attributes.h +38 -0
- data/ext/nokogiri/include/libxslt/documents.h +93 -0
- data/ext/nokogiri/include/libxslt/extensions.h +262 -0
- data/ext/nokogiri/include/libxslt/extra.h +72 -0
- data/ext/nokogiri/include/libxslt/functions.h +78 -0
- data/ext/nokogiri/include/libxslt/imports.h +75 -0
- data/ext/nokogiri/include/libxslt/keys.h +53 -0
- data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
- data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
- data/ext/nokogiri/include/libxslt/pattern.h +84 -0
- data/ext/nokogiri/include/libxslt/preproc.h +43 -0
- data/ext/nokogiri/include/libxslt/security.h +104 -0
- data/ext/nokogiri/include/libxslt/templates.h +77 -0
- data/ext/nokogiri/include/libxslt/transform.h +207 -0
- data/ext/nokogiri/include/libxslt/variables.h +118 -0
- data/ext/nokogiri/include/libxslt/xslt.h +110 -0
- data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +278 -0
- data/ext/nokogiri/nokogiri.h +223 -0
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +103 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_cdata.c +57 -0
- data/ext/nokogiri/xml_comment.c +62 -0
- data/ext/nokogiri/xml_document.c +680 -0
- data/ext/nokogiri/xml_document_fragment.c +44 -0
- data/ext/nokogiri/xml_dtd.c +208 -0
- data/ext/nokogiri/xml_element_content.c +128 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_encoding_handler.c +104 -0
- data/ext/nokogiri/xml_entity_decl.c +112 -0
- data/ext/nokogiri/xml_entity_reference.c +50 -0
- data/ext/nokogiri/xml_namespace.c +120 -0
- data/ext/nokogiri/xml_node.c +2144 -0
- data/ext/nokogiri/xml_node_set.c +498 -0
- data/ext/nokogiri/xml_processing_instruction.c +54 -0
- data/ext/nokogiri/xml_reader.c +719 -0
- data/ext/nokogiri/xml_relax_ng.c +185 -0
- data/ext/nokogiri/xml_sax_parser.c +310 -0
- data/ext/nokogiri/xml_sax_parser_context.c +281 -0
- data/ext/nokogiri/xml_sax_push_parser.c +168 -0
- data/ext/nokogiri/xml_schema.c +284 -0
- data/ext/nokogiri/xml_syntax_error.c +85 -0
- data/ext/nokogiri/xml_text.c +48 -0
- data/ext/nokogiri/xml_xpath_context.c +406 -0
- data/ext/nokogiri/xslt_stylesheet.c +264 -0
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +101 -0
- data/gumbo-parser/THANKS +27 -0
- data/lib/nokogiri/3.1/nokogiri.so +0 -0
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +54 -0
- data/lib/nokogiri/css/parser.rb +759 -0
- data/lib/nokogiri/css/parser.y +280 -0
- data/lib/nokogiri/css/parser_extras.rb +94 -0
- data/lib/nokogiri/css/syntax_error.rb +9 -0
- data/lib/nokogiri/css/tokenizer.rb +155 -0
- data/lib/nokogiri/css/tokenizer.rex +56 -0
- data/lib/nokogiri/css/xpath_visitor.rb +359 -0
- data/lib/nokogiri/css.rb +60 -0
- data/lib/nokogiri/decorators/slop.rb +44 -0
- data/lib/nokogiri/extension.rb +31 -0
- data/lib/nokogiri/gumbo.rb +15 -0
- data/lib/nokogiri/html.rb +48 -0
- data/lib/nokogiri/html4/builder.rb +37 -0
- data/lib/nokogiri/html4/document.rb +331 -0
- data/lib/nokogiri/html4/document_fragment.rb +54 -0
- data/lib/nokogiri/html4/element_description.rb +25 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +578 -0
- data/lib/nokogiri/html4/entity_lookup.rb +15 -0
- data/lib/nokogiri/html4/sax/parser.rb +61 -0
- data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
- data/lib/nokogiri/html4.rb +46 -0
- data/lib/nokogiri/html5/document.rb +88 -0
- data/lib/nokogiri/html5/document_fragment.rb +83 -0
- data/lib/nokogiri/html5/node.rb +96 -0
- data/lib/nokogiri/html5.rb +477 -0
- data/lib/nokogiri/jruby/dependencies.rb +21 -0
- data/lib/nokogiri/syntax_error.rb +6 -0
- data/lib/nokogiri/version/constant.rb +6 -0
- data/lib/nokogiri/version/info.rb +221 -0
- data/lib/nokogiri/version.rb +4 -0
- data/lib/nokogiri/xml/attr.rb +17 -0
- data/lib/nokogiri/xml/attribute_decl.rb +20 -0
- data/lib/nokogiri/xml/builder.rb +485 -0
- data/lib/nokogiri/xml/cdata.rb +13 -0
- data/lib/nokogiri/xml/character_data.rb +9 -0
- data/lib/nokogiri/xml/document.rb +418 -0
- data/lib/nokogiri/xml/document_fragment.rb +162 -0
- data/lib/nokogiri/xml/dtd.rb +34 -0
- data/lib/nokogiri/xml/element_content.rb +38 -0
- data/lib/nokogiri/xml/element_decl.rb +15 -0
- data/lib/nokogiri/xml/entity_decl.rb +21 -0
- data/lib/nokogiri/xml/entity_reference.rb +20 -0
- data/lib/nokogiri/xml/namespace.rb +16 -0
- data/lib/nokogiri/xml/node/save_options.rb +65 -0
- data/lib/nokogiri/xml/node.rb +1402 -0
- data/lib/nokogiri/xml/node_set.rb +364 -0
- data/lib/nokogiri/xml/notation.rb +19 -0
- data/lib/nokogiri/xml/parse_options.rb +133 -0
- data/lib/nokogiri/xml/pp/character_data.rb +21 -0
- data/lib/nokogiri/xml/pp/node.rb +55 -0
- data/lib/nokogiri/xml/pp.rb +4 -0
- data/lib/nokogiri/xml/processing_instruction.rb +10 -0
- data/lib/nokogiri/xml/reader.rb +107 -0
- data/lib/nokogiri/xml/relax_ng.rb +38 -0
- data/lib/nokogiri/xml/sax/document.rb +167 -0
- data/lib/nokogiri/xml/sax/parser.rb +125 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +21 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
- data/lib/nokogiri/xml/sax.rb +6 -0
- data/lib/nokogiri/xml/schema.rb +73 -0
- data/lib/nokogiri/xml/searchable.rb +259 -0
- data/lib/nokogiri/xml/syntax_error.rb +71 -0
- data/lib/nokogiri/xml/text.rb +11 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +13 -0
- data/lib/nokogiri/xml/xpath.rb +21 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xml.rb +75 -0
- data/lib/nokogiri/xslt/stylesheet.rb +27 -0
- data/lib/nokogiri/xslt.rb +58 -0
- data/lib/nokogiri.rb +128 -0
- data/lib/xsd/xmlparser/nokogiri.rb +104 -0
- metadata +536 -0
@@ -0,0 +1,498 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlNodeSet ;
|
4
|
+
|
5
|
+
static ID decorate ;
|
6
|
+
|
7
|
+
static void
|
8
|
+
Check_Node_Set_Node_Type(VALUE node)
|
9
|
+
{
|
10
|
+
if (!(rb_obj_is_kind_of(node, cNokogiriXmlNode) ||
|
11
|
+
rb_obj_is_kind_of(node, cNokogiriXmlNamespace))) {
|
12
|
+
rb_raise(rb_eArgError, "node must be a Nokogiri::XML::Node or Nokogiri::XML::Namespace");
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
|
17
|
+
static
|
18
|
+
VALUE
|
19
|
+
ruby_object_get(xmlNodePtr c_node)
|
20
|
+
{
|
21
|
+
/* see xmlElementType in libxml2 tree.h */
|
22
|
+
switch (c_node->type) {
|
23
|
+
case XML_NAMESPACE_DECL:
|
24
|
+
/* _private is later in the namespace struct */
|
25
|
+
return (VALUE)(((xmlNsPtr)c_node)->_private);
|
26
|
+
|
27
|
+
case XML_DOCUMENT_NODE:
|
28
|
+
case XML_HTML_DOCUMENT_NODE:
|
29
|
+
/* in documents we use _private to store a tuple */
|
30
|
+
if (DOC_RUBY_OBJECT_TEST(((xmlDocPtr)c_node))) {
|
31
|
+
return DOC_RUBY_OBJECT((xmlDocPtr)c_node);
|
32
|
+
}
|
33
|
+
return (VALUE)NULL;
|
34
|
+
|
35
|
+
default:
|
36
|
+
return (VALUE)(c_node->_private);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
static void
|
42
|
+
mark(xmlNodeSetPtr node_set)
|
43
|
+
{
|
44
|
+
VALUE rb_node;
|
45
|
+
int jnode;
|
46
|
+
|
47
|
+
for (jnode = 0; jnode < node_set->nodeNr; jnode++) {
|
48
|
+
rb_node = ruby_object_get(node_set->nodeTab[jnode]);
|
49
|
+
if (rb_node) {
|
50
|
+
rb_gc_mark(rb_node);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
static void
|
56
|
+
xpath_node_set_del(xmlNodeSetPtr cur, xmlNodePtr val)
|
57
|
+
{
|
58
|
+
/*
|
59
|
+
* For reasons outlined in xml_namespace.c, here we reproduce xmlXPathNodeSetDel() except for the
|
60
|
+
* offending call to xmlXPathNodeSetFreeNs().
|
61
|
+
*/
|
62
|
+
int i;
|
63
|
+
|
64
|
+
if (cur == NULL) { return; }
|
65
|
+
if (val == NULL) { return; }
|
66
|
+
|
67
|
+
/*
|
68
|
+
* find node in nodeTab
|
69
|
+
*/
|
70
|
+
for (i = 0; i < cur->nodeNr; i++)
|
71
|
+
if (cur->nodeTab[i] == val) { break; }
|
72
|
+
|
73
|
+
if (i >= cur->nodeNr) { /* not found */
|
74
|
+
return;
|
75
|
+
}
|
76
|
+
cur->nodeNr--;
|
77
|
+
for (; i < cur->nodeNr; i++) {
|
78
|
+
cur->nodeTab[i] = cur->nodeTab[i + 1];
|
79
|
+
}
|
80
|
+
cur->nodeTab[cur->nodeNr] = NULL;
|
81
|
+
}
|
82
|
+
|
83
|
+
|
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
|
+
/*
|
109
|
+
* call-seq:
|
110
|
+
* dup
|
111
|
+
*
|
112
|
+
* Duplicate this NodeSet. Note that the Nodes contained in the NodeSet are not
|
113
|
+
* duplicated (similar to how Array and other Enumerable classes work).
|
114
|
+
*/
|
115
|
+
static VALUE
|
116
|
+
duplicate(VALUE self)
|
117
|
+
{
|
118
|
+
xmlNodeSetPtr node_set;
|
119
|
+
xmlNodeSetPtr dupl;
|
120
|
+
|
121
|
+
Data_Get_Struct(self, xmlNodeSet, node_set);
|
122
|
+
|
123
|
+
dupl = xmlXPathNodeSetMerge(NULL, node_set);
|
124
|
+
|
125
|
+
return noko_xml_node_set_wrap(dupl, rb_iv_get(self, "@document"));
|
126
|
+
}
|
127
|
+
|
128
|
+
/*
|
129
|
+
* call-seq:
|
130
|
+
* length
|
131
|
+
*
|
132
|
+
* Get the length of the node set
|
133
|
+
*/
|
134
|
+
static VALUE
|
135
|
+
length(VALUE self)
|
136
|
+
{
|
137
|
+
xmlNodeSetPtr node_set;
|
138
|
+
|
139
|
+
Data_Get_Struct(self, xmlNodeSet, node_set);
|
140
|
+
|
141
|
+
return node_set ? INT2NUM(node_set->nodeNr) : INT2NUM(0);
|
142
|
+
}
|
143
|
+
|
144
|
+
/*
|
145
|
+
* call-seq:
|
146
|
+
* push(node)
|
147
|
+
*
|
148
|
+
* Append +node+ to the NodeSet.
|
149
|
+
*/
|
150
|
+
static VALUE
|
151
|
+
push(VALUE self, VALUE rb_node)
|
152
|
+
{
|
153
|
+
xmlNodeSetPtr node_set;
|
154
|
+
xmlNodePtr node;
|
155
|
+
|
156
|
+
Check_Node_Set_Node_Type(rb_node);
|
157
|
+
|
158
|
+
Data_Get_Struct(self, xmlNodeSet, node_set);
|
159
|
+
Data_Get_Struct(rb_node, xmlNode, node);
|
160
|
+
|
161
|
+
xmlXPathNodeSetAdd(node_set, node);
|
162
|
+
|
163
|
+
return self;
|
164
|
+
}
|
165
|
+
|
166
|
+
/*
|
167
|
+
* call-seq:
|
168
|
+
* delete(node)
|
169
|
+
*
|
170
|
+
* Delete +node+ from the Nodeset, if it is a member. Returns the deleted node
|
171
|
+
* if found, otherwise returns nil.
|
172
|
+
*/
|
173
|
+
static VALUE
|
174
|
+
delete (VALUE self, VALUE rb_node)
|
175
|
+
{
|
176
|
+
xmlNodeSetPtr node_set;
|
177
|
+
xmlNodePtr node;
|
178
|
+
|
179
|
+
Check_Node_Set_Node_Type(rb_node);
|
180
|
+
|
181
|
+
Data_Get_Struct(self, xmlNodeSet, node_set);
|
182
|
+
Data_Get_Struct(rb_node, xmlNode, node);
|
183
|
+
|
184
|
+
if (xmlXPathNodeSetContains(node_set, node)) {
|
185
|
+
xpath_node_set_del(node_set, node);
|
186
|
+
return rb_node;
|
187
|
+
}
|
188
|
+
return Qnil ;
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
/*
|
193
|
+
* call-seq:
|
194
|
+
* &(node_set)
|
195
|
+
*
|
196
|
+
* Set Intersection — Returns a new NodeSet containing nodes common to the two NodeSets.
|
197
|
+
*/
|
198
|
+
static VALUE
|
199
|
+
intersection(VALUE self, VALUE rb_other)
|
200
|
+
{
|
201
|
+
xmlNodeSetPtr node_set, other ;
|
202
|
+
xmlNodeSetPtr intersection;
|
203
|
+
|
204
|
+
if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet)) {
|
205
|
+
rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
|
206
|
+
}
|
207
|
+
|
208
|
+
Data_Get_Struct(self, xmlNodeSet, node_set);
|
209
|
+
Data_Get_Struct(rb_other, xmlNodeSet, other);
|
210
|
+
|
211
|
+
intersection = xmlXPathIntersection(node_set, other);
|
212
|
+
return noko_xml_node_set_wrap(intersection, rb_iv_get(self, "@document"));
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
/*
|
217
|
+
* call-seq:
|
218
|
+
* include?(node)
|
219
|
+
*
|
220
|
+
* Returns true if any member of node set equals +node+.
|
221
|
+
*/
|
222
|
+
static VALUE
|
223
|
+
include_eh(VALUE self, VALUE rb_node)
|
224
|
+
{
|
225
|
+
xmlNodeSetPtr node_set;
|
226
|
+
xmlNodePtr node;
|
227
|
+
|
228
|
+
Check_Node_Set_Node_Type(rb_node);
|
229
|
+
|
230
|
+
Data_Get_Struct(self, xmlNodeSet, node_set);
|
231
|
+
Data_Get_Struct(rb_node, xmlNode, node);
|
232
|
+
|
233
|
+
return (xmlXPathNodeSetContains(node_set, node) ? Qtrue : Qfalse);
|
234
|
+
}
|
235
|
+
|
236
|
+
|
237
|
+
/*
|
238
|
+
* call-seq:
|
239
|
+
* |(node_set)
|
240
|
+
*
|
241
|
+
* Returns a new set built by merging the set and the elements of the given
|
242
|
+
* set.
|
243
|
+
*/
|
244
|
+
static VALUE
|
245
|
+
rb_xml_node_set_union(VALUE rb_node_set, VALUE rb_other)
|
246
|
+
{
|
247
|
+
xmlNodeSetPtr c_node_set, c_other;
|
248
|
+
xmlNodeSetPtr c_new_node_set;
|
249
|
+
|
250
|
+
if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet)) {
|
251
|
+
rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
|
252
|
+
}
|
253
|
+
|
254
|
+
Data_Get_Struct(rb_node_set, xmlNodeSet, c_node_set);
|
255
|
+
Data_Get_Struct(rb_other, xmlNodeSet, c_other);
|
256
|
+
|
257
|
+
c_new_node_set = xmlXPathNodeSetMerge(NULL, c_node_set);
|
258
|
+
c_new_node_set = xmlXPathNodeSetMerge(c_new_node_set, c_other);
|
259
|
+
|
260
|
+
return noko_xml_node_set_wrap(c_new_node_set, rb_iv_get(rb_node_set, "@document"));
|
261
|
+
}
|
262
|
+
|
263
|
+
/*
|
264
|
+
* call-seq:
|
265
|
+
* -(node_set)
|
266
|
+
*
|
267
|
+
* Difference - returns a new NodeSet that is a copy of this NodeSet, removing
|
268
|
+
* each item that also appears in +node_set+
|
269
|
+
*/
|
270
|
+
static VALUE
|
271
|
+
minus(VALUE self, VALUE rb_other)
|
272
|
+
{
|
273
|
+
xmlNodeSetPtr node_set, other;
|
274
|
+
xmlNodeSetPtr new;
|
275
|
+
int j ;
|
276
|
+
|
277
|
+
if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet)) {
|
278
|
+
rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
|
279
|
+
}
|
280
|
+
|
281
|
+
Data_Get_Struct(self, xmlNodeSet, node_set);
|
282
|
+
Data_Get_Struct(rb_other, xmlNodeSet, other);
|
283
|
+
|
284
|
+
new = xmlXPathNodeSetMerge(NULL, node_set);
|
285
|
+
for (j = 0 ; j < other->nodeNr ; ++j) {
|
286
|
+
xpath_node_set_del(new, other->nodeTab[j]);
|
287
|
+
}
|
288
|
+
|
289
|
+
return noko_xml_node_set_wrap(new, rb_iv_get(self, "@document"));
|
290
|
+
}
|
291
|
+
|
292
|
+
|
293
|
+
static VALUE
|
294
|
+
index_at(VALUE self, long offset)
|
295
|
+
{
|
296
|
+
xmlNodeSetPtr node_set;
|
297
|
+
|
298
|
+
Data_Get_Struct(self, xmlNodeSet, node_set);
|
299
|
+
|
300
|
+
if (offset >= node_set->nodeNr || abs((int)offset) > node_set->nodeNr) {
|
301
|
+
return Qnil;
|
302
|
+
}
|
303
|
+
|
304
|
+
if (offset < 0) { offset += node_set->nodeNr ; }
|
305
|
+
|
306
|
+
return noko_xml_node_wrap_node_set_result(node_set->nodeTab[offset], self);
|
307
|
+
}
|
308
|
+
|
309
|
+
static VALUE
|
310
|
+
subseq(VALUE self, long beg, long len)
|
311
|
+
{
|
312
|
+
long j;
|
313
|
+
xmlNodeSetPtr node_set;
|
314
|
+
xmlNodeSetPtr new_set ;
|
315
|
+
|
316
|
+
Data_Get_Struct(self, xmlNodeSet, node_set);
|
317
|
+
|
318
|
+
if (beg > node_set->nodeNr) { return Qnil ; }
|
319
|
+
if (beg < 0 || len < 0) { return Qnil ; }
|
320
|
+
|
321
|
+
if ((beg + len) > node_set->nodeNr) {
|
322
|
+
len = node_set->nodeNr - beg ;
|
323
|
+
}
|
324
|
+
|
325
|
+
new_set = xmlXPathNodeSetCreate(NULL);
|
326
|
+
for (j = beg ; j < beg + len ; ++j) {
|
327
|
+
xmlXPathNodeSetAddUnique(new_set, node_set->nodeTab[j]);
|
328
|
+
}
|
329
|
+
return noko_xml_node_set_wrap(new_set, rb_iv_get(self, "@document"));
|
330
|
+
}
|
331
|
+
|
332
|
+
/*
|
333
|
+
* call-seq:
|
334
|
+
* [index] -> Node or nil
|
335
|
+
* [start, length] -> NodeSet or nil
|
336
|
+
* [range] -> NodeSet or nil
|
337
|
+
* slice(index) -> Node or nil
|
338
|
+
* slice(start, length) -> NodeSet or nil
|
339
|
+
* slice(range) -> NodeSet or nil
|
340
|
+
*
|
341
|
+
* Element reference - returns the node at +index+, or returns a NodeSet
|
342
|
+
* containing nodes starting at +start+ and continuing for +length+ elements, or
|
343
|
+
* returns a NodeSet containing nodes specified by +range+. Negative +indices+
|
344
|
+
* count backward from the end of the +node_set+ (-1 is the last node). Returns
|
345
|
+
* nil if the +index+ (or +start+) are out of range.
|
346
|
+
*/
|
347
|
+
static VALUE
|
348
|
+
slice(int argc, VALUE *argv, VALUE self)
|
349
|
+
{
|
350
|
+
VALUE arg ;
|
351
|
+
long beg, len ;
|
352
|
+
xmlNodeSetPtr node_set;
|
353
|
+
|
354
|
+
Data_Get_Struct(self, xmlNodeSet, node_set);
|
355
|
+
|
356
|
+
if (argc == 2) {
|
357
|
+
beg = NUM2LONG(argv[0]);
|
358
|
+
len = NUM2LONG(argv[1]);
|
359
|
+
if (beg < 0) {
|
360
|
+
beg += node_set->nodeNr ;
|
361
|
+
}
|
362
|
+
return subseq(self, beg, len);
|
363
|
+
}
|
364
|
+
|
365
|
+
if (argc != 1) {
|
366
|
+
rb_scan_args(argc, argv, "11", NULL, NULL);
|
367
|
+
}
|
368
|
+
arg = argv[0];
|
369
|
+
|
370
|
+
if (FIXNUM_P(arg)) {
|
371
|
+
return index_at(self, FIX2LONG(arg));
|
372
|
+
}
|
373
|
+
|
374
|
+
/* if arg is Range */
|
375
|
+
switch (rb_range_beg_len(arg, &beg, &len, (long)node_set->nodeNr, 0)) {
|
376
|
+
case Qfalse:
|
377
|
+
break;
|
378
|
+
case Qnil:
|
379
|
+
return Qnil;
|
380
|
+
default:
|
381
|
+
return subseq(self, beg, len);
|
382
|
+
}
|
383
|
+
|
384
|
+
return index_at(self, NUM2LONG(arg));
|
385
|
+
}
|
386
|
+
|
387
|
+
|
388
|
+
/*
|
389
|
+
* call-seq:
|
390
|
+
* to_a
|
391
|
+
*
|
392
|
+
* Return this list as an Array
|
393
|
+
*/
|
394
|
+
static VALUE
|
395
|
+
to_array(VALUE self)
|
396
|
+
{
|
397
|
+
xmlNodeSetPtr node_set ;
|
398
|
+
VALUE list;
|
399
|
+
int i;
|
400
|
+
|
401
|
+
Data_Get_Struct(self, xmlNodeSet, node_set);
|
402
|
+
|
403
|
+
list = rb_ary_new2(node_set->nodeNr);
|
404
|
+
for (i = 0; i < node_set->nodeNr; i++) {
|
405
|
+
VALUE elt = noko_xml_node_wrap_node_set_result(node_set->nodeTab[i], self);
|
406
|
+
rb_ary_push(list, elt);
|
407
|
+
}
|
408
|
+
|
409
|
+
return list;
|
410
|
+
}
|
411
|
+
|
412
|
+
/*
|
413
|
+
* call-seq:
|
414
|
+
* unlink
|
415
|
+
*
|
416
|
+
* Unlink this NodeSet and all Node objects it contains from their current context.
|
417
|
+
*/
|
418
|
+
static VALUE
|
419
|
+
unlink_nodeset(VALUE self)
|
420
|
+
{
|
421
|
+
xmlNodeSetPtr node_set;
|
422
|
+
int j, nodeNr ;
|
423
|
+
|
424
|
+
Data_Get_Struct(self, xmlNodeSet, node_set);
|
425
|
+
|
426
|
+
nodeNr = node_set->nodeNr ;
|
427
|
+
for (j = 0 ; j < nodeNr ; j++) {
|
428
|
+
if (! NOKOGIRI_NAMESPACE_EH(node_set->nodeTab[j])) {
|
429
|
+
VALUE node ;
|
430
|
+
xmlNodePtr node_ptr;
|
431
|
+
node = noko_xml_node_wrap(Qnil, node_set->nodeTab[j]);
|
432
|
+
rb_funcall(node, rb_intern("unlink"), 0); /* modifies the C struct out from under the object */
|
433
|
+
Data_Get_Struct(node, xmlNode, node_ptr);
|
434
|
+
node_set->nodeTab[j] = node_ptr ;
|
435
|
+
}
|
436
|
+
}
|
437
|
+
return self ;
|
438
|
+
}
|
439
|
+
|
440
|
+
|
441
|
+
VALUE
|
442
|
+
noko_xml_node_set_wrap(xmlNodeSetPtr c_node_set, VALUE document)
|
443
|
+
{
|
444
|
+
int j;
|
445
|
+
VALUE rb_node_set ;
|
446
|
+
|
447
|
+
if (c_node_set == NULL) {
|
448
|
+
c_node_set = xmlXPathNodeSetCreate(NULL);
|
449
|
+
}
|
450
|
+
|
451
|
+
rb_node_set = Data_Wrap_Struct(cNokogiriXmlNodeSet, mark, deallocate, c_node_set);
|
452
|
+
|
453
|
+
if (!NIL_P(document)) {
|
454
|
+
rb_iv_set(rb_node_set, "@document", document);
|
455
|
+
rb_funcall(document, decorate, 1, rb_node_set);
|
456
|
+
}
|
457
|
+
|
458
|
+
/* make sure we create ruby objects for all the results, so they'll be marked during the GC mark phase */
|
459
|
+
for (j = 0 ; j < c_node_set->nodeNr ; j++) {
|
460
|
+
noko_xml_node_wrap_node_set_result(c_node_set->nodeTab[j], rb_node_set);
|
461
|
+
}
|
462
|
+
|
463
|
+
return rb_node_set ;
|
464
|
+
}
|
465
|
+
|
466
|
+
VALUE
|
467
|
+
noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set)
|
468
|
+
{
|
469
|
+
if (NOKOGIRI_NAMESPACE_EH(node)) {
|
470
|
+
return noko_xml_namespace_wrap_xpath_copy((xmlNsPtr)node);
|
471
|
+
} else {
|
472
|
+
return noko_xml_node_wrap(Qnil, node);
|
473
|
+
}
|
474
|
+
}
|
475
|
+
|
476
|
+
|
477
|
+
void
|
478
|
+
noko_init_xml_node_set(void)
|
479
|
+
{
|
480
|
+
cNokogiriXmlNodeSet = rb_define_class_under(mNokogiriXml, "NodeSet", rb_cObject);
|
481
|
+
|
482
|
+
rb_define_alloc_func(cNokogiriXmlNodeSet, allocate);
|
483
|
+
|
484
|
+
rb_define_method(cNokogiriXmlNodeSet, "length", length, 0);
|
485
|
+
rb_define_method(cNokogiriXmlNodeSet, "[]", slice, -1);
|
486
|
+
rb_define_method(cNokogiriXmlNodeSet, "slice", slice, -1);
|
487
|
+
rb_define_method(cNokogiriXmlNodeSet, "push", push, 1);
|
488
|
+
rb_define_method(cNokogiriXmlNodeSet, "|", rb_xml_node_set_union, 1);
|
489
|
+
rb_define_method(cNokogiriXmlNodeSet, "-", minus, 1);
|
490
|
+
rb_define_method(cNokogiriXmlNodeSet, "unlink", unlink_nodeset, 0);
|
491
|
+
rb_define_method(cNokogiriXmlNodeSet, "to_a", to_array, 0);
|
492
|
+
rb_define_method(cNokogiriXmlNodeSet, "dup", duplicate, 0);
|
493
|
+
rb_define_method(cNokogiriXmlNodeSet, "delete", delete, 1);
|
494
|
+
rb_define_method(cNokogiriXmlNodeSet, "&", intersection, 1);
|
495
|
+
rb_define_method(cNokogiriXmlNodeSet, "include?", include_eh, 1);
|
496
|
+
|
497
|
+
decorate = rb_intern("decorate");
|
498
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlProcessingInstruction;
|
4
|
+
|
5
|
+
/*
|
6
|
+
* call-seq:
|
7
|
+
* new(document, name, content)
|
8
|
+
*
|
9
|
+
* Create a new ProcessingInstruction element on the +document+ with +name+
|
10
|
+
* and +content+
|
11
|
+
*/
|
12
|
+
static VALUE
|
13
|
+
new (int argc, VALUE *argv, VALUE klass)
|
14
|
+
{
|
15
|
+
xmlDocPtr xml_doc;
|
16
|
+
xmlNodePtr node;
|
17
|
+
VALUE document;
|
18
|
+
VALUE name;
|
19
|
+
VALUE content;
|
20
|
+
VALUE rest;
|
21
|
+
VALUE rb_node;
|
22
|
+
|
23
|
+
rb_scan_args(argc, argv, "3*", &document, &name, &content, &rest);
|
24
|
+
|
25
|
+
Data_Get_Struct(document, xmlDoc, xml_doc);
|
26
|
+
|
27
|
+
node = xmlNewDocPI(
|
28
|
+
xml_doc,
|
29
|
+
(const xmlChar *)StringValueCStr(name),
|
30
|
+
(const xmlChar *)StringValueCStr(content)
|
31
|
+
);
|
32
|
+
|
33
|
+
noko_xml_document_pin_node(node);
|
34
|
+
|
35
|
+
rb_node = noko_xml_node_wrap(klass, node);
|
36
|
+
rb_obj_call_init(rb_node, argc, argv);
|
37
|
+
|
38
|
+
if (rb_block_given_p()) { rb_yield(rb_node); }
|
39
|
+
|
40
|
+
return rb_node;
|
41
|
+
}
|
42
|
+
|
43
|
+
void
|
44
|
+
noko_init_xml_processing_instruction()
|
45
|
+
{
|
46
|
+
assert(cNokogiriXmlNode);
|
47
|
+
/*
|
48
|
+
* ProcessingInstruction represents a ProcessingInstruction node in an xml
|
49
|
+
* document.
|
50
|
+
*/
|
51
|
+
cNokogiriXmlProcessingInstruction = rb_define_class_under(mNokogiriXml, "ProcessingInstruction", cNokogiriXmlNode);
|
52
|
+
|
53
|
+
rb_define_singleton_method(cNokogiriXmlProcessingInstruction, "new", new, -1);
|
54
|
+
}
|