Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82901 - in trunk: boost/utility libs/utility/test
From: marshall_at_[hidden]
Date: 2013-02-15 11:07:07


Author: marshall
Date: 2013-02-15 11:07:06 EST (Fri, 15 Feb 2013)
New Revision: 82901
URL: http://svn.boost.org/trac/boost/changeset/82901

Log:
Fixed bug in string_ref::find; Refs #8067
Text files modified:
   trunk/boost/utility/string_ref.hpp | 6 +-
   trunk/libs/utility/test/string_ref_test2.cpp | 88 ++++++++++++++++++++++++++++++++++-----
   2 files changed, 78 insertions(+), 16 deletions(-)

Modified: trunk/boost/utility/string_ref.hpp
==============================================================================
--- trunk/boost/utility/string_ref.hpp (original)
+++ trunk/boost/utility/string_ref.hpp 2013-02-15 11:07:06 EST (Fri, 15 Feb 2013)
@@ -155,7 +155,7 @@
             }
         
         int compare(basic_string_ref x) const {
- int cmp = traits::compare ( ptr_, x.ptr_, (std::min)(len_, x.len_));
+ const int cmp = traits::compare ( ptr_, x.ptr_, (std::min)(len_, x.len_));
             return cmp != 0 ? cmp : ( len_ == x.len_ ? 0 : len_ < x.len_ ? -1 : 1 );
             }
         
@@ -172,7 +172,7 @@
         size_type find(basic_string_ref s) const {
             const_iterator iter = std::search ( this->cbegin (), this->cend (),
                                                 s.cbegin (), s.cend (), traits::eq );
- return iter = this->cend () ? npos : std::distance ( this->cbegin (), iter );
+ return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
             }
         
         size_type find(charT c) const {
@@ -198,7 +198,7 @@
         
         size_type find_first_of(basic_string_ref s) const {
             const_iterator iter = std::find_first_of
- ( this->cbegin (), this->cend (), s.cbegin (), s.cend (), traits::eq );
+ ( this->cbegin (), this->cend (), s.cbegin (), s.cend (), traits::eq );
             return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
             }
         

Modified: trunk/libs/utility/test/string_ref_test2.cpp
==============================================================================
--- trunk/libs/utility/test/string_ref_test2.cpp (original)
+++ trunk/libs/utility/test/string_ref_test2.cpp 2013-02-15 11:07:06 EST (Fri, 15 Feb 2013)
@@ -95,23 +95,33 @@
     const char *p;
 
 // Look for each character in the string(searching from the start)
- p = arg;
- sr1 = arg;
- while ( *p ) {
- string_ref::size_type pos = sr1.find(*p);
- BOOST_CHECK ( pos != string_ref::npos && ( pos <= ptr_diff ( p, arg )));
- ++p;
- }
+ p = arg;
+ sr1 = arg;
+ while ( *p ) {
+ string_ref::size_type pos = sr1.find(*p);
+ BOOST_CHECK ( pos != string_ref::npos && ( pos <= ptr_diff ( p, arg )));
+ ++p;
+ }
   
 // Look for each character in the string (searching from the end)
     p = arg;
     sr1 = arg;
     while ( *p ) {
- string_ref::size_type pos = sr1.rfind(*p);
- BOOST_CHECK ( pos != string_ref::npos && pos < sr1.size () && ( pos >= ptr_diff ( p, arg )));
- ++p;
- }
-
+ string_ref::size_type pos = sr1.rfind(*p);
+ BOOST_CHECK ( pos != string_ref::npos && pos < sr1.size () && ( pos >= ptr_diff ( p, arg )));
+ ++p;
+ }
+
+// Look for pairs on characters (searching from the start)
+ sr1 = arg;
+ p = arg;
+ while ( *p && *(p+1)) {
+ string_ref sr3 ( p, 2 );
+ string_ref::size_type pos = sr1.find ( sr3 );
+ BOOST_CHECK ( pos != string_ref::npos && pos <= ( p - arg ));
+ p++;
+ }
+
     sr1 = arg;
     p = arg;
 // for all possible chars, see if we find them in the right place.
@@ -231,6 +241,56 @@
 
     }
 
+#if 0
+void to_string ( const char *arg ) {
+ string_ref sr1;
+ std::string str1;
+ std::string str2;
+
+ str1.assign ( arg );
+ sr1 = arg;
+// str2 = sr1.to_string<std::allocator<char> > ();
+ str2 = sr1.to_string ();
+ BOOST_CHECK ( str1 == str2 );
+
+#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
+ std::string str3 = static_cast<std::string> ( sr1 );
+ BOOST_CHECK ( str1 == str3 );
+#endif
+ }
+
+void compare ( const char *arg ) {
+ string_ref sr1;
+ std::string str1;
+ std::string str2 = str1;
+
+ str1.assign ( arg );
+ sr1 = arg;
+ BOOST_CHECK ( sr1 == str1); // compare string and string_ref
+ BOOST_CHECK ( str1 == sr1 ); // compare string_ref and string
+ BOOST_CHECK ( sr1 == arg ); // compare string_ref and pointer
+ BOOST_CHECK ( arg == sr1 ); // compare pointer and string_ref
+
+ if ( sr1.size () > 0 ) {
+ (*str1.rbegin())++;
+ BOOST_CHECK ( sr1 != str1 );
+ BOOST_CHECK ( str1 != sr1 );
+ BOOST_CHECK ( sr1 < str1 );
+ BOOST_CHECK ( sr1 <= str1 );
+ BOOST_CHECK ( str1 > sr1 );
+ BOOST_CHECK ( str1 >= sr1 );
+
+ (*str1.rbegin()) -= 2;
+ BOOST_CHECK ( sr1 != str1 );
+ BOOST_CHECK ( str1 != sr1 );
+ BOOST_CHECK ( sr1 > str1 );
+ BOOST_CHECK ( sr1 >= str1 );
+ BOOST_CHECK ( str1 < sr1 );
+ BOOST_CHECK ( str1 <= sr1 );
+ }
+ }
+#endif
+
 const char *test_strings [] = {
     "",
     "0",
@@ -250,7 +310,9 @@
         ends_with ( *p );
         reverse ( *p );
         find ( *p );
-
+// to_string ( *p );
+// compare ( *p );
+
         p++;
         }
 }


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