]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/tools/quickbook/src/actions.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / tools / quickbook / src / actions.cpp
index 15bc7bccd375a9ff8c34035558dfccbaa6365717..408f2a1b19cdef43179b1e3e100beb17378f18e0 100644 (file)
 #include "state.hpp"
 #include "state_save.hpp"
 #include "grammar.hpp"
-#include "native_text.hpp"
+#include "stream.hpp"
 #include "block_tags.hpp"
 #include "phrase_tags.hpp"
 #include "document_state.hpp"
-#include "include_paths.hpp"
+#include "path.hpp"
 
 namespace quickbook
 {
     namespace {
         void write_anchors(quickbook::state& state, collector& tgt)
         {
-            // TODO: This works but is a bit of an odd place to put it.
-            // Might need to redefine the purpose of this function.
             if (state.source_mode_next) {
                 detail::outwarn(state.source_mode_next_pos.get_file(),
                     state.source_mode_next_pos.get_position())
@@ -65,7 +63,7 @@ namespace quickbook
         }
         
         std::string add_anchor(quickbook::state& state,
-                boost::string_ref id,
+                quickbook::string_view id,
                 id_category::categories category =
                     id_category::explicit_anchor_id)
         {
@@ -78,7 +76,7 @@ namespace quickbook
                 quickbook::value const& value)
         {
             std::string x = value.is_encoded() ?
-                value.get_encoded() : detail::to_s(value.get_quickbook());
+                value.get_encoded() : value.get_quickbook().to_s();
 
             if (x.empty()) {
                 detail::outerr(value.get_file(), value.get_position())
@@ -114,7 +112,7 @@ namespace quickbook
                 detail::outerr(id_value.get_file(), id_value.get_position())
                     << "Invalid id: "
                     << (id_value.is_encoded() ? id_value.get_encoded() :
-                        detail::to_s(id_value.get_quickbook()))
+                        id_value.get_quickbook().to_s())
                     << std::endl;
                 ++state.error_count;
             }
@@ -127,7 +125,11 @@ namespace quickbook
         return qbk_version_n >= lower && qbk_version_n < upper;
     }
 
-    void explicit_list_action(quickbook::state&, value);
+    bool quickbook_strict::is_strict_checking() const {
+        return state.strict_mode;
+    }
+
+    void list_action(quickbook::state&, value);
     void header_action(quickbook::state&, value);
     void begin_section_action(quickbook::state&, value);
     void end_section_action(quickbook::state&, value, string_iterator);
@@ -162,7 +164,7 @@ namespace quickbook
         {
         case block_tags::ordered_list:
         case block_tags::itemized_list:
-            return explicit_list_action(state, v);
+            return list_action(state, v);
         case block_tags::generic_heading:
         case block_tags::heading1:
         case block_tags::heading2:
@@ -536,10 +538,12 @@ namespace quickbook
 
         if (saved_conditional)
         {
-            boost::string_ref macro1 = values.consume().get_quickbook();
+            bool positive = values.consume().get_quickbook().empty();
+            quickbook::string_view macro1 = values.consume().get_quickbook();
             std::string macro(macro1.begin(), macro1.end());
 
-            state.conditional = find(state.macro, macro.c_str());
+            state.conditional =
+                (bool)find(state.macro, macro.c_str()) == positive;
 
             if (!state.conditional) {
                 state.push_output();
@@ -681,7 +685,7 @@ namespace quickbook
         return block;
     }
 
-    void explicit_list_action(quickbook::state& state, value list)
+    void list_action(quickbook::state& state, value list)
     {
         write_anchors(state, state.out);
 
@@ -760,7 +764,7 @@ namespace quickbook
         int code_tag = code_block.get_tag();
 
         value_consumer values = code_block;
-        boost::string_ref code_value = values.consume().get_quickbook();
+        quickbook::string_view code_value = values.consume().get_quickbook();
         values.finish();
 
         bool inline_code = code_tag == code_tags::inline_code ||
@@ -855,7 +859,8 @@ namespace quickbook
         
         if(hex_digits.size() == 2 && *first > '0' && *first <= '7') {
             using namespace std;
-            detail::print_char(strtol(hex_digits.c_str(), 0, 16),
+            detail::print_char(
+                    (char) strtol(hex_digits.c_str(), 0, 16),
                     state.phrase.get());
         }
         else {
@@ -870,8 +875,8 @@ namespace quickbook
             detail::print_string(v.get_encoded(), out);
         }
         else {
-            boost::string_ref value = v.get_quickbook();
-            for(boost::string_ref::const_iterator
+            quickbook::string_view value = v.get_quickbook();
+            for(string_iterator
                 first = value.begin(), last  = value.end();
                 first != last; ++first)
             {
@@ -919,7 +924,7 @@ namespace quickbook
         
         std::string fileref = attributes["fileref"].is_encoded() ?
             attributes["fileref"].get_encoded() :
-            detail::to_s(attributes["fileref"].get_quickbook());
+            attributes["fileref"].get_quickbook().to_s();
 
         // Check for windows paths, then convert.
         // A bit crude, but there you go.
@@ -1022,7 +1027,8 @@ namespace quickbook
            {
               attributes.insert(std::make_pair(
                 "contentwidth", encoded_value(std::string(
-                    svg_text.begin() + a + 1, svg_text.begin() + b))
+                    boost::next(svg_text.begin(), a + 1),
+                    boost::next(svg_text.begin(), b)))
                 ));
            }
            a = svg_text.find("height");
@@ -1033,7 +1039,8 @@ namespace quickbook
            {
               attributes.insert(std::make_pair(
                 "contentdepth", encoded_value(std::string(
-                    svg_text.begin() + a + 1, svg_text.begin() + b))
+                    boost::next(svg_text.begin(), a + 1),
+                    boost::next(svg_text.begin(), b)))
                 ));
            }
         }
@@ -1065,7 +1072,7 @@ namespace quickbook
     void macro_definition_action(quickbook::state& state, quickbook::value macro_definition)
     {
         value_consumer values = macro_definition;
-        std::string macro_id = detail::to_s(values.consume().get_quickbook());
+        std::string macro_id = values.consume().get_quickbook().to_s();
         value phrase_value = values.optional_consume();
         std::string phrase;
         if (phrase_value.check()) phrase = phrase_value.get_encoded();
@@ -1094,11 +1101,11 @@ namespace quickbook
     void template_body_action(quickbook::state& state, quickbook::value template_definition)
     {
         value_consumer values = template_definition;
-        std::string identifier = detail::to_s(values.consume().get_quickbook());
+        std::string identifier = values.consume().get_quickbook().to_s();
 
         std::vector<std::string> template_values;
         BOOST_FOREACH(value const& p, values.consume()) {
-            template_values.push_back(detail::to_s(p.get_quickbook()));
+            template_values.push_back(p.get_quickbook().to_s());
         }
 
         BOOST_ASSERT(values.check(template_tags::block) || values.check(template_tags::phrase));
@@ -1191,7 +1198,7 @@ namespace quickbook
         void break_arguments(
             std::vector<value>& args
           , std::vector<std::string> const& params
-          , fs::path const& filename
+          , fs::path const& /* filename */
         )
         {
             // Quickbook 1.4-: If there aren't enough parameters seperated by
@@ -1201,7 +1208,7 @@ namespace quickbook
             //                 then use whitespace to separate them
             //                 (2 = template name + argument).
 
-            if (qbk_version_n < 105 || args.size() == 1)
+            if (qbk_version_n < 105 ? args.size() : args.size() == 1)
             {
            
                 while (args.size() < params.size())
@@ -1267,7 +1274,7 @@ namespace quickbook
             file_ptr saved_current_file = state.current_file;
 
             state.current_file = content.get_file();
-            boost::string_ref source = content.get_quickbook();
+            quickbook::string_view source = content.get_quickbook();
 
             parse_iterator first(source.begin());
             parse_iterator last(source.end());
@@ -1434,7 +1441,7 @@ namespace quickbook
         bool template_escape = values.check(template_tags::escape);
         if(template_escape) values.consume();
 
-        std::string identifier = detail::to_s(values.consume(template_tags::identifier).get_quickbook());
+        std::string identifier = values.consume(template_tags::identifier).get_quickbook().to_s();
 
         std::vector<value> args;
 
@@ -1570,7 +1577,6 @@ namespace quickbook
         else {
             dst = get_attribute_value(state, dst_value);
 
-            // TODO: Might be better to have an error for some invalid urls.
             if (link.get_tag() == phrase_tags::url) {
                 dst = detail::partially_escape_uri(dst);
             }
@@ -1593,7 +1599,7 @@ namespace quickbook
         write_anchors(state, state.out);
 
         value_consumer values = variable_list;
-        std::string title = detail::to_s(values.consume(table_tags::title).get_quickbook());
+        std::string title = values.consume(table_tags::title).get_quickbook().to_s();
 
         state.out << "<variablelist>\n";
 
@@ -1732,6 +1738,7 @@ namespace quickbook
         values.finish();
 
         std::string full_id = state.document.begin_section(
+            element_id,
             element_id.empty() ?
                 detail::make_identifier(content.get_quickbook()) :
                 validate_id(state, element_id),
@@ -1741,27 +1748,33 @@ namespace quickbook
             state.current_source_mode());
 
         state.out << "\n<section id=\"" << full_id << "\">\n";
-        state.out << "<title>";
 
-        write_anchors(state, state.out);
+        std::string title = content.get_encoded();
 
-        if (self_linked_headers && state.document.compatibility_version() >= 103)
-        {
-            state.out << "<link linkend=\"" << full_id << "\">"
-                << content.get_encoded()
-                << "</link>"
-                ;
-        }
-        else
-        {
-            state.out << content.get_encoded();
+        if (!title.empty()) {
+            state.out << "<title>";
+
+            write_anchors(state, state.out);
+
+            if (self_linked_headers && state.document.compatibility_version() >= 103)
+            {
+                state.out << quickbook::detail::linkify(title, full_id);
+            }
+            else
+            {
+                state.out << title;
+            }
+
+            state.out << "</title>\n";
         }
-        
-        state.out << "</title>\n";
     }
 
-    void end_section_action(quickbook::state& state, value end_section, string_iterator first)
+    void end_section_action(quickbook::state& state, value end_section_list, string_iterator first)
     {
+        value_consumer values = end_section_list;
+        value element_id = values.optional_consume(general_tags::element_id);
+        values.finish();
+
         write_anchors(state, state.out);
 
         if (state.document.section_level() <= state.min_section_level)
@@ -1775,6 +1788,29 @@ namespace quickbook
             return;
         }
 
+        if (!element_id.empty() && !(element_id == state.document.explicit_id()))
+        {
+            file_position const pos = state.current_file->position_of(first);
+            value section_element_id = state.document.explicit_id();
+
+            if (section_element_id.empty()) {
+                detail::outerr(state.current_file->path, pos.line)
+                    << "Endsect has unexpected id '"
+                    << element_id.get_quickbook()
+                    << "' in section with no explicit id, near column "
+                    << pos.column << ".\n";
+            } else {
+                detail::outerr(state.current_file->path, pos.line)
+                    << "Endsect has incorrect id '"
+                    << element_id.get_quickbook()
+                    << "', expected '"
+                    << state.document.explicit_id().get_quickbook()
+                    << "', near column "
+                    << pos.column << ".\n";
+            }
+            ++state.error_count;
+        }
+
         state.out << "</section>";
         state.document.end_section();
     }
@@ -1794,7 +1830,7 @@ namespace quickbook
 
         if (x.type == path_parameter::path)
         {
-            quickbook_path path = resolve_xinclude_path(x.value, state);
+            quickbook_path path = resolve_xinclude_path(x.value, state, true);
 
             state.out << "\n<xi:include href=\"";
             detail::print_string(file_path_to_url(path.abstract_file_path), state.out.get());
@@ -1848,7 +1884,7 @@ namespace quickbook
             quickbook_path const& path,
             value::tag_type load_type,
             string_iterator first,
-            value const& include_doc_id = value())
+            value const& /* include_doc_id */ = value())
     {
         assert(load_type == block_tags::include ||
             load_type == block_tags::import);
@@ -1907,11 +1943,8 @@ namespace quickbook
 
         std::set<quickbook_path> search =
             include_search(parameter, state, first);
-        std::set<quickbook_path>::iterator i = search.begin();
-        std::set<quickbook_path>::iterator e = search.end();
-        for (; i != e; ++i)
+        BOOST_FOREACH(quickbook_path const& path, search)
         {
-            quickbook_path const & path = *i;
             try {
                 if (qbk_version_n >= 106)
                 {