Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76381 - in trunk: boost/spirit/home/karma/directive libs/spirit/doc libs/spirit/test libs/spirit/test/karma
From: hartmut.kaiser_at_[hidden]
Date: 2012-01-09 08:47:25


Author: hkaiser
Date: 2012-01-09 08:47:25 EST (Mon, 09 Jan 2012)
New Revision: 76381
URL: http://svn.boost.org/trac/boost/changeset/76381

Log:
Spirit: Fixing problems in karma::center[] directive
Added:
   trunk/libs/spirit/test/karma/regression_center_alignment.cpp (contents, props changed)
Text files modified:
   trunk/boost/spirit/home/karma/directive/center_alignment.hpp | 32 ++++++++++++++++----------------
   trunk/libs/spirit/doc/what_s_new.qbk | 3 +++
   trunk/libs/spirit/test/Jamfile | 3 ++-
   3 files changed, 21 insertions(+), 17 deletions(-)

Modified: trunk/boost/spirit/home/karma/directive/center_alignment.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/directive/center_alignment.hpp (original)
+++ trunk/boost/spirit/home/karma/directive/center_alignment.hpp 2012-01-09 08:47:25 EST (Mon, 09 Jan 2012)
@@ -53,20 +53,20 @@
 
     // enables *lazy* center(d)[g], where d provides a generator
     template <>
- struct use_lazy_directive<karma::domain, tag::center, 1>
+ struct use_lazy_directive<karma::domain, tag::center, 1>
       : mpl::true_ {};
 
- // enables center(w, d)[g], where d is a generator and w is a maximum
+ // enables center(w, d)[g], where d is a generator and w is a maximum
     // width
     template <typename Width, typename Padding>
     struct use_directive<karma::domain
           , terminal_ex<tag::center, fusion::vector2<Width, Padding> > >
       : spirit::traits::matches<karma::domain, Padding> {};
 
- // enables *lazy* center(w, d)[g], where d provides a generator and w is
+ // enables *lazy* center(w, d)[g], where d provides a generator and w is
     // a maximum width
     template <>
- struct use_lazy_directive<karma::domain, tag::center, 2>
+ struct use_lazy_directive<karma::domain, tag::center, 2>
       : mpl::true_ {};
 
 }}
@@ -82,15 +82,15 @@
     namespace detail
     {
         ///////////////////////////////////////////////////////////////////////
- // The center_generate template function is used for all the
- // different flavors of the center[] directive.
+ // The center_generate template function is used for all the
+ // different flavors of the center[] directive.
         ///////////////////////////////////////////////////////////////////////
- template <typename OutputIterator, typename Context, typename Delimiter,
+ template <typename OutputIterator, typename Context, typename Delimiter,
             typename Attribute, typename Embedded, typename Padding>
- inline static bool
- center_generate(OutputIterator& sink, Context& ctx,
- Delimiter const& d, Attribute const& attr, Embedded const& e,
- unsigned int const width, Padding const& p)
+ inline static bool
+ center_generate(OutputIterator& sink, Context& ctx,
+ Delimiter const& d, Attribute const& attr, Embedded const& e,
+ unsigned int const width, Padding const& p)
         {
 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
             e; // suppresses warning: C4100: 'e' : unreferenced formal parameter
@@ -99,7 +99,7 @@
             detail::enable_buffering<OutputIterator> buffering(sink, width);
             bool r = false;
 
- // first generate the embedded output
+ // first generate the embedded output
             {
                 detail::disable_counting<OutputIterator> nocounting(sink);
                 r = e.generate(sink, ctx, d, attr);
@@ -111,7 +111,7 @@
             detail::enable_counting<OutputIterator> counting(sink);
 
             std::size_t const pre = width - (buffering.buffer_size() + width)/2;
- while (r && counting.count() < pre)
+ while (r && counting.count() < pre)
                 r = p.generate(sink, ctx, unused, unused);
 
             if (r) {
@@ -119,7 +119,7 @@
                 buffering.buffer_copy();
 
                 // generate the right padding
- while (r && counting.count() < width)
+ while (r && counting.count() < width)
                     r = p.generate(sink, ctx, unused, unused);
             }
             return r;
@@ -185,12 +185,12 @@
 
         typedef mpl::int_<
             generator_properties::countingbuffer |
- subject_type::properties::value | padding_type::properties::value
+ subject_type::properties::value | padding_type::properties::value
> properties;
 
         template <typename Context, typename Iterator>
         struct attribute
- : traits::attribute_of<Subject, Context, Iterator>::type
+ : traits::attribute_of<Subject, Context, Iterator>
         {};
 
         padding_center_alignment(Subject const& subject, Padding const& padding

Modified: trunk/libs/spirit/doc/what_s_new.qbk
==============================================================================
--- trunk/libs/spirit/doc/what_s_new.qbk (original)
+++ trunk/libs/spirit/doc/what_s_new.qbk 2012-01-09 08:47:25 EST (Mon, 09 Jan 2012)
@@ -20,6 +20,9 @@
 * Added the possibility to match a token range when parsing with a lexer by
   using `qi::token(min, max)`, or `qi::tokenid(min, max)`. Both parsers match
   any token with a token id in the range [min, max].
+* Fixed a problem in [karma_align `center`]`(num)[a]` and
+ [karma_align `center`]`(num, g)[a]` if used inside a compound generator (such
+ as sequences, Kleene, list, or plus.
 
 [endsect]
 

Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2012-01-09 08:47:25 EST (Mon, 09 Jan 2012)
@@ -1,6 +1,6 @@
 #==============================================================================
 # Copyright (c) 2001-2011 Joel de Guzman
-# Copyright (c) 2001-2011 Hartmut Kaiser
+# Copyright (c) 2001-2012 Hartmut Kaiser
 # Copyright (c) 2011 Bryce Lelbach
 #
 # Use, modification and distribution is subject to the Boost Software
@@ -248,6 +248,7 @@
      [ run karma/regression_optional_double.cpp : : : : karma_regression_optional_double ]
      [ run karma/regression_semantic_action_attribute.cpp : : : : karma_regression_semantic_action_attribute ]
      [ run karma/regression_real_scientific.cpp : : : : karma_regression_real_scientific ]
+ [ run karma/regression_center_alignment.cpp : : : : karma_regression_center_alignment ]
 
     ;
 

Added: trunk/libs/spirit/test/karma/regression_center_alignment.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/regression_center_alignment.cpp 2012-01-09 08:47:25 EST (Mon, 09 Jan 2012)
@@ -0,0 +1,66 @@
+// Copyright (c) 2001-2012 Hartmut Kaiser
+// Copyright (c) 2012 yyyy yyyy <typhoonking77_at_[hidden]>
+//
+// Distributed under 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 <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <string>
+#include <vector>
+
+#include<boost/spirit/include/karma.hpp>
+
+int main()
+{
+ namespace karma = boost::spirit::karma;
+
+ int num[] = {0, 1, 2, 3, 4, 5};
+ std::vector<int> contents(num, num + sizeof(num) / sizeof(int));
+
+ {
+ std::string result;
+ BOOST_TEST(karma::generate(std::back_inserter(result),
+ *karma::center[karma::int_], contents));
+ BOOST_TEST(result == " 0 1 2 3 4 5 ");
+ }
+
+ {
+ std::string result;
+ BOOST_TEST(karma::generate(std::back_inserter(result),
+ *karma::center(5)[karma::int_], contents));
+ BOOST_TEST(result == " 0 1 2 3 4 5 ");
+ }
+
+ {
+ std::string result;
+ BOOST_TEST(karma::generate(std::back_inserter(result),
+ *karma::center("_")[karma::int_], contents));
+ BOOST_TEST(result == "_____0_________1_________2_________3_________4_________5____");
+ }
+
+ {
+ std::string result;
+ BOOST_TEST(karma::generate(std::back_inserter(result),
+ *karma::center(5, "_")[karma::int_], contents));
+ BOOST_TEST(result == "__0____1____2____3____4____5__");
+ }
+
+ {
+ std::string result;
+ BOOST_TEST(karma::generate(std::back_inserter(result),
+ *karma::center(karma::char_("_"))[karma::int_], contents));
+ BOOST_TEST(result == "_____0_________1_________2_________3_________4_________5____");
+ }
+
+ {
+ std::string result;
+ BOOST_TEST(karma::generate(std::back_inserter(result),
+ *karma::center(5, karma::char_("_"))[karma::int_], contents));
+ BOOST_TEST(result == "__0____1____2____3____4____5__");
+ }
+
+ return boost::report_errors();
+}
+


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