Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86706 - in trunk/tools/quickbook: src test/include
From: dnljms_at_[hidden]
Date: 2013-11-14 14:24:01


Author: danieljames
Date: 2013-11-14 14:24:01 EST (Thu, 14 Nov 2013)
New Revision: 86706
URL: http://svn.boost.org/trac/boost/changeset/86706

Log:
Handle non-globs containing escaped characters.

Text files modified:
   trunk/tools/quickbook/src/glob.cpp | 39 +++++++++++++++++++++++++++++++++++++++
   trunk/tools/quickbook/src/glob.hpp | 4 ++++
   trunk/tools/quickbook/src/include_paths.cpp | 20 ++++++++++----------
   trunk/tools/quickbook/test/include/filename-1_7.gold | 28 ++++++++++++++++++++++++++++
   trunk/tools/quickbook/test/include/filename-1_7.quickbook | 12 ++++++++++++
   5 files changed, 93 insertions(+), 10 deletions(-)

Modified: trunk/tools/quickbook/src/glob.cpp
==============================================================================
--- trunk/tools/quickbook/src/glob.cpp Thu Nov 14 14:23:26 2013 (r86705)
+++ trunk/tools/quickbook/src/glob.cpp 2013-11-14 14:24:01 EST (Thu, 14 Nov 2013) (r86706)
@@ -251,4 +251,43 @@
 
         return invert_match != matched;
     }
+
+ std::size_t find_glob_char(boost::string_ref pattern,
+ std::size_t pos)
+ {
+ // Weird style is because boost::string_ref's find_first_of
+ // doesn't take a position argument.
+ std::size_t removed = 0;
+
+ while (true) {
+ pos = pattern.find_first_of("[]?*\\");
+ if (pos == boost::string_ref::npos) return pos;
+ if (pattern[pos] != '\\') return pos + removed;
+ pattern.remove_prefix(pos + 2);
+ removed += pos + 2;
+ }
+ }
+
+ std::string glob_unescape(boost::string_ref pattern)
+ {
+ std::string result;
+
+ while (true) {
+ std::size_t pos = pattern.find("\\");
+ if (pos == boost::string_ref::npos) {
+ result.append(pattern.data(), pattern.size());
+ break;
+ }
+
+ result.append(pattern.data(), pos);
+ ++pos;
+ if (pos < pattern.size()) {
+ result += pattern[pos];
+ ++pos;
+ }
+ pattern.remove_prefix(pos);
+ }
+
+ return result;
+ }
 }

Modified: trunk/tools/quickbook/src/glob.hpp
==============================================================================
--- trunk/tools/quickbook/src/glob.hpp Thu Nov 14 14:23:26 2013 (r86705)
+++ trunk/tools/quickbook/src/glob.hpp 2013-11-14 14:24:01 EST (Thu, 14 Nov 2013) (r86706)
@@ -23,4 +23,8 @@
     // pre: glob is valid (call check_glob first on user data).
     bool glob(boost::string_ref const& pattern,
             boost::string_ref const& filename);
+
+ std::size_t find_glob_char(boost::string_ref,
+ std::size_t start = 0);
+ std::string glob_unescape(boost::string_ref);
 }

Modified: trunk/tools/quickbook/src/include_paths.cpp
==============================================================================
--- trunk/tools/quickbook/src/include_paths.cpp Thu Nov 14 14:23:26 2013 (r86705)
+++ trunk/tools/quickbook/src/include_paths.cpp 2013-11-14 14:24:01 EST (Thu, 14 Nov 2013) (r86706)
@@ -32,10 +32,13 @@
             std::string path_text = path.get_encoded();
 
             try {
- bool is_glob = check_glob(path_text);
-
- return path_parameter(path_text,
- is_glob ? path_parameter::glob : path_parameter::path);
+ if (check_glob(path_text)) {
+ return path_parameter(path_text, path_parameter::glob);
+ }
+ else {
+ return path_parameter(glob_unescape(path_text),
+ path_parameter::path);
+ }
             } catch(glob_error& e) {
                 detail::outerr(path.get_file(), path.get_position())
                     << "Invalid path (" << e.what() << "): "
@@ -87,14 +90,11 @@
         quickbook_path const& location,
         std::string path, quickbook::state& state)
     {
- // Search for the first part of the path that contains glob
- // characters. (TODO: Account for escapes?)
-
- std::size_t glob_pos = path.find_first_of("[]?*");
+ std::size_t glob_pos = find_glob_char(path);
 
         if (glob_pos == std::string::npos)
         {
- quickbook_path complete_path = location / path;
+ quickbook_path complete_path = location / glob_unescape(path);
 
             if (fs::exists(complete_path.file_path))
             {
@@ -113,7 +113,7 @@
         quickbook_path new_location = location;
 
         if (prev != std::string::npos) {
- new_location /= path.substr(0, prev);
+ new_location /= glob_unescape(path.substr(0, prev));
         }
 
         if (next != std::string::npos) ++next;

Modified: trunk/tools/quickbook/test/include/filename-1_7.gold
==============================================================================
--- trunk/tools/quickbook/test/include/filename-1_7.gold Thu Nov 14 14:23:26 2013 (r86705)
+++ trunk/tools/quickbook/test/include/filename-1_7.gold 2013-11-14 14:24:01 EST (Thu, 14 Nov 2013) (r86706)
@@ -6,13 +6,41 @@
   <para>
     filename-1_7.quickbook
   </para>
+ <bridgehead renderas="sect2" id="filename_test.h0">
+ <phrase id="filename_test.test_1"/><link linkend="filename_test.test_1">Test
+ 1</link>
+ </bridgehead>
   <para>
     sub/filename_include1.quickbook
   </para>
   <para>
     sub/../filename_include2.quickbook
   </para>
+ <bridgehead renderas="sect2" id="filename_test.h1">
+ <phrase id="filename_test.test_2"/><link linkend="filename_test.test_2">Test
+ 2</link>
+ </bridgehead>
   <para>
     filename_include2.quickbook
   </para>
+ <bridgehead renderas="sect2" id="filename_test.h2">
+ <phrase id="filename_test.test_3"/><link linkend="filename_test.test_3">Test
+ 3</link>
+ </bridgehead>
+ <para>
+ sub/filename_include1.quickbook
+ </para>
+ <para>
+ sub/../filename_include2.quickbook
+ </para>
+ <bridgehead renderas="sect2" id="filename_test.h3">
+ <phrase id="filename_test.test_4"/><link linkend="filename_test.test_4">Test
+ 4</link>
+ </bridgehead>
+ <para>
+ sub/filename_include1.quickbook
+ </para>
+ <para>
+ sub/../filename_include2.quickbook
+ </para>
 </article>

Modified: trunk/tools/quickbook/test/include/filename-1_7.quickbook
==============================================================================
--- trunk/tools/quickbook/test/include/filename-1_7.quickbook Thu Nov 14 14:23:26 2013 (r86705)
+++ trunk/tools/quickbook/test/include/filename-1_7.quickbook 2013-11-14 14:24:01 EST (Thu, 14 Nov 2013) (r86706)
@@ -4,6 +4,18 @@
 
 __FILENAME__
 
+[heading Test 1]
+
 [include sub/*.quickbook]
 
+[heading Test 2]
+
 [include filename_include?.quickbook]
+
+[heading Test 3]
+
+[include su\[b\]/filename\\_include1.quickbook]
+
+[heading Test 4]
+
+[include su\\b/*.quickbook]


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