care for bitsPerCharacter when expanding macros
authorClaus Gittinger <cg@exept.de>
Wed, 19 Sep 2007 12:12:47 +0200
changeset 10721 58e6950264cb
parent 10720 4bb896884092
child 10722 ab6fbe61f116
care for bitsPerCharacter when expanding macros
CharacterArray.st
--- a/CharacterArray.st	Tue Sep 18 16:39:41 2007 +0200
+++ b/CharacterArray.st	Wed Sep 19 12:12:47 2007 +0200
@@ -1259,97 +1259,97 @@
     |in out c fmt nr arg s1 s2 peekc|
 
     in := self readStream.
-    out := WriteStream on:(self species uninitializedNew:self size).
+    out := CharacterWriteStream on:(self species uninitializedNew:self size).
 
     [in atEnd] whileFalse:[
-	c := in next.
-	c == $% ifTrue:[
-	    c := in next.
-	    out nextPut:c
-	] ifFalse:[c ~~ $< ifTrue:[
-	    out nextPut:c.
-	] ifFalse:[
-	    peekc := in peek.
-	    [peekc == $<] whileTrue:[
-		out nextPut:$<.
-		peekc := in nextPeek.
-	    ].
-	    peekc == $n ifTrue:[
-		peekc := in nextPeek.
-		peekc == $> ifTrue:[
-		    in next.
-		    out cr.
-		] ifFalse:[
-		    out nextPutAll:'<n'.
-		]
-	    ] ifFalse:[peekc == $t ifTrue:[
-		peekc := in nextPeek.
-		peekc == $> ifTrue:[
-		    in next.
-		    out tab.
-		] ifFalse:[
-		    out nextPutAll:'<t'.
-		]
-	    ] ifFalse:[
-		peekc isDigit ifTrue:[
-		    "start an argument expansion ..."
-		    nr := Integer readFrom:in onError:nil.
-		    nr isNil ifTrue:[
-			"this cannot happen (there is at least one digit)"
-			self error:'invalid format' mayProceed:true.
-			^ self
-		    ].
-		    fmt := in next.
-		    (fmt ~~ $? and:[in peek ~~ $>]) ifTrue:[
-			out nextPut:$<.
-			nr printOn:out.
-			out nextPut:fmt.
-		    ] ifFalse:[
-			(nr between:1 and:argArray size) ifTrue:[
-			    arg := argArray at:nr.
-			] ifFalse:[
-			    arg := ''
-			].
-
-			fmt == $p ifTrue:[
-			    "expand with args printString"
-			    arg printOn:out.
-			] ifFalse:[fmt == $s ifTrue:[
-			    "expand with arg itself"
-			    arg isText ifTrue:[
-				out contentsSpecies isText ifFalse:[
-				    out := (WriteStream on:Text new) nextPutAll:out contents; yourself.
-				].
-				out nextPutAll:arg.
-			    ] ifFalse:[
-				out nextPutAll:arg asString string.
-			    ]
-			] ifFalse:[fmt == $? ifTrue:[
-			    s1 := in upTo:$:.
-			    s2 := in nextUpTo:$>.
-			    arg == true ifTrue:[
-				out nextPutAll:s1
-			    ] ifFalse:[
-				out nextPutAll:s2
-			    ].
-			] ifFalse:[
-			    "what does VW do here ?"
-			    self error:'invalid format' mayProceed:true.
-			    ^ self
-			]]].
-			c := in next.
-			c ~~ $> ifTrue:[
-			    "what does VW do here ?"
-			    self error:'invalid format' mayProceed:true.
-			    ^ self
-			]
-
-		    ].
-		] ifFalse:[
-		    out nextPut:$<.
-		].
-	    ]].
-	]].
+        c := in next.
+        c == $% ifTrue:[
+            c := in next.
+            out nextPut:c
+        ] ifFalse:[c ~~ $< ifTrue:[
+            out nextPut:c.
+        ] ifFalse:[
+            peekc := in peek.
+            [peekc == $<] whileTrue:[
+                out nextPut:$<.
+                peekc := in nextPeek.
+            ].
+            peekc == $n ifTrue:[
+                peekc := in nextPeek.
+                peekc == $> ifTrue:[
+                    in next.
+                    out cr.
+                ] ifFalse:[
+                    out nextPutAll:'<n'.
+                ]
+            ] ifFalse:[peekc == $t ifTrue:[
+                peekc := in nextPeek.
+                peekc == $> ifTrue:[
+                    in next.
+                    out tab.
+                ] ifFalse:[
+                    out nextPutAll:'<t'.
+                ]
+            ] ifFalse:[
+                peekc isDigit ifTrue:[
+                    "start an argument expansion ..."
+                    nr := Integer readFrom:in onError:nil.
+                    nr isNil ifTrue:[
+                        "this cannot happen (there is at least one digit)"
+                        self error:'invalid format' mayProceed:true.
+                        ^ self
+                    ].
+                    fmt := in next.
+                    (fmt ~~ $? and:[in peek ~~ $>]) ifTrue:[
+                        out nextPut:$<.
+                        nr printOn:out.
+                        out nextPut:fmt.
+                    ] ifFalse:[
+                        (nr between:1 and:argArray size) ifTrue:[
+                            arg := argArray at:nr.
+                        ] ifFalse:[
+                            arg := ''
+                        ].
+
+                        fmt == $p ifTrue:[
+                            "expand with args printString"
+                            arg printOn:out.
+                        ] ifFalse:[fmt == $s ifTrue:[
+                            "expand with arg itself"
+                            arg isText ifTrue:[
+                                out contentsSpecies isText ifFalse:[
+                                    out := (WriteStream on:Text new) nextPutAll:out contents; yourself.
+                                ].
+                                out nextPutAll:arg.
+                            ] ifFalse:[
+                                out nextPutAll:arg "asString" string.
+                            ]
+                        ] ifFalse:[fmt == $? ifTrue:[
+                            s1 := in upTo:$:.
+                            s2 := in nextUpTo:$>.
+                            arg == true ifTrue:[
+                                out nextPutAll:s1
+                            ] ifFalse:[
+                                out nextPutAll:s2
+                            ].
+                        ] ifFalse:[
+                            "what does VW do here ?"
+                            self error:'invalid format' mayProceed:true.
+                            ^ self
+                        ]]].
+                        c := in next.
+                        c ~~ $> ifTrue:[
+                            "what does VW do here ?"
+                            self error:'invalid format' mayProceed:true.
+                            ^ self
+                        ]
+
+                    ].
+                ] ifFalse:[
+                    out nextPut:$<.
+                ].
+            ]].
+        ]].
     ].
     ^ out contents
 
@@ -1358,7 +1358,7 @@
      'one plus one is <1p>' expandMacrosWith:2
     "
 
-    "Modified: / 18.6.1998 / 16:04:46 / cg"
+    "Modified: / 18-09-2007 / 22:50:43 / cg"
 !
 
 isCharacters
@@ -1366,6 +1366,7 @@
     ^ true
 ! !
 
+
 !CharacterArray methodsFor:'character searching'!
 
 includesMatchCharacters
@@ -5257,7 +5258,7 @@
 !CharacterArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.362 2007-09-10 11:43:47 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.363 2007-09-19 10:12:47 cg Exp $'
 ! !
 
 CharacterArray initialize!