$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r63268 - in trunk: boost/graph libs/graph/doc libs/graph/test
From: jewillco_at_[hidden]
Date: 2010-06-23 16:46:23
Author: jewillco
Date: 2010-06-23 16:46:22 EDT (Wed, 23 Jun 2010)
New Revision: 63268
URL: http://svn.boost.org/trac/boost/changeset/63268
Log:
Made Graphviz writer quote and escape output strings properly; added linkage to boost_graph in test program; added note about needing -lboost_regex in documentation
Text files modified: 
   trunk/boost/graph/graphviz.hpp           |    22 ++++++++++++++++++----                  
   trunk/libs/graph/doc/write-graphviz.html |     4 ++--                                    
   trunk/libs/graph/test/Jamfile.v2         |     2 +-                                      
   3 files changed, 21 insertions(+), 7 deletions(-)
Modified: trunk/boost/graph/graphviz.hpp
==============================================================================
--- trunk/boost/graph/graphviz.hpp	(original)
+++ trunk/boost/graph/graphviz.hpp	2010-06-23 16:46:22 EDT (Wed, 23 Jun 2010)
@@ -26,6 +26,9 @@
 #include <boost/graph/overloading.hpp>
 #include <boost/graph/dll_import_export.hpp>
 #include <boost/spirit/include/classic_multi_pass.hpp>
+#include <boost/regex.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/algorithm/string/replace.hpp>
 
 namespace boost {
 
@@ -56,13 +59,24 @@
     }
   };
 
+  template <typename T>
+  inline std::string escape_dot_string(const T& obj) {
+    static boost::regex valid_unquoted_id("[a-zA-Z\\0200-\\0377_][a-zA-Z\\0200-\\0377_0-9]*|-?(?:[.][0-9]*|[0-9]+(?:[.][0-9]*)?)");
+    std::string s(boost::lexical_cast<std::string>(obj));
+    if (boost::regex_match(s, valid_unquoted_id)) {
+      return s;
+    } else {
+      return "\"" + boost::algorithm::replace_all_copy(s, "\"", "\\\"") + "\"";
+    }
+  }
+
   template <class Name>
   class label_writer {
   public:
     label_writer(Name _name) : name(_name) {}
     template <class VertexOrEdge>
     void operator()(std::ostream& out, const VertexOrEdge& v) const {
-      out << "[label=\"" << get(name, v) << "\"]";
+      out << "[label=" << escape_dot_string(get(name, v)) << "]";
     }
   private:
     Name name;
@@ -93,7 +107,7 @@
     iend = attr.end();
 
     while ( i != iend ) {
-      out << i->first << "=\"" << i->second << "\"";
+      out << i->first << "=" << escape_dot_string(i->second);
       ++i;
       if ( i != iend )
         out << ", ";
@@ -506,7 +520,7 @@
           else out << ", ";
           first = false;
 
-          out << i->first << "=\"" << i->second->get_string(key) << "\"";
+          out << i->first << "=" << escape_dot_string(i->second->get_string(key));
         }
       }
 
@@ -536,7 +550,7 @@
           else out << ", ";
           first = false;
 
-          out << i->first << "=\"" << i->second->get_string(key) << "\"";
+          out << i->first << "=" << escape_dot_string(i->second->get_string(key));
         }
       }
 
Modified: trunk/libs/graph/doc/write-graphviz.html
==============================================================================
--- trunk/libs/graph/doc/write-graphviz.html	(original)
+++ trunk/libs/graph/doc/write-graphviz.html	2010-06-23 16:46:22 EDT (Wed, 23 Jun 2010)
@@ -330,8 +330,8 @@
 <a href="./read_graphviz.html"><tt>read_graphviz</tt></a>
 
 <h3>Notes</h3>
-Note that you can use Graphviz dot file write facilities
-without the library <tt>libbglviz.a</tt>.
+The Graphviz file writing functions require that programs link to the
+<tt>boost_regex</tt> library.
 
 <br>
 <HR>
Modified: trunk/libs/graph/test/Jamfile.v2
==============================================================================
--- trunk/libs/graph/test/Jamfile.v2	(original)
+++ trunk/libs/graph/test/Jamfile.v2	2010-06-23 16:46:22 EDT (Wed, 23 Jun 2010)
@@ -112,7 +112,7 @@
     [ run clustering_coefficient.cpp ]
     [ run core_numbers_test.cpp ]
     [ run read_propmap.cpp ]
-    [ run mcgregor_subgraphs_test.cpp ]
+    [ run mcgregor_subgraphs_test.cpp ../build//boost_graph ]
     [ compile grid_graph_cc.cpp ]
     [ run grid_graph_test.cpp ]
     [ run incremental_components_test.cpp ]