|
Class: CharacterWriteStream
Object
|
+--Stream
|
+--PeekableStream
|
+--PositionableStream
|
+--WriteStream
|
+--CharacterWriteStream
|
+--TextStream
- Package:
- stx:libbasic
- Category:
- Streams
- Version:
- rev:
1.34
date: 2021/11/27 13:54:26
- user: cg
- file: CharacterWriteStream.st directory: libbasic
- module: stx stc-classLibrary: libbasic
This is a WriteStream, which automagically changes the underlying collection,
if a character does not fit into the current collection
(i.e. String -> Unicode16String -> Unicode32String )
This means, that any character can be written to instances of me,
not just single-byte chars, as would be the case for a basic String-stream.
Strings readefine the writeStreamClass query, to return me,
so '' writeStream will automatically return the correct type of stream.
[instance variables:]
[class variables:]
copyrightCOPYRIGHT (c) 2004 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
instance creation
-
new
-
I know, that I operate on strings
-
new: count
-
I know, that I operate on strings
accessing
-
reset
-
reset the stream, to write again over the existing (or already written) contents.
See the comment in WriteStream>>contents
private
-
characterSizeChangedTo: newCharacterSize size: additionalSize
-
change aCollection to fit the size of newCharacterSize
private-accessing
-
on: aCollection
-
return a stream for writing into aCollection
-
on: aCollection from: start to: stop
-
return a stream for writing into part of aCollection.
This will position the stream to start writing at start-index,
and setup a writeLimit at stop-index.
Contents after stop-index will not be overwritten.
-
with: aCollection
-
return a stream for writing into aCollection.
This will position the stream to the end, and append written elements
after the initial contents.
I.e. the effect is similar to creating an empty stream first and then write
aCollection.
Usage example(s):
|s|
s := CharacterWriteStream with:'hello'.
s nextPutAll:'1234567890'.
s contents
|
writing
-
next: count put: aCharacter
-
append anObject count times to the receiver.
Redefined to avoid count grows of the underlying collection -
instead a single grow on the final size is performed.
-
nextPut: aCharacter
-
append the argument, aCharacter to the stream.
Answer aCharacter.
Specially tuned for appending to String, Unicode16String and Unicode32String streams.
-
nextPutAll: aCollection
-
append aCollection to the receiver.
Answer the receiver.
Redefined to convert to a string of the needed character size.
-
nextPutAll: aCollection startingAt: start to: stop
-
append the elements from first index to last index
of the argument, aCollection onto the receiver (i.e. both outstreams)
-
nextPutAllUnicode: aCollection
-
(comment from inherited method)
normal streams can not handle multi-byte characters, so convert them to utf8
-
nextPutUnicode: aCharacter
-
(comment from inherited method)
normal streams can not handle multi-byte characters, so convert them to utf8
explicit:
|stream|
stream := CharacterWriteStream on:(String new:32).
stream nextPutAll:'abc'.
stream nextPut:(Character value:16r2c00).
stream contents inspect
| no need to know:
|stream|
stream := String writeStream.
stream nextPutAll:'abc'.
stream nextPut:(Character value:16r2c00).
stream contents inspect
| no need to know:
(String streamContents:[:s |
s nextPutAll:'abc'.
s nextPut:(Character value:16r2c00).
]) inspect
|
|