nokogiri 1.18.0.rc1-arm-linux-gnu

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