libxml-ruby 2.0.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +516 -0
- data/LICENSE +23 -0
- data/MANIFEST +165 -0
- data/README.rdoc +161 -0
- data/Rakefile +82 -0
- data/ext/libxml/extconf.rb +122 -0
- data/ext/libxml/libxml.c +93 -0
- data/ext/libxml/ruby_libxml.h +101 -0
- data/ext/libxml/ruby_xml.c +893 -0
- data/ext/libxml/ruby_xml.h +10 -0
- data/ext/libxml/ruby_xml_attr.c +352 -0
- data/ext/libxml/ruby_xml_attr.h +14 -0
- data/ext/libxml/ruby_xml_attr_decl.c +171 -0
- data/ext/libxml/ruby_xml_attr_decl.h +13 -0
- data/ext/libxml/ruby_xml_attributes.c +277 -0
- data/ext/libxml/ruby_xml_attributes.h +17 -0
- data/ext/libxml/ruby_xml_cbg.c +85 -0
- data/ext/libxml/ruby_xml_document.c +958 -0
- data/ext/libxml/ruby_xml_document.h +17 -0
- data/ext/libxml/ruby_xml_dtd.c +257 -0
- data/ext/libxml/ruby_xml_dtd.h +9 -0
- data/ext/libxml/ruby_xml_encoding.c +221 -0
- data/ext/libxml/ruby_xml_encoding.h +16 -0
- data/ext/libxml/ruby_xml_error.c +1004 -0
- data/ext/libxml/ruby_xml_error.h +14 -0
- data/ext/libxml/ruby_xml_html_parser.c +92 -0
- data/ext/libxml/ruby_xml_html_parser.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_input_cbg.c +191 -0
- data/ext/libxml/ruby_xml_input_cbg.h +20 -0
- data/ext/libxml/ruby_xml_io.c +30 -0
- data/ext/libxml/ruby_xml_io.h +9 -0
- data/ext/libxml/ruby_xml_namespace.c +170 -0
- data/ext/libxml/ruby_xml_namespace.h +12 -0
- data/ext/libxml/ruby_xml_namespaces.c +295 -0
- data/ext/libxml/ruby_xml_namespaces.h +11 -0
- data/ext/libxml/ruby_xml_node.c +1386 -0
- data/ext/libxml/ruby_xml_node.h +13 -0
- data/ext/libxml/ruby_xml_parser.c +94 -0
- data/ext/libxml/ruby_xml_parser.h +14 -0
- data/ext/libxml/ruby_xml_parser_context.c +982 -0
- data/ext/libxml/ruby_xml_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_parser_options.c +68 -0
- data/ext/libxml/ruby_xml_parser_options.h +14 -0
- data/ext/libxml/ruby_xml_reader.c +1057 -0
- data/ext/libxml/ruby_xml_reader.h +14 -0
- data/ext/libxml/ruby_xml_relaxng.c +111 -0
- data/ext/libxml/ruby_xml_relaxng.h +10 -0
- data/ext/libxml/ruby_xml_sax2_handler.c +334 -0
- data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
- data/ext/libxml/ruby_xml_sax_parser.c +136 -0
- data/ext/libxml/ruby_xml_sax_parser.h +12 -0
- data/ext/libxml/ruby_xml_schema.c +159 -0
- data/ext/libxml/ruby_xml_schema.h +11 -0
- data/ext/libxml/ruby_xml_version.h +9 -0
- data/ext/libxml/ruby_xml_xinclude.c +18 -0
- data/ext/libxml/ruby_xml_xinclude.h +13 -0
- data/ext/libxml/ruby_xml_xpath.c +107 -0
- data/ext/libxml/ruby_xml_xpath.h +12 -0
- data/ext/libxml/ruby_xml_xpath_context.c +390 -0
- data/ext/libxml/ruby_xml_xpath_context.h +11 -0
- data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
- data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
- data/ext/libxml/ruby_xml_xpath_object.c +336 -0
- data/ext/libxml/ruby_xml_xpath_object.h +19 -0
- data/ext/libxml/ruby_xml_xpointer.c +101 -0
- data/ext/libxml/ruby_xml_xpointer.h +13 -0
- data/ext/mingw/Rakefile +34 -0
- data/ext/mingw/build.rake +41 -0
- data/ext/vc/libxml_ruby.sln +26 -0
- data/lib/1.8/libxml_ruby.so +0 -0
- data/lib/1.9/libxml_ruby.so +0 -0
- data/lib/libxml.rb +30 -0
- data/lib/libxml/attr.rb +113 -0
- data/lib/libxml/attr_decl.rb +80 -0
- data/lib/libxml/attributes.rb +14 -0
- data/lib/libxml/document.rb +192 -0
- data/lib/libxml/error.rb +90 -0
- data/lib/libxml/hpricot.rb +78 -0
- data/lib/libxml/html_parser.rb +96 -0
- data/lib/libxml/namespace.rb +62 -0
- data/lib/libxml/namespaces.rb +38 -0
- data/lib/libxml/node.rb +399 -0
- data/lib/libxml/ns.rb +22 -0
- data/lib/libxml/parser.rb +367 -0
- data/lib/libxml/properties.rb +23 -0
- data/lib/libxml/reader.rb +29 -0
- data/lib/libxml/sax_callbacks.rb +180 -0
- data/lib/libxml/sax_parser.rb +58 -0
- data/lib/libxml/tree.rb +29 -0
- data/lib/libxml/xpath_object.rb +16 -0
- data/lib/xml.rb +16 -0
- data/lib/xml/libxml.rb +10 -0
- data/libxml-ruby.gemspec +50 -0
- data/script/benchmark/depixelate +634 -0
- data/script/benchmark/hamlet.xml +9055 -0
- data/script/benchmark/parsecount +170 -0
- data/script/benchmark/sock_entries.xml +507 -0
- data/script/benchmark/throughput +41 -0
- data/script/test +6 -0
- data/setup.rb +1585 -0
- data/test/etc_doc_to_s.rb +21 -0
- data/test/ets_doc_file.rb +17 -0
- data/test/ets_doc_to_s.rb +23 -0
- data/test/ets_gpx.rb +28 -0
- data/test/ets_node_gc.rb +23 -0
- data/test/ets_test.xml +2 -0
- data/test/ets_tsr.rb +11 -0
- data/test/model/atom.xml +13 -0
- data/test/model/bands.iso-8859-1.xml +5 -0
- data/test/model/bands.utf-8.xml +5 -0
- data/test/model/bands.xml +5 -0
- data/test/model/books.xml +146 -0
- data/test/model/merge_bug_data.xml +58 -0
- data/test/model/ruby-lang.html +238 -0
- data/test/model/rubynet.xml +79 -0
- data/test/model/rubynet_project +1 -0
- data/test/model/shiporder.rnc +28 -0
- data/test/model/shiporder.rng +86 -0
- data/test/model/shiporder.xml +23 -0
- data/test/model/shiporder.xsd +31 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/rb-magic-comment.rb +33 -0
- data/test/tc_attr.rb +181 -0
- data/test/tc_attr_decl.rb +133 -0
- data/test/tc_attributes.rb +135 -0
- data/test/tc_deprecated_require.rb +13 -0
- data/test/tc_document.rb +119 -0
- data/test/tc_document_write.rb +187 -0
- data/test/tc_dtd.rb +125 -0
- data/test/tc_error.rb +138 -0
- data/test/tc_html_parser.rb +140 -0
- data/test/tc_namespace.rb +62 -0
- data/test/tc_namespaces.rb +177 -0
- data/test/tc_node.rb +258 -0
- data/test/tc_node_cdata.rb +51 -0
- data/test/tc_node_comment.rb +33 -0
- data/test/tc_node_copy.rb +42 -0
- data/test/tc_node_edit.rb +160 -0
- data/test/tc_node_text.rb +71 -0
- data/test/tc_node_write.rb +108 -0
- data/test/tc_node_xlink.rb +29 -0
- data/test/tc_parser.rb +336 -0
- data/test/tc_parser_context.rb +189 -0
- data/test/tc_properties.rb +39 -0
- data/test/tc_reader.rb +298 -0
- data/test/tc_relaxng.rb +54 -0
- data/test/tc_sax_parser.rb +276 -0
- data/test/tc_schema.rb +53 -0
- data/test/tc_traversal.rb +222 -0
- data/test/tc_xinclude.rb +21 -0
- data/test/tc_xml.rb +226 -0
- data/test/tc_xpath.rb +195 -0
- data/test/tc_xpath_context.rb +80 -0
- data/test/tc_xpath_expression.rb +38 -0
- data/test/tc_xpointer.rb +74 -0
- data/test/test_helper.rb +14 -0
- data/test/test_suite.rb +39 -0
- metadata +254 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
/* $Id$ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#ifndef __RXML_DOCUMENT__
|
6
|
+
#define __RXML_DOCUMENT__
|
7
|
+
|
8
|
+
extern VALUE cXMLDocument;
|
9
|
+
|
10
|
+
void rxml_init_document();
|
11
|
+
|
12
|
+
|
13
|
+
#if defined(_WIN32)
|
14
|
+
__declspec(dllexport)
|
15
|
+
#endif
|
16
|
+
VALUE rxml_document_wrap(xmlDocPtr xnode);
|
17
|
+
#endif
|
@@ -0,0 +1,257 @@
|
|
1
|
+
#include "ruby_libxml.h"
|
2
|
+
#include "ruby_xml_dtd.h"
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Document-class: LibXML::XML::Dtd
|
6
|
+
*
|
7
|
+
* The XML::Dtd class is used to prepare DTD's for validation of xml
|
8
|
+
* documents.
|
9
|
+
*
|
10
|
+
* DTDs can be created from a string or a pair of public and system identifiers.
|
11
|
+
* Once a Dtd object is instantiated, an XML document can be validated by the
|
12
|
+
* XML::Document#validate method providing the XML::Dtd object as parameeter.
|
13
|
+
* The method will raise an exception if the document is
|
14
|
+
* not valid.
|
15
|
+
*
|
16
|
+
* Basic usage:
|
17
|
+
*
|
18
|
+
* # parse DTD
|
19
|
+
* dtd = XML::Dtd.new(<<EOF)
|
20
|
+
* <!ELEMENT root (item*) >
|
21
|
+
* <!ELEMENT item (#PCDATA) >
|
22
|
+
* EOF
|
23
|
+
*
|
24
|
+
* # parse xml document to be validated
|
25
|
+
* instance = XML::Document.file('instance.xml')
|
26
|
+
*
|
27
|
+
* # validate
|
28
|
+
* instance.validate(dtd)
|
29
|
+
*/
|
30
|
+
|
31
|
+
VALUE cXMLDtd;
|
32
|
+
|
33
|
+
void rxml_dtd_free(xmlDtdPtr xdtd)
|
34
|
+
{
|
35
|
+
/* Set _private to NULL so that we won't reuse the
|
36
|
+
same, freed, Ruby wrapper object later.*/
|
37
|
+
xdtd->_private = NULL;
|
38
|
+
|
39
|
+
if (xdtd->doc == NULL && xdtd->parent == NULL)
|
40
|
+
xmlFreeDtd(xdtd);
|
41
|
+
}
|
42
|
+
|
43
|
+
void rxml_dtd_mark(xmlDtdPtr xdtd)
|
44
|
+
{
|
45
|
+
if (xdtd == NULL)
|
46
|
+
return;
|
47
|
+
|
48
|
+
if (xdtd->_private == NULL)
|
49
|
+
{
|
50
|
+
rb_warning("XmlNode is not bound! (%s:%d)", __FILE__, __LINE__);
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
|
54
|
+
rxml_node_mark((xmlNodePtr) xdtd);
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
static VALUE rxml_dtd_alloc(VALUE klass)
|
59
|
+
{
|
60
|
+
return Data_Wrap_Struct(klass, rxml_dtd_mark, rxml_dtd_free, NULL);
|
61
|
+
}
|
62
|
+
|
63
|
+
VALUE rxml_dtd_wrap(xmlDtdPtr xdtd)
|
64
|
+
{
|
65
|
+
VALUE result;
|
66
|
+
|
67
|
+
// This node is already wrapped
|
68
|
+
if (xdtd->_private != NULL)
|
69
|
+
return (VALUE) xdtd->_private;
|
70
|
+
|
71
|
+
result = Data_Wrap_Struct(cXMLDtd, NULL, NULL, xdtd);
|
72
|
+
|
73
|
+
xdtd->_private = (void*) result;
|
74
|
+
|
75
|
+
return result;
|
76
|
+
}
|
77
|
+
|
78
|
+
/*
|
79
|
+
* call-seq:
|
80
|
+
* dtd.external_id -> "string"
|
81
|
+
*
|
82
|
+
* Obtain this dtd's external identifer (for a PUBLIC DTD).
|
83
|
+
*/
|
84
|
+
static VALUE rxml_dtd_external_id_get(VALUE self)
|
85
|
+
{
|
86
|
+
xmlDtdPtr xdtd;
|
87
|
+
Data_Get_Struct(self, xmlDtd, xdtd);
|
88
|
+
|
89
|
+
|
90
|
+
if (xdtd->ExternalID == NULL)
|
91
|
+
return (Qnil);
|
92
|
+
else
|
93
|
+
return (rxml_str_new2((const char*) xdtd->ExternalID, xdtd->doc ? xdtd->doc->encoding : NULL));
|
94
|
+
}
|
95
|
+
|
96
|
+
/*
|
97
|
+
* call-seq:
|
98
|
+
* dtd.name -> "string"
|
99
|
+
*
|
100
|
+
* Obtain this dtd's name.
|
101
|
+
*/
|
102
|
+
static VALUE rxml_dtd_name_get(VALUE self)
|
103
|
+
{
|
104
|
+
xmlDtdPtr xdtd;
|
105
|
+
Data_Get_Struct(self, xmlDtd, xdtd);
|
106
|
+
|
107
|
+
|
108
|
+
if (xdtd->name == NULL)
|
109
|
+
return (Qnil);
|
110
|
+
else
|
111
|
+
return (rxml_str_new2((const char*) xdtd->name, xdtd->doc ? xdtd->doc->encoding : NULL));
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
/*
|
116
|
+
* call-seq:
|
117
|
+
* dtd.uri -> "string"
|
118
|
+
*
|
119
|
+
* Obtain this dtd's URI (for a SYSTEM or PUBLIC DTD).
|
120
|
+
*/
|
121
|
+
static VALUE rxml_dtd_uri_get(VALUE self)
|
122
|
+
{
|
123
|
+
xmlDtdPtr xdtd;
|
124
|
+
Data_Get_Struct(self, xmlDtd, xdtd);
|
125
|
+
|
126
|
+
|
127
|
+
if (xdtd->SystemID == NULL)
|
128
|
+
return (Qnil);
|
129
|
+
else
|
130
|
+
return (rxml_str_new2((const char*) xdtd->SystemID, xdtd->doc ? xdtd->doc->encoding : NULL));
|
131
|
+
}
|
132
|
+
|
133
|
+
/*
|
134
|
+
* call-seq:
|
135
|
+
* XML::Dtd.new("DTD string") -> dtd
|
136
|
+
* XML::Dtd.new("public", "system") -> dtd
|
137
|
+
* XML::Dtd.new("name", "public", "system", document) -> external subset dtd
|
138
|
+
* XML::Dtd.new("name", "public", "system", document, false) -> internal subset dtd
|
139
|
+
* XML::Dtd.new("name", "public", "system", document, true) -> internal subset dtd
|
140
|
+
*
|
141
|
+
* Create a new Dtd from the specified public and system
|
142
|
+
* identifiers.
|
143
|
+
*/
|
144
|
+
static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
|
145
|
+
{
|
146
|
+
VALUE external, system, dtd_string;
|
147
|
+
xmlParserInputBufferPtr buffer;
|
148
|
+
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
|
149
|
+
xmlChar *new_string;
|
150
|
+
xmlDtdPtr xdtd;
|
151
|
+
|
152
|
+
// 1 argument -- string --> parsujeme jako dtd
|
153
|
+
// 2 arguments -- public, system --> bude se hledat
|
154
|
+
// 3 arguments -- public, system, name --> creates an external subset (any parameter may be nil)
|
155
|
+
// 4 arguments -- public, system, name, doc --> creates an external subset (any parameter may be nil)
|
156
|
+
// 5 arguments -- public, system, name, doc, true --> creates an internal subset (all but last parameter may be nil)
|
157
|
+
switch (argc)
|
158
|
+
{
|
159
|
+
case 3:
|
160
|
+
case 4:
|
161
|
+
case 5: {
|
162
|
+
VALUE name, doc, internal;
|
163
|
+
const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL;
|
164
|
+
xmlDocPtr xdoc = NULL;
|
165
|
+
|
166
|
+
rb_scan_args(argc, argv, "32", &external, &system, &name, &doc, &internal);
|
167
|
+
|
168
|
+
if (external != Qnil) {
|
169
|
+
Check_Type(external, T_STRING);
|
170
|
+
xpublic = (const xmlChar*) StringValuePtr(external);
|
171
|
+
}
|
172
|
+
if (system != Qnil) {
|
173
|
+
Check_Type(system, T_STRING);
|
174
|
+
xsystem = (const xmlChar*) StringValuePtr(system);
|
175
|
+
}
|
176
|
+
if (name != Qnil) {
|
177
|
+
Check_Type(name, T_STRING);
|
178
|
+
xname = (const xmlChar*) StringValuePtr(name);
|
179
|
+
}
|
180
|
+
if (doc != Qnil) {
|
181
|
+
if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
|
182
|
+
rb_raise(rb_eTypeError, "Must pass an XML::Document object");
|
183
|
+
Data_Get_Struct(doc, xmlDoc, xdoc);
|
184
|
+
}
|
185
|
+
|
186
|
+
if (internal == Qnil || internal == Qfalse)
|
187
|
+
xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem);
|
188
|
+
else
|
189
|
+
xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem);
|
190
|
+
|
191
|
+
if (xdtd == NULL)
|
192
|
+
rxml_raise(&xmlLastError);
|
193
|
+
|
194
|
+
/* Document will free this dtd now. */
|
195
|
+
RDATA(self)->dfree = NULL;
|
196
|
+
DATA_PTR(self) = xdtd;
|
197
|
+
|
198
|
+
xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc);
|
199
|
+
}
|
200
|
+
break;
|
201
|
+
|
202
|
+
case 2:
|
203
|
+
rb_scan_args(argc, argv, "20", &external, &system);
|
204
|
+
|
205
|
+
Check_Type(external, T_STRING);
|
206
|
+
Check_Type(system, T_STRING);
|
207
|
+
|
208
|
+
xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external),
|
209
|
+
(xmlChar*) StringValuePtr(system));
|
210
|
+
|
211
|
+
if (xdtd == NULL)
|
212
|
+
rxml_raise(&xmlLastError);
|
213
|
+
|
214
|
+
DATA_PTR(self) = xdtd;
|
215
|
+
|
216
|
+
xmlSetTreeDoc((xmlNodePtr) xdtd, NULL);
|
217
|
+
break;
|
218
|
+
|
219
|
+
case 1:
|
220
|
+
rb_scan_args(argc, argv, "10", &dtd_string);
|
221
|
+
Check_Type(dtd_string, T_STRING);
|
222
|
+
|
223
|
+
/* Note that buffer is freed by xmlParserInputBufferPush*/
|
224
|
+
buffer = xmlAllocParserInputBuffer(enc);
|
225
|
+
new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string));
|
226
|
+
xmlParserInputBufferPush(buffer, xmlStrlen(new_string),
|
227
|
+
(const char*) new_string);
|
228
|
+
|
229
|
+
xdtd = xmlIOParseDTD(NULL, buffer, enc);
|
230
|
+
|
231
|
+
if (xdtd == NULL)
|
232
|
+
rxml_raise(&xmlLastError);
|
233
|
+
|
234
|
+
xmlFree(new_string);
|
235
|
+
|
236
|
+
DATA_PTR(self) = xdtd;
|
237
|
+
break;
|
238
|
+
|
239
|
+
default:
|
240
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
241
|
+
}
|
242
|
+
|
243
|
+
return self;
|
244
|
+
}
|
245
|
+
|
246
|
+
void rxml_init_dtd()
|
247
|
+
{
|
248
|
+
cXMLDtd = rb_define_class_under(mXML, "Dtd", rb_cObject);
|
249
|
+
rb_define_alloc_func(cXMLDtd, rxml_dtd_alloc);
|
250
|
+
rb_define_method(cXMLDtd, "initialize", rxml_dtd_initialize, -1);
|
251
|
+
rb_define_method(cXMLDtd, "external_id", rxml_dtd_external_id_get, 0);
|
252
|
+
rb_define_method(cXMLDtd, "name", rxml_dtd_name_get, 0);
|
253
|
+
rb_define_method(cXMLDtd, "uri", rxml_dtd_uri_get, 0);
|
254
|
+
|
255
|
+
rb_define_alias(cXMLDtd, "system_id", "uri");
|
256
|
+
}
|
257
|
+
|
@@ -0,0 +1,221 @@
|
|
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
|
+
/*
|
9
|
+
* Document-class: LibXML::XML::Encoding
|
10
|
+
*
|
11
|
+
* The encoding class exposes the encodings that libxml
|
12
|
+
* supports via constants.
|
13
|
+
*
|
14
|
+
* LibXML converts all data sources to UTF8
|
15
|
+
* internally before processing them. By default,
|
16
|
+
* LibXML determines a data source's encoding
|
17
|
+
* using the algorithm described on its
|
18
|
+
* website[http://xmlsoft.org/encoding.html].
|
19
|
+
*
|
20
|
+
* However, you may override a data source's encoding
|
21
|
+
* by using the encoding constants defined in this
|
22
|
+
* module.
|
23
|
+
*
|
24
|
+
* Example 1:
|
25
|
+
*
|
26
|
+
* io = File.open('some_file', 'rb')
|
27
|
+
* parser = XML::Parser.io(io, :encoding => XML::Encoding::ISO_8859_1)
|
28
|
+
* doc = parser.parse
|
29
|
+
*
|
30
|
+
* Example 2:
|
31
|
+
*
|
32
|
+
* parser = XML::HTMLParser.file("some_file", :encoding => XML::Encoding::ISO_8859_1)
|
33
|
+
* doc = parser.parse
|
34
|
+
*
|
35
|
+
* Example 3:
|
36
|
+
*
|
37
|
+
* document = XML::Document.new
|
38
|
+
* document.encoding = XML::Encoding::ISO_8859_1
|
39
|
+
* doc << XML::Node.new
|
40
|
+
*/
|
41
|
+
|
42
|
+
VALUE mXMLEncoding;
|
43
|
+
|
44
|
+
/*
|
45
|
+
* call-seq:
|
46
|
+
* Input.s_to_encoding("UTF_8") -> XML::Encoding::UTF_8
|
47
|
+
*
|
48
|
+
* Converts an encoding string to an encoding constant
|
49
|
+
* defined on the XML::Encoding class.
|
50
|
+
*/
|
51
|
+
static VALUE rxml_encoding_from_s(VALUE klass, VALUE encoding)
|
52
|
+
{
|
53
|
+
xmlCharEncoding xencoding;
|
54
|
+
|
55
|
+
if (encoding == Qnil)
|
56
|
+
return Qnil;
|
57
|
+
|
58
|
+
xencoding = xmlParseCharEncoding(StringValuePtr(encoding));
|
59
|
+
return NUM2INT(xencoding);
|
60
|
+
}
|
61
|
+
|
62
|
+
/*
|
63
|
+
* call-seq:
|
64
|
+
* Input.encoding_to_s(Input::ENCODING) -> "encoding"
|
65
|
+
*
|
66
|
+
* Converts an encoding constant defined on the XML::Encoding
|
67
|
+
* class to its text representation.
|
68
|
+
*/
|
69
|
+
static VALUE rxml_encoding_to_s(VALUE klass, VALUE encoding)
|
70
|
+
{
|
71
|
+
const char* xencoding = xmlGetCharEncodingName(NUM2INT(encoding));
|
72
|
+
|
73
|
+
if (!xencoding)
|
74
|
+
return Qnil;
|
75
|
+
else
|
76
|
+
return rxml_str_new2(xencoding, xencoding);
|
77
|
+
}
|
78
|
+
|
79
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
80
|
+
VALUE rxml_xml_encoding_to_rb_encoding(VALUE klass, xmlCharEncoding xmlEncoding)
|
81
|
+
{
|
82
|
+
ID encoding_name;
|
83
|
+
|
84
|
+
switch (xmlEncoding)
|
85
|
+
{
|
86
|
+
case XML_CHAR_ENCODING_UTF8:
|
87
|
+
encoding_name = rb_intern("UTF_8");
|
88
|
+
break;
|
89
|
+
case XML_CHAR_ENCODING_UTF16LE:
|
90
|
+
encoding_name = rb_intern("UTF_16LE");
|
91
|
+
break;
|
92
|
+
case XML_CHAR_ENCODING_UTF16BE:
|
93
|
+
encoding_name = rb_intern("UTF_16BE");
|
94
|
+
break;
|
95
|
+
case XML_CHAR_ENCODING_UCS4LE:
|
96
|
+
encoding_name = rb_intern("UCS_4LE");
|
97
|
+
break;
|
98
|
+
case XML_CHAR_ENCODING_UCS4BE:
|
99
|
+
encoding_name = rb_intern("UCS_4BE");
|
100
|
+
break;
|
101
|
+
case XML_CHAR_ENCODING_UCS2:
|
102
|
+
encoding_name = rb_intern("UCS_2");
|
103
|
+
break;
|
104
|
+
case XML_CHAR_ENCODING_8859_1:
|
105
|
+
encoding_name = rb_intern("ISO8859_1");
|
106
|
+
break;
|
107
|
+
case XML_CHAR_ENCODING_8859_2:
|
108
|
+
encoding_name = rb_intern("ISO8859_2");
|
109
|
+
break;
|
110
|
+
case XML_CHAR_ENCODING_8859_3:
|
111
|
+
encoding_name = rb_intern("ISO8859_3");
|
112
|
+
break;
|
113
|
+
case XML_CHAR_ENCODING_8859_4:
|
114
|
+
encoding_name = rb_intern("ISO8859_4");
|
115
|
+
break;
|
116
|
+
case XML_CHAR_ENCODING_8859_5:
|
117
|
+
encoding_name = rb_intern("ISO8859_5");
|
118
|
+
break;
|
119
|
+
case XML_CHAR_ENCODING_8859_6:
|
120
|
+
encoding_name = rb_intern("ISO8859_6");
|
121
|
+
break;
|
122
|
+
case XML_CHAR_ENCODING_8859_7:
|
123
|
+
encoding_name = rb_intern("ISO8859_7");
|
124
|
+
break;
|
125
|
+
case XML_CHAR_ENCODING_8859_8:
|
126
|
+
encoding_name = rb_intern("ISO8859_8");
|
127
|
+
break;
|
128
|
+
case XML_CHAR_ENCODING_8859_9:
|
129
|
+
encoding_name = rb_intern("ISO8859_9");
|
130
|
+
break;
|
131
|
+
case XML_CHAR_ENCODING_2022_JP:
|
132
|
+
encoding_name = rb_intern("ISO_2022_JP");
|
133
|
+
break;
|
134
|
+
case XML_CHAR_ENCODING_SHIFT_JIS:
|
135
|
+
encoding_name = rb_intern("SHIFT_JIS");
|
136
|
+
break;
|
137
|
+
case XML_CHAR_ENCODING_EUC_JP:
|
138
|
+
encoding_name = rb_intern("EUC_JP");
|
139
|
+
break;
|
140
|
+
case XML_CHAR_ENCODING_ASCII:
|
141
|
+
encoding_name = rb_intern("US-ASCII");
|
142
|
+
break;
|
143
|
+
default:
|
144
|
+
/* Covers XML_CHAR_ENCODING_ERROR, XML_CHAR_ENCODING_NONE, XML_CHAR_ENCODING_EBCDIC */
|
145
|
+
encoding_name = rb_intern("ASCII_8BIT");
|
146
|
+
}
|
147
|
+
return rb_const_get(rb_cEncoding, encoding_name);
|
148
|
+
}
|
149
|
+
|
150
|
+
/*
|
151
|
+
* call-seq:
|
152
|
+
* Input.encoding_to_rb_encoding(Input::ENCODING) -> Encoding
|
153
|
+
*
|
154
|
+
* Converts an encoding constant defined on the XML::Encoding
|
155
|
+
* class to a Ruby encoding object (available on Ruby 1.9.* and higher).
|
156
|
+
*/
|
157
|
+
VALUE rxml_encoding_to_rb_encoding(VALUE klass, VALUE encoding)
|
158
|
+
{
|
159
|
+
return rxml_xml_encoding_to_rb_encoding(klass, NUM2INT(encoding));
|
160
|
+
}
|
161
|
+
#endif
|
162
|
+
|
163
|
+
void rxml_init_encoding(void)
|
164
|
+
{
|
165
|
+
mXMLEncoding = rb_define_module_under(mXML, "Encoding");
|
166
|
+
rb_define_module_function(mXMLEncoding, "from_s", rxml_encoding_from_s, 1);
|
167
|
+
rb_define_module_function(mXMLEncoding, "to_s", rxml_encoding_to_s, 1);
|
168
|
+
|
169
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
170
|
+
// rb_define_module_function(mXMLEncoding, "to_rb_encoding", rxml_encoding_to_rb_encoding, 2);
|
171
|
+
#endif
|
172
|
+
|
173
|
+
/* -1: No char encoding detected. */
|
174
|
+
rb_define_const(mXMLEncoding, "ERROR", INT2NUM(XML_CHAR_ENCODING_ERROR));
|
175
|
+
/* 0: No char encoding detected. */
|
176
|
+
rb_define_const(mXMLEncoding, "NONE", INT2NUM(XML_CHAR_ENCODING_NONE));
|
177
|
+
/* 1: UTF-8 */
|
178
|
+
rb_define_const(mXMLEncoding, "UTF_8", INT2NUM(XML_CHAR_ENCODING_UTF8));
|
179
|
+
/* 2: UTF-16 little endian. */
|
180
|
+
rb_define_const(mXMLEncoding, "UTF_16LE", INT2NUM(XML_CHAR_ENCODING_UTF16LE));
|
181
|
+
/* 3: UTF-16 big endian. */
|
182
|
+
rb_define_const(mXMLEncoding, "UTF_16BE", INT2NUM(XML_CHAR_ENCODING_UTF16BE));
|
183
|
+
/* 4: UCS-4 little endian. */
|
184
|
+
rb_define_const(mXMLEncoding, "UCS_4LE", INT2NUM(XML_CHAR_ENCODING_UCS4LE));
|
185
|
+
/* 5: UCS-4 big endian. */
|
186
|
+
rb_define_const(mXMLEncoding, "UCS_4BE", INT2NUM(XML_CHAR_ENCODING_UCS4BE));
|
187
|
+
/* 6: EBCDIC uh! */
|
188
|
+
rb_define_const(mXMLEncoding, "EBCDIC", INT2NUM(XML_CHAR_ENCODING_EBCDIC));
|
189
|
+
/* 7: UCS-4 unusual ordering. */
|
190
|
+
rb_define_const(mXMLEncoding, "UCS_4_2143", INT2NUM(XML_CHAR_ENCODING_UCS4_2143));
|
191
|
+
/* 8: UCS-4 unusual ordering. */
|
192
|
+
rb_define_const(mXMLEncoding, "UCS_4_3412", INT2NUM(XML_CHAR_ENCODING_UCS4_3412));
|
193
|
+
/* 9: UCS-2. */
|
194
|
+
rb_define_const(mXMLEncoding, "UCS_2", INT2NUM(XML_CHAR_ENCODING_UCS2));
|
195
|
+
/* 10: ISO-8859-1 ISO Latin 1. */
|
196
|
+
rb_define_const(mXMLEncoding, "ISO_8859_1", INT2NUM(XML_CHAR_ENCODING_8859_1));
|
197
|
+
/* 11: ISO-8859-2 ISO Latin 2. */
|
198
|
+
rb_define_const(mXMLEncoding, "ISO_8859_2", INT2NUM(XML_CHAR_ENCODING_8859_2));
|
199
|
+
/* 12: ISO-8859-3. */
|
200
|
+
rb_define_const(mXMLEncoding, "ISO_8859_3", INT2NUM(XML_CHAR_ENCODING_8859_3));
|
201
|
+
/* 13: ISO-8859-4. */
|
202
|
+
rb_define_const(mXMLEncoding, "ISO_8859_4", INT2NUM(XML_CHAR_ENCODING_8859_4));
|
203
|
+
/* 14: ISO-8859-5. */
|
204
|
+
rb_define_const(mXMLEncoding, "ISO_8859_5", INT2NUM(XML_CHAR_ENCODING_8859_5));
|
205
|
+
/* 15: ISO-8859-6. */
|
206
|
+
rb_define_const(mXMLEncoding, "ISO_8859_6", INT2NUM(XML_CHAR_ENCODING_8859_6));
|
207
|
+
/* 16: ISO-8859-7. */
|
208
|
+
rb_define_const(mXMLEncoding, "ISO_8859_7", INT2NUM(XML_CHAR_ENCODING_8859_7));
|
209
|
+
/* 17: ISO-8859-8. */
|
210
|
+
rb_define_const(mXMLEncoding, "ISO_8859_8", INT2NUM(XML_CHAR_ENCODING_8859_8));
|
211
|
+
/* 18: ISO-8859-9. */
|
212
|
+
rb_define_const(mXMLEncoding, "ISO_8859_9", INT2NUM(XML_CHAR_ENCODING_8859_9));
|
213
|
+
/* 19: ISO-2022-JP. */
|
214
|
+
rb_define_const(mXMLEncoding, "ISO_2022_JP", INT2NUM(XML_CHAR_ENCODING_2022_JP));
|
215
|
+
/* 20: Shift_JIS. */
|
216
|
+
rb_define_const(mXMLEncoding, "SHIFT_JIS", INT2NUM(XML_CHAR_ENCODING_SHIFT_JIS));
|
217
|
+
/* 21: EUC-JP. */
|
218
|
+
rb_define_const(mXMLEncoding, "EUC_JP", INT2NUM(XML_CHAR_ENCODING_EUC_JP));
|
219
|
+
/* 22: pure ASCII. */
|
220
|
+
rb_define_const(mXMLEncoding, "ASCII", INT2NUM(XML_CHAR_ENCODING_ASCII));
|
221
|
+
}
|