libxml-ruby 0.9.4-x86-mswin32-60 → 0.9.5-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGES +22 -0
  2. data/README +3 -1
  3. data/ext/libxml/cbg.c +86 -76
  4. data/ext/libxml/extconf.rb +2 -1
  5. data/ext/libxml/libxml.c +899 -885
  6. data/ext/libxml/ruby_libxml.h +65 -70
  7. data/ext/libxml/ruby_xml_attr.c +485 -500
  8. data/ext/libxml/ruby_xml_attributes.c +107 -106
  9. data/ext/libxml/ruby_xml_document.c +355 -356
  10. data/ext/libxml/ruby_xml_dtd.c +119 -117
  11. data/ext/libxml/ruby_xml_error.c +1112 -581
  12. data/ext/libxml/ruby_xml_html_parser.c +35 -34
  13. data/ext/libxml/ruby_xml_input.c +182 -187
  14. data/ext/libxml/ruby_xml_input_cbg.c +197 -179
  15. data/ext/libxml/ruby_xml_node.c +1529 -1566
  16. data/ext/libxml/ruby_xml_node.h +2 -2
  17. data/ext/libxml/ruby_xml_ns.c +150 -156
  18. data/ext/libxml/ruby_xml_parser.c +37 -36
  19. data/ext/libxml/ruby_xml_parser_context.c +657 -659
  20. data/ext/libxml/ruby_xml_reader.c +203 -209
  21. data/ext/libxml/ruby_xml_relaxng.c +29 -25
  22. data/ext/libxml/ruby_xml_sax_parser.c +33 -32
  23. data/ext/libxml/ruby_xml_schema.c +165 -161
  24. data/ext/libxml/ruby_xml_state.c +19 -21
  25. data/ext/libxml/ruby_xml_xinclude.c +24 -25
  26. data/ext/libxml/ruby_xml_xpath.c +108 -108
  27. data/ext/libxml/ruby_xml_xpath_context.c +305 -293
  28. data/ext/libxml/ruby_xml_xpath_expression.c +24 -24
  29. data/ext/libxml/ruby_xml_xpath_object.c +89 -96
  30. data/ext/libxml/ruby_xml_xpointer.c +107 -109
  31. data/ext/libxml/ruby_xml_xpointer.h +13 -13
  32. data/ext/libxml/version.h +2 -2
  33. data/ext/mingw/Rakefile +1 -1
  34. data/ext/mingw/libxml_ruby.dll.a +0 -0
  35. data/ext/mingw/libxml_ruby.so +0 -0
  36. data/ext/vc/libxml_ruby.vcproj +1 -1
  37. data/lib/libxml/error.rb +4 -4
  38. data/test/tc_node_edit.rb +14 -2
  39. data/test/tc_node_text.rb +9 -9
  40. metadata +2 -2
@@ -1,659 +1,657 @@
1
- /* $Id: ruby_xml_parser_context.c 612 2008-11-21 08:01:29Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include "ruby_libxml.h"
6
- #include "ruby_xml_parser_context.h"
7
-
8
- VALUE cXMLParserContext;
9
-
10
- /*
11
- * Document-class: LibXML::XML::Parser::Context
12
- *
13
- * The XML::Parser::Context class provides in-depth control over how
14
- * a document is parsed.
15
- */
16
-
17
-
18
- static void
19
- rxml_parser_context_free(xmlParserCtxtPtr ctxt) {
20
- if (ctxt != NULL)
21
- xmlFreeParserCtxt(ctxt);
22
- }
23
-
24
- VALUE
25
- rxml_parser_context_wrap(xmlParserCtxtPtr ctxt) {
26
- return Data_Wrap_Struct(cXMLParserContext, NULL, rxml_parser_context_free, ctxt);
27
- }
28
-
29
- /*
30
- * call-seq:
31
- * context.data_directory -> "dir"
32
- *
33
- * Obtain the data directory associated with this context.
34
- */
35
- static VALUE
36
- rxml_parser_context_data_directory_get(VALUE self) {
37
- xmlParserCtxtPtr ctxt;
38
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
39
-
40
- if (ctxt->directory == NULL)
41
- return(Qnil);
42
- else
43
- return(rb_str_new2(ctxt->directory));
44
- }
45
-
46
-
47
- /*
48
- * call-seq:
49
- * context.depth -> num
50
- *
51
- * Obtain the depth of this context.
52
- */
53
- static VALUE
54
- rxml_parser_context_depth_get(VALUE self) {
55
- xmlParserCtxtPtr ctxt;
56
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
57
-
58
- return(INT2NUM(ctxt->depth));
59
- }
60
-
61
-
62
- /*
63
- * call-seq:
64
- * context.disable_sax? -> (true|false)
65
- *
66
- * Determine whether SAX-based processing is disabled
67
- * in this context.
68
- */
69
- static VALUE
70
- rxml_parser_context_disable_sax_q(VALUE self) {
71
- xmlParserCtxtPtr ctxt;
72
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
73
-
74
- if (ctxt->disableSAX)
75
- return(Qtrue);
76
- else
77
- return(Qfalse);
78
- }
79
-
80
-
81
-
82
- /*
83
- * call-seq:
84
- * context.docbook? -> (true|false)
85
- *
86
- * Determine whether this is a docbook context.
87
- */
88
- static VALUE
89
- rxml_parser_context_docbook_q(VALUE self) {
90
- xmlParserCtxtPtr ctxt;
91
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
92
-
93
- if (ctxt->html == 2) // TODO check this
94
- return(Qtrue);
95
- else
96
- return(Qfalse);
97
- }
98
-
99
-
100
- /*
101
- * call-seq:
102
- * context.encoding -> "encoding"
103
- *
104
- * Obtain the character encoding identifier used in
105
- * this context.
106
- */
107
- static VALUE
108
- rxml_parser_context_encoding_get(VALUE self) {
109
- xmlParserCtxtPtr ctxt;
110
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
111
-
112
- if (ctxt->encoding == NULL)
113
- return(Qnil);
114
- else
115
- return(rb_str_new2((const char*)ctxt->encoding));
116
- }
117
-
118
-
119
- /*
120
- * call-seq:
121
- * context.errno -> num
122
- *
123
- * Obtain the last-error number in this context.
124
- */
125
- static VALUE
126
- rxml_parser_context_errno_get(VALUE self) {
127
- xmlParserCtxtPtr ctxt;
128
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
129
-
130
- return(INT2NUM(ctxt->errNo));
131
- }
132
-
133
-
134
-
135
- /*
136
- * call-seq:
137
- * context.html? -> (true|false)
138
- *
139
- * Determine whether this is an html context.
140
- */
141
- static VALUE
142
- rxml_parser_context_html_q(VALUE self) {
143
- xmlParserCtxtPtr ctxt;
144
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
145
-
146
- if (ctxt->html == 1)
147
- return(Qtrue);
148
- else
149
- return(Qfalse);
150
- }
151
-
152
-
153
- /*
154
- * call-seq:
155
- * context.max_num_streams -> num
156
- *
157
- * Obtain the limit on the number of IO streams opened in
158
- * this context.
159
- */
160
- static VALUE
161
- rxml_parser_context_io_max_num_streams_get(VALUE self) {
162
- // TODO alias to max_streams and dep this?
163
- xmlParserCtxtPtr ctxt;
164
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
165
-
166
- return(INT2NUM(ctxt->inputMax));
167
- }
168
-
169
-
170
- /*
171
- * call-seq:
172
- * context.num_streams -> "dir"
173
- *
174
- * Obtain the actual number of IO streams in this
175
- * context.
176
- */
177
- static VALUE
178
- rxml_parser_context_io_num_streams_get(VALUE self) {
179
- xmlParserCtxtPtr ctxt;
180
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
181
-
182
- return(INT2NUM(ctxt->inputNr));
183
- }
184
-
185
-
186
- /*
187
- * call-seq:
188
- * context.keep_blanks? -> (true|false)
189
- *
190
- * Determine whether parsers in this context retain
191
- * whitespace.
192
- */
193
- static VALUE
194
- rxml_parser_context_keep_blanks_q(VALUE self) {
195
- xmlParserCtxtPtr ctxt;
196
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
197
-
198
- if (ctxt->keepBlanks)
199
- return(Qtrue);
200
- else
201
- return(Qfalse);
202
- }
203
-
204
-
205
- /*
206
- * call-seq:
207
- * context.name_depth -> num
208
- *
209
- * Obtain the name depth for this context.
210
- */
211
- static VALUE
212
- rxml_parser_context_name_depth_get(VALUE self) {
213
- xmlParserCtxtPtr ctxt;
214
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
215
-
216
- return(INT2NUM(ctxt->nameNr));
217
- }
218
-
219
-
220
- /*
221
- * call-seq:
222
- * context.name_depth_max -> num
223
- *
224
- * Obtain the maximum name depth for this context.
225
- */
226
- static VALUE
227
- rxml_parser_context_name_depth_max_get(VALUE self) {
228
- xmlParserCtxtPtr ctxt;
229
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
230
-
231
- return(INT2NUM(ctxt->nameMax));
232
- }
233
-
234
-
235
- /*
236
- * call-seq:
237
- * context.name_node -> "name"
238
- *
239
- * Obtain the name node for this context.
240
- */
241
- static VALUE
242
- rxml_parser_context_name_node_get(VALUE self) {
243
- xmlParserCtxtPtr ctxt;
244
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
245
-
246
- if (ctxt->name == NULL)
247
- return(Qnil);
248
- else
249
- return(rb_str_new2((const char*)ctxt->name));
250
- }
251
-
252
-
253
- /*
254
- * call-seq:
255
- * context.name_tab -> ["name", ..., "name"]
256
- *
257
- * Obtain the name table for this context.
258
- */
259
- static VALUE
260
- rxml_parser_context_name_tab_get(VALUE self) {
261
- int i;
262
- xmlParserCtxtPtr ctxt;
263
- VALUE tab_ary;
264
-
265
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
266
-
267
- if (ctxt->nameTab == NULL)
268
- return(Qnil);
269
-
270
- tab_ary = rb_ary_new();
271
-
272
- for (i = (ctxt->nameNr - 1); i >= 0; i--) {
273
- if (ctxt->nameTab[i] == NULL)
274
- continue;
275
- else
276
- rb_ary_push(tab_ary, rb_str_new2((const char*)ctxt->nameTab[i]));
277
- }
278
-
279
- return(tab_ary);
280
- }
281
-
282
-
283
- /*
284
- * call-seq:
285
- * context.node_depth -> num
286
- *
287
- * Obtain the node depth for this context.
288
- */
289
- static VALUE
290
- rxml_parser_context_node_depth_get(VALUE self) {
291
- xmlParserCtxtPtr ctxt;
292
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
293
-
294
- return(INT2NUM(ctxt->nodeNr));
295
- }
296
-
297
-
298
- /*
299
- * call-seq:
300
- * context.node -> node
301
- *
302
- * Obtain the root node of this context.
303
- */
304
- static VALUE
305
- rxml_parser_context_node_get(VALUE self) {
306
- xmlParserCtxtPtr ctxt;
307
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
308
-
309
- if (ctxt->node == NULL)
310
- return(Qnil);
311
- else
312
- return(rxml_node2_wrap(cXMLNode,
313
- ctxt->node));
314
- }
315
-
316
-
317
- /*
318
- * call-seq:
319
- * context.node_depth_max -> num
320
- *
321
- * Obtain the maximum node depth for this context.
322
- */
323
- static VALUE
324
- rxml_parser_context_node_depth_max_get(VALUE self) {
325
- xmlParserCtxtPtr ctxt;
326
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
327
-
328
- return(INT2NUM(ctxt->nodeMax));
329
- }
330
-
331
-
332
- /*
333
- * call-seq:
334
- * context.num_chars -> num
335
- *
336
- * Obtain the number of characters in this context.
337
- */
338
- static VALUE
339
- rxml_parser_context_num_chars_get(VALUE self) {
340
- xmlParserCtxtPtr ctxt;
341
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
342
-
343
- return(LONG2NUM(ctxt->nbChars));
344
- }
345
-
346
- /*
347
- * call-seq:
348
- * context.replace_entities? -> (true|false)
349
- *
350
- * Determine whether external entity replacement is enabled in this
351
- * context.
352
- */
353
- static VALUE
354
- rxml_parser_context_replace_entities_q(VALUE self) {
355
- xmlParserCtxtPtr ctxt;
356
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
357
-
358
- if (ctxt->replaceEntities)
359
- return(Qtrue);
360
- else
361
- return(Qfalse);
362
- }
363
-
364
-
365
- /*
366
- * call-seq:
367
- * context.replace_entities = true|false
368
- *
369
- * Control whether external entity replacement is enabled in this
370
- * context.
371
- */
372
- static VALUE
373
- rxml_parser_context_replace_entities_set(VALUE self, VALUE bool) {
374
- xmlParserCtxtPtr ctxt;
375
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
376
-
377
- if (TYPE(bool) == T_FALSE) {
378
- ctxt->replaceEntities = 0;
379
- return(Qfalse);
380
- } else {
381
- ctxt->replaceEntities = 1;
382
- return(Qfalse);
383
- }
384
- }
385
-
386
- /*
387
- * call-seq:
388
- * context.space_depth -> num
389
- *
390
- * Obtain the space depth for this context.
391
- */
392
- static VALUE
393
- rxml_parser_context_space_depth_get(VALUE self) {
394
- xmlParserCtxtPtr ctxt;
395
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
396
-
397
- return(INT2NUM(ctxt->spaceNr));
398
- }
399
-
400
-
401
- /*
402
- * call-seq:
403
- * context.space_depth -> num
404
- *
405
- * Obtain the maximum space depth for this context.
406
- */
407
- static VALUE
408
- rxml_parser_context_space_depth_max_get(VALUE self) {
409
- xmlParserCtxtPtr ctxt;
410
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
411
-
412
- return(INT2NUM(ctxt->spaceMax));
413
- }
414
-
415
-
416
- /*
417
- * call-seq:
418
- * context.subset_external? -> (true|false)
419
- *
420
- * Determine whether this context is a subset of an
421
- * external context.
422
- */
423
- static VALUE
424
- rxml_parser_context_subset_external_q(VALUE self) {
425
- xmlParserCtxtPtr ctxt;
426
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
427
-
428
- if (ctxt->inSubset == 2)
429
- return(Qtrue);
430
- else
431
- return(Qfalse);
432
- }
433
-
434
-
435
- /*
436
- * call-seq:
437
- * context.subset_internal? -> (true|false)
438
- *
439
- * Determine whether this context is a subset of an
440
- * internal context.
441
- */
442
- static VALUE
443
- rxml_parser_context_subset_internal_q(VALUE self) {
444
- xmlParserCtxtPtr ctxt;
445
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
446
-
447
- if (ctxt->inSubset == 1)
448
- return(Qtrue);
449
- else
450
- return(Qfalse);
451
- }
452
-
453
-
454
- /*
455
- * call-seq:
456
- * context.subset_name -> "name"
457
- *
458
- * Obtain this context's subset name (valid only if
459
- * either of subset_external? or subset_internal?
460
- * is true).
461
- */
462
- static VALUE
463
- rxml_parser_context_subset_name_get(VALUE self) {
464
- xmlParserCtxtPtr ctxt;
465
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
466
-
467
- if (ctxt->intSubName == NULL)
468
- return(Qnil);
469
- else
470
- return(rb_str_new2((const char*)ctxt->intSubName));
471
- }
472
-
473
-
474
- /*
475
- * call-seq:
476
- * context.subset_external_uri -> "uri"
477
- *
478
- * Obtain this context's external subset URI. (valid only if
479
- * either of subset_external? or subset_internal?
480
- * is true).
481
- */
482
- static VALUE
483
- rxml_parser_context_subset_external_uri_get(VALUE self) {
484
- xmlParserCtxtPtr ctxt;
485
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
486
-
487
- if (ctxt->extSubURI == NULL)
488
- return(Qnil);
489
- else
490
- return(rb_str_new2((const char*)ctxt->extSubURI));
491
- }
492
-
493
-
494
- /*
495
- * call-seq:
496
- * context.subset_external_system_id -> "system_id"
497
- *
498
- * Obtain this context's external subset system identifier.
499
- * (valid only if either of subset_external? or subset_internal?
500
- * is true).
501
- */
502
- static VALUE
503
- rxml_parser_context_subset_external_system_id_get(VALUE self) {
504
- xmlParserCtxtPtr ctxt;
505
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
506
-
507
- if (ctxt->extSubSystem == NULL)
508
- return(Qnil);
509
- else
510
- return(rb_str_new2((const char*)ctxt->extSubSystem));
511
- }
512
-
513
-
514
- /*
515
- * call-seq:
516
- * context.standalone? -> (true|false)
517
- *
518
- * Determine whether this is a standalone context.
519
- */
520
- static VALUE
521
- rxml_parser_context_standalone_q(VALUE self) {
522
- xmlParserCtxtPtr ctxt;
523
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
524
-
525
- if (ctxt->standalone)
526
- return(Qtrue);
527
- else
528
- return(Qfalse);
529
- }
530
-
531
-
532
- /*
533
- * call-seq:
534
- * context.stats? -> (true|false)
535
- *
536
- * Determine whether this context maintains statistics.
537
- */
538
- static VALUE
539
- rxml_parser_context_stats_q(VALUE self) {
540
- xmlParserCtxtPtr ctxt;
541
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
542
-
543
- if (ctxt->record_info)
544
- return(Qtrue);
545
- else
546
- return(Qfalse);
547
- }
548
-
549
-
550
- /*
551
- * call-seq:
552
- * context.valid? -> (true|false)
553
- *
554
- * Determine whether this context is valid.
555
- */
556
- static VALUE
557
- rxml_parser_context_valid_q(VALUE self) {
558
- xmlParserCtxtPtr ctxt;
559
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
560
-
561
- if (ctxt->valid)
562
- return(Qtrue);
563
- else
564
- return(Qfalse);
565
- }
566
-
567
-
568
- /*
569
- * call-seq:
570
- * context.validate? -> (true|false)
571
- *
572
- * Determine whether validation is enabled in this context.
573
- */
574
- static VALUE
575
- rxml_parser_context_validate_q(VALUE self) {
576
- xmlParserCtxtPtr ctxt;
577
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
578
-
579
- if (ctxt->validate)
580
- return(Qtrue);
581
- else
582
- return(Qfalse);
583
- }
584
-
585
-
586
- /*
587
- * call-seq:
588
- * context.version -> "version"
589
- *
590
- * Obtain this context's version identifier.
591
- */
592
- static VALUE
593
- rxml_parser_context_version_get(VALUE self) {
594
- xmlParserCtxtPtr ctxt;
595
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
596
-
597
- if (ctxt->version == NULL)
598
- return(Qnil);
599
- else
600
- return(rb_str_new2((const char*)ctxt->version));
601
- }
602
-
603
-
604
- /*
605
- * call-seq:
606
- * context.well_formed? -> (true|false)
607
- *
608
- * Determine whether this context contains well-formed XML.
609
- */
610
- static VALUE
611
- rxml_parser_context_well_formed_q(VALUE self) {
612
- xmlParserCtxtPtr ctxt;
613
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
614
-
615
- if (ctxt->wellFormed)
616
- return(Qtrue);
617
- else
618
- return(Qfalse);
619
- }
620
-
621
- void
622
- ruby_init_xml_parser_context(void) {
623
- cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject);
624
- rb_undef_alloc_func(cXMLParserContext);
625
-
626
- rb_define_method(cXMLParserContext, "data_directory", rxml_parser_context_data_directory_get, 0);
627
- rb_define_method(cXMLParserContext, "depth", rxml_parser_context_depth_get, 0);
628
- rb_define_method(cXMLParserContext, "disable_sax?", rxml_parser_context_disable_sax_q, 0);
629
- rb_define_method(cXMLParserContext, "docbook?", rxml_parser_context_docbook_q, 0);
630
- rb_define_method(cXMLParserContext, "encoding", rxml_parser_context_encoding_get, 0);
631
- rb_define_method(cXMLParserContext, "errno", rxml_parser_context_errno_get, 0);
632
- rb_define_method(cXMLParserContext, "html?", rxml_parser_context_html_q, 0);
633
- rb_define_method(cXMLParserContext, "io_max_num_streams", rxml_parser_context_io_max_num_streams_get, 0);
634
- rb_define_method(cXMLParserContext, "io_num_streams", rxml_parser_context_io_num_streams_get, 0);
635
- rb_define_method(cXMLParserContext, "keep_blanks?", rxml_parser_context_keep_blanks_q, 0);
636
- rb_define_method(cXMLParserContext, "name_node", rxml_parser_context_name_node_get, 0);
637
- rb_define_method(cXMLParserContext, "name_depth", rxml_parser_context_name_depth_get, 0);
638
- rb_define_method(cXMLParserContext, "name_depth_max", rxml_parser_context_name_depth_max_get, 0);
639
- rb_define_method(cXMLParserContext, "name_tab", rxml_parser_context_name_tab_get, 0);
640
- rb_define_method(cXMLParserContext, "node", rxml_parser_context_node_get, 0);
641
- rb_define_method(cXMLParserContext, "node_depth", rxml_parser_context_node_depth_get, 0);
642
- rb_define_method(cXMLParserContext, "node_depth_max", rxml_parser_context_node_depth_max_get, 0);
643
- rb_define_method(cXMLParserContext, "num_chars", rxml_parser_context_num_chars_get, 0);
644
- rb_define_method(cXMLParserContext, "replace_entities?", rxml_parser_context_replace_entities_q, 0);
645
- rb_define_method(cXMLParserContext, "replace_entities=", rxml_parser_context_replace_entities_set, 1);
646
- rb_define_method(cXMLParserContext, "space_depth", rxml_parser_context_space_depth_get, 0);
647
- rb_define_method(cXMLParserContext, "space_depth_max", rxml_parser_context_space_depth_max_get, 0);
648
- rb_define_method(cXMLParserContext, "subset_external?", rxml_parser_context_subset_external_q, 0);
649
- rb_define_method(cXMLParserContext, "subset_external_system_id", rxml_parser_context_subset_external_system_id_get, 0);
650
- rb_define_method(cXMLParserContext, "subset_external_uri", rxml_parser_context_subset_name_get, 0);
651
- rb_define_method(cXMLParserContext, "subset_internal?", rxml_parser_context_subset_internal_q, 0);
652
- rb_define_method(cXMLParserContext, "subset_internal_name", rxml_parser_context_subset_name_get, 0);
653
- rb_define_method(cXMLParserContext, "stats?", rxml_parser_context_stats_q, 0);
654
- rb_define_method(cXMLParserContext, "standalone?", rxml_parser_context_standalone_q, 0);
655
- rb_define_method(cXMLParserContext, "valid", rxml_parser_context_valid_q, 0);
656
- rb_define_method(cXMLParserContext, "validate?", rxml_parser_context_validate_q, 0);
657
- rb_define_method(cXMLParserContext, "version", rxml_parser_context_version_get, 0);
658
- rb_define_method(cXMLParserContext, "well_formed?", rxml_parser_context_well_formed_q, 0);
659
- }
1
+ /* $Id: ruby_xml_parser_context.c 650 2008-11-30 03:40:22Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_parser_context.h"
7
+
8
+ VALUE cXMLParserContext;
9
+
10
+ /*
11
+ * Document-class: LibXML::XML::Parser::Context
12
+ *
13
+ * The XML::Parser::Context class provides in-depth control over how
14
+ * a document is parsed.
15
+ */
16
+
17
+ static void rxml_parser_context_free(xmlParserCtxtPtr ctxt)
18
+ {
19
+ if (ctxt != NULL)
20
+ xmlFreeParserCtxt(ctxt);
21
+ }
22
+
23
+ VALUE rxml_parser_context_wrap(xmlParserCtxtPtr ctxt)
24
+ {
25
+ return Data_Wrap_Struct(cXMLParserContext, NULL, rxml_parser_context_free,
26
+ ctxt);
27
+ }
28
+
29
+ /*
30
+ * call-seq:
31
+ * context.data_directory -> "dir"
32
+ *
33
+ * Obtain the data directory associated with this context.
34
+ */
35
+ static VALUE rxml_parser_context_data_directory_get(VALUE self)
36
+ {
37
+ xmlParserCtxtPtr ctxt;
38
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
39
+
40
+ if (ctxt->directory == NULL)
41
+ return (Qnil);
42
+ else
43
+ return (rb_str_new2(ctxt->directory));
44
+ }
45
+
46
+ /*
47
+ * call-seq:
48
+ * context.depth -> num
49
+ *
50
+ * Obtain the depth of this context.
51
+ */
52
+ static VALUE rxml_parser_context_depth_get(VALUE self)
53
+ {
54
+ xmlParserCtxtPtr ctxt;
55
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
56
+
57
+ return (INT2NUM(ctxt->depth));
58
+ }
59
+
60
+ /*
61
+ * call-seq:
62
+ * context.disable_sax? -> (true|false)
63
+ *
64
+ * Determine whether SAX-based processing is disabled
65
+ * in this context.
66
+ */
67
+ static VALUE rxml_parser_context_disable_sax_q(VALUE self)
68
+ {
69
+ xmlParserCtxtPtr ctxt;
70
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
71
+
72
+ if (ctxt->disableSAX)
73
+ return (Qtrue);
74
+ else
75
+ return (Qfalse);
76
+ }
77
+
78
+ /*
79
+ * call-seq:
80
+ * context.docbook? -> (true|false)
81
+ *
82
+ * Determine whether this is a docbook context.
83
+ */
84
+ static VALUE rxml_parser_context_docbook_q(VALUE self)
85
+ {
86
+ xmlParserCtxtPtr ctxt;
87
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
88
+
89
+ if (ctxt->html == 2) // TODO check this
90
+ return (Qtrue);
91
+ else
92
+ return (Qfalse);
93
+ }
94
+
95
+ /*
96
+ * call-seq:
97
+ * context.encoding -> "encoding"
98
+ *
99
+ * Obtain the character encoding identifier used in
100
+ * this context.
101
+ */
102
+ static VALUE rxml_parser_context_encoding_get(VALUE self)
103
+ {
104
+ xmlParserCtxtPtr ctxt;
105
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
106
+
107
+ if (ctxt->encoding == NULL)
108
+ return (Qnil);
109
+ else
110
+ return (rb_str_new2((const char*) ctxt->encoding));
111
+ }
112
+
113
+ /*
114
+ * call-seq:
115
+ * context.errno -> num
116
+ *
117
+ * Obtain the last-error number in this context.
118
+ */
119
+ static VALUE rxml_parser_context_errno_get(VALUE self)
120
+ {
121
+ xmlParserCtxtPtr ctxt;
122
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
123
+
124
+ return (INT2NUM(ctxt->errNo));
125
+ }
126
+
127
+ /*
128
+ * call-seq:
129
+ * context.html? -> (true|false)
130
+ *
131
+ * Determine whether this is an html context.
132
+ */
133
+ static VALUE rxml_parser_context_html_q(VALUE self)
134
+ {
135
+ xmlParserCtxtPtr ctxt;
136
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
137
+
138
+ if (ctxt->html == 1)
139
+ return (Qtrue);
140
+ else
141
+ return (Qfalse);
142
+ }
143
+
144
+ /*
145
+ * call-seq:
146
+ * context.max_num_streams -> num
147
+ *
148
+ * Obtain the limit on the number of IO streams opened in
149
+ * this context.
150
+ */
151
+ static VALUE rxml_parser_context_io_max_num_streams_get(VALUE self)
152
+ {
153
+ // TODO alias to max_streams and dep this?
154
+ xmlParserCtxtPtr ctxt;
155
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
156
+
157
+ return (INT2NUM(ctxt->inputMax));
158
+ }
159
+
160
+ /*
161
+ * call-seq:
162
+ * context.num_streams -> "dir"
163
+ *
164
+ * Obtain the actual number of IO streams in this
165
+ * context.
166
+ */
167
+ static VALUE rxml_parser_context_io_num_streams_get(VALUE self)
168
+ {
169
+ xmlParserCtxtPtr ctxt;
170
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
171
+
172
+ return (INT2NUM(ctxt->inputNr));
173
+ }
174
+
175
+ /*
176
+ * call-seq:
177
+ * context.keep_blanks? -> (true|false)
178
+ *
179
+ * Determine whether parsers in this context retain
180
+ * whitespace.
181
+ */
182
+ static VALUE rxml_parser_context_keep_blanks_q(VALUE self)
183
+ {
184
+ xmlParserCtxtPtr ctxt;
185
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
186
+
187
+ if (ctxt->keepBlanks)
188
+ return (Qtrue);
189
+ else
190
+ return (Qfalse);
191
+ }
192
+
193
+ /*
194
+ * call-seq:
195
+ * context.name_depth -> num
196
+ *
197
+ * Obtain the name depth for this context.
198
+ */
199
+ static VALUE rxml_parser_context_name_depth_get(VALUE self)
200
+ {
201
+ xmlParserCtxtPtr ctxt;
202
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
203
+
204
+ return (INT2NUM(ctxt->nameNr));
205
+ }
206
+
207
+ /*
208
+ * call-seq:
209
+ * context.name_depth_max -> num
210
+ *
211
+ * Obtain the maximum name depth for this context.
212
+ */
213
+ static VALUE rxml_parser_context_name_depth_max_get(VALUE self)
214
+ {
215
+ xmlParserCtxtPtr ctxt;
216
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
217
+
218
+ return (INT2NUM(ctxt->nameMax));
219
+ }
220
+
221
+ /*
222
+ * call-seq:
223
+ * context.name_node -> "name"
224
+ *
225
+ * Obtain the name node for this context.
226
+ */
227
+ static VALUE rxml_parser_context_name_node_get(VALUE self)
228
+ {
229
+ xmlParserCtxtPtr ctxt;
230
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
231
+
232
+ if (ctxt->name == NULL)
233
+ return (Qnil);
234
+ else
235
+ return (rb_str_new2((const char*) ctxt->name));
236
+ }
237
+
238
+ /*
239
+ * call-seq:
240
+ * context.name_tab -> ["name", ..., "name"]
241
+ *
242
+ * Obtain the name table for this context.
243
+ */
244
+ static VALUE rxml_parser_context_name_tab_get(VALUE self)
245
+ {
246
+ int i;
247
+ xmlParserCtxtPtr ctxt;
248
+ VALUE tab_ary;
249
+
250
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
251
+
252
+ if (ctxt->nameTab == NULL)
253
+ return (Qnil);
254
+
255
+ tab_ary = rb_ary_new();
256
+
257
+ for (i = (ctxt->nameNr - 1); i >= 0; i--)
258
+ {
259
+ if (ctxt->nameTab[i] == NULL)
260
+ continue;
261
+ else
262
+ rb_ary_push(tab_ary, rb_str_new2((const char*) ctxt->nameTab[i]));
263
+ }
264
+
265
+ return (tab_ary);
266
+ }
267
+
268
+ /*
269
+ * call-seq:
270
+ * context.node_depth -> num
271
+ *
272
+ * Obtain the node depth for this context.
273
+ */
274
+ static VALUE rxml_parser_context_node_depth_get(VALUE self)
275
+ {
276
+ xmlParserCtxtPtr ctxt;
277
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
278
+
279
+ return (INT2NUM(ctxt->nodeNr));
280
+ }
281
+
282
+ /*
283
+ * call-seq:
284
+ * context.node -> node
285
+ *
286
+ * Obtain the root node of this context.
287
+ */
288
+ static VALUE rxml_parser_context_node_get(VALUE self)
289
+ {
290
+ xmlParserCtxtPtr ctxt;
291
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
292
+
293
+ if (ctxt->node == NULL)
294
+ return (Qnil);
295
+ else
296
+ return (rxml_node_wrap(cXMLNode, ctxt->node));
297
+ }
298
+
299
+ /*
300
+ * call-seq:
301
+ * context.node_depth_max -> num
302
+ *
303
+ * Obtain the maximum node depth for this context.
304
+ */
305
+ static VALUE rxml_parser_context_node_depth_max_get(VALUE self)
306
+ {
307
+ xmlParserCtxtPtr ctxt;
308
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
309
+
310
+ return (INT2NUM(ctxt->nodeMax));
311
+ }
312
+
313
+ /*
314
+ * call-seq:
315
+ * context.num_chars -> num
316
+ *
317
+ * Obtain the number of characters in this context.
318
+ */
319
+ static VALUE rxml_parser_context_num_chars_get(VALUE self)
320
+ {
321
+ xmlParserCtxtPtr ctxt;
322
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
323
+
324
+ return (LONG2NUM(ctxt->nbChars));
325
+ }
326
+
327
+ /*
328
+ * call-seq:
329
+ * context.replace_entities? -> (true|false)
330
+ *
331
+ * Determine whether external entity replacement is enabled in this
332
+ * context.
333
+ */
334
+ static VALUE rxml_parser_context_replace_entities_q(VALUE self)
335
+ {
336
+ xmlParserCtxtPtr ctxt;
337
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
338
+
339
+ if (ctxt->replaceEntities)
340
+ return (Qtrue);
341
+ else
342
+ return (Qfalse);
343
+ }
344
+
345
+ /*
346
+ * call-seq:
347
+ * context.replace_entities = true|false
348
+ *
349
+ * Control whether external entity replacement is enabled in this
350
+ * context.
351
+ */
352
+ static VALUE rxml_parser_context_replace_entities_set(VALUE self, VALUE bool)
353
+ {
354
+ xmlParserCtxtPtr ctxt;
355
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
356
+
357
+ if (TYPE(bool) == T_FALSE)
358
+ {
359
+ ctxt->replaceEntities = 0;
360
+ return (Qfalse);
361
+ }
362
+ else
363
+ {
364
+ ctxt->replaceEntities = 1;
365
+ return (Qfalse);
366
+ }
367
+ }
368
+
369
+ /*
370
+ * call-seq:
371
+ * context.space_depth -> num
372
+ *
373
+ * Obtain the space depth for this context.
374
+ */
375
+ static VALUE rxml_parser_context_space_depth_get(VALUE self)
376
+ {
377
+ xmlParserCtxtPtr ctxt;
378
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
379
+
380
+ return (INT2NUM(ctxt->spaceNr));
381
+ }
382
+
383
+ /*
384
+ * call-seq:
385
+ * context.space_depth -> num
386
+ *
387
+ * Obtain the maximum space depth for this context.
388
+ */
389
+ static VALUE rxml_parser_context_space_depth_max_get(VALUE self)
390
+ {
391
+ xmlParserCtxtPtr ctxt;
392
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
393
+
394
+ return (INT2NUM(ctxt->spaceMax));
395
+ }
396
+
397
+ /*
398
+ * call-seq:
399
+ * context.subset_external? -> (true|false)
400
+ *
401
+ * Determine whether this context is a subset of an
402
+ * external context.
403
+ */
404
+ static VALUE rxml_parser_context_subset_external_q(VALUE self)
405
+ {
406
+ xmlParserCtxtPtr ctxt;
407
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
408
+
409
+ if (ctxt->inSubset == 2)
410
+ return (Qtrue);
411
+ else
412
+ return (Qfalse);
413
+ }
414
+
415
+ /*
416
+ * call-seq:
417
+ * context.subset_internal? -> (true|false)
418
+ *
419
+ * Determine whether this context is a subset of an
420
+ * internal context.
421
+ */
422
+ static VALUE rxml_parser_context_subset_internal_q(VALUE self)
423
+ {
424
+ xmlParserCtxtPtr ctxt;
425
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
426
+
427
+ if (ctxt->inSubset == 1)
428
+ return (Qtrue);
429
+ else
430
+ return (Qfalse);
431
+ }
432
+
433
+ /*
434
+ * call-seq:
435
+ * context.subset_name -> "name"
436
+ *
437
+ * Obtain this context's subset name (valid only if
438
+ * either of subset_external? or subset_internal?
439
+ * is true).
440
+ */
441
+ static VALUE rxml_parser_context_subset_name_get(VALUE self)
442
+ {
443
+ xmlParserCtxtPtr ctxt;
444
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
445
+
446
+ if (ctxt->intSubName == NULL)
447
+ return (Qnil);
448
+ else
449
+ return (rb_str_new2((const char*) ctxt->intSubName));
450
+ }
451
+
452
+ /*
453
+ * call-seq:
454
+ * context.subset_external_uri -> "uri"
455
+ *
456
+ * Obtain this context's external subset URI. (valid only if
457
+ * either of subset_external? or subset_internal?
458
+ * is true).
459
+ */
460
+ static VALUE rxml_parser_context_subset_external_uri_get(VALUE self)
461
+ {
462
+ xmlParserCtxtPtr ctxt;
463
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
464
+
465
+ if (ctxt->extSubURI == NULL)
466
+ return (Qnil);
467
+ else
468
+ return (rb_str_new2((const char*) ctxt->extSubURI));
469
+ }
470
+
471
+ /*
472
+ * call-seq:
473
+ * context.subset_external_system_id -> "system_id"
474
+ *
475
+ * Obtain this context's external subset system identifier.
476
+ * (valid only if either of subset_external? or subset_internal?
477
+ * is true).
478
+ */
479
+ static VALUE rxml_parser_context_subset_external_system_id_get(VALUE self)
480
+ {
481
+ xmlParserCtxtPtr ctxt;
482
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
483
+
484
+ if (ctxt->extSubSystem == NULL)
485
+ return (Qnil);
486
+ else
487
+ return (rb_str_new2((const char*) ctxt->extSubSystem));
488
+ }
489
+
490
+ /*
491
+ * call-seq:
492
+ * context.standalone? -> (true|false)
493
+ *
494
+ * Determine whether this is a standalone context.
495
+ */
496
+ static VALUE rxml_parser_context_standalone_q(VALUE self)
497
+ {
498
+ xmlParserCtxtPtr ctxt;
499
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
500
+
501
+ if (ctxt->standalone)
502
+ return (Qtrue);
503
+ else
504
+ return (Qfalse);
505
+ }
506
+
507
+ /*
508
+ * call-seq:
509
+ * context.stats? -> (true|false)
510
+ *
511
+ * Determine whether this context maintains statistics.
512
+ */
513
+ static VALUE rxml_parser_context_stats_q(VALUE self)
514
+ {
515
+ xmlParserCtxtPtr ctxt;
516
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
517
+
518
+ if (ctxt->record_info)
519
+ return (Qtrue);
520
+ else
521
+ return (Qfalse);
522
+ }
523
+
524
+ /*
525
+ * call-seq:
526
+ * context.valid? -> (true|false)
527
+ *
528
+ * Determine whether this context is valid.
529
+ */
530
+ static VALUE rxml_parser_context_valid_q(VALUE self)
531
+ {
532
+ xmlParserCtxtPtr ctxt;
533
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
534
+
535
+ if (ctxt->valid)
536
+ return (Qtrue);
537
+ else
538
+ return (Qfalse);
539
+ }
540
+
541
+ /*
542
+ * call-seq:
543
+ * context.validate? -> (true|false)
544
+ *
545
+ * Determine whether validation is enabled in this context.
546
+ */
547
+ static VALUE rxml_parser_context_validate_q(VALUE self)
548
+ {
549
+ xmlParserCtxtPtr ctxt;
550
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
551
+
552
+ if (ctxt->validate)
553
+ return (Qtrue);
554
+ else
555
+ return (Qfalse);
556
+ }
557
+
558
+ /*
559
+ * call-seq:
560
+ * context.version -> "version"
561
+ *
562
+ * Obtain this context's version identifier.
563
+ */
564
+ static VALUE rxml_parser_context_version_get(VALUE self)
565
+ {
566
+ xmlParserCtxtPtr ctxt;
567
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
568
+
569
+ if (ctxt->version == NULL)
570
+ return (Qnil);
571
+ else
572
+ return (rb_str_new2((const char*) ctxt->version));
573
+ }
574
+
575
+ /*
576
+ * call-seq:
577
+ * context.well_formed? -> (true|false)
578
+ *
579
+ * Determine whether this context contains well-formed XML.
580
+ */
581
+ static VALUE rxml_parser_context_well_formed_q(VALUE self)
582
+ {
583
+ xmlParserCtxtPtr ctxt;
584
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
585
+
586
+ if (ctxt->wellFormed)
587
+ return (Qtrue);
588
+ else
589
+ return (Qfalse);
590
+ }
591
+
592
+ void ruby_init_xml_parser_context(void)
593
+ {
594
+ cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject);
595
+ rb_undef_alloc_func(cXMLParserContext);
596
+
597
+ rb_define_method(cXMLParserContext, "data_directory",
598
+ rxml_parser_context_data_directory_get, 0);
599
+ rb_define_method(cXMLParserContext, "depth", rxml_parser_context_depth_get, 0);
600
+ rb_define_method(cXMLParserContext, "disable_sax?",
601
+ rxml_parser_context_disable_sax_q, 0);
602
+ rb_define_method(cXMLParserContext, "docbook?",
603
+ rxml_parser_context_docbook_q, 0);
604
+ rb_define_method(cXMLParserContext, "encoding",
605
+ rxml_parser_context_encoding_get, 0);
606
+ rb_define_method(cXMLParserContext, "errno", rxml_parser_context_errno_get, 0);
607
+ rb_define_method(cXMLParserContext, "html?", rxml_parser_context_html_q, 0);
608
+ rb_define_method(cXMLParserContext, "io_max_num_streams",
609
+ rxml_parser_context_io_max_num_streams_get, 0);
610
+ rb_define_method(cXMLParserContext, "io_num_streams",
611
+ rxml_parser_context_io_num_streams_get, 0);
612
+ rb_define_method(cXMLParserContext, "keep_blanks?",
613
+ rxml_parser_context_keep_blanks_q, 0);
614
+ rb_define_method(cXMLParserContext, "name_node",
615
+ rxml_parser_context_name_node_get, 0);
616
+ rb_define_method(cXMLParserContext, "name_depth",
617
+ rxml_parser_context_name_depth_get, 0);
618
+ rb_define_method(cXMLParserContext, "name_depth_max",
619
+ rxml_parser_context_name_depth_max_get, 0);
620
+ rb_define_method(cXMLParserContext, "name_tab",
621
+ rxml_parser_context_name_tab_get, 0);
622
+ rb_define_method(cXMLParserContext, "node", rxml_parser_context_node_get, 0);
623
+ rb_define_method(cXMLParserContext, "node_depth",
624
+ rxml_parser_context_node_depth_get, 0);
625
+ rb_define_method(cXMLParserContext, "node_depth_max",
626
+ rxml_parser_context_node_depth_max_get, 0);
627
+ rb_define_method(cXMLParserContext, "num_chars",
628
+ rxml_parser_context_num_chars_get, 0);
629
+ rb_define_method(cXMLParserContext, "replace_entities?",
630
+ rxml_parser_context_replace_entities_q, 0);
631
+ rb_define_method(cXMLParserContext, "replace_entities=",
632
+ rxml_parser_context_replace_entities_set, 1);
633
+ rb_define_method(cXMLParserContext, "space_depth",
634
+ rxml_parser_context_space_depth_get, 0);
635
+ rb_define_method(cXMLParserContext, "space_depth_max",
636
+ rxml_parser_context_space_depth_max_get, 0);
637
+ rb_define_method(cXMLParserContext, "subset_external?",
638
+ rxml_parser_context_subset_external_q, 0);
639
+ rb_define_method(cXMLParserContext, "subset_external_system_id",
640
+ rxml_parser_context_subset_external_system_id_get, 0);
641
+ rb_define_method(cXMLParserContext, "subset_external_uri",
642
+ rxml_parser_context_subset_name_get, 0);
643
+ rb_define_method(cXMLParserContext, "subset_internal?",
644
+ rxml_parser_context_subset_internal_q, 0);
645
+ rb_define_method(cXMLParserContext, "subset_internal_name",
646
+ rxml_parser_context_subset_name_get, 0);
647
+ rb_define_method(cXMLParserContext, "stats?", rxml_parser_context_stats_q, 0);
648
+ rb_define_method(cXMLParserContext, "standalone?",
649
+ rxml_parser_context_standalone_q, 0);
650
+ rb_define_method(cXMLParserContext, "valid", rxml_parser_context_valid_q, 0);
651
+ rb_define_method(cXMLParserContext, "validate?",
652
+ rxml_parser_context_validate_q, 0);
653
+ rb_define_method(cXMLParserContext, "version",
654
+ rxml_parser_context_version_get, 0);
655
+ rb_define_method(cXMLParserContext, "well_formed?",
656
+ rxml_parser_context_well_formed_q, 0);
657
+ }