# HG changeset patch # User Claus Gittinger # Date 1241035084 -7200 # Node ID cadc459b3c534f30d45195b4593089d6071a5f58 # Parent aae1c83162bc2783f3c471bfa6bbfd1b047997a9 *** empty log message *** diff -r aae1c83162bc -r cadc459b3c53 TypeConverter.st --- a/TypeConverter.st Tue Mar 31 23:57:34 2009 +0200 +++ b/TypeConverter.st Wed Apr 29 21:58:04 2009 +0200 @@ -712,6 +712,13 @@ updateBlock: [:m :a :p | true] ! +integer + "setup the converter to convert from a string to an integer + and vice versa. Invalid integers are converted to nil." + + self integerToText +! + integerToHexTextMinValue:minVal maxValue:maxVal format:formatStringOrNil "setup the converter to convert from a string to a number and vice versa, but clamping the number into the range." @@ -719,6 +726,35 @@ ^ self integerToTextMinValue:minVal maxValue:maxVal radix:16 format:formatStringOrNil ! +integerToText + "setup the converter to convert from a string to a integer + and vice versa." + + self + getBlock:[:model | + |numericValue| + + (numericValue := model value) isInteger ifFalse:[ + String new + ] ifTrue:[ + numericValue printString + ]] + + putBlock: + [:model :string | + + |value| + + string isEmptyOrNil ifTrue:[ + value := 0 + ] ifFalse:[ + value := Integer readFromString: string onError:[0] + ]. + model value:value] + + updateBlock: [:m :a :p | true] +! + integerToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil "setup the converter to convert from a string to a number and vice versa, but clamping the number into the range." @@ -1721,5 +1757,5 @@ !TypeConverter class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.60 2009-03-26 13:59:44 stefan Exp $' + ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.61 2009-04-29 19:58:04 cg Exp $' ! !