Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84188 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2013-05-07 19:26:08


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

Log:
Cleaner unindentation code.
Text files modified:
   trunk/tools/quickbook/src/files.cpp | 59 ++++++++++++++-------------------------
   1 files changed, 22 insertions(+), 37 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:26:07 EDT (Tue, 07 May 2013)
@@ -551,23 +551,24 @@
             }
         }
 
+ // Trim white spaces from column 0..indent
         std::string unindented_program;
- std::string::size_type copied = start;
+ std::string::size_type copy_start = start;
+ pos = start;
 
- if (mixed_indentation)
- {
- pos = start;
+ do {
+ if (std::string::npos == (pos = program.find_first_not_of("\r\n", pos)))
+ break;
 
- do {
- if (std::string::npos == (pos = program.find_first_not_of("\r\n", pos)))
- break;
+ unindented_program.append(program.begin() + copy_start, program.begin() + pos);
+ copy_start = pos;
 
- unindented_program.append(program.begin() + copied, program.begin() + pos);
- copied = pos;
-
- std::string::size_type next = program.find_first_not_of(" \t", pos);
- if (next == std::string::npos) next = program.size();
+ // Find the end of the indentation.
+ std::string::size_type next = program.find_first_not_of(" \t", pos);
+ if (next == std::string::npos) next = program.size();
 
+ if (mixed_indentation)
+ {
                 unsigned length = indentation_count(boost::string_ref(
                     &program[pos], next - pos));
 
@@ -576,34 +577,18 @@
                     unindented_program.append(new_indentation);
                 }
 
- copied = next;
- } while (std::string::npos !=
- (pos = program.find_first_of("\r\n", pos)));
- }
- else
- {
- // Trim white spaces from column 0..indent
- pos = start + indent;
- copied = pos;
-
- while (std::string::npos != (pos = program.find_first_of("\r\n", pos)))
+ copy_start = next;
+ }
+ else
             {
- if (std::string::npos == (pos = program.find_first_not_of("\r\n", pos)))
- {
- break;
- }
-
- unindented_program.append(program.begin() + copied, program.begin() + pos);
- 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);
+ copy_start = (std::min)(pos + indent, next);
             }
- }
 
- unindented_program.append(program.begin() + copied, program.end());
- copied = program.size();
+ pos = next;
+ } while (std::string::npos !=
+ (pos = program.find_first_of("\r\n", pos)));
+
+ unindented_program.append(program.begin() + copy_start, program.end());
 
         data->new_file->add_indented_mapped_file_section(x.begin());
         data->new_file->source_.append(unindented_program);


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