class: PeekableStream
authorClaus Gittinger <cg@exept.de>
Tue, 14 Apr 2015 13:04:28 +0200
changeset 18213 c0d479ac5af6
parent 18211 d4c844b6a858
child 18214 60e1764add21
class: PeekableStream changed: #nextChunk ouch - failed for unicode characters in the code
PeekableStream.st
--- a/PeekableStream.st	Mon Apr 13 16:02:13 2015 +0200
+++ b/PeekableStream.st	Tue Apr 14 13:04:28 2015 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1994 by Claus Gittinger
 	      All Rights Reserved
@@ -137,30 +139,21 @@
      read chunks containing primitive code 
      - but that doesn't really matter, since C-primitives are an ST/X feature anyway."
 
-    |theString chunkSeparator newString done thisChar nextChar 
+    |buffer theString chunkSeparator newString done thisChar nextChar 
      atBeginOfLine inPrimitive  hasCR hasLF
      index    "{ Class:SmallInteger }"
      currSize "{ Class:SmallInteger }" |
 
     chunkSeparator := ChunkSeparator.
-    currSize := 500.
-    theString := String new:currSize.
+    buffer := CharacterWriteStream on:(String new:100).
     self skipSeparators.
     thisChar := self nextOrNil.
-    index := 0.
     done := false.
     atBeginOfLine := true.
     inPrimitive := false.
     hasCR := hasLF := false.
 
     [done not and:[thisChar notNil]] whileTrue:[
-        ((index + 2) <= currSize) ifFalse:[
-            newString := String new:(currSize * 2).
-            newString replaceFrom:1 to:currSize with:theString.
-            currSize := currSize * 2.
-            theString := newString
-        ].
-
         "match primitive only at beginning of line 
          (ExternalStream>>#nextChunk did this, although stc allows primitive to start anywhere)"
 
@@ -168,14 +161,12 @@
             nextChar := self peekOrNil.
             (nextChar == ${ ) ifTrue:[
                 inPrimitive := true.
-                index := index + 1.
-                theString at:index put:thisChar.
+                buffer nextPut:thisChar.
                 thisChar := self next
             ] ifFalse:[
                 (nextChar == $} ) ifTrue:[
                     inPrimitive := false.
-                    index := index + 1.
-                    theString at:index put:thisChar.
+                    buffer nextPut:thisChar.
                     thisChar := self next
                 ]
             ]
@@ -209,15 +200,12 @@
                 atBeginOfLine := true.
             ]].
                 
-            index := index + 1.
-            theString at:index put:thisChar.
+            buffer nextPut:thisChar.
             thisChar := self nextOrNil.
         ].
     ].
 
-    (index == 0) ifTrue:[^ ''].
-
-    theString := theString copyTo:index.
+    theString := buffer contents.
     (hasCR and:[hasLF not]) ifTrue:[
         "map all CR in a CR only file to NL (ExternalStream>>#nextChunk did this)"
         theString replaceAll:Character cr with:Character nl.
@@ -857,11 +845,11 @@
 !PeekableStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/PeekableStream.st,v 1.53 2015-03-23 15:15:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/PeekableStream.st,v 1.54 2015-04-14 11:04:28 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/PeekableStream.st,v 1.53 2015-03-23 15:15:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/PeekableStream.st,v 1.54 2015-04-14 11:04:28 cg Exp $'
 ! !