Skip to content

Commit a84f430

Browse files
committed
prefactor: clean up CDATA.new implementations
(cherry picked from commit 38b4dce)
1 parent 299b73e commit a84f430

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

ext/java/nokogiri/XmlCdata.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ public class XmlCdata extends XmlText
4343
if (args.length < 2) {
4444
throw getRuntime().newArgumentError(args.length, 2);
4545
}
46-
IRubyObject doc = args[0];
46+
IRubyObject rbDocument = args[0];
4747
content = args[1];
4848

49-
if (!(doc instanceof XmlDocument)) {
49+
if (!(rbDocument instanceof XmlDocument)) {
5050
// TODO: deprecate allowing Node
5151
context.runtime.getWarnings().warn("Passing a Node as the first parameter to CDATA.new is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
5252
}
5353

54-
Document document = ((XmlNode) doc).getOwnerDocument();
54+
Document document = ((XmlNode) rbDocument).getOwnerDocument();
5555
Node node = document.createCDATASection(rubyStringToString(content));
5656
setNode(context.runtime, node);
5757
}

ext/nokogiri/xml_cdata.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,39 @@ VALUE cNokogiriXmlCData;
1212
* raise a TypeError exception.
1313
*/
1414
static VALUE
15-
new (int argc, VALUE *argv, VALUE klass)
15+
rb_xml_cdata_s_new(int argc, VALUE *argv, VALUE klass)
1616
{
17-
xmlDocPtr xml_doc;
18-
xmlNodePtr node;
19-
VALUE doc;
20-
VALUE content;
21-
VALUE rest;
17+
xmlDocPtr c_document;
18+
xmlNodePtr c_node;
19+
VALUE rb_document;
20+
VALUE rb_content;
21+
VALUE rb_rest;
2222
VALUE rb_node;
23-
xmlChar *content_str = NULL;
24-
int content_str_len = 0;
23+
xmlChar *c_content = NULL;
24+
int c_content_len = 0;
2525

26-
rb_scan_args(argc, argv, "2*", &doc, &content, &rest);
26+
rb_scan_args(argc, argv, "2*", &rb_document, &rb_content, &rb_rest);
2727

28-
if (rb_obj_is_kind_of(doc, cNokogiriXmlDocument)) {
29-
xml_doc = noko_xml_document_unwrap(doc);
30-
} else {
28+
if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) {
3129
xmlNodePtr deprecated_node_type_arg;
3230
// TODO: deprecate allowing Node
3331
NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to CDATA.new is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
34-
Noko_Node_Get_Struct(doc, xmlNode, deprecated_node_type_arg);
35-
xml_doc = deprecated_node_type_arg->doc;
32+
Noko_Node_Get_Struct(rb_document, xmlNode, deprecated_node_type_arg);
33+
c_document = deprecated_node_type_arg->doc;
34+
} else {
35+
c_document = noko_xml_document_unwrap(rb_document);
3636
}
3737

38-
if (!NIL_P(content)) {
39-
content_str = (xmlChar *)StringValuePtr(content);
40-
content_str_len = RSTRING_LENINT(content);
38+
if (!NIL_P(rb_content)) {
39+
c_content = (xmlChar *)StringValuePtr(rb_content);
40+
c_content_len = RSTRING_LENINT(rb_content);
4141
}
4242

43-
node = xmlNewCDataBlock(xml_doc, content_str, content_str_len);
43+
c_node = xmlNewCDataBlock(c_document, c_content, c_content_len);
4444

45-
noko_xml_document_pin_node(node);
45+
noko_xml_document_pin_node(c_node);
4646

47-
rb_node = noko_xml_node_wrap(klass, node);
47+
rb_node = noko_xml_node_wrap(klass, c_node);
4848
rb_obj_call_init(rb_node, argc, argv);
4949

5050
if (rb_block_given_p()) { rb_yield(rb_node); }
@@ -61,5 +61,5 @@ noko_init_xml_cdata(void)
6161
*/
6262
cNokogiriXmlCData = rb_define_class_under(mNokogiriXml, "CDATA", cNokogiriXmlText);
6363

64-
rb_define_singleton_method(cNokogiriXmlCData, "new", new, -1);
64+
rb_define_singleton_method(cNokogiriXmlCData, "new", rb_xml_cdata_s_new, -1);
6565
}

0 commit comments

Comments
 (0)