nokogiri 1.11.0.rc3-java → 1.11.4-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 (187) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1015 -947
  4. data/LICENSE.md +1 -1
  5. data/README.md +168 -91
  6. data/dependencies.yml +12 -12
  7. data/ext/java/nokogiri/EncodingHandler.java +76 -89
  8. data/ext/java/nokogiri/HtmlDocument.java +135 -144
  9. data/ext/java/nokogiri/HtmlElementDescription.java +102 -117
  10. data/ext/java/nokogiri/HtmlEntityLookup.java +33 -60
  11. data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -222
  12. data/ext/java/nokogiri/HtmlSaxPushParser.java +162 -169
  13. data/ext/java/nokogiri/NokogiriService.java +595 -556
  14. data/ext/java/nokogiri/XmlAttr.java +118 -126
  15. data/ext/java/nokogiri/XmlAttributeDecl.java +95 -106
  16. data/ext/java/nokogiri/XmlCdata.java +35 -58
  17. data/ext/java/nokogiri/XmlComment.java +46 -67
  18. data/ext/java/nokogiri/XmlDocument.java +645 -572
  19. data/ext/java/nokogiri/XmlDocumentFragment.java +125 -137
  20. data/ext/java/nokogiri/XmlDtd.java +448 -414
  21. data/ext/java/nokogiri/XmlElement.java +23 -48
  22. data/ext/java/nokogiri/XmlElementContent.java +343 -316
  23. data/ext/java/nokogiri/XmlElementDecl.java +124 -125
  24. data/ext/java/nokogiri/XmlEntityDecl.java +119 -127
  25. data/ext/java/nokogiri/XmlEntityReference.java +49 -72
  26. data/ext/java/nokogiri/XmlNamespace.java +175 -175
  27. data/ext/java/nokogiri/XmlNode.java +1843 -1622
  28. data/ext/java/nokogiri/XmlNodeSet.java +361 -331
  29. data/ext/java/nokogiri/XmlProcessingInstruction.java +47 -69
  30. data/ext/java/nokogiri/XmlReader.java +513 -450
  31. data/ext/java/nokogiri/XmlRelaxng.java +89 -101
  32. data/ext/java/nokogiri/XmlSaxParserContext.java +328 -310
  33. data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
  34. data/ext/java/nokogiri/XmlSchema.java +335 -242
  35. data/ext/java/nokogiri/XmlSyntaxError.java +113 -119
  36. data/ext/java/nokogiri/XmlText.java +55 -76
  37. data/ext/java/nokogiri/XmlXpathContext.java +242 -210
  38. data/ext/java/nokogiri/XsltStylesheet.java +280 -269
  39. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  40. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +201 -190
  41. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  42. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  43. data/ext/java/nokogiri/internals/NokogiriDomParser.java +63 -80
  44. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  45. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +27 -52
  46. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -286
  47. data/ext/java/nokogiri/internals/NokogiriHelpers.java +736 -652
  48. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +184 -173
  49. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +79 -89
  50. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +64 -79
  51. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +84 -99
  52. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +48 -65
  53. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +119 -78
  54. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -54
  55. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +23 -46
  56. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +55 -72
  57. data/ext/java/nokogiri/internals/ParserContext.java +206 -211
  58. data/ext/java/nokogiri/internals/ReaderNode.java +478 -403
  59. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -739
  60. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +31 -54
  61. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  62. data/ext/java/nokogiri/internals/XmlDeclHandler.java +3 -34
  63. data/ext/java/nokogiri/internals/XmlDomParserContext.java +206 -207
  64. data/ext/java/nokogiri/internals/XmlSaxParser.java +22 -47
  65. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  66. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  67. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  68. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  77. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  78. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  80. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  81. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  82. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  83. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  84. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  85. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  86. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  87. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  88. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  89. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  90. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  91. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  92. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  93. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -574
  94. data/ext/nokogiri/depend +37 -358
  95. data/ext/nokogiri/extconf.rb +581 -374
  96. data/ext/nokogiri/html_document.c +78 -82
  97. data/ext/nokogiri/html_element_description.c +84 -71
  98. data/ext/nokogiri/html_entity_lookup.c +21 -16
  99. data/ext/nokogiri/html_sax_parser_context.c +69 -66
  100. data/ext/nokogiri/html_sax_push_parser.c +42 -34
  101. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  102. data/ext/nokogiri/nokogiri.c +192 -93
  103. data/ext/nokogiri/test_global_handlers.c +40 -0
  104. data/ext/nokogiri/xml_attr.c +15 -15
  105. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  106. data/ext/nokogiri/xml_cdata.c +13 -18
  107. data/ext/nokogiri/xml_comment.c +19 -26
  108. data/ext/nokogiri/xml_document.c +246 -188
  109. data/ext/nokogiri/xml_document_fragment.c +13 -15
  110. data/ext/nokogiri/xml_dtd.c +54 -48
  111. data/ext/nokogiri/xml_element_content.c +30 -27
  112. data/ext/nokogiri/xml_element_decl.c +22 -22
  113. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  114. data/ext/nokogiri/xml_entity_decl.c +32 -30
  115. data/ext/nokogiri/xml_entity_reference.c +16 -18
  116. data/ext/nokogiri/xml_namespace.c +56 -49
  117. data/ext/nokogiri/xml_node.c +371 -320
  118. data/ext/nokogiri/xml_node_set.c +168 -156
  119. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  120. data/ext/nokogiri/xml_reader.c +191 -157
  121. data/ext/nokogiri/xml_relax_ng.c +52 -28
  122. data/ext/nokogiri/xml_sax_parser.c +118 -118
  123. data/ext/nokogiri/xml_sax_parser_context.c +103 -86
  124. data/ext/nokogiri/xml_sax_push_parser.c +36 -27
  125. data/ext/nokogiri/xml_schema.c +95 -47
  126. data/ext/nokogiri/xml_syntax_error.c +42 -21
  127. data/ext/nokogiri/xml_text.c +13 -17
  128. data/ext/nokogiri/xml_xpath_context.c +206 -123
  129. data/ext/nokogiri/xslt_stylesheet.c +158 -161
  130. data/lib/nokogiri.rb +3 -7
  131. data/lib/nokogiri/css/parser.rb +3 -3
  132. data/lib/nokogiri/css/parser.y +2 -2
  133. data/lib/nokogiri/css/xpath_visitor.rb +70 -42
  134. data/lib/nokogiri/extension.rb +26 -0
  135. data/lib/nokogiri/html/document.rb +12 -26
  136. data/lib/nokogiri/html/document_fragment.rb +15 -15
  137. data/lib/nokogiri/nokogiri.jar +0 -0
  138. data/lib/nokogiri/version.rb +2 -149
  139. data/lib/nokogiri/version/constant.rb +5 -0
  140. data/lib/nokogiri/version/info.rb +205 -0
  141. data/lib/nokogiri/xml/document.rb +91 -35
  142. data/lib/nokogiri/xml/document_fragment.rb +4 -6
  143. data/lib/nokogiri/xml/node.rb +89 -69
  144. data/lib/nokogiri/xml/parse_options.rb +6 -0
  145. data/lib/nokogiri/xml/reader.rb +2 -9
  146. data/lib/nokogiri/xml/relax_ng.rb +6 -2
  147. data/lib/nokogiri/xml/schema.rb +12 -4
  148. data/lib/nokogiri/xml/searchable.rb +3 -1
  149. data/lib/nokogiri/xml/xpath.rb +1 -3
  150. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  151. metadata +86 -177
  152. data/ext/nokogiri/html_document.h +0 -10
  153. data/ext/nokogiri/html_element_description.h +0 -10
  154. data/ext/nokogiri/html_entity_lookup.h +0 -8
  155. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  156. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  157. data/ext/nokogiri/nokogiri.h +0 -134
  158. data/ext/nokogiri/xml_attr.h +0 -9
  159. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  160. data/ext/nokogiri/xml_cdata.h +0 -9
  161. data/ext/nokogiri/xml_comment.h +0 -9
  162. data/ext/nokogiri/xml_document.h +0 -23
  163. data/ext/nokogiri/xml_document_fragment.h +0 -10
  164. data/ext/nokogiri/xml_dtd.h +0 -10
  165. data/ext/nokogiri/xml_element_content.h +0 -10
  166. data/ext/nokogiri/xml_element_decl.h +0 -9
  167. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  168. data/ext/nokogiri/xml_entity_decl.h +0 -10
  169. data/ext/nokogiri/xml_entity_reference.h +0 -9
  170. data/ext/nokogiri/xml_io.c +0 -63
  171. data/ext/nokogiri/xml_io.h +0 -11
  172. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  173. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  174. data/ext/nokogiri/xml_namespace.h +0 -14
  175. data/ext/nokogiri/xml_node.h +0 -13
  176. data/ext/nokogiri/xml_node_set.h +0 -12
  177. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  178. data/ext/nokogiri/xml_reader.h +0 -10
  179. data/ext/nokogiri/xml_relax_ng.h +0 -9
  180. data/ext/nokogiri/xml_sax_parser.h +0 -39
  181. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  182. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  183. data/ext/nokogiri/xml_schema.h +0 -9
  184. data/ext/nokogiri/xml_syntax_error.h +0 -13
  185. data/ext/nokogiri/xml_text.h +0 -9
  186. data/ext/nokogiri/xml_xpath_context.h +0 -10
  187. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -1,6 +1,9 @@
1
- #include <html_document.h>
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriHtmlDocument ;
2
4
 
3
5
  static ID id_encoding_found;
6
+ static ID id_to_s;
4
7
 
5
8
  /*
6
9
  * call-seq:
@@ -8,21 +11,21 @@ static ID id_encoding_found;
8
11
  *
9
12
  * Create a new document
10
13
  */
11
- static VALUE new(int argc, VALUE *argv, VALUE klass)
14
+ static VALUE
15
+ rb_html_document_s_new(int argc, VALUE *argv, VALUE klass)
12
16
  {
13
17
  VALUE uri, external_id, rest, rb_doc;
14
18
  htmlDocPtr doc;
15
19
 
16
20
  rb_scan_args(argc, argv, "0*", &rest);
17
- uri = rb_ary_entry(rest, (long)0);
21
+ uri = rb_ary_entry(rest, (long)0);
18
22
  external_id = rb_ary_entry(rest, (long)1);
19
23
 
20
24
  doc = htmlNewDoc(
21
- RTEST(uri) ? (const xmlChar *)StringValueCStr(uri) : NULL,
22
- RTEST(external_id) ? (const xmlChar *)StringValueCStr(external_id) : NULL
23
- );
24
- rb_doc = Nokogiri_wrap_xml_document(klass, doc);
25
- rb_obj_call_init(rb_doc, argc, argv);
25
+ RTEST(uri) ? (const xmlChar *)StringValueCStr(uri) : NULL,
26
+ RTEST(external_id) ? (const xmlChar *)StringValueCStr(external_id) : NULL
27
+ );
28
+ rb_doc = noko_xml_document_wrap_with_init_args(klass, doc, argc, argv);
26
29
  return rb_doc ;
27
30
  }
28
31
 
@@ -33,60 +36,55 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
33
36
  * Read the HTML document from +io+ with given +url+, +encoding+,
34
37
  * and +options+. See Nokogiri::HTML.parse
35
38
  */
36
- static VALUE read_io( VALUE klass,
37
- VALUE io,
38
- VALUE url,
39
- VALUE encoding,
40
- VALUE options )
39
+ static VALUE
40
+ rb_html_document_s_read_io(VALUE klass, VALUE rb_io, VALUE rb_url, VALUE rb_encoding, VALUE rb_options)
41
41
  {
42
- const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
43
- const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
44
- VALUE error_list = rb_ary_new();
45
- VALUE document;
46
- htmlDocPtr doc;
42
+ VALUE rb_doc;
43
+ VALUE rb_error_list = rb_ary_new();
44
+ htmlDocPtr c_doc;
45
+ const char *c_url = NIL_P(rb_url) ? NULL : StringValueCStr(rb_url);
46
+ const char *c_encoding = NIL_P(rb_encoding) ? NULL : StringValueCStr(rb_encoding);
47
+ int options = NUM2INT(rb_options);
48
+
49
+ xmlSetStructuredErrorFunc((void *)rb_error_list, Nokogiri_error_array_pusher);
50
+
51
+ c_doc = htmlReadIO(noko_io_read, noko_io_close, (void *)rb_io, c_url, c_encoding, options);
47
52
 
48
- xmlResetLastError();
49
- xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
50
-
51
- doc = htmlReadIO(
52
- io_read_callback,
53
- io_close_callback,
54
- (void *)io,
55
- c_url,
56
- c_enc,
57
- (int)NUM2INT(options)
58
- );
59
53
  xmlSetStructuredErrorFunc(NULL, NULL);
60
54
 
61
55
  /*
62
56
  * If EncodingFound has occurred in EncodingReader, make sure to do
63
57
  * a cleanup and propagate the error.
64
58
  */
65
- if (rb_respond_to(io, id_encoding_found)) {
66
- VALUE encoding_found = rb_funcall(io, id_encoding_found, 0);
59
+ if (rb_respond_to(rb_io, id_encoding_found)) {
60
+ VALUE encoding_found = rb_funcall(rb_io, id_encoding_found, 0);
67
61
  if (!NIL_P(encoding_found)) {
68
- xmlFreeDoc(doc);
62
+ xmlFreeDoc(c_doc);
69
63
  rb_exc_raise(encoding_found);
70
64
  }
71
65
  }
72
66
 
73
- if(doc == NULL) {
74
- xmlErrorPtr error;
67
+ if ((c_doc == NULL) || (!(options & XML_PARSE_RECOVER) && (RARRAY_LEN(rb_error_list) > 0))) {
68
+ VALUE rb_error ;
75
69
 
76
- xmlFreeDoc(doc);
70
+ xmlFreeDoc(c_doc);
77
71
 
78
- error = xmlGetLastError();
79
- if(error)
80
- rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
81
- else
72
+ rb_error = rb_ary_entry(rb_error_list, 0);
73
+ if (rb_error == Qnil) {
82
74
  rb_raise(rb_eRuntimeError, "Could not parse document");
75
+ } else {
76
+ VALUE exception_message = rb_funcall(rb_error, id_to_s, 0);
77
+ exception_message = rb_str_concat(rb_str_new2("Parser without recover option encountered error or warning: "),
78
+ exception_message);
79
+ rb_exc_raise(rb_class_new_instance(1, &exception_message, cNokogiriXmlSyntaxError));
80
+ }
83
81
 
84
82
  return Qnil;
85
83
  }
86
84
 
87
- document = Nokogiri_wrap_xml_document(klass, doc);
88
- rb_iv_set(document, "@errors", error_list);
89
- return document;
85
+ rb_doc = noko_xml_document_wrap(klass, c_doc);
86
+ rb_iv_set(rb_doc, "@errors", rb_error_list);
87
+ return rb_doc;
90
88
  }
91
89
 
92
90
  /*
@@ -96,43 +94,45 @@ static VALUE read_io( VALUE klass,
96
94
  * Read the HTML document contained in +string+ with given +url+, +encoding+,
97
95
  * and +options+. See Nokogiri::HTML.parse
98
96
  */
99
- static VALUE read_memory( VALUE klass,
100
- VALUE string,
101
- VALUE url,
102
- VALUE encoding,
103
- VALUE options )
97
+ static VALUE
98
+ rb_html_document_s_read_memory(VALUE klass, VALUE rb_html, VALUE rb_url, VALUE rb_encoding, VALUE rb_options)
104
99
  {
105
- const char * c_buffer = StringValuePtr(string);
106
- const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
107
- const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
108
- int len = (int)RSTRING_LEN(string);
109
- VALUE error_list = rb_ary_new();
110
- VALUE document;
111
- htmlDocPtr doc;
100
+ VALUE rb_doc;
101
+ VALUE rb_error_list = rb_ary_new();
102
+ htmlDocPtr c_doc;
103
+ const char *c_buffer = StringValuePtr(rb_html);
104
+ const char *c_url = NIL_P(rb_url) ? NULL : StringValueCStr(rb_url);
105
+ const char *c_encoding = NIL_P(rb_encoding) ? NULL : StringValueCStr(rb_encoding);
106
+ int html_len = (int)RSTRING_LEN(rb_html);
107
+ int options = NUM2INT(rb_options);
108
+
109
+ xmlSetStructuredErrorFunc((void *)rb_error_list, Nokogiri_error_array_pusher);
112
110
 
113
- xmlResetLastError();
114
- xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
111
+ c_doc = htmlReadMemory(c_buffer, html_len, c_url, c_encoding, options);
115
112
 
116
- doc = htmlReadMemory(c_buffer, len, c_url, c_enc, (int)NUM2INT(options));
117
113
  xmlSetStructuredErrorFunc(NULL, NULL);
118
114
 
119
- if(doc == NULL) {
120
- xmlErrorPtr error;
115
+ if ((c_doc == NULL) || (!(options & XML_PARSE_RECOVER) && (RARRAY_LEN(rb_error_list) > 0))) {
116
+ VALUE rb_error ;
121
117
 
122
- xmlFreeDoc(doc);
118
+ xmlFreeDoc(c_doc);
123
119
 
124
- error = xmlGetLastError();
125
- if(error)
126
- rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
127
- else
120
+ rb_error = rb_ary_entry(rb_error_list, 0);
121
+ if (rb_error == Qnil) {
128
122
  rb_raise(rb_eRuntimeError, "Could not parse document");
123
+ } else {
124
+ VALUE exception_message = rb_funcall(rb_error, id_to_s, 0);
125
+ exception_message = rb_str_concat(rb_str_new2("Parser without recover option encountered error or warning: "),
126
+ exception_message);
127
+ rb_exc_raise(rb_class_new_instance(1, &exception_message, cNokogiriXmlSyntaxError));
128
+ }
129
129
 
130
130
  return Qnil;
131
131
  }
132
132
 
133
- document = Nokogiri_wrap_xml_document(klass, doc);
134
- rb_iv_set(document, "@errors", error_list);
135
- return document;
133
+ rb_doc = noko_xml_document_wrap(klass, c_doc);
134
+ rb_iv_set(rb_doc, "@errors", rb_error_list);
135
+ return rb_doc;
136
136
  }
137
137
 
138
138
  /*
@@ -141,30 +141,26 @@ static VALUE read_memory( VALUE klass,
141
141
  *
142
142
  * The type for this document
143
143
  */
144
- static VALUE type(VALUE self)
144
+ static VALUE
145
+ rb_html_document_type(VALUE self)
145
146
  {
146
147
  htmlDocPtr doc;
147
148
  Data_Get_Struct(self, xmlDoc, doc);
148
149
  return INT2NUM((long)doc->type);
149
150
  }
150
151
 
151
- VALUE cNokogiriHtmlDocument ;
152
- void init_html_document()
152
+ void
153
+ noko_init_html_document()
153
154
  {
154
- VALUE nokogiri = rb_define_module("Nokogiri");
155
- VALUE html = rb_define_module_under(nokogiri, "HTML");
156
- VALUE xml = rb_define_module_under(nokogiri, "XML");
157
- VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
158
- VALUE xml_doc = rb_define_class_under(xml, "Document", node);
159
- VALUE klass = rb_define_class_under(html, "Document", xml_doc);
160
-
161
- cNokogiriHtmlDocument = klass;
155
+ assert(cNokogiriXmlDocument);
156
+ cNokogiriHtmlDocument = rb_define_class_under(mNokogiriHtml, "Document", cNokogiriXmlDocument);
162
157
 
163
- rb_define_singleton_method(klass, "read_memory", read_memory, 4);
164
- rb_define_singleton_method(klass, "read_io", read_io, 4);
165
- rb_define_singleton_method(klass, "new", new, -1);
158
+ rb_define_singleton_method(cNokogiriHtmlDocument, "read_memory", rb_html_document_s_read_memory, 4);
159
+ rb_define_singleton_method(cNokogiriHtmlDocument, "read_io", rb_html_document_s_read_io, 4);
160
+ rb_define_singleton_method(cNokogiriHtmlDocument, "new", rb_html_document_s_new, -1);
166
161
 
167
- rb_define_method(klass, "type", type, 0);
162
+ rb_define_method(cNokogiriHtmlDocument, "type", rb_html_document_type, 0);
168
163
 
169
164
  id_encoding_found = rb_intern("encoding_found");
165
+ id_to_s = rb_intern("to_s");
170
166
  }
@@ -1,4 +1,6 @@
1
- #include <html_element_description.h>
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriHtmlElementDescription ;
2
4
 
3
5
  /*
4
6
  * call-seq:
@@ -6,9 +8,10 @@
6
8
  *
7
9
  * A list of required attributes for this element
8
10
  */
9
- static VALUE required_attributes(VALUE self)
11
+ static VALUE
12
+ required_attributes(VALUE self)
10
13
  {
11
- const htmlElemDesc * description;
14
+ const htmlElemDesc *description;
12
15
  VALUE list;
13
16
  int i;
14
17
 
@@ -16,9 +19,9 @@ static VALUE required_attributes(VALUE self)
16
19
 
17
20
  list = rb_ary_new();
18
21
 
19
- if(NULL == description->attrs_req) return list;
22
+ if (NULL == description->attrs_req) { return list; }
20
23
 
21
- for(i = 0; description->attrs_depr[i]; i++) {
24
+ for (i = 0; description->attrs_depr[i]; i++) {
22
25
  rb_ary_push(list, NOKOGIRI_STR_NEW2(description->attrs_req[i]));
23
26
  }
24
27
 
@@ -31,9 +34,10 @@ static VALUE required_attributes(VALUE self)
31
34
  *
32
35
  * A list of deprecated attributes for this element
33
36
  */
34
- static VALUE deprecated_attributes(VALUE self)
37
+ static VALUE
38
+ deprecated_attributes(VALUE self)
35
39
  {
36
- const htmlElemDesc * description;
40
+ const htmlElemDesc *description;
37
41
  VALUE list;
38
42
  int i;
39
43
 
@@ -41,9 +45,9 @@ static VALUE deprecated_attributes(VALUE self)
41
45
 
42
46
  list = rb_ary_new();
43
47
 
44
- if(NULL == description->attrs_depr) return list;
48
+ if (NULL == description->attrs_depr) { return list; }
45
49
 
46
- for(i = 0; description->attrs_depr[i]; i++) {
50
+ for (i = 0; description->attrs_depr[i]; i++) {
47
51
  rb_ary_push(list, NOKOGIRI_STR_NEW2(description->attrs_depr[i]));
48
52
  }
49
53
 
@@ -56,9 +60,10 @@ static VALUE deprecated_attributes(VALUE self)
56
60
  *
57
61
  * A list of optional attributes for this element
58
62
  */
59
- static VALUE optional_attributes(VALUE self)
63
+ static VALUE
64
+ optional_attributes(VALUE self)
60
65
  {
61
- const htmlElemDesc * description;
66
+ const htmlElemDesc *description;
62
67
  VALUE list;
63
68
  int i;
64
69
 
@@ -66,9 +71,9 @@ static VALUE optional_attributes(VALUE self)
66
71
 
67
72
  list = rb_ary_new();
68
73
 
69
- if(NULL == description->attrs_opt) return list;
74
+ if (NULL == description->attrs_opt) { return list; }
70
75
 
71
- for(i = 0; description->attrs_opt[i]; i++) {
76
+ for (i = 0; description->attrs_opt[i]; i++) {
72
77
  rb_ary_push(list, NOKOGIRI_STR_NEW2(description->attrs_opt[i]));
73
78
  }
74
79
 
@@ -81,13 +86,15 @@ static VALUE optional_attributes(VALUE self)
81
86
  *
82
87
  * The default sub element for this element
83
88
  */
84
- static VALUE default_sub_element(VALUE self)
89
+ static VALUE
90
+ default_sub_element(VALUE self)
85
91
  {
86
- const htmlElemDesc * description;
92
+ const htmlElemDesc *description;
87
93
  Data_Get_Struct(self, htmlElemDesc, description);
88
94
 
89
- if (description->defaultsubelt)
95
+ if (description->defaultsubelt) {
90
96
  return NOKOGIRI_STR_NEW2(description->defaultsubelt);
97
+ }
91
98
 
92
99
  return Qnil;
93
100
  }
@@ -98,9 +105,10 @@ static VALUE default_sub_element(VALUE self)
98
105
  *
99
106
  * A list of allowed sub elements for this element.
100
107
  */
101
- static VALUE sub_elements(VALUE self)
108
+ static VALUE
109
+ sub_elements(VALUE self)
102
110
  {
103
- const htmlElemDesc * description;
111
+ const htmlElemDesc *description;
104
112
  VALUE list;
105
113
  int i;
106
114
 
@@ -108,9 +116,9 @@ static VALUE sub_elements(VALUE self)
108
116
 
109
117
  list = rb_ary_new();
110
118
 
111
- if(NULL == description->subelts) return list;
119
+ if (NULL == description->subelts) { return list; }
112
120
 
113
- for(i = 0; description->subelts[i]; i++) {
121
+ for (i = 0; description->subelts[i]; i++) {
114
122
  rb_ary_push(list, NOKOGIRI_STR_NEW2(description->subelts[i]));
115
123
  }
116
124
 
@@ -123,9 +131,10 @@ static VALUE sub_elements(VALUE self)
123
131
  *
124
132
  * The description for this element
125
133
  */
126
- static VALUE description(VALUE self)
134
+ static VALUE
135
+ description(VALUE self)
127
136
  {
128
- const htmlElemDesc * description;
137
+ const htmlElemDesc *description;
129
138
  Data_Get_Struct(self, htmlElemDesc, description);
130
139
 
131
140
  return NOKOGIRI_STR_NEW2(description->desc);
@@ -137,12 +146,13 @@ static VALUE description(VALUE self)
137
146
  *
138
147
  * Is this element an inline element?
139
148
  */
140
- static VALUE inline_eh(VALUE self)
149
+ static VALUE
150
+ inline_eh(VALUE self)
141
151
  {
142
- const htmlElemDesc * description;
152
+ const htmlElemDesc *description;
143
153
  Data_Get_Struct(self, htmlElemDesc, description);
144
154
 
145
- if(description->isinline) return Qtrue;
155
+ if (description->isinline) { return Qtrue; }
146
156
  return Qfalse;
147
157
  }
148
158
 
@@ -152,12 +162,13 @@ static VALUE inline_eh(VALUE self)
152
162
  *
153
163
  * Is this element deprecated?
154
164
  */
155
- static VALUE deprecated_eh(VALUE self)
165
+ static VALUE
166
+ deprecated_eh(VALUE self)
156
167
  {
157
- const htmlElemDesc * description;
168
+ const htmlElemDesc *description;
158
169
  Data_Get_Struct(self, htmlElemDesc, description);
159
170
 
160
- if(description->depr) return Qtrue;
171
+ if (description->depr) { return Qtrue; }
161
172
  return Qfalse;
162
173
  }
163
174
 
@@ -167,12 +178,13 @@ static VALUE deprecated_eh(VALUE self)
167
178
  *
168
179
  * Is this an empty element?
169
180
  */
170
- static VALUE empty_eh(VALUE self)
181
+ static VALUE
182
+ empty_eh(VALUE self)
171
183
  {
172
- const htmlElemDesc * description;
184
+ const htmlElemDesc *description;
173
185
  Data_Get_Struct(self, htmlElemDesc, description);
174
186
 
175
- if(description->empty) return Qtrue;
187
+ if (description->empty) { return Qtrue; }
176
188
  return Qfalse;
177
189
  }
178
190
 
@@ -182,12 +194,13 @@ static VALUE empty_eh(VALUE self)
182
194
  *
183
195
  * Should the end tag be saved?
184
196
  */
185
- static VALUE save_end_tag_eh(VALUE self)
197
+ static VALUE
198
+ save_end_tag_eh(VALUE self)
186
199
  {
187
- const htmlElemDesc * description;
200
+ const htmlElemDesc *description;
188
201
  Data_Get_Struct(self, htmlElemDesc, description);
189
202
 
190
- if(description->saveEndTag) return Qtrue;
203
+ if (description->saveEndTag) { return Qtrue; }
191
204
  return Qfalse;
192
205
  }
193
206
 
@@ -197,12 +210,13 @@ static VALUE save_end_tag_eh(VALUE self)
197
210
  *
198
211
  * Can the end tag be implied for this tag?
199
212
  */
200
- static VALUE implied_end_tag_eh(VALUE self)
213
+ static VALUE
214
+ implied_end_tag_eh(VALUE self)
201
215
  {
202
- const htmlElemDesc * description;
216
+ const htmlElemDesc *description;
203
217
  Data_Get_Struct(self, htmlElemDesc, description);
204
218
 
205
- if(description->endTag) return Qtrue;
219
+ if (description->endTag) { return Qtrue; }
206
220
  return Qfalse;
207
221
  }
208
222
 
@@ -212,12 +226,13 @@ static VALUE implied_end_tag_eh(VALUE self)
212
226
  *
213
227
  * Can the start tag be implied for this tag?
214
228
  */
215
- static VALUE implied_start_tag_eh(VALUE self)
229
+ static VALUE
230
+ implied_start_tag_eh(VALUE self)
216
231
  {
217
- const htmlElemDesc * description;
232
+ const htmlElemDesc *description;
218
233
  Data_Get_Struct(self, htmlElemDesc, description);
219
234
 
220
- if(description->startTag) return Qtrue;
235
+ if (description->startTag) { return Qtrue; }
221
236
  return Qfalse;
222
237
  }
223
238
 
@@ -227,12 +242,13 @@ static VALUE implied_start_tag_eh(VALUE self)
227
242
  *
228
243
  * Get the tag name for this ElemementDescription
229
244
  */
230
- static VALUE name(VALUE self)
245
+ static VALUE
246
+ name(VALUE self)
231
247
  {
232
- const htmlElemDesc * description;
248
+ const htmlElemDesc *description;
233
249
  Data_Get_Struct(self, htmlElemDesc, description);
234
250
 
235
- if(NULL == description->name) return Qnil;
251
+ if (NULL == description->name) { return Qnil; }
236
252
  return NOKOGIRI_STR_NEW2(description->name);
237
253
  }
238
254
 
@@ -242,38 +258,35 @@ static VALUE name(VALUE self)
242
258
  *
243
259
  * Get ElemementDescription for +tag_name+
244
260
  */
245
- static VALUE get_description(VALUE klass, VALUE tag_name)
261
+ static VALUE
262
+ get_description(VALUE klass, VALUE tag_name)
246
263
  {
247
- const htmlElemDesc * description = htmlTagLookup(
248
- (const xmlChar *)StringValueCStr(tag_name)
249
- );
264
+ const htmlElemDesc *description = htmlTagLookup(
265
+ (const xmlChar *)StringValueCStr(tag_name)
266
+ );
250
267
 
251
- if(NULL == description) return Qnil;
268
+ if (NULL == description) { return Qnil; }
252
269
  return Data_Wrap_Struct(klass, 0, 0, (void *)(uintptr_t)description);
253
270
  }
254
271
 
255
- VALUE cNokogiriHtmlElementDescription ;
256
- void init_html_element_description()
272
+ void
273
+ noko_init_html_element_description()
257
274
  {
258
- VALUE nokogiri = rb_define_module("Nokogiri");
259
- VALUE html = rb_define_module_under(nokogiri, "HTML");
260
- VALUE klass = rb_define_class_under(html, "ElementDescription",rb_cObject);
261
-
262
- cNokogiriHtmlElementDescription = klass;
263
-
264
- rb_define_singleton_method(klass, "[]", get_description, 1);
265
-
266
- rb_define_method(klass, "name", name, 0);
267
- rb_define_method(klass, "implied_start_tag?", implied_start_tag_eh, 0);
268
- rb_define_method(klass, "implied_end_tag?", implied_end_tag_eh, 0);
269
- rb_define_method(klass, "save_end_tag?", save_end_tag_eh, 0);
270
- rb_define_method(klass, "empty?", empty_eh, 0);
271
- rb_define_method(klass, "deprecated?", deprecated_eh, 0);
272
- rb_define_method(klass, "inline?", inline_eh, 0);
273
- rb_define_method(klass, "description", description, 0);
274
- rb_define_method(klass, "sub_elements", sub_elements, 0);
275
- rb_define_method(klass, "default_sub_element", default_sub_element, 0);
276
- rb_define_method(klass, "optional_attributes", optional_attributes, 0);
277
- rb_define_method(klass, "deprecated_attributes", deprecated_attributes, 0);
278
- rb_define_method(klass, "required_attributes", required_attributes, 0);
275
+ cNokogiriHtmlElementDescription = rb_define_class_under(mNokogiriHtml, "ElementDescription", rb_cObject);
276
+
277
+ rb_define_singleton_method(cNokogiriHtmlElementDescription, "[]", get_description, 1);
278
+
279
+ rb_define_method(cNokogiriHtmlElementDescription, "name", name, 0);
280
+ rb_define_method(cNokogiriHtmlElementDescription, "implied_start_tag?", implied_start_tag_eh, 0);
281
+ rb_define_method(cNokogiriHtmlElementDescription, "implied_end_tag?", implied_end_tag_eh, 0);
282
+ rb_define_method(cNokogiriHtmlElementDescription, "save_end_tag?", save_end_tag_eh, 0);
283
+ rb_define_method(cNokogiriHtmlElementDescription, "empty?", empty_eh, 0);
284
+ rb_define_method(cNokogiriHtmlElementDescription, "deprecated?", deprecated_eh, 0);
285
+ rb_define_method(cNokogiriHtmlElementDescription, "inline?", inline_eh, 0);
286
+ rb_define_method(cNokogiriHtmlElementDescription, "description", description, 0);
287
+ rb_define_method(cNokogiriHtmlElementDescription, "sub_elements", sub_elements, 0);
288
+ rb_define_method(cNokogiriHtmlElementDescription, "default_sub_element", default_sub_element, 0);
289
+ rb_define_method(cNokogiriHtmlElementDescription, "optional_attributes", optional_attributes, 0);
290
+ rb_define_method(cNokogiriHtmlElementDescription, "deprecated_attributes", deprecated_attributes, 0);
291
+ rb_define_method(cNokogiriHtmlElementDescription, "required_attributes", required_attributes, 0);
279
292
  }