Thread overview
std.string.replace in 0.133
Sep 27, 2005
Steve Adams
Sep 27, 2005
Thomas Kühne
Sep 27, 2005
Derek Parnell
September 27, 2005
This works in prior releases.  When compiled and run with dmd -w, this
causes an access violation.


import std.string;
int main()
{
  // change "  YYY" to " YYY" and it runs
  char[] s    = replace( std.string.toupper( "xxx" ), "  YYY", "" );
  return( 0 );
}
September 27, 2005
Steve Adams schrieb:

> This works in prior releases.  When compiled and run with dmd -w, this causes an access violation.
> 
> 
> import std.string;
> int main()
> {
>   // change "  YYY" to " YYY" and it runs
>   char[] s    = replace( std.string.toupper( "xxx" ), "  YYY", "" );
>   return( 0 );
> }

FIX: std/string.d -> ifind (line 596)

from:
# size_t imax = s.length - sublength + 1;

to:
# size_t imax;
# if(s.length + 1 > sublength)
#     imax = (s.length + 1) - sublength;

Thomas
September 27, 2005
On Tue, 27 Sep 2005 23:48:24 +0200, Thomas Kühne wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Steve Adams schrieb:
> 
>> This works in prior releases.  When compiled and run with dmd -w, this causes an access violation.
>> 
>> import std.string;
>> int main()
>> {
>>   // change "  YYY" to " YYY" and it runs
>>   char[] s    = replace( std.string.toupper( "xxx" ), "  YYY", "" );
>>   return( 0 );
>> }
> 
> FIX: std/string.d -> ifind (line 596)
> 
> from:
> # size_t imax = s.length - sublength + 1;
> 
> to:
> # size_t imax;
> # if(s.length + 1 > sublength)
> #     imax = (s.length + 1) - sublength;
> 

Could that 'fix' also be

  if (sublength > s.length)
     return -1;

on basis that if the substring is longer than the string, then the string cannot contain the substring.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
28/09/2005 8:44:34 AM