$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r85807 - in trunk/tools/quickbook: doc src
From: dnljms_at_[hidden]
Date: 2013-09-20 15:52:38
Author: danieljames
Date: 2013-09-20 15:52:38 EDT (Fri, 20 Sep 2013)
New Revision: 85807
URL: http://svn.boost.org/trac/boost/changeset/85807
Log:
Encode the filename macro.
Also tweak the utils string functions.
Text files modified: 
   trunk/tools/quickbook/doc/change_log.qbk |     1 +                                       
   trunk/tools/quickbook/src/actions.cpp    |     6 ++----                                  
   trunk/tools/quickbook/src/state.cpp      |     9 ++++++++-                               
   trunk/tools/quickbook/src/state.hpp      |     2 ++                                      
   trunk/tools/quickbook/src/utils.cpp      |    29 +++++++++++++++++++++++++++--           
   trunk/tools/quickbook/src/utils.hpp      |     5 +++--                                   
   6 files changed, 43 insertions(+), 9 deletions(-)
Modified: trunk/tools/quickbook/doc/change_log.qbk
==============================================================================
--- trunk/tools/quickbook/doc/change_log.qbk	Fri Sep 20 15:03:54 2013	(r85806)
+++ trunk/tools/quickbook/doc/change_log.qbk	2013-09-20 15:52:38 EDT (Fri, 20 Sep 2013)	(r85807)
@@ -307,6 +307,7 @@
 * Make escaping templates with a punctuation identifier illegal.
   Escaping templates with an alphanumeric identifier is still fine.
 * Fix detection of code blocks at the start of a file.
+* XML encode the contents of the `__FILENAME__` macro.
 * 1.7 changes:
   * Make it an error to use an element in the wrong context.
   * Error if the body of a phrase element doesn't parse.
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp	Fri Sep 20 15:03:54 2013	(r85806)
+++ trunk/tools/quickbook/src/actions.cpp	2013-09-20 15:52:38 EDT (Fri, 20 Sep 2013)	(r85807)
@@ -1962,8 +1962,7 @@
             state.imported = (load_type == block_tags::import);
 
             // update the __FILENAME__ macro
-            *boost::spirit::classic::find(state.macro, "__FILENAME__")
-                = detail::path_to_generic(state.filename_relative);
+            state.update_filename_macro();
         
             // parse the file
             quickbook::parse_file(state, include_doc_id, true);
@@ -1973,8 +1972,7 @@
         }
 
         // restore the __FILENAME__ macro
-        *boost::spirit::classic::find(state.macro, "__FILENAME__")
-            = detail::path_to_generic(state.filename_relative);
+        state.update_filename_macro();
     }
 
     void load_source_file(quickbook::state& state,
Modified: trunk/tools/quickbook/src/state.cpp
==============================================================================
--- trunk/tools/quickbook/src/state.cpp	Fri Sep 20 15:03:54 2013	(r85806)
+++ trunk/tools/quickbook/src/state.cpp	2013-09-20 15:52:38 EDT (Fri, 20 Sep 2013)	(r85807)
@@ -13,6 +13,7 @@
 #include "quickbook.hpp"
 #include "grammar.hpp"
 #include "input_path.hpp"
+#include "utils.hpp"
 
 #if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
 #pragma warning(disable:4355)
@@ -63,8 +64,9 @@
         macro.add
             ("__DATE__", std::string(quickbook_get_date))
             ("__TIME__", std::string(quickbook_get_time))
-            ("__FILENAME__", detail::path_to_generic(filename_relative))
+            ("__FILENAME__", std::string())
         ;
+        update_filename_macro();
 
         boost::scoped_ptr<quickbook_grammar> g(
             new quickbook_grammar(*this));
@@ -74,6 +76,11 @@
     quickbook_grammar& state::grammar() const {
         return *grammar_;
     }
+
+    void state::update_filename_macro() {
+        *boost::spirit::classic::find(macro, "__FILENAME__")
+            = detail::encode_string(detail::path_to_generic(filename_relative));
+    }
     
     void state::push_output() {
         out.push();
Modified: trunk/tools/quickbook/src/state.hpp
==============================================================================
--- trunk/tools/quickbook/src/state.hpp	Fri Sep 20 15:03:54 2013	(r85806)
+++ trunk/tools/quickbook/src/state.hpp	2013-09-20 15:52:38 EDT (Fri, 20 Sep 2013)	(r85807)
@@ -84,6 +84,8 @@
     // actions
     ///////////////////////////////////////////////////////////////////////////
 
+        void update_filename_macro();
+
         void push_output();
         void pop_output();
 
Modified: trunk/tools/quickbook/src/utils.cpp
==============================================================================
--- trunk/tools/quickbook/src/utils.cpp	Fri Sep 20 15:03:54 2013	(r85806)
+++ trunk/tools/quickbook/src/utils.cpp	2013-09-20 15:52:38 EDT (Fri, 20 Sep 2013)	(r85807)
@@ -15,6 +15,27 @@
 
 namespace quickbook { namespace detail
 {
+    std::string encode_string(boost::string_ref str)
+    {
+        std::string result;
+        result.reserve(str.size());
+
+        for (boost::string_ref::const_iterator it = str.begin();
+            it != str.end(); ++it)
+        {
+            switch (*it)
+            {
+                case '<': result += "<";    break;
+                case '>': result += ">";    break;
+                case '&': result += "&";   break;
+                case '"': result += """;  break;
+                default:  result += *it;       break;
+            }
+        }
+
+        return result;
+    }
+
     void print_char(char ch, std::ostream& out)
     {
         switch (ch)
@@ -29,7 +50,7 @@
         }
     }
 
-    void print_string(boost::string_ref const& str, std::ostream& out)
+    void print_string(boost::string_ref str, std::ostream& out)
     {
         for (boost::string_ref::const_iterator cur = str.begin();
             cur != str.end(); ++cur)
@@ -45,8 +66,11 @@
         return static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
     }
 
-    std::string escape_uri(std::string uri)
+    std::string escape_uri(std::string uri_param)
     {
+        std::string uri;
+        uri.swap(uri_param);
+
         for (std::string::size_type n = 0; n < uri.size(); ++n)
         {
             static char const mark[] = "-_.!~*'()?\\/";
@@ -60,6 +84,7 @@
                 n += 2;
             }
         }
+
         return uri;
     }
 }}
Modified: trunk/tools/quickbook/src/utils.hpp
==============================================================================
--- trunk/tools/quickbook/src/utils.hpp	Fri Sep 20 15:03:54 2013	(r85806)
+++ trunk/tools/quickbook/src/utils.hpp	2013-09-20 15:52:38 EDT (Fri, 20 Sep 2013)	(r85807)
@@ -17,8 +17,9 @@
 #include <boost/utility/string_ref.hpp>
 
 namespace quickbook { namespace detail {
+    std::string encode_string(boost::string_ref);
     void print_char(char ch, std::ostream& out);
-    void print_string(boost::string_ref const& str, std::ostream& out);
+    void print_string(boost::string_ref str, std::ostream& out);
     char filter_identifier_char(char ch);
 
     template <typename Range>
@@ -34,7 +35,7 @@
     }
 
     std::string escape_uri(std::string uri);
-    inline std::string escape_uri(boost::string_ref const& uri) {
+    inline std::string escape_uri(boost::string_ref uri) {
         return escape_uri(std::string(uri.begin(), uri.end()));
     }