mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
parent
05af0deaed
commit
e4d622019f
@ -155,7 +155,7 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int compare(basic_string_ref x) const {
|
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 );
|
return cmp != 0 ? cmp : ( len_ == x.len_ ? 0 : len_ < x.len_ ? -1 : 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ namespace boost {
|
|||||||
size_type find(basic_string_ref s) const {
|
size_type find(basic_string_ref s) const {
|
||||||
const_iterator iter = std::search ( this->cbegin (), this->cend (),
|
const_iterator iter = std::search ( this->cbegin (), this->cend (),
|
||||||
s.cbegin (), s.cend (), traits::eq );
|
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 {
|
size_type find(charT c) const {
|
||||||
|
@ -112,6 +112,16 @@ void find ( const char *arg ) {
|
|||||||
++p;
|
++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;
|
sr1 = arg;
|
||||||
p = arg;
|
p = arg;
|
||||||
// for all possible chars, see if we find them in the right place.
|
// for all possible chars, see if we find them in the right place.
|
||||||
@ -231,6 +241,56 @@ void find ( const char *arg ) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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 [] = {
|
const char *test_strings [] = {
|
||||||
"",
|
"",
|
||||||
"0",
|
"0",
|
||||||
@ -250,6 +310,8 @@ BOOST_AUTO_TEST_CASE( test_main )
|
|||||||
ends_with ( *p );
|
ends_with ( *p );
|
||||||
reverse ( *p );
|
reverse ( *p );
|
||||||
find ( *p );
|
find ( *p );
|
||||||
|
// to_string ( *p );
|
||||||
|
// compare ( *p );
|
||||||
|
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user