nokogiri 1.11.1-java → 1.11.6-java

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 (143) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +12 -12
  3. data/LICENSE.md +1 -1
  4. data/README.md +21 -16
  5. data/dependencies.yml +12 -12
  6. data/ext/java/nokogiri/EncodingHandler.java +76 -89
  7. data/ext/java/nokogiri/HtmlDocument.java +135 -144
  8. data/ext/java/nokogiri/HtmlElementDescription.java +102 -117
  9. data/ext/java/nokogiri/HtmlEntityLookup.java +33 -60
  10. data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -222
  11. data/ext/java/nokogiri/HtmlSaxPushParser.java +162 -169
  12. data/ext/java/nokogiri/NokogiriService.java +595 -556
  13. data/ext/java/nokogiri/XmlAttr.java +118 -126
  14. data/ext/java/nokogiri/XmlAttributeDecl.java +95 -106
  15. data/ext/java/nokogiri/XmlCdata.java +35 -58
  16. data/ext/java/nokogiri/XmlComment.java +46 -67
  17. data/ext/java/nokogiri/XmlDocument.java +645 -572
  18. data/ext/java/nokogiri/XmlDocumentFragment.java +125 -137
  19. data/ext/java/nokogiri/XmlDtd.java +448 -414
  20. data/ext/java/nokogiri/XmlElement.java +23 -48
  21. data/ext/java/nokogiri/XmlElementContent.java +343 -316
  22. data/ext/java/nokogiri/XmlElementDecl.java +124 -125
  23. data/ext/java/nokogiri/XmlEntityDecl.java +119 -127
  24. data/ext/java/nokogiri/XmlEntityReference.java +49 -72
  25. data/ext/java/nokogiri/XmlNamespace.java +175 -175
  26. data/ext/java/nokogiri/XmlNode.java +1843 -1620
  27. data/ext/java/nokogiri/XmlNodeSet.java +361 -331
  28. data/ext/java/nokogiri/XmlProcessingInstruction.java +47 -69
  29. data/ext/java/nokogiri/XmlReader.java +513 -450
  30. data/ext/java/nokogiri/XmlRelaxng.java +85 -104
  31. data/ext/java/nokogiri/XmlSaxParserContext.java +328 -315
  32. data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
  33. data/ext/java/nokogiri/XmlSchema.java +328 -295
  34. data/ext/java/nokogiri/XmlSyntaxError.java +113 -115
  35. data/ext/java/nokogiri/XmlText.java +55 -76
  36. data/ext/java/nokogiri/XmlXpathContext.java +240 -238
  37. data/ext/java/nokogiri/XsltStylesheet.java +280 -269
  38. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  39. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +201 -202
  40. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  41. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  42. data/ext/java/nokogiri/internals/NokogiriDomParser.java +63 -80
  43. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  44. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +27 -52
  45. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -286
  46. data/ext/java/nokogiri/internals/NokogiriHelpers.java +736 -652
  47. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +184 -173
  48. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +81 -98
  49. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +64 -79
  50. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +84 -99
  51. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +48 -65
  52. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +116 -131
  53. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -56
  54. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +23 -46
  55. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +55 -72
  56. data/ext/java/nokogiri/internals/ParserContext.java +206 -211
  57. data/ext/java/nokogiri/internals/ReaderNode.java +478 -403
  58. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -739
  59. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +31 -54
  60. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  61. data/ext/java/nokogiri/internals/XmlDeclHandler.java +3 -34
  62. data/ext/java/nokogiri/internals/XmlDomParserContext.java +206 -207
  63. data/ext/java/nokogiri/internals/XmlSaxParser.java +22 -47
  64. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  65. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  66. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  67. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  68. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  77. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  78. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  80. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  81. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  82. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  83. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  84. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  85. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  86. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  87. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  88. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  89. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  90. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  91. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  92. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -574
  93. data/ext/nokogiri/depend +34 -474
  94. data/ext/nokogiri/extconf.rb +253 -183
  95. data/ext/nokogiri/html_document.c +10 -15
  96. data/ext/nokogiri/html_element_description.c +84 -71
  97. data/ext/nokogiri/html_entity_lookup.c +21 -16
  98. data/ext/nokogiri/html_sax_parser_context.c +66 -65
  99. data/ext/nokogiri/html_sax_push_parser.c +29 -27
  100. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  101. data/ext/nokogiri/nokogiri.c +190 -63
  102. data/ext/nokogiri/test_global_handlers.c +3 -4
  103. data/ext/nokogiri/xml_attr.c +15 -15
  104. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  105. data/ext/nokogiri/xml_cdata.c +13 -18
  106. data/ext/nokogiri/xml_comment.c +19 -26
  107. data/ext/nokogiri/xml_document.c +246 -188
  108. data/ext/nokogiri/xml_document_fragment.c +13 -15
  109. data/ext/nokogiri/xml_dtd.c +54 -48
  110. data/ext/nokogiri/xml_element_content.c +30 -27
  111. data/ext/nokogiri/xml_element_decl.c +22 -22
  112. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  113. data/ext/nokogiri/xml_entity_decl.c +32 -30
  114. data/ext/nokogiri/xml_entity_reference.c +16 -18
  115. data/ext/nokogiri/xml_namespace.c +56 -49
  116. data/ext/nokogiri/xml_node.c +385 -326
  117. data/ext/nokogiri/xml_node_set.c +168 -156
  118. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  119. data/ext/nokogiri/xml_reader.c +191 -157
  120. data/ext/nokogiri/xml_relax_ng.c +29 -23
  121. data/ext/nokogiri/xml_sax_parser.c +117 -112
  122. data/ext/nokogiri/xml_sax_parser_context.c +100 -85
  123. data/ext/nokogiri/xml_sax_push_parser.c +34 -27
  124. data/ext/nokogiri/xml_schema.c +48 -42
  125. data/ext/nokogiri/xml_syntax_error.c +21 -23
  126. data/ext/nokogiri/xml_text.c +13 -17
  127. data/ext/nokogiri/xml_xpath_context.c +134 -127
  128. data/ext/nokogiri/xslt_stylesheet.c +157 -157
  129. data/lib/nokogiri.rb +1 -22
  130. data/lib/nokogiri/css/parser.rb +1 -1
  131. data/lib/nokogiri/extension.rb +26 -0
  132. data/lib/nokogiri/html/document_fragment.rb +15 -15
  133. data/lib/nokogiri/nokogiri.jar +0 -0
  134. data/lib/nokogiri/version/constant.rb +1 -1
  135. data/lib/nokogiri/version/info.rb +32 -8
  136. data/lib/nokogiri/xml/document.rb +74 -28
  137. data/lib/nokogiri/xml/node.rb +39 -42
  138. data/lib/nokogiri/xml/reader.rb +2 -9
  139. data/lib/nokogiri/xml/xpath.rb +1 -3
  140. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  141. metadata +7 -8
  142. data/ext/nokogiri/xml_io.c +0 -63
  143. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
@@ -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
  }