nokogiri 1.14.0-arm-linux

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.

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