Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59568 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-02-07 09:48:17


Author: danieljames
Date: 2010-02-07 09:48:16 EST (Sun, 07 Feb 2010)
New Revision: 59568
URL: http://svn.boost.org/trac/boost/changeset/59568

Log:
Get rid of 'as_string'. Use iterator ranges in some places instead of strings.
Text files modified:
   branches/quickbook-1.5-spirit2/block.cpp | 4 +-
   branches/quickbook-1.5-spirit2/block.hpp | 2
   branches/quickbook-1.5-spirit2/block_actions.cpp | 12 +++++-----
   branches/quickbook-1.5-spirit2/fwd.hpp | 2 +
   branches/quickbook-1.5-spirit2/parse_utils.hpp | 16 -------------
   branches/quickbook-1.5-spirit2/post_process.cpp | 46 ++++++++++++++++++---------------------
   6 files changed, 32 insertions(+), 50 deletions(-)

Modified: branches/quickbook-1.5-spirit2/block.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block.cpp (original)
+++ branches/quickbook-1.5-spirit2/block.cpp 2010-02-07 09:48:16 EST (Sun, 07 Feb 2010)
@@ -40,7 +40,7 @@
 
 BOOST_FUSION_ADAPT_STRUCT(
     quickbook::title,
- (std::string, raw_markup)
+ (quickbook::raw_source, raw)
     (std::string, content)
 )
 
@@ -484,7 +484,7 @@
         title_phrase =
             qi::raw[
                 phrase_attr [ph::at_c<1>(qi::_val) = qi::_1]
- ] [ph::at_c<0>(qi::_val) = as_string(qi::_1)]
+ ] [ph::at_c<0>(qi::_val) = qi::_1]
             ;
 
         inside_paragraph =

Modified: branches/quickbook-1.5-spirit2/block.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block.hpp (original)
+++ branches/quickbook-1.5-spirit2/block.hpp 2010-02-07 09:48:16 EST (Sun, 07 Feb 2010)
@@ -39,7 +39,7 @@
 
     struct title
     {
- std::string raw_markup;
+ raw_source raw;
         std::string content;
     };
 

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-02-07 09:48:16 EST (Sun, 07 Feb 2010)
@@ -48,8 +48,8 @@
         // TODO: This uses the generated title.
         state.section_id = x.id ? *x.id :
             detail::make_identifier(
- x.content.raw_markup.begin(),
- x.content.raw_markup.end());
+ x.content.raw.begin(),
+ x.content.raw.end());
 
         if (state.section_level != 0) {
             state.qualified_section_id += '.';
@@ -125,16 +125,16 @@
         {
             r.id = state.section_id + "." +
                 detail::make_identifier(
- x.content.raw_markup.begin(),
- x.content.raw_markup.end());
+ x.content.raw.begin(),
+ x.content.raw.end());
         }
         else // version 1.3 and above
         {
             r.linkend = r.id = fully_qualified_id(
                 state.doc_id, state.qualified_section_id,
                 detail::make_identifier(
- x.content.raw_markup.begin(),
- x.content.raw_markup.end()));
+ x.content.raw.begin(),
+ x.content.raw.end()));
 
         }
 

Modified: branches/quickbook-1.5-spirit2/fwd.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/fwd.hpp (original)
+++ branches/quickbook-1.5-spirit2/fwd.hpp 2010-02-07 09:48:16 EST (Sun, 07 Feb 2010)
@@ -11,6 +11,7 @@
 #define BOOST_SPIRIT_FWD_HPP
 
 #include <boost/spirit/include/classic_iterator.hpp>
+#include <boost/range.hpp>
 
 namespace quickbook
 {
@@ -30,6 +31,7 @@
     typedef boost::spirit::classic::position_iterator<
         std::string::const_iterator> iterator;
     typedef boost::spirit::classic::file_position file_position;
+ typedef boost::iterator_range<iterator> raw_source;
 
     // templates
 

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-02-07 09:48:16 EST (Sun, 07 Feb 2010)
@@ -13,7 +13,6 @@
 #define BOOST_SPIRIT_QUICKBOOK_AS_STRING_HPP
 
 #include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_function.hpp>
 #include <boost/spirit/include/phoenix_bind.hpp>
 #include <boost/spirit/include/qi_core.hpp>
 #include <string>
@@ -23,20 +22,6 @@
     namespace spirit = boost::spirit;
     namespace ph = boost::phoenix;
 
- // as_string - converts a char range to a string.
-
- struct as_string_impl
- {
- template <typename Arg>
- struct result { typedef std::string type; };
-
- template <typename Arg>
- std::string operator()(Arg const& arg1) const
- {
- return std::string(arg1.begin(), arg1.end());
- }
- };
-
     struct get_position_impl
     {
         template <typename Range, typename Context>
@@ -47,7 +32,6 @@
 
     namespace {
         get_position_impl get_position;
- ph::function<as_string_impl> as_string;
     }
 
     // member_assign - action to assign the attribute to a member of the

Modified: branches/quickbook-1.5-spirit2/post_process.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/post_process.cpp (original)
+++ branches/quickbook-1.5-spirit2/post_process.cpp 2010-02-07 09:48:16 EST (Sun, 07 Feb 2010)
@@ -268,12 +268,17 @@
     template <typename Iterator>
     struct tidy_grammar : qi::grammar<Iterator>
     {
+ typedef boost::iterator_range<Iterator> iterator_range;
+
         tidy_grammar(tidy_compiler& state, int indent)
             : tidy_grammar::base_type(tidy)
             , state(state), indent(indent)
         {
- tag = (qi::lexeme[+(qi::alpha | qi::char_("_:"))])
- [ph::bind(&tidy_grammar::do_tag, this, as_string(qi::_1))];
+ tag =
+ qi::lexeme[qi::raw[
+ +(qi::alpha | qi::char_("_:"))
+ ]]
+ [ph::bind(&tidy_grammar::do_tag, this, qi::_1)];
 
             code = qi::raw[
                     "<programlisting>"
@@ -286,19 +291,13 @@
             // otherwise consumed by the space skipper.
 
             escape =
- qi::lit("<!--quickbook-escape-prefix-->") >>
- (*(qi::char_ - (qi::lit("<!--quickbook-escape-postfix-->"))))
- [
- ph::bind(&tidy_grammar::do_escape, this, as_string(qi::_1))
- ]
- >> qi::lexeme
- [
- qi::lit("<!--quickbook-escape-postfix-->") >>
- (*qi::space)
- [
- ph::bind(&tidy_grammar::do_escape_post, this, as_string(qi::_1))
- ]
+ ( "<!--quickbook-escape-prefix-->"
+ >> qi::raw[*(qi::char_ - "<!--quickbook-escape-postfix-->")]
+ >> qi::lexeme[
+ "<!--quickbook-escape-postfix-->"
+ >> qi::raw[*qi::space]
                     ]
+ ) [ph::bind(&tidy_grammar::do_escape, this, qi::_1, qi::_2)]
                 ;
 
             start_tag = qi::raw['<' >> tag >> *(qi::char_ - '>') >> qi::lexeme['>' >> *qi::space]];
@@ -323,21 +322,18 @@
             tidy = +markup;
         }
 
- void do_escape_post(std::string const& x) const
+ void do_escape(iterator_range x, iterator_range post) const
         {
- for (std::string::const_iterator i = x.begin(), l = x.end(); i != l; ++i)
- state.out += *i;
- }
-
- void do_escape(std::string const& x) const
- {
- std::string::const_iterator f = x.begin(), l = x.end();
+ // Trim spaces from contents and append
+ Iterator f = x.begin(), l = x.end();
             while (f != l && std::isspace(*f))
                 ++f;
             while (f != l && std::isspace(*(l - 1)))
                 --l;
- for (std::string::const_iterator i = f; i != l; ++i)
- state.out += *i;
+ state.out.append(f, l);
+
+ // Append spaces trailing the closing tag.
+ state.out.append(post.begin(), post.end());
         }
 
         void do_code(std::string const& x) const
@@ -370,7 +366,7 @@
             state.printer_.indent();
         }
 
- void do_tag(std::string const& x) const
+ void do_tag(iterator_range x) const
         {
             state.current_tag = std::string(x.begin(), x.end());
         }


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