Commit 87df2752 authored by Murray Cumming's avatar Murray Cumming

Fix the build with -Wshadow.

And add this warning to --enable-warnings=fatal.
parent 9618504f
......@@ -44,7 +44,7 @@ MM_ARG_WITH_TAGFILE_DOC([glibmm-2.4.tag], [glibmm-2.4])
# Evaluate the --enable-warnings=level option.
MM_ARG_ENABLE_WARNINGS([LIBXMLXX_WXXFLAGS],
[-Wall],
[-pedantic -Wall -Wextra -Wno-long-long],
[-pedantic -Wall -Wextra -Wshadow -Wno-long-long],
[G GLIBMM SIGCXX])
# Offer the ability to omit some API from the library.
......
......@@ -55,23 +55,23 @@ bool xpath_test(const xmlpp::Node* node, const Glib::ustring& xpath)
std::cout << set.size() << " nodes have been found:" << std::endl;
//Print the structural paths and the values:
for(const auto& node : set)
for(const auto& child : set)
{
std::cout << " " << node->get_path();
std::cout << " " << child->get_path();
auto attribute = dynamic_cast<xmlpp::Attribute*>(node);
auto attribute = dynamic_cast<xmlpp::Attribute*>(child);
if (attribute)
std::cout << ", value=\"" << attribute->get_value() << "\"";
auto content_node = dynamic_cast<xmlpp::ContentNode*>(node);
auto content_node = dynamic_cast<xmlpp::ContentNode*>(child);
if (content_node)
std::cout << ", content=\"" << content_node->get_content() << "\"";
auto entity_reference = dynamic_cast<xmlpp::EntityReference*>(node);
auto entity_reference = dynamic_cast<xmlpp::EntityReference*>(child);
if (entity_reference)
std::cout << ", text=\"" << entity_reference->get_original_text() << "\"";
auto element = dynamic_cast<xmlpp::Element*>(node);
auto element = dynamic_cast<xmlpp::Element*>(child);
if (element)
{
auto text_node = element->get_child_text();
......
......@@ -108,34 +108,34 @@ void Parser::on_start_element(const Glib::ustring& name,
// In theory, you could change the attributes here.
for(const auto& attr_pair : attributes)
{
auto name = attr_pair.name;
auto value = attr_pair.value;
Glib::ustring::size_type idx = name.find(':');
if (idx == Glib::ustring::npos) // If the separator was not found.
const auto attr_name = attr_pair.name;
const auto attr_value = attr_pair.value;
const auto idx_colon = attr_name.find(':');
if (idx_colon == Glib::ustring::npos) // If the separator was not found.
{
if (name == "xmlns") // This is a namespace declaration.
if (attr_name == "xmlns") // This is a namespace declaration.
{
//There is no second part, so this is a default namespace declaration.
element_derived->set_namespace_declaration(value);
element_derived->set_namespace_declaration(attr_value);
}
else
{
//This is just an attribute value:
element_derived->set_attribute(name, value);
element_derived->set_attribute(attr_name, attr_value);
}
}
else
{
//The separator was found:
auto prefix = name.substr(0, idx);
auto suffix = name.substr(idx + 1);
auto prefix = attr_name.substr(0, idx_colon);
auto suffix = attr_name.substr(idx_colon + 1);
if (prefix == "xmlns") // This is a namespace declaration.
element_derived->set_namespace_declaration(value, suffix);
element_derived->set_namespace_declaration(attr_value, suffix);
else
{
//This is a namespaced attribute value.
//(The namespace must have been declared already)
auto attr = element_derived->set_attribute(suffix, value);
auto attr = element_derived->set_attribute(suffix, attr_value);
attr->set_namespace(prefix); //alternatively, we could have specified the whole name to set_attribute().
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment