Programmer Reference : UnicodeSupport : UnicodeWriteStream
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
view: <UnicodeView>
trimToPosition: <Boolean>
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
lineDelimiter
   Return the receiver's line delimiter.
   
   Answers:
    <Object>
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
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
next:put:
   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>
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
nextPutAll:
   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
Last modified date: 01/18/2023