Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83118 - in trunk/tools/quickbook: src test/unit
From: dnljms_at_[hidden]
Date: 2013-02-24 06:22:04


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

Log:
Store indentation change in source map.

Used to infer it when required, which could go wrong.
Text files modified:
   trunk/tools/quickbook/src/files.cpp | 23 +++++++++++++++--------
   trunk/tools/quickbook/test/unit/source_map_test.cpp | 30 ++++++++++++++++++++++++++++--
   2 files changed, 43 insertions(+), 10 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:03 EST (Sun, 24 Feb 2013)
@@ -195,12 +195,15 @@
         std::string::size_type original_pos;
         std::string::size_type our_pos;
         section_types section_type;
+ int indentation;
 
         mapped_file_section(
                 std::string::size_type original_pos,
                 std::string::size_type our_pos,
- section_types section_type = normal) :
- original_pos(original_pos), our_pos(our_pos), section_type(section_type) {}
+ section_types section_type = normal,
+ int indentation = 0) :
+ original_pos(original_pos), our_pos(our_pos),
+ section_type(section_type), indentation(indentation) {}
 
         std::string::size_type to_original_pos(std::string::size_type pos)
         {
@@ -238,7 +241,9 @@
             case indented:
                 return file_position(
                     original.line + relative.line - 1,
- original.column + relative.column - 1);
+ relative.line == 1 ?
+ original.column + relative.column - 1 :
+ relative.column + indentation);
             default:
                 assert(false);
                 return file_position();
@@ -318,10 +323,12 @@
                 pos - original->source().begin(), source().size()));
         }
 
- void add_indented_mapped_file_section(boost::string_ref::const_iterator pos) {
+ void add_indented_mapped_file_section(boost::string_ref::const_iterator pos,
+ int indentation)
+ {
             mapped_sections.push_back(mapped_file_section(
                 pos - original->source().begin(), source().size(),
- mapped_file_section::indented));
+ mapped_file_section::indented, indentation));
         }
 
         virtual file_position position_of(boost::string_ref::const_iterator) const;
@@ -416,14 +423,14 @@
     
             data->new_file->mapped_sections.push_back(mapped_file_section(
                     start->to_original_pos(begin), size,
- start->section_type));
+ start->section_type, start->indentation));
     
             for (++start; start != x.data->new_file->mapped_sections.end() &&
                     start->our_pos < end; ++start)
             {
                 data->new_file->mapped_sections.push_back(mapped_file_section(
                     start->original_pos, start->our_pos - begin + size,
- start->section_type));
+ start->section_type, start->indentation));
             }
     
             data->new_file->source_.append(
@@ -492,7 +499,7 @@
             program.erase(pos, (std::min)(indent, next-pos));
         }
 
- data->new_file->add_indented_mapped_file_section(x.begin() + indent);
+ data->new_file->add_indented_mapped_file_section(x.begin() + indent, indent);
         data->new_file->source_.append(program);
     }
 

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:22:03 EST (Sun, 24 Feb 2013)
@@ -188,6 +188,32 @@
 
     {
         builder.start(fake_file);
+ {
+ quickbook::mapped_file_builder builder2;
+ builder2.start(fake_file);
+ builder2.unindent_and_add(fake_file->source());
+ builder.add(builder2);
+ }
+ quickbook::file_ptr f1 = builder.release();
+
+ BOOST_TEST_EQ(f1->source(),
+ boost::string_ref("Code line1\nCode line2\n"));
+ BOOST_TEST_EQ(f1->position_of(f1->source().begin()),
+ quickbook::file_position(1,4));
+ BOOST_TEST_EQ(f1->position_of(f1->source().begin() + 1),
+ quickbook::file_position(1,5));
+ BOOST_TEST_EQ(f1->position_of(f1->source().begin() + 5),
+ quickbook::file_position(1,9));
+ BOOST_TEST_EQ(f1->position_of(f1->source().begin() + 10),
+ quickbook::file_position(1,14));
+ BOOST_TEST_EQ(f1->position_of(f1->source().begin() + 11),
+ quickbook::file_position(2,4));
+ BOOST_TEST_EQ(f1->position_of(f1->source().end()),
+ quickbook::file_position(3,4));
+ }
+
+ {
+ builder.start(fake_file);
         builder.unindent_and_add(boost::string_ref(
             fake_file->source().begin() + 3,
             fake_file->source().end() - (fake_file->source().begin() + 3)));
@@ -203,9 +229,9 @@
         BOOST_TEST_EQ(f1->position_of(f1->source().begin() + 10),
             quickbook::file_position(1,14));
         BOOST_TEST_EQ(f1->position_of(f1->source().begin() + 11),
- quickbook::file_position(2,4));
+ quickbook::file_position(2,1));
         BOOST_TEST_EQ(f1->position_of(f1->source().end()),
- quickbook::file_position(3,4));
+ quickbook::file_position(3,1));
     }
 }
 


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