[BUG] String>>asInteger

Michael Roberts mike at mjr104.co.uk
Thu Jan 22 12:06:04 UTC 2004

On Wed, Jan 21, 2004 at 01:36:54PM -0500, Doug Way wrote:
> I agree that the naming here is bad enough to be considered a bug.  The 
> solution would appear to be to rename String>>asInteger to 
> String>>asUnsignedInteger, and rename String>>asSignedInteger to 
> String>>asInteger. 

this seems a good start to me.
> It looks like there are no senders of asUnsignedInteger in the alpha 
> image.  
Yes, I saw that.  That's why I was wondering about the original intent.

> Another possible improvement would be to reimplement these methods to 
> use Integer>>readFrom:.
I was going to write some simple tests but the methods seem to do slightly different things.  

>From the comments in String>>asInteger it is designed to find the first integer in the string 

'abc234def567' asInteger -> 234

but Integer class>>readFrom: is not identical.

Integer readFrom: (ReadStream on: 'abc234def567') -> Error 'at least one digit expected here'

So it wants the integer at the start but will ignore non integers after this 

Integer readFrom: (ReadStream on: '234def567') -> 234

so how tight should the semantics be?  We have both conversion and 'sub-string' behaviour.



More information about the Squeak-dev mailing list