EncodedStream.st
author Stefan Vogel <sv@exept.de>
Fri, 12 Jan 2007 14:37:02 +0100
changeset 10312 7f71d47b09bd
parent 8712 bcef3a0c0a1d
child 11766 b26aac1e4eb1
permissions -rw-r--r--
#additionalTargets_bc_dot_mak for applications

"
 COPYRIGHT (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.
"

"{ Package: 'stx:libbasic' }"

PeekableStream subclass:#EncodedStream
	instanceVariableNames:'encoder stream'
	classVariableNames:''
	poolDictionaries:''
	category:'Collections-Text-Encodings'
!

!EncodedStream class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (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.
"
! !

!EncodedStream class methodsFor:'instance creation'!

stream:streamArg encoder:encoder
    ^ (self basicNew) stream:streamArg; encoder:encoder
! !

!EncodedStream methodsFor:'accessing'!

encoder
    ^ encoder
!

encoder:something
    encoder := something.
!

stream
    ^ stream
!

stream:something
    stream := something.
! !

!EncodedStream methodsFor:'stream protocol'!

atEnd
    ^ stream atEnd
!

close
    stream close
!

cr
    self nextPutAll:(Character cr asString)
!

nextChunk
    |chunk|

    chunk := stream nextChunk.
    chunk isNil ifTrue:[^ chunk].
    ^ encoder decodeString:chunk
!

nextChunkPut:chunk
    stream nextChunkPut:(encoder encodeString:chunk)
!

nextPut:aCharacter
    self nextPutAll:(aCharacter asString).
!

nextPutAll:aCollection
    stream nextPutAll:(encoder encodeString:aCollection).
!

peek
    ^ stream peek
!

peekFor:aCharacter
    ^ stream peekFor:aCharacter
!

position
    ^ stream position
!

position0Based
    ^ stream position0Based
!

position0Based:newPosition
    stream position0Based:newPosition
!

position1Based
    ^ stream position1Based
!

position1Based:newPosition
    stream position1Based:newPosition
!

position:newPosition
    stream position:newPosition
!

setToEnd
    stream setToEnd
!

skipSeparators
    ^ stream skipSeparators
! !

!EncodedStream methodsFor:'utilities'!

skipEncodingChunk
    |pos chunk tree|

    pos := self position.
    chunk := self nextChunk.
    tree := (Parser parseExpression:chunk).
    "/ if this is a valid chunk (i.e. not a comment or encoding-directive),
    "/ then position back, so it will be processed as usual.
    tree notNil ifTrue:[
        self position:pos
    ]
! !

!EncodedStream class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/EncodedStream.st,v 1.11 2005-01-26 17:11:54 cg Exp $'
! !