|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83123 - in trunk/tools/quickbook: src test/unit
From: dnljms_at_[hidden]
Date: 2013-02-24 06:23:16
Author: danieljames
Date: 2013-02-24 06:23:15 EST (Sun, 24 Feb 2013)
New Revision: 83123
URL: http://svn.boost.org/trac/boost/changeset/83123
Log:
Remove whitespace only leading lines from indented blocks.
Text files modified:
trunk/tools/quickbook/src/files.cpp | 14 +++++++-------
trunk/tools/quickbook/test/unit/source_map_test.cpp | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 7 deletions(-)
Modified: trunk/tools/quickbook/src/files.cpp
==============================================================================
--- trunk/tools/quickbook/src/files.cpp (original)
+++ trunk/tools/quickbook/src/files.cpp 2013-02-24 06:23:15 EST (Sun, 24 Feb 2013)
@@ -457,17 +457,17 @@
std::string program(x.begin(), x.end());
// Erase leading blank lines and newlines:
- std::string::size_type start = program.find_first_not_of(" \t");
- if (start != std::string::npos &&
- (program[start] == '\r' || program[start] == '\n'))
+ std::string::size_type start = program.find_first_not_of(" \t\r\n");
+ if (start == std::string::npos) return;
+
+ start = program.find_last_of("\r\n", start);
+ if (start != std::string::npos)
{
+ ++start;
program.erase(0, start);
}
- start = program.find_first_not_of("\r\n");
- program.erase(0, start);
- if (program.size() == 0)
- return; // nothing left to do
+ assert(program.size() != 0);
// Get the first line indent
std::string::size_type indent = program.find_first_not_of(" \t");
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-02-24 06:23:15 EST (Sun, 24 Feb 2013)
@@ -267,10 +267,50 @@
}
}
+void indented_map_leading_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");
+ 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"));
+ }
+
+}
+
int main()
{
simple_map_tests();
indented_map_tests();
indented_map_tests2();
+ indented_map_leading_blanks_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