TypeConverter.st
changeset 1653 f086f72cc8fa
parent 1465 02c6dfc01257
child 1695 3b54883b6392
--- a/TypeConverter.st	Sat Oct 26 17:52:10 2002 +0200
+++ b/TypeConverter.st	Tue Oct 29 10:40:40 2002 +0100
@@ -1038,6 +1038,55 @@
     "Created: / 29.10.1997 / 15:50:16 / cg"
 !
 
+symbolOrBooleanOrNil
+    "setup the converter to convert from a string to a symbol or boolean
+     and vice versa. Invalid symbols (i.e. empty) are converted to nil;
+     nil values are converted to an empty string.
+     In addition, the strings true/false convert to/from booleans."
+
+    self
+        getBlock:[:model |
+                |symbolValue|
+
+                ((symbolValue := model value) isSymbol 
+                or:[symbolValue isBoolean]) 
+                ifFalse:[
+                    ''
+                ] ifTrue:[
+                    symbolValue printString. "/ storeString
+                ]]
+
+        putBlock:
+                [:model :string |
+
+                |value s|
+
+                string size == 0 ifTrue:[
+                    value := nil
+                ] ifFalse:[
+                    s := string withoutSeparators.
+                    (s startsWith:'#') ifTrue:[
+                        s := s copyFrom:2.
+                        (s startsWith:$') ifTrue:[
+                            s := s copyFrom:2 to:(s size - 1)
+                        ].
+                        value := s asSymbol
+                    ] ifFalse:[
+                        (#('true' 'false') includes:s) ifTrue:[
+                            value := Object readFromString:s.
+                        ] ifFalse:[
+                            value := s asSymbol
+                        ]
+                    ].
+                ].
+                model value:value]
+
+        updateBlock: [:m :a :p | true]
+
+    "Created: / 21.2.1997 / 18:58:38 / cg"
+    "Modified: / 26.5.1998 / 15:06:06 / cg"
+!
+
 symbolOrNil
     "setup the converter to convert from a string to a symbol
      and vice versa. Invalid symbols (i.e. empty) are converted to nil;
@@ -1170,5 +1219,5 @@
 !TypeConverter class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.38 2001-04-02 12:58:07 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.39 2002-10-29 09:40:40 cg Exp $'
 ! !