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,38 +1,64 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
2
|
|
3
|
-
|
3
|
+
VALUE cNokogiriXmlSyntaxError;
|
4
|
+
|
5
|
+
void
|
6
|
+
Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state)
|
7
|
+
{
|
8
|
+
/* this method is tightly coupled to the implementation of xmlSetStructuredErrorFunc */
|
9
|
+
handler_state->user_data = xmlStructuredErrorContext;
|
10
|
+
handler_state->handler = xmlStructuredError;
|
11
|
+
}
|
12
|
+
|
13
|
+
void
|
14
|
+
Nokogiri_structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state,
|
15
|
+
void *user_data,
|
16
|
+
xmlStructuredErrorFunc handler)
|
17
|
+
{
|
18
|
+
Nokogiri_structured_error_func_save(handler_state);
|
19
|
+
xmlSetStructuredErrorFunc(user_data, handler);
|
20
|
+
}
|
21
|
+
|
22
|
+
void
|
23
|
+
Nokogiri_structured_error_func_restore(libxmlStructuredErrorHandlerState *handler_state)
|
24
|
+
{
|
25
|
+
xmlSetStructuredErrorFunc(handler_state->user_data, handler_state->handler);
|
26
|
+
}
|
27
|
+
|
28
|
+
void
|
29
|
+
Nokogiri_error_array_pusher(void *ctx, xmlErrorPtr error)
|
4
30
|
{
|
5
31
|
VALUE list = (VALUE)ctx;
|
6
32
|
Check_Type(list, T_ARRAY);
|
7
33
|
rb_ary_push(list, Nokogiri_wrap_xml_syntax_error(error));
|
8
34
|
}
|
9
35
|
|
10
|
-
void
|
36
|
+
void
|
37
|
+
Nokogiri_error_raise(void *ctx, xmlErrorPtr error)
|
11
38
|
{
|
12
39
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
13
40
|
}
|
14
41
|
|
15
|
-
VALUE
|
42
|
+
VALUE
|
43
|
+
Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error)
|
16
44
|
{
|
17
45
|
VALUE msg, e, klass;
|
18
46
|
|
19
47
|
klass = cNokogiriXmlSyntaxError;
|
20
48
|
|
21
49
|
if (error && error->domain == XML_FROM_XPATH) {
|
22
|
-
|
23
|
-
klass = rb_const_get(xpath, rb_intern("SyntaxError"));
|
50
|
+
klass = cNokogiriXmlXpathSyntaxError;
|
24
51
|
}
|
25
52
|
|
26
53
|
msg = (error && error->message) ? NOKOGIRI_STR_NEW2(error->message) : Qnil;
|
27
54
|
|
28
55
|
e = rb_class_new_instance(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
56
|
+
1,
|
57
|
+
&msg,
|
58
|
+
klass
|
59
|
+
);
|
33
60
|
|
34
|
-
if (error)
|
35
|
-
{
|
61
|
+
if (error) {
|
36
62
|
rb_iv_set(e, "@domain", INT2NUM(error->domain));
|
37
63
|
rb_iv_set(e, "@code", INT2NUM(error->code));
|
38
64
|
rb_iv_set(e, "@level", INT2NUM((short)error->level));
|
@@ -48,17 +74,12 @@ VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error)
|
|
48
74
|
return e;
|
49
75
|
}
|
50
76
|
|
51
|
-
|
52
|
-
|
77
|
+
void
|
78
|
+
noko_init_xml_syntax_error()
|
53
79
|
{
|
54
|
-
|
55
|
-
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
56
|
-
|
80
|
+
assert(cNokogiriSyntaxError);
|
57
81
|
/*
|
58
82
|
* The XML::SyntaxError is raised on parse errors
|
59
83
|
*/
|
60
|
-
|
61
|
-
VALUE klass = rb_define_class_under(xml, "SyntaxError", syntax_error_mommy);
|
62
|
-
cNokogiriXmlSyntaxError = klass;
|
63
|
-
|
84
|
+
cNokogiriXmlSyntaxError = rb_define_class_under(mNokogiriXml, "SyntaxError", cNokogiriSyntaxError);
|
64
85
|
}
|
data/ext/nokogiri/xml_text.c
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlText ;
|
2
4
|
|
3
5
|
/*
|
4
6
|
* call-seq:
|
@@ -6,7 +8,8 @@
|
|
6
8
|
*
|
7
9
|
* Create a new Text element on the +document+ with +content+
|
8
10
|
*/
|
9
|
-
static VALUE
|
11
|
+
static VALUE
|
12
|
+
new (int argc, VALUE *argv, VALUE klass)
|
10
13
|
{
|
11
14
|
xmlDocPtr doc;
|
12
15
|
xmlNodePtr node;
|
@@ -22,31 +25,24 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
|
|
22
25
|
node = xmlNewText((xmlChar *)StringValueCStr(string));
|
23
26
|
node->doc = doc->doc;
|
24
27
|
|
25
|
-
|
28
|
+
noko_xml_document_pin_node(node);
|
26
29
|
|
27
|
-
rb_node =
|
30
|
+
rb_node = noko_xml_node_wrap(klass, node) ;
|
28
31
|
rb_obj_call_init(rb_node, argc, argv);
|
29
32
|
|
30
|
-
if(rb_block_given_p()) rb_yield(rb_node);
|
33
|
+
if (rb_block_given_p()) { rb_yield(rb_node); }
|
31
34
|
|
32
35
|
return rb_node;
|
33
36
|
}
|
34
37
|
|
35
|
-
|
36
|
-
|
38
|
+
void
|
39
|
+
noko_init_xml_text()
|
37
40
|
{
|
38
|
-
|
39
|
-
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
40
|
-
/* */
|
41
|
-
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
42
|
-
VALUE char_data = rb_define_class_under(xml, "CharacterData", node);
|
43
|
-
|
41
|
+
assert(cNokogiriXmlCharacterData);
|
44
42
|
/*
|
45
43
|
* Wraps Text nodes.
|
46
44
|
*/
|
47
|
-
|
48
|
-
|
49
|
-
cNokogiriXmlText = klass;
|
45
|
+
cNokogiriXmlText = rb_define_class_under(mNokogiriXml, "Text", cNokogiriXmlCharacterData);
|
50
46
|
|
51
|
-
rb_define_singleton_method(
|
47
|
+
rb_define_singleton_method(cNokogiriXmlText, "new", new, -1);
|
52
48
|
}
|
@@ -1,4 +1,6 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlXpathContext;
|
2
4
|
|
3
5
|
/*
|
4
6
|
* these constants have matching declarations in
|
@@ -7,7 +9,8 @@
|
|
7
9
|
static const xmlChar *NOKOGIRI_BUILTIN_PREFIX = (const xmlChar *)"nokogiri-builtin";
|
8
10
|
static const xmlChar *NOKOGIRI_BUILTIN_URI = (const xmlChar *)"https://www.nokogiri.org/default_ns/ruby/builtins";
|
9
11
|
|
10
|
-
static void
|
12
|
+
static void
|
13
|
+
deallocate(xmlXPathContextPtr ctx)
|
11
14
|
{
|
12
15
|
NOKOGIRI_DEBUG_START(ctx);
|
13
16
|
xmlXPathFreeContext(ctx);
|
@@ -15,23 +18,24 @@ static void deallocate(xmlXPathContextPtr ctx)
|
|
15
18
|
}
|
16
19
|
|
17
20
|
/* find a CSS class in an HTML element's `class` attribute */
|
18
|
-
|
21
|
+
static const xmlChar *
|
22
|
+
builtin_css_class(const xmlChar *str, const xmlChar *val)
|
19
23
|
{
|
20
24
|
int val_len;
|
21
25
|
|
22
|
-
if (str == NULL) { return(NULL); }
|
23
|
-
if (val == NULL) { return(NULL); }
|
26
|
+
if (str == NULL) { return (NULL); }
|
27
|
+
if (val == NULL) { return (NULL); }
|
24
28
|
|
25
29
|
val_len = xmlStrlen(val);
|
26
|
-
if (val_len == 0) { return(str); }
|
30
|
+
if (val_len == 0) { return (str); }
|
27
31
|
|
28
32
|
while (*str != 0) {
|
29
33
|
if ((*str == *val) && !xmlStrncmp(str, val, val_len)) {
|
30
|
-
const xmlChar*
|
34
|
+
const xmlChar *next_byte = str + val_len;
|
31
35
|
|
32
36
|
/* only match if the next byte is whitespace or end of string */
|
33
37
|
if ((*next_byte == 0) || (IS_BLANK_CH(*next_byte))) {
|
34
|
-
return((const xmlChar*)str);
|
38
|
+
return ((const xmlChar *)str);
|
35
39
|
}
|
36
40
|
}
|
37
41
|
|
@@ -46,11 +50,12 @@ const xmlChar* builtin_css_class(const xmlChar* str, const xmlChar *val)
|
|
46
50
|
}
|
47
51
|
}
|
48
52
|
|
49
|
-
return(NULL);
|
53
|
+
return (NULL);
|
50
54
|
}
|
51
55
|
|
52
56
|
/* xmlXPathFunction to wrap builtin_css_class() */
|
53
|
-
static void
|
57
|
+
static void
|
58
|
+
xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
|
54
59
|
{
|
55
60
|
xmlXPathObjectPtr hay, needle;
|
56
61
|
|
@@ -87,15 +92,16 @@ static void xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
|
|
87
92
|
*
|
88
93
|
* Register the namespace with +prefix+ and +uri+.
|
89
94
|
*/
|
90
|
-
static VALUE
|
95
|
+
static VALUE
|
96
|
+
register_ns(VALUE self, VALUE prefix, VALUE uri)
|
91
97
|
{
|
92
98
|
xmlXPathContextPtr ctx;
|
93
99
|
Data_Get_Struct(self, xmlXPathContext, ctx);
|
94
100
|
|
95
|
-
xmlXPathRegisterNs(
|
96
|
-
|
97
|
-
|
98
|
-
|
101
|
+
xmlXPathRegisterNs(ctx,
|
102
|
+
(const xmlChar *)StringValueCStr(prefix),
|
103
|
+
(const xmlChar *)StringValueCStr(uri)
|
104
|
+
);
|
99
105
|
return self;
|
100
106
|
}
|
101
107
|
|
@@ -105,23 +111,26 @@ static VALUE register_ns(VALUE self, VALUE prefix, VALUE uri)
|
|
105
111
|
*
|
106
112
|
* Register the variable +name+ with +value+.
|
107
113
|
*/
|
108
|
-
static VALUE
|
114
|
+
static VALUE
|
115
|
+
register_variable(VALUE self, VALUE name, VALUE value)
|
109
116
|
{
|
110
|
-
|
111
|
-
|
112
|
-
|
117
|
+
xmlXPathContextPtr ctx;
|
118
|
+
xmlXPathObjectPtr xmlValue;
|
119
|
+
Data_Get_Struct(self, xmlXPathContext, ctx);
|
113
120
|
|
114
|
-
|
121
|
+
xmlValue = xmlXPathNewCString(StringValueCStr(value));
|
115
122
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
123
|
+
xmlXPathRegisterVariable(ctx,
|
124
|
+
(const xmlChar *)StringValueCStr(name),
|
125
|
+
xmlValue
|
126
|
+
);
|
120
127
|
|
121
|
-
|
128
|
+
return self;
|
122
129
|
}
|
123
130
|
|
124
|
-
void
|
131
|
+
void
|
132
|
+
Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler,
|
133
|
+
const char *function_name)
|
125
134
|
{
|
126
135
|
int i;
|
127
136
|
VALUE result, doc;
|
@@ -144,76 +153,76 @@ void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr c
|
|
144
153
|
i = nargs - 1;
|
145
154
|
do {
|
146
155
|
obj = valuePop(ctx);
|
147
|
-
switch(obj->type) {
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
156
|
+
switch (obj->type) {
|
157
|
+
case XPATH_STRING:
|
158
|
+
argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
|
159
|
+
break;
|
160
|
+
case XPATH_BOOLEAN:
|
161
|
+
argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
|
162
|
+
break;
|
163
|
+
case XPATH_NUMBER:
|
164
|
+
argv[i] = rb_float_new(obj->floatval);
|
165
|
+
break;
|
166
|
+
case XPATH_NODESET:
|
167
|
+
argv[i] = noko_xml_node_set_wrap(obj->nodesetval, doc);
|
168
|
+
break;
|
169
|
+
default:
|
170
|
+
argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
|
162
171
|
}
|
163
172
|
xmlXPathFreeNodeSetList(obj);
|
164
|
-
} while(i-- > 0);
|
173
|
+
} while (i-- > 0);
|
165
174
|
}
|
166
175
|
|
167
|
-
result = rb_funcall2(handler, rb_intern((const char*)function_name), nargs, argv);
|
176
|
+
result = rb_funcall2(handler, rb_intern((const char *)function_name), nargs, argv);
|
168
177
|
|
169
178
|
for (i = 0 ; i < nargs ; ++i) {
|
170
179
|
rb_gc_unregister_address(&argv[i]);
|
171
180
|
}
|
172
181
|
free(argv);
|
173
182
|
|
174
|
-
switch(TYPE(result)) {
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
break;
|
180
|
-
case T_STRING:
|
181
|
-
xmlXPathReturnString(
|
182
|
-
ctx,
|
183
|
-
xmlCharStrdup(StringValueCStr(result))
|
184
|
-
);
|
185
|
-
break;
|
186
|
-
case T_TRUE:
|
187
|
-
xmlXPathReturnTrue(ctx);
|
188
|
-
break;
|
189
|
-
case T_FALSE:
|
190
|
-
xmlXPathReturnFalse(ctx);
|
191
|
-
break;
|
192
|
-
case T_NIL:
|
193
|
-
break;
|
194
|
-
case T_ARRAY:
|
195
|
-
{
|
196
|
-
VALUE args[2];
|
197
|
-
args[0] = doc;
|
198
|
-
args[1] = result;
|
199
|
-
node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
|
200
|
-
Data_Get_Struct(node_set, xmlNodeSet, xml_node_set);
|
201
|
-
xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
|
202
|
-
}
|
183
|
+
switch (TYPE(result)) {
|
184
|
+
case T_FLOAT:
|
185
|
+
case T_BIGNUM:
|
186
|
+
case T_FIXNUM:
|
187
|
+
xmlXPathReturnNumber(ctx, NUM2DBL(result));
|
203
188
|
break;
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
189
|
+
case T_STRING:
|
190
|
+
xmlXPathReturnString(
|
191
|
+
ctx,
|
192
|
+
xmlCharStrdup(StringValueCStr(result))
|
193
|
+
);
|
194
|
+
break;
|
195
|
+
case T_TRUE:
|
196
|
+
xmlXPathReturnTrue(ctx);
|
197
|
+
break;
|
198
|
+
case T_FALSE:
|
199
|
+
xmlXPathReturnFalse(ctx);
|
200
|
+
break;
|
201
|
+
case T_NIL:
|
202
|
+
break;
|
203
|
+
case T_ARRAY: {
|
204
|
+
VALUE args[2];
|
205
|
+
args[0] = doc;
|
206
|
+
args[1] = result;
|
207
|
+
node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
|
208
|
+
Data_Get_Struct(node_set, xmlNodeSet, xml_node_set);
|
209
|
+
xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
|
210
|
+
}
|
211
|
+
break;
|
212
|
+
case T_DATA:
|
213
|
+
if (rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
|
214
|
+
Data_Get_Struct(result, xmlNodeSet, xml_node_set);
|
215
|
+
/* Copy the node set, otherwise it will get GC'd. */
|
216
|
+
xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
|
217
|
+
break;
|
213
218
|
}
|
219
|
+
default:
|
220
|
+
rb_raise(rb_eRuntimeError, "Invalid return type");
|
221
|
+
}
|
214
222
|
}
|
215
223
|
|
216
|
-
static void
|
224
|
+
static void
|
225
|
+
ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
|
217
226
|
{
|
218
227
|
VALUE handler = Qnil;
|
219
228
|
const char *function = NULL ;
|
@@ -224,26 +233,29 @@ static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
|
|
224
233
|
assert(ctx->context->function);
|
225
234
|
|
226
235
|
handler = (VALUE)(ctx->context->userData);
|
227
|
-
function = (const char*)(ctx->context->function);
|
236
|
+
function = (const char *)(ctx->context->function);
|
228
237
|
|
229
238
|
Nokogiri_marshal_xpath_funcall_and_return_values(ctx, nargs, handler, function);
|
230
239
|
}
|
231
240
|
|
232
|
-
static xmlXPathFunction
|
233
|
-
|
234
|
-
|
241
|
+
static xmlXPathFunction
|
242
|
+
lookup(void *ctx,
|
243
|
+
const xmlChar *name,
|
244
|
+
const xmlChar *ns_uri)
|
235
245
|
{
|
236
246
|
VALUE xpath_handler = (VALUE)ctx;
|
237
|
-
if(rb_respond_to(xpath_handler, rb_intern((const char *)name)))
|
247
|
+
if (rb_respond_to(xpath_handler, rb_intern((const char *)name))) {
|
238
248
|
return ruby_funcall;
|
249
|
+
}
|
239
250
|
|
240
251
|
return NULL;
|
241
252
|
}
|
242
253
|
|
243
|
-
NORETURN(static void xpath_generic_exception_handler(void *
|
244
|
-
static void
|
254
|
+
NORETURN(static void xpath_generic_exception_handler(void *ctx, const char *msg, ...));
|
255
|
+
static void
|
256
|
+
xpath_generic_exception_handler(void *ctx, const char *msg, ...)
|
245
257
|
{
|
246
|
-
char *
|
258
|
+
char *message;
|
247
259
|
|
248
260
|
va_list args;
|
249
261
|
va_start(args, msg);
|
@@ -259,7 +271,8 @@ static void xpath_generic_exception_handler(void * ctx, const char *msg, ...)
|
|
259
271
|
*
|
260
272
|
* Evaluate the +search_path+ returning an XML::XPath object.
|
261
273
|
*/
|
262
|
-
static VALUE
|
274
|
+
static VALUE
|
275
|
+
evaluate(int argc, VALUE *argv, VALUE self)
|
263
276
|
{
|
264
277
|
VALUE search_path, xpath_handler;
|
265
278
|
VALUE thing = Qnil;
|
@@ -269,12 +282,13 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
269
282
|
|
270
283
|
Data_Get_Struct(self, xmlXPathContext, ctx);
|
271
284
|
|
272
|
-
if(rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1)
|
285
|
+
if (rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1) {
|
273
286
|
xpath_handler = Qnil;
|
287
|
+
}
|
274
288
|
|
275
289
|
query = (xmlChar *)StringValueCStr(search_path);
|
276
290
|
|
277
|
-
if(Qnil != xpath_handler) {
|
291
|
+
if (Qnil != xpath_handler) {
|
278
292
|
/* FIXME: not sure if this is the correct place to shove private data. */
|
279
293
|
ctx->userData = (void *)xpath_handler;
|
280
294
|
xmlXPathRegisterFuncLookup(ctx, lookup, (void *)xpath_handler);
|
@@ -291,7 +305,7 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
291
305
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
292
306
|
xmlSetGenericErrorFunc(NULL, NULL);
|
293
307
|
|
294
|
-
if(xpath == NULL) {
|
308
|
+
if (xpath == NULL) {
|
295
309
|
xmlErrorPtr error = xmlGetLastError();
|
296
310
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
297
311
|
}
|
@@ -299,23 +313,23 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
299
313
|
assert(ctx->doc);
|
300
314
|
assert(DOC_RUBY_OBJECT_TEST(ctx->doc));
|
301
315
|
|
302
|
-
switch(xpath->type) {
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
316
|
+
switch (xpath->type) {
|
317
|
+
case XPATH_STRING:
|
318
|
+
thing = NOKOGIRI_STR_NEW2(xpath->stringval);
|
319
|
+
xmlFree(xpath->stringval);
|
320
|
+
break;
|
321
|
+
case XPATH_NODESET:
|
322
|
+
thing = noko_xml_node_set_wrap(xpath->nodesetval,
|
323
|
+
DOC_RUBY_OBJECT(ctx->doc));
|
324
|
+
break;
|
325
|
+
case XPATH_NUMBER:
|
326
|
+
thing = rb_float_new(xpath->floatval);
|
327
|
+
break;
|
328
|
+
case XPATH_BOOLEAN:
|
329
|
+
thing = xpath->boolval == 1 ? Qtrue : Qfalse;
|
330
|
+
break;
|
331
|
+
default:
|
332
|
+
thing = noko_xml_node_set_wrap(NULL, DOC_RUBY_OBJECT(ctx->doc));
|
319
333
|
}
|
320
334
|
|
321
335
|
xmlXPathFreeNodeSetList(xpath);
|
@@ -329,7 +343,8 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
329
343
|
*
|
330
344
|
* Create a new XPathContext with +node+ as the reference point.
|
331
345
|
*/
|
332
|
-
static VALUE
|
346
|
+
static VALUE
|
347
|
+
new (VALUE klass, VALUE nodeobj)
|
333
348
|
{
|
334
349
|
xmlNodePtr node;
|
335
350
|
xmlXPathContextPtr ctx;
|
@@ -350,25 +365,17 @@ static VALUE new(VALUE klass, VALUE nodeobj)
|
|
350
365
|
return self;
|
351
366
|
}
|
352
367
|
|
353
|
-
|
354
|
-
|
368
|
+
void
|
369
|
+
noko_init_xml_xpath_context(void)
|
355
370
|
{
|
356
|
-
VALUE module = rb_define_module("Nokogiri");
|
357
|
-
|
358
|
-
/*
|
359
|
-
* Nokogiri::XML
|
360
|
-
*/
|
361
|
-
VALUE xml = rb_define_module_under(module, "XML");
|
362
|
-
|
363
371
|
/*
|
364
372
|
* XPathContext is the entry point for searching a Document by using XPath.
|
365
373
|
*/
|
366
|
-
|
374
|
+
cNokogiriXmlXpathContext = rb_define_class_under(mNokogiriXml, "XPathContext", rb_cObject);
|
367
375
|
|
368
|
-
cNokogiriXmlXpathContext
|
376
|
+
rb_define_singleton_method(cNokogiriXmlXpathContext, "new", new, 1);
|
369
377
|
|
370
|
-
|
371
|
-
rb_define_method(
|
372
|
-
rb_define_method(
|
373
|
-
rb_define_method(klass, "register_ns", register_ns, 2);
|
378
|
+
rb_define_method(cNokogiriXmlXpathContext, "evaluate", evaluate, -1);
|
379
|
+
rb_define_method(cNokogiriXmlXpathContext, "register_variable", register_variable, 2);
|
380
|
+
rb_define_method(cNokogiriXmlXpathContext, "register_ns", register_ns, 2);
|
374
381
|
}
|