libxml-ruby 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/HISTORY +15 -0
- data/README.rdoc +7 -7
- data/Rakefile +80 -78
- data/ext/libxml/extconf.h +4 -0
- data/ext/libxml/extconf.rb +57 -116
- data/ext/libxml/libxml.c +4 -0
- data/ext/libxml/ruby_xml.c +977 -893
- data/ext/libxml/ruby_xml.h +20 -10
- data/ext/libxml/ruby_xml_attr.c +333 -333
- data/ext/libxml/ruby_xml_attr_decl.c +2 -2
- data/ext/libxml/ruby_xml_cbg.c +85 -85
- data/ext/libxml/ruby_xml_document.c +1133 -1147
- data/ext/libxml/ruby_xml_dtd.c +261 -268
- data/ext/libxml/ruby_xml_encoding.c +262 -260
- data/ext/libxml/ruby_xml_encoding.h +19 -19
- data/ext/libxml/ruby_xml_html_parser_context.c +337 -338
- data/ext/libxml/ruby_xml_input_cbg.c +191 -191
- data/ext/libxml/ruby_xml_io.c +52 -50
- data/ext/libxml/ruby_xml_namespace.c +2 -2
- data/ext/libxml/ruby_xml_node.c +1446 -1452
- data/ext/libxml/ruby_xml_parser_context.c +999 -1001
- data/ext/libxml/ruby_xml_reader.c +1226 -1228
- data/ext/libxml/ruby_xml_relaxng.c +110 -111
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -328
- data/ext/libxml/ruby_xml_schema.c +300 -301
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/ext/libxml/ruby_xml_writer.c +14 -15
- data/ext/libxml/ruby_xml_xpath.c +188 -188
- data/ext/libxml/ruby_xml_xpath_context.c +360 -361
- data/ext/libxml/ruby_xml_xpath_object.c +335 -335
- data/libxml-ruby.gemspec +47 -44
- data/test/tc_attr.rb +5 -7
- data/test/tc_attr_decl.rb +5 -6
- data/test/tc_attributes.rb +1 -2
- data/test/tc_canonicalize.rb +1 -2
- data/test/tc_deprecated_require.rb +1 -2
- data/test/tc_document.rb +4 -5
- data/test/tc_document_write.rb +2 -3
- data/test/tc_dtd.rb +4 -5
- data/test/tc_encoding.rb +126 -126
- data/test/tc_encoding_sax.rb +4 -3
- data/test/tc_error.rb +14 -15
- data/test/tc_html_parser.rb +15 -7
- data/test/tc_html_parser_context.rb +1 -2
- data/test/tc_namespace.rb +2 -3
- data/test/tc_namespaces.rb +5 -6
- data/test/tc_node.rb +2 -3
- data/test/tc_node_cdata.rb +2 -3
- data/test/tc_node_comment.rb +1 -2
- data/test/tc_node_copy.rb +1 -2
- data/test/tc_node_edit.rb +5 -7
- data/test/tc_node_pi.rb +1 -2
- data/test/tc_node_text.rb +2 -3
- data/test/tc_node_write.rb +2 -3
- data/test/tc_node_xlink.rb +1 -2
- data/test/tc_parser.rb +18 -24
- data/test/tc_parser_context.rb +6 -7
- data/test/tc_properties.rb +1 -2
- data/test/tc_reader.rb +9 -10
- data/test/tc_relaxng.rb +4 -5
- data/test/tc_sax_parser.rb +9 -10
- data/test/tc_schema.rb +4 -5
- data/test/tc_traversal.rb +1 -2
- data/test/tc_writer.rb +1 -2
- data/test/tc_xinclude.rb +1 -2
- data/test/tc_xml.rb +1 -2
- data/test/tc_xpath.rb +8 -9
- data/test/tc_xpath_context.rb +3 -4
- data/test/tc_xpath_expression.rb +3 -4
- data/test/tc_xpointer.rb +1 -3
- data/test/test_helper.rb +3 -1
- data/test/test_suite.rb +0 -1
- metadata +47 -11
- data/test/etc_doc_to_s.rb +0 -21
- data/test/ets_doc_file.rb +0 -17
- data/test/ets_doc_to_s.rb +0 -23
- data/test/ets_gpx.rb +0 -28
- data/test/ets_node_gc.rb +0 -23
- data/test/ets_test.xml +0 -2
- 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
|
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
|
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
|
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
|
-
#
|
190
|
-
return rb_str_new2(xstr);
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
#
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
/*
|
215
|
-
rb_define_const(mXMLEncoding, "
|
216
|
-
/*
|
217
|
-
rb_define_const(mXMLEncoding, "
|
218
|
-
/*
|
219
|
-
rb_define_const(mXMLEncoding, "
|
220
|
-
/*
|
221
|
-
rb_define_const(mXMLEncoding, "
|
222
|
-
/*
|
223
|
-
rb_define_const(mXMLEncoding, "
|
224
|
-
/*
|
225
|
-
rb_define_const(mXMLEncoding, "
|
226
|
-
/*
|
227
|
-
rb_define_const(mXMLEncoding, "
|
228
|
-
/*
|
229
|
-
rb_define_const(mXMLEncoding, "
|
230
|
-
/*
|
231
|
-
rb_define_const(mXMLEncoding, "
|
232
|
-
/*
|
233
|
-
rb_define_const(mXMLEncoding, "
|
234
|
-
/*
|
235
|
-
rb_define_const(mXMLEncoding, "
|
236
|
-
/*
|
237
|
-
rb_define_const(mXMLEncoding, "
|
238
|
-
/*
|
239
|
-
rb_define_const(mXMLEncoding, "
|
240
|
-
/*
|
241
|
-
rb_define_const(mXMLEncoding, "
|
242
|
-
/*
|
243
|
-
rb_define_const(mXMLEncoding, "
|
244
|
-
/*
|
245
|
-
rb_define_const(mXMLEncoding, "
|
246
|
-
/*
|
247
|
-
rb_define_const(mXMLEncoding, "
|
248
|
-
/*
|
249
|
-
rb_define_const(mXMLEncoding, "
|
250
|
-
/*
|
251
|
-
rb_define_const(mXMLEncoding, "
|
252
|
-
/*
|
253
|
-
rb_define_const(mXMLEncoding, "
|
254
|
-
/*
|
255
|
-
rb_define_const(mXMLEncoding, "
|
256
|
-
/*
|
257
|
-
rb_define_const(mXMLEncoding, "
|
258
|
-
/*
|
259
|
-
rb_define_const(mXMLEncoding, "
|
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
|
+
}
|