libxml-ruby 3.0.0 → 3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/HISTORY +37 -0
- data/MANIFEST +34 -34
- data/README.rdoc +65 -36
- data/Rakefile +21 -3
- data/ext/libxml/extconf.rb +30 -26
- data/ext/libxml/ruby_libxml.h +0 -8
- data/ext/libxml/ruby_xml.c +40 -0
- data/ext/libxml/ruby_xml_document.c +1 -5
- data/ext/libxml/ruby_xml_dtd.c +6 -8
- data/ext/libxml/ruby_xml_encoding.c +1 -13
- data/ext/libxml/ruby_xml_encoding.h +0 -3
- data/ext/libxml/ruby_xml_error.c +1 -1
- data/ext/libxml/ruby_xml_error.h +1 -1
- data/ext/libxml/ruby_xml_io.c +14 -18
- data/ext/libxml/ruby_xml_io.h +1 -1
- data/ext/libxml/ruby_xml_node.c +16 -17
- data/ext/libxml/ruby_xml_parser_context.c +1 -1
- data/ext/libxml/ruby_xml_reader.c +7 -2
- data/ext/libxml/ruby_xml_schema.c +44 -66
- data/ext/libxml/ruby_xml_schema_element.c +15 -14
- data/ext/libxml/ruby_xml_schema_type.c +66 -93
- data/ext/libxml/ruby_xml_version.h +4 -4
- data/ext/libxml/ruby_xml_writer.c +189 -192
- data/lib/libxml/schema/element.rb +0 -8
- data/lib/libxml/schema/type.rb +0 -8
- data/lib/libxml/schema.rb +0 -19
- data/lib/libxml-ruby.rb +30 -0
- data/lib/libxml.rb +3 -28
- data/libxml-ruby.gemspec +5 -4
- data/setup.rb +0 -1
- data/test/model/cwm_1_0.xml +11336 -0
- data/test/{tc_attr.rb → test_attr.rb} +18 -18
- data/test/{tc_attr_decl.rb → test_attr_decl.rb} +8 -8
- data/test/{tc_attributes.rb → test_attributes.rb} +10 -10
- data/test/{tc_canonicalize.rb → test_canonicalize.rb} +35 -39
- data/test/test_deprecated_require.rb +12 -0
- data/test/{tc_document.rb → test_document.rb} +31 -24
- data/test/test_document_write.rb +146 -0
- data/test/{tc_dtd.rb → test_dtd.rb} +26 -25
- data/test/{tc_encoding.rb → test_encoding.rb} +20 -17
- data/test/{tc_encoding_sax.rb → test_encoding_sax.rb} +3 -3
- data/test/test_error.rb +178 -0
- data/test/test_helper.rb +4 -11
- data/test/{tc_html_parser.rb → test_html_parser.rb} +31 -30
- data/test/test_html_parser_context.rb +23 -0
- data/test/test_namespace.rb +60 -0
- data/test/{tc_namespaces.rb → test_namespaces.rb} +29 -38
- data/test/{tc_node.rb → test_node.rb} +37 -31
- data/test/{tc_node_cdata.rb → test_node_cdata.rb} +10 -10
- data/test/{tc_node_comment.rb → test_node_comment.rb} +6 -6
- data/test/{tc_node_copy.rb → test_node_copy.rb} +3 -4
- data/test/{tc_node_edit.rb → test_node_edit.rb} +20 -21
- data/test/{tc_node_pi.rb → test_node_pi.rb} +8 -10
- data/test/{tc_node_text.rb → test_node_text.rb} +8 -9
- data/test/{tc_node_write.rb → test_node_write.rb} +16 -26
- data/test/test_node_xlink.rb +28 -0
- data/test/{tc_parser.rb → test_parser.rb} +72 -75
- data/test/{tc_parser_context.rb → test_parser_context.rb} +38 -44
- data/test/{tc_properties.rb → test_properties.rb} +5 -5
- data/test/test_reader.rb +364 -0
- data/test/{tc_relaxng.rb → test_relaxng.rb} +11 -11
- data/test/{tc_sax_parser.rb → test_sax_parser.rb} +38 -31
- data/test/{tc_schema.rb → test_schema.rb} +40 -33
- data/test/test_suite.rb +39 -40
- data/test/{tc_traversal.rb → test_traversal.rb} +4 -4
- data/test/{tc_writer.rb → test_writer.rb} +95 -74
- data/test/{tc_xinclude.rb → test_xinclude.rb} +3 -3
- data/test/test_xml.rb +263 -0
- data/test/{tc_xpath.rb → test_xpath.rb} +25 -25
- data/test/{tc_xpath_context.rb → test_xpath_context.rb} +5 -5
- data/test/{tc_xpath_expression.rb → test_xpath_expression.rb} +7 -7
- data/test/{tc_xpointer.rb → test_xpointer.rb} +15 -15
- metadata +91 -102
- data/test/tc_deprecated_require.rb +0 -12
- data/test/tc_document_write.rb +0 -195
- data/test/tc_error.rb +0 -178
- data/test/tc_html_parser_context.rb +0 -23
- data/test/tc_namespace.rb +0 -61
- data/test/tc_node_xlink.rb +0 -28
- data/test/tc_reader.rb +0 -358
- data/test/tc_xml.rb +0 -225
@@ -19,57 +19,29 @@ static VALUE sEncoding, sStandalone;
|
|
19
19
|
#include <libxml/xmlwriter.h>
|
20
20
|
|
21
21
|
|
22
|
-
typedef enum
|
22
|
+
typedef enum
|
23
|
+
{
|
23
24
|
RXMLW_OUTPUT_NONE,
|
24
25
|
RXMLW_OUTPUT_IO,
|
25
26
|
RXMLW_OUTPUT_DOC,
|
26
27
|
RXMLW_OUTPUT_STRING
|
27
28
|
} rxmlw_output_type;
|
28
29
|
|
29
|
-
typedef struct
|
30
|
+
typedef struct
|
31
|
+
{
|
30
32
|
VALUE output;
|
31
|
-
|
32
|
-
rb_encoding *encoding;
|
33
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
33
|
+
rb_encoding* encoding;
|
34
34
|
xmlBufferPtr buffer;
|
35
35
|
xmlTextWriterPtr writer;
|
36
36
|
rxmlw_output_type output_type;
|
37
37
|
int closed;
|
38
38
|
} rxml_writer_object;
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
#define /*VALUE*/ rxml_writer_c_to_ruby_string(/*const xmlChar **/ string, /*long*/ string_len) \
|
43
|
-
rb_external_str_new_with_enc(string, string_len, rb_utf8_encoding())
|
44
|
-
|
45
|
-
#define /*VALUE*/ rxml_writer_ruby_string_to_utf8(/*VALUE*/ string) \
|
46
|
-
rb_str_conv_enc(string, rb_enc_get(string), rb_utf8_encoding())
|
47
|
-
// rb_str_export_to_enc(string, rb_utf8_encoding())
|
48
|
-
|
49
|
-
#define /*void*/ rxml_writer_free_utf8_string(/*VALUE*/ orig, /*VALUE*/ utf8) \
|
50
|
-
do { \
|
51
|
-
if (orig != utf8) { \
|
52
|
-
rb_str_free(utf8); \
|
53
|
-
} \
|
54
|
-
} while (0);
|
55
|
-
|
56
|
-
#else
|
57
|
-
|
58
|
-
#define /*VALUE*/ rxml_writer_c_to_ruby_string(/*const xmlChar **/ string, /*long*/ string_len) \
|
59
|
-
rb_str_new(string, string_len)
|
60
|
-
|
61
|
-
#define /*VALUE*/ rxml_writer_ruby_string_to_utf8(/*VALUE*/ string) \
|
62
|
-
string
|
63
|
-
|
64
|
-
#define /*void*/ rxml_writer_free_utf8_string(/*VALUE*/ orig, /*VALUE*/ utf8) \
|
65
|
-
/* NOP */
|
66
|
-
|
67
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
68
|
-
|
69
|
-
static void rxml_writer_free(rxml_writer_object *rwo)
|
40
|
+
static void rxml_writer_free(rxml_writer_object* rwo)
|
70
41
|
{
|
71
42
|
#if 0 /* seems to be done by xmlFreeTextWriter */
|
72
|
-
if (NULL != rwo->buffer)
|
43
|
+
if (NULL != rwo->buffer)
|
44
|
+
{
|
73
45
|
xmlBufferFree(rwo->buffer);
|
74
46
|
}
|
75
47
|
#endif
|
@@ -79,36 +51,40 @@ static void rxml_writer_free(rxml_writer_object *rwo)
|
|
79
51
|
xfree(rwo);
|
80
52
|
}
|
81
53
|
|
82
|
-
static void rxml_writer_mark(rxml_writer_object
|
54
|
+
static void rxml_writer_mark(rxml_writer_object* rwo)
|
83
55
|
{
|
84
|
-
if (!NIL_P(rwo->output))
|
56
|
+
if (!NIL_P(rwo->output))
|
57
|
+
{
|
85
58
|
rb_gc_mark(rwo->output);
|
86
59
|
}
|
87
60
|
}
|
88
61
|
|
89
|
-
static VALUE rxml_writer_wrap(rxml_writer_object
|
62
|
+
static VALUE rxml_writer_wrap(rxml_writer_object* rwo)
|
90
63
|
{
|
91
64
|
return Data_Wrap_Struct(cXMLWriter, rxml_writer_mark, rxml_writer_free, rwo);
|
92
65
|
}
|
93
66
|
|
94
|
-
static rxml_writer_object
|
67
|
+
static rxml_writer_object* rxml_textwriter_get(VALUE obj)
|
95
68
|
{
|
96
|
-
rxml_writer_object
|
69
|
+
rxml_writer_object* rwo;
|
97
70
|
|
98
71
|
Data_Get_Struct(obj, rxml_writer_object, rwo);
|
99
72
|
|
100
73
|
return rwo;
|
101
74
|
}
|
102
75
|
|
103
|
-
int rxml_writer_write_callback(void
|
76
|
+
int rxml_writer_write_callback(void* context, const char* buffer, int len)
|
104
77
|
{
|
105
|
-
|
78
|
+
rxml_writer_object* rwo = context;
|
106
79
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
80
|
+
if (rwo->closed)
|
81
|
+
{
|
82
|
+
return 0;
|
83
|
+
}
|
84
|
+
else
|
85
|
+
{
|
86
|
+
return rxml_write_callback(rwo->output, buffer, len);
|
87
|
+
}
|
112
88
|
}
|
113
89
|
|
114
90
|
/* ===== public class methods ===== */
|
@@ -120,31 +96,26 @@ int rxml_writer_write_callback(void *context, const char *buffer, int len)
|
|
120
96
|
*/
|
121
97
|
static VALUE rxml_writer_io(VALUE klass, VALUE io)
|
122
98
|
{
|
123
|
-
#if 0
|
124
|
-
typedef int (*xmlOutputCloseCallback)(void * context);
|
125
|
-
typedef int (*xmlOutputWriteCallback)(void * context, const char * buffer, int len);
|
126
|
-
|
127
|
-
ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size);
|
128
|
-
|
129
|
-
xmlOutputBufferPtr xmlOutputBufferCreateIO(xmlOutputWriteCallback iowrite, xmlOutputCloseCallback ioclose, void * ioctx, xmlCharEncodingHandlerPtr encoder)
|
130
|
-
|
131
|
-
xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char * name);
|
132
|
-
#endif
|
133
99
|
xmlOutputBufferPtr out;
|
134
|
-
rxml_writer_object
|
100
|
+
rxml_writer_object* rwo;
|
135
101
|
|
136
102
|
rwo = ALLOC(rxml_writer_object);
|
137
103
|
rwo->output = io;
|
138
104
|
rwo->buffer = NULL;
|
139
105
|
rwo->closed = 0;
|
140
|
-
|
141
|
-
rwo->encoding
|
142
|
-
|
106
|
+
rwo->encoding = rb_enc_get(io);
|
107
|
+
if (!rwo->encoding)
|
108
|
+
rwo->encoding = rb_utf8_encoding();
|
109
|
+
|
143
110
|
rwo->output_type = RXMLW_OUTPUT_IO;
|
144
|
-
|
111
|
+
|
112
|
+
xmlCharEncodingHandlerPtr encodingHdlr = xmlFindCharEncodingHandler(rwo->encoding->name);
|
113
|
+
if (NULL == (out = xmlOutputBufferCreateIO(rxml_writer_write_callback, NULL, (void*)rwo, encodingHdlr)))
|
114
|
+
{
|
145
115
|
rxml_raise(&xmlLastError);
|
146
116
|
}
|
147
|
-
if (NULL == (rwo->writer = xmlNewTextWriter(out)))
|
117
|
+
if (NULL == (rwo->writer = xmlNewTextWriter(out)))
|
118
|
+
{
|
148
119
|
rxml_raise(&xmlLastError);
|
149
120
|
}
|
150
121
|
|
@@ -160,17 +131,16 @@ xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char * name);
|
|
160
131
|
*/
|
161
132
|
static VALUE rxml_writer_file(VALUE klass, VALUE filename)
|
162
133
|
{
|
163
|
-
rxml_writer_object
|
134
|
+
rxml_writer_object* rwo;
|
164
135
|
|
165
136
|
rwo = ALLOC(rxml_writer_object);
|
166
137
|
rwo->output = Qnil;
|
167
138
|
rwo->buffer = NULL;
|
168
139
|
rwo->closed = 0;
|
169
|
-
|
170
|
-
rwo->encoding = NULL;
|
171
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
140
|
+
rwo->encoding = rb_utf8_encoding();
|
172
141
|
rwo->output_type = RXMLW_OUTPUT_NONE;
|
173
|
-
if (NULL == (rwo->writer = xmlNewTextWriterFilename(StringValueCStr(filename), 0)))
|
142
|
+
if (NULL == (rwo->writer = xmlNewTextWriterFilename(StringValueCStr(filename), 0)))
|
143
|
+
{
|
174
144
|
rxml_raise(&xmlLastError);
|
175
145
|
}
|
176
146
|
|
@@ -184,19 +154,19 @@ static VALUE rxml_writer_file(VALUE klass, VALUE filename)
|
|
184
154
|
*/
|
185
155
|
static VALUE rxml_writer_string(VALUE klass)
|
186
156
|
{
|
187
|
-
rxml_writer_object
|
157
|
+
rxml_writer_object* rwo;
|
188
158
|
|
189
159
|
rwo = ALLOC(rxml_writer_object);
|
190
160
|
rwo->output = Qnil;
|
191
161
|
rwo->closed = 0;
|
192
|
-
|
193
|
-
rwo->encoding = NULL;
|
194
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
162
|
+
rwo->encoding = rb_utf8_encoding();
|
195
163
|
rwo->output_type = RXMLW_OUTPUT_STRING;
|
196
|
-
if (NULL == (rwo->buffer = xmlBufferCreate()))
|
164
|
+
if (NULL == (rwo->buffer = xmlBufferCreate()))
|
165
|
+
{
|
197
166
|
rxml_raise(&xmlLastError);
|
198
167
|
}
|
199
|
-
if (NULL == (rwo->writer = xmlNewTextWriterMemory(rwo->buffer, 0)))
|
168
|
+
if (NULL == (rwo->writer = xmlNewTextWriterMemory(rwo->buffer, 0)))
|
169
|
+
{
|
200
170
|
xmlBufferFree(rwo->buffer);
|
201
171
|
rxml_raise(&xmlLastError);
|
202
172
|
}
|
@@ -212,17 +182,16 @@ static VALUE rxml_writer_string(VALUE klass)
|
|
212
182
|
static VALUE rxml_writer_doc(VALUE klass)
|
213
183
|
{
|
214
184
|
xmlDocPtr doc;
|
215
|
-
rxml_writer_object
|
185
|
+
rxml_writer_object* rwo;
|
216
186
|
|
217
187
|
rwo = ALLOC(rxml_writer_object);
|
218
188
|
rwo->buffer = NULL;
|
219
189
|
rwo->output = Qnil;
|
220
190
|
rwo->closed = 0;
|
221
|
-
|
222
|
-
rwo->encoding = NULL;
|
223
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
191
|
+
rwo->encoding = rb_utf8_encoding();
|
224
192
|
rwo->output_type = RXMLW_OUTPUT_DOC;
|
225
|
-
if (NULL == (rwo->writer = xmlNewTextWriterDoc(&doc, 0)))
|
193
|
+
if (NULL == (rwo->writer = xmlNewTextWriterDoc(&doc, 0)))
|
194
|
+
{
|
226
195
|
rxml_raise(&xmlLastError);
|
227
196
|
}
|
228
197
|
rwo->output = rxml_document_wrap(doc);
|
@@ -240,33 +209,34 @@ static VALUE rxml_writer_doc(VALUE klass)
|
|
240
209
|
* If +empty?+ is +true+, and for a in memory XML::Writer, this internel
|
241
210
|
* buffer is empty.
|
242
211
|
*/
|
243
|
-
static VALUE rxml_writer_flush(int argc, VALUE
|
212
|
+
static VALUE rxml_writer_flush(int argc, VALUE* argv, VALUE self)
|
244
213
|
{
|
245
214
|
int ret;
|
246
215
|
VALUE empty;
|
247
|
-
rxml_writer_object
|
216
|
+
rxml_writer_object* rwo;
|
248
217
|
|
249
218
|
rb_scan_args(argc, argv, "01", &empty);
|
250
219
|
|
251
220
|
rwo = rxml_textwriter_get(self);
|
252
|
-
if (-1 == (ret = xmlTextWriterFlush(rwo->writer)))
|
221
|
+
if (-1 == (ret = xmlTextWriterFlush(rwo->writer)))
|
222
|
+
{
|
253
223
|
rxml_raise(&xmlLastError);
|
254
224
|
}
|
255
225
|
|
256
|
-
if (NULL != rwo->buffer)
|
226
|
+
if (NULL != rwo->buffer)
|
227
|
+
{
|
257
228
|
VALUE content;
|
258
229
|
|
259
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
260
230
|
content = rb_external_str_new_with_enc((const char*)rwo->buffer->content, rwo->buffer->use, rwo->encoding);
|
261
|
-
|
262
|
-
|
263
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
264
|
-
if (NIL_P(empty) || RTEST(empty)) { /* nil = default value = true */
|
231
|
+
if (NIL_P(empty) || RTEST(empty))
|
232
|
+
{ /* nil = default value = true */
|
265
233
|
xmlBufferEmpty(rwo->buffer);
|
266
234
|
}
|
267
235
|
|
268
236
|
return content;
|
269
|
-
}
|
237
|
+
}
|
238
|
+
else
|
239
|
+
{
|
270
240
|
return INT2NUM(ret);
|
271
241
|
}
|
272
242
|
}
|
@@ -281,26 +251,28 @@ static VALUE rxml_writer_flush(int argc, VALUE *argv, VALUE self)
|
|
281
251
|
static VALUE rxml_writer_result(VALUE self)
|
282
252
|
{
|
283
253
|
VALUE ret = Qnil;
|
284
|
-
rxml_writer_object
|
254
|
+
rxml_writer_object* rwo = rxml_textwriter_get(self);
|
285
255
|
int bytesWritten = xmlTextWriterFlush(rwo->writer);
|
286
256
|
|
287
|
-
if (bytesWritten == -1)
|
257
|
+
if (bytesWritten == -1)
|
258
|
+
{
|
288
259
|
rxml_raise(&xmlLastError);
|
289
260
|
}
|
290
261
|
|
291
|
-
switch (rwo->output_type)
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
262
|
+
switch (rwo->output_type)
|
263
|
+
{
|
264
|
+
case RXMLW_OUTPUT_DOC:
|
265
|
+
ret = rwo->output;
|
266
|
+
break;
|
267
|
+
case RXMLW_OUTPUT_STRING:
|
268
|
+
ret = rb_external_str_new_with_enc((const char*)rwo->buffer->content, rwo->buffer->use, rwo->encoding);
|
269
|
+
break;
|
270
|
+
case RXMLW_OUTPUT_IO:
|
271
|
+
case RXMLW_OUTPUT_NONE:
|
272
|
+
break;
|
273
|
+
default:
|
274
|
+
rb_bug("unexpected output");
|
275
|
+
break;
|
304
276
|
}
|
305
277
|
|
306
278
|
return ret;
|
@@ -311,7 +283,7 @@ static VALUE rxml_writer_result(VALUE self)
|
|
311
283
|
static VALUE numeric_rxml_writer_void(VALUE obj, int (*fn)(xmlTextWriterPtr))
|
312
284
|
{
|
313
285
|
int ret;
|
314
|
-
rxml_writer_object
|
286
|
+
rxml_writer_object* rwo;
|
315
287
|
|
316
288
|
rwo = rxml_textwriter_get(obj);
|
317
289
|
ret = fn(rwo->writer);
|
@@ -335,88 +307,102 @@ static VALUE numeric_rxml_writer_va_strings(VALUE obj, VALUE pe, size_t strings_
|
|
335
307
|
{
|
336
308
|
va_list ap;
|
337
309
|
size_t argc;
|
338
|
-
|
339
|
-
rxml_writer_object
|
340
|
-
const xmlChar
|
310
|
+
int ret = -1;
|
311
|
+
rxml_writer_object* rwo;
|
312
|
+
const xmlChar* argv[XMLWRITER_MAX_STRING_ARGS];
|
341
313
|
VALUE utf8[XMLWRITER_MAX_STRING_ARGS], orig[XMLWRITER_MAX_STRING_ARGS];
|
342
314
|
|
343
|
-
if (strings_count > XMLWRITER_MAX_STRING_ARGS)
|
315
|
+
if (strings_count > XMLWRITER_MAX_STRING_ARGS)
|
316
|
+
{
|
344
317
|
rb_bug("more arguments than expected");
|
345
318
|
}
|
346
319
|
va_start(ap, fn);
|
347
320
|
rwo = rxml_textwriter_get(obj);
|
348
|
-
for (argc = 0; argc < strings_count; argc++)
|
321
|
+
for (argc = 0; argc < strings_count; argc++)
|
322
|
+
{
|
349
323
|
VALUE arg;
|
350
324
|
|
351
325
|
arg = va_arg(ap, VALUE);
|
352
326
|
orig[argc] = arg;
|
353
|
-
if (NIL_P(arg))
|
327
|
+
if (NIL_P(arg))
|
328
|
+
{
|
354
329
|
utf8[argc] = Qnil;
|
355
330
|
argv[argc] = NULL;
|
356
|
-
}
|
357
|
-
|
331
|
+
}
|
332
|
+
else
|
333
|
+
{
|
334
|
+
utf8[argc] = rb_str_conv_enc(orig[argc], rb_enc_get(orig[argc]), rwo->encoding);
|
358
335
|
argv[argc] = BAD_CAST StringValueCStr(utf8[argc]);
|
359
336
|
}
|
360
337
|
}
|
361
338
|
va_end(ap);
|
362
339
|
|
363
|
-
if (Qundef == pe)
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
340
|
+
if (Qundef == pe)
|
341
|
+
{
|
342
|
+
switch (strings_count)
|
343
|
+
{
|
344
|
+
case 0:
|
345
|
+
ret = fn(rwo->writer);
|
346
|
+
break;
|
347
|
+
case 1:
|
348
|
+
ret = fn(rwo->writer, argv[0]);
|
349
|
+
break;
|
350
|
+
case 2:
|
351
|
+
ret = fn(rwo->writer, argv[0], argv[1]);
|
352
|
+
break;
|
353
|
+
case 3:
|
354
|
+
ret = fn(rwo->writer, argv[0], argv[1], argv[2]);
|
355
|
+
break;
|
356
|
+
case 4:
|
357
|
+
ret = fn(rwo->writer, argv[0], argv[1], argv[2], argv[3]);
|
358
|
+
break;
|
359
|
+
case 5:
|
360
|
+
ret = fn(rwo->writer, argv[0], argv[1], argv[2], argv[3], argv[4]);
|
361
|
+
break;
|
362
|
+
default:
|
363
|
+
break;
|
385
364
|
}
|
386
|
-
}
|
365
|
+
}
|
366
|
+
else
|
367
|
+
{
|
387
368
|
int xpe;
|
388
369
|
|
389
370
|
xpe = RTEST(pe);
|
390
|
-
switch (strings_count)
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
371
|
+
switch (strings_count)
|
372
|
+
{ /* strings_count doesn't include pe */
|
373
|
+
case 0:
|
374
|
+
ret = fn(rwo->writer, xpe);
|
375
|
+
break;
|
376
|
+
case 1:
|
377
|
+
ret = fn(rwo->writer, xpe, argv[0]);
|
378
|
+
break;
|
379
|
+
case 2:
|
380
|
+
ret = fn(rwo->writer, xpe, argv[0], argv[1]);
|
381
|
+
break;
|
382
|
+
case 3:
|
383
|
+
ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2]);
|
384
|
+
break;
|
385
|
+
case 4:
|
386
|
+
ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2], argv[3]);
|
387
|
+
break;
|
388
|
+
case 5:
|
389
|
+
ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2], argv[3], argv[4]);
|
390
|
+
break;
|
391
|
+
default:
|
392
|
+
break;
|
411
393
|
}
|
412
394
|
}
|
413
|
-
|
414
|
-
while (--strings_count > 0)
|
415
|
-
|
416
|
-
|
395
|
+
|
396
|
+
while (--strings_count > 0)
|
397
|
+
{
|
398
|
+
if (!NIL_P(orig[strings_count]))
|
399
|
+
{
|
400
|
+
if (orig[strings_count] != utf8[strings_count])
|
401
|
+
{
|
402
|
+
rb_str_free(utf8[strings_count]);
|
403
|
+
}
|
417
404
|
}
|
418
405
|
}
|
419
|
-
#endif /* HAVE_RUBY_ENCODING_H */
|
420
406
|
|
421
407
|
return (-1 == ret ? Qfalse : Qtrue);
|
422
408
|
}
|
@@ -434,7 +420,7 @@ static VALUE numeric_rxml_writer_va_strings(VALUE obj, VALUE pe, size_t strings_
|
|
434
420
|
static VALUE rxml_writer_set_indent(VALUE self, VALUE indentation)
|
435
421
|
{
|
436
422
|
int ret;
|
437
|
-
rxml_writer_object
|
423
|
+
rxml_writer_object* rwo;
|
438
424
|
|
439
425
|
rwo = rxml_textwriter_get(self);
|
440
426
|
ret = xmlTextWriterSetIndent(rwo->writer, RTEST(indentation));
|
@@ -484,7 +470,7 @@ static VALUE rxml_writer_write_cdata(VALUE self, VALUE content)
|
|
484
470
|
}
|
485
471
|
|
486
472
|
static VALUE rxml_writer_start_element(VALUE, VALUE);
|
487
|
-
static VALUE rxml_writer_start_element_ns(int, VALUE
|
473
|
+
static VALUE rxml_writer_start_element_ns(int, VALUE*, VALUE);
|
488
474
|
static VALUE rxml_writer_end_element(VALUE);
|
489
475
|
|
490
476
|
/* call-seq:
|
@@ -494,17 +480,21 @@ static VALUE rxml_writer_end_element(VALUE);
|
|
494
480
|
* This is equivalent to start_element(name) + write_string(content) +
|
495
481
|
* end_element.
|
496
482
|
*/
|
497
|
-
static VALUE rxml_writer_write_element(int argc, VALUE
|
483
|
+
static VALUE rxml_writer_write_element(int argc, VALUE* argv, VALUE self)
|
498
484
|
{
|
499
485
|
VALUE name, content;
|
500
486
|
|
501
487
|
rb_scan_args(argc, argv, "11", &name, &content);
|
502
|
-
if (Qnil == content)
|
503
|
-
|
488
|
+
if (Qnil == content)
|
489
|
+
{
|
490
|
+
if (Qfalse == rxml_writer_start_element(self, name))
|
491
|
+
{
|
504
492
|
return Qfalse;
|
505
493
|
}
|
506
494
|
return rxml_writer_end_element(self);
|
507
|
-
}
|
495
|
+
}
|
496
|
+
else
|
497
|
+
{
|
508
498
|
return numeric_rxml_writer_va_strings(self, Qundef, 2, xmlTextWriterWriteElement, name, content);
|
509
499
|
}
|
510
500
|
}
|
@@ -526,19 +516,23 @@ static VALUE rxml_writer_write_element(int argc, VALUE *argv, VALUE self)
|
|
526
516
|
* earlier.
|
527
517
|
* - +content+ can be omitted for an empty tag
|
528
518
|
*/
|
529
|
-
static VALUE rxml_writer_write_element_ns(int argc, VALUE
|
519
|
+
static VALUE rxml_writer_write_element_ns(int argc, VALUE* argv, VALUE self)
|
530
520
|
{
|
531
521
|
VALUE prefix, name, namespaceURI, content;
|
532
522
|
|
533
523
|
rb_scan_args(argc, argv, "22", &prefix, &name, &namespaceURI, &content);
|
534
|
-
if (Qnil == content)
|
524
|
+
if (Qnil == content)
|
525
|
+
{
|
535
526
|
VALUE argv[3] = { prefix, name, namespaceURI };
|
536
527
|
|
537
|
-
if (Qfalse == rxml_writer_start_element_ns(ARRAY_SIZE(argv), argv, self))
|
528
|
+
if (Qfalse == rxml_writer_start_element_ns(ARRAY_SIZE(argv), argv, self))
|
529
|
+
{
|
538
530
|
return Qfalse;
|
539
531
|
}
|
540
532
|
return rxml_writer_end_element(self);
|
541
|
-
}
|
533
|
+
}
|
534
|
+
else
|
535
|
+
{
|
542
536
|
return numeric_rxml_writer_va_strings(self, Qundef, 4, xmlTextWriterWriteElementNS, prefix, name, namespaceURI, content);
|
543
537
|
}
|
544
538
|
}
|
@@ -568,7 +562,7 @@ static VALUE rxml_writer_write_attribute(VALUE self, VALUE name, VALUE content)
|
|
568
562
|
* earlier.
|
569
563
|
* - +content+ can be omitted too for an empty attribute
|
570
564
|
*/
|
571
|
-
static VALUE rxml_writer_write_attribute_ns(int argc, VALUE
|
565
|
+
static VALUE rxml_writer_write_attribute_ns(int argc, VALUE* argv, VALUE self)
|
572
566
|
{
|
573
567
|
VALUE prefix, name, namespaceURI, content;
|
574
568
|
|
@@ -634,7 +628,7 @@ static VALUE rxml_writer_start_attribute(VALUE self, VALUE name)
|
|
634
628
|
* +namespaceURI+ to nil or omit it. Don't forget to declare the namespace
|
635
629
|
* prefix somewhere earlier.
|
636
630
|
*/
|
637
|
-
static VALUE rxml_writer_start_attribute_ns(int argc, VALUE
|
631
|
+
static VALUE rxml_writer_start_attribute_ns(int argc, VALUE* argv, VALUE self)
|
638
632
|
{
|
639
633
|
VALUE prefix, name, namespaceURI;
|
640
634
|
|
@@ -697,7 +691,7 @@ static VALUE rxml_writer_start_element(VALUE self, VALUE name)
|
|
697
691
|
* +namespaceURI+ to nil or omit it. Don't forget to declare the namespace
|
698
692
|
* prefix somewhere earlier.
|
699
693
|
*/
|
700
|
-
static VALUE rxml_writer_start_element_ns(int argc, VALUE
|
694
|
+
static VALUE rxml_writer_start_element_ns(int argc, VALUE* argv, VALUE self)
|
701
695
|
{
|
702
696
|
VALUE prefix, name, namespaceURI;
|
703
697
|
|
@@ -762,16 +756,17 @@ static VALUE rxml_writer_end_cdata(VALUE self)
|
|
762
756
|
* - standalone: nil (default) or a boolean to indicate if the document is
|
763
757
|
* standalone or not
|
764
758
|
*/
|
765
|
-
static VALUE rxml_writer_start_document(int argc, VALUE
|
759
|
+
static VALUE rxml_writer_start_document(int argc, VALUE* argv, VALUE self)
|
766
760
|
{
|
767
761
|
int ret;
|
768
762
|
VALUE options = Qnil;
|
769
|
-
rxml_writer_object
|
770
|
-
const xmlChar
|
771
|
-
const char
|
763
|
+
rxml_writer_object* rwo;
|
764
|
+
const xmlChar* xencoding = NULL;
|
765
|
+
const char* xstandalone = NULL;
|
772
766
|
|
773
767
|
rb_scan_args(argc, argv, "01", &options);
|
774
|
-
if (!NIL_P(options))
|
768
|
+
if (!NIL_P(options))
|
769
|
+
{
|
775
770
|
VALUE encoding, standalone;
|
776
771
|
|
777
772
|
encoding = standalone = Qnil;
|
@@ -779,16 +774,17 @@ static VALUE rxml_writer_start_document(int argc, VALUE *argv, VALUE self)
|
|
779
774
|
encoding = rb_hash_aref(options, sEncoding);
|
780
775
|
xencoding = NIL_P(encoding) ? NULL : (const xmlChar*)xmlGetCharEncodingName(NUM2INT(encoding));
|
781
776
|
standalone = rb_hash_aref(options, sStandalone);
|
782
|
-
if (NIL_P(standalone))
|
777
|
+
if (NIL_P(standalone))
|
778
|
+
{
|
783
779
|
xstandalone = NULL;
|
784
|
-
}
|
780
|
+
}
|
781
|
+
else
|
782
|
+
{
|
785
783
|
xstandalone = RTEST(standalone) ? "yes" : "no";
|
786
784
|
}
|
787
785
|
}
|
788
786
|
rwo = rxml_textwriter_get(self);
|
789
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
790
787
|
rwo->encoding = rxml_figure_encoding(xencoding);
|
791
|
-
#endif /* !HAVE_RUBY_ENCODING_H */
|
792
788
|
ret = xmlTextWriterStartDocument(rwo->writer, NULL, (const char*)xencoding, xstandalone);
|
793
789
|
|
794
790
|
return (-1 == ret ? Qfalse : Qtrue);
|
@@ -829,7 +825,7 @@ static VALUE rxml_writer_end_pi(VALUE self)
|
|
829
825
|
*
|
830
826
|
* Starts a DTD. Returns +false+ on failure.
|
831
827
|
*/
|
832
|
-
static VALUE rxml_writer_start_dtd(int argc, VALUE
|
828
|
+
static VALUE rxml_writer_start_dtd(int argc, VALUE* argv, VALUE self)
|
833
829
|
{
|
834
830
|
VALUE name, pubid, sysid;
|
835
831
|
|
@@ -853,12 +849,13 @@ static VALUE rxml_writer_start_dtd_element(VALUE self, VALUE name)
|
|
853
849
|
*
|
854
850
|
* Starts a DTD entity (<!ENTITY ... >). Returns +false+ on failure.
|
855
851
|
*/
|
856
|
-
static VALUE rxml_writer_start_dtd_entity(int argc, VALUE
|
852
|
+
static VALUE rxml_writer_start_dtd_entity(int argc, VALUE* argv, VALUE self)
|
857
853
|
{
|
858
854
|
VALUE name, pe;
|
859
855
|
|
860
856
|
rb_scan_args(argc, argv, "11", &name, &pe);
|
861
|
-
if (NIL_P(pe))
|
857
|
+
if (NIL_P(pe))
|
858
|
+
{
|
862
859
|
pe = Qfalse;
|
863
860
|
}
|
864
861
|
|
@@ -934,7 +931,7 @@ static VALUE rxml_writer_end_dtd_element(VALUE self)
|
|
934
931
|
* writer.write_dtd 'person', nil, nil, '<!ELEMENT person (firstname,lastname)><!ELEMENT firstname (#PCDATA)><!ELEMENT lastname (#PCDATA)>'
|
935
932
|
* #=> <!DOCTYPE person [<!ELEMENT person (firstname,lastname)><!ELEMENT firstname (#PCDATA)><!ELEMENT lastname (#PCDATA)>]>
|
936
933
|
*/
|
937
|
-
static VALUE rxml_writer_write_dtd(int argc, VALUE
|
934
|
+
static VALUE rxml_writer_write_dtd(int argc, VALUE* argv, VALUE self)
|
938
935
|
{
|
939
936
|
VALUE name, pubid, sysid, subset;
|
940
937
|
|
@@ -1043,12 +1040,12 @@ static VALUE rxml_writer_write_dtd_notation(VALUE self, VALUE name, VALUE pubid,
|
|
1043
1040
|
static VALUE rxml_writer_set_quote_char(VALUE self, VALUE quotechar)
|
1044
1041
|
{
|
1045
1042
|
int ret;
|
1046
|
-
const char
|
1047
|
-
rxml_writer_object
|
1043
|
+
const char* xquotechar;
|
1044
|
+
rxml_writer_object* rwo;
|
1048
1045
|
|
1049
1046
|
rwo = rxml_textwriter_get(self);
|
1050
1047
|
xquotechar = StringValueCStr(quotechar);
|
1051
|
-
ret = xmlTextWriterSetQuoteChar(rwo->writer, (xmlChar)
|
1048
|
+
ret = xmlTextWriterSetQuoteChar(rwo->writer, (xmlChar)xquotechar[0]);
|
1052
1049
|
|
1053
1050
|
return (-1 == ret ? Qfalse : Qtrue);
|
1054
1051
|
}
|
@@ -14,14 +14,6 @@ module LibXML
|
|
14
14
|
def elements
|
15
15
|
type.elements
|
16
16
|
end
|
17
|
-
|
18
|
-
def annotation
|
19
|
-
return if node.nil?
|
20
|
-
annotations = node.children.select { |n| n.name == 'annotation' }
|
21
|
-
annotations.map do |annotation|
|
22
|
-
annotation.children.map(&:content).join("\n")
|
23
|
-
end.join("\n")
|
24
|
-
end
|
25
17
|
end
|
26
18
|
end
|
27
19
|
end
|