got nextChunk from subclass
authorClaus Gittinger <cg@exept.de>
Mon, 22 May 2000 13:11:09 +0200
changeset 5394 f877659e09f7
parent 5393 7e2230bd4bad
child 5395 8766e18acdb5
got nextChunk from subclass
PeekableStream.st
--- a/PeekableStream.st	Mon May 22 13:10:37 2000 +0200
+++ b/PeekableStream.st	Mon May 22 13:11:09 2000 +0200
@@ -10,6 +10,8 @@
  hereby transferred.
 "
 
+"{ Package: 'stx:libbasic' }"
+
 Stream subclass:#PeekableStream
 	instanceVariableNames:''
 	classVariableNames:''
@@ -44,6 +46,78 @@
 "
 ! !
 
+!PeekableStream methodsFor:'chunk input/output'!
+
+nextChunk
+    "return the next chunk, i.e. all characters up to the next
+     exclamation mark. Within the chunk, exclamation marks have to be doubled,
+     they are undoubled here.
+     Except for primitive code, in which doubling is not needed (allowed).
+     This exception was added to make it easier to edit primitive code with 
+     external editors. However, this means, that other Smalltalks cannot always 
+     read chunks containing primitive code 
+     - but that doesnt really matter, since C-primitives are an ST/X feature anyway."
+
+    |theString sep newString done thisChar nextChar inPrimitive
+     index    "{ Class:SmallInteger }"
+     currSize "{ Class:SmallInteger }" |
+
+    sep := ChunkSeparator.
+    theString := String new:500.
+    currSize := 500.
+    thisChar := self skipSeparators.
+    thisChar := self next.
+    index := 0.
+    done := false.
+    inPrimitive := false.
+
+    [done] whileFalse:[
+	((index + 2) <= currSize) ifFalse:[
+	    newString := String new:(currSize * 2).
+	    newString replaceFrom:1 to:currSize with:theString.
+	    currSize := currSize * 2.
+	    theString := newString
+	].
+	thisChar isNil ifTrue:[
+	    done := true
+	] ifFalse:[
+	    (thisChar == $% ) ifTrue:[
+		nextChar := self peek.
+		(nextChar == ${ ) ifTrue:[
+		    inPrimitive := true.
+		    index := index + 1.
+		    theString at:index put:thisChar.
+		    thisChar := self next
+		] ifFalse:[
+		    (nextChar == $} ) ifTrue:[
+			inPrimitive := false.
+			index := index + 1.
+			theString at:index put:thisChar.
+			thisChar := self next
+		    ]
+		]
+	    ] ifFalse:[
+		inPrimitive ifFalse:[
+		    (thisChar == sep) ifTrue:[
+			(self peek == sep) ifFalse:[
+			    done := true
+			] ifTrue:[
+			    self next
+			]
+		    ]
+		]
+	    ]
+	].
+	done ifFalse:[
+	    index := index + 1.
+	    theString at:index put:thisChar.
+	    thisChar := self next
+	]
+    ].
+    (index == 0) ifTrue:[^ ''].
+    ^ theString copyTo:index
+! !
+
 !PeekableStream methodsFor:'positioning'!
 
 skipAny:skipCollection
@@ -293,5 +367,5 @@
 !PeekableStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/PeekableStream.st,v 1.20 1999-07-22 16:29:18 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/PeekableStream.st,v 1.21 2000-05-22 11:11:09 cg Exp $'
 ! !