Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84187 - in trunk/tools/quickbook: src test/unit
From: dnljms_at_[hidden]
Date: 2013-05-07 19:25:48


Author: danieljames
Date: 2013-05-07 19:25:47 EDT (Tue, 07 May 2013)
New Revision: 84187
URL: http://svn.boost.org/trac/boost/changeset/84187

Log:
Fix unindenting trailing spaces in code blocks.
Text files modified:
   trunk/tools/quickbook/src/files.cpp | 2 ++
   trunk/tools/quickbook/test/unit/source_map_test.cpp | 39 +++++++++++++++++++++++++++++++++++++++
   2 files changed, 41 insertions(+), 0 deletions(-)

Modified: trunk/tools/quickbook/src/files.cpp
==============================================================================
--- trunk/tools/quickbook/src/files.cpp (original)
+++ trunk/tools/quickbook/src/files.cpp 2013-05-07 19:25:47 EDT (Tue, 07 May 2013)
@@ -566,6 +566,7 @@
                 copied = pos;
 
                 std::string::size_type next = program.find_first_not_of(" \t", pos);
+ if (next == std::string::npos) next = program.size();
 
                 unsigned length = indentation_count(boost::string_ref(
                     &program[pos], next - pos));
@@ -596,6 +597,7 @@
                 copied = pos;
 
                 std::string::size_type next = program.find_first_of("\r\n", pos);
+ if (next == std::string::npos) next = program.size();
                 copied = pos + (std::min)(indent, next-pos);
             }
         }

Modified: trunk/tools/quickbook/test/unit/source_map_test.cpp
==============================================================================
--- trunk/tools/quickbook/test/unit/source_map_test.cpp (original)
+++ trunk/tools/quickbook/test/unit/source_map_test.cpp 2013-05-07 19:25:47 EDT (Tue, 07 May 2013)
@@ -303,6 +303,44 @@
         BOOST_TEST_EQ(f1->source(),
             boost::string_ref("Code line1\n\nCode line2"));
     }
+}
+
+void indented_map_trailing_blanks_test()
+{
+ quickbook::mapped_file_builder builder;
+
+ {
+ boost::string_ref source("\n\n Code line1\n ");
+ quickbook::file_ptr fake_file = new quickbook::file(
+ "(fake file)", source, 105u);
+ builder.start(fake_file);
+ builder.unindent_and_add(fake_file->source());
+ quickbook::file_ptr f1 = builder.release();
+ BOOST_TEST_EQ(f1->source(),
+ boost::string_ref("Code line1\n"));
+ }
+
+ {
+ boost::string_ref source(" \n \n Code line1\n ");
+ quickbook::file_ptr fake_file = new quickbook::file(
+ "(fake file)", source, 105u);
+ builder.start(fake_file);
+ builder.unindent_and_add(fake_file->source());
+ quickbook::file_ptr f1 = builder.release();
+ BOOST_TEST_EQ(f1->source(),
+ boost::string_ref("Code line1\n "));
+ }
+
+ {
+ boost::string_ref source(" Code line1\n \n Code line2\n ");
+ quickbook::file_ptr fake_file = new quickbook::file(
+ "(fake file)", source, 105u);
+ builder.start(fake_file);
+ builder.unindent_and_add(fake_file->source());
+ quickbook::file_ptr f1 = builder.release();
+ BOOST_TEST_EQ(f1->source(),
+ boost::string_ref("Code line1\n\nCode line2\n"));
+ }
 
 }
 
@@ -351,6 +389,7 @@
     indented_map_tests();
     indented_map_tests2();
     indented_map_leading_blanks_test();
+ indented_map_trailing_blanks_test();
     indented_map_mixed_test();
     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