Bug on String>>replaceAll:with:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug on String>>replaceAll:with:

Giorgio Ferraris
Andy & Blair,

I find a bug on the following method:

>>>>>
replaceAll: sourceElement with: destElement
        "Replace all occurrences of sourceElement with destElement within the
receiver"
       
        |copia index|
       
        copia := self copy.
        index := 1.
        [(index < copia size) ] whileTrue: [
        index :=copia indexOfSubCollection: sourceElement startingAt: index.
        index = 0 ifTrue:[^self].
        index = 1 ifTrue:[copia := destElement,(self copyFrom: (index +
sourceElement size  ) to: (self size ))]
        ifFalse:[copia :=(copia copyFrom:1 to: (index-1)),destElement,(copia
copyFrom: (index + sourceElement size) to: (copia size)).].
        ].
        ^copia
<<<<<<<<


I think the line:
                   index = 0 ifTrue:[^self].
should answer copia intead of self.

                   index = 0 ifTrue:[^copia].

Here is a testCase for it:

 self assert: (('abc.defhgh.def.dehkl.defnnhtgf' replaceAll: '.def'
with: 'xxx') =
                'abcxxxhghxxx.dehklxxxnnhtgf')




BTW, I found the ivar named copia, wich is the Italian name for a
copy. Trying to learn italian?  :-)

Thanks for the good work!

Ciao

Giorgio Ferraris

PS: NO, I don't have a test suite for every smalltalk method (yet...),
but replaceAll:with is not portable (different on VW, same on VSE and
VA), so I have my version, under test, and I found the bug.


Reply | Threaded
Open this post in threaded view
|

Re: Bug on String>>replaceAll:with:

Andy Bower
Giorgio,

Hmmm... the appearence of Italian instance variables in the method made me
suspicious since, apart from a trip to Sardinia last year, I haven't tried
practising my Italian elsewhere. Could this be one of your own methods that
has slipped into the base system? In my image I don't have any definitions
of #replaceAll:with:. :-)

Best Regards,

Andy Bower
Dolphin Support
http://www.object-arts.com
---
Are you trying too hard?
http://www.object-arts.com/Relax.htm
---

> I find a bug on the following method:
>
> >>>>>
> replaceAll: sourceElement with: destElement
> "Replace all occurrences of sourceElement with destElement within the
> receiver"
>
> |copia index|
>
> copia := self copy.
> index := 1.
> [(index < copia size) ] whileTrue: [
> index :=copia indexOfSubCollection: sourceElement startingAt: index.
> index = 0 ifTrue:[^self].
> index = 1 ifTrue:[copia := destElement,(self copyFrom: (index +
> sourceElement size  ) to: (self size ))]
> ifFalse:[copia :=(copia copyFrom:1 to: (index-1)),destElement,(copia
> copyFrom: (index + sourceElement size) to: (copia size)).].
> ].
> ^copia
> <<<<<<<<
>
>
> I think the line:
>                    index = 0 ifTrue:[^self].
> should answer copia intead of self.
>
>                    index = 0 ifTrue:[^copia].
>
> Here is a testCase for it:
>
>  self assert: (('abc.defhgh.def.dehkl.defnnhtgf' replaceAll: '.def'
> with: 'xxx') =
>                 'abcxxxhghxxx.dehklxxxnnhtgf')
>
>
>
>
> BTW, I found the ivar named copia, wich is the Italian name for a
> copy. Trying to learn italian?  :-)
>
> Thanks for the good work!
>
> Ciao
>
> Giorgio Ferraris
>
> PS: NO, I don't have a test suite for every smalltalk method (yet...),
> but replaceAll:with is not portable (different on VW, same on VSE and
> VA), so I have my version, under test, and I found the bug.