IndentStream.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5373 9a516ecec5d5
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:

"{ Encoding: utf8 }"

"
 COPYRIGHT (c) 2018 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:libbasic2' }"

"{ NameSpace: Smalltalk }"

WriteStream subclass:#IndentStream
	instanceVariableNames:'indentLevel indentString'
	classVariableNames:''
	poolDictionaries:''
	category:'Streams-Misc'
!

!IndentStream class methodsFor:'documentation'!

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

documentation
"
    a write stream which keeps a current indent and
    automatically emits the indent on every cr.

    [author:]
        Claus Gittinger (ported from Squeak)
"
! !

!IndentStream class methodsFor:'instance creation'!

on: aCollection

	^(super on: aCollection) initialize
!

with: aCollection

	^(super with: aCollection) initialize
! !

!IndentStream methodsFor:'accessing'!

indentLevel
    "the current indent"
    
    ^indentLevel

    "Modified (comment): / 01-07-2018 / 10:16:32 / Claus Gittinger"
!

indentString:aString
    "the string to use for indentation.
     If left unset, a tab is used"
     
    indentString := aString

    "Created: / 01-07-2018 / 10:16:17 / Claus Gittinger"
! !

!IndentStream methodsFor:'indentation'!

indent

	self tab.
	indentLevel := indentLevel + 1.
!

indentBack

	indentLevel := indentLevel - 1.
! !

!IndentStream methodsFor:'initialization'!

initialize

	super initialize.
	indentLevel := 0.
! !

!IndentStream methodsFor:'writing'!

cr

        super cr.
        self putIndent.

    "Modified: / 01-07-2018 / 10:13:45 / Claus Gittinger"
!

crtab

	self cr.
	self indent.
!

putIndent
    indentString notNil ifTrue:[
        indentLevel timesRepeat:[
            self nextPutAll:indentString
        ].
        ^ self.
    ].
    "/ original
    self tab: self indentLevel.

    "Created: / 01-07-2018 / 10:13:40 / Claus Gittinger"
! !

!IndentStream class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !