nokogiri 1.11.1-x64-mingw32 → 1.11.2-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +12 -12
  3. data/LICENSE.md +1 -1
  4. data/README.md +20 -15
  5. data/ext/nokogiri/depend +34 -474
  6. data/ext/nokogiri/extconf.rb +253 -183
  7. data/ext/nokogiri/html_document.c +10 -15
  8. data/ext/nokogiri/html_element_description.c +84 -71
  9. data/ext/nokogiri/html_entity_lookup.c +21 -16
  10. data/ext/nokogiri/html_sax_parser_context.c +66 -65
  11. data/ext/nokogiri/html_sax_push_parser.c +29 -27
  12. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  13. data/ext/nokogiri/nokogiri.c +171 -63
  14. data/ext/nokogiri/nokogiri.h +158 -75
  15. data/ext/nokogiri/test_global_handlers.c +3 -4
  16. data/ext/nokogiri/xml_attr.c +15 -15
  17. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  18. data/ext/nokogiri/xml_cdata.c +13 -18
  19. data/ext/nokogiri/xml_comment.c +19 -26
  20. data/ext/nokogiri/xml_document.c +221 -164
  21. data/ext/nokogiri/xml_document_fragment.c +13 -15
  22. data/ext/nokogiri/xml_dtd.c +54 -48
  23. data/ext/nokogiri/xml_element_content.c +30 -27
  24. data/ext/nokogiri/xml_element_decl.c +22 -22
  25. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  26. data/ext/nokogiri/xml_entity_decl.c +32 -30
  27. data/ext/nokogiri/xml_entity_reference.c +16 -18
  28. data/ext/nokogiri/xml_namespace.c +56 -49
  29. data/ext/nokogiri/xml_node.c +338 -286
  30. data/ext/nokogiri/xml_node_set.c +168 -156
  31. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  32. data/ext/nokogiri/xml_reader.c +191 -157
  33. data/ext/nokogiri/xml_relax_ng.c +29 -23
  34. data/ext/nokogiri/xml_sax_parser.c +117 -112
  35. data/ext/nokogiri/xml_sax_parser_context.c +100 -85
  36. data/ext/nokogiri/xml_sax_push_parser.c +34 -27
  37. data/ext/nokogiri/xml_schema.c +48 -42
  38. data/ext/nokogiri/xml_syntax_error.c +21 -23
  39. data/ext/nokogiri/xml_text.c +13 -17
  40. data/ext/nokogiri/xml_xpath_context.c +134 -127
  41. data/ext/nokogiri/xslt_stylesheet.c +157 -157
  42. data/lib/nokogiri.rb +1 -22
  43. data/lib/nokogiri/2.5/nokogiri.so +0 -0
  44. data/lib/nokogiri/2.6/nokogiri.so +0 -0
  45. data/lib/nokogiri/2.7/nokogiri.so +0 -0
  46. data/lib/nokogiri/3.0/nokogiri.so +0 -0
  47. data/lib/nokogiri/css/parser.rb +1 -1
  48. data/lib/nokogiri/extension.rb +26 -0
  49. data/lib/nokogiri/html/document_fragment.rb +15 -15
  50. data/lib/nokogiri/version/constant.rb +1 -1
  51. data/lib/nokogiri/version/info.rb +31 -8
  52. data/lib/nokogiri/xml/document.rb +31 -11
  53. data/lib/nokogiri/xml/node.rb +38 -42
  54. data/lib/nokogiri/xml/reader.rb +2 -9
  55. data/lib/nokogiri/xml/xpath.rb +1 -3
  56. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  57. metadata +7 -41
  58. data/ext/nokogiri/html_document.h +0 -10
  59. data/ext/nokogiri/html_element_description.h +0 -10
  60. data/ext/nokogiri/html_entity_lookup.h +0 -8
  61. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  62. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  63. data/ext/nokogiri/xml_attr.h +0 -9
  64. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  65. data/ext/nokogiri/xml_cdata.h +0 -9
  66. data/ext/nokogiri/xml_comment.h +0 -9
  67. data/ext/nokogiri/xml_document.h +0 -23
  68. data/ext/nokogiri/xml_document_fragment.h +0 -10
  69. data/ext/nokogiri/xml_dtd.h +0 -10
  70. data/ext/nokogiri/xml_element_content.h +0 -10
  71. data/ext/nokogiri/xml_element_decl.h +0 -9
  72. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  73. data/ext/nokogiri/xml_entity_decl.h +0 -10
  74. data/ext/nokogiri/xml_entity_reference.h +0 -9
  75. data/ext/nokogiri/xml_io.c +0 -63
  76. data/ext/nokogiri/xml_io.h +0 -11
  77. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  78. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  79. data/ext/nokogiri/xml_namespace.h +0 -14
  80. data/ext/nokogiri/xml_node.h +0 -13
  81. data/ext/nokogiri/xml_node_set.h +0 -12
  82. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  83. data/ext/nokogiri/xml_reader.h +0 -10
  84. data/ext/nokogiri/xml_relax_ng.h +0 -9
  85. data/ext/nokogiri/xml_sax_parser.h +0 -39
  86. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  87. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  88. data/ext/nokogiri/xml_schema.h +0 -9
  89. data/ext/nokogiri/xml_syntax_error.h +0 -25
  90. data/ext/nokogiri/xml_text.h +0 -9
  91. data/ext/nokogiri/xml_xpath_context.h +0 -10
  92. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -1,4 +1,6 @@
1
- #include <xml_syntax_error.h>
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriXmlSyntaxError;
2
4
 
3
5
  void
4
6
  Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state)
@@ -10,8 +12,8 @@ Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_s
10
12
 
11
13
  void
12
14
  Nokogiri_structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state,
13
- void *user_data,
14
- xmlStructuredErrorFunc handler)
15
+ void *user_data,
16
+ xmlStructuredErrorFunc handler)
15
17
  {
16
18
  Nokogiri_structured_error_func_save(handler_state);
17
19
  xmlSetStructuredErrorFunc(user_data, handler);
@@ -23,39 +25,40 @@ Nokogiri_structured_error_func_restore(libxmlStructuredErrorHandlerState *handle
23
25
  xmlSetStructuredErrorFunc(handler_state->user_data, handler_state->handler);
24
26
  }
25
27
 
26
- void Nokogiri_error_array_pusher(void * ctx, xmlErrorPtr error)
28
+ void
29
+ Nokogiri_error_array_pusher(void *ctx, xmlErrorPtr error)
27
30
  {
28
31
  VALUE list = (VALUE)ctx;
29
32
  Check_Type(list, T_ARRAY);
30
33
  rb_ary_push(list, Nokogiri_wrap_xml_syntax_error(error));
31
34
  }
32
35
 
33
- void Nokogiri_error_raise(void * ctx, xmlErrorPtr error)
36
+ void
37
+ Nokogiri_error_raise(void *ctx, xmlErrorPtr error)
34
38
  {
35
39
  rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
36
40
  }
37
41
 
38
- VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error)
42
+ VALUE
43
+ Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error)
39
44
  {
40
45
  VALUE msg, e, klass;
41
46
 
42
47
  klass = cNokogiriXmlSyntaxError;
43
48
 
44
49
  if (error && error->domain == XML_FROM_XPATH) {
45
- VALUE xpath = rb_const_get(mNokogiriXml, rb_intern("XPath"));
46
- klass = rb_const_get(xpath, rb_intern("SyntaxError"));
50
+ klass = cNokogiriXmlXpathSyntaxError;
47
51
  }
48
52
 
49
53
  msg = (error && error->message) ? NOKOGIRI_STR_NEW2(error->message) : Qnil;
50
54
 
51
55
  e = rb_class_new_instance(
52
- 1,
53
- &msg,
54
- klass
55
- );
56
+ 1,
57
+ &msg,
58
+ klass
59
+ );
56
60
 
57
- if (error)
58
- {
61
+ if (error) {
59
62
  rb_iv_set(e, "@domain", INT2NUM(error->domain));
60
63
  rb_iv_set(e, "@code", INT2NUM(error->code));
61
64
  rb_iv_set(e, "@level", INT2NUM((short)error->level));
@@ -71,17 +74,12 @@ VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error)
71
74
  return e;
72
75
  }
73
76
 
74
- VALUE cNokogiriXmlSyntaxError;
75
- void init_xml_syntax_error()
77
+ void
78
+ noko_init_xml_syntax_error()
76
79
  {
77
- VALUE nokogiri = rb_define_module("Nokogiri");
78
- VALUE xml = rb_define_module_under(nokogiri, "XML");
79
-
80
+ assert(cNokogiriSyntaxError);
80
81
  /*
81
82
  * The XML::SyntaxError is raised on parse errors
82
83
  */
83
- VALUE syntax_error_mommy = rb_define_class_under(nokogiri, "SyntaxError", rb_eStandardError);
84
- VALUE klass = rb_define_class_under(xml, "SyntaxError", syntax_error_mommy);
85
- cNokogiriXmlSyntaxError = klass;
86
-
84
+ cNokogiriXmlSyntaxError = rb_define_class_under(mNokogiriXml, "SyntaxError", cNokogiriSyntaxError);
87
85
  }
@@ -1,4 +1,6 @@
1
- #include <xml_text.h>
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriXmlText ;
2
4
 
3
5
  /*
4
6
  * call-seq:
@@ -6,7 +8,8 @@
6
8
  *
7
9
  * Create a new Text element on the +document+ with +content+
8
10
  */
9
- static VALUE new(int argc, VALUE *argv, VALUE klass)
11
+ static VALUE
12
+ new (int argc, VALUE *argv, VALUE klass)
10
13
  {
11
14
  xmlDocPtr doc;
12
15
  xmlNodePtr node;
@@ -22,31 +25,24 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
22
25
  node = xmlNewText((xmlChar *)StringValueCStr(string));
23
26
  node->doc = doc->doc;
24
27
 
25
- nokogiri_root_node(node);
28
+ noko_xml_document_pin_node(node);
26
29
 
27
- rb_node = Nokogiri_wrap_xml_node(klass, node) ;
30
+ rb_node = noko_xml_node_wrap(klass, node) ;
28
31
  rb_obj_call_init(rb_node, argc, argv);
29
32
 
30
- if(rb_block_given_p()) rb_yield(rb_node);
33
+ if (rb_block_given_p()) { rb_yield(rb_node); }
31
34
 
32
35
  return rb_node;
33
36
  }
34
37
 
35
- VALUE cNokogiriXmlText ;
36
- void init_xml_text()
38
+ void
39
+ noko_init_xml_text()
37
40
  {
38
- VALUE nokogiri = rb_define_module("Nokogiri");
39
- VALUE xml = rb_define_module_under(nokogiri, "XML");
40
- /* */
41
- VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
42
- VALUE char_data = rb_define_class_under(xml, "CharacterData", node);
43
-
41
+ assert(cNokogiriXmlCharacterData);
44
42
  /*
45
43
  * Wraps Text nodes.
46
44
  */
47
- VALUE klass = rb_define_class_under(xml, "Text", char_data);
48
-
49
- cNokogiriXmlText = klass;
45
+ cNokogiriXmlText = rb_define_class_under(mNokogiriXml, "Text", cNokogiriXmlCharacterData);
50
46
 
51
- rb_define_singleton_method(klass, "new", new, -1);
47
+ rb_define_singleton_method(cNokogiriXmlText, "new", new, -1);
52
48
  }
@@ -1,4 +1,6 @@
1
- #include <xml_xpath_context.h>
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriXmlXpathContext;
2
4
 
3
5
  /*
4
6
  * these constants have matching declarations in
@@ -7,7 +9,8 @@
7
9
  static const xmlChar *NOKOGIRI_BUILTIN_PREFIX = (const xmlChar *)"nokogiri-builtin";
8
10
  static const xmlChar *NOKOGIRI_BUILTIN_URI = (const xmlChar *)"https://www.nokogiri.org/default_ns/ruby/builtins";
9
11
 
10
- static void deallocate(xmlXPathContextPtr ctx)
12
+ static void
13
+ deallocate(xmlXPathContextPtr ctx)
11
14
  {
12
15
  NOKOGIRI_DEBUG_START(ctx);
13
16
  xmlXPathFreeContext(ctx);
@@ -15,23 +18,24 @@ static void deallocate(xmlXPathContextPtr ctx)
15
18
  }
16
19
 
17
20
  /* find a CSS class in an HTML element's `class` attribute */
18
- const xmlChar* builtin_css_class(const xmlChar* str, const xmlChar *val)
21
+ static const xmlChar *
22
+ builtin_css_class(const xmlChar *str, const xmlChar *val)
19
23
  {
20
24
  int val_len;
21
25
 
22
- if (str == NULL) { return(NULL); }
23
- if (val == NULL) { return(NULL); }
26
+ if (str == NULL) { return (NULL); }
27
+ if (val == NULL) { return (NULL); }
24
28
 
25
29
  val_len = xmlStrlen(val);
26
- if (val_len == 0) { return(str); }
30
+ if (val_len == 0) { return (str); }
27
31
 
28
32
  while (*str != 0) {
29
33
  if ((*str == *val) && !xmlStrncmp(str, val, val_len)) {
30
- const xmlChar* next_byte = str + val_len;
34
+ const xmlChar *next_byte = str + val_len;
31
35
 
32
36
  /* only match if the next byte is whitespace or end of string */
33
37
  if ((*next_byte == 0) || (IS_BLANK_CH(*next_byte))) {
34
- return((const xmlChar*)str);
38
+ return ((const xmlChar *)str);
35
39
  }
36
40
  }
37
41
 
@@ -46,11 +50,12 @@ const xmlChar* builtin_css_class(const xmlChar* str, const xmlChar *val)
46
50
  }
47
51
  }
48
52
 
49
- return(NULL);
53
+ return (NULL);
50
54
  }
51
55
 
52
56
  /* xmlXPathFunction to wrap builtin_css_class() */
53
- static void xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
57
+ static void
58
+ xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
54
59
  {
55
60
  xmlXPathObjectPtr hay, needle;
56
61
 
@@ -87,15 +92,16 @@ static void xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
87
92
  *
88
93
  * Register the namespace with +prefix+ and +uri+.
89
94
  */
90
- static VALUE register_ns(VALUE self, VALUE prefix, VALUE uri)
95
+ static VALUE
96
+ register_ns(VALUE self, VALUE prefix, VALUE uri)
91
97
  {
92
98
  xmlXPathContextPtr ctx;
93
99
  Data_Get_Struct(self, xmlXPathContext, ctx);
94
100
 
95
- xmlXPathRegisterNs( ctx,
96
- (const xmlChar *)StringValueCStr(prefix),
97
- (const xmlChar *)StringValueCStr(uri)
98
- );
101
+ xmlXPathRegisterNs(ctx,
102
+ (const xmlChar *)StringValueCStr(prefix),
103
+ (const xmlChar *)StringValueCStr(uri)
104
+ );
99
105
  return self;
100
106
  }
101
107
 
@@ -105,23 +111,26 @@ static VALUE register_ns(VALUE self, VALUE prefix, VALUE uri)
105
111
  *
106
112
  * Register the variable +name+ with +value+.
107
113
  */
108
- static VALUE register_variable(VALUE self, VALUE name, VALUE value)
114
+ static VALUE
115
+ register_variable(VALUE self, VALUE name, VALUE value)
109
116
  {
110
- xmlXPathContextPtr ctx;
111
- xmlXPathObjectPtr xmlValue;
112
- Data_Get_Struct(self, xmlXPathContext, ctx);
117
+ xmlXPathContextPtr ctx;
118
+ xmlXPathObjectPtr xmlValue;
119
+ Data_Get_Struct(self, xmlXPathContext, ctx);
113
120
 
114
- xmlValue = xmlXPathNewCString(StringValueCStr(value));
121
+ xmlValue = xmlXPathNewCString(StringValueCStr(value));
115
122
 
116
- xmlXPathRegisterVariable( ctx,
117
- (const xmlChar *)StringValueCStr(name),
118
- xmlValue
119
- );
123
+ xmlXPathRegisterVariable(ctx,
124
+ (const xmlChar *)StringValueCStr(name),
125
+ xmlValue
126
+ );
120
127
 
121
- return self;
128
+ return self;
122
129
  }
123
130
 
124
- void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler, const char* function_name)
131
+ void
132
+ Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler,
133
+ const char *function_name)
125
134
  {
126
135
  int i;
127
136
  VALUE result, doc;
@@ -144,76 +153,76 @@ void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr c
144
153
  i = nargs - 1;
145
154
  do {
146
155
  obj = valuePop(ctx);
147
- switch(obj->type) {
148
- case XPATH_STRING:
149
- argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
150
- break;
151
- case XPATH_BOOLEAN:
152
- argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
153
- break;
154
- case XPATH_NUMBER:
155
- argv[i] = rb_float_new(obj->floatval);
156
- break;
157
- case XPATH_NODESET:
158
- argv[i] = Nokogiri_wrap_xml_node_set(obj->nodesetval, doc);
159
- break;
160
- default:
161
- argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
156
+ switch (obj->type) {
157
+ case XPATH_STRING:
158
+ argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
159
+ break;
160
+ case XPATH_BOOLEAN:
161
+ argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
162
+ break;
163
+ case XPATH_NUMBER:
164
+ argv[i] = rb_float_new(obj->floatval);
165
+ break;
166
+ case XPATH_NODESET:
167
+ argv[i] = noko_xml_node_set_wrap(obj->nodesetval, doc);
168
+ break;
169
+ default:
170
+ argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
162
171
  }
163
172
  xmlXPathFreeNodeSetList(obj);
164
- } while(i-- > 0);
173
+ } while (i-- > 0);
165
174
  }
166
175
 
167
- result = rb_funcall2(handler, rb_intern((const char*)function_name), nargs, argv);
176
+ result = rb_funcall2(handler, rb_intern((const char *)function_name), nargs, argv);
168
177
 
169
178
  for (i = 0 ; i < nargs ; ++i) {
170
179
  rb_gc_unregister_address(&argv[i]);
171
180
  }
172
181
  free(argv);
173
182
 
174
- switch(TYPE(result)) {
175
- case T_FLOAT:
176
- case T_BIGNUM:
177
- case T_FIXNUM:
178
- xmlXPathReturnNumber(ctx, NUM2DBL(result));
179
- break;
180
- case T_STRING:
181
- xmlXPathReturnString(
182
- ctx,
183
- xmlCharStrdup(StringValueCStr(result))
184
- );
185
- break;
186
- case T_TRUE:
187
- xmlXPathReturnTrue(ctx);
188
- break;
189
- case T_FALSE:
190
- xmlXPathReturnFalse(ctx);
191
- break;
192
- case T_NIL:
193
- break;
194
- case T_ARRAY:
195
- {
196
- VALUE args[2];
197
- args[0] = doc;
198
- args[1] = result;
199
- node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
200
- Data_Get_Struct(node_set, xmlNodeSet, xml_node_set);
201
- xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
202
- }
183
+ switch (TYPE(result)) {
184
+ case T_FLOAT:
185
+ case T_BIGNUM:
186
+ case T_FIXNUM:
187
+ xmlXPathReturnNumber(ctx, NUM2DBL(result));
203
188
  break;
204
- case T_DATA:
205
- if(rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
206
- Data_Get_Struct(result, xmlNodeSet, xml_node_set);
207
- /* Copy the node set, otherwise it will get GC'd. */
208
- xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
209
- break;
210
- }
211
- default:
212
- rb_raise(rb_eRuntimeError, "Invalid return type");
189
+ case T_STRING:
190
+ xmlXPathReturnString(
191
+ ctx,
192
+ xmlCharStrdup(StringValueCStr(result))
193
+ );
194
+ break;
195
+ case T_TRUE:
196
+ xmlXPathReturnTrue(ctx);
197
+ break;
198
+ case T_FALSE:
199
+ xmlXPathReturnFalse(ctx);
200
+ break;
201
+ case T_NIL:
202
+ break;
203
+ case T_ARRAY: {
204
+ VALUE args[2];
205
+ args[0] = doc;
206
+ args[1] = result;
207
+ node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
208
+ Data_Get_Struct(node_set, xmlNodeSet, xml_node_set);
209
+ xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
210
+ }
211
+ break;
212
+ case T_DATA:
213
+ if (rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
214
+ Data_Get_Struct(result, xmlNodeSet, xml_node_set);
215
+ /* Copy the node set, otherwise it will get GC'd. */
216
+ xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
217
+ break;
213
218
  }
219
+ default:
220
+ rb_raise(rb_eRuntimeError, "Invalid return type");
221
+ }
214
222
  }
215
223
 
216
- static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
224
+ static void
225
+ ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
217
226
  {
218
227
  VALUE handler = Qnil;
219
228
  const char *function = NULL ;
@@ -224,26 +233,29 @@ static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
224
233
  assert(ctx->context->function);
225
234
 
226
235
  handler = (VALUE)(ctx->context->userData);
227
- function = (const char*)(ctx->context->function);
236
+ function = (const char *)(ctx->context->function);
228
237
 
229
238
  Nokogiri_marshal_xpath_funcall_and_return_values(ctx, nargs, handler, function);
230
239
  }
231
240
 
232
- static xmlXPathFunction lookup( void *ctx,
233
- const xmlChar * name,
234
- const xmlChar* ns_uri )
241
+ static xmlXPathFunction
242
+ lookup(void *ctx,
243
+ const xmlChar *name,
244
+ const xmlChar *ns_uri)
235
245
  {
236
246
  VALUE xpath_handler = (VALUE)ctx;
237
- if(rb_respond_to(xpath_handler, rb_intern((const char *)name)))
247
+ if (rb_respond_to(xpath_handler, rb_intern((const char *)name))) {
238
248
  return ruby_funcall;
249
+ }
239
250
 
240
251
  return NULL;
241
252
  }
242
253
 
243
- NORETURN(static void xpath_generic_exception_handler(void * ctx, const char *msg, ...));
244
- static void xpath_generic_exception_handler(void * ctx, const char *msg, ...)
254
+ NORETURN(static void xpath_generic_exception_handler(void *ctx, const char *msg, ...));
255
+ static void
256
+ xpath_generic_exception_handler(void *ctx, const char *msg, ...)
245
257
  {
246
- char * message;
258
+ char *message;
247
259
 
248
260
  va_list args;
249
261
  va_start(args, msg);
@@ -259,7 +271,8 @@ static void xpath_generic_exception_handler(void * ctx, const char *msg, ...)
259
271
  *
260
272
  * Evaluate the +search_path+ returning an XML::XPath object.
261
273
  */
262
- static VALUE evaluate(int argc, VALUE *argv, VALUE self)
274
+ static VALUE
275
+ evaluate(int argc, VALUE *argv, VALUE self)
263
276
  {
264
277
  VALUE search_path, xpath_handler;
265
278
  VALUE thing = Qnil;
@@ -269,12 +282,13 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
269
282
 
270
283
  Data_Get_Struct(self, xmlXPathContext, ctx);
271
284
 
272
- if(rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1)
285
+ if (rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1) {
273
286
  xpath_handler = Qnil;
287
+ }
274
288
 
275
289
  query = (xmlChar *)StringValueCStr(search_path);
276
290
 
277
- if(Qnil != xpath_handler) {
291
+ if (Qnil != xpath_handler) {
278
292
  /* FIXME: not sure if this is the correct place to shove private data. */
279
293
  ctx->userData = (void *)xpath_handler;
280
294
  xmlXPathRegisterFuncLookup(ctx, lookup, (void *)xpath_handler);
@@ -291,7 +305,7 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
291
305
  xmlSetStructuredErrorFunc(NULL, NULL);
292
306
  xmlSetGenericErrorFunc(NULL, NULL);
293
307
 
294
- if(xpath == NULL) {
308
+ if (xpath == NULL) {
295
309
  xmlErrorPtr error = xmlGetLastError();
296
310
  rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
297
311
  }
@@ -299,23 +313,23 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
299
313
  assert(ctx->doc);
300
314
  assert(DOC_RUBY_OBJECT_TEST(ctx->doc));
301
315
 
302
- switch(xpath->type) {
303
- case XPATH_STRING:
304
- thing = NOKOGIRI_STR_NEW2(xpath->stringval);
305
- xmlFree(xpath->stringval);
306
- break;
307
- case XPATH_NODESET:
308
- thing = Nokogiri_wrap_xml_node_set(xpath->nodesetval,
309
- DOC_RUBY_OBJECT(ctx->doc));
310
- break;
311
- case XPATH_NUMBER:
312
- thing = rb_float_new(xpath->floatval);
313
- break;
314
- case XPATH_BOOLEAN:
315
- thing = xpath->boolval == 1 ? Qtrue : Qfalse;
316
- break;
317
- default:
318
- thing = Nokogiri_wrap_xml_node_set(NULL, DOC_RUBY_OBJECT(ctx->doc));
316
+ switch (xpath->type) {
317
+ case XPATH_STRING:
318
+ thing = NOKOGIRI_STR_NEW2(xpath->stringval);
319
+ xmlFree(xpath->stringval);
320
+ break;
321
+ case XPATH_NODESET:
322
+ thing = noko_xml_node_set_wrap(xpath->nodesetval,
323
+ DOC_RUBY_OBJECT(ctx->doc));
324
+ break;
325
+ case XPATH_NUMBER:
326
+ thing = rb_float_new(xpath->floatval);
327
+ break;
328
+ case XPATH_BOOLEAN:
329
+ thing = xpath->boolval == 1 ? Qtrue : Qfalse;
330
+ break;
331
+ default:
332
+ thing = noko_xml_node_set_wrap(NULL, DOC_RUBY_OBJECT(ctx->doc));
319
333
  }
320
334
 
321
335
  xmlXPathFreeNodeSetList(xpath);
@@ -329,7 +343,8 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
329
343
  *
330
344
  * Create a new XPathContext with +node+ as the reference point.
331
345
  */
332
- static VALUE new(VALUE klass, VALUE nodeobj)
346
+ static VALUE
347
+ new (VALUE klass, VALUE nodeobj)
333
348
  {
334
349
  xmlNodePtr node;
335
350
  xmlXPathContextPtr ctx;
@@ -350,25 +365,17 @@ static VALUE new(VALUE klass, VALUE nodeobj)
350
365
  return self;
351
366
  }
352
367
 
353
- VALUE cNokogiriXmlXpathContext;
354
- void init_xml_xpath_context(void)
368
+ void
369
+ noko_init_xml_xpath_context(void)
355
370
  {
356
- VALUE module = rb_define_module("Nokogiri");
357
-
358
- /*
359
- * Nokogiri::XML
360
- */
361
- VALUE xml = rb_define_module_under(module, "XML");
362
-
363
371
  /*
364
372
  * XPathContext is the entry point for searching a Document by using XPath.
365
373
  */
366
- VALUE klass = rb_define_class_under(xml, "XPathContext", rb_cObject);
374
+ cNokogiriXmlXpathContext = rb_define_class_under(mNokogiriXml, "XPathContext", rb_cObject);
367
375
 
368
- cNokogiriXmlXpathContext = klass;
376
+ rb_define_singleton_method(cNokogiriXmlXpathContext, "new", new, 1);
369
377
 
370
- rb_define_singleton_method(klass, "new", new, 1);
371
- rb_define_method(klass, "evaluate", evaluate, -1);
372
- rb_define_method(klass, "register_variable", register_variable, 2);
373
- rb_define_method(klass, "register_ns", register_ns, 2);
378
+ rb_define_method(cNokogiriXmlXpathContext, "evaluate", evaluate, -1);
379
+ rb_define_method(cNokogiriXmlXpathContext, "register_variable", register_variable, 2);
380
+ rb_define_method(cNokogiriXmlXpathContext, "register_ns", register_ns, 2);
374
381
  }