nokogiri 1.13.0-aarch64-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 (198) 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/2.6/nokogiri.so +0 -0
  121. data/lib/nokogiri/2.7/nokogiri.so +0 -0
  122. data/lib/nokogiri/3.0/nokogiri.so +0 -0
  123. data/lib/nokogiri/3.1/nokogiri.so +0 -0
  124. data/lib/nokogiri/class_resolver.rb +67 -0
  125. data/lib/nokogiri/css/node.rb +54 -0
  126. data/lib/nokogiri/css/parser.rb +759 -0
  127. data/lib/nokogiri/css/parser.y +280 -0
  128. data/lib/nokogiri/css/parser_extras.rb +94 -0
  129. data/lib/nokogiri/css/syntax_error.rb +9 -0
  130. data/lib/nokogiri/css/tokenizer.rb +155 -0
  131. data/lib/nokogiri/css/tokenizer.rex +56 -0
  132. data/lib/nokogiri/css/xpath_visitor.rb +359 -0
  133. data/lib/nokogiri/css.rb +60 -0
  134. data/lib/nokogiri/decorators/slop.rb +44 -0
  135. data/lib/nokogiri/extension.rb +31 -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 +331 -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 +578 -0
  143. data/lib/nokogiri/html4/entity_lookup.rb +15 -0
  144. data/lib/nokogiri/html4/sax/parser.rb +61 -0
  145. data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
  146. data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
  147. data/lib/nokogiri/html4.rb +46 -0
  148. data/lib/nokogiri/html5/document.rb +88 -0
  149. data/lib/nokogiri/html5/document_fragment.rb +83 -0
  150. data/lib/nokogiri/html5/node.rb +96 -0
  151. data/lib/nokogiri/html5.rb +477 -0
  152. data/lib/nokogiri/jruby/dependencies.rb +21 -0
  153. data/lib/nokogiri/syntax_error.rb +6 -0
  154. data/lib/nokogiri/version/constant.rb +6 -0
  155. data/lib/nokogiri/version/info.rb +221 -0
  156. data/lib/nokogiri/version.rb +4 -0
  157. data/lib/nokogiri/xml/attr.rb +17 -0
  158. data/lib/nokogiri/xml/attribute_decl.rb +20 -0
  159. data/lib/nokogiri/xml/builder.rb +485 -0
  160. data/lib/nokogiri/xml/cdata.rb +13 -0
  161. data/lib/nokogiri/xml/character_data.rb +9 -0
  162. data/lib/nokogiri/xml/document.rb +418 -0
  163. data/lib/nokogiri/xml/document_fragment.rb +162 -0
  164. data/lib/nokogiri/xml/dtd.rb +34 -0
  165. data/lib/nokogiri/xml/element_content.rb +38 -0
  166. data/lib/nokogiri/xml/element_decl.rb +15 -0
  167. data/lib/nokogiri/xml/entity_decl.rb +21 -0
  168. data/lib/nokogiri/xml/entity_reference.rb +20 -0
  169. data/lib/nokogiri/xml/namespace.rb +16 -0
  170. data/lib/nokogiri/xml/node/save_options.rb +65 -0
  171. data/lib/nokogiri/xml/node.rb +1402 -0
  172. data/lib/nokogiri/xml/node_set.rb +364 -0
  173. data/lib/nokogiri/xml/notation.rb +19 -0
  174. data/lib/nokogiri/xml/parse_options.rb +133 -0
  175. data/lib/nokogiri/xml/pp/character_data.rb +21 -0
  176. data/lib/nokogiri/xml/pp/node.rb +55 -0
  177. data/lib/nokogiri/xml/pp.rb +4 -0
  178. data/lib/nokogiri/xml/processing_instruction.rb +10 -0
  179. data/lib/nokogiri/xml/reader.rb +107 -0
  180. data/lib/nokogiri/xml/relax_ng.rb +38 -0
  181. data/lib/nokogiri/xml/sax/document.rb +167 -0
  182. data/lib/nokogiri/xml/sax/parser.rb +125 -0
  183. data/lib/nokogiri/xml/sax/parser_context.rb +21 -0
  184. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  185. data/lib/nokogiri/xml/sax.rb +6 -0
  186. data/lib/nokogiri/xml/schema.rb +73 -0
  187. data/lib/nokogiri/xml/searchable.rb +259 -0
  188. data/lib/nokogiri/xml/syntax_error.rb +71 -0
  189. data/lib/nokogiri/xml/text.rb +11 -0
  190. data/lib/nokogiri/xml/xpath/syntax_error.rb +13 -0
  191. data/lib/nokogiri/xml/xpath.rb +21 -0
  192. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  193. data/lib/nokogiri/xml.rb +75 -0
  194. data/lib/nokogiri/xslt/stylesheet.rb +27 -0
  195. data/lib/nokogiri/xslt.rb +58 -0
  196. data/lib/nokogiri.rb +128 -0
  197. data/lib/xsd/xmlparser/nokogiri.rb +104 -0
  198. metadata +539 -0
@@ -0,0 +1,364 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ ####
6
+ # A NodeSet contains a list of Nokogiri::XML::Node objects. Typically
7
+ # a NodeSet is return as a result of searching a Document via
8
+ # Nokogiri::XML::Searchable#css or Nokogiri::XML::Searchable#xpath
9
+ class NodeSet
10
+ include Nokogiri::XML::Searchable
11
+ include Enumerable
12
+
13
+ # The Document this NodeSet is associated with
14
+ attr_accessor :document
15
+
16
+ alias_method :clone, :dup
17
+
18
+ # Create a NodeSet with +document+ defaulting to +list+
19
+ def initialize(document, list = [])
20
+ @document = document
21
+ document.decorate(self)
22
+ list.each { |x| self << x }
23
+ yield self if block_given?
24
+ end
25
+
26
+ ###
27
+ # Get the first element of the NodeSet.
28
+ def first(n = nil)
29
+ return self[0] unless n
30
+ list = []
31
+ [n, length].min.times { |i| list << self[i] }
32
+ list
33
+ end
34
+
35
+ ###
36
+ # Get the last element of the NodeSet.
37
+ def last
38
+ self[-1]
39
+ end
40
+
41
+ ###
42
+ # Is this NodeSet empty?
43
+ def empty?
44
+ length == 0
45
+ end
46
+
47
+ ###
48
+ # Returns the index of the first node in self that is == to +node+ or meets the given block. Returns nil if no match is found.
49
+ def index(node = nil)
50
+ if node
51
+ warn("given block not used") if block_given?
52
+ each_with_index { |member, j| return j if member == node }
53
+ elsif block_given?
54
+ each_with_index { |member, j| return j if yield(member) }
55
+ end
56
+ nil
57
+ end
58
+
59
+ ###
60
+ # Insert +datum+ before the first Node in this NodeSet
61
+ def before(datum)
62
+ first.before(datum)
63
+ end
64
+
65
+ ###
66
+ # Insert +datum+ after the last Node in this NodeSet
67
+ def after(datum)
68
+ last.after(datum)
69
+ end
70
+
71
+ alias_method :<<, :push
72
+ alias_method :remove, :unlink
73
+
74
+ ###
75
+ # call-seq: css *rules, [namespace-bindings, custom-pseudo-class]
76
+ #
77
+ # Search this node set for CSS +rules+. +rules+ must be one or more CSS
78
+ # selectors. For example:
79
+ #
80
+ # For more information see Nokogiri::XML::Searchable#css
81
+ def css(*args)
82
+ rules, handler, ns, _ = extract_params(args)
83
+ paths = css_rules_to_xpath(rules, ns)
84
+
85
+ inject(NodeSet.new(document)) do |set, node|
86
+ set + xpath_internal(node, paths, handler, ns, nil)
87
+ end
88
+ end
89
+
90
+ ###
91
+ # call-seq: xpath *paths, [namespace-bindings, variable-bindings, custom-handler-class]
92
+ #
93
+ # Search this node set for XPath +paths+. +paths+ must be one or more XPath
94
+ # queries.
95
+ #
96
+ # For more information see Nokogiri::XML::Searchable#xpath
97
+ def xpath(*args)
98
+ paths, handler, ns, binds = extract_params(args)
99
+
100
+ inject(NodeSet.new(document)) do |set, node|
101
+ set + xpath_internal(node, paths, handler, ns, binds)
102
+ end
103
+ end
104
+
105
+ ###
106
+ # call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
107
+ #
108
+ # Search this object for +paths+, and return only the first
109
+ # result. +paths+ must be one or more XPath or CSS queries.
110
+ #
111
+ # See Searchable#search for more information.
112
+ #
113
+ # Or, if passed an integer, index into the NodeSet:
114
+ #
115
+ # node_set.at(3) # same as node_set[3]
116
+ #
117
+ def at(*args)
118
+ if args.length == 1 && args.first.is_a?(Numeric)
119
+ return self[args.first]
120
+ end
121
+
122
+ super(*args)
123
+ end
124
+ alias_method :%, :at
125
+
126
+ ###
127
+ # Filter this list for nodes that match +expr+
128
+ def filter(expr)
129
+ find_all { |node| node.matches?(expr) }
130
+ end
131
+
132
+ ###
133
+ # Add the class attribute +name+ to all Node objects in the
134
+ # NodeSet.
135
+ #
136
+ # See Nokogiri::XML::Node#add_class for more information.
137
+ def add_class(name)
138
+ each do |el|
139
+ el.add_class(name)
140
+ end
141
+ self
142
+ end
143
+
144
+ ###
145
+ # Append the class attribute +name+ to all Node objects in the
146
+ # NodeSet.
147
+ #
148
+ # See Nokogiri::XML::Node#append_class for more information.
149
+ def append_class(name)
150
+ each do |el|
151
+ el.append_class(name)
152
+ end
153
+ self
154
+ end
155
+
156
+ ###
157
+ # Remove the class attribute +name+ from all Node objects in the
158
+ # NodeSet.
159
+ #
160
+ # See Nokogiri::XML::Node#remove_class for more information.
161
+ def remove_class(name = nil)
162
+ each do |el|
163
+ el.remove_class(name)
164
+ end
165
+ self
166
+ end
167
+
168
+ ###
169
+ # Set attributes on each Node in the NodeSet, or get an
170
+ # attribute from the first Node in the NodeSet.
171
+ #
172
+ # To get an attribute from the first Node in a NodeSet:
173
+ #
174
+ # node_set.attr("href") # => "https://www.nokogiri.org"
175
+ #
176
+ # Note that an empty NodeSet will return nil when +#attr+ is called as a getter.
177
+ #
178
+ # To set an attribute on each node, +key+ can either be an
179
+ # attribute name, or a Hash of attribute names and values. When
180
+ # called as a setter, +#attr+ returns the NodeSet.
181
+ #
182
+ # If +key+ is an attribute name, then either +value+ or +block+
183
+ # must be passed.
184
+ #
185
+ # If +key+ is a Hash then attributes will be set for each
186
+ # key/value pair:
187
+ #
188
+ # node_set.attr("href" => "https://www.nokogiri.org", "class" => "member")
189
+ #
190
+ # If +value+ is passed, it will be used as the attribute value
191
+ # for all nodes:
192
+ #
193
+ # node_set.attr("href", "https://www.nokogiri.org")
194
+ #
195
+ # If +block+ is passed, it will be called on each Node object in
196
+ # the NodeSet and the return value used as the attribute value
197
+ # for that node:
198
+ #
199
+ # node_set.attr("class") { |node| node.name }
200
+ #
201
+ def attr(key, value = nil, &block)
202
+ unless key.is_a?(Hash) || (key && (value || block))
203
+ return first ? first.attribute(key) : nil
204
+ end
205
+
206
+ hash = key.is_a?(Hash) ? key : { key => value }
207
+
208
+ hash.each do |k, v|
209
+ each do |node|
210
+ node[k] = v || yield(node)
211
+ end
212
+ end
213
+
214
+ self
215
+ end
216
+ alias_method :set, :attr
217
+ alias_method :attribute, :attr
218
+
219
+ ###
220
+ # Remove the attributed named +name+ from all Node objects in the NodeSet
221
+ def remove_attr(name)
222
+ each { |el| el.delete(name) }
223
+ self
224
+ end
225
+ alias_method :remove_attribute, :remove_attr
226
+
227
+ ###
228
+ # Iterate over each node, yielding to +block+
229
+ def each
230
+ return to_enum unless block_given?
231
+
232
+ 0.upto(length - 1) do |x|
233
+ yield self[x]
234
+ end
235
+ self
236
+ end
237
+
238
+ ###
239
+ # Get the inner text of all contained Node objects
240
+ #
241
+ # Note: This joins the text of all Node objects in the NodeSet:
242
+ #
243
+ # doc = Nokogiri::XML('<xml><a><d>foo</d><d>bar</d></a></xml>')
244
+ # doc.css('d').text # => "foobar"
245
+ #
246
+ # Instead, if you want to return the text of all nodes in the NodeSet:
247
+ #
248
+ # doc.css('d').map(&:text) # => ["foo", "bar"]
249
+ #
250
+ # See Nokogiri::XML::Node#content for more information.
251
+ def inner_text
252
+ collect(&:inner_text).join("")
253
+ end
254
+ alias_method :text, :inner_text
255
+
256
+ ###
257
+ # Get the inner html of all contained Node objects
258
+ def inner_html(*args)
259
+ collect { |j| j.inner_html(*args) }.join("")
260
+ end
261
+
262
+ ###
263
+ # Wrap this NodeSet with +html+
264
+ def wrap(html)
265
+ map { |node| node.wrap(html) }
266
+ end
267
+
268
+ ###
269
+ # Convert this NodeSet to a string.
270
+ def to_s
271
+ map(&:to_s).join
272
+ end
273
+
274
+ ###
275
+ # Convert this NodeSet to HTML
276
+ def to_html(*args)
277
+ if Nokogiri.jruby?
278
+ options = args.first.is_a?(Hash) ? args.shift : {}
279
+ unless options[:save_with]
280
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
281
+ end
282
+ args.insert(0, options)
283
+ end
284
+ map { |x| x.to_html(*args) }.join
285
+ end
286
+
287
+ ###
288
+ # Convert this NodeSet to XHTML
289
+ def to_xhtml(*args)
290
+ map { |x| x.to_xhtml(*args) }.join
291
+ end
292
+
293
+ ###
294
+ # Convert this NodeSet to XML
295
+ def to_xml(*args)
296
+ map { |x| x.to_xml(*args) }.join
297
+ end
298
+
299
+ alias_method :size, :length
300
+ alias_method :to_ary, :to_a
301
+
302
+ ###
303
+ # Removes the last element from set and returns it, or +nil+ if
304
+ # the set is empty
305
+ def pop
306
+ return nil if length == 0
307
+ delete(last)
308
+ end
309
+
310
+ ###
311
+ # Returns the first element of the NodeSet and removes it. Returns
312
+ # +nil+ if the set is empty.
313
+ def shift
314
+ return nil if length == 0
315
+ delete(first)
316
+ end
317
+
318
+ ###
319
+ # Equality -- Two NodeSets are equal if the contain the same number
320
+ # of elements and if each element is equal to the corresponding
321
+ # element in the other NodeSet
322
+ def ==(other)
323
+ return false unless other.is_a?(Nokogiri::XML::NodeSet)
324
+ return false unless length == other.length
325
+ each_with_index do |node, i|
326
+ return false unless node == other[i]
327
+ end
328
+ true
329
+ end
330
+
331
+ ###
332
+ # Returns a new NodeSet containing all the children of all the nodes in
333
+ # the NodeSet
334
+ def children
335
+ node_set = NodeSet.new(document)
336
+ each do |node|
337
+ node.children.each { |n| node_set.push(n) }
338
+ end
339
+ node_set
340
+ end
341
+
342
+ ###
343
+ # Returns a new NodeSet containing all the nodes in the NodeSet
344
+ # in reverse order
345
+ def reverse
346
+ node_set = NodeSet.new(document)
347
+ (length - 1).downto(0) do |x|
348
+ node_set.push(self[x])
349
+ end
350
+ node_set
351
+ end
352
+
353
+ ###
354
+ # Return a nicely formated string representation
355
+ def inspect
356
+ "[#{map(&:inspect).join(", ")}]"
357
+ end
358
+
359
+ alias_method :+, :|
360
+
361
+ IMPLIED_XPATH_CONTEXTS = [".//", "self::"].freeze # :nodoc:
362
+ end
363
+ end
364
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ # Struct representing an {XML Schema Notation}[https://www.w3.org/TR/xml/#Notations]
6
+ class Notation < Struct.new(:name, :public_id, :system_id)
7
+ # dead comment to ensure rdoc processing
8
+
9
+ # :attr: name (String)
10
+ # The name for the element.
11
+
12
+ # :attr: public_id (String)
13
+ # The URI corresponding to the public identifier
14
+
15
+ # :attr: system_id (String,nil)
16
+ # The URI corresponding to the system identifier
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ ###
6
+ # Parse options for passing to Nokogiri.XML or Nokogiri.HTML
7
+ #
8
+ # == Building combinations of parse options
9
+ # You can build your own combinations of these parse options by using any of the following methods:
10
+ # *Note*: All examples attempt to set the +RECOVER+ & +NOENT+ options.
11
+ # [Ruby's bitwise operators] You can use the Ruby bitwise operators to set various combinations.
12
+ # Nokogiri.XML('<content>Chapter 1</content', nil, nil, Nokogiri::XML::ParseOptions.new((1 << 0) | (1 << 1)))
13
+ # [Method chaining] Every option has an equivalent method in lowercase. You can chain these methods together to set various combinations.
14
+ # Nokogiri.XML('<content>Chapter 1</content', nil, nil, Nokogiri::XML::ParseOptions.new.recover.noent)
15
+ # [Using Ruby Blocks] You can also setup parse combinations in the block passed to Nokogiri.XML or Nokogiri.HTML
16
+ # Nokogiri.XML('<content>Chapter 1</content') {|config| config.recover.noent}
17
+ #
18
+ # == Removing particular parse options
19
+ # You can also remove options from an instance of +ParseOptions+ dynamically.
20
+ # Every option has an equivalent <code>no{option}</code> method in lowercase. You can call these methods on an instance of +ParseOptions+ to remove the option.
21
+ # Note that this is not available for +STRICT+.
22
+ #
23
+ # # Setting the RECOVER & NOENT options...
24
+ # options = Nokogiri::XML::ParseOptions.new.recover.noent
25
+ # # later...
26
+ # options.norecover # Removes the Nokogiri::XML::ParseOptions::RECOVER option
27
+ # options.nonoent # Removes the Nokogiri::XML::ParseOptions::NOENT option
28
+ #
29
+ class ParseOptions
30
+ # Strict parsing
31
+ STRICT = 0
32
+ # Recover from errors
33
+ RECOVER = 1 << 0
34
+ # Substitute entities
35
+ NOENT = 1 << 1
36
+ # Load external subsets
37
+ DTDLOAD = 1 << 2
38
+ # Default DTD attributes
39
+ DTDATTR = 1 << 3
40
+ # validate with the DTD
41
+ DTDVALID = 1 << 4
42
+ # suppress error reports
43
+ NOERROR = 1 << 5
44
+ # suppress warning reports
45
+ NOWARNING = 1 << 6
46
+ # pedantic error reporting
47
+ PEDANTIC = 1 << 7
48
+ # remove blank nodes
49
+ NOBLANKS = 1 << 8
50
+ # use the SAX1 interface internally
51
+ SAX1 = 1 << 9
52
+ # Implement XInclude substitution
53
+ XINCLUDE = 1 << 10
54
+ # Forbid network access. Recommended for dealing with untrusted documents.
55
+ NONET = 1 << 11
56
+ # Do not reuse the context dictionary
57
+ NODICT = 1 << 12
58
+ # remove redundant namespaces declarations
59
+ NSCLEAN = 1 << 13
60
+ # merge CDATA as text nodes
61
+ NOCDATA = 1 << 14
62
+ # do not generate XINCLUDE START/END nodes
63
+ NOXINCNODE = 1 << 15
64
+ # compact small text nodes; no modification of the tree allowed afterwards (will possibly crash if you try to modify the tree)
65
+ COMPACT = 1 << 16
66
+ # parse using XML-1.0 before update 5
67
+ OLD10 = 1 << 17
68
+ # do not fixup XINCLUDE xml:base uris
69
+ NOBASEFIX = 1 << 18
70
+ # relax any hardcoded limit from the parser
71
+ HUGE = 1 << 19
72
+ # line numbers stored as long int (instead of a short int)
73
+ BIG_LINES = 1 << 22
74
+
75
+ # the default options used for parsing XML documents
76
+ DEFAULT_XML = RECOVER | NONET | BIG_LINES
77
+ # the default options used for parsing XSLT stylesheets
78
+ DEFAULT_XSLT = RECOVER | NONET | NOENT | DTDLOAD | DTDATTR | NOCDATA | BIG_LINES
79
+ # the default options used for parsing HTML documents
80
+ DEFAULT_HTML = RECOVER | NOERROR | NOWARNING | NONET | BIG_LINES
81
+ # the default options used for parsing XML schemas
82
+ DEFAULT_SCHEMA = NONET | BIG_LINES
83
+
84
+ attr_accessor :options
85
+
86
+ def initialize(options = STRICT)
87
+ @options = options
88
+ end
89
+
90
+ constants.each do |constant|
91
+ next if constant.to_sym == :STRICT
92
+ class_eval %{
93
+ def #{constant.downcase}
94
+ @options |= #{constant}
95
+ self
96
+ end
97
+
98
+ def no#{constant.downcase}
99
+ @options &= ~#{constant}
100
+ self
101
+ end
102
+
103
+ def #{constant.downcase}?
104
+ #{constant} & @options == #{constant}
105
+ end
106
+ }
107
+ end
108
+
109
+ def strict
110
+ @options &= ~RECOVER
111
+ self
112
+ end
113
+
114
+ def strict?
115
+ @options & RECOVER == STRICT
116
+ end
117
+
118
+ def ==(other)
119
+ other.to_i == to_i
120
+ end
121
+
122
+ alias_method :to_i, :options
123
+
124
+ def inspect
125
+ options = []
126
+ self.class.constants.each do |k|
127
+ options << k.downcase if send(:"#{k.downcase}?")
128
+ end
129
+ super.sub(/>$/, " " + options.join(", ") + ">")
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ # :nodoc: all
6
+ module PP
7
+ module CharacterData
8
+ def pretty_print(pp)
9
+ nice_name = self.class.name.split("::").last
10
+ pp.group(2, "#(#{nice_name} ", ")") do
11
+ pp.pp(text)
12
+ end
13
+ end
14
+
15
+ def inspect
16
+ "#<#{self.class.name}:#{format("0x%x", object_id)} #{text.inspect}>"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ # :nodoc: all
6
+ module PP
7
+ module Node
8
+ def inspect
9
+ attributes = inspect_attributes.reject do |x|
10
+ attribute = send(x)
11
+ !attribute || (attribute.respond_to?(:empty?) && attribute.empty?)
12
+ rescue NoMethodError
13
+ true
14
+ end.map do |attribute|
15
+ "#{attribute.to_s.sub(/_\w+/, "s")}=#{send(attribute).inspect}"
16
+ end.join(" ")
17
+ "#<#{self.class.name}:#{format("0x%x", object_id)} #{attributes}>"
18
+ end
19
+
20
+ def pretty_print(pp)
21
+ nice_name = self.class.name.split("::").last
22
+ pp.group(2, "#(#{nice_name}:#{format("0x%x", object_id)} {", "})") do
23
+ pp.breakable
24
+ attrs = inspect_attributes.map do |t|
25
+ [t, send(t)] if respond_to?(t)
26
+ end.compact.find_all do |x|
27
+ if x.last
28
+ if [:attribute_nodes, :children].include?(x.first)
29
+ !x.last.empty?
30
+ else
31
+ true
32
+ end
33
+ end
34
+ end
35
+
36
+ pp.seplist(attrs) do |v|
37
+ if [:attribute_nodes, :children].include?(v.first)
38
+ pp.group(2, "#{v.first.to_s.sub(/_\w+$/, "s")} = [", "]") do
39
+ pp.breakable
40
+ pp.seplist(v.last) do |item|
41
+ pp.pp(item)
42
+ end
43
+ end
44
+ else
45
+ pp.text("#{v.first} = ")
46
+ pp.pp(v.last)
47
+ end
48
+ end
49
+ pp.breakable
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pp/node"
4
+ require_relative "pp/character_data"
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class ProcessingInstruction < Node
6
+ def initialize(document, name, content)
7
+ end
8
+ end
9
+ end
10
+ end