Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83121 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2013-02-24 06:22:45


Author: danieljames
Date: 2013-02-24 06:22:45 EST (Sun, 24 Feb 2013)
New Revision: 83121
URL: http://svn.boost.org/trac/boost/changeset/83121

Log:
Extract duplicated find_section code.
Text files modified:
   trunk/tools/quickbook/src/files.cpp | 30 +++++++++++++++++-------------
   1 files changed, 17 insertions(+), 13 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:22:45 EST (Sun, 24 Feb 2013)
@@ -310,6 +310,19 @@
                     return section->original_pos;
             }
         }
+
+ std::vector<mapped_file_section>::const_iterator find_section(
+ boost::string_ref::const_iterator pos) const
+ {
+ std::vector<mapped_file_section>::const_iterator section =
+ boost::upper_bound(mapped_sections,
+ std::string::size_type(pos - source().begin()),
+ mapped_section_pos_cmp());
+ assert(section != mapped_sections.begin());
+ --section;
+
+ return section;
+ }
 
         virtual file_position position_of(boost::string_ref::const_iterator) const;
     };
@@ -387,11 +400,9 @@
 
         if (begin != end)
         {
- std::vector<mapped_file_section>::iterator start =
- boost::upper_bound(x.data->new_file->mapped_sections,
- begin, mapped_section_pos_cmp());
- assert(start != x.data->new_file->mapped_sections.begin());
- --start;
+ std::vector<mapped_file_section>::const_iterator start =
+ x.data->new_file->find_section(
+ x.data->new_file->source().begin() + begin);
     
             std::string::size_type size = data->new_file->source_.size();
     
@@ -479,14 +490,7 @@
 
     file_position mapped_file::position_of(boost::string_ref::const_iterator pos) const
     {
- std::vector<mapped_file_section>::const_iterator section =
- boost::upper_bound(mapped_sections,
- std::string::size_type(pos - source().begin()),
- mapped_section_pos_cmp());
- assert(section != mapped_sections.begin());
- --section;
-
         return original->position_of(original->source().begin() +
- to_original_pos(section, pos - source().begin()));
+ to_original_pos(find_section(pos), pos - source().begin()));
     }
 }


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