nokogiri 1.11.0.rc4-java → 1.11.5-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/Gemfile +3 -0
- data/LICENSE-DEPENDENCIES.md +12 -12
- data/LICENSE.md +1 -1
- data/README.md +168 -91
- data/dependencies.yml +12 -12
- data/ext/java/nokogiri/EncodingHandler.java +76 -89
- data/ext/java/nokogiri/HtmlDocument.java +135 -144
- data/ext/java/nokogiri/HtmlElementDescription.java +102 -117
- data/ext/java/nokogiri/HtmlEntityLookup.java +33 -60
- data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -222
- data/ext/java/nokogiri/HtmlSaxPushParser.java +162 -169
- data/ext/java/nokogiri/NokogiriService.java +595 -556
- data/ext/java/nokogiri/XmlAttr.java +118 -126
- data/ext/java/nokogiri/XmlAttributeDecl.java +95 -106
- data/ext/java/nokogiri/XmlCdata.java +35 -58
- data/ext/java/nokogiri/XmlComment.java +46 -67
- data/ext/java/nokogiri/XmlDocument.java +645 -572
- data/ext/java/nokogiri/XmlDocumentFragment.java +125 -137
- data/ext/java/nokogiri/XmlDtd.java +448 -414
- data/ext/java/nokogiri/XmlElement.java +23 -48
- data/ext/java/nokogiri/XmlElementContent.java +343 -316
- data/ext/java/nokogiri/XmlElementDecl.java +124 -125
- data/ext/java/nokogiri/XmlEntityDecl.java +119 -127
- data/ext/java/nokogiri/XmlEntityReference.java +49 -72
- data/ext/java/nokogiri/XmlNamespace.java +175 -175
- data/ext/java/nokogiri/XmlNode.java +1843 -1620
- data/ext/java/nokogiri/XmlNodeSet.java +361 -331
- data/ext/java/nokogiri/XmlProcessingInstruction.java +47 -69
- data/ext/java/nokogiri/XmlReader.java +513 -450
- data/ext/java/nokogiri/XmlRelaxng.java +85 -104
- data/ext/java/nokogiri/XmlSaxParserContext.java +328 -315
- data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
- data/ext/java/nokogiri/XmlSchema.java +328 -295
- data/ext/java/nokogiri/XmlSyntaxError.java +113 -115
- data/ext/java/nokogiri/XmlText.java +55 -76
- data/ext/java/nokogiri/XmlXpathContext.java +240 -238
- data/ext/java/nokogiri/XsltStylesheet.java +280 -269
- data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +201 -202
- 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 +63 -80
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +27 -52
- data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -286
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +736 -652
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +184 -173
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +81 -98
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +64 -79
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +84 -99
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +48 -65
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +116 -131
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -56
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +23 -46
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +55 -72
- data/ext/java/nokogiri/internals/ParserContext.java +206 -211
- data/ext/java/nokogiri/internals/ReaderNode.java +478 -403
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -739
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +31 -54
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +3 -34
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +206 -207
- data/ext/java/nokogiri/internals/XmlSaxParser.java +22 -47
- 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 -574
- data/ext/nokogiri/depend +34 -474
- data/ext/nokogiri/extconf.rb +270 -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 +67 -64
- data/ext/nokogiri/html_sax_push_parser.c +42 -34
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +190 -60
- data/ext/nokogiri/test_global_handlers.c +40 -0
- 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 +246 -188
- 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 +371 -320
- 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 +101 -84
- data/ext/nokogiri/xml_sax_push_parser.c +36 -27
- data/ext/nokogiri/xml_schema.c +48 -42
- data/ext/nokogiri/xml_syntax_error.c +42 -21
- 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 +2 -6
- 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 +32 -8
- data/lib/nokogiri/xml/document.rb +74 -28
- data/lib/nokogiri/xml/node.rb +39 -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 +62 -127
- data/ext/nokogiri/xml_io.c +0 -63
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
@@ -1,35 +1,3 @@
|
|
1
|
-
/**
|
2
|
-
* (The MIT License)
|
3
|
-
*
|
4
|
-
* Copyright (c) 2008 - 2012:
|
5
|
-
*
|
6
|
-
* * {Aaron Patterson}[http://tenderlovemaking.com]
|
7
|
-
* * {Mike Dalessio}[http://mike.daless.io]
|
8
|
-
* * {Charles Nutter}[http://blog.headius.com]
|
9
|
-
* * {Sergio Arbeo}[http://www.serabe.com]
|
10
|
-
* * {Patrick Mahoney}[http://polycrystal.org]
|
11
|
-
* * {Yoko Harada}[http://yokolet.blogspot.com]
|
12
|
-
*
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining
|
14
|
-
* a copy of this software and associated documentation files (the
|
15
|
-
* 'Software'), to deal in the Software without restriction, including
|
16
|
-
* without limitation the rights to use, copy, modify, merge, publish,
|
17
|
-
* distribute, sublicense, and/or sell copies of the Software, and to
|
18
|
-
* permit persons to whom the Software is furnished to do so, subject to
|
19
|
-
* the following conditions:
|
20
|
-
*
|
21
|
-
* The above copyright notice and this permission notice shall be
|
22
|
-
* included in all copies or substantial portions of the Software.
|
23
|
-
*
|
24
|
-
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
25
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
26
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
27
|
-
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
28
|
-
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
29
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
30
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
31
|
-
*/
|
32
|
-
|
33
1
|
package nokogiri;
|
34
2
|
|
35
3
|
import static nokogiri.XmlNode.setDocumentAndDecorate;
|
@@ -57,378 +25,440 @@ import org.w3c.dom.NodeList;
|
|
57
25
|
* @author sergio
|
58
26
|
* @author Yoko Harada <yokolet@gmail.com>
|
59
27
|
*/
|
60
|
-
@JRubyClass(name="Nokogiri::XML::NodeSet")
|
61
|
-
public class XmlNodeSet extends RubyObject implements NodeList
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
28
|
+
@JRubyClass(name = "Nokogiri::XML::NodeSet")
|
29
|
+
public class XmlNodeSet extends RubyObject implements NodeList
|
30
|
+
{
|
31
|
+
|
32
|
+
IRubyObject[] nodes;
|
33
|
+
|
34
|
+
public
|
35
|
+
XmlNodeSet(Ruby ruby, RubyClass klazz)
|
36
|
+
{
|
37
|
+
super(ruby, klazz);
|
38
|
+
nodes = IRubyObject.NULL_ARRAY;
|
39
|
+
}
|
40
|
+
|
41
|
+
XmlNodeSet(Ruby ruby, RubyClass klazz, IRubyObject[] nodes)
|
42
|
+
{
|
43
|
+
super(ruby, klazz);
|
44
|
+
this.nodes = nodes;
|
45
|
+
}
|
46
|
+
|
47
|
+
public static XmlNodeSet
|
48
|
+
newEmptyNodeSet(ThreadContext context, XmlNodeSet docOwner)
|
49
|
+
{
|
50
|
+
final Ruby runtime = context.runtime;
|
51
|
+
XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
|
52
|
+
set.initializeFrom(context, docOwner);
|
53
|
+
return set;
|
54
|
+
}
|
55
|
+
|
56
|
+
public static XmlNodeSet
|
57
|
+
newEmptyNodeSet(ThreadContext context, XmlNode docOwner)
|
58
|
+
{
|
59
|
+
final Ruby runtime = context.runtime;
|
60
|
+
XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
|
61
|
+
set.initialize(runtime, docOwner);
|
62
|
+
return set;
|
63
|
+
}
|
64
|
+
|
65
|
+
public static XmlNodeSet
|
66
|
+
newNodeSet(Ruby runtime, IRubyObject[] nodes)
|
67
|
+
{
|
68
|
+
XmlNodeSet xmlNodeSet = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
|
69
|
+
xmlNodeSet.setNodes(nodes);
|
70
|
+
return xmlNodeSet;
|
71
|
+
}
|
72
|
+
|
73
|
+
public static XmlNodeSet
|
74
|
+
newNodeSet(Ruby runtime, IRubyObject[] nodes, XmlNode docOwner)
|
75
|
+
{
|
76
|
+
XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"), nodes);
|
77
|
+
set.initialize(runtime, docOwner);
|
78
|
+
return set;
|
79
|
+
}
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Create and return a copy of this object.
|
83
|
+
*
|
84
|
+
* @return a clone of this object
|
85
|
+
*/
|
86
|
+
@Override
|
87
|
+
public Object
|
88
|
+
clone() throws CloneNotSupportedException
|
89
|
+
{
|
90
|
+
return super.clone();
|
91
|
+
}
|
92
|
+
|
93
|
+
private void
|
94
|
+
setNodes(IRubyObject[] array)
|
95
|
+
{
|
96
|
+
this.nodes = array;
|
97
|
+
|
98
|
+
IRubyObject first = array.length > 0 ? array[0] : null;
|
99
|
+
initialize(getRuntime(), first);
|
100
|
+
}
|
101
|
+
|
102
|
+
private void
|
103
|
+
initializeFrom(ThreadContext context, XmlNodeSet ref)
|
104
|
+
{
|
105
|
+
IRubyObject document = ref.getInstanceVariable("@document");
|
106
|
+
if (document != null && !document.isNil()) {
|
107
|
+
initialize(context, (XmlDocument) document);
|
68
108
|
}
|
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;
|
109
|
+
}
|
110
|
+
|
111
|
+
final void
|
112
|
+
initialize(Ruby runtime, IRubyObject refNode)
|
113
|
+
{
|
114
|
+
if (refNode instanceof XmlNode) {
|
115
|
+
XmlDocument doc = ((XmlNode) refNode).document(runtime);
|
116
|
+
setDocumentAndDecorate(runtime.getCurrentContext(), this, doc);
|
87
117
|
}
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
118
|
+
}
|
119
|
+
|
120
|
+
private void
|
121
|
+
initialize(ThreadContext context, XmlDocument doc)
|
122
|
+
{
|
123
|
+
setDocumentAndDecorate(context, this, doc);
|
124
|
+
}
|
125
|
+
|
126
|
+
public int
|
127
|
+
length()
|
128
|
+
{
|
129
|
+
return nodes == null ? 0 : nodes.length;
|
130
|
+
}
|
131
|
+
|
132
|
+
@JRubyMethod(name = "&")
|
133
|
+
public IRubyObject
|
134
|
+
op_and(ThreadContext context, IRubyObject nodeSet)
|
135
|
+
{
|
136
|
+
IRubyObject[] otherNodes = getNodes(context, nodeSet);
|
137
|
+
|
138
|
+
if (otherNodes == null || otherNodes.length == 0) {
|
139
|
+
return newEmptyNodeSet(context, this);
|
99
140
|
}
|
100
141
|
|
101
|
-
|
102
|
-
|
103
|
-
*
|
104
|
-
* @return a clone of this object
|
105
|
-
*/
|
106
|
-
@Override
|
107
|
-
public Object clone() throws CloneNotSupportedException {
|
108
|
-
return super.clone();
|
142
|
+
if (nodes == null || nodes.length == 0) {
|
143
|
+
return newEmptyNodeSet(context, this);
|
109
144
|
}
|
110
145
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
IRubyObject first = array.length > 0 ? array[0] : null;
|
115
|
-
initialize(getRuntime(), first);
|
116
|
-
}
|
146
|
+
IRubyObject[] curr = nodes;
|
147
|
+
IRubyObject[] other = getNodes(context, nodeSet);
|
148
|
+
IRubyObject[] result = new IRubyObject[nodes.length];
|
117
149
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
}
|
123
|
-
}
|
150
|
+
int last = 0;
|
151
|
+
outer:
|
152
|
+
for (int i = 0; i < curr.length; i++) {
|
153
|
+
IRubyObject n = curr[i];
|
124
154
|
|
125
|
-
|
126
|
-
if (
|
127
|
-
|
128
|
-
|
155
|
+
for (int j = 0; j < other.length; j++) {
|
156
|
+
if (other[j] == n) {
|
157
|
+
result[last++] = n;
|
158
|
+
continue outer;
|
129
159
|
}
|
160
|
+
}
|
130
161
|
}
|
131
162
|
|
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);
|
143
|
-
|
144
|
-
if (otherNodes == null || otherNodes.length == 0) {
|
145
|
-
return newEmptyNodeSet(context, this);
|
146
|
-
}
|
147
|
-
|
148
|
-
if (nodes == null || nodes.length == 0) {
|
149
|
-
return newEmptyNodeSet(context, this);
|
150
|
-
}
|
163
|
+
XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
|
164
|
+
newSet.initializeFrom(context, this);
|
165
|
+
return newSet;
|
166
|
+
}
|
151
167
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
+
@JRubyMethod
|
169
|
+
public IRubyObject
|
170
|
+
delete (ThreadContext context, IRubyObject node_or_namespace)
|
171
|
+
{
|
172
|
+
IRubyObject nodeOrNamespace = asXmlNodeOrNamespace(context, node_or_namespace);
|
168
173
|
|
169
|
-
|
170
|
-
|
171
|
-
return newSet;
|
174
|
+
if (nodes.length == 0) {
|
175
|
+
return context.nil;
|
172
176
|
}
|
173
177
|
|
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];
|
184
|
-
|
185
|
-
int last = 0;
|
186
|
-
|
187
|
-
for (int i = 0; i < orig.length; i++) {
|
188
|
-
IRubyObject n = orig[i];
|
189
|
-
|
190
|
-
if (n == nodeOrNamespace) {
|
191
|
-
continue;
|
192
|
-
}
|
193
|
-
|
194
|
-
result[last++] = n;
|
195
|
-
}
|
178
|
+
IRubyObject[] orig = nodes;
|
179
|
+
IRubyObject[] result = new IRubyObject[nodes.length];
|
196
180
|
|
197
|
-
|
198
|
-
((XmlNamespace) nodeOrNamespace).deleteHref();
|
199
|
-
}
|
181
|
+
int last = 0;
|
200
182
|
|
201
|
-
|
183
|
+
for (int i = 0; i < orig.length; i++) {
|
184
|
+
IRubyObject n = orig[i];
|
202
185
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
}
|
186
|
+
if (n == nodeOrNamespace) {
|
187
|
+
continue;
|
188
|
+
}
|
207
189
|
|
208
|
-
|
190
|
+
result[last++] = n;
|
209
191
|
}
|
210
192
|
|
211
|
-
|
212
|
-
|
213
|
-
XmlNodeSet dup = newNodeSet(context.runtime, nodes.clone());
|
214
|
-
dup.initializeFrom(context, this);
|
215
|
-
return dup;
|
193
|
+
if (nodeOrNamespace instanceof XmlNamespace) {
|
194
|
+
((XmlNamespace) nodeOrNamespace).deleteHref();
|
216
195
|
}
|
217
196
|
|
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
|
-
}
|
197
|
+
nodes = Arrays.copyOf(result, last);
|
225
198
|
|
226
|
-
|
199
|
+
if (nodes.length < orig.length) {
|
200
|
+
// if we found the node return it
|
201
|
+
return nodeOrNamespace;
|
227
202
|
}
|
228
203
|
|
229
|
-
|
230
|
-
|
231
|
-
|
204
|
+
return context.nil;
|
205
|
+
}
|
206
|
+
|
207
|
+
@JRubyMethod
|
208
|
+
public IRubyObject
|
209
|
+
dup(ThreadContext context)
|
210
|
+
{
|
211
|
+
XmlNodeSet dup = newNodeSet(context.runtime, nodes.clone());
|
212
|
+
dup.initializeFrom(context, this);
|
213
|
+
return dup;
|
214
|
+
}
|
215
|
+
|
216
|
+
@JRubyMethod(name = "include?")
|
217
|
+
public IRubyObject
|
218
|
+
include_p(ThreadContext context, IRubyObject node_or_namespace)
|
219
|
+
{
|
220
|
+
for (int i = 0; i < nodes.length; i++) {
|
221
|
+
if (nodes[i] == node_or_namespace) {
|
222
|
+
return context.tru;
|
223
|
+
}
|
232
224
|
}
|
233
225
|
|
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
|
-
}
|
245
|
-
|
246
|
-
IRubyObject[] curr = nodes;
|
247
|
-
IRubyObject[] other = getNodes(context, nodeSet);
|
248
|
-
IRubyObject[] result = new IRubyObject[nodes.length];
|
226
|
+
return context.fals;
|
227
|
+
}
|
249
228
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
229
|
+
@JRubyMethod(name = {"length", "size"})
|
230
|
+
public IRubyObject
|
231
|
+
length(ThreadContext context)
|
232
|
+
{
|
233
|
+
return context.runtime.newFixnum(nodes.length);
|
234
|
+
}
|
254
235
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
236
|
+
@JRubyMethod(name = "-")
|
237
|
+
public IRubyObject
|
238
|
+
op_diff(ThreadContext context, IRubyObject nodeSet)
|
239
|
+
{
|
240
|
+
IRubyObject[] otherNodes = getNodes(context, nodeSet);
|
260
241
|
|
261
|
-
|
262
|
-
|
242
|
+
if (otherNodes.length == 0) {
|
243
|
+
return dup(context);
|
244
|
+
}
|
263
245
|
|
264
|
-
|
265
|
-
|
266
|
-
return newSet;
|
246
|
+
if (nodes.length == 0) {
|
247
|
+
return newEmptyNodeSet(context, this);
|
267
248
|
}
|
268
249
|
|
269
|
-
|
270
|
-
|
271
|
-
|
250
|
+
IRubyObject[] curr = nodes;
|
251
|
+
IRubyObject[] other = getNodes(context, nodeSet);
|
252
|
+
IRubyObject[] result = new IRubyObject[nodes.length];
|
272
253
|
|
273
|
-
|
274
|
-
|
275
|
-
|
254
|
+
int last = 0;
|
255
|
+
outer:
|
256
|
+
for (int i = 0; i < curr.length; i++) {
|
257
|
+
IRubyObject n = curr[i];
|
276
258
|
|
277
|
-
|
278
|
-
|
259
|
+
for (int j = 0; j < other.length; j++) {
|
260
|
+
if (other[j] == n) {
|
261
|
+
continue outer;
|
279
262
|
}
|
263
|
+
}
|
280
264
|
|
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];
|
265
|
+
result[last++] = n;
|
266
|
+
}
|
289
267
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
}
|
268
|
+
XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
|
269
|
+
newSet.initializeFrom(context, this);
|
270
|
+
return newSet;
|
271
|
+
}
|
295
272
|
|
296
|
-
|
297
|
-
|
273
|
+
@JRubyMethod(name = {"|", "+"})
|
274
|
+
public IRubyObject
|
275
|
+
op_or(ThreadContext context, IRubyObject nodeSet)
|
276
|
+
{
|
277
|
+
IRubyObject[] otherNodes = getNodes(context, nodeSet);
|
298
278
|
|
299
|
-
|
300
|
-
|
301
|
-
return newSet;
|
279
|
+
if (nodes.length == 0) {
|
280
|
+
return ((XmlNodeSet) nodeSet).dup(context);
|
302
281
|
}
|
303
282
|
|
304
|
-
|
305
|
-
|
306
|
-
nodes = Arrays.copyOf(nodes, nodes.length+1);
|
307
|
-
nodes[nodes.length-1] = node_or_namespace;
|
308
|
-
return this;
|
283
|
+
if (otherNodes.length == 0) {
|
284
|
+
return dup(context);
|
309
285
|
}
|
310
286
|
|
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
|
-
}
|
287
|
+
IRubyObject[] curr = nodes;
|
288
|
+
IRubyObject[] other = getNodes(context, nodeSet);
|
289
|
+
IRubyObject[] result = Arrays.copyOf(curr, curr.length + other.length);
|
325
290
|
|
326
|
-
|
327
|
-
|
328
|
-
|
291
|
+
int last = curr.length;
|
292
|
+
outer:
|
293
|
+
for (int i = 0; i < other.length; i++) {
|
294
|
+
IRubyObject n = other[i];
|
329
295
|
|
330
|
-
|
331
|
-
|
296
|
+
for (int j = 0; j < curr.length; j++) {
|
297
|
+
if (curr[j] == n) {
|
298
|
+
continue outer;
|
332
299
|
}
|
300
|
+
}
|
333
301
|
|
334
|
-
|
335
|
-
begLen[1] = max;
|
336
|
-
return context.tru;
|
302
|
+
result[last++] = n;
|
337
303
|
}
|
338
304
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
305
|
+
XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
|
306
|
+
newSet.initializeFrom(context, this);
|
307
|
+
return newSet;
|
308
|
+
}
|
309
|
+
|
310
|
+
@JRubyMethod(name = {"push", "<<"})
|
311
|
+
public IRubyObject
|
312
|
+
push(ThreadContext context, IRubyObject node_or_namespace)
|
313
|
+
{
|
314
|
+
nodes = Arrays.copyOf(nodes, nodes.length + 1);
|
315
|
+
nodes[nodes.length - 1] = node_or_namespace;
|
316
|
+
return this;
|
317
|
+
}
|
318
|
+
|
319
|
+
// replace with
|
320
|
+
// https://github.com/jruby/jruby/blame/13a3ec76d883a162b9d46c374c6e9eeea27b3261/core/src/main/java/org/jruby/RubyRange.java#L974
|
321
|
+
// once we upgraded the min JRuby version to >= 9.2
|
322
|
+
private static IRubyObject
|
323
|
+
rangeBeginLength(ThreadContext context, IRubyObject rangeMaybe, int len, int[] begLen)
|
324
|
+
{
|
325
|
+
RubyRange range = (RubyRange) rangeMaybe;
|
326
|
+
int min = range.begin(context).convertToInteger().getIntValue();
|
327
|
+
int max = range.end(context).convertToInteger().getIntValue();
|
328
|
+
|
329
|
+
if (min < 0) {
|
330
|
+
min += len;
|
331
|
+
if (min < 0) {
|
332
|
+
throw context.runtime.newRangeError(min + ".." + (range.isExcludeEnd() ? "." : "") + max + " out of range");
|
333
|
+
}
|
351
334
|
}
|
352
335
|
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
}
|
357
|
-
|
358
|
-
if (idx >= nodes.length || idx < 0) {
|
359
|
-
return context.nil;
|
360
|
-
}
|
336
|
+
if (max < 0) {
|
337
|
+
max += len;
|
338
|
+
}
|
361
339
|
|
362
|
-
|
340
|
+
if (!range.isExcludeEnd()) {
|
341
|
+
max++;
|
363
342
|
}
|
364
343
|
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
344
|
+
begLen[0] = min;
|
345
|
+
begLen[1] = max;
|
346
|
+
return context.tru;
|
347
|
+
}
|
369
348
|
|
370
|
-
if (s < 0) {
|
371
|
-
s += nodes.length;
|
372
|
-
}
|
373
349
|
|
374
|
-
|
350
|
+
@JRubyMethod(name = {"[]", "slice"})
|
351
|
+
public IRubyObject
|
352
|
+
slice(ThreadContext context, IRubyObject indexOrRange)
|
353
|
+
{
|
354
|
+
if (indexOrRange instanceof RubyFixnum) {
|
355
|
+
return slice(context, ((RubyFixnum) indexOrRange).getIntValue());
|
375
356
|
}
|
376
357
|
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
358
|
+
int[] begLen = new int[2];
|
359
|
+
rangeBeginLength(context, indexOrRange, nodes.length, begLen);
|
360
|
+
int min = begLen[0];
|
361
|
+
int max = begLen[1];
|
362
|
+
return subseq(context, min, max - min);
|
363
|
+
}
|
364
|
+
|
365
|
+
IRubyObject
|
366
|
+
slice(ThreadContext context, int idx)
|
367
|
+
{
|
368
|
+
if (idx < 0) {
|
369
|
+
idx += nodes.length;
|
370
|
+
}
|
381
371
|
|
382
|
-
|
383
|
-
|
384
|
-
|
372
|
+
if (idx >= nodes.length || idx < 0) {
|
373
|
+
return context.nil;
|
374
|
+
}
|
385
375
|
|
386
|
-
|
387
|
-
|
388
|
-
}
|
376
|
+
return nodes[idx];
|
377
|
+
}
|
389
378
|
|
390
|
-
|
379
|
+
@JRubyMethod(name = {"[]", "slice"})
|
380
|
+
public IRubyObject
|
381
|
+
slice(ThreadContext context, IRubyObject start, IRubyObject length)
|
382
|
+
{
|
383
|
+
int s = ((RubyFixnum) start).getIntValue();
|
384
|
+
int l = ((RubyFixnum) length).getIntValue();
|
391
385
|
|
392
|
-
|
386
|
+
if (s < 0) {
|
387
|
+
s += nodes.length;
|
393
388
|
}
|
394
389
|
|
395
|
-
|
396
|
-
|
397
|
-
return context.runtime.newArrayNoCopy(nodes);
|
398
|
-
}
|
390
|
+
return subseq(context, s, l);
|
391
|
+
}
|
399
392
|
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
}
|
406
|
-
}
|
407
|
-
return this;
|
393
|
+
public IRubyObject
|
394
|
+
subseq(ThreadContext context, int start, int length)
|
395
|
+
{
|
396
|
+
if (start > nodes.length) {
|
397
|
+
return context.nil;
|
408
398
|
}
|
409
399
|
|
410
|
-
|
411
|
-
|
412
|
-
return possibleNode;
|
413
|
-
}
|
414
|
-
throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::Node or Nokogiri::XML::Namespace");
|
400
|
+
if (start < 0 || length < 0) {
|
401
|
+
return context.nil;
|
415
402
|
}
|
416
403
|
|
417
|
-
|
418
|
-
|
419
|
-
return ((XmlNodeSet) possibleNodeSet).nodes;
|
420
|
-
}
|
421
|
-
throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::NodeSet");
|
404
|
+
if (start + length > nodes.length) {
|
405
|
+
length = nodes.length - start;
|
422
406
|
}
|
423
407
|
|
424
|
-
|
425
|
-
|
408
|
+
int to = start + length;
|
409
|
+
|
410
|
+
return newNodeSet(context.runtime, Arrays.copyOfRange(nodes, start, to));
|
411
|
+
}
|
412
|
+
|
413
|
+
@JRubyMethod(name = {"to_a", "to_ary"})
|
414
|
+
public RubyArray
|
415
|
+
to_a(ThreadContext context)
|
416
|
+
{
|
417
|
+
return context.runtime.newArrayNoCopy(nodes);
|
418
|
+
}
|
419
|
+
|
420
|
+
@JRubyMethod(name = {"unlink", "remove"})
|
421
|
+
public IRubyObject
|
422
|
+
unlink(ThreadContext context)
|
423
|
+
{
|
424
|
+
for (int i = 0; i < nodes.length; i++) {
|
425
|
+
if (nodes[i] instanceof XmlNode) {
|
426
|
+
((XmlNode) nodes[i]).unlink(context);
|
427
|
+
}
|
426
428
|
}
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
429
|
+
return this;
|
430
|
+
}
|
431
|
+
|
432
|
+
private static IRubyObject
|
433
|
+
asXmlNodeOrNamespace(ThreadContext context, IRubyObject possibleNode)
|
434
|
+
{
|
435
|
+
if (possibleNode instanceof XmlNode || possibleNode instanceof XmlNamespace) {
|
436
|
+
return possibleNode;
|
437
|
+
}
|
438
|
+
throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::Node or Nokogiri::XML::Namespace");
|
439
|
+
}
|
440
|
+
|
441
|
+
private static IRubyObject[]
|
442
|
+
getNodes(ThreadContext context, IRubyObject possibleNodeSet)
|
443
|
+
{
|
444
|
+
if (possibleNodeSet instanceof XmlNodeSet) {
|
445
|
+
return ((XmlNodeSet) possibleNodeSet).nodes;
|
433
446
|
}
|
447
|
+
throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::NodeSet");
|
448
|
+
}
|
449
|
+
|
450
|
+
public int
|
451
|
+
getLength()
|
452
|
+
{
|
453
|
+
return nodes.length;
|
454
|
+
}
|
455
|
+
|
456
|
+
public Node
|
457
|
+
item(int index)
|
458
|
+
{
|
459
|
+
Object n = nodes[index];
|
460
|
+
if (n instanceof XmlNode) { return ((XmlNode) n).node; }
|
461
|
+
if (n instanceof XmlNamespace) { return ((XmlNamespace) n).getNode(); }
|
462
|
+
return null;
|
463
|
+
}
|
434
464
|
}
|