PeekableStream.st
author james
Thu, 25 Oct 2001 08:04:22 +0200
changeset 6102 7fdf73f3256b
parent 5394 f877659e09f7
child 7685 535a69a7cd69
permissions -rw-r--r--
initial checkin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     1
"
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
379
5b5a130ccd09 revision added
claus
parents: 369
diff changeset
     3
	      All Rights Reserved
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     4
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    11
"
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    12
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    13
"{ Package: 'stx:libbasic' }"
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    14
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    15
Stream subclass:#PeekableStream
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    16
	instanceVariableNames:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    17
	classVariableNames:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    18
	poolDictionaries:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    19
	category:'Streams'
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    20
!
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    22
!PeekableStream class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
 COPYRIGHT (c) 1994 by Claus Gittinger
379
5b5a130ccd09 revision added
claus
parents: 369
diff changeset
    27
	      All Rights Reserved
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
!
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    37
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
    abstract superclass for all Stream which support read-ahead
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
    (i.e. peeking) of one element.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
    Concrete subclasses must implement a peek method.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    43
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    44
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    45
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    46
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    47
! !
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
    48
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    49
!PeekableStream methodsFor:'chunk input/output'!
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    50
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    51
nextChunk
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    52
    "return the next chunk, i.e. all characters up to the next
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    53
     exclamation mark. Within the chunk, exclamation marks have to be doubled,
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    54
     they are undoubled here.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    55
     Except for primitive code, in which doubling is not needed (allowed).
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    56
     This exception was added to make it easier to edit primitive code with 
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    57
     external editors. However, this means, that other Smalltalks cannot always 
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    58
     read chunks containing primitive code 
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    59
     - but that doesnt really matter, since C-primitives are an ST/X feature anyway."
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    60
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    61
    |theString sep newString done thisChar nextChar inPrimitive
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    62
     index    "{ Class:SmallInteger }"
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    63
     currSize "{ Class:SmallInteger }" |
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    64
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    65
    sep := ChunkSeparator.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    66
    theString := String new:500.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    67
    currSize := 500.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    68
    thisChar := self skipSeparators.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    69
    thisChar := self next.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    70
    index := 0.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    71
    done := false.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    72
    inPrimitive := false.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    73
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    74
    [done] whileFalse:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    75
	((index + 2) <= currSize) ifFalse:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    76
	    newString := String new:(currSize * 2).
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    77
	    newString replaceFrom:1 to:currSize with:theString.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    78
	    currSize := currSize * 2.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    79
	    theString := newString
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    80
	].
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    81
	thisChar isNil ifTrue:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    82
	    done := true
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    83
	] ifFalse:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    84
	    (thisChar == $% ) ifTrue:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    85
		nextChar := self peek.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    86
		(nextChar == ${ ) ifTrue:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    87
		    inPrimitive := true.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    88
		    index := index + 1.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    89
		    theString at:index put:thisChar.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    90
		    thisChar := self next
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    91
		] ifFalse:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    92
		    (nextChar == $} ) ifTrue:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    93
			inPrimitive := false.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    94
			index := index + 1.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    95
			theString at:index put:thisChar.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    96
			thisChar := self next
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    97
		    ]
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    98
		]
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
    99
	    ] ifFalse:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   100
		inPrimitive ifFalse:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   101
		    (thisChar == sep) ifTrue:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   102
			(self peek == sep) ifFalse:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   103
			    done := true
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   104
			] ifTrue:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   105
			    self next
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   106
			]
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   107
		    ]
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   108
		]
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   109
	    ]
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   110
	].
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   111
	done ifFalse:[
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   112
	    index := index + 1.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   113
	    theString at:index put:thisChar.
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   114
	    thisChar := self next
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   115
	]
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   116
    ].
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   117
    (index == 0) ifTrue:[^ ''].
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   118
    ^ theString copyTo:index
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   119
! !
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   120
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   121
!PeekableStream methodsFor:'positioning'!
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
   122
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   123
skipAny:skipCollection
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   124
    "skip all characters included in the argument-set.
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   125
     returns the next peeked element or nil, if the end-of-stream was reached."
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   126
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   127
    |nextOne|
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   128
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   129
    nextOne := self peekOrNil.
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   130
    [nextOne notNil and:[skipCollection includes:nextOne]] whileTrue:[
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   131
        self next.
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   132
        nextOne := self peekOrNil
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   133
    ].
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   134
    ^ nextOne
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   135
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   136
    "
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   137
     |s skipChars|
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   138
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   139
     s := ReadStream on:'some numbers1234with\in other99 stuff' withCRs.
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   140
     skipChars := 'abcdefghijklmnopqrstuvwxyz\ ' withCRs.
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   141
     s skipAny:skipChars.
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   142
     Transcript showCR:(Integer readFrom:s).
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   143
     s skipAny:skipChars.
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   144
     Transcript showCR:(Integer readFrom:s).
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   145
    "
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   146
!
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   147
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   148
skipSeparators
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   149
    "skip all whitespace; returns the next peeked element or
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   150
     nil, if the end-of-stream was reached.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   151
     The streams elements should be characters.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   152
     Notice: compare this method to skipSpaces"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   153
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   154
    |nextOne|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   155
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   156
    nextOne := self peekOrNil.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   157
    [nextOne notNil and:[nextOne isSeparator]] whileTrue:[
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   158
        self next.
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   159
        nextOne := self peekOrNil
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   160
    ].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   161
    ^ nextOne
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   162
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   163
    "
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   164
     |s|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   165
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   166
     s := ReadStream on:'one      two\three' withCRs.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   167
     s skipSeparators.
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   168
     Transcript showCR:(s nextWord).
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   169
     s skipSeparators.
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   170
     Transcript showCR:(s nextWord).
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   171
     s skipSeparators.
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   172
     Transcript showCR:(s next displayString).
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   173
    "
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   174
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   175
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   176
skipSeparatorsExceptCR
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   177
    "skip all whitespace except carriage return; returns the 
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   178
     next peeked element or nil, if the end-of-stream was reached.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   179
     The streams elements should be characters.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   180
     Notice: compare this method to skipSpaces and skipSeparators"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   181
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   182
    |nextOne|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   183
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   184
    nextOne := self peekOrNil.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   185
    [nextOne notNil 
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   186
     and:[nextOne isSeparator
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   187
     and:[nextOne ~~ Character cr]]] whileTrue:[
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   188
        self next.
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   189
        nextOne := self peekOrNil
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   190
    ].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   191
    ^ nextOne
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   192
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   193
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   194
skipSpaces
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   195
    "skip all spaces; returns the next peeked element or
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   196
     nil, if the end-of-stream was reached.
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   197
     The streams elements should be characters.
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   198
     Notice: this one skips only spaces (i.e. no cr, tabs etc)
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   199
             usually, skipSeparators is what you want."
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   200
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   201
    |nextOne|
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   202
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   203
    nextOne := self peekOrNil.
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   204
    [nextOne notNil and:[nextOne == Character space]] whileTrue:[
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   205
        self next.
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   206
        nextOne := self peekOrNil
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   207
    ].
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   208
    ^ nextOne
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   209
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   210
    "
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   211
     |s|
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   212
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   213
     s := ReadStream on:'one      two\three' withCRs.
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   214
     s skipSpaces.
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   215
     Transcript showCR:(s nextWord).
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   216
     s skipSpaces.
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   217
     Transcript showCR:(s nextWord).
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   218
     s skipSpaces.
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   219
     Transcript showCR:(s next displayString).
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   220
    "
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   221
! !
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   222
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   223
!PeekableStream methodsFor:'reading'!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   224
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   225
nextDecimalInteger
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   226
    "read the next integer in radix 10. Does NOT skip initial whitespace.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   227
     The streams elements should be characters.
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   228
     Be careful - this method returns 0 if not posiioned on a digit intitially
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   229
     or if the end of the stream is encountered."
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   230
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   231
    |nextOne value|
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   232
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   233
    nextOne := self peekOrNil.
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   234
    value := 0.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   235
    [nextOne notNil and:[nextOne isDigitRadix:10]] whileTrue:[
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   236
        value := (value * 10) + nextOne digitValue.
4432
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   237
        self next.
5267a659f8d9 avoid raising pastEnd exceptions in skip-methods
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   238
        nextOne := self peekOrNil
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   239
    ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   240
    ^ value
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   241
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   242
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   243
     |s|
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   244
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   245
     s := '1234 5678' readStream.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   246
     s nextDecimalInteger. 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   247
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   248
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   249
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   250
     |s|
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   251
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   252
     s := '1234 5678' readStream.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   253
     s nextDecimalInteger.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   254
     s skipSpaces.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   255
     s nextDecimalInteger. 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   256
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   257
!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   258
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   259
nextDelimited:terminator
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   260
    "return the contents of the receiver, up to the next terminator character. 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   261
     Doubled terminators indicate an embedded terminator character.  
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   262
     For example: 'this '' was a quote'. 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   263
     Start postioned before the initial terminator."
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   264
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   265
    | out ch |
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   266
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   267
    out := WriteStream on: (String new: 1000).
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   268
    self atEnd ifTrue: [^ ''].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   269
    self next == terminator ifFalse: [self skip: -1].       "absorb initial terminator"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   270
    [(ch := self next) == nil] whileFalse: [
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   271
        (ch == terminator) ifTrue: [
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   272
            self peek == terminator ifFalse: [
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   273
                ^ out contents  "terminator is not doubled; we're done!!"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   274
            ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   275
            self next.  "skip doubled terminator"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   276
        ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   277
        out nextPut: ch.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   278
    ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   279
    ^ out contents
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   280
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   281
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   282
     ('*foo bar baz* more foo' readStream nextDelimited:$*) 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   283
     ('*foo bar **baz***' readStream nextDelimited:$*)   
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   284
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   285
!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   286
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   287
nextPeek
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   288
    "advance to next element and return the peeked element"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   289
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   290
    self next.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   291
    ^ self peek
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   292
!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   293
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   294
peek 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   295
    "return the next element of the stream without advancing (i.e.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   296
     the following send of next will return this element again.)
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   297
     - we do not know here how to do it, it must be redefined in subclass"
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   298
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   299
    ^ self subclassResponsibility
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   300
!
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   301
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   302
peekFor:anObject 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   303
    "if the next-to-be-read object is equal to the argument, anObject, read it
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   304
     and return true. Otherwise, leave the receiver unaffected and return false."
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   305
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   306
    self peek = anObject ifTrue:[
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   307
	self next.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   308
	^ true
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   309
    ].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   310
    ^ false
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   311
!
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   312
2419
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   313
upToMatching:aBlock
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   314
    "Return the next elements up to but not including the next element
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   315
     for which aBlock returns true.
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   316
     The next read will return that matching element."
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   317
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   318
    |answerStream element|
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   319
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   320
    answerStream := WriteStream on:(self contentsSpecies new).
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   321
    [self atEnd] whileFalse: [
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   322
        element := self peek.
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   323
        (aBlock value:element) ifTrue: [^ answerStream contents].
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   324
        answerStream nextPut:element.
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   325
        self next.
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   326
    ].
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   327
    ^ answerStream contents
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   328
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   329
    "
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   330
     'hello world' readStream upToMatching:[:c | c isSeparator].
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   331
    "
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   332
    "
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   333
     |s|
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   334
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   335
     s := 'hello world' readStream.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   336
     s upToMatching:[:c | c isSeparator].
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   337
     s upToEnd
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   338
    "
2419
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   339
2421
0b8966d99a87 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2419
diff changeset
   340
    "Modified: 26.2.1997 / 12:20:57 / cg"
2419
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   341
!
13804903a785 added #upToMatching:
Claus Gittinger <cg@exept.de>
parents: 2060
diff changeset
   342
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   343
upToSeparator
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   344
    "Return the next elements up to but not including the next separator.
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   345
     The next read will return the separator.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   346
     If no separator is encountered, the contents up to the end is returned.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   347
     The elements are supposed to understand #isSeparator 
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   348
     (i.e. the receiver is supposed to be a character-stream)."
68
59faa75185ba *** empty log message ***
claus
parents: 58
diff changeset
   349
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   350
    ^ self upToMatching:[:ch | ch isSeparator]
2060
4f93a792ba9d commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   351
4f93a792ba9d commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   352
    "
4404
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   353
     'hello world' readStream upToSeparator  
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   354
     'helloworld' readStream upToSeparator   
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   355
     'helloworld' readStream upToSeparator   
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   356
     '' readStream upToSeparator   
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   357
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   358
     |s|
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   359
     s := 'hello world' readStream.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   360
     s upToSeparator.
417e6668f732 added #nextDelimited:
Claus Gittinger <cg@exept.de>
parents: 2421
diff changeset
   361
     s upToEnd  
2060
4f93a792ba9d commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   362
    "
4f93a792ba9d commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   363
4f93a792ba9d commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   364
    "Modified: 4.1.1997 / 23:38:05 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   365
! !
58
b5453a2ff4aa Initial revision
claus
parents:
diff changeset
   366
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   367
!PeekableStream class methodsFor:'documentation'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   368
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   369
version
5394
f877659e09f7 got nextChunk from subclass
Claus Gittinger <cg@exept.de>
parents: 4432
diff changeset
   370
    ^ '$Header: /cvs/stx/stx/libbasic/PeekableStream.st,v 1.21 2000-05-22 11:11:09 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   371
! !