libxml-ruby 0.9.7-x86-mswin32-60 → 0.9.8-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/CHANGES +53 -0
  2. data/Rakefile +1 -0
  3. data/ext/libxml/build.log +4 -0
  4. data/ext/libxml/cbg.c +86 -86
  5. data/ext/libxml/libxml.c +878 -876
  6. data/ext/libxml/ruby_libxml.h +8 -4
  7. data/ext/libxml/ruby_xml_attr.c +36 -168
  8. data/ext/libxml/ruby_xml_attr.h +2 -4
  9. data/ext/libxml/ruby_xml_attr_decl.c +177 -0
  10. data/ext/libxml/ruby_xml_attr_decl.h +13 -0
  11. data/ext/libxml/ruby_xml_attributes.c +29 -20
  12. data/ext/libxml/ruby_xml_document.c +895 -898
  13. data/ext/libxml/ruby_xml_dtd.c +18 -1
  14. data/ext/libxml/ruby_xml_dtd.h +1 -0
  15. data/ext/libxml/ruby_xml_encoding.c +116 -0
  16. data/ext/libxml/ruby_xml_encoding.h +12 -0
  17. data/ext/libxml/ruby_xml_error.c +8 -2
  18. data/ext/libxml/ruby_xml_html_parser.c +53 -74
  19. data/ext/libxml/ruby_xml_html_parser.h +2 -3
  20. data/ext/libxml/ruby_xml_html_parser_context.c +145 -0
  21. data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
  22. data/ext/libxml/ruby_xml_html_parser_options.c +48 -0
  23. data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
  24. data/ext/libxml/ruby_xml_input_cbg.c +1 -1
  25. data/ext/libxml/ruby_xml_io.c +30 -0
  26. data/ext/libxml/ruby_xml_io.h +9 -0
  27. data/ext/libxml/ruby_xml_namespace.c +34 -16
  28. data/ext/libxml/ruby_xml_namespace.h +2 -2
  29. data/ext/libxml/ruby_xml_namespaces.c +6 -6
  30. data/ext/libxml/ruby_xml_node.c +1367 -1324
  31. data/ext/libxml/ruby_xml_node.h +2 -2
  32. data/ext/libxml/ruby_xml_parser.c +26 -78
  33. data/ext/libxml/ruby_xml_parser.h +1 -1
  34. data/ext/libxml/ruby_xml_parser_context.c +284 -13
  35. data/ext/libxml/ruby_xml_parser_context.h +1 -2
  36. data/ext/libxml/ruby_xml_parser_options.c +75 -0
  37. data/ext/libxml/ruby_xml_parser_options.h +14 -0
  38. data/ext/libxml/ruby_xml_reader.c +277 -183
  39. data/ext/libxml/ruby_xml_sax_parser.c +60 -57
  40. data/ext/libxml/ruby_xml_xpath_context.c +43 -8
  41. data/ext/libxml/ruby_xml_xpath_expression.c +6 -0
  42. data/ext/libxml/ruby_xml_xpath_object.c +107 -95
  43. data/ext/libxml/ruby_xml_xpath_object.h +9 -1
  44. data/ext/libxml/ruby_xml_xpointer.c +107 -107
  45. data/ext/libxml/version.h +2 -2
  46. data/ext/mingw/libxml_ruby.dll.a +0 -0
  47. data/ext/mingw/libxml_ruby.so +0 -0
  48. data/ext/vc/libxml_ruby.vcproj +43 -3
  49. data/lib/libxml.rb +2 -3
  50. data/lib/libxml/attr.rb +71 -2
  51. data/lib/libxml/attr_decl.rb +81 -0
  52. data/lib/libxml/document.rb +78 -14
  53. data/lib/libxml/html_parser.rb +75 -42
  54. data/lib/libxml/node.rb +11 -0
  55. data/lib/libxml/parser.rb +106 -62
  56. data/lib/libxml/reader.rb +12 -0
  57. data/lib/libxml/sax_parser.rb +42 -52
  58. data/lib/libxml/xpath_object.rb +15 -0
  59. data/test/model/atom.xml +12 -12
  60. data/test/model/bands.xml +4 -4
  61. data/test/model/books.xml +146 -147
  62. data/test/model/merge_bug_data.xml +1 -1
  63. data/test/model/rubynet.xml +1 -0
  64. data/test/model/shiporder.rng +1 -1
  65. data/test/model/shiporder.xml +22 -22
  66. data/test/model/shiporder.xsd +30 -30
  67. data/test/model/xinclude.xml +1 -1
  68. data/test/{tc_node_attr.rb → tc_attr.rb} +1 -1
  69. data/test/tc_attr_decl.rb +131 -0
  70. data/test/tc_deprecated_require.rb +1 -3
  71. data/test/tc_document.rb +13 -3
  72. data/test/tc_document_write.rb +5 -5
  73. data/test/tc_dtd.rb +13 -5
  74. data/test/tc_html_parser.rb +14 -26
  75. data/test/tc_node_cdata.rb +1 -3
  76. data/test/tc_node_comment.rb +2 -4
  77. data/test/tc_node_edit.rb +2 -3
  78. data/test/tc_node_text.rb +35 -1
  79. data/test/tc_node_write.rb +3 -3
  80. data/test/tc_node_xlink.rb +2 -4
  81. data/test/tc_parser.rb +163 -70
  82. data/test/tc_parser_context.rb +103 -42
  83. data/test/tc_reader.rb +173 -45
  84. data/test/tc_relaxng.rb +2 -2
  85. data/test/tc_sax_parser.rb +48 -52
  86. data/test/tc_schema.rb +2 -2
  87. data/test/tc_xpath.rb +37 -6
  88. data/test/tc_xpath_context.rb +7 -1
  89. data/test/tc_xpath_expression.rb +1 -3
  90. data/test/tc_xpointer.rb +1 -3
  91. data/test/test_suite.rb +2 -3
  92. metadata +20 -13
  93. data/ext/libxml/ruby_xml_input.c +0 -329
  94. data/ext/libxml/ruby_xml_input.h +0 -20
  95. data/lib/libxml/parser_context.rb +0 -17
  96. data/lib/libxml/parser_options.rb +0 -25
  97. data/test/model/simple.xml +0 -7
  98. data/test/tc_input.rb +0 -13
  99. data/test/tc_well_formed.rb +0 -11
@@ -3,8 +3,8 @@ require 'test/unit'
3
3
 
4
4
  class TestSchema < Test::Unit::TestCase
5
5
  def setup
6
- xp = XML::Parser.new
7
- @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xml'))
6
+ file = File.join(File.dirname(__FILE__), 'model/shiporder.xml')
7
+ @doc = XML::Document.file(file)
8
8
  end
9
9
 
10
10
  def teardown
@@ -16,7 +16,6 @@ class TestXPath < Test::Unit::TestCase
16
16
  assert_instance_of(XML::XPath::Object, nodes)
17
17
  assert_equal(1, nodes.length)
18
18
  assert_equal(nodes.xpath_type, XML::XPath::NODESET)
19
- assert_instance_of(XML::XPath::Context, nodes.context)
20
19
  end
21
20
 
22
21
  def test_doc_find_first
@@ -163,9 +162,41 @@ class TestXPath < Test::Unit::TestCase
163
162
  assert_equal('Envelope', nodes.first.name)
164
163
  end
165
164
 
166
- # --- Debug ---
167
- #def test_debug
168
- # nodes = @doc.find('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
169
- # assert(nodes.debug)
170
- #end
165
+ def foo
166
+ puts nodes.length
167
+ doc = nil
168
+ assert_equal(4, nodes.length)
169
+ GC.start
170
+ node = nodes.first
171
+ nodes = nil
172
+ GC.start
173
+ end
174
+
175
+ def test_xpath_namespace_nodes
176
+ doc = XML::Document.string('<feed xmlns="http://www.w3.org/2005/Atom" xmlns:xhtml="http://www.w3.org/1999/xhtml"><entry/></feed>')
177
+ nodes = doc.find('//atom:entry|namespace::*', :atom => "http://www.w3.org/2005/Atom")
178
+ assert_equal(4, nodes.length)
179
+
180
+ node = nodes[0]
181
+ assert_equal(XML::Node::ELEMENT_NODE, node.node_type)
182
+
183
+ node = nodes[1]
184
+ assert_equal(XML::Node::NAMESPACE_DECL, node.node_type)
185
+
186
+ node = nodes[2]
187
+ assert_equal(XML::Node::NAMESPACE_DECL, node.node_type)
188
+
189
+ node = nodes[3]
190
+ assert_equal(XML::Node::NAMESPACE_DECL, node.node_type)
191
+ end
192
+
193
+ # Test to make sure we don't get nil on empty results.
194
+ # This is also to test that we don't segfault due to our C code getting a NULL pointer
195
+ # and not handling it properly.
196
+ def test_xpath_empty_result
197
+ doc = XML::Document.string('<html><body><p>Welcome to XHTML land!</p></body></html>')
198
+ nodes = doc.find("//object/param[translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'wmode']")
199
+ assert_not_nil nodes
200
+ end
201
+
171
202
  end
@@ -9,7 +9,7 @@ class TestXPathContext < Test::Unit::TestCase
9
9
  NS0_PREFIX = 'ns0'
10
10
  NS0_URI = 'http://services.somewhere.com'
11
11
 
12
- def setup()
12
+ def setup
13
13
  doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
14
14
  @context = XML::XPath::Context.new(doc)
15
15
  end
@@ -69,4 +69,10 @@ class TestXPathContext < Test::Unit::TestCase
69
69
  nodes = @context.find('soap:Body')
70
70
  assert_equal(0, nodes.length)
71
71
  end
72
+
73
+ def test_cache
74
+ @context.enable_cache
75
+ @context.enable_cache(10)
76
+ @context.disable_cache
77
+ end
72
78
  end
@@ -3,9 +3,7 @@ require 'test/unit'
3
3
 
4
4
  class TestXPathExpression < Test::Unit::TestCase
5
5
  def setup
6
- xp = XML::Parser.new()
7
- str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
8
- xp.string = str
6
+ xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
9
7
  @doc = xp.parse
10
8
  end
11
9
 
@@ -3,9 +3,7 @@ require "test/unit"
3
3
 
4
4
  class TC_XML_XPointer < Test::Unit::TestCase
5
5
  def setup()
6
- xp = XML::Parser.new()
7
- str = '<!DOCTYPE ra [<!ELEMENT ra (foo+)><!ATTLIST ra id ID #IMPLIED><!ELEMENT foo (#PCDATA)><!ATTLIST foo id ID #IMPLIED>]><ra id="start"><foo id="one">one</foo><foo id="two">two</foo><foo id="three">three</foo></ra>'
8
- assert_equal(str, xp.string = str)
6
+ xp = XML::Parser.string('<!DOCTYPE ra [<!ELEMENT ra (foo+)><!ATTLIST ra id ID #IMPLIED><!ELEMENT foo (#PCDATA)><!ATTLIST foo id ID #IMPLIED>]><ra id="start"><foo id="one">one</foo><foo id="two">two</foo><foo id="three">three</foo></ra>')
9
7
  @doc = xp.parse
10
8
  assert_instance_of(XML::Document, @doc)
11
9
  @root = @doc.root
@@ -1,14 +1,14 @@
1
1
  require 'tc_xml'
2
2
  require 'tc_attributes'
3
+ require 'tc_attr'
4
+ require 'tc_attr_decl'
3
5
  require 'tc_document'
4
6
  require 'tc_document_write'
5
7
  require 'tc_dtd'
6
- require 'tc_input'
7
8
  require 'tc_html_parser'
8
9
  require 'tc_namespaces'
9
10
  require 'tc_namespace'
10
11
  require 'tc_node'
11
- require 'tc_node_attr'
12
12
  require 'tc_node_cdata'
13
13
  require 'tc_node_comment'
14
14
  require 'tc_node_copy'
@@ -23,7 +23,6 @@ require 'tc_relaxng'
23
23
  require 'tc_sax_parser'
24
24
  require 'tc_schema'
25
25
  require 'tc_traversal'
26
- require 'tc_well_formed'
27
26
  require 'tc_xinclude'
28
27
  require 'tc_xpath'
29
28
  require 'tc_xpath_expression'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libxml-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: x86-mswin32-60
6
6
  authors:
7
7
  - Charlie Savage
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-12 00:00:00 -07:00
12
+ date: 2009-01-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -41,6 +41,7 @@ files:
41
41
  - doc/log
42
42
  - doc/log/changelog.xml
43
43
  - doc/log/changelog.xsl
44
+ - ext/libxml/build.log
44
45
  - ext/libxml/cbg.c
45
46
  - ext/libxml/extconf.rb
46
47
  - ext/libxml/libxml.c
@@ -49,18 +50,26 @@ files:
49
50
  - ext/libxml/ruby_xml_attr.h
50
51
  - ext/libxml/ruby_xml_attributes.c
51
52
  - ext/libxml/ruby_xml_attributes.h
53
+ - ext/libxml/ruby_xml_attr_decl.c
54
+ - ext/libxml/ruby_xml_attr_decl.h
52
55
  - ext/libxml/ruby_xml_document.c
53
56
  - ext/libxml/ruby_xml_document.h
54
57
  - ext/libxml/ruby_xml_dtd.c
55
58
  - ext/libxml/ruby_xml_dtd.h
59
+ - ext/libxml/ruby_xml_encoding.c
60
+ - ext/libxml/ruby_xml_encoding.h
56
61
  - ext/libxml/ruby_xml_error.c
57
62
  - ext/libxml/ruby_xml_error.h
58
63
  - ext/libxml/ruby_xml_html_parser.c
59
64
  - ext/libxml/ruby_xml_html_parser.h
60
- - ext/libxml/ruby_xml_input.c
61
- - ext/libxml/ruby_xml_input.h
65
+ - ext/libxml/ruby_xml_html_parser_context.c
66
+ - ext/libxml/ruby_xml_html_parser_context.h
67
+ - ext/libxml/ruby_xml_html_parser_options.c
68
+ - ext/libxml/ruby_xml_html_parser_options.h
62
69
  - ext/libxml/ruby_xml_input_cbg.c
63
70
  - ext/libxml/ruby_xml_input_cbg.h
71
+ - ext/libxml/ruby_xml_io.c
72
+ - ext/libxml/ruby_xml_io.h
64
73
  - ext/libxml/ruby_xml_namespace.c
65
74
  - ext/libxml/ruby_xml_namespace.h
66
75
  - ext/libxml/ruby_xml_namespaces.c
@@ -71,6 +80,8 @@ files:
71
80
  - ext/libxml/ruby_xml_parser.h
72
81
  - ext/libxml/ruby_xml_parser_context.c
73
82
  - ext/libxml/ruby_xml_parser_context.h
83
+ - ext/libxml/ruby_xml_parser_options.c
84
+ - ext/libxml/ruby_xml_parser_options.h
74
85
  - ext/libxml/ruby_xml_reader.c
75
86
  - ext/libxml/ruby_xml_reader.h
76
87
  - ext/libxml/ruby_xml_relaxng.c
@@ -103,6 +114,7 @@ files:
103
114
  - lib/libxml
104
115
  - lib/libxml/attr.rb
105
116
  - lib/libxml/attributes.rb
117
+ - lib/libxml/attr_decl.rb
106
118
  - lib/libxml/document.rb
107
119
  - lib/libxml/error.rb
108
120
  - lib/libxml/hpricot.rb
@@ -112,8 +124,6 @@ files:
112
124
  - lib/libxml/node.rb
113
125
  - lib/libxml/ns.rb
114
126
  - lib/libxml/parser.rb
115
- - lib/libxml/parser_context.rb
116
- - lib/libxml/parser_options.rb
117
127
  - lib/libxml/properties.rb
118
128
  - lib/libxml/reader.rb
119
129
  - lib/libxml/sax_callbacks.rb
@@ -143,21 +153,20 @@ files:
143
153
  - test/model/shiporder.rng
144
154
  - test/model/shiporder.xml
145
155
  - test/model/shiporder.xsd
146
- - test/model/simple.xml
147
156
  - test/model/soap.xml
148
157
  - test/model/xinclude.xml
158
+ - test/tc_attr.rb
149
159
  - test/tc_attributes.rb
160
+ - test/tc_attr_decl.rb
150
161
  - test/tc_deprecated_require.rb
151
162
  - test/tc_document.rb
152
163
  - test/tc_document_write.rb
153
164
  - test/tc_dtd.rb
154
165
  - test/tc_error.rb
155
166
  - test/tc_html_parser.rb
156
- - test/tc_input.rb
157
167
  - test/tc_namespace.rb
158
168
  - test/tc_namespaces.rb
159
169
  - test/tc_node.rb
160
- - test/tc_node_attr.rb
161
170
  - test/tc_node_cdata.rb
162
171
  - test/tc_node_comment.rb
163
172
  - test/tc_node_copy.rb
@@ -173,7 +182,6 @@ files:
173
182
  - test/tc_sax_parser.rb
174
183
  - test/tc_schema.rb
175
184
  - test/tc_traversal.rb
176
- - test/tc_well_formed.rb
177
185
  - test/tc_xinclude.rb
178
186
  - test/tc_xml.rb
179
187
  - test/tc_xpath.rb
@@ -213,18 +221,18 @@ signing_key:
213
221
  specification_version: 2
214
222
  summary: Ruby libxml bindings
215
223
  test_files:
224
+ - test/tc_attr.rb
216
225
  - test/tc_attributes.rb
226
+ - test/tc_attr_decl.rb
217
227
  - test/tc_deprecated_require.rb
218
228
  - test/tc_document.rb
219
229
  - test/tc_document_write.rb
220
230
  - test/tc_dtd.rb
221
231
  - test/tc_error.rb
222
232
  - test/tc_html_parser.rb
223
- - test/tc_input.rb
224
233
  - test/tc_namespace.rb
225
234
  - test/tc_namespaces.rb
226
235
  - test/tc_node.rb
227
- - test/tc_node_attr.rb
228
236
  - test/tc_node_cdata.rb
229
237
  - test/tc_node_comment.rb
230
238
  - test/tc_node_copy.rb
@@ -240,7 +248,6 @@ test_files:
240
248
  - test/tc_sax_parser.rb
241
249
  - test/tc_schema.rb
242
250
  - test/tc_traversal.rb
243
- - test/tc_well_formed.rb
244
251
  - test/tc_xinclude.rb
245
252
  - test/tc_xml.rb
246
253
  - test/tc_xpath.rb
@@ -1,329 +0,0 @@
1
- /* $Id: rxml_input.c 528 2008-11-15 23:43:48Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include <stdarg.h>
6
- #include "ruby_libxml.h"
7
-
8
- VALUE cXMLInput;
9
-
10
- /*
11
- * Document-class: LibXML::XML::Input
12
- *
13
- * Input is a helper class that defines a libxml data source.
14
- * Libxml can parse files, strings, io streams and documents
15
- * accessible via networking protocols such as http.
16
- * Be default, the ruby-libxml bindings expose parsing
17
- * files, io streams and strings.
18
- *
19
- * Generally you will not directly work with the input object,
20
- * but instead will use the various Document and Parser apis.
21
- * For example:
22
- *
23
- * parser = XML::Parser.file('my_file')
24
- * parser = XML::Parser.string('<myxml/>')
25
- * parser = XML::Parser.io(File.open('my_file'))
26
- *
27
- * XML::HTMLParser, XML::Reader, XML::SaxParser and
28
- * XML::Document work in the same way.
29
- *
30
- * LibXML converts all data sources to UTF8 internally before
31
- * processing them. By default, LibXML will determine a data
32
- * source's encoding using the algorithm described on its
33
- * website[* http://xmlsoft.org/encoding.html].
34
- *
35
- * However, its some cases it is possible to tell LibXML
36
- * the data source's encoding via the constants defined in
37
- * the Encoding module.
38
- *
39
- * Example 1:
40
- *
41
- * parser = XML::Parser.new
42
- * parser.input.encoding = XML::Input::ISO_8859_1
43
- * parser.io = File.open('some_file', 'rb')
44
- * doc = parser.parse
45
- *
46
- * Example 2:
47
- *
48
- * parser = XML::HTMLParser.new
49
- * parser.encoding = XML::Input::ISO_8859_1
50
- * parser.file = "some_file"
51
- * doc = parser.parse
52
- *
53
- * Example 3:
54
- *
55
- * document = XML::Document.new
56
- * encoding_string = XML::Input.encoding_to_s(XML::Encoding::ISO_8859_1)
57
- * document.encoding = document
58
- * doc << XML::Node.new */
59
-
60
- ID BASE_URL_ATTR;
61
- ID ENCODING_ATTR;
62
- ID FILE_ATTR;
63
- ID STRING_ATTR;
64
- ID IO_ATTR;
65
-
66
- static ID READ_METHOD;
67
-
68
- /* This method is called by libxml when it wants to read
69
- more data from a stream. We go with the duck typing
70
- solution to support StringIO objects. */
71
- int rxml_read_callback(void *context, char *buffer, int len)
72
- {
73
- VALUE io = (VALUE) context;
74
- VALUE string = rb_funcall(io, READ_METHOD, 1, INT2NUM(len));
75
- int size;
76
-
77
- if (string == Qnil)
78
- return 0;
79
-
80
- size = RSTRING_LEN(string);
81
- memcpy(buffer, StringValuePtr(string), size);
82
-
83
- return size;
84
- }
85
-
86
- /*
87
- * call-seq:
88
- * Input.encoding_to_s(Input::ENCODING) -> "encoding"
89
- *
90
- * Converts an encoding contstant defined on the XML::Input
91
- * class to its text representation.
92
- */
93
- VALUE rxml_input_encoding_to_s(VALUE klass, VALUE encoding)
94
- {
95
- char* encodingStr = NULL;
96
-
97
- switch (NUM2INT(encoding))
98
- {
99
- case XML_CHAR_ENCODING_ERROR:
100
- encodingStr = "Error";
101
- break;
102
- case XML_CHAR_ENCODING_NONE:
103
- encodingStr = "None";
104
- break;
105
- case XML_CHAR_ENCODING_UTF8:
106
- encodingStr = "UTF-8";
107
- break;
108
- case XML_CHAR_ENCODING_UTF16LE:
109
- encodingStr = "UTF-16LE";
110
- break;
111
- case XML_CHAR_ENCODING_UTF16BE:
112
- encodingStr = "UTF-16BE";
113
- break;
114
- case XML_CHAR_ENCODING_UCS4LE:
115
- encodingStr = "UCS-4LE";
116
- break;
117
- case XML_CHAR_ENCODING_UCS4BE:
118
- encodingStr = "UCS-4BE";
119
- break;
120
- case XML_CHAR_ENCODING_EBCDIC:
121
- encodingStr = "EBCDIC";
122
- break;
123
- case XML_CHAR_ENCODING_UCS4_2143:
124
- encodingStr = "UCS-4";
125
- break;
126
- case XML_CHAR_ENCODING_UCS4_3412:
127
- encodingStr = "UCS-4";
128
- break;
129
- case XML_CHAR_ENCODING_UCS2:
130
- encodingStr = "UCS-2";
131
- break;
132
- case XML_CHAR_ENCODING_8859_1:
133
- encodingStr = "ISO-8859-1";
134
- break;
135
- case XML_CHAR_ENCODING_8859_2:
136
- encodingStr = "ISO-8859-2";
137
- break;
138
- case XML_CHAR_ENCODING_8859_3:
139
- encodingStr = "ISO-8859-3";
140
- break;
141
- case XML_CHAR_ENCODING_8859_4:
142
- encodingStr = "ISO-8859-4";
143
- break;
144
- case XML_CHAR_ENCODING_8859_5:
145
- encodingStr = "ISO-8859-5";
146
- break;
147
- case XML_CHAR_ENCODING_8859_6:
148
- encodingStr = "ISO-8859-6";
149
- break;
150
- case XML_CHAR_ENCODING_8859_7:
151
- encodingStr = "ISO-8859-7";
152
- break;
153
- case XML_CHAR_ENCODING_8859_8:
154
- encodingStr = "ISO-8859-8";
155
- break;
156
- case XML_CHAR_ENCODING_8859_9:
157
- encodingStr = "ISO-8859-9";
158
- break;
159
- case XML_CHAR_ENCODING_2022_JP:
160
- encodingStr = "ISO-2022-JP";
161
- break;
162
- case XML_CHAR_ENCODING_SHIFT_JIS:
163
- encodingStr = "Shift_JIS";
164
- break;
165
- case XML_CHAR_ENCODING_EUC_JP:
166
- encodingStr = "EUC-JP";
167
- break;
168
- case XML_CHAR_ENCODING_ASCII:
169
- encodingStr = "ASCII";
170
- break;
171
- default:
172
- rb_raise(rb_eArgError, "Unknown encoding.");
173
- }
174
-
175
- return rb_str_new2(encodingStr);
176
- }
177
-
178
- /*
179
- * call-seq:
180
- * initialize -> LibXML::XML::Input instance
181
- *
182
- * Initialize a new intput object.
183
- */
184
- static VALUE rxml_input_initialize(VALUE self)
185
- {
186
- rb_ivar_set(self, BASE_URL_ATTR, Qnil);
187
- rb_ivar_set(self, ENCODING_ATTR, INT2NUM(XML_CHAR_ENCODING_UTF8));
188
- return self;
189
- }
190
-
191
- /*
192
- * call-seq:
193
- * input.FILE -> "FILE"
194
- *
195
- * Obtain the FILE this parser will read from.
196
- */
197
- static VALUE rxml_input_file_get(VALUE self)
198
- {
199
- return rb_ivar_get(self, FILE_ATTR);
200
- }
201
-
202
- /*
203
- * call-seq:
204
- * input.FILE = "FILE"
205
- *
206
- * Set the FILE this parser will read from.
207
- */
208
- static VALUE rxml_input_file_set(VALUE self, VALUE FILE)
209
- {
210
- Check_Type(FILE, T_STRING);
211
- rb_ivar_set(self, FILE_ATTR, FILE);
212
- rb_ivar_set(self, IO_ATTR, Qnil);
213
- rb_ivar_set(self, STRING_ATTR, Qnil);
214
- return self;
215
- }
216
-
217
- /*
218
- * call-seq:
219
- * input.string -> "string"
220
- *
221
- * Obtain the string this parser will read from.
222
- */
223
- static VALUE rxml_input_string_get(VALUE self)
224
- {
225
- return rb_ivar_get(self, STRING_ATTR);
226
- }
227
-
228
- /*
229
- * call-seq:
230
- * input.string = "string"
231
- *
232
- * Set the string this parser will read from.
233
- */
234
- static VALUE rxml_input_string_set(VALUE self, VALUE string)
235
- {
236
- Check_Type(string, T_STRING);
237
- rb_ivar_set(self, FILE_ATTR, Qnil);
238
- rb_ivar_set(self, IO_ATTR, Qnil);
239
- rb_ivar_set(self, STRING_ATTR, string);
240
- return self;
241
- }
242
-
243
- /*
244
- * call-seq:
245
- * input.io -> IO
246
- *
247
- * Obtain the IO instance this parser works with.
248
- */
249
- static VALUE rxml_input_io_get(VALUE self)
250
- {
251
- return rb_ivar_get(self, IO_ATTR);
252
- }
253
-
254
- /*
255
- * call-seq:
256
- * input.io = IO
257
- *
258
- * Set the IO instance this parser works with.
259
- */
260
- static VALUE rxml_input_io_set(VALUE self, VALUE io)
261
- {
262
- rb_ivar_set(self, FILE_ATTR, Qnil);
263
- rb_ivar_set(self, IO_ATTR, io);
264
- rb_ivar_set(self, STRING_ATTR, Qnil);
265
- return self;
266
- }
267
-
268
- // Rdoc needs to know
269
- #ifdef RDOC_NEVER_DEFINED
270
- mLibXML = rb_define_module("LibXML");
271
- mXML = rb_define_module_under(mLibXML, "XML");
272
- #endif
273
-
274
- // Rdoc needs to know
275
- #ifdef RDOC_NEVER_DEFINED
276
- mLibXML = rb_define_module("LibXML");
277
- mXML = rb_define_module_under(mLibXML, "XML");
278
- #endif
279
-
280
- void ruby_init_xml_input(void)
281
- {
282
- BASE_URL_ATTR = rb_intern("@base_url");
283
- ENCODING_ATTR = rb_intern("@encoding");
284
- FILE_ATTR = rb_intern("@file");
285
- IO_ATTR = rb_intern("@io");
286
- STRING_ATTR = rb_intern("@string");
287
-
288
- READ_METHOD = rb_intern("read");
289
-
290
- cXMLInput = rb_define_class_under(mXML, "Input", rb_cObject);
291
- rb_define_singleton_method(cXMLInput, "encoding_to_s", rxml_input_encoding_to_s, 1);
292
-
293
- rb_define_const(cXMLInput, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
294
- rb_define_const(cXMLInput, "ERROR", INT2NUM(XML_CHAR_ENCODING_ERROR)); /* No char encoding detected */
295
- rb_define_const(cXMLInput, "NONE", INT2NUM(XML_CHAR_ENCODING_NONE)); /* No char encoding detected */
296
- rb_define_const(cXMLInput, "UTF_8", INT2NUM(XML_CHAR_ENCODING_UTF8)); /* UTF-8 */
297
- rb_define_const(cXMLInput, "UTF_16LE", INT2NUM(XML_CHAR_ENCODING_UTF16LE)); /* UTF-16 little endian */
298
- rb_define_const(cXMLInput, "UTF_16BE", INT2NUM(XML_CHAR_ENCODING_UTF16BE)); /* UTF-16 big endian */
299
- rb_define_const(cXMLInput, "UCS_4LE", INT2NUM(XML_CHAR_ENCODING_UCS4LE)); /* UCS-4 little endian */
300
- rb_define_const(cXMLInput, "UCS_4BE", INT2NUM(XML_CHAR_ENCODING_UCS4BE)); /* UCS-4 big endian */
301
- rb_define_const(cXMLInput, "EBCDIC", INT2NUM(XML_CHAR_ENCODING_EBCDIC)); /* EBCDIC uh! */
302
- rb_define_const(cXMLInput, "UCS_4_2143", INT2NUM(XML_CHAR_ENCODING_UCS4_2143)); /* UCS-4 unusual ordering */
303
- rb_define_const(cXMLInput, "UCS_4_3412", INT2NUM(XML_CHAR_ENCODING_UCS4_3412)); /* UCS-4 unusual ordering */
304
- rb_define_const(cXMLInput, "UCS_2", INT2NUM(XML_CHAR_ENCODING_UCS2)); /* UCS-2 */
305
- rb_define_const(cXMLInput, "ISO_8859_1", INT2NUM(XML_CHAR_ENCODING_8859_1)); /* ISO-8859-1 ISO Latin 1 */
306
- rb_define_const(cXMLInput, "ISO_8859_2", INT2NUM(XML_CHAR_ENCODING_8859_2)); /* ISO-8859-2 ISO Latin 2 */
307
- rb_define_const(cXMLInput, "ISO_8859_3", INT2NUM(XML_CHAR_ENCODING_8859_3)); /* ISO-8859-3 */
308
- rb_define_const(cXMLInput, "ISO_8859_4", INT2NUM(XML_CHAR_ENCODING_8859_4)); /* ISO-8859-4 */
309
- rb_define_const(cXMLInput, "ISO_8859_5", INT2NUM(XML_CHAR_ENCODING_8859_5)); /* ISO-8859-5 */
310
- rb_define_const(cXMLInput, "ISO_8859_6", INT2NUM(XML_CHAR_ENCODING_8859_6)); /* ISO-8859-6 */
311
- rb_define_const(cXMLInput, "ISO_8859_7", INT2NUM(XML_CHAR_ENCODING_8859_7)); /* ISO-8859-7 */
312
- rb_define_const(cXMLInput, "ISO_8859_8", INT2NUM(XML_CHAR_ENCODING_8859_8)); /* ISO-8859-8 */
313
- rb_define_const(cXMLInput, "ISO_8859_9", INT2NUM(XML_CHAR_ENCODING_8859_9)); /* ISO-8859-9 */
314
- rb_define_const(cXMLInput, "ISO_2022_JP", INT2NUM(XML_CHAR_ENCODING_2022_JP)); /* ISO-2022-JP */
315
- rb_define_const(cXMLInput, "SHIFT_JIS", INT2NUM(XML_CHAR_ENCODING_SHIFT_JIS)); /* Shift_JIS */
316
- rb_define_const(cXMLInput, "EUC_JP", INT2NUM(XML_CHAR_ENCODING_EUC_JP)); /* EUC-JP */
317
- rb_define_const(cXMLInput, "ASCII", INT2NUM(XML_CHAR_ENCODING_ASCII)); /* pure ASCII */
318
-
319
- rb_define_attr(cXMLInput, "base_url", 1, 1);
320
- rb_define_attr(cXMLInput, "encoding", 1, 1);
321
-
322
- rb_define_method(cXMLInput, "initialize", rxml_input_initialize, 0);
323
- rb_define_method(cXMLInput, "file", rxml_input_file_get, 0);
324
- rb_define_method(cXMLInput, "file=", rxml_input_file_set, 1);
325
- rb_define_method(cXMLInput, "string", rxml_input_string_get, 0);
326
- rb_define_method(cXMLInput, "string=", rxml_input_string_set, 1);
327
- rb_define_method(cXMLInput, "io", rxml_input_io_get, 0);
328
- rb_define_method(cXMLInput, "io=", rxml_input_io_set, 1);
329
- }