Commit 512d70b8 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix empty property problem in graphml

Properties with empty values are now simply not printed in the output.
parent c9621bc6
...@@ -376,12 +376,13 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, ...@@ -376,12 +376,13 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index,
{ {
if (i->second->key() == typeid(graph_property_tag)) if (i->second->key() == typeid(graph_property_tag))
{ {
std::string val = protect_xml_string
(print_value<value_types>(*i->second, graph_property_tag()));
if (val.empty())
continue;
out << " <data key=\"" out << " <data key=\""
<< protect_xml_string(graph_key_ids[i->first]) << "\">" << protect_xml_string(graph_key_ids[i->first]) << "\">"
<< protect_xml_string << val << "</data>\n";
(print_value<value_types>(*i->second,
graph_property_tag()))
<< "</data>\n";
} }
} }
...@@ -398,11 +399,13 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, ...@@ -398,11 +399,13 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index,
{ {
if (i->second->key() == typeid(vertex_descriptor)) if (i->second->key() == typeid(vertex_descriptor))
{ {
std::string val = protect_xml_string
(print_value<value_types>(*i->second, *v));
if (val.empty())
continue;
out << " <data key=\"" out << " <data key=\""
<< protect_xml_string(vertex_key_ids[i->first]) << "\">" << protect_xml_string(vertex_key_ids[i->first]) << "\">"
<< protect_xml_string << val << "</data>\n";
(print_value<value_types>(*i->second, *v))
<< "</data>\n";
} }
} }
out << " </node>\n"; out << " </node>\n";
...@@ -424,11 +427,13 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, ...@@ -424,11 +427,13 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index,
{ {
if (i->second->key() == typeid(edge_descriptor)) if (i->second->key() == typeid(edge_descriptor))
{ {
std::string val = protect_xml_string
(print_value<value_types>(*i->second, *e));
if (val.empty())
continue;
out << " <data key=\"" out << " <data key=\""
<< protect_xml_string(edge_key_ids[i->first]) << "\">" << protect_xml_string(edge_key_ids[i->first]) << "\">"
<< protect_xml_string << val << "</data>\n";
(print_value<value_types>(*i->second, *e))
<< "</data>\n";
} }
} }
out << " </edge>\n"; out << " </edge>\n";
......
...@@ -150,6 +150,9 @@ istream& operator>>(istream& in, vector<string>& vec) ...@@ -150,6 +150,9 @@ istream& operator>>(istream& in, vector<string>& vec)
data += line; data += line;
} }
if (data == "")
return in; // empty string is OK
sregex re = sregex::compile(", "); sregex re = sregex::compile(", ");
sregex_token_iterator iter(data.begin(), data.end(), re, -1), end; sregex_token_iterator iter(data.begin(), data.end(), re, -1), end;
for (; iter != end; ++iter) for (; iter != end; ++iter)
...@@ -161,6 +164,7 @@ istream& operator>>(istream& in, vector<string>& vec) ...@@ -161,6 +164,7 @@ istream& operator>>(istream& in, vector<string>& vec)
} }
return in; return in;
} }
} // std namespace } // std namespace
......
Supports Markdown
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