$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r76634 - in trunk/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2012-01-22 08:24:34
Author: danieljames
Date: 2012-01-22 08:24:31 EST (Sun, 22 Jan 2012)
New Revision: 76634
URL: http://svn.boost.org/trac/boost/changeset/76634
Log:
Quickbook: Fix id generation for headers containing id placeholders.
Text files modified: 
   trunk/tools/quickbook/src/actions.cpp            |     7 +++++--                                 
   trunk/tools/quickbook/src/id_manager.cpp         |    29 +++++++++++++++++++++++------           
   trunk/tools/quickbook/src/id_manager.hpp         |     2 ++                                      
   trunk/tools/quickbook/test/heading-1_1.gold      |     6 ++++++                                  
   trunk/tools/quickbook/test/heading-1_1.quickbook |     6 ++++++                                  
   trunk/tools/quickbook/test/heading-1_5.gold      |    13 +++++++++++--                           
   trunk/tools/quickbook/test/heading-1_5.quickbook |     6 ++++++                                  
   trunk/tools/quickbook/test/heading-1_6.gold      |    14 +++++++++++---                          
   trunk/tools/quickbook/test/heading-1_6.quickbook |     6 ++++++                                  
   9 files changed, 76 insertions(+), 13 deletions(-)
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp	(original)
+++ trunk/tools/quickbook/src/actions.cpp	2012-01-22 08:24:31 EST (Sun, 22 Jan 2012)
@@ -392,7 +392,9 @@
             // version and the generation version are less then 103u.
 
             std::string anchor = actions.ids.old_style_id(
-                detail::make_identifier(content.get_encoded()),
+                detail::make_identifier(
+                    actions.ids.replace_placeholders_with_unresolved_ids(
+                        content.get_encoded())),
                 id_category::generated_heading);
 
             write_bridgehead(actions, level,
@@ -405,7 +407,8 @@
                 detail::make_identifier(
                     actions.ids.compatibility_version() >= 106 ?
                         content.get_quickbook() :
-                        content.get_encoded()
+                        actions.ids.replace_placeholders_with_unresolved_ids(
+                            content.get_encoded())
                 ),
                 id_category::generated_heading);
 
Modified: trunk/tools/quickbook/src/id_manager.cpp
==============================================================================
--- trunk/tools/quickbook/src/id_manager.cpp	(original)
+++ trunk/tools/quickbook/src/id_manager.cpp	2012-01-22 08:24:31 EST (Sun, 22 Jan 2012)
@@ -30,6 +30,8 @@
 
     struct id_placeholder;
     struct id_data;
+    std::string replace_ids(id_state& state, std::string const& xml,
+            bool use_resolved_ids = true);
     std::string process_ids(id_state&, std::string const&);
 
     static const std::size_t max_size = 32;
@@ -46,6 +48,9 @@
         state_enum generation_state;
                                 // Placeholder's position in generation
                                 // process.
+        std::string unresolved_id;
+                                // The id that would be generated without any
+                                // duplicate handling.
         std::string id;         // The id so far.
         id_placeholder* parent; // Placeholder of the parent id.
                                 // Only when generation_state == child
@@ -69,6 +74,7 @@
                 id_placeholder* parent_ = 0)
           : index(index),
             generation_state(parent_ ? child : unresolved),
+            unresolved_id(parent_ ? parent_->unresolved_id + '.' + id : id),
             id(id),
             parent(parent_),
             category(category),
@@ -285,6 +291,12 @@
         return state->add_placeholder(id, category)->to_string();
     }
 
+    std::string id_manager::replace_placeholders_with_unresolved_ids(
+            std::string const& xml) const
+    {
+        return replace_ids(*state, xml, false);
+    }
+
     std::string id_manager::replace_placeholders(std::string const& xml) const
     {
         assert(!state->current_file);
@@ -868,7 +880,6 @@
     placeholder_index index_placeholders(id_state&, std::string const& xml);
     void resolve_id(id_placeholder&, allocated_ids&);
     void generate_id(id_placeholder&, allocated_ids&);
-    std::string replace_ids(id_state& state, std::string const& xml);
 
     std::string process_ids(id_state& state, std::string const& xml)
     {
@@ -1081,11 +1092,13 @@
     struct replace_ids_callback : xml_processor::callback
     {
         id_state& state;
+        bool use_resolved_ids;
         std::string::const_iterator source_pos;
         std::string result;
 
-        replace_ids_callback(id_state& state)
+        replace_ids_callback(id_state& state, bool resolved)
           : state(state),
+            use_resolved_ids(resolved),
             source_pos(),
             result()
         {}
@@ -1099,10 +1112,13 @@
         {
             if (id_placeholder* p = state.get_placeholder(value))
             {
-                assert(p->check_state(id_placeholder::generated));
+                assert(!use_resolved_ids ||
+                    p->check_state(id_placeholder::generated));
+                std::string const& id = use_resolved_ids ?
+                    p->id : p->unresolved_id;
 
                 result.append(source_pos, value.begin());
-                result.append(p->id.begin(), p->id.end());
+                result.append(id.begin(), id.end());
                 source_pos = value.end();
             }
         }
@@ -1114,10 +1130,11 @@
         }
     };
 
-    std::string replace_ids(id_state& state, std::string const& xml)
+    std::string replace_ids(id_state& state, std::string const& xml,
+            bool use_unresolved_ids)
     {
         xml_processor processor;
-        replace_ids_callback callback(state);
+        replace_ids_callback callback(state, use_unresolved_ids);
         processor.parse(xml, callback);
         return callback.result;
     }
Modified: trunk/tools/quickbook/src/id_manager.hpp
==============================================================================
--- trunk/tools/quickbook/src/id_manager.hpp	(original)
+++ trunk/tools/quickbook/src/id_manager.hpp	2012-01-22 08:24:31 EST (Sun, 22 Jan 2012)
@@ -73,6 +73,8 @@
         std::string add_id(std::string const&, id_category);
         std::string add_anchor(std::string const&, id_category);
 
+        std::string replace_placeholders_with_unresolved_ids(
+                std::string const&) const;
         std::string replace_placeholders(std::string const&) const;
         
         unsigned compatibility_version() const;
Modified: trunk/tools/quickbook/test/heading-1_1.gold
==============================================================================
--- trunk/tools/quickbook/test/heading-1_1.gold	(original)
+++ trunk/tools/quickbook/test/heading-1_1.gold	2012-01-22 08:24:31 EST (Sun, 22 Jan 2012)
@@ -37,6 +37,12 @@
   <bridgehead renderas="sect1" id="._also_not_an_id">
     :also not an id
   </bridgehead>
+  <bridgehead renderas="sect1" id="._anchor_id__anchor___anchor_heading">
+    <anchor id="anchor"/>Anchor heading
+  </bridgehead>
+  <bridgehead renderas="sect1" id="._link_linkend__anchor__link_heading__link_">
+    <link linkend="anchor">Link heading</link>
+  </bridgehead>
   <bridgehead renderas="sect1" id=".h1">
     H1
   </bridgehead>
Modified: trunk/tools/quickbook/test/heading-1_1.quickbook
==============================================================================
--- trunk/tools/quickbook/test/heading-1_1.quickbook	(original)
+++ trunk/tools/quickbook/test/heading-1_1.quickbook	2012-01-22 08:24:31 EST (Sun, 22 Jan 2012)
@@ -20,6 +20,12 @@
 [h1:notanid]
 [h1:also not an id]
 
+[/ Test how ids are generated for headings containing things like anchors
+   and links ]
+
+[h1 [#anchor]Anchor heading]
+[h1 [link anchor Link heading]]
+
 [/ Test how heading ids are generated inside sections]
 
 [h1 H1]
Modified: trunk/tools/quickbook/test/heading-1_5.gold
==============================================================================
--- trunk/tools/quickbook/test/heading-1_5.gold	(original)
+++ trunk/tools/quickbook/test/heading-1_5.gold	2012-01-22 08:24:31 EST (Sun, 22 Jan 2012)
@@ -45,7 +45,16 @@
     <phrase id="heading_test_1_5._also_not_an_id"/><link linkend="heading_test_1_5._also_not_an_id">:also
     not an id</link>
   </bridgehead>
-  <bridgehead renderas="sect2" id="heading_test_1_5.h13">
+  <bridgehead renderas="sect1" id="heading_test_1_5.h13">
+    <phrase id="heading_test_1_5._anchor_id__anchor___anchor_heading"/><link linkend="heading_test_1_5._anchor_id__anchor___anchor_heading"><anchor
+    id="anchor"/>Anchor heading</link>
+  </bridgehead>
+  <bridgehead renderas="sect1" id="heading_test_1_5.h14">
+    <phrase id="heading_test_1_5._link_linkend__anchor__link_heading__link_"/><link
+    linkend="heading_test_1_5._link_linkend__anchor__link_heading__link_"><link linkend="anchor">Link
+    heading</link></link>
+  </bridgehead>
+  <bridgehead renderas="sect2" id="heading_test_1_5.h15">
     <phrase id="heading_test_1_5.h1"/><link linkend="heading_test_1_5.h1">H1</link>
   </bridgehead>
   <section id="heading_test_1_5.s1">
@@ -72,7 +81,7 @@
       <phrase id="heading_test_1_5.s1.h6"/><link linkend="heading_test_1_5.s1.h6">H6</link>
     </bridgehead>
   </section>
-  <bridgehead renderas="sect1" id="heading_test_1_5.h14">
+  <bridgehead renderas="sect1" id="heading_test_1_5.h16">
     <phrase id="heading_test_1_5.h7"/><link linkend="heading_test_1_5.h7">H7</link>
   </bridgehead>
 </article>
Modified: trunk/tools/quickbook/test/heading-1_5.quickbook
==============================================================================
--- trunk/tools/quickbook/test/heading-1_5.quickbook	(original)
+++ trunk/tools/quickbook/test/heading-1_5.quickbook	2012-01-22 08:24:31 EST (Sun, 22 Jan 2012)
@@ -22,6 +22,12 @@
 [h1:notanid]
 [h1:also not an id]
 
+[/ Test how ids are generated for headings containing things like anchors
+   and links ]
+
+[h1 [#anchor]Anchor heading]
+[h1 [link anchor Link heading]]
+
 [/ Test how heading ids are generated inside sections]
 
 [heading H1]
Modified: trunk/tools/quickbook/test/heading-1_6.gold
==============================================================================
--- trunk/tools/quickbook/test/heading-1_6.gold	(original)
+++ trunk/tools/quickbook/test/heading-1_6.gold	2012-01-22 08:24:31 EST (Sun, 22 Jan 2012)
@@ -39,6 +39,14 @@
     <phrase id="heading_test_1_6.comment"/><link linkend="heading_test_1_6.comment">Comment</link>
   </bridgehead>
   <bridgehead renderas="sect1" id="heading_test_1_6.h11">
+    <phrase id="heading_test_1_6.anchor_anchor_heading"/><link linkend="heading_test_1_6.anchor_anchor_heading"><anchor
+    id="anchor"/>Anchor heading</link>
+  </bridgehead>
+  <bridgehead renderas="sect1" id="heading_test_1_6.h12">
+    <phrase id="heading_test_1_6.link_anchor_link_heading"/><link linkend="heading_test_1_6.link_anchor_link_heading"><link
+    linkend="anchor">Link heading</link></link>
+  </bridgehead>
+  <bridgehead renderas="sect1" id="heading_test_1_6.h13">
     <phrase id="heading_test_1_6.h1"/><link linkend="heading_test_1_6.h1">H1</link>
   </bridgehead>
   <section id="heading_test_1_6.s1">
@@ -65,10 +73,10 @@
       <phrase id="heading_test_1_6.s1.h6"/><link linkend="heading_test_1_6.s1.h6">H6</link>
     </bridgehead>
   </section>
-  <bridgehead renderas="sect1" id="heading_test_1_6.h12">
+  <bridgehead renderas="sect1" id="heading_test_1_6.h14">
     <phrase id="heading_test_1_6.h7"/><link linkend="heading_test_1_6.h7">H7</link>
   </bridgehead>
-  <bridgehead renderas="sect1" id="heading_test_1_6.h13">
+  <bridgehead renderas="sect1" id="heading_test_1_6.h15">
     <phrase id="heading_test_1_6.a1"/><link linkend="heading_test_1_6.a1">H1</link>
   </bridgehead>
   <section id="heading_test_1_6.s1_0">
@@ -95,7 +103,7 @@
       <phrase id="heading_test_1_6.s1_0.a6"/><link linkend="heading_test_1_6.s1_0.a6">H6</link>
     </bridgehead>
   </section>
-  <bridgehead renderas="sect1" id="heading_test_1_6.h14">
+  <bridgehead renderas="sect1" id="heading_test_1_6.h16">
     <phrase id="heading_test_1_6.a7"/><link linkend="heading_test_1_6.a7">H7</link>
   </bridgehead>
 </article>
Modified: trunk/tools/quickbook/test/heading-1_6.quickbook
==============================================================================
--- trunk/tools/quickbook/test/heading-1_6.quickbook	(original)
+++ trunk/tools/quickbook/test/heading-1_6.quickbook	2012-01-22 08:24:31 EST (Sun, 22 Jan 2012)
@@ -17,6 +17,12 @@
 [h1 *Bold*]
 [h1 [/]Comment[/]]
 
+[/ Test how ids are generated for headings containing things like anchors
+   and links ]
+
+[h1 [#anchor]Anchor heading]
+[h1 [link anchor Link heading]]
+
 [/ Test how heading ids are generated inside sections]
 
 [h1 H1]