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.
- checksums.yaml +4 -4
- data/LICENSE-DEPENDENCIES.md +12 -12
- data/LICENSE.md +1 -1
- data/README.md +20 -15
- data/ext/java/nokogiri/EncodingHandler.java +78 -59
- data/ext/java/nokogiri/HtmlDocument.java +137 -114
- data/ext/java/nokogiri/HtmlElementDescription.java +104 -87
- data/ext/java/nokogiri/HtmlEntityLookup.java +31 -26
- data/ext/java/nokogiri/HtmlSaxParserContext.java +220 -192
- data/ext/java/nokogiri/HtmlSaxPushParser.java +164 -139
- data/ext/java/nokogiri/NokogiriService.java +597 -526
- data/ext/java/nokogiri/XmlAttr.java +120 -96
- data/ext/java/nokogiri/XmlAttributeDecl.java +97 -76
- data/ext/java/nokogiri/XmlCdata.java +35 -26
- data/ext/java/nokogiri/XmlComment.java +48 -37
- data/ext/java/nokogiri/XmlDocument.java +642 -540
- data/ext/java/nokogiri/XmlDocumentFragment.java +127 -107
- data/ext/java/nokogiri/XmlDtd.java +450 -384
- data/ext/java/nokogiri/XmlElement.java +25 -18
- data/ext/java/nokogiri/XmlElementContent.java +345 -286
- data/ext/java/nokogiri/XmlElementDecl.java +126 -95
- data/ext/java/nokogiri/XmlEntityDecl.java +121 -97
- data/ext/java/nokogiri/XmlEntityReference.java +51 -42
- data/ext/java/nokogiri/XmlNamespace.java +177 -145
- data/ext/java/nokogiri/XmlNode.java +1843 -1588
- data/ext/java/nokogiri/XmlNodeSet.java +361 -299
- data/ext/java/nokogiri/XmlProcessingInstruction.java +49 -39
- data/ext/java/nokogiri/XmlReader.java +513 -418
- data/ext/java/nokogiri/XmlRelaxng.java +91 -78
- data/ext/java/nokogiri/XmlSaxParserContext.java +330 -285
- data/ext/java/nokogiri/XmlSaxPushParser.java +229 -190
- data/ext/java/nokogiri/XmlSchema.java +328 -263
- data/ext/java/nokogiri/XmlSyntaxError.java +113 -83
- data/ext/java/nokogiri/XmlText.java +57 -46
- data/ext/java/nokogiri/XmlXpathContext.java +240 -206
- data/ext/java/nokogiri/XsltStylesheet.java +282 -239
- data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +199 -168
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
- data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +65 -50
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +25 -18
- data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -254
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +738 -622
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +186 -143
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +83 -68
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +66 -49
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +86 -69
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +44 -29
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +118 -101
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -24
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +25 -17
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +57 -42
- data/ext/java/nokogiri/internals/ParserContext.java +206 -179
- data/ext/java/nokogiri/internals/ReaderNode.java +478 -371
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -707
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +28 -19
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +5 -4
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +208 -177
- data/ext/java/nokogiri/internals/XmlSaxParser.java +24 -17
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
- data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -570
- data/ext/nokogiri/depend +34 -474
- data/ext/nokogiri/extconf.rb +253 -183
- data/ext/nokogiri/html_document.c +10 -15
- data/ext/nokogiri/html_element_description.c +84 -71
- data/ext/nokogiri/html_entity_lookup.c +21 -16
- data/ext/nokogiri/html_sax_parser_context.c +66 -65
- data/ext/nokogiri/html_sax_push_parser.c +29 -27
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +171 -63
- data/ext/nokogiri/test_global_handlers.c +3 -4
- data/ext/nokogiri/xml_attr.c +15 -15
- data/ext/nokogiri/xml_attribute_decl.c +18 -18
- data/ext/nokogiri/xml_cdata.c +13 -18
- data/ext/nokogiri/xml_comment.c +19 -26
- data/ext/nokogiri/xml_document.c +221 -164
- data/ext/nokogiri/xml_document_fragment.c +13 -15
- data/ext/nokogiri/xml_dtd.c +54 -48
- data/ext/nokogiri/xml_element_content.c +30 -27
- data/ext/nokogiri/xml_element_decl.c +22 -22
- data/ext/nokogiri/xml_encoding_handler.c +17 -11
- data/ext/nokogiri/xml_entity_decl.c +32 -30
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +56 -49
- data/ext/nokogiri/xml_node.c +338 -286
- data/ext/nokogiri/xml_node_set.c +168 -156
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +191 -157
- data/ext/nokogiri/xml_relax_ng.c +29 -23
- data/ext/nokogiri/xml_sax_parser.c +117 -112
- data/ext/nokogiri/xml_sax_parser_context.c +100 -85
- data/ext/nokogiri/xml_sax_push_parser.c +34 -27
- data/ext/nokogiri/xml_schema.c +48 -42
- data/ext/nokogiri/xml_syntax_error.c +21 -23
- data/ext/nokogiri/xml_text.c +13 -17
- data/ext/nokogiri/xml_xpath_context.c +134 -127
- data/ext/nokogiri/xslt_stylesheet.c +157 -157
- data/lib/nokogiri.rb +1 -22
- data/lib/nokogiri/css/parser.rb +1 -1
- data/lib/nokogiri/extension.rb +26 -0
- data/lib/nokogiri/html/document_fragment.rb +15 -15
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +31 -8
- data/lib/nokogiri/xml/document.rb +31 -11
- data/lib/nokogiri/xml/node.rb +38 -42
- data/lib/nokogiri/xml/reader.rb +2 -9
- data/lib/nokogiri/xml/xpath.rb +1 -3
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
- metadata +7 -8
- data/ext/nokogiri/xml_io.c +0 -63
- 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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
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
|
-
|
112
|
-
|
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
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
-
|
126
|
-
if (
|
127
|
-
|
128
|
-
|
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
|
-
|
133
|
-
|
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
|
-
|
145
|
-
|
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
|
-
|
149
|
-
|
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
|
-
|
175
|
-
|
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
|
-
|
213
|
+
int last = 0;
|
186
214
|
|
187
|
-
|
188
|
-
|
215
|
+
for (int i = 0; i < orig.length; i++) {
|
216
|
+
IRubyObject n = orig[i];
|
189
217
|
|
190
|
-
|
191
|
-
|
192
|
-
|
218
|
+
if (n == nodeOrNamespace) {
|
219
|
+
continue;
|
220
|
+
}
|
193
221
|
|
194
|
-
|
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
|
-
|
212
|
-
|
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
|
-
|
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
|
-
|
231
|
+
if (nodes.length < orig.length) {
|
232
|
+
// if we found the node return it
|
233
|
+
return nodeOrNamespace;
|
227
234
|
}
|
228
235
|
|
229
|
-
|
230
|
-
|
231
|
-
|
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
|
-
|
235
|
-
|
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
|
-
|
247
|
-
|
248
|
-
|
261
|
+
@JRubyMethod(name = {"length", "size"})
|
262
|
+
public IRubyObject
|
263
|
+
length(ThreadContext context)
|
264
|
+
{
|
265
|
+
return context.runtime.newFixnum(nodes.length);
|
266
|
+
}
|
249
267
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
268
|
+
@JRubyMethod(name = "-")
|
269
|
+
public IRubyObject
|
270
|
+
op_diff(ThreadContext context, IRubyObject nodeSet)
|
271
|
+
{
|
272
|
+
IRubyObject[] otherNodes = getNodes(context, nodeSet);
|
254
273
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
}
|
259
|
-
}
|
260
|
-
|
261
|
-
result[last++] = n;
|
262
|
-
}
|
274
|
+
if (otherNodes.length == 0) {
|
275
|
+
return dup(context);
|
276
|
+
}
|
263
277
|
|
264
|
-
|
265
|
-
|
266
|
-
return newSet;
|
278
|
+
if (nodes.length == 0) {
|
279
|
+
return newEmptyNodeSet(context, this);
|
267
280
|
}
|
268
281
|
|
269
|
-
|
270
|
-
|
271
|
-
|
282
|
+
IRubyObject[] curr = nodes;
|
283
|
+
IRubyObject[] other = getNodes(context, nodeSet);
|
284
|
+
IRubyObject[] result = new IRubyObject[nodes.length];
|
272
285
|
|
273
|
-
|
274
|
-
|
275
|
-
|
286
|
+
int last = 0;
|
287
|
+
outer:
|
288
|
+
for (int i = 0; i < curr.length; i++) {
|
289
|
+
IRubyObject n = curr[i];
|
276
290
|
|
277
|
-
|
278
|
-
|
291
|
+
for (int j = 0; j < other.length; j++) {
|
292
|
+
if (other[j] == n) {
|
293
|
+
continue outer;
|
279
294
|
}
|
295
|
+
}
|
280
296
|
|
281
|
-
|
282
|
-
|
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
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
}
|
300
|
+
XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
|
301
|
+
newSet.initializeFrom(context, this);
|
302
|
+
return newSet;
|
303
|
+
}
|
295
304
|
|
296
|
-
|
297
|
-
|
305
|
+
@JRubyMethod(name = {"|", "+"})
|
306
|
+
public IRubyObject
|
307
|
+
op_or(ThreadContext context, IRubyObject nodeSet)
|
308
|
+
{
|
309
|
+
IRubyObject[] otherNodes = getNodes(context, nodeSet);
|
298
310
|
|
299
|
-
|
300
|
-
|
301
|
-
return newSet;
|
311
|
+
if (nodes.length == 0) {
|
312
|
+
return ((XmlNodeSet) nodeSet).dup(context);
|
302
313
|
}
|
303
314
|
|
304
|
-
|
305
|
-
|
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
|
-
|
312
|
-
|
313
|
-
|
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
|
-
|
327
|
-
|
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
|
-
|
331
|
-
|
328
|
+
for (int j = 0; j < curr.length; j++) {
|
329
|
+
if (curr[j] == n) {
|
330
|
+
continue outer;
|
332
331
|
}
|
332
|
+
}
|
333
333
|
|
334
|
-
|
335
|
-
begLen[1] = max;
|
336
|
-
return context.tru;
|
334
|
+
result[last++] = n;
|
337
335
|
}
|
338
336
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
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
|
-
|
354
|
-
|
355
|
-
|
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
|
-
|
372
|
+
if (!range.isExcludeEnd()) {
|
373
|
+
max++;
|
363
374
|
}
|
364
375
|
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
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
|
-
|
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
|
-
|
378
|
-
|
379
|
-
|
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
|
-
|
383
|
-
|
384
|
-
|
404
|
+
if (idx >= nodes.length || idx < 0) {
|
405
|
+
return context.nil;
|
406
|
+
}
|
385
407
|
|
386
|
-
|
387
|
-
|
388
|
-
}
|
408
|
+
return nodes[idx];
|
409
|
+
}
|
389
410
|
|
390
|
-
|
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
|
-
|
418
|
+
if (s < 0) {
|
419
|
+
s += nodes.length;
|
393
420
|
}
|
394
421
|
|
395
|
-
|
396
|
-
|
397
|
-
return context.runtime.newArrayNoCopy(nodes);
|
398
|
-
}
|
422
|
+
return subseq(context, s, l);
|
423
|
+
}
|
399
424
|
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
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
|
-
|
411
|
-
|
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
|
-
|
418
|
-
|
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
|
-
|
425
|
-
|
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
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
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
|
}
|