nokogiri 1.3.1-x86-mswin32 → 1.3.2-x86-mswin32
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.
- data/CHANGELOG.ja.rdoc +25 -0
- data/CHANGELOG.rdoc +23 -0
- data/Manifest.txt +5 -0
- data/README.ja.rdoc +5 -5
- data/README.rdoc +3 -3
- data/Rakefile +25 -21
- data/ext/nokogiri/extconf.rb +54 -12
- data/ext/nokogiri/xml_document.c +4 -1
- data/ext/nokogiri/xml_document.h +2 -0
- data/ext/nokogiri/xml_dtd.c +29 -0
- data/ext/nokogiri/xml_node.c +9 -1
- data/ext/nokogiri/xml_node_set.c +5 -1
- data/ext/nokogiri/xml_relax_ng.c +50 -3
- data/ext/nokogiri/xml_sax_parser.c +84 -77
- data/ext/nokogiri/xml_schema.c +52 -3
- data/ext/nokogiri/xml_syntax_error.c +7 -0
- data/ext/nokogiri/xml_syntax_error.h +1 -0
- data/lib/nokogiri.rb +2 -2
- data/lib/nokogiri/1.8/nokogiri.so +0 -0
- data/lib/nokogiri/1.9/nokogiri.so +0 -0
- data/lib/nokogiri/css/parser.rb +2 -2
- data/lib/nokogiri/ffi/io_callbacks.rb +20 -12
- data/lib/nokogiri/ffi/libxml.rb +8 -0
- data/lib/nokogiri/ffi/xml/document.rb +1 -1
- data/lib/nokogiri/ffi/xml/dtd.rb +22 -6
- data/lib/nokogiri/ffi/xml/namespace.rb +9 -7
- data/lib/nokogiri/ffi/xml/node.rb +4 -0
- data/lib/nokogiri/ffi/xml/node_set.rb +4 -1
- data/lib/nokogiri/ffi/xml/relax_ng.rb +35 -3
- data/lib/nokogiri/ffi/xml/sax/parser.rb +20 -19
- data/lib/nokogiri/ffi/xml/schema.rb +41 -4
- data/lib/nokogiri/html.rb +2 -2
- data/lib/nokogiri/html/document.rb +3 -3
- data/lib/nokogiri/version.rb +2 -2
- data/lib/nokogiri/xml.rb +3 -3
- data/lib/nokogiri/xml/document.rb +14 -4
- data/lib/nokogiri/xml/fragment_handler.rb +8 -0
- data/lib/nokogiri/xml/node.rb +1 -104
- data/lib/nokogiri/xml/node_set.rb +46 -6
- data/lib/nokogiri/xml/parse_options.rb +7 -2
- data/lib/nokogiri/xml/relax_ng.rb +2 -2
- data/lib/nokogiri/xml/sax.rb +1 -0
- data/lib/nokogiri/xml/sax/document.rb +4 -4
- data/lib/nokogiri/xml/sax/legacy_handlers.rb +65 -0
- data/lib/nokogiri/xml/sax/parser.rb +7 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +3 -0
- data/lib/nokogiri/xml/schema.rb +1 -5
- data/lib/xsd/xmlparser/nokogiri.rb +14 -7
- data/tasks/test.rb +1 -62
- data/test/files/bar/bar.xsd +4 -0
- data/test/files/foo/foo.xsd +4 -0
- data/test/files/snuggles.xml +3 -0
- data/test/files/valid_bar.xml +2 -0
- data/test/helper.rb +9 -8
- data/test/html/test_document_fragment.rb +14 -0
- data/test/test_reader.rb +10 -10
- data/test/xml/sax/test_parser.rb +77 -0
- data/test/xml/sax/test_push_parser.rb +11 -7
- data/test/xml/test_document.rb +25 -0
- data/test/xml/test_dtd.rb +6 -1
- data/test/xml/test_node.rb +7 -0
- data/test/xml/test_node_set.rb +19 -0
- data/test/xml/test_schema.rb +24 -0
- metadata +10 -5
@@ -1,5 +1,11 @@
|
|
1
1
|
#include <nokogiri.h>
|
2
2
|
|
3
|
+
#define STRING_OR_NULL(str) \
|
4
|
+
(RTEST(str) ? StringValuePtr(str) : NULL)
|
5
|
+
|
6
|
+
#define RBSTR_OR_QNIL(_str, rb_enc) \
|
7
|
+
(_str ? NOKOGIRI_STR_NEW2(_str, STRING_OR_NULL(rb_enc)) : Qnil)
|
8
|
+
|
3
9
|
/*
|
4
10
|
* call-seq:
|
5
11
|
* parse_memory(data)
|
@@ -89,7 +95,7 @@ static void start_element(void * ctx, const xmlChar *name, const xmlChar **atts)
|
|
89
95
|
if(atts) {
|
90
96
|
while((attr = atts[i]) != NULL) {
|
91
97
|
rb_funcall(attributes, rb_intern("<<"), 1,
|
92
|
-
NOKOGIRI_STR_NEW2(attr,
|
98
|
+
NOKOGIRI_STR_NEW2(attr, STRING_OR_NULL(enc))
|
93
99
|
);
|
94
100
|
i++;
|
95
101
|
}
|
@@ -98,7 +104,7 @@ static void start_element(void * ctx, const xmlChar *name, const xmlChar **atts)
|
|
98
104
|
rb_funcall( doc,
|
99
105
|
rb_intern("start_element"),
|
100
106
|
2,
|
101
|
-
NOKOGIRI_STR_NEW2(name,
|
107
|
+
NOKOGIRI_STR_NEW2(name, STRING_OR_NULL(enc)),
|
102
108
|
attributes
|
103
109
|
);
|
104
110
|
}
|
@@ -109,19 +115,51 @@ static void end_element(void * ctx, const xmlChar *name)
|
|
109
115
|
VALUE MAYBE_UNUSED(enc) = rb_iv_get(self, "@encoding");
|
110
116
|
VALUE doc = rb_funcall(self, rb_intern("document"), 0);
|
111
117
|
rb_funcall(doc, rb_intern("end_element"), 1,
|
112
|
-
NOKOGIRI_STR_NEW2(name,
|
118
|
+
NOKOGIRI_STR_NEW2(name, STRING_OR_NULL(enc))
|
113
119
|
);
|
114
120
|
}
|
115
121
|
|
116
|
-
|
117
|
-
|
118
|
-
|
122
|
+
static VALUE attributes_as_list(
|
123
|
+
VALUE self,
|
124
|
+
int nb_attributes,
|
125
|
+
const xmlChar ** attributes)
|
126
|
+
{
|
127
|
+
VALUE list = rb_ary_new2(nb_attributes);
|
128
|
+
VALUE MAYBE_UNUSED(enc) = rb_iv_get(self, "@encoding");
|
129
|
+
|
130
|
+
VALUE attr_klass = rb_const_get(cNokogiriXmlSaxParser, rb_intern("Attribute"));
|
131
|
+
if (attributes) {
|
132
|
+
/* Each attribute is an array of [localname, prefix, URI, value, end] */
|
133
|
+
int i;
|
134
|
+
for (i = 0; i < nb_attributes * 5; i += 5) {
|
135
|
+
VALUE attribute = rb_funcall(attr_klass, rb_intern("new"), 4,
|
136
|
+
/* localname */
|
137
|
+
RBSTR_OR_QNIL(attributes[i + 0], enc),
|
138
|
+
|
139
|
+
/* prefix */
|
140
|
+
RBSTR_OR_QNIL(attributes[i + 1], enc),
|
141
|
+
|
142
|
+
/* URI */
|
143
|
+
RBSTR_OR_QNIL(attributes[i + 2], enc),
|
144
|
+
|
145
|
+
/* value */
|
146
|
+
NOKOGIRI_STR_NEW((const char*)attributes[i+3],
|
147
|
+
(attributes[i+4] - attributes[i+3]),
|
148
|
+
STRING_OR_NULL(enc))
|
149
|
+
);
|
150
|
+
rb_ary_push(list, attribute);
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
return list;
|
155
|
+
}
|
156
|
+
|
119
157
|
static void
|
120
158
|
start_element_ns (
|
121
159
|
void * ctx,
|
122
160
|
const xmlChar * localname,
|
123
161
|
const xmlChar * prefix,
|
124
|
-
const xmlChar *
|
162
|
+
const xmlChar * uri,
|
125
163
|
int nb_namespaces,
|
126
164
|
const xmlChar ** namespaces,
|
127
165
|
int nb_attributes,
|
@@ -132,61 +170,42 @@ start_element_ns (
|
|
132
170
|
VALUE doc = rb_funcall(self, rb_intern("document"), 0);
|
133
171
|
VALUE MAYBE_UNUSED(enc) = rb_iv_get(self, "@encoding");
|
134
172
|
|
135
|
-
VALUE
|
136
|
-
VALUE nsHash = rb_hash_new();
|
173
|
+
VALUE attribute_list = attributes_as_list(self, nb_attributes, attributes);
|
137
174
|
|
138
|
-
|
139
|
-
{
|
140
|
-
/* Each attribute is an array of [localname, prefix, URI, value, end] */
|
141
|
-
int i;
|
142
|
-
for (i = 0; i < nb_attributes * 5; i += 5)
|
143
|
-
{
|
144
|
-
rb_hash_aset( attrHash,
|
145
|
-
NOKOGIRI_STR_NEW2((const char*)attributes[i+0], RTEST(enc) ? StringValuePtr(enc) : NULL),
|
146
|
-
NOKOGIRI_STR_NEW((const char*)attributes[i+3], (attributes[i+4] - attributes[i+3]), RTEST(enc) ? StringValuePtr(enc) : NULL));
|
147
|
-
}
|
148
|
-
}
|
175
|
+
VALUE ns_list = rb_ary_new2(nb_namespaces);
|
149
176
|
|
150
|
-
if (namespaces)
|
151
|
-
{
|
177
|
+
if (namespaces) {
|
152
178
|
int i;
|
153
179
|
for (i = 0; i < nb_namespaces * 2; i += 2)
|
154
180
|
{
|
155
|
-
|
156
|
-
|
157
|
-
|
181
|
+
rb_ary_push(ns_list,
|
182
|
+
rb_ary_new3(2,
|
183
|
+
RBSTR_OR_QNIL(namespaces[i + 0], enc),
|
184
|
+
RBSTR_OR_QNIL(namespaces[i + 1], enc)
|
185
|
+
)
|
186
|
+
);
|
158
187
|
}
|
159
188
|
}
|
160
189
|
|
161
190
|
rb_funcall( doc,
|
162
|
-
rb_intern("
|
191
|
+
rb_intern("start_element_namespace"),
|
163
192
|
5,
|
164
|
-
NOKOGIRI_STR_NEW2(localname,
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
193
|
+
NOKOGIRI_STR_NEW2(localname, STRING_OR_NULL(enc)),
|
194
|
+
attribute_list,
|
195
|
+
RBSTR_OR_QNIL(prefix, enc),
|
196
|
+
RBSTR_OR_QNIL(uri, enc),
|
197
|
+
ns_list
|
169
198
|
);
|
170
199
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
}
|
181
|
-
else
|
182
|
-
{
|
183
|
-
name = NOKOGIRI_STR_NEW2(localname, RTEST(enc) ? StringValuePtr(enc) : NULL);
|
184
|
-
}
|
185
|
-
VALUE attrArray = rb_funcall(attrHash, rb_intern("to_a"), 0);
|
186
|
-
attrArray = rb_funcall(attrArray, rb_intern("flatten"), 0);
|
187
|
-
rb_funcall(doc, rb_intern("start_element"), 2, name, attrArray);
|
188
|
-
}
|
189
|
-
|
200
|
+
rb_funcall( self,
|
201
|
+
rb_intern("start_element_namespace"),
|
202
|
+
5,
|
203
|
+
NOKOGIRI_STR_NEW2(localname, STRING_OR_NULL(enc)),
|
204
|
+
attribute_list,
|
205
|
+
RBSTR_OR_QNIL(prefix, enc),
|
206
|
+
RBSTR_OR_QNIL(uri, enc),
|
207
|
+
ns_list
|
208
|
+
);
|
190
209
|
}
|
191
210
|
|
192
211
|
/**
|
@@ -197,35 +216,23 @@ end_element_ns (
|
|
197
216
|
void * ctx,
|
198
217
|
const xmlChar * localname,
|
199
218
|
const xmlChar * prefix,
|
200
|
-
const xmlChar *
|
219
|
+
const xmlChar * uri)
|
201
220
|
{
|
202
221
|
VALUE self = (VALUE)ctx;
|
203
222
|
VALUE doc = rb_funcall(self, rb_intern("document"), 0);
|
204
223
|
VALUE MAYBE_UNUSED(enc) = rb_iv_get(self, "@encoding");
|
205
224
|
|
206
|
-
rb_funcall(doc, rb_intern("
|
207
|
-
|
208
|
-
|
209
|
-
|
225
|
+
rb_funcall(doc, rb_intern("end_element_namespace"), 3,
|
226
|
+
NOKOGIRI_STR_NEW2(localname, STRING_OR_NULL(enc)),
|
227
|
+
RBSTR_OR_QNIL(prefix, enc),
|
228
|
+
RBSTR_OR_QNIL(uri, enc)
|
210
229
|
);
|
211
230
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
{
|
218
|
-
name = NOKOGIRI_STR_NEW2(prefix, RTEST(enc) ? StringValuePtr(enc) : NULL);
|
219
|
-
rb_funcall(name, rb_intern("<<"), 1, NOKOGIRI_STR_NEW2(":", RTEST(enc) ? StringValuePtr(enc) : NULL));
|
220
|
-
rb_funcall(name, rb_intern("<<"), 1, NOKOGIRI_STR_NEW2(localname, RTEST(enc) ? StringValuePtr(enc) : NULL));
|
221
|
-
}
|
222
|
-
else
|
223
|
-
{
|
224
|
-
name = NOKOGIRI_STR_NEW2(localname, RTEST(enc) ? StringValuePtr(enc) : NULL);
|
225
|
-
}
|
226
|
-
rb_funcall(doc, rb_intern("end_element"), 1, name);
|
227
|
-
}
|
228
|
-
|
231
|
+
rb_funcall(self, rb_intern("end_element_namespace"), 3,
|
232
|
+
NOKOGIRI_STR_NEW2(localname, STRING_OR_NULL(enc)),
|
233
|
+
RBSTR_OR_QNIL(prefix, enc),
|
234
|
+
RBSTR_OR_QNIL(uri, enc)
|
235
|
+
);
|
229
236
|
}
|
230
237
|
|
231
238
|
static void characters_func(void * ctx, const xmlChar * ch, int len)
|
@@ -233,7 +240,7 @@ static void characters_func(void * ctx, const xmlChar * ch, int len)
|
|
233
240
|
VALUE self = (VALUE)ctx;
|
234
241
|
VALUE MAYBE_UNUSED(enc) = rb_iv_get(self, "@encoding");
|
235
242
|
VALUE doc = rb_funcall(self, rb_intern("document"), 0);
|
236
|
-
VALUE str = NOKOGIRI_STR_NEW(ch, len,
|
243
|
+
VALUE str = NOKOGIRI_STR_NEW(ch, len, STRING_OR_NULL(enc));
|
237
244
|
rb_funcall(doc, rb_intern("characters"), 1, str);
|
238
245
|
}
|
239
246
|
|
@@ -242,7 +249,7 @@ static void comment_func(void * ctx, const xmlChar * value)
|
|
242
249
|
VALUE self = (VALUE)ctx;
|
243
250
|
VALUE MAYBE_UNUSED(enc) = rb_iv_get(self, "@encoding");
|
244
251
|
VALUE doc = rb_funcall(self, rb_intern("document"), 0);
|
245
|
-
VALUE str = NOKOGIRI_STR_NEW2(value,
|
252
|
+
VALUE str = NOKOGIRI_STR_NEW2(value, STRING_OR_NULL(enc));
|
246
253
|
rb_funcall(doc, rb_intern("comment"), 1, str);
|
247
254
|
}
|
248
255
|
|
@@ -259,7 +266,7 @@ static void warning_func(void * ctx, const char *msg, ...)
|
|
259
266
|
va_end(args);
|
260
267
|
|
261
268
|
rb_funcall(doc, rb_intern("warning"), 1,
|
262
|
-
NOKOGIRI_STR_NEW2(message,
|
269
|
+
NOKOGIRI_STR_NEW2(message, STRING_OR_NULL(enc))
|
263
270
|
);
|
264
271
|
free(message);
|
265
272
|
}
|
@@ -277,7 +284,7 @@ static void error_func(void * ctx, const char *msg, ...)
|
|
277
284
|
va_end(args);
|
278
285
|
|
279
286
|
rb_funcall(doc, rb_intern("error"), 1,
|
280
|
-
NOKOGIRI_STR_NEW2(message,
|
287
|
+
NOKOGIRI_STR_NEW2(message, STRING_OR_NULL(enc))
|
281
288
|
);
|
282
289
|
free(message);
|
283
290
|
}
|
@@ -288,7 +295,7 @@ static void cdata_block(void * ctx, const xmlChar * value, int len)
|
|
288
295
|
VALUE MAYBE_UNUSED(enc) = rb_iv_get(self, "@encoding");
|
289
296
|
VALUE doc = rb_funcall(self, rb_intern("document"), 0);
|
290
297
|
VALUE string =
|
291
|
-
NOKOGIRI_STR_NEW(value, len,
|
298
|
+
NOKOGIRI_STR_NEW(value, len, STRING_OR_NULL(enc));
|
292
299
|
rb_funcall(doc, rb_intern("cdata_block"), 1, string);
|
293
300
|
}
|
294
301
|
|
data/ext/nokogiri/xml_schema.c
CHANGED
@@ -78,9 +78,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
|
78
78
|
if(NULL == schema) {
|
79
79
|
xmlErrorPtr error = xmlGetLastError();
|
80
80
|
if(error)
|
81
|
-
|
82
|
-
Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error)
|
83
|
-
);
|
81
|
+
Nokogiri_error_raise(NULL, error);
|
84
82
|
else
|
85
83
|
rb_raise(rb_eRuntimeError, "Could not parse document");
|
86
84
|
|
@@ -93,6 +91,56 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
|
93
91
|
return rb_schema;
|
94
92
|
}
|
95
93
|
|
94
|
+
/*
|
95
|
+
* call-seq:
|
96
|
+
* from_document(doc)
|
97
|
+
*
|
98
|
+
* Create a new Schema from the Nokogiri::XML::Document +doc+
|
99
|
+
*/
|
100
|
+
static VALUE from_document(VALUE klass, VALUE document)
|
101
|
+
{
|
102
|
+
xmlDocPtr doc;
|
103
|
+
Data_Get_Struct(document, xmlDoc, doc);
|
104
|
+
|
105
|
+
// In case someone passes us a node. ugh.
|
106
|
+
doc = doc->doc;
|
107
|
+
|
108
|
+
xmlSchemaParserCtxtPtr ctx = xmlSchemaNewDocParserCtxt(doc);
|
109
|
+
|
110
|
+
VALUE errors = rb_ary_new();
|
111
|
+
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
112
|
+
|
113
|
+
#ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS
|
114
|
+
xmlSchemaSetParserStructuredErrors(
|
115
|
+
ctx,
|
116
|
+
Nokogiri_error_array_pusher,
|
117
|
+
(void *)errors
|
118
|
+
);
|
119
|
+
#endif
|
120
|
+
|
121
|
+
xmlSchemaPtr schema = xmlSchemaParse(ctx);
|
122
|
+
|
123
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
124
|
+
xmlSchemaFreeParserCtxt(ctx);
|
125
|
+
|
126
|
+
if(NULL == schema) {
|
127
|
+
xmlErrorPtr error = xmlGetLastError();
|
128
|
+
if(error)
|
129
|
+
Nokogiri_error_raise(NULL, error);
|
130
|
+
else
|
131
|
+
rb_raise(rb_eRuntimeError, "Could not parse document");
|
132
|
+
|
133
|
+
return Qnil;
|
134
|
+
}
|
135
|
+
|
136
|
+
VALUE rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
137
|
+
rb_iv_set(rb_schema, "@errors", errors);
|
138
|
+
|
139
|
+
return rb_schema;
|
140
|
+
|
141
|
+
return Qnil;
|
142
|
+
}
|
143
|
+
|
96
144
|
VALUE cNokogiriXmlSchema;
|
97
145
|
void init_xml_schema()
|
98
146
|
{
|
@@ -103,5 +151,6 @@ void init_xml_schema()
|
|
103
151
|
cNokogiriXmlSchema = klass;
|
104
152
|
|
105
153
|
rb_define_singleton_method(klass, "read_memory", read_memory, 1);
|
154
|
+
rb_define_singleton_method(klass, "from_document", from_document, 1);
|
106
155
|
rb_define_private_method(klass, "validate_document", validate_document, 1);
|
107
156
|
}
|
@@ -166,6 +166,13 @@ void Nokogiri_error_array_pusher(void * ctx, xmlErrorPtr error)
|
|
166
166
|
rb_ary_push(list, Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error));
|
167
167
|
}
|
168
168
|
|
169
|
+
void Nokogiri_error_raise(void * ctx, xmlErrorPtr error)
|
170
|
+
{
|
171
|
+
rb_funcall(rb_mKernel, rb_intern("raise"), 1,
|
172
|
+
Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error)
|
173
|
+
);
|
174
|
+
}
|
175
|
+
|
169
176
|
VALUE Nokogiri_wrap_xml_syntax_error(VALUE klass, xmlErrorPtr error)
|
170
177
|
{
|
171
178
|
if(!klass) klass = cNokogiriXmlSyntaxError;
|
@@ -6,6 +6,7 @@
|
|
6
6
|
void init_xml_syntax_error();
|
7
7
|
VALUE Nokogiri_wrap_xml_syntax_error(VALUE klass, xmlErrorPtr error);
|
8
8
|
void Nokogiri_error_array_pusher(void * ctx, xmlErrorPtr error);
|
9
|
+
void Nokogiri_error_raise(void * ctx, xmlErrorPtr error);
|
9
10
|
|
10
11
|
extern VALUE cNokogiriXmlSyntaxError;
|
11
12
|
#endif
|
data/lib/nokogiri.rb
CHANGED
@@ -55,9 +55,9 @@ module Nokogiri
|
|
55
55
|
def parse string, url = nil, encoding = nil, options = nil
|
56
56
|
doc =
|
57
57
|
if string =~ /^\s*<[^Hh>]*html/i # Probably html
|
58
|
-
Nokogiri::HTML::Document.parse(string, url, encoding, options ||
|
58
|
+
Nokogiri::HTML::Document.parse(string, url, encoding, options || XML::ParseOptions::DEFAULT_HTML)
|
59
59
|
else
|
60
|
-
Nokogiri::XML::Document.parse(string, url, encoding, options ||
|
60
|
+
Nokogiri::XML::Document.parse(string, url, encoding, options || XML::ParseOptions::DEFAULT_XML)
|
61
61
|
end
|
62
62
|
yield doc if block_given?
|
63
63
|
doc
|
Binary file
|
Binary file
|
data/lib/nokogiri/css/parser.rb
CHANGED
@@ -43,7 +43,7 @@ module Nokogiri
|
|
43
43
|
def parse selector
|
44
44
|
@warned ||= false
|
45
45
|
unless @warned
|
46
|
-
$stderr.puts('Nokogiri::CSS::Parser.parse is deprecated, call Nokogiri::CSS.parse()')
|
46
|
+
$stderr.puts('Nokogiri::CSS::Parser.parse is deprecated, call Nokogiri::CSS.parse(), this will be removed August 1st or version 1.4.0 (whichever is first)')
|
47
47
|
@warned = true
|
48
48
|
end
|
49
49
|
new.parse selector
|
@@ -59,7 +59,7 @@ module Nokogiri
|
|
59
59
|
|
60
60
|
# Get the xpath for +string+ using +options+
|
61
61
|
def xpath_for string, options={}
|
62
|
-
key = string
|
62
|
+
key = "#{string}#{options[:ns]}#{options[:prefix]}"
|
63
63
|
v = self.class[key]
|
64
64
|
return v if v
|
65
65
|
|
@@ -2,22 +2,30 @@ module Nokogiri
|
|
2
2
|
module IoCallbacks # :nodoc:
|
3
3
|
|
4
4
|
class << self
|
5
|
+
|
6
|
+
def plain_old_reader(io)
|
7
|
+
lambda do |ctx, buffer, len|
|
8
|
+
string = io.read(len)
|
9
|
+
return 0 if string.nil?
|
10
|
+
buffer.put_bytes(0, string, 0, string.length)
|
11
|
+
string.length
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
if defined?(FFI::IO.native_read)
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
16
|
+
def ffi_io_native_reader(io)
|
17
|
+
if io.is_a?(StringIO)
|
18
|
+
plain_old_reader(io)
|
19
|
+
else
|
20
|
+
lambda do |ctx, buffer, len|
|
21
|
+
rcode = FFI::IO.native_read(io, buffer, len)
|
22
|
+
(rcode < 0) ? 0 : rcode
|
23
|
+
end
|
10
24
|
end
|
11
25
|
end
|
26
|
+
alias :reader :ffi_io_native_reader
|
12
27
|
else
|
13
|
-
|
14
|
-
lambda do |ctx, buffer, len|
|
15
|
-
string = io.read(len)
|
16
|
-
return 0 if string.nil?
|
17
|
-
buffer.put_bytes(0, string, 0, string.length)
|
18
|
-
string.length
|
19
|
-
end
|
20
|
-
end
|
28
|
+
alias :reader :plain_old_reader
|
21
29
|
end
|
22
30
|
|
23
31
|
def writer(io)
|
data/lib/nokogiri/ffi/libxml.rb
CHANGED
@@ -118,6 +118,7 @@ module Nokogiri
|
|
118
118
|
attach_function :xmlStringGetNodeList, [:pointer, :pointer], :pointer # second arg should be a :string, but we only ship the results of xmlEncodeEntitiesReentrant, so let's optimize.
|
119
119
|
attach_function :xmlNewNs, [:pointer, :string, :string], :pointer
|
120
120
|
attach_function :xmlNewNsProp, [:pointer, :pointer, :string, :string], :pointer
|
121
|
+
attach_function :xmlSearchNs, [:pointer, :pointer, :string], :pointer
|
121
122
|
attach_function :xmlSearchNsByHref, [:pointer, :pointer, :string], :pointer
|
122
123
|
attach_function :xmlGetIntSubset, [:pointer], :pointer
|
123
124
|
attach_function :xmlBufferCreate, [], :pointer
|
@@ -126,6 +127,11 @@ module Nokogiri
|
|
126
127
|
attach_function :xmlNewDocProp, [:pointer, :string, :string], :pointer
|
127
128
|
attach_function :xmlFreePropList, [:pointer], :void
|
128
129
|
|
130
|
+
# valid.c
|
131
|
+
attach_function :xmlNewValidCtxt, [], :pointer
|
132
|
+
attach_function :xmlValidateDtd, [:pointer, :pointer, :pointer], :int
|
133
|
+
attach_function :xmlFreeValidCtxt, [:pointer], :void
|
134
|
+
|
129
135
|
# xmlsave.c
|
130
136
|
attach_function :xmlDocDumpMemory, [:pointer, :pointer, :pointer], :void
|
131
137
|
attach_function :xmlNodeDump, [:pointer, :pointer, :pointer, :int, :int], :int
|
@@ -240,6 +246,7 @@ module Nokogiri
|
|
240
246
|
attach_function :xmlSchemaSetParserStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
241
247
|
attach_function :xmlSchemaParse, [:pointer], :pointer
|
242
248
|
attach_function :xmlSchemaFreeParserCtxt, [:pointer], :void
|
249
|
+
attach_function :xmlSchemaNewDocParserCtxt, [:pointer], :pointer
|
243
250
|
|
244
251
|
# relaxng.c
|
245
252
|
attach_function :xmlRelaxNGNewValidCtxt, [:pointer], :pointer
|
@@ -250,6 +257,7 @@ module Nokogiri
|
|
250
257
|
attach_function :xmlRelaxNGSetParserStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
251
258
|
attach_function :xmlRelaxNGParse, [:pointer], :pointer
|
252
259
|
attach_function :xmlRelaxNGFreeParserCtxt, [:pointer], :void
|
260
|
+
attach_function :xmlRelaxNGNewDocParserCtxt, [:pointer], :pointer
|
253
261
|
|
254
262
|
# helpers
|
255
263
|
def self.pointer_offset(n)
|