UnicodeReadWriteStream
Description
This is an adapter class used for bridging <UnicodeView>s with <ReadWriteStream>s. By default, this streams 'graphemes' which are user-perceived characters. A grapheme is represented in VAST by a <Grapheme> object.
Instance State
Class Methods
<details> on:
Answer a new instance of the receiver, streaming over argument
aUnicodeString.
Arguments:
aUnicodeString - <UnicodeString>
Answers:
<UnicodeReadWriteStream>
</details>
Instance Methods
<details> asStream
</details>
<details> contents
Answer a Collection which is a copy collection that the receiver is
streaming over, truncated to the current position reference.
Example:
| stream |
stream := UnicodeReadWriteStream on: UnicodeString new.
stream nextPutAll: 'Smalltalk'.
self assert: [stream contents = 'Smalltalk']
Answers:
<UnicodeString>
</details>
<details> next
<pre><code> Answer an Object that is the next accessible by the receiver. Change the state of the receiver so that returned object is no longer accessible.
Example: self assert: [('Smalltalk' asUnicodeString readStream next; next; next) = $a asGrapheme]. self assert: [('Smalltalk' asUnicodeString readStream switchToUnicodeScalarMode; next; next; next) = $a asUnicodeScalar]. Answers: <Object> view object </code></pre> </details>
<details> next:
<pre><code> Answer a collection containing the next @anInteger elements from the view. If @anInteger < 1, an empty collection is answered
Example: self assert: [('Smalltalk' asUnicodeString readStream next: 5) = 'Small']. self assert: [| stream | stream := 'Smalltalk' asUnicodeString readStream. (stream switchToUnicodeScalarMode; next: 5) = 'Small' unicodeScalars contents] Arguments: anInteger - <Integer> Answers: <Object> instance of view collection class Raises: <Exception> ExCLDTIndexOutOfRange </code></pre> </details>
<details> next:into:startingAt:
<pre><code> Answer @anIndexedCollection with the next @anInteger number of items from the receiver, stored starting at position @initialPosition.
If the receiver's state is such that there are fewer than anInteger elements between its current position and the end of the stream, the operation will fail, and the receiver will be left in a state such that it answers true to the atEnd message.
Example: | col | col := Array new: 5. 'Smalltalk' asUnicodeString readStream next: 5 into: col startingAt: 1. self assert: [col = 'Small' asUnicodeString asArray] Arguments: anInteger - <Integer> anIndexedCollection - <Collection> initialPosition - <Integer> Answers: <Collection> - anIndexedCollection </code></pre> </details>
<details> nextLine
<pre><code> Answer the elements between the current position and the next lineDelimiter.
Example: | stream | stream := ('Small' , String lf , 'talk' , String cr , 'er' , String crlf , 's') asUnicodeString readStream. self assert: [stream nextLine = 'Small']. self assert: [stream nextLine = 'talk']. self assert: [stream nextLine = 'er']. self assert: [stream nextLine = 's']. stream switchToUnicodeScalarMode. self assert: [stream nextLine = 'Small' unicodeScalars contents]. self assert: [stream nextLine = 'talk' unicodeScalars contents]. self assert: [stream nextLine = 'er' unicodeScalars contents]. self assert: [stream nextLine = 's' unicodeScalars contents]. self assert: stream atEnd. Answers: <Object> view-dependent </code></pre> </details>
<details> nextPut:
Store the argument anObject at the next position
accessible to the receiver. Answer anObject. Change the
state of the receiver so that the argument anObject is no
longer accessible.
This sets the 'refreshView' flag so we are sure to update
the view on a subsequent read.
Example:
self assert: [((UnicodeReadWriteStream on: UnicodeString new)
nextPut: $S;
nextPut: $T;
position: 0;
upToEnd) = 'ST']
Arguments:
anObject - <Object> @see implementors of #asGrapheme
Answers:
<Grapheme> anObject converted to Grapheme
</details>
<details> nextPutAll:
<pre><code> Store each of the elements of aCollection starting at the current position accessible to the receiver. Answer aCollection. Change the state of the receiver so that the objects contained with aCollection are no longer accessible.
This sets the 'refreshView' flag so we are sure to update the view on a subsequent read.
Example: self assert: [((UnicodeString new writeStream) nextPutAll: 'Smalltalk' asUnicodeString; position: 0; upToEnd) = 'Smalltalk'] Arguments: aCollection - <Object> @see implementors of #asUnicodeString Answers: <UnicodeString> aCollection converted to UnicodeString </code></pre> </details>
<details> peek
Answer an Object that is the next accessible by the receiver.
Change the state of the receiver so that returned object is no longer accessible.
Answer nil if the view is atEnd
Example:
self assert: [('' asUnicodeString readStream peek) isNil].
self assert: [('Smalltalk' asUnicodeString readStream peek) = $S asGrapheme].
self assert: [('Smalltalk' asUnicodeString readStream switchToUnicodeScalarMode; peek) = $S asUnicodeScalar].
Answers:
<Object> or nil if at end
</details>
<details> position:
Set the receiver's position reference to argument anInteger.
Arguments:
anInteger - <Integer>
Answers:
<UnicodeWriteStream> receiver
Raises:
<Exception> ExCLDTIndexOutOfRange if anInteger is out of range
</details>
<details> skip:
<pre><code> Increment the receiver's current reference position by anInteger. Fail if anInteger is not a kind of Integer.
Example: self assert: [('abcde' asUnicodeString readStream skip: 2; upToEnd) = 'cde'] Arguments: anInteger - <Integer> Raises: <Exception> ExCLDTIndexOutOfRange </code></pre> </details>
<details> skipTo:
<pre><code> Read and discard elements just past the occurrence of @anObject.
Example: self assert: [('abcde' asUnicodeString readStream skipTo: $c; upToEnd) = 'de']. self assert: [('abcde' asUnicodeString readStream skipTo: $z; upToEnd) = ''] Arguments: anObject - <Object> Answers: <Boolean> true if found, false otherwise </code></pre> </details>
<details> skipToAll:
<pre><code> Attempt to read and discard elements just past the occurrence of @aSequentialCollection. Answer true if all elements in @aSequentialCollection occurred, else answer false.
Note: If aSequentialCollection is an EsString, then we attempt ot convert to a UnicodeString
Example: self assert: ['abcde' asUnicodeString readStream skipToAll: 'bc']. self assert: [('abcde' asUnicodeString readStream skipToAll: 'bc'; upToEnd) = 'de']. self assert: [('abcde' asUnicodeString readStream skipToAll: 'zzz') not]. self assert: [('abcde' asUnicodeString readStream skipToAll: 'zzz'; upToEnd) = '']. Arguments: aSequentialCollection - <aSequentialCollection> Answers: <Boolean> </code></pre> </details>
<details> skipToAny:
<pre><code> Read and discard elements beyond the next occurrence of an element that exists in @aSequentialCollection or if none, to the end of stream.
Answer true if an element in @aSequentialCollection occurred, else answer false.
Note: If aSequentialCollection is an EsString, then we attempt ot convert to a UnicodeString
Example: self assert: ['abcde' asUnicodeString readStream skipToAny: 'bd']. self assert: [('abcde' asUnicodeString readStream skipToAny: 'bd'; upToEnd) = 'cde']. self assert: [('abcde' asUnicodeString readStream skipToAny: 'zzz') not]. self assert: [('abcde' asUnicodeString readStream skipToAny: 'zzz'; upToEnd) = '']. Arguments: aSequentialCollection - <aSequentialCollection> Answers: <Boolean> </code></pre> </details>
<details> truncate
Set the size of the receiver stream to its current position.
Example:
| stream |
stream := ReadWriteStream on: UnicodeString new.
stream nextPutAll: 'Smalltalk'.
self assert: [stream contents = 'Smalltalk'].
stream position: 5.
self assert: [stream contents = 'Smalltalk'].
stream truncate.
self assert: [stream contents = 'Small'].
</details>
<details> upTo:
<pre><code> Answers a collection of all of the objects in the view beginning from the current position up to, but not including, @anObject.
Example: self assert: [('abcde' asUnicodeString readStream upTo: $c) = 'ab']. self assert: [('abcde' asUnicodeString readStream upTo: $z) = 'abcde'] Arguments: anObject - <Object> Answers: <Object> instance of view collection class </code></pre> </details>
<details> upToAll:
<pre><code> Answers a collection of all of the objects in the view beginning from the current position up to, but not including, @aSequenceableCollection
Note: If aSequenceableCollection is an EsString, then we attempt ot convert to a UnicodeString
Example: self assert: [('abcde' asUnicodeString readStream upToAll: 'bc') = 'a']. self assert: [('abcde' asUnicodeString readStream upToAll: 'bc'; upToEnd) = 'de']. self assert: [('abcde' asUnicodeString readStream upToAll: 'zzz') = 'abcde']. self assert: [('abcde' asUnicodeString readStream upToAll: 'zzz'; upToEnd) isEmpty]. Arguments: aSequenceableCollection - <SequenceableCollection> Answers: <Object> instance of view collection class </code></pre> </details>
<details> upToAny:
<pre><code> Answers a collection of all of the objects in the view up to, but not including, the next occurrence of the element that exists in @aSequenceableCollection. If the element that exists in @aSequenceableCollection is not found and the end of the view is encountered, a collection of the objects read is returned.
Note: If aSequenceableCollection is an EsString, then we attempt ot convert to a UnicodeString
Example: self assert: [('abcde' asUnicodeString readStream upToAny: 'bd') = 'a']. self assert: [('abcde' asUnicodeString readStream upToAny: 'bd'; upToEnd) = 'cde']. self assert: [('abcde' asUnicodeString readStream upToAny: 'zzz') = 'abcde']. self assert: [('abcde' asUnicodeString readStream upToAny: 'zzz'; upToEnd) isEmpty]. Arguments: aSequenceableCollection - <SequenceableCollection> Answers: <Object> view collection class </code></pre> </details>
<details> upToEnd
<pre><code> Answer a collection containing UP TO the maximum number of elements read from the view. If there are no more elements available to be read, then an empty collection is answered.
Example: self assert: ['abcde' asUnicodeString readStream upToEnd = 'abcde']. self assert: [('abcde' asUnicodeString readStream next: 2; upToEnd) = 'cde']. self assert: ['' asUnicodeString readStream upToEnd = ''] Answers: <Object> instance of view collection class </code></pre> </details>