#BUGFIX by cg
authorClaus Gittinger <cg@exept.de>
Wed, 27 Mar 2019 16:01:17 +0100
changeset 23988 fdde978e324a
parent 23987 bba7ed9be3c1
child 23989 c34a416053bb
#BUGFIX by cg class: EncodedStream class definition added: #skip: comment/format in: #nextChunk changed: #next some better skipping (remember position of last character for skip:-1)
EncodedStream.st
--- a/EncodedStream.st	Wed Mar 27 15:41:37 2019 +0100
+++ b/EncodedStream.st	Wed Mar 27 16:01:17 2019 +0100
@@ -16,7 +16,7 @@
 "{ NameSpace: Smalltalk }"
 
 PeekableStream subclass:#EncodedStream
-	instanceVariableNames:'encoder stream peekChar'
+	instanceVariableNames:'encoder stream peekChar positionOfStreamBeforeLast'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Collections-Text-Encodings'
@@ -201,7 +201,8 @@
 !EncodedStream methodsFor:'chunk input/output'!
 
 nextChunk
-    "as a side effect, check for an encoding chunk"
+    "reads a smalltalk chunk.
+     as a side effect, check for an encoding chunk"
     
     |chunk|
 
@@ -311,6 +312,7 @@
         peekChar := nil.
         ^ p.
     ].
+    positionOfStreamBeforeLast := stream position.
     ^ encoder readNextCharacterFrom:stream
 
     "Created: / 14-06-2005 / 17:01:39 / janfrog"
@@ -450,6 +452,19 @@
     "Created: / 31-08-2012 / 16:52:40 / cg"
 !
 
+skip:nrToSkip
+    "sigh: this positions the underlying stream, ignoring any encodings"
+
+    "/ can only skip backward by one single character
+    nrToSkip == -1 ifTrue:[
+        stream position:positionOfStreamBeforeLast.
+        peekChar := nil.
+        ^ self.
+    ].
+    self breakPoint:#cg info:'possibly wrong positioning'.
+    stream position:(stream position + nrToSkip).
+!
+
 sync
     stream sync
 !