mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 23:14:02 +00:00
fix breakage of string_ref logical ops, detabify, remove trailing whitespace
[SVN r83147]
This commit is contained in:
parent
9284a64936
commit
e0e16be802
@ -34,8 +34,6 @@ namespace boost {
|
|||||||
bool operator () ( charT val ) const { return traits::eq ( ch_, val ); }
|
bool operator () ( charT val ) const { return traits::eq ( ch_, val ); }
|
||||||
charT ch_;
|
charT ch_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T> struct __identity { typedef T type; };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits> class basic_string_ref;
|
template<typename charT, typename traits> class basic_string_ref;
|
||||||
@ -215,7 +213,7 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_type find_first_not_of(basic_string_ref s) const {
|
size_type find_first_not_of(basic_string_ref s) const {
|
||||||
const_iterator iter = find_not_of ( this->cbegin (), this->cend (), s );
|
const_iterator iter = find_not_of ( this->cbegin (), this->cend (), s );
|
||||||
return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
|
return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +225,7 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_type find_last_not_of(basic_string_ref s) const {
|
size_type find_last_not_of(basic_string_ref s) const {
|
||||||
const_reverse_iterator iter = find_not_of ( this->crbegin (), this->crend (), s );
|
const_reverse_iterator iter = find_not_of ( this->crbegin (), this->crend (), s );
|
||||||
return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter );
|
return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,11 +244,11 @@ namespace boost {
|
|||||||
|
|
||||||
template <typename Iterator>
|
template <typename Iterator>
|
||||||
Iterator find_not_of ( Iterator first, Iterator last, basic_string_ref s ) const {
|
Iterator find_not_of ( Iterator first, Iterator last, basic_string_ref s ) const {
|
||||||
for ( ; first != last ; ++first )
|
for ( ; first != last ; ++first )
|
||||||
if ( 0 == traits::find ( s.ptr_, s.len_, *first ))
|
if ( 0 == traits::find ( s.ptr_, s.len_, *first ))
|
||||||
return first;
|
return first;
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -259,22 +257,32 @@ namespace boost {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Comparison operators (3 for each operation)
|
// Comparison operators
|
||||||
// Equality
|
// Equality
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
bool operator==(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
|
bool operator==(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
|
||||||
if ( x.size () != y.size ()) return false;
|
if ( x.size () != y.size ()) return false;
|
||||||
return x.compare(y) == 0;
|
return x.compare(y) == 0;
|
||||||
}
|
}
|
||||||
template<typename charT, typename traits>
|
|
||||||
bool operator==(basic_string_ref<charT, traits> x, typename detail::__identity<basic_string_ref<charT, traits> >::type y) {
|
template<typename charT, typename traits, typename Allocator>
|
||||||
if ( x.size () != y.size ()) return false;
|
bool operator==(basic_string_ref<charT, traits> x, const std::basic_string<charT, traits, Allocator> & y) {
|
||||||
return x.compare(y) == 0;
|
return x == basic_string_ref<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits, typename Allocator>
|
||||||
|
bool operator==(const std::basic_string<charT, traits, Allocator> & x, basic_string_ref<charT, traits> y) {
|
||||||
|
return basic_string_ref<charT, traits>(x) == y;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
bool operator==(typename detail::__identity<basic_string_ref<charT, traits> >::type x, basic_string_ref<charT, traits> y) {
|
bool operator==(basic_string_ref<charT, traits> x, const charT * y) {
|
||||||
if ( x.size () != y.size ()) return false;
|
return x == basic_string_ref<charT, traits>(y);
|
||||||
return x.compare(y) == 0;
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits>
|
||||||
|
bool operator==(const charT * x, basic_string_ref<charT, traits> y) {
|
||||||
|
return basic_string_ref<charT, traits>(x) == y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inequality
|
// Inequality
|
||||||
@ -283,15 +291,25 @@ namespace boost {
|
|||||||
if ( x.size () != y.size ()) return true;
|
if ( x.size () != y.size ()) return true;
|
||||||
return x.compare(y) != 0;
|
return x.compare(y) != 0;
|
||||||
}
|
}
|
||||||
template<typename charT, typename traits>
|
|
||||||
bool operator!=(basic_string_ref<charT, traits> x, typename detail::__identity<basic_string_ref<charT, traits> >::type y) {
|
template<typename charT, typename traits, typename Allocator>
|
||||||
if ( x.size () != y.size ()) return true;
|
bool operator!=(basic_string_ref<charT, traits> x, const std::basic_string<charT, traits, Allocator> & y) {
|
||||||
return x.compare(y) != 0;
|
return x != basic_string_ref<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits, typename Allocator>
|
||||||
|
bool operator!=(const std::basic_string<charT, traits, Allocator> & x, basic_string_ref<charT, traits> y) {
|
||||||
|
return basic_string_ref<charT, traits>(x) != y;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
bool operator!=(typename detail::__identity<basic_string_ref<charT, traits> >::type x, basic_string_ref<charT, traits> y) {
|
bool operator!=(basic_string_ref<charT, traits> x, const charT * y) {
|
||||||
if ( x.size () != y.size ()) return true;
|
return x != basic_string_ref<charT, traits>(y);
|
||||||
return x.compare(y) != 0;
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits>
|
||||||
|
bool operator!=(const charT * x, basic_string_ref<charT, traits> y) {
|
||||||
|
return basic_string_ref<charT, traits>(x) != y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Less than
|
// Less than
|
||||||
@ -299,13 +317,25 @@ namespace boost {
|
|||||||
bool operator<(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
|
bool operator<(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
|
||||||
return x.compare(y) < 0;
|
return x.compare(y) < 0;
|
||||||
}
|
}
|
||||||
template<typename charT, typename traits>
|
|
||||||
bool operator<(basic_string_ref<charT, traits> x, typename detail::__identity<basic_string_ref<charT, traits> >::type y) {
|
template<typename charT, typename traits, typename Allocator>
|
||||||
return x.compare(y) < 0;
|
bool operator<(basic_string_ref<charT, traits> x, const std::basic_string<charT, traits, Allocator> & y) {
|
||||||
|
return x < basic_string_ref<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits, typename Allocator>
|
||||||
|
bool operator<(const std::basic_string<charT, traits, Allocator> & x, basic_string_ref<charT, traits> y) {
|
||||||
|
return basic_string_ref<charT, traits>(x) < y;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
bool operator<(typename detail::__identity<basic_string_ref<charT, traits> >::type x, basic_string_ref<charT, traits> y) {
|
bool operator<(basic_string_ref<charT, traits> x, const charT * y) {
|
||||||
return x.compare(y) < 0;
|
return x < basic_string_ref<charT, traits>(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits>
|
||||||
|
bool operator<(const charT * x, basic_string_ref<charT, traits> y) {
|
||||||
|
return basic_string_ref<charT, traits>(x) < y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greater than
|
// Greater than
|
||||||
@ -313,13 +343,25 @@ namespace boost {
|
|||||||
bool operator>(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
|
bool operator>(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
|
||||||
return x.compare(y) > 0;
|
return x.compare(y) > 0;
|
||||||
}
|
}
|
||||||
template<typename charT, typename traits>
|
|
||||||
bool operator>(basic_string_ref<charT, traits> x, typename detail::__identity<basic_string_ref<charT, traits> >::type y) {
|
template<typename charT, typename traits, typename Allocator>
|
||||||
return x.compare(y) > 0;
|
bool operator>(basic_string_ref<charT, traits> x, const std::basic_string<charT, traits, Allocator> & y) {
|
||||||
|
return x > basic_string_ref<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits, typename Allocator>
|
||||||
|
bool operator>(const std::basic_string<charT, traits, Allocator> & x, basic_string_ref<charT, traits> y) {
|
||||||
|
return basic_string_ref<charT, traits>(x) > y;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
bool operator>(typename detail::__identity<basic_string_ref<charT, traits> >::type x, basic_string_ref<charT, traits> y) {
|
bool operator>(basic_string_ref<charT, traits> x, const charT * y) {
|
||||||
return x.compare(y) > 0;
|
return x > basic_string_ref<charT, traits>(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits>
|
||||||
|
bool operator>(const charT * x, basic_string_ref<charT, traits> y) {
|
||||||
|
return basic_string_ref<charT, traits>(x) > y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Less than or equal to
|
// Less than or equal to
|
||||||
@ -327,13 +369,25 @@ namespace boost {
|
|||||||
bool operator<=(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
|
bool operator<=(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
|
||||||
return x.compare(y) <= 0;
|
return x.compare(y) <= 0;
|
||||||
}
|
}
|
||||||
template<typename charT, typename traits>
|
|
||||||
bool operator<=(basic_string_ref<charT, traits> x, typename detail::__identity<basic_string_ref<charT, traits> >::type y) {
|
template<typename charT, typename traits, typename Allocator>
|
||||||
return x.compare(y) <= 0;
|
bool operator<=(basic_string_ref<charT, traits> x, const std::basic_string<charT, traits, Allocator> & y) {
|
||||||
|
return x <= basic_string_ref<charT, traits>(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits, typename Allocator>
|
||||||
|
bool operator<=(const std::basic_string<charT, traits, Allocator> & x, basic_string_ref<charT, traits> y) {
|
||||||
|
return basic_string_ref<charT, traits>(x) <= y;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
bool operator<=(typename detail::__identity<basic_string_ref<charT, traits> >::type x, basic_string_ref<charT, traits> y) {
|
bool operator<=(basic_string_ref<charT, traits> x, const charT * y) {
|
||||||
return x.compare(y) <= 0;
|
return x <= basic_string_ref<charT, traits>(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits>
|
||||||
|
bool operator<=(const charT * x, basic_string_ref<charT, traits> y) {
|
||||||
|
return basic_string_ref<charT, traits>(x) <= y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greater than or equal to
|
// Greater than or equal to
|
||||||
@ -341,16 +395,26 @@ namespace boost {
|
|||||||
bool operator>=(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
|
bool operator>=(basic_string_ref<charT, traits> x, basic_string_ref<charT, traits> y) {
|
||||||
return x.compare(y) >= 0;
|
return x.compare(y) >= 0;
|
||||||
}
|
}
|
||||||
template<typename charT, typename traits>
|
|
||||||
bool operator>=(basic_string_ref<charT, traits> x, typename detail::__identity<basic_string_ref<charT, traits> >::type y) {
|
template<typename charT, typename traits, typename Allocator>
|
||||||
return x.compare(y) >= 0;
|
bool operator>=(basic_string_ref<charT, traits> x, const std::basic_string<charT, traits, Allocator> & y) {
|
||||||
}
|
return x >= basic_string_ref<charT, traits>(y);
|
||||||
template<typename charT, typename traits>
|
|
||||||
bool operator>=(typename detail::__identity<basic_string_ref<charT, traits> >::type x, basic_string_ref<charT, traits> y) {
|
|
||||||
return x.compare(y) >= 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits, typename Allocator>
|
||||||
|
bool operator>=(const std::basic_string<charT, traits, Allocator> & x, basic_string_ref<charT, traits> y) {
|
||||||
|
return basic_string_ref<charT, traits>(x) >= y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits>
|
||||||
|
bool operator>=(basic_string_ref<charT, traits> x, const charT * y) {
|
||||||
|
return x >= basic_string_ref<charT, traits>(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename charT, typename traits>
|
||||||
|
bool operator>=(const charT * x, basic_string_ref<charT, traits> y) {
|
||||||
|
return basic_string_ref<charT, traits>(x) >= y;
|
||||||
|
}
|
||||||
|
|
||||||
// Inserter
|
// Inserter
|
||||||
template<class charT, class traits>
|
template<class charT, class traits>
|
||||||
|
@ -85,9 +85,9 @@ void reverse ( const char *arg ) {
|
|||||||
|
|
||||||
// This helper function eliminates signed vs. unsigned warnings
|
// This helper function eliminates signed vs. unsigned warnings
|
||||||
string_ref::size_type ptr_diff ( const char *res, const char *base ) {
|
string_ref::size_type ptr_diff ( const char *res, const char *base ) {
|
||||||
BOOST_CHECK ( res >= base );
|
BOOST_CHECK ( res >= base );
|
||||||
return static_cast<string_ref::size_type> ( res - base );
|
return static_cast<string_ref::size_type> ( res - base );
|
||||||
}
|
}
|
||||||
|
|
||||||
void find ( const char *arg ) {
|
void find ( const char *arg ) {
|
||||||
string_ref sr1;
|
string_ref sr1;
|
||||||
@ -115,12 +115,12 @@ void find ( const char *arg ) {
|
|||||||
// Look for pairs on characters (searching from the start)
|
// Look for pairs on characters (searching from the start)
|
||||||
sr1 = arg;
|
sr1 = arg;
|
||||||
p = arg;
|
p = arg;
|
||||||
while ( *p && *(p+1)) {
|
while ( *p && *(p+1)) {
|
||||||
string_ref sr3 ( p, 2 );
|
string_ref sr3 ( p, 2 );
|
||||||
string_ref::size_type pos = sr1.find ( sr3 );
|
string_ref::size_type pos = sr1.find ( sr3 );
|
||||||
BOOST_CHECK ( pos != string_ref::npos && pos <= static_cast<string_ref::size_type>( p - arg ));
|
BOOST_CHECK ( pos != string_ref::npos && pos <= static_cast<string_ref::size_type>( p - arg ));
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
sr1 = arg;
|
sr1 = arg;
|
||||||
p = arg;
|
p = arg;
|
||||||
@ -244,50 +244,51 @@ void find ( const char *arg ) {
|
|||||||
|
|
||||||
void to_string ( const char *arg ) {
|
void to_string ( const char *arg ) {
|
||||||
string_ref sr1;
|
string_ref sr1;
|
||||||
std::string str1;
|
std::string str1;
|
||||||
std::string str2;
|
std::string str2;
|
||||||
|
|
||||||
str1.assign ( arg );
|
str1.assign ( arg );
|
||||||
sr1 = arg;
|
sr1 = arg;
|
||||||
// str2 = sr1.to_string<std::allocator<char> > ();
|
// str2 = sr1.to_string<std::allocator<char> > ();
|
||||||
str2 = sr1.to_string ();
|
str2 = sr1.to_string ();
|
||||||
BOOST_CHECK ( str1 == str2 );
|
BOOST_CHECK ( str1 == str2 );
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
|
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
|
||||||
std::string str3 = static_cast<std::string> ( sr1 );
|
std::string str3 = static_cast<std::string> ( sr1 );
|
||||||
BOOST_CHECK ( str1 == str3 );
|
BOOST_CHECK ( str1 == str3 );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void compare ( const char *arg ) {
|
void compare ( const char *arg ) {
|
||||||
string_ref sr1;
|
string_ref sr1;
|
||||||
std::string str1;
|
std::string str1;
|
||||||
std::string str2 = str1;
|
std::string str2 = str1;
|
||||||
|
|
||||||
str1.assign ( arg );
|
str1.assign ( arg );
|
||||||
sr1 = arg;
|
sr1 = arg;
|
||||||
BOOST_CHECK ( sr1 == str1); // compare string and string_ref
|
BOOST_CHECK ( sr1 == sr1); // compare string_ref and string_ref
|
||||||
BOOST_CHECK ( str1 == sr1 ); // compare string_ref and string
|
BOOST_CHECK ( sr1 == str1); // compare string and string_ref
|
||||||
BOOST_CHECK ( sr1 == arg ); // compare string_ref and pointer
|
BOOST_CHECK ( str1 == sr1 ); // compare string_ref and string
|
||||||
BOOST_CHECK ( arg == sr1 ); // compare pointer and string_ref
|
BOOST_CHECK ( sr1 == arg ); // compare string_ref and pointer
|
||||||
|
BOOST_CHECK ( arg == sr1 ); // compare pointer and string_ref
|
||||||
|
|
||||||
if ( sr1.size () > 0 ) {
|
if ( sr1.size () > 0 ) {
|
||||||
(*str1.rbegin())++;
|
(*str1.rbegin())++;
|
||||||
BOOST_CHECK ( sr1 != str1 );
|
BOOST_CHECK ( sr1 != str1 );
|
||||||
BOOST_CHECK ( str1 != sr1 );
|
BOOST_CHECK ( str1 != sr1 );
|
||||||
BOOST_CHECK ( sr1 < str1 );
|
BOOST_CHECK ( sr1 < str1 );
|
||||||
BOOST_CHECK ( sr1 <= str1 );
|
BOOST_CHECK ( sr1 <= str1 );
|
||||||
BOOST_CHECK ( str1 > sr1 );
|
BOOST_CHECK ( str1 > sr1 );
|
||||||
BOOST_CHECK ( str1 >= sr1 );
|
BOOST_CHECK ( str1 >= sr1 );
|
||||||
|
|
||||||
(*str1.rbegin()) -= 2;
|
(*str1.rbegin()) -= 2;
|
||||||
BOOST_CHECK ( sr1 != str1 );
|
BOOST_CHECK ( sr1 != str1 );
|
||||||
BOOST_CHECK ( str1 != sr1 );
|
BOOST_CHECK ( str1 != sr1 );
|
||||||
BOOST_CHECK ( sr1 > str1 );
|
BOOST_CHECK ( sr1 > str1 );
|
||||||
BOOST_CHECK ( sr1 >= str1 );
|
BOOST_CHECK ( sr1 >= str1 );
|
||||||
BOOST_CHECK ( str1 < sr1 );
|
BOOST_CHECK ( str1 < sr1 );
|
||||||
BOOST_CHECK ( str1 <= sr1 );
|
BOOST_CHECK ( str1 <= sr1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *test_strings [] = {
|
const char *test_strings [] = {
|
||||||
@ -310,7 +311,7 @@ BOOST_AUTO_TEST_CASE( test_main )
|
|||||||
reverse ( *p );
|
reverse ( *p );
|
||||||
find ( *p );
|
find ( *p );
|
||||||
to_string ( *p );
|
to_string ( *p );
|
||||||
compare ( *p );
|
compare ( *p );
|
||||||
|
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user