libxml-ruby 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/CHANGES +22 -0
  2. data/README +3 -1
  3. data/ext/libxml/cbg.c +86 -76
  4. data/ext/libxml/extconf.rb +2 -1
  5. data/ext/libxml/libxml.c +899 -885
  6. data/ext/libxml/ruby_libxml.h +65 -70
  7. data/ext/libxml/ruby_xml_attr.c +485 -500
  8. data/ext/libxml/ruby_xml_attributes.c +107 -106
  9. data/ext/libxml/ruby_xml_document.c +355 -356
  10. data/ext/libxml/ruby_xml_dtd.c +119 -117
  11. data/ext/libxml/ruby_xml_error.c +1112 -581
  12. data/ext/libxml/ruby_xml_html_parser.c +35 -34
  13. data/ext/libxml/ruby_xml_input.c +182 -187
  14. data/ext/libxml/ruby_xml_input_cbg.c +197 -179
  15. data/ext/libxml/ruby_xml_node.c +1529 -1566
  16. data/ext/libxml/ruby_xml_node.h +2 -2
  17. data/ext/libxml/ruby_xml_ns.c +150 -156
  18. data/ext/libxml/ruby_xml_parser.c +37 -36
  19. data/ext/libxml/ruby_xml_parser_context.c +657 -659
  20. data/ext/libxml/ruby_xml_reader.c +203 -209
  21. data/ext/libxml/ruby_xml_relaxng.c +29 -25
  22. data/ext/libxml/ruby_xml_sax_parser.c +33 -32
  23. data/ext/libxml/ruby_xml_schema.c +165 -161
  24. data/ext/libxml/ruby_xml_state.c +19 -21
  25. data/ext/libxml/ruby_xml_xinclude.c +24 -25
  26. data/ext/libxml/ruby_xml_xpath.c +108 -108
  27. data/ext/libxml/ruby_xml_xpath_context.c +305 -293
  28. data/ext/libxml/ruby_xml_xpath_expression.c +24 -24
  29. data/ext/libxml/ruby_xml_xpath_object.c +89 -96
  30. data/ext/libxml/ruby_xml_xpointer.c +107 -109
  31. data/ext/libxml/ruby_xml_xpointer.h +13 -13
  32. data/ext/libxml/version.h +2 -2
  33. data/ext/mingw/Rakefile +1 -1
  34. data/ext/vc/libxml_ruby.vcproj +1 -1
  35. data/lib/libxml/error.rb +4 -4
  36. data/test/tc_node_edit.rb +14 -2
  37. data/test/tc_node_text.rb +9 -9
  38. metadata +2 -2
@@ -8,8 +8,8 @@
8
8
 
9
9
  /*
10
10
  * Document-class: LibXML::XML::XPath::Expression
11
- *
12
- * The XML::XPath::Expression class is used to compile
11
+ *
12
+ * The XML::XPath::Expression class is used to compile
13
13
  * XPath expressions so they can be parsed only once
14
14
  * but reused multiple times.
15
15
  *
@@ -23,47 +23,47 @@
23
23
 
24
24
  VALUE cXMLXPathExpression;
25
25
 
26
- static void
27
- rxml_xpath_expression_free(xmlXPathCompExprPtr expr) {
26
+ static void rxml_xpath_expression_free(xmlXPathCompExprPtr expr)
27
+ {
28
28
  xmlXPathFreeCompExpr(expr);
29
29
  }
30
30
 
31
- static VALUE
32
- rxml_xpath_expression_alloc(VALUE klass) {
33
- return Data_Wrap_Struct(cXMLXPathExpression,
34
- NULL,
35
- rxml_xpath_expression_free,
36
- NULL);
31
+ static VALUE rxml_xpath_expression_alloc(VALUE klass)
32
+ {
33
+ return Data_Wrap_Struct(cXMLXPathExpression, NULL,
34
+ rxml_xpath_expression_free, NULL);
37
35
  }
38
36
 
39
37
  /* call-seq:
40
38
  * XPath::Expression.new(expression) -> XPath::Expression
41
- *
42
- * Compiled XPatch expression. Work faster when find called many times
39
+ *
40
+ * Compiled XPatch expression. Work faster when find called many times
43
41
  * same expression.
44
42
  *
45
43
  * doc = XML::Document.string('<header><first>hi</first></header>')
46
44
  * expr = XPath::Expression.new('//first')
47
45
  * nodes = doc.find(expr)
48
46
  */
49
- static VALUE
50
- rxml_xpath_expression_initialize(VALUE self, VALUE expression) {
51
- xmlXPathCompExprPtr compexpr = xmlXPathCompile(StringValueCStr(expression));
47
+ static VALUE rxml_xpath_expression_initialize(VALUE self, VALUE expression)
48
+ {
49
+ xmlXPathCompExprPtr compexpr = xmlXPathCompile(StringValueCStr(expression));
52
50
 
53
- if (compexpr == NULL) {
54
- xmlErrorPtr xerror = xmlGetLastError();
55
- rxml_raise(xerror);
51
+ if (compexpr == NULL)
52
+ {
53
+ xmlErrorPtr xerror = xmlGetLastError();
54
+ rxml_raise(xerror);
56
55
  }
57
56
 
58
- DATA_PTR(self) = compexpr;
57
+ DATA_PTR( self) = compexpr;
59
58
  return self;
60
59
  }
61
60
 
62
- void
63
- ruby_init_xml_xpath_expression(void) {
61
+ void ruby_init_xml_xpath_expression(void)
62
+ {
64
63
  cXMLXPathExpression = rb_define_class_under(mXPath, "Expression", rb_cObject);
65
64
  rb_define_alloc_func(cXMLXPathExpression, rxml_xpath_expression_alloc);
66
- rb_define_singleton_method(rb_cRegexp, "compile", rb_class_new_instance, 1);
67
-
68
- rb_define_method(cXMLXPathExpression, "initialize", rxml_xpath_expression_initialize, 1);
65
+ rb_define_singleton_method(cXMLXPathExpression, "compile",
66
+ rb_class_new_instance, 1);
67
+ rb_define_method(cXMLXPathExpression, "initialize",
68
+ rxml_xpath_expression_initialize, 1);
69
69
  }
@@ -6,14 +6,12 @@
6
6
  * Document-class: LibXML::XML::XPath::Object
7
7
  *
8
8
  * A collection of nodes returned from the evaluation of an XML::XPath
9
- * or XML::XPointer expression.
9
+ * or XML::XPointer expression.
10
10
  *
11
11
  */
12
12
  VALUE cXMLXPathObject;
13
13
 
14
-
15
- static xmlDocPtr
16
- rxml_xpath_object_doc(xmlXPathObjectPtr xpop)
14
+ static xmlDocPtr rxml_xpath_object_doc(xmlXPathObjectPtr xpop)
17
15
  {
18
16
  xmlDocPtr result = NULL;
19
17
  xmlNodePtr *nodes = NULL;
@@ -32,117 +30,114 @@ rxml_xpath_object_doc(xmlXPathObjectPtr xpop)
32
30
  return (*nodes)->doc;
33
31
  }
34
32
 
35
- static void
36
- rxml_xpath_object_mark(xmlXPathObjectPtr xpop)
33
+ static void rxml_xpath_object_mark(xmlXPathObjectPtr xpop)
37
34
  {
38
35
  int i;
39
36
 
40
- if ( xpop->type == XPATH_NODESET && xpop->nodesetval != NULL )
37
+ if (xpop->type == XPATH_NODESET && xpop->nodesetval != NULL)
41
38
  {
42
39
  xmlDocPtr xdoc = rxml_xpath_object_doc(xpop);
43
40
  if (xdoc && xdoc->_private)
44
- rb_gc_mark((VALUE)xdoc->_private);
41
+ rb_gc_mark((VALUE) xdoc->_private);
45
42
 
46
- for (i=0; i<xpop->nodesetval->nodeNr; i++)
43
+ for (i = 0; i < xpop->nodesetval->nodeNr; i++)
47
44
  {
48
45
  if (xpop->nodesetval->nodeTab[i]->_private)
49
- rb_gc_mark((VALUE)xpop->nodesetval->nodeTab[i]->_private);
46
+ rb_gc_mark((VALUE) xpop->nodesetval->nodeTab[i]->_private);
50
47
  }
51
48
  }
52
49
  }
53
50
 
54
- static void
55
- rxml_xpath_object_free(xmlXPathObjectPtr xpop)
51
+ static void rxml_xpath_object_free(xmlXPathObjectPtr xpop)
56
52
  {
57
53
  /* Now free the xpath result but not underlying nodes
58
- since those belong to the document. */
54
+ since those belong to the document. */
59
55
  xmlXPathFreeNodeSetList(xpop);
60
56
  }
61
57
 
62
- VALUE
63
- rxml_xpath_object_wrap(xmlXPathObjectPtr xpop)
58
+ VALUE rxml_xpath_object_wrap(xmlXPathObjectPtr xpop)
64
59
  {
65
60
  VALUE rval;
66
61
 
67
- if ( xpop==NULL )
62
+ if (xpop == NULL)
68
63
  return Qnil;
69
64
 
70
- switch(xpop->type) {
65
+ switch (xpop->type)
66
+ {
71
67
  case XPATH_NODESET:
72
- rval = Data_Wrap_Struct(cXMLXPathObject,
73
- rxml_xpath_object_mark,
74
- rxml_xpath_object_free,
75
- xpop);
76
-
68
+ rval = Data_Wrap_Struct(cXMLXPathObject, rxml_xpath_object_mark,
69
+ rxml_xpath_object_free, xpop);
70
+
77
71
  break;
78
72
  case XPATH_BOOLEAN:
79
73
  if (xpop->boolval != 0)
80
- rval=Qtrue;
74
+ rval = Qtrue;
81
75
  else
82
- rval=Qfalse;
83
-
76
+ rval = Qfalse;
77
+
84
78
  xmlXPathFreeObject(xpop);
85
79
  break;
86
80
  case XPATH_NUMBER:
87
- rval=rb_float_new(xpop->floatval);
88
-
81
+ rval = rb_float_new(xpop->floatval);
82
+
89
83
  xmlXPathFreeObject(xpop);
90
84
  break;
91
85
  case XPATH_STRING:
92
- rval=rb_str_new2(xpop->stringval);
93
-
86
+ rval = rb_str_new2(xpop->stringval);
87
+
94
88
  xmlXPathFreeObject(xpop);
95
89
  break;
96
90
  default:
97
91
  xmlXPathFreeObject(xpop);
98
- rval=Qnil;
92
+ rval = Qnil;
99
93
  }
100
94
  return rval;
101
95
  }
102
96
 
103
- static VALUE
104
- rxml_xpath_object_tabref(xmlXPathObjectPtr xpop, int apos) {
97
+ static VALUE rxml_xpath_object_tabref(xmlXPathObjectPtr xpop, int apos)
98
+ {
105
99
 
106
- if (apos < 0 )
107
- apos=xpop->nodesetval->nodeNr+apos;
100
+ if (apos < 0)
101
+ apos = xpop->nodesetval->nodeNr + apos;
108
102
 
109
- if (apos < 0 || apos+1 > xpop->nodesetval->nodeNr )
103
+ if (apos < 0 || apos + 1 > xpop->nodesetval->nodeNr)
110
104
  return Qnil;
111
105
 
112
- switch(xpop->nodesetval->nodeTab[apos]->type) {
106
+ switch (xpop->nodesetval->nodeTab[apos]->type)
107
+ {
113
108
  case XML_ATTRIBUTE_NODE:
114
- return rxml_attr_wrap((xmlAttrPtr)xpop->nodesetval->nodeTab[apos]);
109
+ return rxml_attr_wrap((xmlAttrPtr) xpop->nodesetval->nodeTab[apos]);
115
110
  break;
116
111
  default:
117
- return rxml_node2_wrap(cXMLNode,
118
- xpop->nodesetval->nodeTab[apos]);
112
+ return rxml_node_wrap(cXMLNode, xpop->nodesetval->nodeTab[apos]);
119
113
  }
120
114
  }
121
115
 
122
116
  /*
123
117
  * call-seq:
124
118
  * xpath_object.to_a -> [node, ..., node]
125
- *
119
+ *
126
120
  * Obtain an array of the nodes in this set.
127
121
  */
128
- static VALUE
129
- rxml_xpath_object_to_a(VALUE self)
122
+ static VALUE rxml_xpath_object_to_a(VALUE self)
130
123
  {
131
124
  VALUE set_ary, nodeobj;
132
125
  xmlXPathObjectPtr xpop;
133
126
  int i;
134
-
135
- Data_Get_Struct(self,xmlXPathObject,xpop);
127
+
128
+ Data_Get_Struct(self, xmlXPathObject, xpop);
136
129
 
137
130
  set_ary = rb_ary_new();
138
- if (!((xpop->nodesetval == NULL) || (xpop->nodesetval->nodeNr == 0))) {
139
- for (i = 0; i < xpop->nodesetval->nodeNr; i++) {
131
+ if (!((xpop->nodesetval == NULL) || (xpop->nodesetval->nodeNr == 0)))
132
+ {
133
+ for (i = 0; i < xpop->nodesetval->nodeNr; i++)
134
+ {
140
135
  nodeobj = rxml_xpath_object_tabref(xpop, i);
141
136
  rb_ary_push(set_ary, nodeobj);
142
137
  }
143
138
  }
144
-
145
- return(set_ary);
139
+
140
+ return (set_ary);
146
141
  }
147
142
 
148
143
  /*
@@ -151,39 +146,40 @@ rxml_xpath_object_to_a(VALUE self)
151
146
  *
152
147
  * Determine whether this nodeset is empty (contains no nodes).
153
148
  */
154
- static VALUE
155
- rxml_xpath_object_empty_q(VALUE self) {
149
+ static VALUE rxml_xpath_object_empty_q(VALUE self)
150
+ {
156
151
  xmlXPathObjectPtr xpop;
157
152
 
158
- Data_Get_Struct(self,xmlXPathObject,xpop);
153
+ Data_Get_Struct(self, xmlXPathObject, xpop);
159
154
 
160
155
  if (xpop->type != XPATH_NODESET)
161
156
  return Qnil;
162
-
163
- return ( xpop->nodesetval == NULL || xpop->nodesetval->nodeNr <= 0 ) ? Qtrue : Qfalse;
157
+
158
+ return (xpop->nodesetval == NULL || xpop->nodesetval->nodeNr <= 0) ? Qtrue
159
+ : Qfalse;
164
160
  }
165
161
 
166
162
  /*
167
163
  * call-seq:
168
164
  * xpath_object.each { |node| ... } -> self
169
- *
165
+ *
170
166
  * Call the supplied block for each node in this set.
171
167
  */
172
- static VALUE
173
- rxml_xpath_object_each(VALUE self)
168
+ static VALUE rxml_xpath_object_each(VALUE self)
174
169
  {
175
170
  xmlXPathObjectPtr xpop;
176
171
  int i;
177
172
 
178
- if ( rxml_xpath_object_empty_q(self) == Qtrue )
173
+ if (rxml_xpath_object_empty_q(self) == Qtrue)
179
174
  return Qnil;
180
175
 
181
- Data_Get_Struct(self,xmlXPathObject,xpop);
176
+ Data_Get_Struct(self, xmlXPathObject, xpop);
182
177
 
183
- for (i = 0; i < xpop->nodesetval->nodeNr; i++) {
184
- rb_yield(rxml_xpath_object_tabref(xpop,i));
178
+ for (i = 0; i < xpop->nodesetval->nodeNr; i++)
179
+ {
180
+ rb_yield(rxml_xpath_object_tabref(xpop, i));
185
181
  }
186
- return(self);
182
+ return (self);
187
183
  }
188
184
 
189
185
  /*
@@ -192,12 +188,12 @@ rxml_xpath_object_each(VALUE self)
192
188
  *
193
189
  * Returns the first node in this node set, or nil if none exist.
194
190
  */
195
- static VALUE
196
- rxml_xpath_object_first(VALUE self) {
197
- if ( rxml_xpath_object_empty_q(self) == Qtrue )
191
+ static VALUE rxml_xpath_object_first(VALUE self)
192
+ {
193
+ if (rxml_xpath_object_empty_q(self) == Qtrue)
198
194
  return Qnil;
199
-
200
- return rxml_xpath_object_tabref((xmlXPathObjectPtr)DATA_PTR(self),0);
195
+
196
+ return rxml_xpath_object_tabref((xmlXPathObjectPtr) DATA_PTR(self), 0);
201
197
  }
202
198
 
203
199
  /*
@@ -206,29 +202,29 @@ rxml_xpath_object_first(VALUE self) {
206
202
  *
207
203
  * array index into set of nodes
208
204
  */
209
- static VALUE
210
- rxml_xpath_object_aref(VALUE self, VALUE aref) {
211
- if ( rxml_xpath_object_empty_q(self) == Qtrue )
205
+ static VALUE rxml_xpath_object_aref(VALUE self, VALUE aref)
206
+ {
207
+ if (rxml_xpath_object_empty_q(self) == Qtrue)
212
208
  return Qnil;
213
209
 
214
- return rxml_xpath_object_tabref((xmlXPathObjectPtr)DATA_PTR(self),
215
- NUM2INT(aref));
210
+ return rxml_xpath_object_tabref((xmlXPathObjectPtr) DATA_PTR(self), NUM2INT(
211
+ aref));
216
212
  }
217
213
 
218
214
  /*
219
215
  * call-seq:
220
216
  * xpath_object.length -> num
221
- *
217
+ *
222
218
  * Obtain the length of the nodesetval node list.
223
219
  */
224
- static VALUE
225
- rxml_xpath_object_length(VALUE self) {
220
+ static VALUE rxml_xpath_object_length(VALUE self)
221
+ {
226
222
  xmlXPathObjectPtr xpop;
227
223
 
228
224
  if (rxml_xpath_object_empty_q(self) == Qtrue)
229
225
  return INT2FIX(0);
230
226
 
231
- Data_Get_Struct(self,xmlXPathObject,xpop);
227
+ Data_Get_Struct(self, xmlXPathObject, xpop);
232
228
 
233
229
  return INT2NUM(xpop->nodesetval->nodeNr);
234
230
  }
@@ -236,11 +232,11 @@ rxml_xpath_object_length(VALUE self) {
236
232
  /*
237
233
  * call-seq:
238
234
  * xpath_object.xpath_type -> int
239
- *
240
- * Returns the XPath type of the result object.
235
+ *
236
+ * Returns the XPath type of the result object.
241
237
  * Possible values are defined as constants
242
238
  * on the XML::XPath class and include:
243
- *
239
+ *
244
240
  * * XML::XPath::UNDEFINED
245
241
  * * XML::XPath::NODESET
246
242
  * * XML::XPath::BOOLEAN
@@ -250,31 +246,28 @@ rxml_xpath_object_length(VALUE self) {
250
246
  * * XML::XPath::RANGE
251
247
  * * XML::XPath::LOCATIONSET
252
248
  * * XML::XPath::USERS
253
- * * XML::XPath::XSLT_TREE
249
+ * * XML::XPath::XSLT_TREE
254
250
  */
255
- static VALUE
256
- rxml_xpath_object_get_type(VALUE self)
251
+ static VALUE rxml_xpath_object_get_type(VALUE self)
257
252
  {
258
253
  xmlXPathObjectPtr xpop;
259
254
 
260
- Data_Get_Struct(self,xmlXPathObject,xpop);
255
+ Data_Get_Struct(self, xmlXPathObject, xpop);
261
256
 
262
257
  return INT2FIX(xpop->type);
263
258
  }
264
259
 
265
-
266
260
  /*
267
261
  * call-seq:
268
262
  * xpath_object.string -> String
269
- *
263
+ *
270
264
  * Returns the original XPath expression as a string.
271
265
  */
272
- static VALUE
273
- rxml_xpath_object_string(VALUE self)
266
+ static VALUE rxml_xpath_object_string(VALUE self)
274
267
  {
275
268
  xmlXPathObjectPtr xpop;
276
269
 
277
- Data_Get_Struct(self,xmlXPathObject,xpop);
270
+ Data_Get_Struct(self, xmlXPathObject, xpop);
278
271
 
279
272
  if (xpop->stringval == NULL)
280
273
  return Qnil;
@@ -282,28 +275,28 @@ rxml_xpath_object_string(VALUE self)
282
275
  return rb_str_new2((const char*) xpop->stringval);
283
276
  }
284
277
 
285
- /*
278
+ /*
286
279
  * call-seq:
287
280
  * nodes.debug -> (true|false)
288
- *
281
+ *
289
282
  * Dump libxml debugging information to stdout.
290
283
  * Requires Libxml be compiled with debugging enabled.
291
284
  */
292
- static VALUE
293
- rxml_xpath_object_debug(VALUE self) {
285
+ static VALUE rxml_xpath_object_debug(VALUE self)
286
+ {
294
287
  xmlXPathObjectPtr xpop;
295
-
296
- #ifndef LIBXML_DEBUG_ENABLED
288
+
289
+ #ifndef LIBXML_DEBUG_ENABLED
297
290
  rb_raise(rb_eTypeError, "libxml was not compiled with debug support.");
298
- #endif
291
+ #endif
299
292
 
300
293
  Data_Get_Struct(self, xmlXPathObject, xpop);
301
294
  xmlXPathDebugDumpObject(stdout, xpop, 0);
302
295
  return Qnil;
303
296
  }
304
297
 
305
- void
306
- ruby_init_xml_xpath_object(void) {
298
+ void ruby_init_xml_xpath_object(void)
299
+ {
307
300
  cXMLXPathObject = rb_define_class_under(mXPath, "Object", rb_cObject);
308
301
  rb_include_module(cXMLXPathObject, rb_mEnumerable);
309
302
  rb_define_attr(cXMLXPathObject, "context", 1, 0);