nokogiri 1.11.1-java → 1.11.2-java

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 (142) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +12 -12
  3. data/LICENSE.md +1 -1
  4. data/README.md +20 -15
  5. data/ext/java/nokogiri/EncodingHandler.java +78 -59
  6. data/ext/java/nokogiri/HtmlDocument.java +137 -114
  7. data/ext/java/nokogiri/HtmlElementDescription.java +104 -87
  8. data/ext/java/nokogiri/HtmlEntityLookup.java +31 -26
  9. data/ext/java/nokogiri/HtmlSaxParserContext.java +220 -192
  10. data/ext/java/nokogiri/HtmlSaxPushParser.java +164 -139
  11. data/ext/java/nokogiri/NokogiriService.java +597 -526
  12. data/ext/java/nokogiri/XmlAttr.java +120 -96
  13. data/ext/java/nokogiri/XmlAttributeDecl.java +97 -76
  14. data/ext/java/nokogiri/XmlCdata.java +35 -26
  15. data/ext/java/nokogiri/XmlComment.java +48 -37
  16. data/ext/java/nokogiri/XmlDocument.java +642 -540
  17. data/ext/java/nokogiri/XmlDocumentFragment.java +127 -107
  18. data/ext/java/nokogiri/XmlDtd.java +450 -384
  19. data/ext/java/nokogiri/XmlElement.java +25 -18
  20. data/ext/java/nokogiri/XmlElementContent.java +345 -286
  21. data/ext/java/nokogiri/XmlElementDecl.java +126 -95
  22. data/ext/java/nokogiri/XmlEntityDecl.java +121 -97
  23. data/ext/java/nokogiri/XmlEntityReference.java +51 -42
  24. data/ext/java/nokogiri/XmlNamespace.java +177 -145
  25. data/ext/java/nokogiri/XmlNode.java +1843 -1588
  26. data/ext/java/nokogiri/XmlNodeSet.java +361 -299
  27. data/ext/java/nokogiri/XmlProcessingInstruction.java +49 -39
  28. data/ext/java/nokogiri/XmlReader.java +513 -418
  29. data/ext/java/nokogiri/XmlRelaxng.java +91 -78
  30. data/ext/java/nokogiri/XmlSaxParserContext.java +330 -285
  31. data/ext/java/nokogiri/XmlSaxPushParser.java +229 -190
  32. data/ext/java/nokogiri/XmlSchema.java +328 -263
  33. data/ext/java/nokogiri/XmlSyntaxError.java +113 -83
  34. data/ext/java/nokogiri/XmlText.java +57 -46
  35. data/ext/java/nokogiri/XmlXpathContext.java +240 -206
  36. data/ext/java/nokogiri/XsltStylesheet.java +282 -239
  37. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  38. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +199 -168
  39. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  40. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  41. data/ext/java/nokogiri/internals/NokogiriDomParser.java +65 -50
  42. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  43. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +25 -18
  44. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -254
  45. data/ext/java/nokogiri/internals/NokogiriHelpers.java +738 -622
  46. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +186 -143
  47. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +83 -68
  48. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +66 -49
  49. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +86 -69
  50. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +44 -29
  51. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +118 -101
  52. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -24
  53. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +25 -17
  54. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +57 -42
  55. data/ext/java/nokogiri/internals/ParserContext.java +206 -179
  56. data/ext/java/nokogiri/internals/ReaderNode.java +478 -371
  57. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -707
  58. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +28 -19
  59. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  60. data/ext/java/nokogiri/internals/XmlDeclHandler.java +5 -4
  61. data/ext/java/nokogiri/internals/XmlDomParserContext.java +208 -177
  62. data/ext/java/nokogiri/internals/XmlSaxParser.java +24 -17
  63. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  64. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  65. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  66. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  67. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  68. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  77. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  78. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  80. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  81. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  82. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  83. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  84. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  85. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  86. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  87. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  88. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  89. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  90. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  91. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -570
  92. data/ext/nokogiri/depend +34 -474
  93. data/ext/nokogiri/extconf.rb +253 -183
  94. data/ext/nokogiri/html_document.c +10 -15
  95. data/ext/nokogiri/html_element_description.c +84 -71
  96. data/ext/nokogiri/html_entity_lookup.c +21 -16
  97. data/ext/nokogiri/html_sax_parser_context.c +66 -65
  98. data/ext/nokogiri/html_sax_push_parser.c +29 -27
  99. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  100. data/ext/nokogiri/nokogiri.c +171 -63
  101. data/ext/nokogiri/test_global_handlers.c +3 -4
  102. data/ext/nokogiri/xml_attr.c +15 -15
  103. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  104. data/ext/nokogiri/xml_cdata.c +13 -18
  105. data/ext/nokogiri/xml_comment.c +19 -26
  106. data/ext/nokogiri/xml_document.c +221 -164
  107. data/ext/nokogiri/xml_document_fragment.c +13 -15
  108. data/ext/nokogiri/xml_dtd.c +54 -48
  109. data/ext/nokogiri/xml_element_content.c +30 -27
  110. data/ext/nokogiri/xml_element_decl.c +22 -22
  111. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  112. data/ext/nokogiri/xml_entity_decl.c +32 -30
  113. data/ext/nokogiri/xml_entity_reference.c +16 -18
  114. data/ext/nokogiri/xml_namespace.c +56 -49
  115. data/ext/nokogiri/xml_node.c +338 -286
  116. data/ext/nokogiri/xml_node_set.c +168 -156
  117. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  118. data/ext/nokogiri/xml_reader.c +191 -157
  119. data/ext/nokogiri/xml_relax_ng.c +29 -23
  120. data/ext/nokogiri/xml_sax_parser.c +117 -112
  121. data/ext/nokogiri/xml_sax_parser_context.c +100 -85
  122. data/ext/nokogiri/xml_sax_push_parser.c +34 -27
  123. data/ext/nokogiri/xml_schema.c +48 -42
  124. data/ext/nokogiri/xml_syntax_error.c +21 -23
  125. data/ext/nokogiri/xml_text.c +13 -17
  126. data/ext/nokogiri/xml_xpath_context.c +134 -127
  127. data/ext/nokogiri/xslt_stylesheet.c +157 -157
  128. data/lib/nokogiri.rb +1 -22
  129. data/lib/nokogiri/css/parser.rb +1 -1
  130. data/lib/nokogiri/extension.rb +26 -0
  131. data/lib/nokogiri/html/document_fragment.rb +15 -15
  132. data/lib/nokogiri/nokogiri.jar +0 -0
  133. data/lib/nokogiri/version/constant.rb +1 -1
  134. data/lib/nokogiri/version/info.rb +31 -8
  135. data/lib/nokogiri/xml/document.rb +31 -11
  136. data/lib/nokogiri/xml/node.rb +38 -42
  137. data/lib/nokogiri/xml/reader.rb +2 -9
  138. data/lib/nokogiri/xml/xpath.rb +1 -3
  139. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  140. metadata +7 -8
  141. data/ext/nokogiri/xml_io.c +0 -63
  142. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
@@ -57,378 +57,440 @@ import org.w3c.dom.NodeList;
57
57
  * @author sergio
58
58
  * @author Yoko Harada <yokolet@gmail.com>
59
59
  */
60
- @JRubyClass(name="Nokogiri::XML::NodeSet")
61
- public class XmlNodeSet extends RubyObject implements NodeList {
62
-
63
- IRubyObject[] nodes;
64
-
65
- public XmlNodeSet(Ruby ruby, RubyClass klazz) {
66
- super(ruby, klazz);
67
- nodes = IRubyObject.NULL_ARRAY;
60
+ @JRubyClass(name = "Nokogiri::XML::NodeSet")
61
+ public class XmlNodeSet extends RubyObject implements NodeList
62
+ {
63
+
64
+ IRubyObject[] nodes;
65
+
66
+ public
67
+ XmlNodeSet(Ruby ruby, RubyClass klazz)
68
+ {
69
+ super(ruby, klazz);
70
+ nodes = IRubyObject.NULL_ARRAY;
71
+ }
72
+
73
+ XmlNodeSet(Ruby ruby, RubyClass klazz, IRubyObject[] nodes)
74
+ {
75
+ super(ruby, klazz);
76
+ this.nodes = nodes;
77
+ }
78
+
79
+ public static XmlNodeSet
80
+ newEmptyNodeSet(ThreadContext context, XmlNodeSet docOwner)
81
+ {
82
+ final Ruby runtime = context.runtime;
83
+ XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
84
+ set.initializeFrom(context, docOwner);
85
+ return set;
86
+ }
87
+
88
+ public static XmlNodeSet
89
+ newEmptyNodeSet(ThreadContext context, XmlNode docOwner)
90
+ {
91
+ final Ruby runtime = context.runtime;
92
+ XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
93
+ set.initialize(runtime, docOwner);
94
+ return set;
95
+ }
96
+
97
+ public static XmlNodeSet
98
+ newNodeSet(Ruby runtime, IRubyObject[] nodes)
99
+ {
100
+ XmlNodeSet xmlNodeSet = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
101
+ xmlNodeSet.setNodes(nodes);
102
+ return xmlNodeSet;
103
+ }
104
+
105
+ public static XmlNodeSet
106
+ newNodeSet(Ruby runtime, IRubyObject[] nodes, XmlNode docOwner)
107
+ {
108
+ XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"), nodes);
109
+ set.initialize(runtime, docOwner);
110
+ return set;
111
+ }
112
+
113
+ /**
114
+ * Create and return a copy of this object.
115
+ *
116
+ * @return a clone of this object
117
+ */
118
+ @Override
119
+ public Object
120
+ clone() throws CloneNotSupportedException
121
+ {
122
+ return super.clone();
123
+ }
124
+
125
+ private void
126
+ setNodes(IRubyObject[] array)
127
+ {
128
+ this.nodes = array;
129
+
130
+ IRubyObject first = array.length > 0 ? array[0] : null;
131
+ initialize(getRuntime(), first);
132
+ }
133
+
134
+ private void
135
+ initializeFrom(ThreadContext context, XmlNodeSet ref)
136
+ {
137
+ IRubyObject document = ref.getInstanceVariable("@document");
138
+ if (document != null && !document.isNil()) {
139
+ initialize(context, (XmlDocument) document);
68
140
  }
69
-
70
- XmlNodeSet(Ruby ruby, RubyClass klazz, IRubyObject[] nodes) {
71
- super(ruby, klazz);
72
- this.nodes = nodes;
73
- }
74
-
75
- public static XmlNodeSet newEmptyNodeSet(ThreadContext context, XmlNodeSet docOwner) {
76
- final Ruby runtime = context.runtime;
77
- XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
78
- set.initializeFrom(context, docOwner);
79
- return set;
80
- }
81
-
82
- public static XmlNodeSet newEmptyNodeSet(ThreadContext context, XmlNode docOwner) {
83
- final Ruby runtime = context.runtime;
84
- XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
85
- set.initialize(runtime, docOwner);
86
- return set;
87
- }
88
-
89
- public static XmlNodeSet newNodeSet(Ruby runtime, IRubyObject[] nodes) {
90
- XmlNodeSet xmlNodeSet = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
91
- xmlNodeSet.setNodes(nodes);
92
- return xmlNodeSet;
141
+ }
142
+
143
+ final void
144
+ initialize(Ruby runtime, IRubyObject refNode)
145
+ {
146
+ if (refNode instanceof XmlNode) {
147
+ XmlDocument doc = ((XmlNode) refNode).document(runtime);
148
+ setDocumentAndDecorate(runtime.getCurrentContext(), this, doc);
93
149
  }
94
-
95
- public static XmlNodeSet newNodeSet(Ruby runtime, IRubyObject[] nodes, XmlNode docOwner) {
96
- XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"), nodes);
97
- set.initialize(runtime, docOwner);
98
- return set;
150
+ }
151
+
152
+ private void
153
+ initialize(ThreadContext context, XmlDocument doc)
154
+ {
155
+ setDocumentAndDecorate(context, this, doc);
156
+ }
157
+
158
+ public int
159
+ length()
160
+ {
161
+ return nodes == null ? 0 : nodes.length;
162
+ }
163
+
164
+ @JRubyMethod(name = "&")
165
+ public IRubyObject
166
+ op_and(ThreadContext context, IRubyObject nodeSet)
167
+ {
168
+ IRubyObject[] otherNodes = getNodes(context, nodeSet);
169
+
170
+ if (otherNodes == null || otherNodes.length == 0) {
171
+ return newEmptyNodeSet(context, this);
99
172
  }
100
173
 
101
- /**
102
- * Create and return a copy of this object.
103
- *
104
- * @return a clone of this object
105
- */
106
- @Override
107
- public Object clone() throws CloneNotSupportedException {
108
- return super.clone();
174
+ if (nodes == null || nodes.length == 0) {
175
+ return newEmptyNodeSet(context, this);
109
176
  }
110
177
 
111
- private void setNodes(IRubyObject[] array) {
112
- this.nodes = array;
113
-
114
- IRubyObject first = array.length > 0 ? array[0] : null;
115
- initialize(getRuntime(), first);
116
- }
178
+ IRubyObject[] curr = nodes;
179
+ IRubyObject[] other = getNodes(context, nodeSet);
180
+ IRubyObject[] result = new IRubyObject[nodes.length];
117
181
 
118
- private void initializeFrom(ThreadContext context, XmlNodeSet ref) {
119
- IRubyObject document = ref.getInstanceVariable("@document");
120
- if (document != null && !document.isNil()) {
121
- initialize(context, (XmlDocument) document);
122
- }
123
- }
182
+ int last = 0;
183
+ outer:
184
+ for (int i = 0; i < curr.length; i++) {
185
+ IRubyObject n = curr[i];
124
186
 
125
- final void initialize(Ruby runtime, IRubyObject refNode) {
126
- if (refNode instanceof XmlNode) {
127
- XmlDocument doc = ((XmlNode) refNode).document(runtime);
128
- setDocumentAndDecorate(runtime.getCurrentContext(), this, doc);
187
+ for (int j = 0; j < other.length; j++) {
188
+ if (other[j] == n) {
189
+ result[last++] = n;
190
+ continue outer;
129
191
  }
192
+ }
130
193
  }
131
194
 
132
- private void initialize(ThreadContext context, XmlDocument doc) {
133
- setDocumentAndDecorate(context, this, doc);
134
- }
135
-
136
- public int length() {
137
- return nodes == null ? 0 : nodes.length;
138
- }
139
-
140
- @JRubyMethod(name="&")
141
- public IRubyObject op_and(ThreadContext context, IRubyObject nodeSet) {
142
- IRubyObject[] otherNodes = getNodes(context, nodeSet);
195
+ XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
196
+ newSet.initializeFrom(context, this);
197
+ return newSet;
198
+ }
143
199
 
144
- if (otherNodes == null || otherNodes.length == 0) {
145
- return newEmptyNodeSet(context, this);
146
- }
200
+ @JRubyMethod
201
+ public IRubyObject
202
+ delete (ThreadContext context, IRubyObject node_or_namespace)
203
+ {
204
+ IRubyObject nodeOrNamespace = asXmlNodeOrNamespace(context, node_or_namespace);
147
205
 
148
- if (nodes == null || nodes.length == 0) {
149
- return newEmptyNodeSet(context, this);
150
- }
151
-
152
- IRubyObject[] curr = nodes;
153
- IRubyObject[] other = getNodes(context, nodeSet);
154
- IRubyObject[] result = new IRubyObject[nodes.length];
155
-
156
- int last = 0;
157
- outer:
158
- for (int i = 0; i < curr.length; i++) {
159
- IRubyObject n = curr[i];
160
-
161
- for (int j = 0; j < other.length; j++) {
162
- if (other[j] == n) {
163
- result[last++] = n;
164
- continue outer;
165
- }
166
- }
167
- }
168
-
169
- XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
170
- newSet.initializeFrom(context, this);
171
- return newSet;
206
+ if (nodes.length == 0) {
207
+ return context.nil;
172
208
  }
173
209
 
174
- @JRubyMethod
175
- public IRubyObject delete(ThreadContext context, IRubyObject node_or_namespace) {
176
- IRubyObject nodeOrNamespace = asXmlNodeOrNamespace(context, node_or_namespace);
177
-
178
- if (nodes.length == 0) {
179
- return context.nil;
180
- }
181
-
182
- IRubyObject[] orig = nodes;
183
- IRubyObject[] result = new IRubyObject[nodes.length];
210
+ IRubyObject[] orig = nodes;
211
+ IRubyObject[] result = new IRubyObject[nodes.length];
184
212
 
185
- int last = 0;
213
+ int last = 0;
186
214
 
187
- for (int i = 0; i < orig.length; i++) {
188
- IRubyObject n = orig[i];
215
+ for (int i = 0; i < orig.length; i++) {
216
+ IRubyObject n = orig[i];
189
217
 
190
- if (n == nodeOrNamespace) {
191
- continue;
192
- }
218
+ if (n == nodeOrNamespace) {
219
+ continue;
220
+ }
193
221
 
194
- result[last++] = n;
195
- }
196
-
197
- if (nodeOrNamespace instanceof XmlNamespace) {
198
- ((XmlNamespace) nodeOrNamespace).deleteHref();
199
- }
200
-
201
- nodes = Arrays.copyOf(result, last);
202
-
203
- if (nodes.length < orig.length) {
204
- // if we found the node return it
205
- return nodeOrNamespace;
206
- }
207
-
208
- return context.nil;
222
+ result[last++] = n;
209
223
  }
210
224
 
211
- @JRubyMethod
212
- public IRubyObject dup(ThreadContext context) {
213
- XmlNodeSet dup = newNodeSet(context.runtime, nodes.clone());
214
- dup.initializeFrom(context, this);
215
- return dup;
225
+ if (nodeOrNamespace instanceof XmlNamespace) {
226
+ ((XmlNamespace) nodeOrNamespace).deleteHref();
216
227
  }
217
228
 
218
- @JRubyMethod(name = "include?")
219
- public IRubyObject include_p(ThreadContext context, IRubyObject node_or_namespace) {
220
- for (int i = 0; i < nodes.length; i++) {
221
- if (nodes[i] == node_or_namespace) {
222
- return context.tru;
223
- }
224
- }
229
+ nodes = Arrays.copyOf(result, last);
225
230
 
226
- return context.fals;
231
+ if (nodes.length < orig.length) {
232
+ // if we found the node return it
233
+ return nodeOrNamespace;
227
234
  }
228
235
 
229
- @JRubyMethod(name = {"length", "size"})
230
- public IRubyObject length(ThreadContext context) {
231
- return context.runtime.newFixnum(nodes.length);
236
+ return context.nil;
237
+ }
238
+
239
+ @JRubyMethod
240
+ public IRubyObject
241
+ dup(ThreadContext context)
242
+ {
243
+ XmlNodeSet dup = newNodeSet(context.runtime, nodes.clone());
244
+ dup.initializeFrom(context, this);
245
+ return dup;
246
+ }
247
+
248
+ @JRubyMethod(name = "include?")
249
+ public IRubyObject
250
+ include_p(ThreadContext context, IRubyObject node_or_namespace)
251
+ {
252
+ for (int i = 0; i < nodes.length; i++) {
253
+ if (nodes[i] == node_or_namespace) {
254
+ return context.tru;
255
+ }
232
256
  }
233
257
 
234
- @JRubyMethod(name="-")
235
- public IRubyObject op_diff(ThreadContext context, IRubyObject nodeSet) {
236
- IRubyObject[] otherNodes = getNodes(context, nodeSet);
237
-
238
- if (otherNodes.length == 0) {
239
- return dup(context);
240
- }
241
-
242
- if (nodes.length == 0) {
243
- return newEmptyNodeSet(context, this);
244
- }
258
+ return context.fals;
259
+ }
245
260
 
246
- IRubyObject[] curr = nodes;
247
- IRubyObject[] other = getNodes(context, nodeSet);
248
- IRubyObject[] result = new IRubyObject[nodes.length];
261
+ @JRubyMethod(name = {"length", "size"})
262
+ public IRubyObject
263
+ length(ThreadContext context)
264
+ {
265
+ return context.runtime.newFixnum(nodes.length);
266
+ }
249
267
 
250
- int last = 0;
251
- outer:
252
- for (int i = 0; i < curr.length; i++) {
253
- IRubyObject n = curr[i];
268
+ @JRubyMethod(name = "-")
269
+ public IRubyObject
270
+ op_diff(ThreadContext context, IRubyObject nodeSet)
271
+ {
272
+ IRubyObject[] otherNodes = getNodes(context, nodeSet);
254
273
 
255
- for (int j = 0; j < other.length; j++) {
256
- if (other[j] == n) {
257
- continue outer;
258
- }
259
- }
260
-
261
- result[last++] = n;
262
- }
274
+ if (otherNodes.length == 0) {
275
+ return dup(context);
276
+ }
263
277
 
264
- XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
265
- newSet.initializeFrom(context, this);
266
- return newSet;
278
+ if (nodes.length == 0) {
279
+ return newEmptyNodeSet(context, this);
267
280
  }
268
281
 
269
- @JRubyMethod(name={"|", "+"})
270
- public IRubyObject op_or(ThreadContext context, IRubyObject nodeSet) {
271
- IRubyObject[] otherNodes = getNodes(context, nodeSet);
282
+ IRubyObject[] curr = nodes;
283
+ IRubyObject[] other = getNodes(context, nodeSet);
284
+ IRubyObject[] result = new IRubyObject[nodes.length];
272
285
 
273
- if (nodes.length == 0) {
274
- return ((XmlNodeSet) nodeSet).dup(context);
275
- }
286
+ int last = 0;
287
+ outer:
288
+ for (int i = 0; i < curr.length; i++) {
289
+ IRubyObject n = curr[i];
276
290
 
277
- if (otherNodes.length == 0) {
278
- return dup(context);
291
+ for (int j = 0; j < other.length; j++) {
292
+ if (other[j] == n) {
293
+ continue outer;
279
294
  }
295
+ }
280
296
 
281
- IRubyObject[] curr = nodes;
282
- IRubyObject[] other = getNodes(context, nodeSet);
283
- IRubyObject[] result = Arrays.copyOf(curr, curr.length + other.length);
284
-
285
- int last = curr.length;
286
- outer:
287
- for (int i = 0; i < other.length; i++) {
288
- IRubyObject n = other[i];
297
+ result[last++] = n;
298
+ }
289
299
 
290
- for (int j = 0; j < curr.length; j++) {
291
- if (curr[j] == n) {
292
- continue outer;
293
- }
294
- }
300
+ XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
301
+ newSet.initializeFrom(context, this);
302
+ return newSet;
303
+ }
295
304
 
296
- result[last++] = n;
297
- }
305
+ @JRubyMethod(name = {"|", "+"})
306
+ public IRubyObject
307
+ op_or(ThreadContext context, IRubyObject nodeSet)
308
+ {
309
+ IRubyObject[] otherNodes = getNodes(context, nodeSet);
298
310
 
299
- XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
300
- newSet.initializeFrom(context, this);
301
- return newSet;
311
+ if (nodes.length == 0) {
312
+ return ((XmlNodeSet) nodeSet).dup(context);
302
313
  }
303
314
 
304
- @JRubyMethod(name = {"push", "<<"})
305
- public IRubyObject push(ThreadContext context, IRubyObject node_or_namespace) {
306
- nodes = Arrays.copyOf(nodes, nodes.length+1);
307
- nodes[nodes.length-1] = node_or_namespace;
308
- return this;
315
+ if (otherNodes.length == 0) {
316
+ return dup(context);
309
317
  }
310
318
 
311
- // replace with
312
- // https://github.com/jruby/jruby/blame/13a3ec76d883a162b9d46c374c6e9eeea27b3261/core/src/main/java/org/jruby/RubyRange.java#L974
313
- // once we upgraded the min JRuby version to >= 9.2
314
- private static IRubyObject rangeBeginLength(ThreadContext context, IRubyObject rangeMaybe, int len, int[] begLen) {
315
- RubyRange range = (RubyRange) rangeMaybe;
316
- int min = range.begin(context).convertToInteger().getIntValue();
317
- int max = range.end(context).convertToInteger().getIntValue();
318
-
319
- if (min < 0) {
320
- min += len;
321
- if (min < 0) {
322
- throw context.runtime.newRangeError(min + ".." + (range.isExcludeEnd() ? "." : "") + max + " out of range");
323
- }
324
- }
319
+ IRubyObject[] curr = nodes;
320
+ IRubyObject[] other = getNodes(context, nodeSet);
321
+ IRubyObject[] result = Arrays.copyOf(curr, curr.length + other.length);
325
322
 
326
- if (max < 0) {
327
- max += len;
328
- }
323
+ int last = curr.length;
324
+ outer:
325
+ for (int i = 0; i < other.length; i++) {
326
+ IRubyObject n = other[i];
329
327
 
330
- if (!range.isExcludeEnd()) {
331
- max++;
328
+ for (int j = 0; j < curr.length; j++) {
329
+ if (curr[j] == n) {
330
+ continue outer;
332
331
  }
332
+ }
333
333
 
334
- begLen[0] = min;
335
- begLen[1] = max;
336
- return context.tru;
334
+ result[last++] = n;
337
335
  }
338
336
 
339
-
340
- @JRubyMethod(name={"[]", "slice"})
341
- public IRubyObject slice(ThreadContext context, IRubyObject indexOrRange) {
342
- if (indexOrRange instanceof RubyFixnum) {
343
- return slice(context, ((RubyFixnum) indexOrRange).getIntValue());
344
- }
345
-
346
- int[] begLen = new int[2];
347
- rangeBeginLength(context, indexOrRange, nodes.length, begLen);
348
- int min = begLen[0];
349
- int max = begLen[1];
350
- return subseq(context, min, max - min);
337
+ XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
338
+ newSet.initializeFrom(context, this);
339
+ return newSet;
340
+ }
341
+
342
+ @JRubyMethod(name = {"push", "<<"})
343
+ public IRubyObject
344
+ push(ThreadContext context, IRubyObject node_or_namespace)
345
+ {
346
+ nodes = Arrays.copyOf(nodes, nodes.length + 1);
347
+ nodes[nodes.length - 1] = node_or_namespace;
348
+ return this;
349
+ }
350
+
351
+ // replace with
352
+ // https://github.com/jruby/jruby/blame/13a3ec76d883a162b9d46c374c6e9eeea27b3261/core/src/main/java/org/jruby/RubyRange.java#L974
353
+ // once we upgraded the min JRuby version to >= 9.2
354
+ private static IRubyObject
355
+ rangeBeginLength(ThreadContext context, IRubyObject rangeMaybe, int len, int[] begLen)
356
+ {
357
+ RubyRange range = (RubyRange) rangeMaybe;
358
+ int min = range.begin(context).convertToInteger().getIntValue();
359
+ int max = range.end(context).convertToInteger().getIntValue();
360
+
361
+ if (min < 0) {
362
+ min += len;
363
+ if (min < 0) {
364
+ throw context.runtime.newRangeError(min + ".." + (range.isExcludeEnd() ? "." : "") + max + " out of range");
365
+ }
351
366
  }
352
367
 
353
- IRubyObject slice(ThreadContext context, int idx) {
354
- if (idx < 0) {
355
- idx += nodes.length;
356
- }
357
-
358
- if (idx >= nodes.length || idx < 0) {
359
- return context.nil;
360
- }
368
+ if (max < 0) {
369
+ max += len;
370
+ }
361
371
 
362
- return nodes[idx];
372
+ if (!range.isExcludeEnd()) {
373
+ max++;
363
374
  }
364
375
 
365
- @JRubyMethod(name={"[]", "slice"})
366
- public IRubyObject slice(ThreadContext context, IRubyObject start, IRubyObject length) {
367
- int s = ((RubyFixnum) start).getIntValue();
368
- int l = ((RubyFixnum) length).getIntValue();
376
+ begLen[0] = min;
377
+ begLen[1] = max;
378
+ return context.tru;
379
+ }
369
380
 
370
- if (s < 0) {
371
- s += nodes.length;
372
- }
373
381
 
374
- return subseq(context, s, l);
382
+ @JRubyMethod(name = {"[]", "slice"})
383
+ public IRubyObject
384
+ slice(ThreadContext context, IRubyObject indexOrRange)
385
+ {
386
+ if (indexOrRange instanceof RubyFixnum) {
387
+ return slice(context, ((RubyFixnum) indexOrRange).getIntValue());
375
388
  }
376
389
 
377
- public IRubyObject subseq(ThreadContext context, int start, int length) {
378
- if (start > nodes.length) {
379
- return context.nil;
380
- }
390
+ int[] begLen = new int[2];
391
+ rangeBeginLength(context, indexOrRange, nodes.length, begLen);
392
+ int min = begLen[0];
393
+ int max = begLen[1];
394
+ return subseq(context, min, max - min);
395
+ }
396
+
397
+ IRubyObject
398
+ slice(ThreadContext context, int idx)
399
+ {
400
+ if (idx < 0) {
401
+ idx += nodes.length;
402
+ }
381
403
 
382
- if (start < 0 || length < 0) {
383
- return context.nil;
384
- }
404
+ if (idx >= nodes.length || idx < 0) {
405
+ return context.nil;
406
+ }
385
407
 
386
- if (start + length > nodes.length) {
387
- length = nodes.length - start;
388
- }
408
+ return nodes[idx];
409
+ }
389
410
 
390
- int to = start + length;
411
+ @JRubyMethod(name = {"[]", "slice"})
412
+ public IRubyObject
413
+ slice(ThreadContext context, IRubyObject start, IRubyObject length)
414
+ {
415
+ int s = ((RubyFixnum) start).getIntValue();
416
+ int l = ((RubyFixnum) length).getIntValue();
391
417
 
392
- return newNodeSet(context.runtime, Arrays.copyOfRange(nodes, start, to));
418
+ if (s < 0) {
419
+ s += nodes.length;
393
420
  }
394
421
 
395
- @JRubyMethod(name = {"to_a", "to_ary"})
396
- public RubyArray to_a(ThreadContext context) {
397
- return context.runtime.newArrayNoCopy(nodes);
398
- }
422
+ return subseq(context, s, l);
423
+ }
399
424
 
400
- @JRubyMethod(name = {"unlink", "remove"})
401
- public IRubyObject unlink(ThreadContext context) {
402
- for (int i = 0; i < nodes.length; i++) {
403
- if (nodes[i] instanceof XmlNode) {
404
- ((XmlNode) nodes[i] ).unlink(context);
405
- }
406
- }
407
- return this;
425
+ public IRubyObject
426
+ subseq(ThreadContext context, int start, int length)
427
+ {
428
+ if (start > nodes.length) {
429
+ return context.nil;
408
430
  }
409
431
 
410
- private static IRubyObject asXmlNodeOrNamespace(ThreadContext context, IRubyObject possibleNode) {
411
- if (possibleNode instanceof XmlNode || possibleNode instanceof XmlNamespace) {
412
- return possibleNode;
413
- }
414
- throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::Node or Nokogiri::XML::Namespace");
432
+ if (start < 0 || length < 0) {
433
+ return context.nil;
415
434
  }
416
435
 
417
- private static IRubyObject[] getNodes(ThreadContext context, IRubyObject possibleNodeSet) {
418
- if (possibleNodeSet instanceof XmlNodeSet) {
419
- return ((XmlNodeSet) possibleNodeSet).nodes;
420
- }
421
- throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::NodeSet");
436
+ if (start + length > nodes.length) {
437
+ length = nodes.length - start;
422
438
  }
423
439
 
424
- public int getLength() {
425
- return nodes.length;
440
+ int to = start + length;
441
+
442
+ return newNodeSet(context.runtime, Arrays.copyOfRange(nodes, start, to));
443
+ }
444
+
445
+ @JRubyMethod(name = {"to_a", "to_ary"})
446
+ public RubyArray
447
+ to_a(ThreadContext context)
448
+ {
449
+ return context.runtime.newArrayNoCopy(nodes);
450
+ }
451
+
452
+ @JRubyMethod(name = {"unlink", "remove"})
453
+ public IRubyObject
454
+ unlink(ThreadContext context)
455
+ {
456
+ for (int i = 0; i < nodes.length; i++) {
457
+ if (nodes[i] instanceof XmlNode) {
458
+ ((XmlNode) nodes[i]).unlink(context);
459
+ }
426
460
  }
427
-
428
- public Node item(int index) {
429
- Object n = nodes[index];
430
- if (n instanceof XmlNode) return ((XmlNode) n).node;
431
- if (n instanceof XmlNamespace) return ((XmlNamespace) n).getNode();
432
- return null;
461
+ return this;
462
+ }
463
+
464
+ private static IRubyObject
465
+ asXmlNodeOrNamespace(ThreadContext context, IRubyObject possibleNode)
466
+ {
467
+ if (possibleNode instanceof XmlNode || possibleNode instanceof XmlNamespace) {
468
+ return possibleNode;
469
+ }
470
+ throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::Node or Nokogiri::XML::Namespace");
471
+ }
472
+
473
+ private static IRubyObject[]
474
+ getNodes(ThreadContext context, IRubyObject possibleNodeSet)
475
+ {
476
+ if (possibleNodeSet instanceof XmlNodeSet) {
477
+ return ((XmlNodeSet) possibleNodeSet).nodes;
433
478
  }
479
+ throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::NodeSet");
480
+ }
481
+
482
+ public int
483
+ getLength()
484
+ {
485
+ return nodes.length;
486
+ }
487
+
488
+ public Node
489
+ item(int index)
490
+ {
491
+ Object n = nodes[index];
492
+ if (n instanceof XmlNode) { return ((XmlNode) n).node; }
493
+ if (n instanceof XmlNamespace) { return ((XmlNamespace) n).getNode(); }
494
+ return null;
495
+ }
434
496
  }