nokogiri 1.11.0-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 +7 -0
- data/Gemfile +3 -0
- data/LICENSE-DEPENDENCIES.md +1682 -0
- data/LICENSE.md +9 -0
- data/README.md +272 -0
- data/bin/nokogiri +118 -0
- data/dependencies.yml +74 -0
- data/ext/nokogiri/depend +477 -0
- data/ext/nokogiri/extconf.rb +836 -0
- data/ext/nokogiri/html_document.c +171 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +279 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +32 -0
- data/ext/nokogiri/html_entity_lookup.h +8 -0
- data/ext/nokogiri/html_sax_parser_context.c +116 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/html_sax_push_parser.c +87 -0
- data/ext/nokogiri/html_sax_push_parser.h +9 -0
- data/ext/nokogiri/include/libexslt/exslt.h +102 -0
- data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
- data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +126 -0
- data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
- data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
- data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
- data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
- data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
- data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1241 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
- data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
- data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
- data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
- data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +366 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +945 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +153 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +566 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
- data/ext/nokogiri/include/libxslt/attributes.h +38 -0
- data/ext/nokogiri/include/libxslt/documents.h +93 -0
- data/ext/nokogiri/include/libxslt/extensions.h +262 -0
- data/ext/nokogiri/include/libxslt/extra.h +72 -0
- data/ext/nokogiri/include/libxslt/functions.h +78 -0
- data/ext/nokogiri/include/libxslt/imports.h +75 -0
- data/ext/nokogiri/include/libxslt/keys.h +53 -0
- data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
- data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
- data/ext/nokogiri/include/libxslt/pattern.h +84 -0
- data/ext/nokogiri/include/libxslt/preproc.h +43 -0
- data/ext/nokogiri/include/libxslt/security.h +104 -0
- data/ext/nokogiri/include/libxslt/templates.h +77 -0
- data/ext/nokogiri/include/libxslt/transform.h +207 -0
- data/ext/nokogiri/include/libxslt/variables.h +118 -0
- data/ext/nokogiri/include/libxslt/xslt.h +110 -0
- data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
- data/ext/nokogiri/nokogiri.c +135 -0
- data/ext/nokogiri/nokogiri.h +130 -0
- data/ext/nokogiri/xml_attr.c +103 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +62 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +69 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +622 -0
- data/ext/nokogiri/xml_document.h +23 -0
- data/ext/nokogiri/xml_document_fragment.c +48 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +202 -0
- data/ext/nokogiri/xml_dtd.h +10 -0
- data/ext/nokogiri/xml_element_content.c +123 -0
- data/ext/nokogiri/xml_element_content.h +10 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_element_decl.h +9 -0
- data/ext/nokogiri/xml_encoding_handler.c +79 -0
- data/ext/nokogiri/xml_encoding_handler.h +8 -0
- data/ext/nokogiri/xml_entity_decl.c +110 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +52 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +63 -0
- data/ext/nokogiri/xml_io.h +11 -0
- data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
- data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
- data/ext/nokogiri/xml_namespace.c +111 -0
- data/ext/nokogiri/xml_namespace.h +14 -0
- data/ext/nokogiri/xml_node.c +1773 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +486 -0
- data/ext/nokogiri/xml_node_set.h +12 -0
- data/ext/nokogiri/xml_processing_instruction.c +56 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +657 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +179 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +305 -0
- data/ext/nokogiri/xml_sax_parser.h +39 -0
- data/ext/nokogiri/xml_sax_parser_context.c +262 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +159 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +276 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +64 -0
- data/ext/nokogiri/xml_syntax_error.h +13 -0
- data/ext/nokogiri/xml_text.c +52 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath_context.c +374 -0
- data/ext/nokogiri/xml_xpath_context.h +10 -0
- data/ext/nokogiri/xslt_stylesheet.c +263 -0
- data/ext/nokogiri/xslt_stylesheet.h +14 -0
- data/lib/nokogiri.rb +144 -0
- 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.rb +28 -0
- data/lib/nokogiri/css/node.rb +53 -0
- data/lib/nokogiri/css/parser.rb +751 -0
- data/lib/nokogiri/css/parser.y +272 -0
- data/lib/nokogiri/css/parser_extras.rb +94 -0
- data/lib/nokogiri/css/syntax_error.rb +8 -0
- data/lib/nokogiri/css/tokenizer.rb +154 -0
- data/lib/nokogiri/css/tokenizer.rex +55 -0
- data/lib/nokogiri/css/xpath_visitor.rb +260 -0
- data/lib/nokogiri/decorators/slop.rb +43 -0
- data/lib/nokogiri/html.rb +38 -0
- data/lib/nokogiri/html/builder.rb +36 -0
- data/lib/nokogiri/html/document.rb +322 -0
- data/lib/nokogiri/html/document_fragment.rb +50 -0
- data/lib/nokogiri/html/element_description.rb +24 -0
- data/lib/nokogiri/html/element_description_defaults.rb +672 -0
- data/lib/nokogiri/html/entity_lookup.rb +14 -0
- data/lib/nokogiri/html/sax/parser.rb +63 -0
- data/lib/nokogiri/html/sax/parser_context.rb +17 -0
- data/lib/nokogiri/html/sax/push_parser.rb +37 -0
- data/lib/nokogiri/jruby/dependencies.rb +20 -0
- data/lib/nokogiri/syntax_error.rb +5 -0
- data/lib/nokogiri/version.rb +3 -0
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +182 -0
- data/lib/nokogiri/xml.rb +76 -0
- data/lib/nokogiri/xml/attr.rb +15 -0
- data/lib/nokogiri/xml/attribute_decl.rb +19 -0
- data/lib/nokogiri/xml/builder.rb +447 -0
- data/lib/nokogiri/xml/cdata.rb +12 -0
- data/lib/nokogiri/xml/character_data.rb +8 -0
- data/lib/nokogiri/xml/document.rb +290 -0
- data/lib/nokogiri/xml/document_fragment.rb +159 -0
- data/lib/nokogiri/xml/dtd.rb +33 -0
- data/lib/nokogiri/xml/element_content.rb +37 -0
- data/lib/nokogiri/xml/element_decl.rb +14 -0
- data/lib/nokogiri/xml/entity_decl.rb +20 -0
- data/lib/nokogiri/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/xml/namespace.rb +14 -0
- data/lib/nokogiri/xml/node.rb +1240 -0
- data/lib/nokogiri/xml/node/save_options.rb +62 -0
- data/lib/nokogiri/xml/node_set.rb +372 -0
- data/lib/nokogiri/xml/notation.rb +7 -0
- data/lib/nokogiri/xml/parse_options.rb +127 -0
- data/lib/nokogiri/xml/pp.rb +3 -0
- data/lib/nokogiri/xml/pp/character_data.rb +19 -0
- data/lib/nokogiri/xml/pp/node.rb +57 -0
- data/lib/nokogiri/xml/processing_instruction.rb +9 -0
- data/lib/nokogiri/xml/reader.rb +116 -0
- data/lib/nokogiri/xml/relax_ng.rb +37 -0
- data/lib/nokogiri/xml/sax.rb +5 -0
- data/lib/nokogiri/xml/sax/document.rb +172 -0
- data/lib/nokogiri/xml/sax/parser.rb +123 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
- data/lib/nokogiri/xml/schema.rb +72 -0
- data/lib/nokogiri/xml/searchable.rb +239 -0
- data/lib/nokogiri/xml/syntax_error.rb +71 -0
- data/lib/nokogiri/xml/text.rb +10 -0
- data/lib/nokogiri/xml/xpath.rb +11 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
- data/lib/nokogiri/xml/xpath_context.rb +17 -0
- data/lib/nokogiri/xslt.rb +57 -0
- data/lib/nokogiri/xslt/stylesheet.rb +26 -0
- data/lib/xsd/xmlparser/nokogiri.rb +103 -0
- metadata +499 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
#ifndef NOKOGIRI_XML_SAX_PARSER
|
2
|
+
#define NOKOGIRI_XML_SAX_PARSER
|
3
|
+
|
4
|
+
#include <nokogiri.h>
|
5
|
+
|
6
|
+
void init_xml_sax_parser();
|
7
|
+
|
8
|
+
extern VALUE cNokogiriXmlSaxParser ;
|
9
|
+
|
10
|
+
typedef struct _nokogiriSAXTuple {
|
11
|
+
xmlParserCtxtPtr ctxt;
|
12
|
+
VALUE self;
|
13
|
+
} nokogiriSAXTuple;
|
14
|
+
|
15
|
+
typedef nokogiriSAXTuple * nokogiriSAXTuplePtr;
|
16
|
+
|
17
|
+
#define NOKOGIRI_SAX_SELF(_ctxt) \
|
18
|
+
((nokogiriSAXTuplePtr)(_ctxt))->self
|
19
|
+
|
20
|
+
#define NOKOGIRI_SAX_CTXT(_ctxt) \
|
21
|
+
((nokogiriSAXTuplePtr)(_ctxt))->ctxt
|
22
|
+
|
23
|
+
#define NOKOGIRI_SAX_TUPLE_NEW(_ctxt, _self) \
|
24
|
+
nokogiri_sax_tuple_new(_ctxt, _self)
|
25
|
+
|
26
|
+
static inline nokogiriSAXTuplePtr
|
27
|
+
nokogiri_sax_tuple_new(xmlParserCtxtPtr ctxt, VALUE self)
|
28
|
+
{
|
29
|
+
nokogiriSAXTuplePtr tuple = malloc(sizeof(nokogiriSAXTuple));
|
30
|
+
tuple->self = self;
|
31
|
+
tuple->ctxt = ctxt;
|
32
|
+
return tuple;
|
33
|
+
}
|
34
|
+
|
35
|
+
#define NOKOGIRI_SAX_TUPLE_DESTROY(_tuple) \
|
36
|
+
free(_tuple) \
|
37
|
+
|
38
|
+
#endif
|
39
|
+
|
@@ -0,0 +1,262 @@
|
|
1
|
+
#include <xml_sax_parser_context.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlSaxParserContext ;
|
4
|
+
|
5
|
+
static void deallocate(xmlParserCtxtPtr ctxt)
|
6
|
+
{
|
7
|
+
NOKOGIRI_DEBUG_START(ctxt);
|
8
|
+
|
9
|
+
ctxt->sax = NULL;
|
10
|
+
|
11
|
+
xmlFreeParserCtxt(ctxt);
|
12
|
+
|
13
|
+
NOKOGIRI_DEBUG_END(ctxt);
|
14
|
+
}
|
15
|
+
|
16
|
+
/*
|
17
|
+
* call-seq:
|
18
|
+
* parse_io(io, encoding)
|
19
|
+
*
|
20
|
+
* Parse +io+ object with +encoding+
|
21
|
+
*/
|
22
|
+
static VALUE
|
23
|
+
parse_io(VALUE klass, VALUE io, VALUE encoding)
|
24
|
+
{
|
25
|
+
xmlParserCtxtPtr ctxt;
|
26
|
+
xmlCharEncoding enc = (xmlCharEncoding)NUM2INT(encoding);
|
27
|
+
|
28
|
+
ctxt = xmlCreateIOParserCtxt(NULL, NULL,
|
29
|
+
(xmlInputReadCallback)io_read_callback,
|
30
|
+
(xmlInputCloseCallback)io_close_callback,
|
31
|
+
(void *)io, enc);
|
32
|
+
if (ctxt->sax) {
|
33
|
+
xmlFree(ctxt->sax);
|
34
|
+
ctxt->sax = NULL;
|
35
|
+
}
|
36
|
+
|
37
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
|
38
|
+
}
|
39
|
+
|
40
|
+
/*
|
41
|
+
* call-seq:
|
42
|
+
* parse_file(filename)
|
43
|
+
*
|
44
|
+
* Parse file given +filename+
|
45
|
+
*/
|
46
|
+
static VALUE parse_file(VALUE klass, VALUE filename)
|
47
|
+
{
|
48
|
+
xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(StringValueCStr(filename));
|
49
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
53
|
+
* call-seq:
|
54
|
+
* parse_memory(data)
|
55
|
+
*
|
56
|
+
* Parse the XML stored in memory in +data+
|
57
|
+
*/
|
58
|
+
static VALUE
|
59
|
+
parse_memory(VALUE klass, VALUE data)
|
60
|
+
{
|
61
|
+
xmlParserCtxtPtr ctxt;
|
62
|
+
|
63
|
+
if (NIL_P(data))
|
64
|
+
rb_raise(rb_eArgError, "data cannot be nil");
|
65
|
+
if (!(int)RSTRING_LEN(data))
|
66
|
+
rb_raise(rb_eRuntimeError, "data cannot be empty");
|
67
|
+
|
68
|
+
ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(data),
|
69
|
+
(int)RSTRING_LEN(data));
|
70
|
+
if (ctxt->sax) {
|
71
|
+
xmlFree(ctxt->sax);
|
72
|
+
ctxt->sax = NULL;
|
73
|
+
}
|
74
|
+
|
75
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
|
76
|
+
}
|
77
|
+
|
78
|
+
static VALUE
|
79
|
+
parse_doc(VALUE ctxt_val)
|
80
|
+
{
|
81
|
+
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctxt_val;
|
82
|
+
xmlParseDocument(ctxt);
|
83
|
+
return Qnil;
|
84
|
+
}
|
85
|
+
|
86
|
+
static VALUE
|
87
|
+
parse_doc_finalize(VALUE ctxt_val)
|
88
|
+
{
|
89
|
+
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctxt_val;
|
90
|
+
|
91
|
+
if (NULL != ctxt->myDoc)
|
92
|
+
xmlFreeDoc(ctxt->myDoc);
|
93
|
+
|
94
|
+
NOKOGIRI_SAX_TUPLE_DESTROY(ctxt->userData);
|
95
|
+
return Qnil;
|
96
|
+
}
|
97
|
+
|
98
|
+
/*
|
99
|
+
* call-seq:
|
100
|
+
* parse_with(sax_handler)
|
101
|
+
*
|
102
|
+
* Use +sax_handler+ and parse the current document
|
103
|
+
*/
|
104
|
+
static VALUE
|
105
|
+
parse_with(VALUE self, VALUE sax_handler)
|
106
|
+
{
|
107
|
+
xmlParserCtxtPtr ctxt;
|
108
|
+
xmlSAXHandlerPtr sax;
|
109
|
+
|
110
|
+
if (!rb_obj_is_kind_of(sax_handler, cNokogiriXmlSaxParser))
|
111
|
+
rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::SAX::Parser");
|
112
|
+
|
113
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
114
|
+
Data_Get_Struct(sax_handler, xmlSAXHandler, sax);
|
115
|
+
|
116
|
+
/* Free the sax handler since we'll assign our own */
|
117
|
+
if (ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler)
|
118
|
+
xmlFree(ctxt->sax);
|
119
|
+
|
120
|
+
ctxt->sax = sax;
|
121
|
+
ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);
|
122
|
+
|
123
|
+
rb_ensure(parse_doc, (VALUE)ctxt, parse_doc_finalize, (VALUE)ctxt);
|
124
|
+
|
125
|
+
return Qnil;
|
126
|
+
}
|
127
|
+
|
128
|
+
/*
|
129
|
+
* call-seq:
|
130
|
+
* replace_entities=(boolean)
|
131
|
+
*
|
132
|
+
* Should this parser replace entities? & will get converted to '&' if
|
133
|
+
* set to true
|
134
|
+
*/
|
135
|
+
static VALUE set_replace_entities(VALUE self, VALUE value)
|
136
|
+
{
|
137
|
+
xmlParserCtxtPtr ctxt;
|
138
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
139
|
+
|
140
|
+
if(Qfalse == value)
|
141
|
+
ctxt->replaceEntities = 0;
|
142
|
+
else
|
143
|
+
ctxt->replaceEntities = 1;
|
144
|
+
|
145
|
+
return value;
|
146
|
+
}
|
147
|
+
|
148
|
+
/*
|
149
|
+
* call-seq:
|
150
|
+
* replace_entities
|
151
|
+
*
|
152
|
+
* Should this parser replace entities? & will get converted to '&' if
|
153
|
+
* set to true
|
154
|
+
*/
|
155
|
+
static VALUE get_replace_entities(VALUE self)
|
156
|
+
{
|
157
|
+
xmlParserCtxtPtr ctxt;
|
158
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
159
|
+
|
160
|
+
if(0 == ctxt->replaceEntities)
|
161
|
+
return Qfalse;
|
162
|
+
else
|
163
|
+
return Qtrue;
|
164
|
+
}
|
165
|
+
|
166
|
+
/*
|
167
|
+
* call-seq: line
|
168
|
+
*
|
169
|
+
* Get the current line the parser context is processing.
|
170
|
+
*/
|
171
|
+
static VALUE line(VALUE self)
|
172
|
+
{
|
173
|
+
xmlParserCtxtPtr ctxt;
|
174
|
+
xmlParserInputPtr io;
|
175
|
+
|
176
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
177
|
+
|
178
|
+
io = ctxt->input;
|
179
|
+
if(io)
|
180
|
+
return INT2NUM(io->line);
|
181
|
+
|
182
|
+
return Qnil;
|
183
|
+
}
|
184
|
+
|
185
|
+
/*
|
186
|
+
* call-seq: column
|
187
|
+
*
|
188
|
+
* Get the current column the parser context is processing.
|
189
|
+
*/
|
190
|
+
static VALUE column(VALUE self)
|
191
|
+
{
|
192
|
+
xmlParserCtxtPtr ctxt;
|
193
|
+
xmlParserInputPtr io;
|
194
|
+
|
195
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
196
|
+
|
197
|
+
io = ctxt->input;
|
198
|
+
if(io)
|
199
|
+
return INT2NUM(io->col);
|
200
|
+
|
201
|
+
return Qnil;
|
202
|
+
}
|
203
|
+
|
204
|
+
/*
|
205
|
+
* call-seq:
|
206
|
+
* recovery=(boolean)
|
207
|
+
*
|
208
|
+
* Should this parser recover from structural errors? It will not stop processing
|
209
|
+
* file on structural errors if set to true
|
210
|
+
*/
|
211
|
+
static VALUE set_recovery(VALUE self, VALUE value)
|
212
|
+
{
|
213
|
+
xmlParserCtxtPtr ctxt;
|
214
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
215
|
+
|
216
|
+
if(value == Qfalse)
|
217
|
+
ctxt->recovery = 0;
|
218
|
+
else
|
219
|
+
ctxt->recovery = 1;
|
220
|
+
|
221
|
+
return value;
|
222
|
+
}
|
223
|
+
|
224
|
+
/*
|
225
|
+
* call-seq:
|
226
|
+
* recovery
|
227
|
+
*
|
228
|
+
* Should this parser recover from structural errors? It will not stop processing
|
229
|
+
* file on structural errors if set to true
|
230
|
+
*/
|
231
|
+
static VALUE get_recovery(VALUE self)
|
232
|
+
{
|
233
|
+
xmlParserCtxtPtr ctxt;
|
234
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
235
|
+
|
236
|
+
if(ctxt->recovery == 0)
|
237
|
+
return Qfalse;
|
238
|
+
else
|
239
|
+
return Qtrue;
|
240
|
+
}
|
241
|
+
|
242
|
+
void init_xml_sax_parser_context()
|
243
|
+
{
|
244
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
245
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
246
|
+
VALUE sax = rb_define_module_under(xml, "SAX");
|
247
|
+
VALUE klass = rb_define_class_under(sax, "ParserContext", rb_cObject);
|
248
|
+
|
249
|
+
cNokogiriXmlSaxParserContext = klass;
|
250
|
+
|
251
|
+
rb_define_singleton_method(klass, "io", parse_io, 2);
|
252
|
+
rb_define_singleton_method(klass, "memory", parse_memory, 1);
|
253
|
+
rb_define_singleton_method(klass, "file", parse_file, 1);
|
254
|
+
|
255
|
+
rb_define_method(klass, "parse_with", parse_with, 1);
|
256
|
+
rb_define_method(klass, "replace_entities=", set_replace_entities, 1);
|
257
|
+
rb_define_method(klass, "replace_entities", get_replace_entities, 0);
|
258
|
+
rb_define_method(klass, "recovery=", set_recovery, 1);
|
259
|
+
rb_define_method(klass, "recovery", get_recovery, 0);
|
260
|
+
rb_define_method(klass, "line", line, 0);
|
261
|
+
rb_define_method(klass, "column", column, 0);
|
262
|
+
}
|
@@ -0,0 +1,159 @@
|
|
1
|
+
#include <xml_sax_push_parser.h>
|
2
|
+
|
3
|
+
static void deallocate(xmlParserCtxtPtr ctx)
|
4
|
+
{
|
5
|
+
NOKOGIRI_DEBUG_START(ctx);
|
6
|
+
if (ctx != NULL) {
|
7
|
+
NOKOGIRI_SAX_TUPLE_DESTROY(ctx->userData);
|
8
|
+
xmlFreeParserCtxt(ctx);
|
9
|
+
}
|
10
|
+
NOKOGIRI_DEBUG_END(ctx);
|
11
|
+
}
|
12
|
+
|
13
|
+
static VALUE allocate(VALUE klass)
|
14
|
+
{
|
15
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, NULL);
|
16
|
+
}
|
17
|
+
|
18
|
+
/*
|
19
|
+
* call-seq:
|
20
|
+
* native_write(chunk, last_chunk)
|
21
|
+
*
|
22
|
+
* Write +chunk+ to PushParser. +last_chunk+ triggers the end_document handle
|
23
|
+
*/
|
24
|
+
static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
|
25
|
+
{
|
26
|
+
xmlParserCtxtPtr ctx;
|
27
|
+
const char * chunk = NULL;
|
28
|
+
int size = 0;
|
29
|
+
|
30
|
+
|
31
|
+
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
32
|
+
|
33
|
+
if (Qnil != _chunk) {
|
34
|
+
chunk = StringValuePtr(_chunk);
|
35
|
+
size = (int)RSTRING_LEN(_chunk);
|
36
|
+
}
|
37
|
+
|
38
|
+
if (xmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
|
39
|
+
if (!(ctx->options & XML_PARSE_RECOVER)) {
|
40
|
+
xmlErrorPtr e = xmlCtxtGetLastError(ctx);
|
41
|
+
Nokogiri_error_raise(NULL, e);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
return self;
|
46
|
+
}
|
47
|
+
|
48
|
+
/*
|
49
|
+
* call-seq:
|
50
|
+
* initialize_native(xml_sax, filename)
|
51
|
+
*
|
52
|
+
* Initialize the push parser with +xml_sax+ using +filename+
|
53
|
+
*/
|
54
|
+
static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename)
|
55
|
+
{
|
56
|
+
xmlSAXHandlerPtr sax;
|
57
|
+
const char * filename = NULL;
|
58
|
+
xmlParserCtxtPtr ctx;
|
59
|
+
|
60
|
+
Data_Get_Struct(_xml_sax, xmlSAXHandler, sax);
|
61
|
+
|
62
|
+
if (_filename != Qnil) { filename = StringValueCStr(_filename); }
|
63
|
+
|
64
|
+
ctx = xmlCreatePushParserCtxt(
|
65
|
+
sax,
|
66
|
+
NULL,
|
67
|
+
NULL,
|
68
|
+
0,
|
69
|
+
filename
|
70
|
+
);
|
71
|
+
if (ctx == NULL) {
|
72
|
+
rb_raise(rb_eRuntimeError, "Could not create a parser context");
|
73
|
+
}
|
74
|
+
|
75
|
+
ctx->userData = NOKOGIRI_SAX_TUPLE_NEW(ctx, self);
|
76
|
+
|
77
|
+
ctx->sax2 = 1;
|
78
|
+
DATA_PTR(self) = ctx;
|
79
|
+
return self;
|
80
|
+
}
|
81
|
+
|
82
|
+
static VALUE get_options(VALUE self)
|
83
|
+
{
|
84
|
+
xmlParserCtxtPtr ctx;
|
85
|
+
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
86
|
+
|
87
|
+
return INT2NUM(ctx->options);
|
88
|
+
}
|
89
|
+
|
90
|
+
static VALUE set_options(VALUE self, VALUE options)
|
91
|
+
{
|
92
|
+
xmlParserCtxtPtr ctx;
|
93
|
+
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
94
|
+
|
95
|
+
if (xmlCtxtUseOptions(ctx, (int)NUM2INT(options)) != 0) {
|
96
|
+
rb_raise(rb_eRuntimeError, "Cannot set XML parser context options");
|
97
|
+
}
|
98
|
+
|
99
|
+
return Qnil;
|
100
|
+
}
|
101
|
+
|
102
|
+
/*
|
103
|
+
* call-seq:
|
104
|
+
* replace_entities
|
105
|
+
*
|
106
|
+
* Should this parser replace entities? & will get converted to '&' if
|
107
|
+
* set to true
|
108
|
+
*/
|
109
|
+
static VALUE get_replace_entities(VALUE self)
|
110
|
+
{
|
111
|
+
xmlParserCtxtPtr ctx;
|
112
|
+
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
113
|
+
|
114
|
+
if (0 == ctx->replaceEntities) {
|
115
|
+
return Qfalse;
|
116
|
+
} else {
|
117
|
+
return Qtrue;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
/*
|
122
|
+
* call-seq:
|
123
|
+
* replace_entities=(boolean)
|
124
|
+
*
|
125
|
+
* Should this parser replace entities? & will get converted to '&' if
|
126
|
+
* set to true
|
127
|
+
*/
|
128
|
+
static VALUE set_replace_entities(VALUE self, VALUE value)
|
129
|
+
{
|
130
|
+
xmlParserCtxtPtr ctx;
|
131
|
+
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
132
|
+
|
133
|
+
if (Qfalse == value) {
|
134
|
+
ctx->replaceEntities = 0;
|
135
|
+
} else {
|
136
|
+
ctx->replaceEntities = 1;
|
137
|
+
}
|
138
|
+
|
139
|
+
return value;
|
140
|
+
}
|
141
|
+
|
142
|
+
VALUE cNokogiriXmlSaxPushParser ;
|
143
|
+
void init_xml_sax_push_parser()
|
144
|
+
{
|
145
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
146
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
147
|
+
VALUE sax = rb_define_module_under(xml, "SAX");
|
148
|
+
VALUE klass = rb_define_class_under(sax, "PushParser", rb_cObject);
|
149
|
+
|
150
|
+
cNokogiriXmlSaxPushParser = klass;
|
151
|
+
|
152
|
+
rb_define_alloc_func(klass, allocate);
|
153
|
+
rb_define_private_method(klass, "initialize_native", initialize_native, 2);
|
154
|
+
rb_define_private_method(klass, "native_write", native_write, 2);
|
155
|
+
rb_define_method(klass, "options", get_options, 0);
|
156
|
+
rb_define_method(klass, "options=", set_options, 1);
|
157
|
+
rb_define_method(klass, "replace_entities", get_replace_entities, 0);
|
158
|
+
rb_define_method(klass, "replace_entities=", set_replace_entities, 1);
|
159
|
+
}
|