nokogiri 1.11.0.rc1-x86-linux

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.

Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-DEPENDENCIES.md +1614 -0
  3. data/LICENSE.md +9 -0
  4. data/README.md +200 -0
  5. data/bin/nokogiri +118 -0
  6. data/dependencies.yml +74 -0
  7. data/ext/nokogiri/depend +358 -0
  8. data/ext/nokogiri/extconf.rb +695 -0
  9. data/ext/nokogiri/html_document.c +170 -0
  10. data/ext/nokogiri/html_document.h +10 -0
  11. data/ext/nokogiri/html_element_description.c +279 -0
  12. data/ext/nokogiri/html_element_description.h +10 -0
  13. data/ext/nokogiri/html_entity_lookup.c +32 -0
  14. data/ext/nokogiri/html_entity_lookup.h +8 -0
  15. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  16. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  17. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  18. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  19. data/ext/nokogiri/nokogiri.c +147 -0
  20. data/ext/nokogiri/nokogiri.h +122 -0
  21. data/ext/nokogiri/xml_attr.c +103 -0
  22. data/ext/nokogiri/xml_attr.h +9 -0
  23. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  24. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  25. data/ext/nokogiri/xml_cdata.c +62 -0
  26. data/ext/nokogiri/xml_cdata.h +9 -0
  27. data/ext/nokogiri/xml_comment.c +69 -0
  28. data/ext/nokogiri/xml_comment.h +9 -0
  29. data/ext/nokogiri/xml_document.c +617 -0
  30. data/ext/nokogiri/xml_document.h +23 -0
  31. data/ext/nokogiri/xml_document_fragment.c +48 -0
  32. data/ext/nokogiri/xml_document_fragment.h +10 -0
  33. data/ext/nokogiri/xml_dtd.c +202 -0
  34. data/ext/nokogiri/xml_dtd.h +10 -0
  35. data/ext/nokogiri/xml_element_content.c +123 -0
  36. data/ext/nokogiri/xml_element_content.h +10 -0
  37. data/ext/nokogiri/xml_element_decl.c +69 -0
  38. data/ext/nokogiri/xml_element_decl.h +9 -0
  39. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  40. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  41. data/ext/nokogiri/xml_entity_decl.c +110 -0
  42. data/ext/nokogiri/xml_entity_decl.h +10 -0
  43. data/ext/nokogiri/xml_entity_reference.c +52 -0
  44. data/ext/nokogiri/xml_entity_reference.h +9 -0
  45. data/ext/nokogiri/xml_io.c +61 -0
  46. data/ext/nokogiri/xml_io.h +11 -0
  47. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  48. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  49. data/ext/nokogiri/xml_namespace.c +111 -0
  50. data/ext/nokogiri/xml_namespace.h +14 -0
  51. data/ext/nokogiri/xml_node.c +1773 -0
  52. data/ext/nokogiri/xml_node.h +13 -0
  53. data/ext/nokogiri/xml_node_set.c +486 -0
  54. data/ext/nokogiri/xml_node_set.h +12 -0
  55. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  56. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  57. data/ext/nokogiri/xml_reader.c +668 -0
  58. data/ext/nokogiri/xml_reader.h +10 -0
  59. data/ext/nokogiri/xml_relax_ng.c +161 -0
  60. data/ext/nokogiri/xml_relax_ng.h +9 -0
  61. data/ext/nokogiri/xml_sax_parser.c +310 -0
  62. data/ext/nokogiri/xml_sax_parser.h +39 -0
  63. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  64. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  65. data/ext/nokogiri/xml_sax_push_parser.c +159 -0
  66. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  67. data/ext/nokogiri/xml_schema.c +205 -0
  68. data/ext/nokogiri/xml_schema.h +9 -0
  69. data/ext/nokogiri/xml_syntax_error.c +64 -0
  70. data/ext/nokogiri/xml_syntax_error.h +13 -0
  71. data/ext/nokogiri/xml_text.c +52 -0
  72. data/ext/nokogiri/xml_text.h +9 -0
  73. data/ext/nokogiri/xml_xpath_context.c +298 -0
  74. data/ext/nokogiri/xml_xpath_context.h +10 -0
  75. data/ext/nokogiri/xslt_stylesheet.c +266 -0
  76. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  77. data/lib/nokogiri.rb +127 -0
  78. data/lib/nokogiri/2.4/nokogiri.so +0 -0
  79. data/lib/nokogiri/2.5/nokogiri.so +0 -0
  80. data/lib/nokogiri/2.6/nokogiri.so +0 -0
  81. data/lib/nokogiri/2.7/nokogiri.so +0 -0
  82. data/lib/nokogiri/css.rb +28 -0
  83. data/lib/nokogiri/css/node.rb +53 -0
  84. data/lib/nokogiri/css/parser.rb +751 -0
  85. data/lib/nokogiri/css/parser.y +272 -0
  86. data/lib/nokogiri/css/parser_extras.rb +92 -0
  87. data/lib/nokogiri/css/syntax_error.rb +8 -0
  88. data/lib/nokogiri/css/tokenizer.rb +154 -0
  89. data/lib/nokogiri/css/tokenizer.rex +55 -0
  90. data/lib/nokogiri/css/xpath_visitor.rb +232 -0
  91. data/lib/nokogiri/decorators/slop.rb +43 -0
  92. data/lib/nokogiri/html.rb +38 -0
  93. data/lib/nokogiri/html/builder.rb +36 -0
  94. data/lib/nokogiri/html/document.rb +336 -0
  95. data/lib/nokogiri/html/document_fragment.rb +50 -0
  96. data/lib/nokogiri/html/element_description.rb +24 -0
  97. data/lib/nokogiri/html/element_description_defaults.rb +672 -0
  98. data/lib/nokogiri/html/entity_lookup.rb +14 -0
  99. data/lib/nokogiri/html/sax/parser.rb +63 -0
  100. data/lib/nokogiri/html/sax/parser_context.rb +17 -0
  101. data/lib/nokogiri/html/sax/push_parser.rb +37 -0
  102. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  103. data/lib/nokogiri/syntax_error.rb +5 -0
  104. data/lib/nokogiri/version.rb +149 -0
  105. data/lib/nokogiri/xml.rb +76 -0
  106. data/lib/nokogiri/xml/attr.rb +15 -0
  107. data/lib/nokogiri/xml/attribute_decl.rb +19 -0
  108. data/lib/nokogiri/xml/builder.rb +447 -0
  109. data/lib/nokogiri/xml/cdata.rb +12 -0
  110. data/lib/nokogiri/xml/character_data.rb +8 -0
  111. data/lib/nokogiri/xml/document.rb +280 -0
  112. data/lib/nokogiri/xml/document_fragment.rb +161 -0
  113. data/lib/nokogiri/xml/dtd.rb +33 -0
  114. data/lib/nokogiri/xml/element_content.rb +37 -0
  115. data/lib/nokogiri/xml/element_decl.rb +14 -0
  116. data/lib/nokogiri/xml/entity_decl.rb +20 -0
  117. data/lib/nokogiri/xml/entity_reference.rb +19 -0
  118. data/lib/nokogiri/xml/namespace.rb +14 -0
  119. data/lib/nokogiri/xml/node.rb +916 -0
  120. data/lib/nokogiri/xml/node/save_options.rb +62 -0
  121. data/lib/nokogiri/xml/node_set.rb +372 -0
  122. data/lib/nokogiri/xml/notation.rb +7 -0
  123. data/lib/nokogiri/xml/parse_options.rb +121 -0
  124. data/lib/nokogiri/xml/pp.rb +3 -0
  125. data/lib/nokogiri/xml/pp/character_data.rb +19 -0
  126. data/lib/nokogiri/xml/pp/node.rb +57 -0
  127. data/lib/nokogiri/xml/processing_instruction.rb +9 -0
  128. data/lib/nokogiri/xml/reader.rb +116 -0
  129. data/lib/nokogiri/xml/relax_ng.rb +33 -0
  130. data/lib/nokogiri/xml/sax.rb +5 -0
  131. data/lib/nokogiri/xml/sax/document.rb +172 -0
  132. data/lib/nokogiri/xml/sax/parser.rb +123 -0
  133. data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
  134. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  135. data/lib/nokogiri/xml/schema.rb +64 -0
  136. data/lib/nokogiri/xml/searchable.rb +231 -0
  137. data/lib/nokogiri/xml/syntax_error.rb +71 -0
  138. data/lib/nokogiri/xml/text.rb +10 -0
  139. data/lib/nokogiri/xml/xpath.rb +11 -0
  140. data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
  141. data/lib/nokogiri/xml/xpath_context.rb +17 -0
  142. data/lib/nokogiri/xslt.rb +57 -0
  143. data/lib/nokogiri/xslt/stylesheet.rb +26 -0
  144. data/lib/xsd/xmlparser/nokogiri.rb +103 -0
  145. metadata +482 -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(handler);
8
+
9
+ ctxt->sax = NULL;
10
+
11
+ xmlFreeParserCtxt(ctxt);
12
+
13
+ NOKOGIRI_DEBUG_END(handler);
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? &amp; 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? &amp; 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,10 @@
1
+ #ifndef NOKOGIRI_XML_SAX_PARSER_CONTEXT
2
+ #define NOKOGIRI_XML_SAX_PARSER_CONTEXT
3
+
4
+ #include <nokogiri.h>
5
+
6
+ extern VALUE cNokogiriXmlSaxParserContext;
7
+
8
+ void init_xml_sax_parser_context();
9
+
10
+ #endif
@@ -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? &amp; 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? &amp; 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
+ }