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.

Files changed (195) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/LICENSE-DEPENDENCIES.md +1903 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +280 -0
  6. data/bin/nokogiri +131 -0
  7. data/dependencies.yml +73 -0
  8. data/ext/nokogiri/depend +38 -0
  9. data/ext/nokogiri/extconf.rb +1000 -0
  10. data/ext/nokogiri/gumbo.c +584 -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 +120 -0
  15. data/ext/nokogiri/html4_sax_push_parser.c +95 -0
  16. data/ext/nokogiri/include/libexslt/exslt.h +102 -0
  17. data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
  18. data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
  19. data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
  20. data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
  21. data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
  22. data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
  23. data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
  24. data/ext/nokogiri/include/libxml2/libxml/c14n.h +128 -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 +79 -0
  29. data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
  30. data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
  31. data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
  32. data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
  33. data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
  34. data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
  35. data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
  36. data/ext/nokogiri/include/libxml2/libxml/parser.h +1243 -0
  37. data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
  38. data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
  39. data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
  40. data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
  41. data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
  42. data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
  43. data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
  44. data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
  45. data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
  46. data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
  47. data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
  48. data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +368 -0
  49. data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
  50. data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +946 -0
  51. data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +77 -0
  52. data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
  53. data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
  54. data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
  55. data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
  56. data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
  57. data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
  58. data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
  59. data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
  60. data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
  61. data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
  62. data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
  63. data/ext/nokogiri/include/libxml2/libxml/xpath.h +564 -0
  64. data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
  65. data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
  66. data/ext/nokogiri/include/libxslt/attributes.h +38 -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 +1978 -0
  83. data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
  84. data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
  85. data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
  86. data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
  87. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  88. data/ext/nokogiri/nokogiri.c +278 -0
  89. data/ext/nokogiri/nokogiri.h +223 -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 +57 -0
  94. data/ext/nokogiri/xml_comment.c +62 -0
  95. data/ext/nokogiri/xml_document.c +680 -0
  96. data/ext/nokogiri/xml_document_fragment.c +44 -0
  97. data/ext/nokogiri/xml_dtd.c +208 -0
  98. data/ext/nokogiri/xml_element_content.c +128 -0
  99. data/ext/nokogiri/xml_element_decl.c +69 -0
  100. data/ext/nokogiri/xml_encoding_handler.c +104 -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 +120 -0
  104. data/ext/nokogiri/xml_node.c +2144 -0
  105. data/ext/nokogiri/xml_node_set.c +498 -0
  106. data/ext/nokogiri/xml_processing_instruction.c +54 -0
  107. data/ext/nokogiri/xml_reader.c +719 -0
  108. data/ext/nokogiri/xml_relax_ng.c +185 -0
  109. data/ext/nokogiri/xml_sax_parser.c +310 -0
  110. data/ext/nokogiri/xml_sax_parser_context.c +281 -0
  111. data/ext/nokogiri/xml_sax_push_parser.c +168 -0
  112. data/ext/nokogiri/xml_schema.c +284 -0
  113. data/ext/nokogiri/xml_syntax_error.c +85 -0
  114. data/ext/nokogiri/xml_text.c +48 -0
  115. data/ext/nokogiri/xml_xpath_context.c +406 -0
  116. data/ext/nokogiri/xslt_stylesheet.c +264 -0
  117. data/gumbo-parser/CHANGES.md +63 -0
  118. data/gumbo-parser/Makefile +101 -0
  119. data/gumbo-parser/THANKS +27 -0
  120. data/lib/nokogiri/3.1/nokogiri.so +0 -0
  121. data/lib/nokogiri/class_resolver.rb +67 -0
  122. data/lib/nokogiri/css/node.rb +54 -0
  123. data/lib/nokogiri/css/parser.rb +759 -0
  124. data/lib/nokogiri/css/parser.y +280 -0
  125. data/lib/nokogiri/css/parser_extras.rb +94 -0
  126. data/lib/nokogiri/css/syntax_error.rb +9 -0
  127. data/lib/nokogiri/css/tokenizer.rb +155 -0
  128. data/lib/nokogiri/css/tokenizer.rex +56 -0
  129. data/lib/nokogiri/css/xpath_visitor.rb +359 -0
  130. data/lib/nokogiri/css.rb +60 -0
  131. data/lib/nokogiri/decorators/slop.rb +44 -0
  132. data/lib/nokogiri/extension.rb +31 -0
  133. data/lib/nokogiri/gumbo.rb +15 -0
  134. data/lib/nokogiri/html.rb +48 -0
  135. data/lib/nokogiri/html4/builder.rb +37 -0
  136. data/lib/nokogiri/html4/document.rb +331 -0
  137. data/lib/nokogiri/html4/document_fragment.rb +54 -0
  138. data/lib/nokogiri/html4/element_description.rb +25 -0
  139. data/lib/nokogiri/html4/element_description_defaults.rb +578 -0
  140. data/lib/nokogiri/html4/entity_lookup.rb +15 -0
  141. data/lib/nokogiri/html4/sax/parser.rb +61 -0
  142. data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
  143. data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
  144. data/lib/nokogiri/html4.rb +46 -0
  145. data/lib/nokogiri/html5/document.rb +88 -0
  146. data/lib/nokogiri/html5/document_fragment.rb +83 -0
  147. data/lib/nokogiri/html5/node.rb +96 -0
  148. data/lib/nokogiri/html5.rb +477 -0
  149. data/lib/nokogiri/jruby/dependencies.rb +21 -0
  150. data/lib/nokogiri/syntax_error.rb +6 -0
  151. data/lib/nokogiri/version/constant.rb +6 -0
  152. data/lib/nokogiri/version/info.rb +221 -0
  153. data/lib/nokogiri/version.rb +4 -0
  154. data/lib/nokogiri/xml/attr.rb +17 -0
  155. data/lib/nokogiri/xml/attribute_decl.rb +20 -0
  156. data/lib/nokogiri/xml/builder.rb +485 -0
  157. data/lib/nokogiri/xml/cdata.rb +13 -0
  158. data/lib/nokogiri/xml/character_data.rb +9 -0
  159. data/lib/nokogiri/xml/document.rb +418 -0
  160. data/lib/nokogiri/xml/document_fragment.rb +162 -0
  161. data/lib/nokogiri/xml/dtd.rb +34 -0
  162. data/lib/nokogiri/xml/element_content.rb +38 -0
  163. data/lib/nokogiri/xml/element_decl.rb +15 -0
  164. data/lib/nokogiri/xml/entity_decl.rb +21 -0
  165. data/lib/nokogiri/xml/entity_reference.rb +20 -0
  166. data/lib/nokogiri/xml/namespace.rb +16 -0
  167. data/lib/nokogiri/xml/node/save_options.rb +65 -0
  168. data/lib/nokogiri/xml/node.rb +1402 -0
  169. data/lib/nokogiri/xml/node_set.rb +364 -0
  170. data/lib/nokogiri/xml/notation.rb +19 -0
  171. data/lib/nokogiri/xml/parse_options.rb +133 -0
  172. data/lib/nokogiri/xml/pp/character_data.rb +21 -0
  173. data/lib/nokogiri/xml/pp/node.rb +55 -0
  174. data/lib/nokogiri/xml/pp.rb +4 -0
  175. data/lib/nokogiri/xml/processing_instruction.rb +10 -0
  176. data/lib/nokogiri/xml/reader.rb +107 -0
  177. data/lib/nokogiri/xml/relax_ng.rb +38 -0
  178. data/lib/nokogiri/xml/sax/document.rb +167 -0
  179. data/lib/nokogiri/xml/sax/parser.rb +125 -0
  180. data/lib/nokogiri/xml/sax/parser_context.rb +21 -0
  181. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  182. data/lib/nokogiri/xml/sax.rb +6 -0
  183. data/lib/nokogiri/xml/schema.rb +73 -0
  184. data/lib/nokogiri/xml/searchable.rb +259 -0
  185. data/lib/nokogiri/xml/syntax_error.rb +71 -0
  186. data/lib/nokogiri/xml/text.rb +11 -0
  187. data/lib/nokogiri/xml/xpath/syntax_error.rb +13 -0
  188. data/lib/nokogiri/xml/xpath.rb +21 -0
  189. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  190. data/lib/nokogiri/xml.rb +75 -0
  191. data/lib/nokogiri/xslt/stylesheet.rb +27 -0
  192. data/lib/nokogiri/xslt.rb +58 -0
  193. data/lib/nokogiri.rb +128 -0
  194. data/lib/xsd/xmlparser/nokogiri.rb +104 -0
  195. metadata +536 -0
@@ -0,0 +1,719 @@
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriXmlReader;
4
+
5
+ static void
6
+ dealloc(xmlTextReaderPtr reader)
7
+ {
8
+ NOKOGIRI_DEBUG_START(reader);
9
+ xmlFreeTextReader(reader);
10
+ NOKOGIRI_DEBUG_END(reader);
11
+ }
12
+
13
+ static int
14
+ has_attributes(xmlTextReaderPtr reader)
15
+ {
16
+ /*
17
+ * this implementation of xmlTextReaderHasAttributes explicitly includes
18
+ * namespaces and properties, because some earlier versions ignore
19
+ * namespaces.
20
+ */
21
+ xmlNodePtr node ;
22
+ node = xmlTextReaderCurrentNode(reader);
23
+ if (node == NULL) {
24
+ return (0);
25
+ }
26
+
27
+ if ((node->type == XML_ELEMENT_NODE) &&
28
+ ((node->properties != NULL) || (node->nsDef != NULL))) {
29
+ return (1);
30
+ }
31
+ return (0);
32
+ }
33
+
34
+ static void
35
+ Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
36
+ {
37
+ xmlNsPtr ns;
38
+ VALUE key;
39
+
40
+ if (node->type != XML_ELEMENT_NODE) { return ; }
41
+
42
+ ns = node->nsDef;
43
+ while (ns != NULL) {
44
+
45
+ key = rb_enc_str_new_cstr(XMLNS_PREFIX, rb_utf8_encoding());
46
+ if (ns->prefix) {
47
+ rb_str_cat_cstr(key, ":");
48
+ rb_str_cat_cstr(key, (const char *)ns->prefix);
49
+ }
50
+
51
+ key = rb_str_conv_enc(key, rb_utf8_encoding(), rb_default_internal_encoding());
52
+ rb_hash_aset(attr_hash,
53
+ key,
54
+ (ns->href ? NOKOGIRI_STR_NEW2(ns->href) : Qnil)
55
+ );
56
+ ns = ns->next ;
57
+ }
58
+ }
59
+
60
+
61
+ /*
62
+ * call-seq:
63
+ * default?
64
+ *
65
+ * Was an attribute generated from the default value in the DTD or schema?
66
+ */
67
+ static VALUE
68
+ default_eh(VALUE self)
69
+ {
70
+ xmlTextReaderPtr reader;
71
+ int eh;
72
+
73
+ Data_Get_Struct(self, xmlTextReader, reader);
74
+ eh = xmlTextReaderIsDefault(reader);
75
+ if (eh == 0) { return Qfalse; }
76
+ if (eh == 1) { return Qtrue; }
77
+
78
+ return Qnil;
79
+ }
80
+
81
+ /*
82
+ * call-seq:
83
+ * value?
84
+ *
85
+ * Does this node have a text value?
86
+ */
87
+ static VALUE
88
+ value_eh(VALUE self)
89
+ {
90
+ xmlTextReaderPtr reader;
91
+ int eh;
92
+
93
+ Data_Get_Struct(self, xmlTextReader, reader);
94
+ eh = xmlTextReaderHasValue(reader);
95
+ if (eh == 0) { return Qfalse; }
96
+ if (eh == 1) { return Qtrue; }
97
+
98
+ return Qnil;
99
+ }
100
+
101
+ /*
102
+ * call-seq:
103
+ * attributes?
104
+ *
105
+ * Does this node have attributes?
106
+ */
107
+ static VALUE
108
+ attributes_eh(VALUE self)
109
+ {
110
+ xmlTextReaderPtr reader;
111
+ int eh;
112
+
113
+ Data_Get_Struct(self, xmlTextReader, reader);
114
+ eh = has_attributes(reader);
115
+ if (eh == 0) { return Qfalse; }
116
+ if (eh == 1) { return Qtrue; }
117
+
118
+ return Qnil;
119
+ }
120
+
121
+ /*
122
+ * call-seq:
123
+ * namespaces
124
+ *
125
+ * Get a hash of namespaces for this Node
126
+ */
127
+ static VALUE
128
+ namespaces(VALUE self)
129
+ {
130
+ xmlTextReaderPtr reader;
131
+ xmlNodePtr ptr;
132
+ VALUE attr ;
133
+
134
+ Data_Get_Struct(self, xmlTextReader, reader);
135
+
136
+ attr = rb_hash_new() ;
137
+
138
+ if (! has_attributes(reader)) {
139
+ return attr ;
140
+ }
141
+
142
+ ptr = xmlTextReaderExpand(reader);
143
+ if (ptr == NULL) { return Qnil; }
144
+
145
+ Nokogiri_xml_node_namespaces(ptr, attr);
146
+
147
+ return attr ;
148
+ }
149
+
150
+ /*
151
+ :call-seq: attribute_nodes() → Array<Nokogiri::XML::Attr>
152
+
153
+ Get the attributes of the current node as an Array of Attr
154
+ */
155
+ static VALUE
156
+ rb_xml_reader_attribute_nodes(VALUE rb_reader)
157
+ {
158
+ xmlTextReaderPtr c_reader;
159
+ xmlNodePtr c_node;
160
+ VALUE attr_nodes;
161
+ int j;
162
+
163
+ Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
164
+
165
+ if (! has_attributes(c_reader)) {
166
+ return rb_ary_new() ;
167
+ }
168
+
169
+ c_node = xmlTextReaderExpand(c_reader);
170
+ if (c_node == NULL) {
171
+ return Qnil;
172
+ }
173
+
174
+ attr_nodes = noko_xml_node_attrs(c_node);
175
+
176
+ /* ensure that the Reader won't be GCed as long as a node is referenced */
177
+ for (j = 0 ; j < RARRAY_LEN(attr_nodes) ; j++) {
178
+ rb_iv_set(rb_ary_entry(attr_nodes, j), "@reader", rb_reader);
179
+ }
180
+
181
+ return attr_nodes;
182
+ }
183
+
184
+ /*
185
+ * call-seq:
186
+ * attribute_at(index)
187
+ *
188
+ * Get the value of attribute at +index+
189
+ */
190
+ static VALUE
191
+ attribute_at(VALUE self, VALUE index)
192
+ {
193
+ xmlTextReaderPtr reader;
194
+ xmlChar *value;
195
+ VALUE rb_value;
196
+
197
+ Data_Get_Struct(self, xmlTextReader, reader);
198
+
199
+ if (NIL_P(index)) { return Qnil; }
200
+ index = rb_Integer(index);
201
+
202
+ value = xmlTextReaderGetAttributeNo(
203
+ reader,
204
+ (int)NUM2INT(index)
205
+ );
206
+ if (value == NULL) { return Qnil; }
207
+
208
+ rb_value = NOKOGIRI_STR_NEW2(value);
209
+ xmlFree(value);
210
+ return rb_value;
211
+ }
212
+
213
+ /*
214
+ * call-seq:
215
+ * attribute(name)
216
+ *
217
+ * Get the value of attribute named +name+
218
+ */
219
+ static VALUE
220
+ reader_attribute(VALUE self, VALUE name)
221
+ {
222
+ xmlTextReaderPtr reader;
223
+ xmlChar *value ;
224
+ VALUE rb_value;
225
+
226
+ Data_Get_Struct(self, xmlTextReader, reader);
227
+
228
+ if (NIL_P(name)) { return Qnil; }
229
+ name = StringValue(name) ;
230
+
231
+ value = xmlTextReaderGetAttribute(reader, (xmlChar *)StringValueCStr(name));
232
+ if (value == NULL) { return Qnil; }
233
+
234
+ rb_value = NOKOGIRI_STR_NEW2(value);
235
+ xmlFree(value);
236
+ return rb_value;
237
+ }
238
+
239
+ /*
240
+ * call-seq:
241
+ * attribute_count
242
+ *
243
+ * Get the number of attributes for the current node
244
+ */
245
+ static VALUE
246
+ attribute_count(VALUE self)
247
+ {
248
+ xmlTextReaderPtr reader;
249
+ int count;
250
+
251
+ Data_Get_Struct(self, xmlTextReader, reader);
252
+ count = xmlTextReaderAttributeCount(reader);
253
+ if (count == -1) { return Qnil; }
254
+
255
+ return INT2NUM((long)count);
256
+ }
257
+
258
+ /*
259
+ * call-seq:
260
+ * depth
261
+ *
262
+ * Get the depth of the node
263
+ */
264
+ static VALUE
265
+ depth(VALUE self)
266
+ {
267
+ xmlTextReaderPtr reader;
268
+ int depth;
269
+
270
+ Data_Get_Struct(self, xmlTextReader, reader);
271
+ depth = xmlTextReaderDepth(reader);
272
+ if (depth == -1) { return Qnil; }
273
+
274
+ return INT2NUM((long)depth);
275
+ }
276
+
277
+ /*
278
+ * call-seq:
279
+ * xml_version
280
+ *
281
+ * Get the XML version of the document being read
282
+ */
283
+ static VALUE
284
+ xml_version(VALUE self)
285
+ {
286
+ xmlTextReaderPtr reader;
287
+ const char *version;
288
+
289
+ Data_Get_Struct(self, xmlTextReader, reader);
290
+ version = (const char *)xmlTextReaderConstXmlVersion(reader);
291
+ if (version == NULL) { return Qnil; }
292
+
293
+ return NOKOGIRI_STR_NEW2(version);
294
+ }
295
+
296
+ /*
297
+ * call-seq:
298
+ * lang
299
+ *
300
+ * Get the xml:lang scope within which the node resides.
301
+ */
302
+ static VALUE
303
+ lang(VALUE self)
304
+ {
305
+ xmlTextReaderPtr reader;
306
+ const char *lang;
307
+
308
+ Data_Get_Struct(self, xmlTextReader, reader);
309
+ lang = (const char *)xmlTextReaderConstXmlLang(reader);
310
+ if (lang == NULL) { return Qnil; }
311
+
312
+ return NOKOGIRI_STR_NEW2(lang);
313
+ }
314
+
315
+ /*
316
+ * call-seq:
317
+ * value
318
+ *
319
+ * Get the text value of the node if present. Returns a utf-8 encoded string.
320
+ */
321
+ static VALUE
322
+ value(VALUE self)
323
+ {
324
+ xmlTextReaderPtr reader;
325
+ const char *value;
326
+
327
+ Data_Get_Struct(self, xmlTextReader, reader);
328
+ value = (const char *)xmlTextReaderConstValue(reader);
329
+ if (value == NULL) { return Qnil; }
330
+
331
+ return NOKOGIRI_STR_NEW2(value);
332
+ }
333
+
334
+ /*
335
+ * call-seq:
336
+ * prefix
337
+ *
338
+ * Get the shorthand reference to the namespace associated with the node.
339
+ */
340
+ static VALUE
341
+ prefix(VALUE self)
342
+ {
343
+ xmlTextReaderPtr reader;
344
+ const char *prefix;
345
+
346
+ Data_Get_Struct(self, xmlTextReader, reader);
347
+ prefix = (const char *)xmlTextReaderConstPrefix(reader);
348
+ if (prefix == NULL) { return Qnil; }
349
+
350
+ return NOKOGIRI_STR_NEW2(prefix);
351
+ }
352
+
353
+ /*
354
+ * call-seq:
355
+ * namespace_uri
356
+ *
357
+ * Get the URI defining the namespace associated with the node
358
+ */
359
+ static VALUE
360
+ namespace_uri(VALUE self)
361
+ {
362
+ xmlTextReaderPtr reader;
363
+ const char *uri;
364
+
365
+ Data_Get_Struct(self, xmlTextReader, reader);
366
+ uri = (const char *)xmlTextReaderConstNamespaceUri(reader);
367
+ if (uri == NULL) { return Qnil; }
368
+
369
+ return NOKOGIRI_STR_NEW2(uri);
370
+ }
371
+
372
+ /*
373
+ * call-seq:
374
+ * local_name
375
+ *
376
+ * Get the local name of the node
377
+ */
378
+ static VALUE
379
+ local_name(VALUE self)
380
+ {
381
+ xmlTextReaderPtr reader;
382
+ const char *name;
383
+
384
+ Data_Get_Struct(self, xmlTextReader, reader);
385
+ name = (const char *)xmlTextReaderConstLocalName(reader);
386
+ if (name == NULL) { return Qnil; }
387
+
388
+ return NOKOGIRI_STR_NEW2(name);
389
+ }
390
+
391
+ /*
392
+ * call-seq:
393
+ * name
394
+ *
395
+ * Get the name of the node. Returns a utf-8 encoded string.
396
+ */
397
+ static VALUE
398
+ name(VALUE self)
399
+ {
400
+ xmlTextReaderPtr reader;
401
+ const char *name;
402
+
403
+ Data_Get_Struct(self, xmlTextReader, reader);
404
+ name = (const char *)xmlTextReaderConstName(reader);
405
+ if (name == NULL) { return Qnil; }
406
+
407
+ return NOKOGIRI_STR_NEW2(name);
408
+ }
409
+
410
+ /*
411
+ * call-seq:
412
+ * base_uri
413
+ *
414
+ * Get the xml:base of the node
415
+ */
416
+ static VALUE
417
+ rb_xml_reader_base_uri(VALUE rb_reader)
418
+ {
419
+ VALUE rb_base_uri;
420
+ xmlTextReaderPtr c_reader;
421
+ xmlChar *c_base_uri;
422
+
423
+ Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
424
+
425
+ c_base_uri = xmlTextReaderBaseUri(c_reader);
426
+ if (c_base_uri == NULL) {
427
+ return Qnil;
428
+ }
429
+
430
+ rb_base_uri = NOKOGIRI_STR_NEW2(c_base_uri);
431
+ xmlFree(c_base_uri);
432
+
433
+ return rb_base_uri;
434
+ }
435
+
436
+ /*
437
+ * call-seq:
438
+ * state
439
+ *
440
+ * Get the state of the reader
441
+ */
442
+ static VALUE
443
+ state(VALUE self)
444
+ {
445
+ xmlTextReaderPtr reader;
446
+ Data_Get_Struct(self, xmlTextReader, reader);
447
+ return INT2NUM((long)xmlTextReaderReadState(reader));
448
+ }
449
+
450
+ /*
451
+ * call-seq:
452
+ * node_type
453
+ *
454
+ * Get the type of readers current node
455
+ */
456
+ static VALUE
457
+ node_type(VALUE self)
458
+ {
459
+ xmlTextReaderPtr reader;
460
+ Data_Get_Struct(self, xmlTextReader, reader);
461
+ return INT2NUM((long)xmlTextReaderNodeType(reader));
462
+ }
463
+
464
+ /*
465
+ * call-seq:
466
+ * read
467
+ *
468
+ * Move the Reader forward through the XML document.
469
+ */
470
+ static VALUE
471
+ read_more(VALUE self)
472
+ {
473
+ xmlTextReaderPtr reader;
474
+ xmlErrorPtr error;
475
+ VALUE error_list;
476
+ int ret;
477
+
478
+ Data_Get_Struct(self, xmlTextReader, reader);
479
+
480
+ error_list = rb_funcall(self, rb_intern("errors"), 0);
481
+
482
+ xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
483
+ ret = xmlTextReaderRead(reader);
484
+ xmlSetStructuredErrorFunc(NULL, NULL);
485
+
486
+ if (ret == 1) { return self; }
487
+ if (ret == 0) { return Qnil; }
488
+
489
+ error = xmlGetLastError();
490
+ if (error) {
491
+ rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
492
+ } else {
493
+ rb_raise(rb_eRuntimeError, "Error pulling: %d", ret);
494
+ }
495
+
496
+ return Qnil;
497
+ }
498
+
499
+ /*
500
+ * call-seq:
501
+ * inner_xml
502
+ *
503
+ * Read the contents of the current node, including child nodes and markup.
504
+ * Returns a utf-8 encoded string.
505
+ */
506
+ static VALUE
507
+ inner_xml(VALUE self)
508
+ {
509
+ xmlTextReaderPtr reader;
510
+ xmlChar *value;
511
+ VALUE str;
512
+
513
+ Data_Get_Struct(self, xmlTextReader, reader);
514
+
515
+ value = xmlTextReaderReadInnerXml(reader);
516
+
517
+ str = Qnil;
518
+ if (value) {
519
+ str = NOKOGIRI_STR_NEW2((char *)value);
520
+ xmlFree(value);
521
+ }
522
+
523
+ return str;
524
+ }
525
+
526
+ /*
527
+ * call-seq:
528
+ * outer_xml
529
+ *
530
+ * Read the current node and its contents, including child nodes and markup.
531
+ * Returns a utf-8 encoded string.
532
+ */
533
+ static VALUE
534
+ outer_xml(VALUE self)
535
+ {
536
+ xmlTextReaderPtr reader;
537
+ xmlChar *value;
538
+ VALUE str = Qnil;
539
+
540
+ Data_Get_Struct(self, xmlTextReader, reader);
541
+
542
+ value = xmlTextReaderReadOuterXml(reader);
543
+
544
+ if (value) {
545
+ str = NOKOGIRI_STR_NEW2((char *)value);
546
+ xmlFree(value);
547
+ }
548
+ return str;
549
+ }
550
+
551
+ /*
552
+ * call-seq:
553
+ * from_memory(string, url = nil, encoding = nil, options = 0)
554
+ *
555
+ * Create a new reader that parses +string+
556
+ */
557
+ static VALUE
558
+ from_memory(int argc, VALUE *argv, VALUE klass)
559
+ {
560
+ VALUE rb_buffer, rb_url, encoding, rb_options;
561
+ xmlTextReaderPtr reader;
562
+ const char *c_url = NULL;
563
+ const char *c_encoding = NULL;
564
+ int c_options = 0;
565
+ VALUE rb_reader, args[3];
566
+
567
+ rb_scan_args(argc, argv, "13", &rb_buffer, &rb_url, &encoding, &rb_options);
568
+
569
+ if (!RTEST(rb_buffer)) { rb_raise(rb_eArgError, "string cannot be nil"); }
570
+ if (RTEST(rb_url)) { c_url = StringValueCStr(rb_url); }
571
+ if (RTEST(encoding)) { c_encoding = StringValueCStr(encoding); }
572
+ if (RTEST(rb_options)) { c_options = (int)NUM2INT(rb_options); }
573
+
574
+ reader = xmlReaderForMemory(
575
+ StringValuePtr(rb_buffer),
576
+ (int)RSTRING_LEN(rb_buffer),
577
+ c_url,
578
+ c_encoding,
579
+ c_options
580
+ );
581
+
582
+ if (reader == NULL) {
583
+ xmlFreeTextReader(reader);
584
+ rb_raise(rb_eRuntimeError, "couldn't create a parser");
585
+ }
586
+
587
+ rb_reader = Data_Wrap_Struct(klass, NULL, dealloc, reader);
588
+ args[0] = rb_buffer;
589
+ args[1] = rb_url;
590
+ args[2] = encoding;
591
+ rb_obj_call_init(rb_reader, 3, args);
592
+
593
+ return rb_reader;
594
+ }
595
+
596
+ /*
597
+ * call-seq:
598
+ * from_io(io, url = nil, encoding = nil, options = 0)
599
+ *
600
+ * Create a new reader that parses +io+
601
+ */
602
+ static VALUE
603
+ from_io(int argc, VALUE *argv, VALUE klass)
604
+ {
605
+ VALUE rb_io, rb_url, encoding, rb_options;
606
+ xmlTextReaderPtr reader;
607
+ const char *c_url = NULL;
608
+ const char *c_encoding = NULL;
609
+ int c_options = 0;
610
+ VALUE rb_reader, args[3];
611
+
612
+ rb_scan_args(argc, argv, "13", &rb_io, &rb_url, &encoding, &rb_options);
613
+
614
+ if (!RTEST(rb_io)) { rb_raise(rb_eArgError, "io cannot be nil"); }
615
+ if (RTEST(rb_url)) { c_url = StringValueCStr(rb_url); }
616
+ if (RTEST(encoding)) { c_encoding = StringValueCStr(encoding); }
617
+ if (RTEST(rb_options)) { c_options = (int)NUM2INT(rb_options); }
618
+
619
+ reader = xmlReaderForIO(
620
+ (xmlInputReadCallback)noko_io_read,
621
+ (xmlInputCloseCallback)noko_io_close,
622
+ (void *)rb_io,
623
+ c_url,
624
+ c_encoding,
625
+ c_options
626
+ );
627
+
628
+ if (reader == NULL) {
629
+ xmlFreeTextReader(reader);
630
+ rb_raise(rb_eRuntimeError, "couldn't create a parser");
631
+ }
632
+
633
+ rb_reader = Data_Wrap_Struct(klass, NULL, dealloc, reader);
634
+ args[0] = rb_io;
635
+ args[1] = rb_url;
636
+ args[2] = encoding;
637
+ rb_obj_call_init(rb_reader, 3, args);
638
+
639
+ return rb_reader;
640
+ }
641
+
642
+ /*
643
+ * call-seq:
644
+ * reader.empty_element? # => true or false
645
+ *
646
+ * Returns true if the current node is empty, otherwise false.
647
+ */
648
+ static VALUE
649
+ empty_element_p(VALUE self)
650
+ {
651
+ xmlTextReaderPtr reader;
652
+
653
+ Data_Get_Struct(self, xmlTextReader, reader);
654
+
655
+ if (xmlTextReaderIsEmptyElement(reader)) {
656
+ return Qtrue;
657
+ }
658
+
659
+ return Qfalse;
660
+ }
661
+
662
+ static VALUE
663
+ rb_xml_reader_encoding(VALUE rb_reader)
664
+ {
665
+ xmlTextReaderPtr c_reader;
666
+ const char *parser_encoding;
667
+ VALUE constructor_encoding;
668
+
669
+ constructor_encoding = rb_iv_get(rb_reader, "@encoding");
670
+ if (RTEST(constructor_encoding)) {
671
+ return constructor_encoding;
672
+ }
673
+
674
+ Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
675
+ parser_encoding = (const char *)xmlTextReaderConstEncoding(c_reader);
676
+ if (parser_encoding == NULL) { return Qnil; }
677
+ return NOKOGIRI_STR_NEW2(parser_encoding);
678
+ }
679
+
680
+ void
681
+ noko_init_xml_reader()
682
+ {
683
+ /*
684
+ * The Reader parser allows you to effectively pull parse an XML document.
685
+ * Once instantiated, call Nokogiri::XML::Reader#each to iterate over each
686
+ * node. Note that you may only iterate over the document once!
687
+ */
688
+ cNokogiriXmlReader = rb_define_class_under(mNokogiriXml, "Reader", rb_cObject);
689
+
690
+ rb_undef_alloc_func(cNokogiriXmlReader);
691
+
692
+ rb_define_singleton_method(cNokogiriXmlReader, "from_memory", from_memory, -1);
693
+ rb_define_singleton_method(cNokogiriXmlReader, "from_io", from_io, -1);
694
+
695
+ rb_define_method(cNokogiriXmlReader, "attribute", reader_attribute, 1);
696
+ rb_define_method(cNokogiriXmlReader, "attribute_at", attribute_at, 1);
697
+ rb_define_method(cNokogiriXmlReader, "attribute_count", attribute_count, 0);
698
+ rb_define_method(cNokogiriXmlReader, "attribute_nodes", rb_xml_reader_attribute_nodes, 0);
699
+ rb_define_method(cNokogiriXmlReader, "attributes?", attributes_eh, 0);
700
+ rb_define_method(cNokogiriXmlReader, "base_uri", rb_xml_reader_base_uri, 0);
701
+ rb_define_method(cNokogiriXmlReader, "default?", default_eh, 0);
702
+ rb_define_method(cNokogiriXmlReader, "depth", depth, 0);
703
+ rb_define_method(cNokogiriXmlReader, "empty_element?", empty_element_p, 0);
704
+ rb_define_method(cNokogiriXmlReader, "encoding", rb_xml_reader_encoding, 0);
705
+ rb_define_method(cNokogiriXmlReader, "inner_xml", inner_xml, 0);
706
+ rb_define_method(cNokogiriXmlReader, "lang", lang, 0);
707
+ rb_define_method(cNokogiriXmlReader, "local_name", local_name, 0);
708
+ rb_define_method(cNokogiriXmlReader, "name", name, 0);
709
+ rb_define_method(cNokogiriXmlReader, "namespace_uri", namespace_uri, 0);
710
+ rb_define_method(cNokogiriXmlReader, "namespaces", namespaces, 0);
711
+ rb_define_method(cNokogiriXmlReader, "node_type", node_type, 0);
712
+ rb_define_method(cNokogiriXmlReader, "outer_xml", outer_xml, 0);
713
+ rb_define_method(cNokogiriXmlReader, "prefix", prefix, 0);
714
+ rb_define_method(cNokogiriXmlReader, "read", read_more, 0);
715
+ rb_define_method(cNokogiriXmlReader, "state", state, 0);
716
+ rb_define_method(cNokogiriXmlReader, "value", value, 0);
717
+ rb_define_method(cNokogiriXmlReader, "value?", value_eh, 0);
718
+ rb_define_method(cNokogiriXmlReader, "xml_version", xml_version, 0);
719
+ }