libxml-ruby 2.8.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY +15 -0
  3. data/README.rdoc +7 -7
  4. data/Rakefile +80 -78
  5. data/ext/libxml/extconf.h +4 -0
  6. data/ext/libxml/extconf.rb +57 -116
  7. data/ext/libxml/libxml.c +4 -0
  8. data/ext/libxml/ruby_xml.c +977 -893
  9. data/ext/libxml/ruby_xml.h +20 -10
  10. data/ext/libxml/ruby_xml_attr.c +333 -333
  11. data/ext/libxml/ruby_xml_attr_decl.c +2 -2
  12. data/ext/libxml/ruby_xml_cbg.c +85 -85
  13. data/ext/libxml/ruby_xml_document.c +1133 -1147
  14. data/ext/libxml/ruby_xml_dtd.c +261 -268
  15. data/ext/libxml/ruby_xml_encoding.c +262 -260
  16. data/ext/libxml/ruby_xml_encoding.h +19 -19
  17. data/ext/libxml/ruby_xml_html_parser_context.c +337 -338
  18. data/ext/libxml/ruby_xml_input_cbg.c +191 -191
  19. data/ext/libxml/ruby_xml_io.c +52 -50
  20. data/ext/libxml/ruby_xml_namespace.c +2 -2
  21. data/ext/libxml/ruby_xml_node.c +1446 -1452
  22. data/ext/libxml/ruby_xml_parser_context.c +999 -1001
  23. data/ext/libxml/ruby_xml_reader.c +1226 -1228
  24. data/ext/libxml/ruby_xml_relaxng.c +110 -111
  25. data/ext/libxml/ruby_xml_sax2_handler.c +326 -328
  26. data/ext/libxml/ruby_xml_schema.c +300 -301
  27. data/ext/libxml/ruby_xml_version.h +3 -3
  28. data/ext/libxml/ruby_xml_writer.c +14 -15
  29. data/ext/libxml/ruby_xml_xpath.c +188 -188
  30. data/ext/libxml/ruby_xml_xpath_context.c +360 -361
  31. data/ext/libxml/ruby_xml_xpath_object.c +335 -335
  32. data/libxml-ruby.gemspec +47 -44
  33. data/test/tc_attr.rb +5 -7
  34. data/test/tc_attr_decl.rb +5 -6
  35. data/test/tc_attributes.rb +1 -2
  36. data/test/tc_canonicalize.rb +1 -2
  37. data/test/tc_deprecated_require.rb +1 -2
  38. data/test/tc_document.rb +4 -5
  39. data/test/tc_document_write.rb +2 -3
  40. data/test/tc_dtd.rb +4 -5
  41. data/test/tc_encoding.rb +126 -126
  42. data/test/tc_encoding_sax.rb +4 -3
  43. data/test/tc_error.rb +14 -15
  44. data/test/tc_html_parser.rb +15 -7
  45. data/test/tc_html_parser_context.rb +1 -2
  46. data/test/tc_namespace.rb +2 -3
  47. data/test/tc_namespaces.rb +5 -6
  48. data/test/tc_node.rb +2 -3
  49. data/test/tc_node_cdata.rb +2 -3
  50. data/test/tc_node_comment.rb +1 -2
  51. data/test/tc_node_copy.rb +1 -2
  52. data/test/tc_node_edit.rb +5 -7
  53. data/test/tc_node_pi.rb +1 -2
  54. data/test/tc_node_text.rb +2 -3
  55. data/test/tc_node_write.rb +2 -3
  56. data/test/tc_node_xlink.rb +1 -2
  57. data/test/tc_parser.rb +18 -24
  58. data/test/tc_parser_context.rb +6 -7
  59. data/test/tc_properties.rb +1 -2
  60. data/test/tc_reader.rb +9 -10
  61. data/test/tc_relaxng.rb +4 -5
  62. data/test/tc_sax_parser.rb +9 -10
  63. data/test/tc_schema.rb +4 -5
  64. data/test/tc_traversal.rb +1 -2
  65. data/test/tc_writer.rb +1 -2
  66. data/test/tc_xinclude.rb +1 -2
  67. data/test/tc_xml.rb +1 -2
  68. data/test/tc_xpath.rb +8 -9
  69. data/test/tc_xpath_context.rb +3 -4
  70. data/test/tc_xpath_expression.rb +3 -4
  71. data/test/tc_xpointer.rb +1 -3
  72. data/test/test_helper.rb +3 -1
  73. data/test/test_suite.rb +0 -1
  74. metadata +47 -11
  75. data/test/etc_doc_to_s.rb +0 -21
  76. data/test/ets_doc_file.rb +0 -17
  77. data/test/ets_doc_to_s.rb +0 -23
  78. data/test/ets_gpx.rb +0 -28
  79. data/test/ets_node_gc.rb +0 -23
  80. data/test/ets_test.xml +0 -2
  81. data/test/ets_tsr.rb +0 -11
@@ -1,260 +1,262 @@
1
- /* Please see the LICENSE file for copyright and distribution information */
2
-
3
- #include <stdarg.h>
4
- #include "ruby_libxml.h"
5
-
6
- /*
7
- * Document-class: LibXML::XML::Encoding
8
- *
9
- * The encoding class exposes the encodings that libxml
10
- * supports via constants.
11
- *
12
- * LibXML converts all data sources to UTF8
13
- * internally before processing them. By default,
14
- * LibXML determines a data source's encoding
15
- * using the algorithm described on its
16
- * website[http://xmlsoft.org/encoding.html].
17
- *
18
- * However, you may override a data source's encoding
19
- * by using the encoding constants defined in this
20
- * module.
21
- *
22
- * Example 1:
23
- *
24
- * io = File.open('some_file', 'rb')
25
- * parser = XML::Parser.io(io, :encoding => XML::Encoding::ISO_8859_1)
26
- * doc = parser.parse
27
- *
28
- * Example 2:
29
- *
30
- * parser = XML::HTMLParser.file("some_file", :encoding => XML::Encoding::ISO_8859_1)
31
- * doc = parser.parse
32
- *
33
- * Example 3:
34
- *
35
- * document = XML::Document.new
36
- * document.encoding = XML::Encoding::ISO_8859_1
37
- * doc << XML::Node.new
38
- */
39
-
40
- VALUE mXMLEncoding;
41
-
42
- /*
43
- * call-seq:
44
- * Encoding.from_s("UTF_8") -> XML::Encoding::UTF_8
45
- *
46
- * Converts an encoding string to an encoding constant
47
- * defined on the XML::Encoding class.
48
- */
49
- static VALUE rxml_encoding_from_s(VALUE klass, VALUE encoding)
50
- {
51
- xmlCharEncoding xencoding;
52
-
53
- if (encoding == Qnil)
54
- return Qnil;
55
-
56
- xencoding = xmlParseCharEncoding(StringValuePtr(encoding));
57
- return INT2NUM(xencoding);
58
- }
59
-
60
- /*
61
- * call-seq:
62
- * Encoding.to_s(XML::Encoding::UTF_8) -> "UTF-8"
63
- *
64
- * Converts an encoding constant defined on the XML::Encoding
65
- * class to its text representation.
66
- */
67
- static VALUE rxml_encoding_to_s(VALUE klass, VALUE encoding)
68
- {
69
- const char* xencoding = xmlGetCharEncodingName(NUM2INT(encoding));
70
-
71
- if (!xencoding)
72
- return Qnil;
73
- else
74
- return rxml_new_cstr(xencoding, xencoding);
75
- }
76
-
77
- #ifdef HAVE_RUBY_ENCODING_H
78
- /*
79
- * Converts an xmlCharEncoding enum value into a Ruby Encoding object (available
80
- * on Ruby 1.9.* and higher).
81
- */
82
- rb_encoding* rxml_xml_encoding_to_rb_encoding(VALUE klass, xmlCharEncoding xmlEncoding)
83
- {
84
- const char* encodingName;
85
-
86
- switch (xmlEncoding)
87
- {
88
- case XML_CHAR_ENCODING_UTF8:
89
- encodingName = "UTF-8";
90
- break;
91
- case XML_CHAR_ENCODING_UTF16LE:
92
- encodingName = "UTF-16LE";
93
- break;
94
- case XML_CHAR_ENCODING_UTF16BE:
95
- encodingName = "UTF-16BE";
96
- break;
97
- case XML_CHAR_ENCODING_UCS4LE:
98
- encodingName = "UCS-4LE";
99
- break;
100
- case XML_CHAR_ENCODING_UCS4BE:
101
- encodingName = "UCS-4BE";
102
- break;
103
- case XML_CHAR_ENCODING_UCS2:
104
- encodingName = "UCS-2";
105
- break;
106
- case XML_CHAR_ENCODING_8859_1:
107
- encodingName = "ISO8859-1";
108
- break;
109
- case XML_CHAR_ENCODING_8859_2:
110
- encodingName = "ISO8859-2";
111
- break;
112
- case XML_CHAR_ENCODING_8859_3:
113
- encodingName = "ISO8859-3";
114
- break;
115
- case XML_CHAR_ENCODING_8859_4:
116
- encodingName = "ISO8859-4";
117
- break;
118
- case XML_CHAR_ENCODING_8859_5:
119
- encodingName = "ISO8859-5";
120
- break;
121
- case XML_CHAR_ENCODING_8859_6:
122
- encodingName = "ISO8859-6";
123
- break;
124
- case XML_CHAR_ENCODING_8859_7:
125
- encodingName = "ISO8859-7";
126
- break;
127
- case XML_CHAR_ENCODING_8859_8:
128
- encodingName = "ISO8859-8";
129
- break;
130
- case XML_CHAR_ENCODING_8859_9:
131
- encodingName = "ISO8859-9";
132
- break;
133
- case XML_CHAR_ENCODING_2022_JP:
134
- encodingName = "ISO-2022-JP";
135
- break;
136
- case XML_CHAR_ENCODING_SHIFT_JIS:
137
- encodingName = "SHIFT-JIS";
138
- break;
139
- case XML_CHAR_ENCODING_EUC_JP:
140
- encodingName = "EUC-JP";
141
- break;
142
- case XML_CHAR_ENCODING_ASCII:
143
- encodingName = "US-ASCII";
144
- break;
145
- default:
146
- /* Covers XML_CHAR_ENCODING_ERROR, XML_CHAR_ENCODING_NONE, XML_CHAR_ENCODING_EBCDIC */
147
- encodingName = "ASCII-8BIT";
148
- break;
149
- }
150
-
151
- return rb_enc_find(encodingName);
152
- }
153
-
154
- /*
155
- * call-seq:
156
- * Input.encoding_to_rb_encoding(Input::ENCODING) -> Encoding
157
- *
158
- * Converts an encoding constant defined on the XML::Encoding
159
- * class to a Ruby encoding object (available on Ruby 1.9.* and higher).
160
- */
161
- VALUE rxml_encoding_to_rb_encoding(VALUE klass, VALUE encoding)
162
- {
163
- xmlCharEncoding xmlEncoding = (xmlCharEncoding)NUM2INT(encoding);
164
- rb_encoding* rbencoding = rxml_xml_encoding_to_rb_encoding(klass, xmlEncoding);
165
- return rb_enc_from_encoding(rbencoding);
166
- }
167
-
168
- rb_encoding* rxml_figure_encoding(const char* xencoding)
169
- {
170
- rb_encoding* result;
171
- if (xencoding)
172
- {
173
- xmlCharEncoding xmlEncoding = xmlParseCharEncoding(xencoding);
174
- result = rxml_xml_encoding_to_rb_encoding(mXMLEncoding, xmlEncoding);
175
- }
176
- else
177
- {
178
- result = rb_utf8_encoding();
179
- }
180
- return result;
181
- }
182
- #endif
183
-
184
- VALUE rxml_new_cstr(const char* xstr, const char* xencoding)
185
- {
186
- #ifdef HAVE_RUBY_ENCODING_H
187
- rb_encoding *rbencoding = rxml_figure_encoding(xencoding);
188
- return rb_external_str_new_with_enc(xstr, strlen(xstr), rbencoding);
189
- #endif
190
- return rb_str_new2(xstr);
191
- }
192
-
193
- VALUE rxml_new_cstr_len(const char* xstr, const int length, const char* xencoding)
194
- {
195
- #ifdef HAVE_RUBY_ENCODING_H
196
- rb_encoding *rbencoding = rxml_figure_encoding(xencoding);
197
- return rb_external_str_new_with_enc(xstr, length, rbencoding);
198
- #endif
199
- return rb_str_new(xstr, length);
200
- }
201
-
202
- void rxml_init_encoding(void)
203
- {
204
- mXMLEncoding = rb_define_module_under(mXML, "Encoding");
205
- rb_define_module_function(mXMLEncoding, "from_s", rxml_encoding_from_s, 1);
206
- rb_define_module_function(mXMLEncoding, "to_s", rxml_encoding_to_s, 1);
207
-
208
- #ifdef HAVE_RUBY_ENCODING_H
209
- // rb_define_module_function(mXMLEncoding, "to_rb_encoding", rxml_encoding_to_rb_encoding, 2);
210
- #endif
211
-
212
- /* -1: No char encoding detected. */
213
- rb_define_const(mXMLEncoding, "ERROR", INT2NUM(XML_CHAR_ENCODING_ERROR));
214
- /* 0: No char encoding detected. */
215
- rb_define_const(mXMLEncoding, "NONE", INT2NUM(XML_CHAR_ENCODING_NONE));
216
- /* 1: UTF-8 */
217
- rb_define_const(mXMLEncoding, "UTF_8", INT2NUM(XML_CHAR_ENCODING_UTF8));
218
- /* 2: UTF-16 little endian. */
219
- rb_define_const(mXMLEncoding, "UTF_16LE", INT2NUM(XML_CHAR_ENCODING_UTF16LE));
220
- /* 3: UTF-16 big endian. */
221
- rb_define_const(mXMLEncoding, "UTF_16BE", INT2NUM(XML_CHAR_ENCODING_UTF16BE));
222
- /* 4: UCS-4 little endian. */
223
- rb_define_const(mXMLEncoding, "UCS_4LE", INT2NUM(XML_CHAR_ENCODING_UCS4LE));
224
- /* 5: UCS-4 big endian. */
225
- rb_define_const(mXMLEncoding, "UCS_4BE", INT2NUM(XML_CHAR_ENCODING_UCS4BE));
226
- /* 6: EBCDIC uh! */
227
- rb_define_const(mXMLEncoding, "EBCDIC", INT2NUM(XML_CHAR_ENCODING_EBCDIC));
228
- /* 7: UCS-4 unusual ordering. */
229
- rb_define_const(mXMLEncoding, "UCS_4_2143", INT2NUM(XML_CHAR_ENCODING_UCS4_2143));
230
- /* 8: UCS-4 unusual ordering. */
231
- rb_define_const(mXMLEncoding, "UCS_4_3412", INT2NUM(XML_CHAR_ENCODING_UCS4_3412));
232
- /* 9: UCS-2. */
233
- rb_define_const(mXMLEncoding, "UCS_2", INT2NUM(XML_CHAR_ENCODING_UCS2));
234
- /* 10: ISO-8859-1 ISO Latin 1. */
235
- rb_define_const(mXMLEncoding, "ISO_8859_1", INT2NUM(XML_CHAR_ENCODING_8859_1));
236
- /* 11: ISO-8859-2 ISO Latin 2. */
237
- rb_define_const(mXMLEncoding, "ISO_8859_2", INT2NUM(XML_CHAR_ENCODING_8859_2));
238
- /* 12: ISO-8859-3. */
239
- rb_define_const(mXMLEncoding, "ISO_8859_3", INT2NUM(XML_CHAR_ENCODING_8859_3));
240
- /* 13: ISO-8859-4. */
241
- rb_define_const(mXMLEncoding, "ISO_8859_4", INT2NUM(XML_CHAR_ENCODING_8859_4));
242
- /* 14: ISO-8859-5. */
243
- rb_define_const(mXMLEncoding, "ISO_8859_5", INT2NUM(XML_CHAR_ENCODING_8859_5));
244
- /* 15: ISO-8859-6. */
245
- rb_define_const(mXMLEncoding, "ISO_8859_6", INT2NUM(XML_CHAR_ENCODING_8859_6));
246
- /* 16: ISO-8859-7. */
247
- rb_define_const(mXMLEncoding, "ISO_8859_7", INT2NUM(XML_CHAR_ENCODING_8859_7));
248
- /* 17: ISO-8859-8. */
249
- rb_define_const(mXMLEncoding, "ISO_8859_8", INT2NUM(XML_CHAR_ENCODING_8859_8));
250
- /* 18: ISO-8859-9. */
251
- rb_define_const(mXMLEncoding, "ISO_8859_9", INT2NUM(XML_CHAR_ENCODING_8859_9));
252
- /* 19: ISO-2022-JP. */
253
- rb_define_const(mXMLEncoding, "ISO_2022_JP", INT2NUM(XML_CHAR_ENCODING_2022_JP));
254
- /* 20: Shift_JIS. */
255
- rb_define_const(mXMLEncoding, "SHIFT_JIS", INT2NUM(XML_CHAR_ENCODING_SHIFT_JIS));
256
- /* 21: EUC-JP. */
257
- rb_define_const(mXMLEncoding, "EUC_JP", INT2NUM(XML_CHAR_ENCODING_EUC_JP));
258
- /* 22: pure ASCII. */
259
- rb_define_const(mXMLEncoding, "ASCII", INT2NUM(XML_CHAR_ENCODING_ASCII));
260
- }
1
+ /* Please see the LICENSE file for copyright and distribution information */
2
+
3
+ #include <stdarg.h>
4
+ #include "ruby_libxml.h"
5
+
6
+ /*
7
+ * Document-class: LibXML::XML::Encoding
8
+ *
9
+ * The encoding class exposes the encodings that libxml
10
+ * supports via constants.
11
+ *
12
+ * LibXML converts all data sources to UTF8
13
+ * internally before processing them. By default,
14
+ * LibXML determines a data source's encoding
15
+ * using the algorithm described on its
16
+ * website[http://xmlsoft.org/encoding.html].
17
+ *
18
+ * However, you may override a data source's encoding
19
+ * by using the encoding constants defined in this
20
+ * module.
21
+ *
22
+ * Example 1:
23
+ *
24
+ * io = File.open('some_file', 'rb')
25
+ * parser = XML::Parser.io(io, :encoding => XML::Encoding::ISO_8859_1)
26
+ * doc = parser.parse
27
+ *
28
+ * Example 2:
29
+ *
30
+ * parser = XML::HTMLParser.file("some_file", :encoding => XML::Encoding::ISO_8859_1)
31
+ * doc = parser.parse
32
+ *
33
+ * Example 3:
34
+ *
35
+ * document = XML::Document.new
36
+ * document.encoding = XML::Encoding::ISO_8859_1
37
+ * doc << XML::Node.new
38
+ */
39
+
40
+ VALUE mXMLEncoding;
41
+
42
+ /*
43
+ * call-seq:
44
+ * Encoding.from_s("UTF_8") -> XML::Encoding::UTF_8
45
+ *
46
+ * Converts an encoding string to an encoding constant
47
+ * defined on the XML::Encoding class.
48
+ */
49
+ static VALUE rxml_encoding_from_s(VALUE klass, VALUE encoding)
50
+ {
51
+ xmlCharEncoding xencoding;
52
+
53
+ if (encoding == Qnil)
54
+ return Qnil;
55
+
56
+ xencoding = xmlParseCharEncoding(StringValuePtr(encoding));
57
+ return INT2NUM(xencoding);
58
+ }
59
+
60
+ /*
61
+ * call-seq:
62
+ * Encoding.to_s(XML::Encoding::UTF_8) -> "UTF-8"
63
+ *
64
+ * Converts an encoding constant defined on the XML::Encoding
65
+ * class to its text representation.
66
+ */
67
+ static VALUE rxml_encoding_to_s(VALUE klass, VALUE encoding)
68
+ {
69
+ const xmlChar* xencoding = (const xmlChar*)xmlGetCharEncodingName(NUM2INT(encoding));
70
+
71
+ if (!xencoding)
72
+ return Qnil;
73
+ else
74
+ return rxml_new_cstr(xencoding, xencoding);
75
+ }
76
+
77
+ #ifdef HAVE_RUBY_ENCODING_H
78
+ /*
79
+ * Converts an xmlCharEncoding enum value into a Ruby Encoding object (available
80
+ * on Ruby 1.9.* and higher).
81
+ */
82
+ rb_encoding* rxml_xml_encoding_to_rb_encoding(VALUE klass, xmlCharEncoding xmlEncoding)
83
+ {
84
+ const char* encodingName;
85
+
86
+ switch (xmlEncoding)
87
+ {
88
+ case XML_CHAR_ENCODING_UTF8:
89
+ encodingName = "UTF-8";
90
+ break;
91
+ case XML_CHAR_ENCODING_UTF16LE:
92
+ encodingName = "UTF-16LE";
93
+ break;
94
+ case XML_CHAR_ENCODING_UTF16BE:
95
+ encodingName = "UTF-16BE";
96
+ break;
97
+ case XML_CHAR_ENCODING_UCS4LE:
98
+ encodingName = "UCS-4LE";
99
+ break;
100
+ case XML_CHAR_ENCODING_UCS4BE:
101
+ encodingName = "UCS-4BE";
102
+ break;
103
+ case XML_CHAR_ENCODING_UCS2:
104
+ encodingName = "UCS-2";
105
+ break;
106
+ case XML_CHAR_ENCODING_8859_1:
107
+ encodingName = "ISO8859-1";
108
+ break;
109
+ case XML_CHAR_ENCODING_8859_2:
110
+ encodingName = "ISO8859-2";
111
+ break;
112
+ case XML_CHAR_ENCODING_8859_3:
113
+ encodingName = "ISO8859-3";
114
+ break;
115
+ case XML_CHAR_ENCODING_8859_4:
116
+ encodingName = "ISO8859-4";
117
+ break;
118
+ case XML_CHAR_ENCODING_8859_5:
119
+ encodingName = "ISO8859-5";
120
+ break;
121
+ case XML_CHAR_ENCODING_8859_6:
122
+ encodingName = "ISO8859-6";
123
+ break;
124
+ case XML_CHAR_ENCODING_8859_7:
125
+ encodingName = "ISO8859-7";
126
+ break;
127
+ case XML_CHAR_ENCODING_8859_8:
128
+ encodingName = "ISO8859-8";
129
+ break;
130
+ case XML_CHAR_ENCODING_8859_9:
131
+ encodingName = "ISO8859-9";
132
+ break;
133
+ case XML_CHAR_ENCODING_2022_JP:
134
+ encodingName = "ISO-2022-JP";
135
+ break;
136
+ case XML_CHAR_ENCODING_SHIFT_JIS:
137
+ encodingName = "SHIFT-JIS";
138
+ break;
139
+ case XML_CHAR_ENCODING_EUC_JP:
140
+ encodingName = "EUC-JP";
141
+ break;
142
+ case XML_CHAR_ENCODING_ASCII:
143
+ encodingName = "US-ASCII";
144
+ break;
145
+ default:
146
+ /* Covers XML_CHAR_ENCODING_ERROR, XML_CHAR_ENCODING_NONE, XML_CHAR_ENCODING_EBCDIC */
147
+ encodingName = "ASCII-8BIT";
148
+ break;
149
+ }
150
+
151
+ return rb_enc_find(encodingName);
152
+ }
153
+
154
+ /*
155
+ * call-seq:
156
+ * Input.encoding_to_rb_encoding(Input::ENCODING) -> Encoding
157
+ *
158
+ * Converts an encoding constant defined on the XML::Encoding
159
+ * class to a Ruby encoding object (available on Ruby 1.9.* and higher).
160
+ */
161
+ VALUE rxml_encoding_to_rb_encoding(VALUE klass, VALUE encoding)
162
+ {
163
+ xmlCharEncoding xmlEncoding = (xmlCharEncoding)NUM2INT(encoding);
164
+ rb_encoding* rbencoding = rxml_xml_encoding_to_rb_encoding(klass, xmlEncoding);
165
+ return rb_enc_from_encoding(rbencoding);
166
+ }
167
+
168
+ rb_encoding* rxml_figure_encoding(const xmlChar* xencoding)
169
+ {
170
+ rb_encoding* result;
171
+ if (xencoding)
172
+ {
173
+ xmlCharEncoding xmlEncoding = xmlParseCharEncoding((const char*)xencoding);
174
+ result = rxml_xml_encoding_to_rb_encoding(mXMLEncoding, xmlEncoding);
175
+ }
176
+ else
177
+ {
178
+ result = rb_utf8_encoding();
179
+ }
180
+ return result;
181
+ }
182
+ #endif
183
+
184
+ VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding)
185
+ {
186
+ #ifdef HAVE_RUBY_ENCODING_H
187
+ rb_encoding *rbencoding = rxml_figure_encoding(xencoding);
188
+ return rb_external_str_new_with_enc((const char*)xstr, strlen((const char*)xstr), rbencoding);
189
+ #else
190
+ return rb_str_new2((const char*)xstr);
191
+ #endif
192
+ }
193
+
194
+ VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding)
195
+ {
196
+ #ifdef HAVE_RUBY_ENCODING_H
197
+ rb_encoding *rbencoding = rxml_figure_encoding(xencoding);
198
+ return rb_external_str_new_with_enc((const char*)xstr, length, rbencoding);
199
+ #else
200
+ return rb_str_new((const char*)xstr, length);
201
+ #endif
202
+ }
203
+
204
+ void rxml_init_encoding(void)
205
+ {
206
+ mXMLEncoding = rb_define_module_under(mXML, "Encoding");
207
+ rb_define_module_function(mXMLEncoding, "from_s", rxml_encoding_from_s, 1);
208
+ rb_define_module_function(mXMLEncoding, "to_s", rxml_encoding_to_s, 1);
209
+
210
+ #ifdef HAVE_RUBY_ENCODING_H
211
+ // rb_define_module_function(mXMLEncoding, "to_rb_encoding", rxml_encoding_to_rb_encoding, 2);
212
+ #endif
213
+
214
+ /* -1: No char encoding detected. */
215
+ rb_define_const(mXMLEncoding, "ERROR", INT2NUM(XML_CHAR_ENCODING_ERROR));
216
+ /* 0: No char encoding detected. */
217
+ rb_define_const(mXMLEncoding, "NONE", INT2NUM(XML_CHAR_ENCODING_NONE));
218
+ /* 1: UTF-8 */
219
+ rb_define_const(mXMLEncoding, "UTF_8", INT2NUM(XML_CHAR_ENCODING_UTF8));
220
+ /* 2: UTF-16 little endian. */
221
+ rb_define_const(mXMLEncoding, "UTF_16LE", INT2NUM(XML_CHAR_ENCODING_UTF16LE));
222
+ /* 3: UTF-16 big endian. */
223
+ rb_define_const(mXMLEncoding, "UTF_16BE", INT2NUM(XML_CHAR_ENCODING_UTF16BE));
224
+ /* 4: UCS-4 little endian. */
225
+ rb_define_const(mXMLEncoding, "UCS_4LE", INT2NUM(XML_CHAR_ENCODING_UCS4LE));
226
+ /* 5: UCS-4 big endian. */
227
+ rb_define_const(mXMLEncoding, "UCS_4BE", INT2NUM(XML_CHAR_ENCODING_UCS4BE));
228
+ /* 6: EBCDIC uh! */
229
+ rb_define_const(mXMLEncoding, "EBCDIC", INT2NUM(XML_CHAR_ENCODING_EBCDIC));
230
+ /* 7: UCS-4 unusual ordering. */
231
+ rb_define_const(mXMLEncoding, "UCS_4_2143", INT2NUM(XML_CHAR_ENCODING_UCS4_2143));
232
+ /* 8: UCS-4 unusual ordering. */
233
+ rb_define_const(mXMLEncoding, "UCS_4_3412", INT2NUM(XML_CHAR_ENCODING_UCS4_3412));
234
+ /* 9: UCS-2. */
235
+ rb_define_const(mXMLEncoding, "UCS_2", INT2NUM(XML_CHAR_ENCODING_UCS2));
236
+ /* 10: ISO-8859-1 ISO Latin 1. */
237
+ rb_define_const(mXMLEncoding, "ISO_8859_1", INT2NUM(XML_CHAR_ENCODING_8859_1));
238
+ /* 11: ISO-8859-2 ISO Latin 2. */
239
+ rb_define_const(mXMLEncoding, "ISO_8859_2", INT2NUM(XML_CHAR_ENCODING_8859_2));
240
+ /* 12: ISO-8859-3. */
241
+ rb_define_const(mXMLEncoding, "ISO_8859_3", INT2NUM(XML_CHAR_ENCODING_8859_3));
242
+ /* 13: ISO-8859-4. */
243
+ rb_define_const(mXMLEncoding, "ISO_8859_4", INT2NUM(XML_CHAR_ENCODING_8859_4));
244
+ /* 14: ISO-8859-5. */
245
+ rb_define_const(mXMLEncoding, "ISO_8859_5", INT2NUM(XML_CHAR_ENCODING_8859_5));
246
+ /* 15: ISO-8859-6. */
247
+ rb_define_const(mXMLEncoding, "ISO_8859_6", INT2NUM(XML_CHAR_ENCODING_8859_6));
248
+ /* 16: ISO-8859-7. */
249
+ rb_define_const(mXMLEncoding, "ISO_8859_7", INT2NUM(XML_CHAR_ENCODING_8859_7));
250
+ /* 17: ISO-8859-8. */
251
+ rb_define_const(mXMLEncoding, "ISO_8859_8", INT2NUM(XML_CHAR_ENCODING_8859_8));
252
+ /* 18: ISO-8859-9. */
253
+ rb_define_const(mXMLEncoding, "ISO_8859_9", INT2NUM(XML_CHAR_ENCODING_8859_9));
254
+ /* 19: ISO-2022-JP. */
255
+ rb_define_const(mXMLEncoding, "ISO_2022_JP", INT2NUM(XML_CHAR_ENCODING_2022_JP));
256
+ /* 20: Shift_JIS. */
257
+ rb_define_const(mXMLEncoding, "SHIFT_JIS", INT2NUM(XML_CHAR_ENCODING_SHIFT_JIS));
258
+ /* 21: EUC-JP. */
259
+ rb_define_const(mXMLEncoding, "EUC_JP", INT2NUM(XML_CHAR_ENCODING_EUC_JP));
260
+ /* 22: pure ASCII. */
261
+ rb_define_const(mXMLEncoding, "ASCII", INT2NUM(XML_CHAR_ENCODING_ASCII));
262
+ }