This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
[patch] Re: string::rfind() -- empty strings...
Ok, I think I'll take the brown paper bag off my head before I go
for a beer :) This patch is correct. For
std::string a("doh");
a.rfind("",pos); // null string
effectively returns min(a.size(),pos). No other behavior is affected.
I'll put together a testsuite for this -- Q: should I just copy
21_string/find.cc to rfind.cc or just add the rfind() stuff to
find.cc?
If this is wrong, just take the keyboard away :o
cheers.
brent
*** string.tcc.orig Fri Jun 23 19:33:26 2000
--- string.tcc.brent Fri Jun 23 19:33:47 2000
*************** namespace std
*** 634,647 ****
size_type __size = this->size();
if (__n <= __size)
{
! size_t __xpos = __size - __n;
! if (__xpos > __pos)
! __xpos = __pos;
!
! for (++__xpos; __xpos-- > 0; )
! if (traits_type::eq(_M_data()[__xpos], *__s)
! && traits_type::compare(_M_data() + __xpos, __s, __n) == 0)
! return __xpos;
}
return npos;
}
--- 634,645 ----
size_type __size = this->size();
if (__n <= __size)
{
! __pos = std::min(__size - __n,__pos);
! const _CharT* __data = _M_data();
! do {
! if (traits_type::compare(__data + __pos, __s, __n) == 0)
! return __pos;
! } while (--__pos > 0);
}
return npos;
}