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:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5373
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
     1
"{ Encoding: utf8 }"
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
     2
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
     3
"
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
     4
 COPYRIGHT (c) 2018 by eXept Software AG
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
     5
              All Rights Reserved
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
     6
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
     7
 This software is furnished under a license and may be used
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
     8
 only in accordance with the terms of that license and with the
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    10
 be provided or otherwise made available to, or used by, any
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    11
 other person.  No title to or ownership of the software is
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    12
 hereby transferred.
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    13
"
4685
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
"{ NameSpace: Smalltalk }"
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
WriteStream subclass:#IndentStream
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:'indentLevel indentString'
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
4696
78a1dd7c7624 #DOCUMENTATION by Lukas Vogel
lukas
parents: 4685
diff changeset
    22
	category:'Streams-Misc'
4685
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!IndentStream class methodsFor:'documentation'!
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
5373
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    27
copyright
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    28
"
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    29
 COPYRIGHT (c) 2018 by eXept Software AG
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    30
              All Rights Reserved
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    31
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    32
 This software is furnished under a license and may be used
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    33
 only in accordance with the terms of that license and with the
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    35
 be provided or otherwise made available to, or used by, any
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    36
 other person.  No title to or ownership of the software is
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    37
 hereby transferred.
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    38
"
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    39
!
9a516ecec5d5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5242
diff changeset
    40
4685
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    a write stream which keeps a current indent and
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    automatically emits the indent on every cr.
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    [author:]
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
        Claus Gittinger (ported from Squeak)
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
"
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
! !
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
!IndentStream class methodsFor:'instance creation'!
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
on: aCollection
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
	^(super on: aCollection) initialize
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
!
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
with: aCollection
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
	^(super with: aCollection) initialize
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
! !
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
!IndentStream methodsFor:'accessing'!
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
indentLevel
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    "the current indent"
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    ^indentLevel
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    "Modified (comment): / 01-07-2018 / 10:16:32 / Claus Gittinger"
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
!
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
indentString:aString
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    "the string to use for indentation.
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
     If left unset, a tab is used"
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
     
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
    indentString := aString
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    "Created: / 01-07-2018 / 10:16:17 / Claus Gittinger"
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
! !
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
5242
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    82
!IndentStream methodsFor:'indentation'!
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    83
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    84
indent
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    85
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    86
	self tab.
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    87
	indentLevel := indentLevel + 1.
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    88
!
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    89
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    90
indentBack
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    91
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    92
	indentLevel := indentLevel - 1.
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    93
! !
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    94
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    95
!IndentStream methodsFor:'initialization'!
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    96
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    97
initialize
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    98
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
    99
	super initialize.
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
   100
	indentLevel := 0.
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
   101
! !
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
   102
f3faddcbd93d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4696
diff changeset
   103
!IndentStream methodsFor:'writing'!
4685
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
cr
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
        super cr.
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
        self putIndent.
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    "Modified: / 01-07-2018 / 10:13:45 / Claus Gittinger"
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
!
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
crtab
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
	self cr.
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
	self indent.
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
!
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
putIndent
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
    indentString notNil ifTrue:[
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
        indentLevel timesRepeat:[
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
            self nextPutAll:indentString
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
        ].
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
        ^ self.
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    ].
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
    "/ original
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    self tab: self indentLevel.
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    "Created: / 01-07-2018 / 10:13:40 / Claus Gittinger"
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
! !
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
!IndentStream class methodsFor:'documentation'!
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
version
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
    ^ '$Header$'
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
!
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
version_CVS
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    ^ '$Header$'
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
! !
ea7ff233d26b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141