Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61079 - in branches/quickbook-1.5-spirit2: . test
From: daniel_james_at_[hidden]
Date: 2010-04-05 15:43:18


Author: danieljames
Date: 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
New Revision: 61079
URL: http://svn.boost.org/trac/boost/changeset/61079

Log:
Fix the character escaping in some places. A bit clumsy.
Added:
   branches/quickbook-1.5-spirit2/strings.hpp (contents, props changed)
   branches/quickbook-1.5-spirit2/test/xml-escape.gold (contents, props changed)
   branches/quickbook-1.5-spirit2/test/xml-escape.quickbook (contents, props changed)
Text files modified:
   branches/quickbook-1.5-spirit2/actions.cpp | 14 --------
   branches/quickbook-1.5-spirit2/block.hpp | 7 ++-
   branches/quickbook-1.5-spirit2/block_actions.cpp | 63 ++++++++++++++++++++++-----------------
   branches/quickbook-1.5-spirit2/block_markup_grammar.cpp | 20 ++++++++----
   branches/quickbook-1.5-spirit2/boostbook.cpp | 33 ++++++++++++--------
   branches/quickbook-1.5-spirit2/code_snippet_actions.cpp | 3 +
   branches/quickbook-1.5-spirit2/code_snippet_types.hpp | 5 +-
   branches/quickbook-1.5-spirit2/doc_info.hpp | 14 +++++---
   branches/quickbook-1.5-spirit2/doc_info_grammar.cpp | 28 +++++++++--------
   branches/quickbook-1.5-spirit2/encoder.hpp | 2 +
   branches/quickbook-1.5-spirit2/encoder_impl.hpp | 13 ++++++++
   branches/quickbook-1.5-spirit2/fwd.hpp | 2 +
   branches/quickbook-1.5-spirit2/gen_types.hpp | 10 +++---
   branches/quickbook-1.5-spirit2/html.cpp | 25 +++++++++------
   branches/quickbook-1.5-spirit2/parse_utils.hpp | 5 +++
   branches/quickbook-1.5-spirit2/state.hpp | 13 ++++---
   branches/quickbook-1.5-spirit2/test/Jamfile.v2 | 1
   17 files changed, 149 insertions(+), 109 deletions(-)

Modified: branches/quickbook-1.5-spirit2/actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/actions.cpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -32,20 +32,6 @@
         , error(state.error_count)
     {}
 
- namespace {
- std::string fully_qualified_id(std::string const& library_id,
- std::string const& qualified_section_id,
- std::string const& section_id)
- {
- std::string id = library_id;
- if(!id.empty() && !qualified_section_id.empty()) id += '.';
- id += qualified_section_id;
- if(!id.empty() && !section_id.empty()) id += '.';
- id += section_id;
- return id;
- }
- }
-
     void error_action::operator()(iterator_range x, unused_type, unused_type) const
     {
         file_position const pos = x.begin().get_position();

Modified: branches/quickbook-1.5-spirit2/block.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block.hpp (original)
+++ branches/quickbook-1.5-spirit2/block.hpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -15,6 +15,7 @@
 #include <boost/optional.hpp>
 #include "fwd.hpp"
 #include "parse_types.hpp"
+#include "strings.hpp"
 
 namespace quickbook
 {
@@ -45,7 +46,7 @@
 
     struct begin_section
     {
- boost::optional<std::string> id;
+ boost::optional<raw_string> id;
         title content;
     };
     
@@ -79,7 +80,7 @@
     
     struct table
     {
- boost::optional<std::string> id;
+ boost::optional<raw_string> id;
         std::string title;
         std::vector<table_row> rows;
     };
@@ -96,7 +97,7 @@
     
     struct include
     {
- boost::optional<std::string> id;
+ boost::optional<raw_string> id;
         std::string path;
     };
 }

Modified: branches/quickbook-1.5-spirit2/block_actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_actions.cpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -22,15 +22,16 @@
 namespace quickbook
 {
     namespace {
- std::string fully_qualified_id(std::string const& library_id,
- std::string const& qualified_section_id,
- std::string const& section_id)
- {
- std::string id = library_id;
- if(!id.empty() && !qualified_section_id.empty()) id += '.';
- id += qualified_section_id;
- if(!id.empty() && !section_id.empty()) id += '.';
- id += section_id;
+ raw_string fully_qualified_id(raw_string const& library_id,
+ raw_string const& qualified_section_id,
+ raw_string const& section_id)
+ {
+ raw_string id;
+ id.value = library_id.value;
+ if(!id.empty() && !qualified_section_id.empty()) id.value += '.';
+ id.value += qualified_section_id.value;
+ if(!id.empty() && !section_id.empty()) id.value += '.';
+ id.value += section_id.value;
             return id;
         }
     }
@@ -46,30 +47,32 @@
     begin_section2 process(quickbook::state& state, begin_section const& x)
     {
         // TODO: This uses the generated title.
- state.section_id = x.id ? *x.id :
+ state.section_id.value = x.id ?
+ x.id->value :
             detail::make_identifier(
                 x.content.raw.begin(),
                 x.content.raw.end());
 
         if (state.section_level != 0) {
- state.qualified_section_id += '.';
+ state.qualified_section_id.value += '.';
         }
         else {
             BOOST_ASSERT(state.qualified_section_id.empty());
         }
 
- state.qualified_section_id += state.section_id;
+ state.qualified_section_id.value += state.section_id.value;
         ++state.section_level;
 
         begin_section2 r;
 
         if (qbk_version_n < 103) // version 1.2 and below
         {
- r.id = state.doc_id + "." + state.section_id;
+ r.id.value = state.doc_id.value + "." + state.section_id.value;
         }
         else // version 1.3 and above
         {
- r.linkend = r.id = state.doc_id + "." + state.qualified_section_id;
+ r.linkend.value = r.id.value =
+ state.doc_id.value + "." + state.qualified_section_id.value;
         }
         
         r.content = x.content.content;
@@ -93,14 +96,14 @@
 
         if (state.section_level == 0)
         {
- state.qualified_section_id.clear();
+ state.qualified_section_id.value.clear();
         }
         else
         {
             std::string::size_type const n =
- state.qualified_section_id.find_last_of('.');
+ state.qualified_section_id.value.find_last_of('.');
             if(std::string::npos != n)
- state.qualified_section_id.erase(n, std::string::npos);
+ state.qualified_section_id.value.erase(n, std::string::npos);
         }
         
         return end_section2();
@@ -125,18 +128,20 @@
 
         if (!new_style) // version 1.2 and below
         {
- r.id = state.section_id + "." +
+ r.id.value = state.section_id.value + "." +
                 detail::make_identifier(
                     x.content.content.begin(),
                     x.content.content.end());
         }
         else // version 1.3 and above
         {
- r.linkend = r.id = fully_qualified_id(
- state.doc_id, state.qualified_section_id,
- detail::make_identifier(
+ raw_string id;
+ id.value = detail::make_identifier(
                     x.content.content.begin(),
- x.content.content.end()));
+ x.content.content.end());
+
+ r.linkend = r.id = fully_qualified_id(
+ state.doc_id, state.qualified_section_id, id);
 
         }
 
@@ -177,9 +182,11 @@
                     state.qualified_section_id, *x.id);
             }
             else if(r.title) {
+ raw_string id;
+ id.value = detail::make_identifier(x.title.begin(), x.title.end());
+
                 r.id = fully_qualified_id(state.doc_id,
- state.qualified_section_id,
- detail::make_identifier(x.title.begin(), x.title.end()));
+ state.qualified_section_id, id);
             }
         }
         
@@ -208,7 +215,7 @@
           , std::vector<define_template>& storage // for storing snippets are stored in a
                                                     // vector of define_templates
           , std::string const& extension
- , std::string const& doc_id)
+ , raw_string const& doc_id)
         {
             std::string code;
             int err = detail::load(file, code);
@@ -307,13 +314,13 @@
     nothing process(quickbook::state& state, include const& x)
     {
         fs::path filein = include_search(state.filename.branch_path(), x.path);
- std::string doc_id;
+ raw_string doc_id;
 
         // swap the filenames
         std::swap(state.filename, filein);
 
         // save the doc info strings
- state.doc_id.swap(doc_id);
+ std::swap(state.doc_id, doc_id);
 
         // scope the macros
         macro_symbols macro = state.macro;
@@ -334,7 +341,7 @@
         // restore the values
         std::swap(state.filename, filein);
 
- state.doc_id.swap(doc_id);
+ std::swap(state.doc_id, doc_id);
 
         // restore the macros
         state.macro = macro;

Modified: branches/quickbook-1.5-spirit2/block_markup_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_markup_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_markup_grammar.cpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -30,7 +30,7 @@
 
 BOOST_FUSION_ADAPT_STRUCT(
     quickbook::begin_section,
- (boost::optional<std::string>, id)
+ (boost::optional<quickbook::raw_string>, id)
     (quickbook::title, content)
 )
 
@@ -72,7 +72,7 @@
 
 BOOST_FUSION_ADAPT_STRUCT(
     quickbook::table,
- (boost::optional<std::string>, id)
+ (boost::optional<quickbook::raw_string>, id)
     (std::string, title)
     (std::vector<quickbook::table_row>, rows)
 )
@@ -89,7 +89,7 @@
 
 BOOST_FUSION_ADAPT_STRUCT(
     quickbook::include,
- (boost::optional<std::string>, id)
+ (boost::optional<quickbook::raw_string>, id)
     (std::string, path)
 )
 
@@ -117,7 +117,7 @@
         qi::rule<iterator, std::string()>& inside_paragraph = store_.create();
         qi::rule<iterator, std::string()>& phrase_attr = store_.create();
         qi::rule<iterator>& phrase_end = store_.create();
- qi::rule<iterator, boost::optional<std::string>()>& element_id = store_.create();
+ qi::rule<iterator, boost::optional<raw_string>()>& element_id = store_.create();
         qi::rule<iterator>& error = store_.create();
 
         block_markup =
@@ -299,17 +299,22 @@
>> qi::attr(nothing())
             ;
 
+ qi::rule<iterator, raw_string()>& include_id = store_.create();
+
         include =
                 "include"
>> hard_space
>> -(
                     ':'
- >> *((qi::alnum | '_') - qi::space)
+ >> include_id
>> space
                 )
>> *(qi::char_ - phrase_end)
             ;
 
+ include_id = qi::raw[*((qi::alnum | '_') - qi::space)]
+ [qi::_val = qi::_1];
+
         import =
                 "import"
>> hard_space
@@ -396,7 +401,7 @@
 
         // Identifiers
 
- qi::rule<iterator, std::string()>& element_id_part = store_.create();
+ qi::rule<iterator, raw_string()>& element_id_part = store_.create();
 
         element_id =
             ( ':'
@@ -411,7 +416,8 @@
             | qi::eps
             ;
 
- element_id_part = +(qi::alnum | qi::char_('_'));
+ element_id_part = qi::raw[+(qi::alnum | qi::char_('_'))]
+ [qi::_val = qi::_1];
 
         error =
             qi::raw[qi::eps] [actions.error];

Modified: branches/quickbook-1.5-spirit2/boostbook.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/boostbook.cpp (original)
+++ branches/quickbook-1.5-spirit2/boostbook.cpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -23,6 +23,11 @@
         return r;
     }
 
+ std::string boostbook_encoder::encode(raw_string const& x)
+ {
+ return encode_impl(x.begin(), x.end());
+ }
+
     std::string boostbook_encoder::encode(std::string const& x)
     {
         return encode_impl(x.begin(), x.end());
@@ -215,7 +220,7 @@
 
     void boostbook_encoder::operator()(quickbook::state& state, begin_section2 const& x)
     {
- state.phrase << "\n<section id=\"" << x.id << "\">\n";
+ state.phrase << "\n<section id=\"" << encode(x.id) << "\">\n";
         if(x.linkend.empty()) {
             state.phrase
                 << "<title>"
@@ -227,7 +232,7 @@
             state.phrase
                 << "<title>"
                 << "<link linkend=\""
- << x.linkend
+ << encode(x.linkend)
                 << "\">"
                 << x.content
                 << "</link>"
@@ -244,7 +249,7 @@
     void boostbook_encoder::operator()(quickbook::state& state, heading2 const& x)
     {
         state.phrase
- << "<anchor id=\"" << x.id << "\"/>"
+ << "<anchor id=\"" << encode(x.id) << "\"/>"
             << "<bridgehead renderas=\"sect" << x.level << "\">";
 
         if(x.linkend.empty()) {
@@ -252,7 +257,7 @@
         }
         else {
             state.phrase
- << "<link linkend=\"" << x.linkend << "\">"
+ << "<link linkend=\"" << encode(x.linkend) << "\">"
                 << x.content << "</link>";
         }
 
@@ -286,7 +291,7 @@
         {
             state.phrase << "<table frame=\"all\"";
             if(x.id)
- state.phrase << " id=\"" << *x.id << "\"";
+ state.phrase << " id=\"" << encode(*x.id) << "\"";
             state.phrase << ">\n";
             state.phrase << "<title>";
             state.phrase << encode(*x.title);
@@ -296,7 +301,7 @@
         {
             state.phrase << "<informaltable frame=\"all\"";
             if(x.id)
- state.phrase << " id=\"" << *x.id << "\"";
+ state.phrase << " id=\"" << encode(*x.id) << "\"";
             state.phrase << ">\n";
         }
 
@@ -413,20 +418,20 @@
         // Document tag
 
         state.phrase
- << '<' << info.doc_type << " id=\"" << info.doc_id << "\"\n";
+ << '<' << info.doc_type << " id=\"" << encode(info.doc_id) << "\"\n";
         
         if(info.doc_type == "library")
         {
- state.phrase << " name=\"" << info.doc_title << "\"\n";
+ state.phrase << " name=\"" << encode(info.doc_title) << "\"\n";
         }
 
         if(!info.doc_dirname.empty())
         {
- state.phrase << " dirname=\"" << info.doc_dirname << "\"\n";
+ state.phrase << " dirname=\"" << encode(info.doc_dirname) << "\"\n";
         }
 
         state.phrase
- << "last-revision=\"" << info.doc_last_revision << "\""
+ << "last-revision=\"" << encode(info.doc_last_revision) << "\""
             << " xmlns:xi=\"http://www.w3.org/2001/XInclude\"";
 
         state.phrase << ">"; // end document tag.
@@ -434,11 +439,11 @@
         // Title tag
 
         std::string title;
- if(!info.doc_title.empty())
+ if(info.doc_title.begin() != info.doc_title.end())
         {
- title = "<title>" + info.doc_title;
+ title = "<title>" + encode(info.doc_title);
             if (!info.doc_version.empty())
- title += ' ' + info.doc_version;
+ title += ' ' + info.doc_version.value;
             title += "</title>\n";
         }
 
@@ -504,7 +509,7 @@
         {
             state.phrase
                 << "<" << info.doc_type << "category name=\"category:"
- << info.doc_category
+ << encode(info.doc_category)
                 << "\"></" << info.doc_type << "category>\n"
                 << "\n"
             ;

Modified: branches/quickbook-1.5-spirit2/code_snippet_actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/code_snippet_actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/code_snippet_actions.cpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -37,7 +37,8 @@
         using detail::callout_id;
 
         callout_source item;
- item.identifier = actions.doc_id + boost::lexical_cast<std::string>(callout_id + actions.callouts.size());
+ item.identifier = std::string(actions.doc_id.begin(), actions.doc_id.end());
+ item.identifier += boost::lexical_cast<std::string>(callout_id + actions.callouts.size());
         item.body = template_value(x.position, x.content);
 
         actions.code += "``[[callout]";

Modified: branches/quickbook-1.5-spirit2/code_snippet_types.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/code_snippet_types.hpp (original)
+++ branches/quickbook-1.5-spirit2/code_snippet_types.hpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -18,6 +18,7 @@
 #include <boost/spirit/include/support_unused.hpp>
 #include "fwd.hpp"
 #include "template.hpp"
+#include "strings.hpp"
 
 namespace quickbook
 {
@@ -65,7 +66,7 @@
     struct code_snippet_actions
     {
         code_snippet_actions(std::vector<define_template>& storage,
- std::string const& doc_id,
+ raw_string const& doc_id,
                                  char const* source_type)
             : process(*this)
             , output(*this)
@@ -102,7 +103,7 @@
         std::string snippet;
         quickbook::callouts callouts;
         std::vector<define_template>& storage;
- std::string const doc_id;
+ raw_string const doc_id;
         char const* const source_type;
     };
 }

Modified: branches/quickbook-1.5-spirit2/doc_info.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/doc_info.hpp (original)
+++ branches/quickbook-1.5-spirit2/doc_info.hpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -13,6 +13,8 @@
 #include <vector>
 #include <string>
 #include <utility>
+#include "fwd.hpp"
+#include "strings.hpp"
 
 namespace quickbook
 {
@@ -25,16 +27,16 @@
         typedef std::vector<author> author_list;
 
         std::string doc_type;
- std::string doc_title;
- std::string doc_version;
- std::string doc_id;
- std::string doc_dirname;
+ raw_string doc_title;
+ raw_string doc_version;
+ raw_string doc_id;
+ raw_string doc_dirname;
         copyright_list doc_copyrights;
         std::string doc_purpose;
- std::string doc_category;
+ raw_string doc_category;
         author_list doc_authors;
         std::string doc_license;
- std::string doc_last_revision;
+ raw_string doc_last_revision;
         bool ignore;
     };
     

Modified: branches/quickbook-1.5-spirit2/doc_info_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/doc_info_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/doc_info_grammar.cpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -62,7 +62,10 @@
         qi::symbols<char> doc_types;
         qi::rule<iterator, doc_info()> doc_info_details;
         qi::rule<iterator, std::pair<unsigned, unsigned>()> quickbook_version;
- qi::rule<iterator, std::string()> phrase, doc_version, doc_id, doc_dirname, doc_category, doc_last_revision, doc_source_mode, doc_purpose, doc_license;
+ qi::rule<iterator, std::string()> phrase;
+ qi::rule<iterator, raw_source()> doc_version, doc_id, doc_dirname, doc_category, doc_last_revision;
+ qi::rule<iterator, std::string()> doc_source_mode; // TODO: raw_source
+ qi::rule<iterator, std::string()> doc_purpose, doc_license;
         qi::rule<iterator, std::pair<std::vector<unsigned int>, std::string>()> doc_copyright;
         qi::rule<iterator, std::vector<std::pair<std::string, std::string> >()> doc_authors;
         qi::rule<iterator, boost::fusion::reverse_view<
@@ -90,13 +93,12 @@
         
         doc_info_details =
             space
- >> '[' >> space
- >> qi::raw[doc_types] [member_assign(&doc_info::doc_type)]
- >> hard_space
- >> ( *(qi::char_ -
- (qi::char_('[') | ']' | qi::eol)
- )
- ) [member_assign(&doc_info::doc_title)]
+ >> '[' >> space
+ >> qi::raw[doc_types] [member_assign(&doc_info::doc_type)]
+ >> hard_space
+ >> qi::raw[
+ *(qi::char_ - (qi::char_('[') | ']' | qi::eol))
+ ] [member_assign(&doc_info::doc_title)]
>> quickbook_version [set_quickbook_version]
>>
                 *(
@@ -130,11 +132,11 @@
>> space >> ']'
             );
 
- doc_version = "version" >> hard_space >> *(qi::char_ - ']');
- doc_id = "id" >> hard_space >> *(qi::char_ - ']');
- doc_dirname = "dirname" >> hard_space >> *(qi::char_ - ']');
- doc_category="category" >> hard_space >> *(qi::char_ - ']');
- doc_last_revision = "last-revision" >> hard_space >> *(qi::char_ - ']');
+ doc_version = "version" >> hard_space >> qi::raw[*(qi::char_ - ']')];
+ doc_id = "id" >> hard_space >> qi::raw[*(qi::char_ - ']')];
+ doc_dirname = "dirname" >> hard_space >> qi::raw[*(qi::char_ - ']')];
+ doc_category="category" >> hard_space >> qi::raw[*(qi::char_ - ']')];
+ doc_last_revision = "last-revision" >> hard_space >> qi::raw[*(qi::char_ - ']')];
 
         doc_copyright =
                 "copyright"

Modified: branches/quickbook-1.5-spirit2/encoder.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/encoder.hpp (original)
+++ branches/quickbook-1.5-spirit2/encoder.hpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -20,6 +20,7 @@
 #include "doc_info.hpp"
 #include "gen_types.hpp"
 #include "template.hpp"
+#include "strings.hpp"
 
 namespace quickbook
 {
@@ -61,6 +62,7 @@
     
         virtual void operator()(quickbook::state&, code_token const&) = 0;
     
+ virtual std::string encode(raw_string const&) = 0;
         virtual std::string encode(std::string const&) = 0;
         virtual std::string encode(char) = 0;
         virtual std::string encode(char const*) = 0;

Modified: branches/quickbook-1.5-spirit2/encoder_impl.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/encoder_impl.hpp (original)
+++ branches/quickbook-1.5-spirit2/encoder_impl.hpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -1,3 +1,14 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ Copyright (c) 2010 Daniel James
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+
 #include "fwd.hpp"
 #include "encoder.hpp"
 #include "phrase.hpp"
@@ -35,6 +46,7 @@
     
         virtual void operator()(quickbook::state&, code_token const&);
     
+ virtual std::string encode(raw_string const&);
         virtual std::string encode(std::string const&);
         virtual std::string encode(char);
         virtual std::string encode(char const*);
@@ -71,6 +83,7 @@
     
         virtual void operator()(quickbook::state&, code_token const&);
     
+ virtual std::string encode(raw_string const&);
         virtual std::string encode(std::string const&);
         virtual std::string encode(char);
         virtual std::string encode(char const*);

Modified: branches/quickbook-1.5-spirit2/fwd.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/fwd.hpp (original)
+++ branches/quickbook-1.5-spirit2/fwd.hpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -35,6 +35,8 @@
         std::string::const_iterator> iterator;
     typedef boost::spirit::classic::file_position file_position;
     typedef boost::iterator_range<iterator> raw_source;
+
+ struct raw_string;
 
     // templates
 

Modified: branches/quickbook-1.5-spirit2/gen_types.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/gen_types.hpp (original)
+++ branches/quickbook-1.5-spirit2/gen_types.hpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -30,9 +30,9 @@
     };
     
     struct begin_section2 {
- std::string id;
+ raw_string id;
         std::string content;
- std::string linkend;
+ raw_string linkend;
     };
 
     struct end_section2 {
@@ -41,14 +41,14 @@
     struct heading2
     {
         int level;
- std::string id;
+ raw_string id;
         std::string content;
- std::string linkend;
+ raw_string linkend;
     };
 
     struct table2
     {
- boost::optional<std::string> id;
+ boost::optional<raw_string> id;
         boost::optional<std::string> title;
         int cols;
         boost::optional<table_row> head;

Modified: branches/quickbook-1.5-spirit2/html.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/html.cpp (original)
+++ branches/quickbook-1.5-spirit2/html.cpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -27,6 +27,11 @@
         return r;
     }
 
+ std::string html_encoder::encode(raw_string const& x)
+ {
+ return encode_impl(x.begin(), x.end());
+ }
+
     std::string html_encoder::encode(std::string const& x)
     {
         return encode_impl(x.begin(), x.end());
@@ -231,7 +236,7 @@
         int level = state.section_level + 1;
         if (level > 6) level = 6;
     
- state.phrase << "\n<section id=\"" << x.id << "\">\n";
+ state.phrase << "\n<section id=\"" << encode(x.id) << "\">\n";
         if(x.linkend.empty()) {
             state.phrase
                 << "<h" << level << ">"
@@ -242,7 +247,7 @@
         else {
             state.phrase
                 << "<h" << level << " id=\""
- << x.linkend
+ << encode(x.linkend)
                 << "\">"
                 << x.content
                 << "</h" << level << ">\n"
@@ -262,12 +267,12 @@
     void html_encoder::operator()(quickbook::state& state, heading2 const& x)
     {
         state.phrase
- << "<h" << x.level << " id=\"" << x.id << "\">"
+ << "<h" << x.level << " id=\"" << encode(x.id) << "\">"
             ;
 
         if(!x.linkend.empty()) {
             state.phrase
- << "<a id=\"" << x.linkend << "\"></a>"
+ << "<a id=\"" << encode(x.linkend) << "\"></a>"
                 ;
         }
         state.phrase << x.content;
@@ -303,7 +308,7 @@
         {
             state.phrase << "<table";
             if(x.id)
- state.phrase << " id=\"" << *x.id << "\"";
+ state.phrase << " id=\"" << encode(*x.id) << "\"";
             state.phrase << ">\n";
             state.phrase << "<caption>";
             state.phrase << encode(*x.title);
@@ -313,7 +318,7 @@
         {
             state.phrase << "<table";
             if(x.id)
- state.phrase << " id=\"" << *x.id << "\"";
+ state.phrase << " id=\"" << encode(*x.id) << "\"";
             state.phrase << ">\n";
         }
 
@@ -426,12 +431,12 @@
         state.phrase
             << "<!DOCTYPE html>"
             << "<html><head>"
- << "<title>" << info.doc_title << "</title>"
+ << "<title>" << encode(info.doc_title) << "</title>"
             << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
             << "</head>"
             << "<body>"
             << "<header>"
- << "<h1>" << info.doc_title << "</h1>"
+ << "<h1>" << encode(info.doc_title) << "</h1>"
             ;
 
         if(!info.doc_authors.empty() || !info.doc_copyrights.empty() ||
@@ -554,8 +559,8 @@
             
             BOOST_FOREACH(footnote const& x, notes) {
                 state.phrase
- << "<dt id=\"footnote_" << x.id << "\">"
- << "<a href=\"#footnote_ref_" << x.id << "\">"
+ << "<dt id=\"footnote_" << encode(x.id) << "\">"
+ << "<a href=\"#footnote_ref_" << encode(x.id) << "\">"
                     << "Footnote"
                     << "</a>"
                     << "</dt>"

Modified: branches/quickbook-1.5-spirit2/parse_utils.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/parse_utils.hpp (original)
+++ branches/quickbook-1.5-spirit2/parse_utils.hpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -34,6 +34,11 @@
             (ph::bind(mem_ptr_, spirit::_val) = attrib)(attrib, context, pass);
         }
         
+ template <typename Attrib, typename Context>
+ void operator()(Attrib& attrib, Context& context, bool& pass) const {
+ (ph::bind(mem_ptr_, spirit::_val) = attrib)(attrib, context, pass);
+ }
+
         Member Struct::*mem_ptr_;
     };
     

Modified: branches/quickbook-1.5-spirit2/state.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/state.hpp (original)
+++ branches/quickbook-1.5-spirit2/state.hpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -17,6 +17,7 @@
 #include "collector.hpp"
 #include "template.hpp"
 #include "actions.hpp"
+#include "strings.hpp"
 
 namespace quickbook
 {
@@ -34,8 +35,8 @@
 
         static int const max_template_depth = 100;
 
- std::string doc_id;
- std::string doc_title;
+ raw_string doc_id;
+ raw_string doc_title;
 
     // main output stream
         collector phrase;
@@ -50,16 +51,16 @@
         macro_symbols macro;
         int section_level;
         int min_section_level;
- std::string section_id;
- std::string qualified_section_id;
+ raw_string section_id;
+ raw_string qualified_section_id;
         std::string source_mode;
 
         typedef boost::tuple<
             macro_symbols
           , int
           , int
- , std::string
- , std::string
+ , raw_string
+ , raw_string
           , std::string>
         state_tuple;
 

Added: branches/quickbook-1.5-spirit2/strings.hpp
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/strings.hpp 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -0,0 +1,39 @@
+/*=============================================================================
+ Copyright (c) 2010 Daniel James
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_QUICKBOOK_STRINGS_HPP)
+#define BOOST_SPIRIT_QUICKBOOK_STRINGS_HPP
+
+#include "fwd.hpp"
+
+namespace quickbook
+{
+ struct raw_string {
+ raw_string() {}
+ explicit raw_string(raw_source const& x) : value(x.begin(), x.end()) {}
+ raw_string& operator=(raw_source const& x) {
+ value.assign(x.begin(), x.end());
+ return *this;
+ }
+ raw_string& operator=(std::string const& x) {
+ value = x;
+ return *this;
+ }
+ raw_string& operator=(char const* x) {
+ value = x;
+ return *this;
+ }
+ std::string::const_iterator begin() const { return value.begin(); }
+ std::string::const_iterator end() const { return value.end(); }
+ bool empty() const { return value.empty(); }
+
+ std::string value;
+ };
+}
+
+#endif
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/test/Jamfile.v2
==============================================================================
--- branches/quickbook-1.5-spirit2/test/Jamfile.v2 (original)
+++ branches/quickbook-1.5-spirit2/test/Jamfile.v2 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -37,6 +37,7 @@
     [ quickbook-test doc-info-1 ]
     [ quickbook-test callouts ]
     [ quickbook-test simple_markup ]
+ [ quickbook-test xml-escape ]
     [ quickbook-fail-test fail-include ]
     [ quickbook-fail-test fail-import ]
     [ quickbook-fail-test fail-template-arguments1 ]

Added: branches/quickbook-1.5-spirit2/test/xml-escape.gold
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/test/xml-escape.gold 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<article id="test_that______are_being_escaped_" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+ xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>Test that &amp;, &lt; are being escaped.</title>
+ <articleinfo>
+ <articlepurpose>
+ &amp; should be &amp;amp;, &lt; should &amp;lt;
+ </articlepurpose>
+ </articleinfo>
+ <section id="test_that______are_being_escaped_.escapes___explicitly_written_markup">
+ <title><link linkend="test_that______are_being_escaped_.escapes___explicitly_written_markup">Escapes
+ &amp; explicitly written markup</link></title>
+ <itemizedlist>
+ <listitem>
+ &amp; -&gt; &amp;amp;
+ </listitem>
+ <listitem>
+ &lt; -&gt; &amp;lt;
+ </listitem>
+ <listitem>
+ &gt; -&gt; &amp;gt;
+ </listitem>
+ <listitem>
+ &quot; -&gt; &amp;quot;
+ </listitem>
+ </itemizedlist>
+ </section>
+</article>

Added: branches/quickbook-1.5-spirit2/test/xml-escape.quickbook
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/test/xml-escape.quickbook 2010-04-05 15:43:14 EDT (Mon, 05 Apr 2010)
@@ -0,0 +1,13 @@
+[article Test that &, < are being escaped.
+ [quickbook 1.5]
+ [purpose & should be &amp;, < should &lt;]
+]
+
+[section Escapes & explicitly written markup]
+
+* & -> &amp;
+* < -> &lt;
+* > -> &gt;
+* " -> &quot;
+
+[endsect]
\ No newline at end of file


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk