nokogiri 1.11.1-arm64-darwin → 1.11.2-arm64-darwin
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/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/include/libxslt/xsltconfig.h +1 -1
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +171 -63
- data/ext/nokogiri/nokogiri.h +158 -75
- 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/2.5/nokogiri.bundle +0 -0
- data/lib/nokogiri/2.6/nokogiri.bundle +0 -0
- data/lib/nokogiri/2.7/nokogiri.bundle +0 -0
- data/lib/nokogiri/3.0/nokogiri.bundle +0 -0
- 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/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 -41
- data/ext/nokogiri/html_document.h +0 -10
- data/ext/nokogiri/html_element_description.h +0 -10
- data/ext/nokogiri/html_entity_lookup.h +0 -8
- data/ext/nokogiri/html_sax_parser_context.h +0 -11
- data/ext/nokogiri/html_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_attr.h +0 -9
- data/ext/nokogiri/xml_attribute_decl.h +0 -9
- data/ext/nokogiri/xml_cdata.h +0 -9
- data/ext/nokogiri/xml_comment.h +0 -9
- data/ext/nokogiri/xml_document.h +0 -23
- data/ext/nokogiri/xml_document_fragment.h +0 -10
- data/ext/nokogiri/xml_dtd.h +0 -10
- data/ext/nokogiri/xml_element_content.h +0 -10
- data/ext/nokogiri/xml_element_decl.h +0 -9
- data/ext/nokogiri/xml_encoding_handler.h +0 -8
- data/ext/nokogiri/xml_entity_decl.h +0 -10
- data/ext/nokogiri/xml_entity_reference.h +0 -9
- data/ext/nokogiri/xml_io.c +0 -63
- data/ext/nokogiri/xml_io.h +0 -11
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
- data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
- data/ext/nokogiri/xml_namespace.h +0 -14
- data/ext/nokogiri/xml_node.h +0 -13
- data/ext/nokogiri/xml_node_set.h +0 -12
- data/ext/nokogiri/xml_processing_instruction.h +0 -9
- data/ext/nokogiri/xml_reader.h +0 -10
- data/ext/nokogiri/xml_relax_ng.h +0 -9
- data/ext/nokogiri/xml_sax_parser.h +0 -39
- data/ext/nokogiri/xml_sax_parser_context.h +0 -10
- data/ext/nokogiri/xml_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_schema.h +0 -9
- data/ext/nokogiri/xml_syntax_error.h +0 -25
- data/ext/nokogiri/xml_text.h +0 -9
- data/ext/nokogiri/xml_xpath_context.h +0 -10
- data/ext/nokogiri/xslt_stylesheet.h +0 -14
data/ext/nokogiri/xml_relax_ng.c
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
2
|
|
3
|
-
|
3
|
+
VALUE cNokogiriXmlRelaxNG;
|
4
|
+
|
5
|
+
static void
|
6
|
+
dealloc(xmlRelaxNGPtr schema)
|
4
7
|
{
|
5
8
|
NOKOGIRI_DEBUG_START(schema);
|
6
9
|
xmlRelaxNGFree(schema);
|
@@ -13,7 +16,8 @@ static void dealloc(xmlRelaxNGPtr schema)
|
|
13
16
|
*
|
14
17
|
* Validate a Nokogiri::XML::Document against this RelaxNG schema.
|
15
18
|
*/
|
16
|
-
static VALUE
|
19
|
+
static VALUE
|
20
|
+
validate_document(VALUE self, VALUE document)
|
17
21
|
{
|
18
22
|
xmlDocPtr doc;
|
19
23
|
xmlRelaxNGPtr schema;
|
@@ -27,7 +31,7 @@ static VALUE validate_document(VALUE self, VALUE document)
|
|
27
31
|
|
28
32
|
valid_ctxt = xmlRelaxNGNewValidCtxt(schema);
|
29
33
|
|
30
|
-
if(NULL == valid_ctxt) {
|
34
|
+
if (NULL == valid_ctxt) {
|
31
35
|
/* we have a problem */
|
32
36
|
rb_raise(rb_eRuntimeError, "Could not create a validation context");
|
33
37
|
}
|
@@ -53,7 +57,8 @@ static VALUE validate_document(VALUE self, VALUE document)
|
|
53
57
|
*
|
54
58
|
* Create a new RelaxNG from the contents of +string+
|
55
59
|
*/
|
56
|
-
static VALUE
|
60
|
+
static VALUE
|
61
|
+
read_memory(int argc, VALUE *argv, VALUE klass)
|
57
62
|
{
|
58
63
|
VALUE content;
|
59
64
|
VALUE parse_options;
|
@@ -65,7 +70,7 @@ static VALUE read_memory(int argc, VALUE *argv, VALUE klass)
|
|
65
70
|
|
66
71
|
scanned_args = rb_scan_args(argc, argv, "11", &content, &parse_options);
|
67
72
|
if (scanned_args == 1) {
|
68
|
-
parse_options =
|
73
|
+
parse_options = rb_const_get_at(rb_const_get_at(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
69
74
|
}
|
70
75
|
|
71
76
|
ctx = xmlRelaxNGNewMemParserCtxt((const char *)StringValuePtr(content), (int)RSTRING_LEN(content));
|
@@ -86,12 +91,13 @@ static VALUE read_memory(int argc, VALUE *argv, VALUE klass)
|
|
86
91
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
87
92
|
xmlRelaxNGFreeParserCtxt(ctx);
|
88
93
|
|
89
|
-
if(NULL == schema) {
|
94
|
+
if (NULL == schema) {
|
90
95
|
xmlErrorPtr error = xmlGetLastError();
|
91
|
-
if(error)
|
96
|
+
if (error) {
|
92
97
|
Nokogiri_error_raise(NULL, error);
|
93
|
-
else
|
98
|
+
} else {
|
94
99
|
rb_raise(rb_eRuntimeError, "Could not parse document");
|
100
|
+
}
|
95
101
|
|
96
102
|
return Qnil;
|
97
103
|
}
|
@@ -109,7 +115,8 @@ static VALUE read_memory(int argc, VALUE *argv, VALUE klass)
|
|
109
115
|
*
|
110
116
|
* Create a new RelaxNG schema from the Nokogiri::XML::Document +doc+
|
111
117
|
*/
|
112
|
-
static VALUE
|
118
|
+
static VALUE
|
119
|
+
from_document(int argc, VALUE *argv, VALUE klass)
|
113
120
|
{
|
114
121
|
VALUE document;
|
115
122
|
VALUE parse_options;
|
@@ -126,7 +133,7 @@ static VALUE from_document(int argc, VALUE *argv, VALUE klass)
|
|
126
133
|
doc = doc->doc; /* In case someone passes us a node. ugh. */
|
127
134
|
|
128
135
|
if (scanned_args == 1) {
|
129
|
-
parse_options =
|
136
|
+
parse_options = rb_const_get_at(rb_const_get_at(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
130
137
|
}
|
131
138
|
|
132
139
|
ctx = xmlRelaxNGNewDocParserCtxt(doc);
|
@@ -147,12 +154,13 @@ static VALUE from_document(int argc, VALUE *argv, VALUE klass)
|
|
147
154
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
148
155
|
xmlRelaxNGFreeParserCtxt(ctx);
|
149
156
|
|
150
|
-
if(NULL == schema) {
|
157
|
+
if (NULL == schema) {
|
151
158
|
xmlErrorPtr error = xmlGetLastError();
|
152
|
-
if(error)
|
159
|
+
if (error) {
|
153
160
|
Nokogiri_error_raise(NULL, error);
|
154
|
-
else
|
161
|
+
} else {
|
155
162
|
rb_raise(rb_eRuntimeError, "Could not parse document");
|
163
|
+
}
|
156
164
|
|
157
165
|
return Qnil;
|
158
166
|
}
|
@@ -164,16 +172,14 @@ static VALUE from_document(int argc, VALUE *argv, VALUE klass)
|
|
164
172
|
return rb_schema;
|
165
173
|
}
|
166
174
|
|
167
|
-
|
168
|
-
|
175
|
+
void
|
176
|
+
noko_init_xml_relax_ng()
|
169
177
|
{
|
170
|
-
|
171
|
-
|
172
|
-
VALUE klass = rb_define_class_under(xml, "RelaxNG", cNokogiriXmlSchema);
|
178
|
+
assert(cNokogiriXmlSchema);
|
179
|
+
cNokogiriXmlRelaxNG = rb_define_class_under(mNokogiriXml, "RelaxNG", cNokogiriXmlSchema);
|
173
180
|
|
174
|
-
cNokogiriXmlRelaxNG
|
181
|
+
rb_define_singleton_method(cNokogiriXmlRelaxNG, "read_memory", read_memory, -1);
|
182
|
+
rb_define_singleton_method(cNokogiriXmlRelaxNG, "from_document", from_document, -1);
|
175
183
|
|
176
|
-
|
177
|
-
rb_define_singleton_method(klass, "from_document", from_document, -1);
|
178
|
-
rb_define_private_method(klass, "validate_document", validate_document, 1);
|
184
|
+
rb_define_private_method(cNokogiriXmlRelaxNG, "validate_document", validate_document, 1);
|
179
185
|
}
|
@@ -1,20 +1,23 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlSaxParser ;
|
2
4
|
|
3
5
|
static ID id_start_document, id_end_document, id_start_element, id_end_element;
|
4
6
|
static ID id_start_element_namespace, id_end_element_namespace;
|
5
7
|
static ID id_comment, id_characters, id_xmldecl, id_error, id_warning;
|
6
|
-
static ID id_cdata_block
|
8
|
+
static ID id_cdata_block;
|
7
9
|
static ID id_processing_instruction;
|
8
10
|
|
9
|
-
static void
|
11
|
+
static void
|
12
|
+
start_document(void *ctx)
|
10
13
|
{
|
11
14
|
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
12
15
|
VALUE doc = rb_iv_get(self, "@document");
|
13
16
|
|
14
17
|
xmlParserCtxtPtr ctxt = NOKOGIRI_SAX_CTXT(ctx);
|
15
18
|
|
16
|
-
if(NULL != ctxt && ctxt->html != 1) {
|
17
|
-
if(ctxt->standalone != -1) {
|
19
|
+
if (NULL != ctxt && ctxt->html != 1) {
|
20
|
+
if (ctxt->standalone != -1) { /* -1 means there was no declaration */
|
18
21
|
VALUE encoding = Qnil ;
|
19
22
|
VALUE standalone = Qnil;
|
20
23
|
VALUE version;
|
@@ -26,14 +29,13 @@ static void start_document(void * ctx)
|
|
26
29
|
|
27
30
|
version = ctxt->version ? NOKOGIRI_STR_NEW2(ctxt->version) : Qnil;
|
28
31
|
|
29
|
-
switch(ctxt->standalone)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
break;
|
32
|
+
switch (ctxt->standalone) {
|
33
|
+
case 0:
|
34
|
+
standalone = NOKOGIRI_STR_NEW2("no");
|
35
|
+
break;
|
36
|
+
case 1:
|
37
|
+
standalone = NOKOGIRI_STR_NEW2("yes");
|
38
|
+
break;
|
37
39
|
}
|
38
40
|
|
39
41
|
rb_funcall(doc, id_xmldecl, 3, version, encoding, standalone);
|
@@ -43,138 +45,140 @@ static void start_document(void * ctx)
|
|
43
45
|
rb_funcall(doc, id_start_document, 0);
|
44
46
|
}
|
45
47
|
|
46
|
-
static void
|
48
|
+
static void
|
49
|
+
end_document(void *ctx)
|
47
50
|
{
|
48
51
|
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
49
52
|
VALUE doc = rb_iv_get(self, "@document");
|
50
53
|
rb_funcall(doc, id_end_document, 0);
|
51
54
|
}
|
52
55
|
|
53
|
-
static void
|
56
|
+
static void
|
57
|
+
start_element(void *ctx, const xmlChar *name, const xmlChar **atts)
|
54
58
|
{
|
55
59
|
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
56
60
|
VALUE doc = rb_iv_get(self, "@document");
|
57
61
|
VALUE attributes = rb_ary_new();
|
58
|
-
const xmlChar *
|
62
|
+
const xmlChar *attr;
|
59
63
|
int i = 0;
|
60
|
-
if(atts) {
|
61
|
-
while((attr = atts[i]) != NULL) {
|
62
|
-
const xmlChar *
|
64
|
+
if (atts) {
|
65
|
+
while ((attr = atts[i]) != NULL) {
|
66
|
+
const xmlChar *val = atts[i + 1];
|
63
67
|
VALUE value = val != NULL ? NOKOGIRI_STR_NEW2(val) : Qnil;
|
64
68
|
rb_ary_push(attributes, rb_ary_new3(2, NOKOGIRI_STR_NEW2(attr), value));
|
65
|
-
i+=2;
|
69
|
+
i += 2;
|
66
70
|
}
|
67
71
|
}
|
68
72
|
|
69
|
-
rb_funcall(
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
rb_funcall(doc,
|
74
|
+
id_start_element,
|
75
|
+
2,
|
76
|
+
NOKOGIRI_STR_NEW2(name),
|
77
|
+
attributes
|
78
|
+
);
|
75
79
|
}
|
76
80
|
|
77
|
-
static void
|
81
|
+
static void
|
82
|
+
end_element(void *ctx, const xmlChar *name)
|
78
83
|
{
|
79
84
|
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
80
85
|
VALUE doc = rb_iv_get(self, "@document");
|
81
86
|
rb_funcall(doc, id_end_element, 1, NOKOGIRI_STR_NEW2(name));
|
82
87
|
}
|
83
88
|
|
84
|
-
static VALUE
|
85
|
-
|
86
|
-
int nb_attributes,
|
87
|
-
const xmlChar ** attributes)
|
89
|
+
static VALUE
|
90
|
+
attributes_as_array(int attributes_len, const xmlChar **c_attributes)
|
88
91
|
{
|
89
|
-
VALUE
|
92
|
+
VALUE rb_array = rb_ary_new2((long)attributes_len);
|
93
|
+
VALUE cNokogiriXmlSaxParserAttribute;
|
90
94
|
|
91
|
-
|
92
|
-
if (
|
95
|
+
cNokogiriXmlSaxParserAttribute = rb_const_get_at(cNokogiriXmlSaxParser, rb_intern("Attribute"));
|
96
|
+
if (c_attributes) {
|
93
97
|
/* Each attribute is an array of [localname, prefix, URI, value, end] */
|
94
98
|
int i;
|
95
|
-
for (i = 0; i <
|
96
|
-
VALUE
|
99
|
+
for (i = 0; i < attributes_len * 5; i += 5) {
|
100
|
+
VALUE rb_constructor_args[4], rb_attribute;
|
97
101
|
|
98
|
-
|
99
|
-
|
100
|
-
|
102
|
+
rb_constructor_args[0] = RBSTR_OR_QNIL(c_attributes[i + 0]); /* localname */
|
103
|
+
rb_constructor_args[1] = RBSTR_OR_QNIL(c_attributes[i + 1]); /* prefix */
|
104
|
+
rb_constructor_args[2] = RBSTR_OR_QNIL(c_attributes[i + 2]); /* URI */
|
101
105
|
|
102
106
|
/* value */
|
103
|
-
|
104
|
-
|
107
|
+
rb_constructor_args[3] = NOKOGIRI_STR_NEW((const char *)c_attributes[i + 3],
|
108
|
+
(c_attributes[i + 4] - c_attributes[i + 3]));
|
105
109
|
|
106
|
-
|
107
|
-
rb_ary_push(
|
110
|
+
rb_attribute = rb_class_new_instance(4, rb_constructor_args, cNokogiriXmlSaxParserAttribute);
|
111
|
+
rb_ary_push(rb_array, rb_attribute);
|
108
112
|
}
|
109
113
|
}
|
110
114
|
|
111
|
-
return
|
115
|
+
return rb_array;
|
112
116
|
}
|
113
117
|
|
114
118
|
static void
|
115
|
-
start_element_ns
|
116
|
-
void *
|
117
|
-
const xmlChar *
|
118
|
-
const xmlChar *
|
119
|
-
const xmlChar *
|
119
|
+
start_element_ns(
|
120
|
+
void *ctx,
|
121
|
+
const xmlChar *localname,
|
122
|
+
const xmlChar *prefix,
|
123
|
+
const xmlChar *uri,
|
120
124
|
int nb_namespaces,
|
121
|
-
const xmlChar **
|
125
|
+
const xmlChar **namespaces,
|
122
126
|
int nb_attributes,
|
123
127
|
int nb_defaulted,
|
124
|
-
const xmlChar **
|
128
|
+
const xmlChar **attributes)
|
125
129
|
{
|
126
130
|
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
127
131
|
VALUE doc = rb_iv_get(self, "@document");
|
128
132
|
|
129
|
-
VALUE
|
133
|
+
VALUE attribute_ary = attributes_as_array(nb_attributes, attributes);
|
130
134
|
|
131
135
|
VALUE ns_list = rb_ary_new2((long)nb_namespaces);
|
132
136
|
|
133
137
|
if (namespaces) {
|
134
138
|
int i;
|
135
|
-
for (i = 0; i < nb_namespaces * 2; i += 2)
|
136
|
-
{
|
139
|
+
for (i = 0; i < nb_namespaces * 2; i += 2) {
|
137
140
|
rb_ary_push(ns_list,
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
141
|
+
rb_ary_new3((long)2,
|
142
|
+
RBSTR_OR_QNIL(namespaces[i + 0]),
|
143
|
+
RBSTR_OR_QNIL(namespaces[i + 1])
|
144
|
+
)
|
145
|
+
);
|
143
146
|
}
|
144
147
|
}
|
145
148
|
|
146
|
-
rb_funcall(
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
149
|
+
rb_funcall(doc,
|
150
|
+
id_start_element_namespace,
|
151
|
+
5,
|
152
|
+
NOKOGIRI_STR_NEW2(localname),
|
153
|
+
attribute_ary,
|
154
|
+
RBSTR_OR_QNIL(prefix),
|
155
|
+
RBSTR_OR_QNIL(uri),
|
156
|
+
ns_list
|
157
|
+
);
|
155
158
|
}
|
156
159
|
|
157
160
|
/**
|
158
161
|
* end_element_ns was borrowed heavily from libxml-ruby.
|
159
162
|
*/
|
160
163
|
static void
|
161
|
-
end_element_ns
|
162
|
-
void *
|
163
|
-
const xmlChar *
|
164
|
-
const xmlChar *
|
165
|
-
const xmlChar *
|
164
|
+
end_element_ns(
|
165
|
+
void *ctx,
|
166
|
+
const xmlChar *localname,
|
167
|
+
const xmlChar *prefix,
|
168
|
+
const xmlChar *uri)
|
166
169
|
{
|
167
170
|
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
168
171
|
VALUE doc = rb_iv_get(self, "@document");
|
169
172
|
|
170
173
|
rb_funcall(doc, id_end_element_namespace, 3,
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
174
|
+
NOKOGIRI_STR_NEW2(localname),
|
175
|
+
RBSTR_OR_QNIL(prefix),
|
176
|
+
RBSTR_OR_QNIL(uri)
|
177
|
+
);
|
175
178
|
}
|
176
179
|
|
177
|
-
static void
|
180
|
+
static void
|
181
|
+
characters_func(void *ctx, const xmlChar *ch, int len)
|
178
182
|
{
|
179
183
|
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
180
184
|
VALUE doc = rb_iv_get(self, "@document");
|
@@ -182,7 +186,8 @@ static void characters_func(void * ctx, const xmlChar * ch, int len)
|
|
182
186
|
rb_funcall(doc, id_characters, 1, str);
|
183
187
|
}
|
184
188
|
|
185
|
-
static void
|
189
|
+
static void
|
190
|
+
comment_func(void *ctx, const xmlChar *value)
|
186
191
|
{
|
187
192
|
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
188
193
|
VALUE doc = rb_iv_get(self, "@document");
|
@@ -190,11 +195,12 @@ static void comment_func(void * ctx, const xmlChar * value)
|
|
190
195
|
rb_funcall(doc, id_comment, 1, str);
|
191
196
|
}
|
192
197
|
|
193
|
-
static void
|
198
|
+
static void
|
199
|
+
warning_func(void *ctx, const char *msg, ...)
|
194
200
|
{
|
195
201
|
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
196
202
|
VALUE doc = rb_iv_get(self, "@document");
|
197
|
-
char *
|
203
|
+
char *message;
|
198
204
|
VALUE ruby_message;
|
199
205
|
|
200
206
|
va_list args;
|
@@ -207,11 +213,12 @@ static void warning_func(void * ctx, const char *msg, ...)
|
|
207
213
|
rb_funcall(doc, id_warning, 1, ruby_message);
|
208
214
|
}
|
209
215
|
|
210
|
-
static void
|
216
|
+
static void
|
217
|
+
error_func(void *ctx, const char *msg, ...)
|
211
218
|
{
|
212
219
|
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
213
220
|
VALUE doc = rb_iv_get(self, "@document");
|
214
|
-
char *
|
221
|
+
char *message;
|
215
222
|
VALUE ruby_message;
|
216
223
|
|
217
224
|
va_list args;
|
@@ -224,7 +231,8 @@ static void error_func(void * ctx, const char *msg, ...)
|
|
224
231
|
rb_funcall(doc, id_error, 1, ruby_message);
|
225
232
|
}
|
226
233
|
|
227
|
-
static void
|
234
|
+
static void
|
235
|
+
cdata_block(void *ctx, const xmlChar *value, int len)
|
228
236
|
{
|
229
237
|
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
230
238
|
VALUE doc = rb_iv_get(self, "@document");
|
@@ -232,7 +240,8 @@ static void cdata_block(void * ctx, const xmlChar * value, int len)
|
|
232
240
|
rb_funcall(doc, id_cdata_block, 1, string);
|
233
241
|
}
|
234
242
|
|
235
|
-
static void
|
243
|
+
static void
|
244
|
+
processing_instruction(void *ctx, const xmlChar *name, const xmlChar *content)
|
236
245
|
{
|
237
246
|
VALUE rb_content;
|
238
247
|
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
@@ -240,22 +249,24 @@ static void processing_instruction(void * ctx, const xmlChar * name, const xmlCh
|
|
240
249
|
|
241
250
|
rb_content = content ? NOKOGIRI_STR_NEW2(content) : Qnil;
|
242
251
|
|
243
|
-
rb_funcall(
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
252
|
+
rb_funcall(doc,
|
253
|
+
id_processing_instruction,
|
254
|
+
2,
|
255
|
+
NOKOGIRI_STR_NEW2(name),
|
256
|
+
rb_content
|
257
|
+
);
|
249
258
|
}
|
250
259
|
|
251
|
-
static void
|
260
|
+
static void
|
261
|
+
deallocate(xmlSAXHandlerPtr handler)
|
252
262
|
{
|
253
263
|
NOKOGIRI_DEBUG_START(handler);
|
254
264
|
free(handler);
|
255
265
|
NOKOGIRI_DEBUG_END(handler);
|
256
266
|
}
|
257
267
|
|
258
|
-
static VALUE
|
268
|
+
static VALUE
|
269
|
+
allocate(VALUE klass)
|
259
270
|
{
|
260
271
|
xmlSAXHandlerPtr handler = calloc((size_t)1, sizeof(xmlSAXHandler));
|
261
272
|
|
@@ -276,29 +287,23 @@ static VALUE allocate(VALUE klass)
|
|
276
287
|
return Data_Wrap_Struct(klass, NULL, deallocate, handler);
|
277
288
|
}
|
278
289
|
|
279
|
-
|
280
|
-
|
290
|
+
void
|
291
|
+
noko_init_xml_sax_parser()
|
281
292
|
{
|
282
|
-
|
283
|
-
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
284
|
-
VALUE sax = rb_define_module_under(xml, "SAX");
|
285
|
-
VALUE klass = rb_define_class_under(sax, "Parser", rb_cObject);
|
286
|
-
|
287
|
-
cNokogiriXmlSaxParser = klass;
|
293
|
+
cNokogiriXmlSaxParser = rb_define_class_under(mNokogiriXmlSax, "Parser", rb_cObject);
|
288
294
|
|
289
|
-
rb_define_alloc_func(
|
295
|
+
rb_define_alloc_func(cNokogiriXmlSaxParser, allocate);
|
290
296
|
|
291
297
|
id_start_document = rb_intern("start_document");
|
292
|
-
id_end_document
|
293
|
-
id_start_element
|
294
|
-
id_end_element
|
295
|
-
id_comment
|
296
|
-
id_characters
|
297
|
-
id_xmldecl
|
298
|
-
id_error
|
299
|
-
id_warning
|
300
|
-
id_cdata_block
|
301
|
-
id_cAttribute = rb_intern("Attribute");
|
298
|
+
id_end_document = rb_intern("end_document");
|
299
|
+
id_start_element = rb_intern("start_element");
|
300
|
+
id_end_element = rb_intern("end_element");
|
301
|
+
id_comment = rb_intern("comment");
|
302
|
+
id_characters = rb_intern("characters");
|
303
|
+
id_xmldecl = rb_intern("xmldecl");
|
304
|
+
id_error = rb_intern("error");
|
305
|
+
id_warning = rb_intern("warning");
|
306
|
+
id_cdata_block = rb_intern("cdata_block");
|
302
307
|
id_start_element_namespace = rb_intern("start_element_namespace");
|
303
308
|
id_end_element_namespace = rb_intern("end_element_namespace");
|
304
309
|
id_processing_instruction = rb_intern("processing_instruction");
|