[libxml++] Element: Rename set/get_child_text() to set/get_first_child_text()
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml++] Element: Rename set/get_child_text() to set/get_first_child_text()
- Date: Thu, 1 Oct 2015 13:46:26 +0000 (UTC)
commit ad65ef4efc924cae9a04afc4c8951914c9ee30fa
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Thu Oct 1 15:39:55 2015 +0200
Element: Rename set/get_child_text() to set/get_first_child_text()
* libxml++/nodes/element.[h|cc]: Rename set/get_child_text() to
set/get_first_child_text() by analogy with Node::get_first_child().
* examples/dom_build/main.cc:
* examples/dom_xpath/main.cc:
* examples/import_node/main.cc: Replace set/get_child_text() by
set/get_first_child_text(). Bug #754673.
examples/dom_build/main.cc | 4 ++--
examples/dom_xpath/main.cc | 4 ++--
examples/import_node/main.cc | 2 +-
libxml++/nodes/element.cc | 28 +++++++++-------------------
libxml++/nodes/element.h | 19 +++++++++++++------
5 files changed, 27 insertions(+), 30 deletions(-)
---
diff --git a/examples/dom_build/main.cc b/examples/dom_build/main.cc
index f22b493..3674b0e 100644
--- a/examples/dom_build/main.cc
+++ b/examples/dom_build/main.cc
@@ -45,7 +45,7 @@ main(int /* argc */, char** /* argv */)
auto nodeRoot = document.create_root_node("exampleroot", "http://foo", "foo"); //Declares the namespace
and uses its prefix for this node
nodeRoot->set_namespace_declaration("http://foobar", "foobar"); //Also associate this prefix with this
namespace:
- nodeRoot->set_child_text("\n");
+ nodeRoot->set_first_child_text("\n");
auto nodeChild = nodeRoot->add_child_element("examplechild");
//Associate prefix with namespace:
@@ -53,7 +53,7 @@ main(int /* argc */, char** /* argv */)
nodeChild->set_namespace("bar"); //So it will be bar::examplechild.
nodeChild->set_attribute("id", "1", "foo"); //foo is the namespace prefix. You could also just use a
name of foo:id".
- nodeChild->set_child_text("\nSome content\n");
+ nodeChild->set_first_child_text("\nSome content\n");
nodeChild->add_child_comment("Some comments");
nodeChild->add_child_entity_reference("example1");
nodeChild->add_child_entity_reference("#x20ac"); // €
diff --git a/examples/dom_xpath/main.cc b/examples/dom_xpath/main.cc
index 8000df8..c35e409 100644
--- a/examples/dom_xpath/main.cc
+++ b/examples/dom_xpath/main.cc
@@ -72,9 +72,9 @@ bool xpath_test(const xmlpp::Node* node, const Glib::ustring& xpath)
auto element = dynamic_cast<const xmlpp::Element*>(child);
if (element)
{
- auto text_node = element->get_child_text();
+ auto text_node = element->get_first_child_text();
if (text_node)
- std::cout << ", child_text=\"" << text_node->get_content() << "\"";
+ std::cout << ", first_child_text=\"" << text_node->get_content() << "\"";
}
std::cout << std::endl;
}
diff --git a/examples/import_node/main.cc b/examples/import_node/main.cc
index a539721..edcbaa0 100644
--- a/examples/import_node/main.cc
+++ b/examples/import_node/main.cc
@@ -46,7 +46,7 @@ int main (int /* argc */, char** /* argv */)
cerr << "first_child2 == nullptr" << endl;
return EXIT_FAILURE;
}
- auto text_to_add = first_child2->get_child_text();
+ auto text_to_add = first_child2->get_first_child_text();
// Import the text under the first "child" element in example1.
// Adjacent text nodes are merged.
diff --git a/libxml++/nodes/element.cc b/libxml++/nodes/element.cc
index 30e912c..cb9baa9 100644
--- a/libxml++/nodes/element.cc
+++ b/libxml++/nodes/element.cc
@@ -260,36 +260,26 @@ _xmlNode* Element::create_new_child_element_node_with_new_ns(const Glib::ustring
return child;
}
-const TextNode* Element::get_child_text() const
+TextNode* Element::get_first_child_text()
{
- // FIXME: return only the first content node
- for(auto child = cobj()->children; child; child = child->next)
- if(child->type == XML_TEXT_NODE)
+ for (auto child = cobj()->children; child; child = child->next)
+ if (child->type == XML_TEXT_NODE)
{
Node::create_wrapper(child);
return static_cast<TextNode*>(child->_private);
}
- return 0;
+ return nullptr;
}
-TextNode* Element::get_child_text()
+const TextNode* Element::get_first_child_text() const
{
- // TODO: This only returns the first content node.
- // What should we do instead? Update the documentation if we change this. murrayc.
- for(auto child = cobj()->children; child; child = child->next)
- if(child->type == XML_TEXT_NODE)
- {
- Node::create_wrapper(child);
- return static_cast<TextNode*>(child->_private);
- }
-
- return 0;
+ return const_cast<Element*>(this)->get_first_child_text();
}
-void Element::set_child_text(const Glib::ustring& content)
+void Element::set_first_child_text(const Glib::ustring& content)
{
- auto node = get_child_text();
+ auto node = get_first_child_text();
if(node)
node->set_content(content);
else
@@ -361,7 +351,7 @@ TextNode* Element::add_child_text_before(xmlpp::Node* next_sibling, const Glib::
bool Element::has_child_text() const
{
- return get_child_text() != nullptr;
+ return get_first_child_text() != nullptr;
}
void Element::set_namespace_declaration(const Glib::ustring& ns_uri, const Glib::ustring& ns_prefix)
diff --git a/libxml++/nodes/element.h b/libxml++/nodes/element.h
index 472c402..bc879d9 100644
--- a/libxml++/nodes/element.h
+++ b/libxml++/nodes/element.h
@@ -204,17 +204,21 @@ public:
/** Get the first child text content node.
* This is a convenience method, meant as an alternative to iterating over all the
- * child nodes to find the first suitable node then and getting the text directly.
+ * child nodes to find the first suitable node and then getting the text directly.
* @returns The first text node, if any.
+ *
+ * @newin{3,0} Replaces get_child_text().
*/
- TextNode* get_child_text();
+ TextNode* get_first_child_text();
/** Get the first child text content node.
* This is a convenience method, meant as an alternative to iterating over all the
- * child nodes to find the first suitable node then and getting the text directly.
+ * child nodes to find the first suitable node and then getting the text directly.
* @returns The first text node, if any.
+ *
+ * @newin{3,0} Replaces get_child_text().
*/
- const TextNode* get_child_text() const;
+ const TextNode* get_first_child_text() const;
/** Append a new text node.
* @param content The text. This should be unescaped - see ContentNode::set_content().
@@ -246,11 +250,14 @@ public:
TextNode* add_child_text_before(xmlpp::Node* next_sibling, const Glib::ustring& content = Glib::ustring());
/** Set the text of the first text node, adding one if necessary.
- * This is a convenience method, meant as an alternative to iterating over all the child nodes to find the
first suitable node then and setting the text directly.
+ * This is a convenience method, meant as an alternative to iterating over all the
+ * child nodes to find the first suitable node and then setting the text directly.
* @param content The text. This should be unescaped - see ContentNode::set_content().
* @throws xmlpp::internal_error
+ *
+ * @newin{3,0} Replaces set_child_text().
*/
- void set_child_text(const Glib::ustring& content);
+ void set_first_child_text(const Glib::ustring& content);
/** Discover whether one of the child nodes is a text node.
* This is a convenience method, meant as an alternative to iterating over all the child nodes and
examining them directly.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]