Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57730 - in trunk: boost/spirit/home/qi/string libs/spirit/test/qi
From: daniel_james_at_[hidden]
Date: 2009-11-17 15:26:15


Author: danieljames
Date: 2009-11-17 15:26:15 EST (Tue, 17 Nov 2009)
New Revision: 57730
URL: http://svn.boost.org/trac/boost/changeset/57730

Log:
Implement prefix_find.
Text files modified:
   trunk/boost/spirit/home/qi/string/symbols.hpp | 12 ++++++++++++
   trunk/libs/spirit/test/qi/symbols.cpp | 32 +++++++++++++++++++++++++++++---
   2 files changed, 41 insertions(+), 3 deletions(-)

Modified: trunk/boost/spirit/home/qi/string/symbols.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/string/symbols.hpp (original)
+++ trunk/boost/spirit/home/qi/string/symbols.hpp 2009-11-17 15:26:15 EST (Tue, 17 Nov 2009)
@@ -187,6 +187,18 @@
                 , traits::get_end<Char>(str), T());
         }
 
+ template <typename Iterator>
+ value_type* prefix_find(Iterator& first, Iterator const& last)
+ {
+ return lookup->find(first, last, Filter());
+ }
+
+ template <typename Iterator>
+ value_type const* prefix_find(Iterator& first, Iterator const& last) const
+ {
+ return lookup->find(first, last, Filter());
+ }
+
         template <typename Str>
         value_type* find(Str const& str)
         {

Modified: trunk/libs/spirit/test/qi/symbols.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/symbols.cpp (original)
+++ trunk/libs/spirit/test/qi/symbols.cpp 2009-11-17 15:26:15 EST (Tue, 17 Nov 2009)
@@ -304,10 +304,18 @@
         BOOST_TEST(const_sym.find("a") && *const_sym.find("a") == 1);
         BOOST_TEST(const_sym.find("b") && *const_sym.find("b") == 2);
         BOOST_TEST(const_sym.find("c") && *const_sym.find("c") == 0);
- BOOST_TEST(!const_sym.find("d"));
+ BOOST_TEST(!const_sym.find("d"));
+
+ char const *str1 = "all";
+ char const *first = str1, *last = str1 + 3;
+ BOOST_TEST(*sym.prefix_find(first, last) == 1 && first == str1 + 1);
+
+ char const *str2 = "dart";
+ first = str2; last = str2 + 4;
+ BOOST_TEST(!sym.prefix_find(first, last) && first == str2);
     }
     
- { // Don't find substring
+ { // Substrings
     
         symbols<char, int> sym;
         BOOST_TEST(sym.at("foo") == 0);
@@ -316,8 +324,26 @@
         BOOST_TEST(sym.at("fool") == 0);
         sym.at("fool") = 2;
         BOOST_TEST(sym.find("foo") && *sym.find("foo") == 1);
- BOOST_TEST(sym.find("fool") && *sym.find("foo") == 2);
+ BOOST_TEST(sym.find("fool") && *sym.find("fool") == 2);
         BOOST_TEST(!sym.find("foolish"));
+ BOOST_TEST(!sym.find("foot"));
+ BOOST_TEST(!sym.find("afoot"));
+
+ char const *str, *first, *last;
+ str = "foolish"; first = str; last = str + 7;
+ BOOST_TEST(*sym.prefix_find(first, last) == 2 && first == str + 4);
+
+ first = str; last = str + 4;
+ BOOST_TEST(*sym.prefix_find(first, last) == 2 && first == str + 4);
+
+ str = "food"; first = str; last = str + 4;
+ BOOST_TEST(*sym.prefix_find(first, last) == 1 && first == str + 3);
+
+ first = str; last = str + 3;
+ BOOST_TEST(*sym.prefix_find(first, last) == 1 && first == str + 3);
+
+ first = str; last = str + 2;
+ BOOST_TEST(!sym.prefix_find(first, last) && first == str);
     }
 
     return boost::report_errors();


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