CharacterArray.st
changeset 8938 860bbcbd3bd8
parent 8913 b9498d27a554
child 8954 12e701d7b5ac
--- a/CharacterArray.st	Tue Jul 26 16:24:31 2005 +0200
+++ b/CharacterArray.st	Tue Aug 16 17:46:12 2005 +0200
@@ -3811,52 +3811,54 @@
     stop := self size.
     start := 1.
     [start <= stop] whileTrue:[
-	idx := self indexOf:$% startingAt:start.
-	(idx == 0 or:[idx == stop]) ifTrue:[
-	    ^ expandedString , (self copyFrom:start to:stop)
-	].
-	"found a %"
-	expandedString := expandedString , (self copyFrom:start to:(idx - 1)).
-	next := self at:(idx + 1).
-	(next == $%) ifTrue:[
-	    expandedString := expandedString , '%'
-	] ifFalse:[
-	    (next between:$1 and:$9) ifTrue:[
-		v := argArrayOrDictionary at:(next digitValue) ifAbsent:nil
-	    ] ifFalse:[
-		next == $( ifTrue:[
-		    idx2 := self indexOf:$) startingAt:idx+2.
-		    key := self copyFrom:idx+2 to:idx2-1.
-		    idx := idx2 - 1.
-		    keyAsSymbol := key asSymbolIfInterned.
-		    (keyAsSymbol notNil and:[ argArrayOrDictionary includesKey:keyAsSymbol ]) ifTrue:[
-			v := argArrayOrDictionary at:keyAsSymbol
-		    ] ifFalse:[
-			(key conform:[:each | each isDigit]) ifTrue:[
-			    key := Number readFrom:key onError:nil.
-			].
-			v := argArrayOrDictionary at:key ifAbsent:nil
-		    ].
-		] ifFalse:[
-		    v := argArrayOrDictionary at:next ifAbsent:nil.
-		    v isNil ifTrue:[
-			(argArrayOrDictionary includesKey:next asString) ifTrue:[
-			    v := argArrayOrDictionary at:next asString asSymbol ifAbsent:nil.
-			] ifFalse:[
-			    v := String with:$% with:next. "/ next asString.
-			]
-		    ].
-		]
-	    ].
-	    v isNil
-		ifTrue:[v := '']
-		ifFalse:[
-		    v isBlock ifTrue:[
-			v := v value
-		    ]].
-	    expandedString := expandedString , v printString
-	].
-	start := idx + 2
+        idx := self indexOf:$% startingAt:start.
+        (idx == 0 or:[idx == stop]) ifTrue:[
+            ^ expandedString , (self copyFrom:start to:stop)
+        ].
+        "found a %"
+        expandedString := expandedString , (self copyFrom:start to:(idx - 1)).
+        next := self at:(idx + 1).
+        (next == $%) ifTrue:[
+            expandedString := expandedString , '%'
+        ] ifFalse:[
+            (next between:$1 and:$9) ifTrue:[
+                v := argArrayOrDictionary at:(next digitValue) ifAbsent:nil
+            ] ifFalse:[
+                next == $( ifTrue:[
+                    idx2 := self indexOf:$) startingAt:idx+2.
+                    key := self copyFrom:idx+2 to:idx2-1.
+                    idx := idx2 - 1.
+                    keyAsSymbol := key asSymbolIfInterned.
+                    (keyAsSymbol notNil and:[ argArrayOrDictionary includesKey:keyAsSymbol ]) ifTrue:[
+                        v := argArrayOrDictionary at:keyAsSymbol
+                    ] ifFalse:[
+                        (key conform:[:each | each isDigit]) ifTrue:[
+                            key := Number readFrom:key onError:nil.
+                        ].
+                        v := argArrayOrDictionary at:key ifAbsent:nil
+                    ].
+                ] ifFalse:[
+                    argArrayOrDictionary isSequenceable ifFalse:[
+                        "Arrays etc. can be only indexed with integers, not with characters or strings"
+                        v := argArrayOrDictionary at:next ifAbsent:nil.
+                        v isNil ifTrue:[
+                            v := argArrayOrDictionary at:next asString asSymbol ifAbsent:nil.
+                        ].
+                    ].
+                    v isNil ifTrue:[
+                        v := String with:$% with:next. "No match, keep original sequence"
+                    ].
+                ]
+            ].
+            v isNil
+                ifTrue:[v := '']
+                ifFalse:[
+                    v isBlock ifTrue:[
+                        v := v value
+                    ]].
+            expandedString := expandedString , v printString
+        ].
+        start := idx + 2
     ].
     ^  expandedString
 
@@ -3868,6 +3870,7 @@
      '%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123)
      '%%10 gives %10' expandPlaceholdersWith:#(123)
      '%%(10) gives %(10)' expandPlaceholdersWith:#(123)
+     '%test gives %1' expandPlaceholdersWith:#(123)
     "
 
     "
@@ -4988,7 +4991,7 @@
 !CharacterArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.320 2005-07-08 17:15:00 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.321 2005-08-16 15:46:12 stefan Exp $'
 ! !
 
 CharacterArray initialize!