Float.st
branchjv
changeset 17751 b2273fa8d59f
parent 17736 26cfea63471d
child 17761 b0e5971141bc
--- a/Float.st	Sat Feb 13 18:48:33 2010 +0000
+++ b/Float.st	Sat Feb 13 23:34:44 2010 +0000
@@ -327,6 +327,24 @@
     "
 !
 
+fromSchemaString: aString
+	"Answer a float. Convert the schema string into a format dolphin can work with.
+	Throw an error if the string is a lexical representation that I cant convert to a float, (so I can catch INF,-INF,NaN)"
+
+	| lcString |
+	#swAdded.
+	(aString isNil or: [aString isEmpty]) ifTrue: [self error: 'Invalid Float'].
+	(#('INF' '-INF' 'NaN') includes: aString)
+		ifTrue: [SOAP::XeValueRangeError signal: 'Can not convert into a native value: ' , aString displayString]
+		ifFalse: [(aString allSatisfy: [ :each | each isDigit or: [ 'eE]+-.' includes: each]]) ifFalse: [
+			self error: 'Can not convert to integer: ' , aString displayString]].
+
+	lcString := aString asLowercase copyWithout: $+.
+	(lcString first isLetter or: [lcString first = $- and: [lcString second isLetter]])
+		ifTrue: [self error: 'Can not convert ' , aString displayString , ' into a Float'].
+	^self fromString: lcString
+!
+
 fromVAXFloatBytes:b1 b2:b2 b3:b3 b4:b4
     "creates a double, given the four vax float bytes to an ieee double.
      For NaNs and Infinity, nil is returned.
@@ -653,6 +671,7 @@
     ^ 2 "must be careful here, whenever ST/X is used on VAX or a 370"
 ! !
 
+
 !Float methodsFor:'arithmetic'!
 
 * aNumber
@@ -1252,7 +1271,6 @@
     ^ super ~= aNumber
 ! !
 
-
 !Float methodsFor:'mathematical functions'!
 
 exp
@@ -1437,6 +1455,25 @@
     "Modified: / 16.11.2001 / 14:14:43 / cg"
 ! !
 
+!Float methodsFor:'printing'!
+
+schemaDisplayString
+	"Answer a valid XMLSchema lexical representation of the float"
+
+	| basicString basicStream real|
+	#swAdded.
+	basicString := self displayString.
+	basicString := (basicString = '0.0' and: [self sign = -1])
+		ifTrue: ['-0.0']
+		ifFalse: [basicString].
+
+	basicStream  := basicString readStream.
+	real := basicStream upTo: $..
+	^(basicStream peek = $e)
+		ifTrue: [real , '.0' , basicStream upToEnd]
+		ifFalse: [basicString ]
+! !
+
 !Float methodsFor:'printing & storing'!
 
 printString
@@ -1842,6 +1879,7 @@
     "
 ! !
 
+
 !Float methodsFor:'testing'!
 
 isFinite
@@ -2738,13 +2776,14 @@
 !Float class methodsFor:'documentation'!
 
 version
-    ^ '$Id: Float.st 10482 2009-12-04 20:30:11Z vranyj1 $'
+    ^ '$Id: Float.st 10501 2010-02-13 23:34:44Z vranyj1 $'
 !
 
 version_CVS
-    ^ '§Header: /cvs/stx/stx/libbasic/Float.st,v 1.172 2009/12/03 10:16:49 cg Exp §'
+    ^ '§Header: /cvs/stx/stx/libbasic/Float.st,v 1.173 2010/02/10 17:45:57 cg Exp §'
 ! !
 
 Float initialize!
 
 
+