CharacterWriteStream.st
branchjv
changeset 18120 e3a375d5f6a8
parent 18066 89d51443ba6f
parent 17622 553ee52df434
child 18274 042d13555f1f
equal deleted inserted replaced
18119:cb7a12afe736 18120:e3a375d5f6a8
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 2005 by eXept Software AG
     4  COPYRIGHT (c) 2005 by eXept Software AG
     3               All Rights Reserved
     5               All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
     9  other person.  No title to or ownership of the software is
    11  other person.  No title to or ownership of the software is
    10  hereby transferred.
    12  hereby transferred.
    11 "
    13 "
    12 "{ Package: 'stx:libbasic' }"
    14 "{ Package: 'stx:libbasic' }"
    13 
    15 
       
    16 "{ NameSpace: Smalltalk }"
       
    17 
    14 WriteStream subclass:#CharacterWriteStream
    18 WriteStream subclass:#CharacterWriteStream
    15 	instanceVariableNames:'currentCharacterSize'
    19 	instanceVariableNames:'currentCharacterSize'
    16 	classVariableNames:''
    20 	classVariableNames:''
    17 	poolDictionaries:''
    21 	poolDictionaries:''
    18 	category:'Streams'
    22 	category:'Streams'
    79     super resetPosition.
    83     super resetPosition.
    80 ! !
    84 ! !
    81 
    85 
    82 !CharacterWriteStream methodsFor:'private'!
    86 !CharacterWriteStream methodsFor:'private'!
    83 
    87 
    84 characterSizeChanged:aCharacterOrString
    88 characterSizeChanged:aCharacterOrString size:additionalSize
    85     "change aCollection to fit the size of aCharacter"
    89     "change aCollection to fit the size of aCharacter"
    86 
    90 
    87     |sz newSz bitsPerCharacter|
    91     |sz newSz bitsPerCharacter|
    88 
    92 
    89     bitsPerCharacter := aCharacterOrString bitsPerCharacter. 
    93     bitsPerCharacter := aCharacterOrString bitsPerCharacter. 
    90     currentCharacterSize < bitsPerCharacter ifTrue:[
    94     currentCharacterSize < bitsPerCharacter ifTrue:[
    91         sz := collection size.
    95         sz := collection size.
    92         position >= sz ifTrue:[
    96         position + additionalSize >= sz ifTrue:[
    93             newSz := sz + 1.
    97             newSz := sz + additionalSize.
    94         ] ifFalse:[
    98         ] ifFalse:[
    95             newSz := sz.
    99             newSz := sz.
    96         ].
   100         ].
    97         collection := (aCharacterOrString stringSpecies new:newSz) 
   101         collection := (aCharacterOrString stringSpecies new:newSz) 
    98                         replaceFrom:1 to:sz with:collection startingAt:1.
   102                         replaceFrom:1 to:sz with:collection startingAt:1.
   126     "append anObject count times to the receiver.
   130     "append anObject count times to the receiver.
   127      Redefined to avoid count grows of the underlying collection -
   131      Redefined to avoid count grows of the underlying collection -
   128      instead a single grow on the final size is performed."
   132      instead a single grow on the final size is performed."
   129 
   133 
   130     aCharacter bitsPerCharacter > currentCharacterSize ifTrue:[
   134     aCharacter bitsPerCharacter > currentCharacterSize ifTrue:[
   131         self characterSizeChanged:aCharacter.
   135         self characterSizeChanged:aCharacter size:count.
   132     ].
   136     ].
   133     super next:count put:aCharacter
   137     super next:count put:aCharacter
   134 !
   138 !
   135 
   139 
   136 nextPut:aCharacter
   140 nextPut:aCharacter
   209 
   213 
   210 
   214 
   211     (writeLimit isNil
   215     (writeLimit isNil
   212      or:[(position + 1) <= writeLimit]) ifTrue:[
   216      or:[(position + 1) <= writeLimit]) ifTrue:[
   213         currentCharacterSize < aCharacter bitsPerCharacter ifTrue:[
   217         currentCharacterSize < aCharacter bitsPerCharacter ifTrue:[
   214             self characterSizeChanged:aCharacter
   218             self characterSizeChanged:aCharacter size:1.
   215         ].
   219         ].
   216         (position >= collection size) ifTrue:[self growCollection].
   220         (position >= collection size) ifTrue:[self growCollection].
   217         collection at:(position + 1) put:aCharacter.
   221         collection at:(position + 1) put:aCharacter.
   218         (position >= readLimit) ifTrue:[readLimit := (position + 1)].
   222         (position >= readLimit) ifTrue:[readLimit := (position + 1)].
   219         position := position + 1.
   223         position := position + 1.
   226 nextPutAll:aCollection
   230 nextPutAll:aCollection
   227     "append aCollection to the receiver.
   231     "append aCollection to the receiver.
   228      Redefined to convert to a string of the needed charcter size."
   232      Redefined to convert to a string of the needed charcter size."
   229 
   233 
   230     aCollection bitsPerCharacter > currentCharacterSize ifTrue:[
   234     aCollection bitsPerCharacter > currentCharacterSize ifTrue:[
   231         self characterSizeChanged:aCollection.
   235         self characterSizeChanged:aCollection size:aCollection size.
   232     ].
   236     ].
   233     super nextPutAll:aCollection
   237     super nextPutAll:aCollection
   234 !
   238 !
   235 
   239 
   236 nextPutAll:aCollection startingAt:start to:stop
   240 nextPutAll:aCollection startingAt:start to:stop
   237     aCollection bitsPerCharacter > currentCharacterSize ifTrue:[
   241     aCollection bitsPerCharacter > currentCharacterSize ifTrue:[
   238         self characterSizeChanged:aCollection.
   242         self characterSizeChanged:aCollection size:stop-start+1.
   239     ].
   243     ].
   240     ^ super nextPutAll:aCollection startingAt:start to:stop
   244     ^ super nextPutAll:aCollection startingAt:start to:stop
   241 !
   245 !
   242 
   246 
   243 nextPutAllUnicode:aCollection
   247 nextPutAllUnicode:aCollection
   249 ! !
   253 ! !
   250 
   254 
   251 !CharacterWriteStream class methodsFor:'documentation'!
   255 !CharacterWriteStream class methodsFor:'documentation'!
   252 
   256 
   253 version
   257 version
   254     ^ '$Header: /cvs/stx/stx/libbasic/CharacterWriteStream.st,v 1.12 2013-06-03 18:40:36 cg Exp $'
   258     ^ '$Header: /cvs/stx/stx/libbasic/CharacterWriteStream.st,v 1.13 2015-03-14 21:31:57 stefan Exp $'
   255 !
   259 !
   256 
   260 
   257 version_CVS
   261 version_CVS
   258     ^ '$Header: /cvs/stx/stx/libbasic/CharacterWriteStream.st,v 1.12 2013-06-03 18:40:36 cg Exp $'
   262     ^ '$Header: /cvs/stx/stx/libbasic/CharacterWriteStream.st,v 1.13 2015-03-14 21:31:57 stefan Exp $'
   259 ! !
   263 ! !
   260 
   264