Number.st
branchjv
changeset 21242 19fabe339f8b
parent 21024 8734987eb5c7
parent 21142 d9692dfa814f
child 25426 963f86568b2d
--- a/Number.st	Tue Dec 06 07:06:38 2016 +0100
+++ b/Number.st	Sun Dec 18 11:19:27 2016 +0000
@@ -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
@@ -784,6 +801,7 @@
     ^ self == Number
 ! !
 
+
 !Number methodsFor:'Compatibility-Squeak'!
 
 asSmallAngleDegrees
@@ -933,6 +951,7 @@
     ^ self rounded printString
 ! !
 
+
 !Number methodsFor:'coercing & converting'!
 
 i
@@ -1105,7 +1124,7 @@
 !
 
 degreesToRadians
-    "interpreting the receiver as radians, return the degrees"
+    "interpreting the receiver as degrees, return the radians"
 
     ^ self * (Float pi / 180.0)
 
@@ -1138,7 +1157,7 @@
 !
 
 radiansToDegrees
-    "interpreting the receiver as degrees, return the radians"
+    "interpreting the receiver as radians, return the degrees"
 
     ^ self * (180.0 / Float pi)
 
@@ -2791,6 +2810,7 @@
     "Modified: / 5.11.2001 / 17:54:22 / cg"
 ! !
 
+
 !Number class methodsFor:'documentation'!
 
 version