This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [patch] Re: string::rfind() -- empty strings...


On 23 Jun 2000 at 19:46 (-0400), brent verner said:
| 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

boy this has been a bad day :)) new (tested) patch attached. the 
--__pos should have been __pos-- ... testsuite on the way...

  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,__pos);
! 	  const _CharT* __data = _M_data();
! 	  do {
! 	    if (traits_type::compare(__data + __pos, __s, __n) == 0)
! 	      return __pos;
! 	  } while (__pos-- > 0);
  	}
        return npos;
      }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]