UnicodeWriteStream
Description
This is an adapter class used for bridging <UnicodeView>s with <WriteStream>s.
This stream produces a <UnicodeString> as its contents.
Instance State
CLDT-API
This adapter redefines the necessary <WriteStream> (and superclass) APIs to allow for efficient streaming of a <UnicodeString>.
Input to be appended using #nextPut: will be internally converted to <Grapheme>s.
| stream |
stream := UnicodeString new writeStream.
stream
nextPut: $a value;
nextPut: $a;
nextPut: { $a value };
nextPut: $a asUnicodeScalar;
nextPut: $a asGrapheme.
self assert: [stream contents = 'aaaaa']
Input to be appended using #nextPutAll: will be internally converted to <UnicodeString>s.
| stream |
stream := UnicodeString new writeStream.
stream
nextPutAll: 'Small';
nextPutAll: 'talk' asUnicodeString.
self assert: [stream contents = 'Smalltalk']
Its important to remember that <Grapheme>s can combine when next to each other. For example, if Grapheme cr and Grapheme lf are added one after the other into a <UnicodeString>, then they will combine into the single Grapheme crlf. The total size of this <UnicodeString> is 1 not 2.
| stream |
stream := UnicodeString new writeStream.
stream
nextPutAll: String cr;
nextPutAll: String lf.
"The cr and lf combined to form the user-perceived character 'crlf'.
This behavior is defined in Unicode Standard Annex #29"
self assert: [stream size = 1].
self assert: [stream contents = UnicodeString crlf].
Class Methods
None
Instance Methods
<details> lineDelimiter
Return the receiver's line delimiter.
Answers:
<Object>
</details>
<details> lineDelimiter:
Set the receiver's line delimiter to be delimiter, and
answer the receiver.
Example:
| stream |
stream := UnicodeString new writeStream.
stream lineDelimiter: Grapheme cr.
stream cr.
stream lineDelimiter: Grapheme lf.
stream cr.
self assert: [stream contents = UnicodeString crlf].
self assert: [stream contents first = Grapheme crlf]
Arguments:
delimiter - <Grapheme> grapheme delim
<UnicodeScalar> scalar delim
<UnicodeString> graphemes
<Array> of <Grapheme>
Compat: <String | Character>
Answers:
<UnicodeWriteStream> self
</details>
<details> newLine
Store the lineDelimiter (CR, LF, CRLF or any custom one) as the next object in the
receiver. Answer self. Set the receiver's position reference to
be immediately after the lineDelimiter characters.
Example:
| stream |
stream := UnicodeString new writeStream.
stream lineDelimiter: Grapheme cr.
stream newLine; newLine.
self assert: [stream contents = (UnicodeString with: Grapheme cr with: Grapheme cr)]
Answers:
<UnicodeWriteStream> receiver
</details>
<details> next:put:
<pre><code> Store argument anObject into the next anInteger elements accessible to the receiver. Answer anObject. Change the state of the receiver so that the anInteger elements of anObject are not accessible. If anInteger < 1, then do not store any instances of anObject.
Fail if anInteger is not a kind of Integer.
Example: | stream | stream := UnicodeString new writeStream. stream next: 10 put: $a asGrapheme. self assert: [stream contents = (UnicodeString new: 10 withAll: $a asGrapheme)]
Arguments: anInteger - <Integer> anObject - <Object> Answers: <Object> </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.
Example:
self assert: [((UnicodeString new writeStream)
nextPut: $a value;
nextPut: $a;
nextPut: { $a value };
nextPut: $a asUnicodeScalar;
nextPut: $a asGrapheme;
contents) = 'aaaaa']
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.
Example: self assert: [((UnicodeString new writeStream) nextPutAll: 'Smalltalk' asUnicodeString; space; nextPutAll: 'Smalltalk'; space; nextPutAll: 'Smalltalk' asByteArray; contents) = 'Smalltalk Smalltalk Smalltalk'] Arguments: aCollection - <Object> @see implementors of #asUnicodeString Answers: <UnicodeString> aCollection converted to UnicodeString </code></pre> </details>
Last modified date: 01/18/2023