Fix #skipToAll: (partial match at end of stream
authorStefan Vogel <sv@exept.de>
Wed, 24 Jan 2007 17:22:41 +0100
changeset 10357 66543e405aa4
parent 10356 6f32850bdc81
child 10358 5a679e45aeaa
Fix #skipToAll: (partial match at end of stream Speed up #skipThroughAll:
PositionableStream.st
--- a/PositionableStream.st	Wed Jan 24 17:20:55 2007 +0100
+++ b/PositionableStream.st	Wed Jan 24 17:22:41 2007 +0100
@@ -9,7 +9,6 @@
  other person.  No title to or ownership of the software is
  hereby transferred.
 "
-
 "{ Package: 'stx:libbasic' }"
 
 PeekableStream subclass:#PositionableStream
@@ -370,17 +369,20 @@
         buffer = aCollection ifTrue:[
             ^ self
         ].
-        idx := buffer indexOf:first startingAt:2.
-        idx == 0 ifFalse:[
-            self position:(self position - len + idx - 1)
-        ]
+        buffer size == len ifTrue:[
+            "expect more input"
+            idx := buffer indexOf:first startingAt:2.
+            idx == 0 ifFalse:[
+                self position:(self position - len + idx - 1)
+            ].
+        ].
     ].
     ^ nil
 
     "
      |s|
-     s := ReadStream on:'12345678901234567890'.
-     s skipThroughAll:'901'.
+     s := ReadStream on:'12345678901234567890a'.
+     s skipThroughAll:'90ab'.
      s upToEnd  
     "
     "
@@ -411,15 +413,18 @@
     len := aCollection size.
     first := aCollection at:1.
     [self atEnd] whileFalse:[
-        buffer := self next:len.
+        buffer := self nextAvailable:len.
         buffer = aCollection ifTrue:[
             self position:(self position - len).
             ^ self
         ].
-        idx := buffer indexOf:first startingAt:2.
-        idx == 0 ifFalse:[
-            self position:(self position - len + idx - 1)
-        ]
+        buffer size == len ifTrue:[
+            "more input can be expected"
+            idx := buffer indexOf:first startingAt:2.
+            idx == 0 ifFalse:[
+                self position:(self position - len + idx - 1)
+            ].
+        ].
     ].
     self position:oldPos.
     ^ nil
@@ -431,10 +436,40 @@
      s upToEnd  
     "
 
+    "
+     |s|
+     s := ReadStream on:'1234567890'.
+     s skipToAll:'901'.
+     s upToEnd  
+    "
+
+    "
+     |s|
+     s := 'Makefile' asFilename readStream.
+     [
+         (s skipToAll:'EDIT') notNil ifTrue:[
+            s next:100.
+         ].
+     ] ensure:[
+        s close.
+     ]
+    "
+
     "Modified: 26.6.1996 / 09:28:27 / cg"
     "Created: 26.6.1996 / 09:35:06 / cg"
 ! !
 
+!PositionableStream methodsFor:'printing & storing'!
+
+printOn:aStream
+    aStream nextPutAll:self className; nextPutAll:'(on:'; nextPutAll:collection classNameWithArticle; nextPut:$)
+
+    "
+      '' readStream printString
+      '' writeStream printString
+    "
+! !
+
 !PositionableStream methodsFor:'private'!
 
 contentsSpecies
@@ -590,7 +625,7 @@
 !PositionableStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.148 2006-09-21 15:42:44 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.149 2007-01-24 16:22:41 stefan Exp $'
 ! !
 
 PositionableStream initialize!