Skip to content

Commit e6c7768

Browse files
committed
prefactor: clean up Text.new implementations
(cherry picked from commit 6325ed6)
1 parent e6eb81b commit e6c7768

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

ext/java/nokogiri/XmlText.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ public class XmlText extends XmlNode
5151
}
5252

5353
content = args[0];
54-
IRubyObject xNode = args[1];
54+
IRubyObject rbDocument = args[1];
5555

56-
if (!(xNode instanceof XmlDocument)) {
56+
if (!(rbDocument instanceof XmlDocument)) {
5757
// TODO: deprecate allowing Node
5858
context.runtime.getWarnings().warn("Passing a Node as the second parameter to Text.new is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
5959
}
6060

61-
Document document = asXmlNode(context, xNode).getOwnerDocument();
61+
Document document = asXmlNode(context, rbDocument).getOwnerDocument();
6262
// text node content should not be encoded when it is created by Text node.
6363
// while content should be encoded when it is created by Element node.
6464
Node node = document.createTextNode(rubyStringToString(content));

ext/nokogiri/xml_text.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,33 @@ VALUE cNokogiriXmlText ;
99
* Create a new Text element on the +document+ with +content+
1010
*/
1111
static VALUE
12-
new (int argc, VALUE *argv, VALUE klass)
12+
rb_xml_text_s_new(int argc, VALUE *argv, VALUE klass)
1313
{
14-
xmlDocPtr doc;
15-
xmlNodePtr node;
16-
VALUE string;
17-
VALUE document;
18-
VALUE rest;
14+
xmlDocPtr c_document;
15+
xmlNodePtr c_node;
16+
VALUE rb_string;
17+
VALUE rb_document;
18+
VALUE rb_rest;
1919
VALUE rb_node;
2020

21-
rb_scan_args(argc, argv, "2*", &string, &document, &rest);
21+
rb_scan_args(argc, argv, "2*", &rb_string, &rb_document, &rb_rest);
2222

23-
if (rb_obj_is_kind_of(document, cNokogiriXmlDocument)) {
24-
doc = noko_xml_document_unwrap(document);
25-
} else {
23+
if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) {
2624
xmlNodePtr deprecated_node_type_arg;
2725
// TODO: deprecate allowing Node
2826
NOKO_WARN_DEPRECATION("Passing a Node as the second parameter to Text.new is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
29-
Noko_Node_Get_Struct(document, xmlNode, deprecated_node_type_arg);
30-
doc = deprecated_node_type_arg->doc;
27+
Noko_Node_Get_Struct(rb_document, xmlNode, deprecated_node_type_arg);
28+
c_document = deprecated_node_type_arg->doc;
29+
} else {
30+
c_document = noko_xml_document_unwrap(rb_document);
3131
}
3232

33-
node = xmlNewText((xmlChar *)StringValueCStr(string));
34-
node->doc = doc;
33+
c_node = xmlNewText((xmlChar *)StringValueCStr(rb_string));
34+
c_node->doc = c_document;
3535

36-
noko_xml_document_pin_node(node);
36+
noko_xml_document_pin_node(c_node);
3737

38-
rb_node = noko_xml_node_wrap(klass, node) ;
38+
rb_node = noko_xml_node_wrap(klass, c_node) ;
3939
rb_obj_call_init(rb_node, argc, argv);
4040

4141
if (rb_block_given_p()) { rb_yield(rb_node); }
@@ -52,5 +52,5 @@ noko_init_xml_text(void)
5252
*/
5353
cNokogiriXmlText = rb_define_class_under(mNokogiriXml, "Text", cNokogiriXmlCharacterData);
5454

55-
rb_define_singleton_method(cNokogiriXmlText, "new", new, -1);
55+
rb_define_singleton_method(cNokogiriXmlText, "new", rb_xml_text_s_new, -1);
5656
}

0 commit comments

Comments
 (0)