--- a/Number.st Thu Dec 15 14:32:46 2016 +0100
+++ b/Number.st Thu Dec 15 14:34:09 2016 +0100
@@ -157,11 +157,25 @@
In contrast to readFrom:, no garbage is allowed after the number.
I.e. the string must contain exactly one valid number (with optional separators around)"
- ^ self readFrom:aString decimalPointCharacters:decimalPointCharacters onError:exceptionBlock
+ |s num|
+
+ s := aString readStream.
+ num := self readFrom:s decimalPointCharacters:decimalPointCharacters onError:[^ exceptionBlock value].
+ s atEnd ifFalse:[
+ s skipSeparators.
+ s atEnd ifFalse:[
+ ^ exceptionBlock value "/ - garbage at end of number'
+ ].
+ ].
+ ^ num.
"
Number fromString:'12345' onError:0
+ Number fromString:'12,345' decimalPointCharacters:',' onError:0
+ Number fromString:'12,345' decimalPointCharacters:',' onError:0
Number fromString:'fooBarBaz' onError:0
+ Number fromString:'123fooBarBaz' onError:0
+ Number fromString:'123,fooBarBaz' decimalPointCharacters:',' onError:0
"
"Modified: / 3.8.1998 / 20:05:34 / cg"
@@ -172,11 +186,12 @@
In contrast to readFrom:, no garbage is allowed after the number.
I.e. the string must contain exactly one valid number (with optional separators around)"
- ^ self readFrom:aString onError:exceptionBlock
+ ^ self fromString:aString decimalPointCharacters:(self decimalPointCharactersForReading) onError:exceptionBlock
"
Number fromString:'12345' onError:0
Number fromString:'fooBarBaz' onError:0
+ Number fromString:'123fooBarBaz' onError:0
"
"Modified: / 3.8.1998 / 20:05:34 / cg"
@@ -503,6 +518,7 @@
^ Integer readFrom:aStream radix:radix
! !
+
!Number class methodsFor:'constants'!
decimalPointCharacter
@@ -710,6 +726,7 @@
"
! !
+
!Number class methodsFor:'private'!
readMantissaAndScaleFrom:aStream radix:radix
@@ -934,6 +951,7 @@
^ self rounded printString
! !
+
!Number methodsFor:'coercing & converting'!
i
@@ -2792,6 +2810,7 @@
"Modified: / 5.11.2001 / 17:54:22 / cg"
! !
+
!Number class methodsFor:'documentation'!
version