FilteringLineStream.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5178 61d677db25fb
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:
5161
a6ed595625e9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 3437
diff changeset
     1
"{ Encoding: utf8 }"
a6ed595625e9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 3437
diff changeset
     2
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
     3
"
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
     4
 COPYRIGHT (c) 1996 by Claus Gittinger
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 474
diff changeset
     5
	      All Rights Reserved
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
     6
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
     7
 This software is furnished under a license and may be used
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
     8
 only in accordance with the terms of that license and with the
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    10
 be provided or otherwise made available to, or used by, any
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    11
 other person.  No title to or ownership of the software is
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    12
 hereby transferred.
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    13
"
2377
2c8db8ee1b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 988
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
988
e7e70b439226 example added
md
parents: 885
diff changeset
    15
5161
a6ed595625e9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 3437
diff changeset
    16
"{ NameSpace: Smalltalk }"
a6ed595625e9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 3437
diff changeset
    17
400
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
    18
FilteringStream subclass:#FilteringLineStream
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
    19
	instanceVariableNames:'lineBuffer lineFilter'
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
    22
	category:'Streams-Misc'
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    25
!FilteringLineStream class methodsFor:'documentation'!
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    26
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    27
copyright
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    28
"
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    29
 COPYRIGHT (c) 1996 by Claus Gittinger
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 474
diff changeset
    30
	      All Rights Reserved
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    31
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    32
 This software is furnished under a license and may be used
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    33
 only in accordance with the terms of that license and with the
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    35
 be provided or otherwise made available to, or used by, any
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    36
 other person.  No title to or ownership of the software is
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    37
 hereby transferred.
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    38
"
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    39
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    40
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    41
!
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    42
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    43
documentation
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    44
"
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    45
    A FilteringLineStream is much like a FilteringStream, but
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    46
    processes its input line-wise.
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    47
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    48
    A FilteringLineStream can be connected to some input
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    49
    (from which characters are read via the ReadStream protocol),
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    50
    and/or to some output (to which characters are written via
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    51
    the WriteStream protocol.
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    52
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    53
    The FilteringLineStream itself performs some filtering/processing
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    54
    on the elements as they arrive, optionally suppressing filtering
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    55
    (i.e. removing) some elements.
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    56
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    57
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    58
    [author:]
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 474
diff changeset
    59
	Claus Gittinger
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    60
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    61
    [See also:]
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 474
diff changeset
    62
	FilteringStream ReadStream WriteStream
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    63
"
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    64
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    65
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
    66
!
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
examples
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
"
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
    70
  pushing the contents of a stream onto another stream
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
    71
  (here, the Transcript) without a need to read everyting into a
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
    72
  buffer or to reinvent the read-loop:
3437
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    73
                                                                [exBegin]
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
    74
    |in pusher|
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
    75
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
    76
    in := 'Makefile' asFilename readStream.
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
    77
    pusher := FilteringLineStream readingFrom:in writingTo:Transcript.
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
    78
    pusher filterUpToEnd
3437
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    79
                                                                [exEnd]
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    80
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    81
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    82
  collect a command's stdout and stderr, colorizing error output in red and normal output in green:
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    83
                                                                [exBegin]
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    84
    |in out stdoutColorizer errColorizer|
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    85
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    86
    out := Transcript.
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    87
    in := OperatingSystem 
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    88
            executeCommand:'bc'
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    89
            inputFrom:
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    90
'4+5
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    91
bla bla foo
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    92
4+5
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    93
bar
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    94
' readStream
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    95
            outputTo:((FilteringLineStream writingTo:out) filter:[:line | line colorizeAllWith:Color green darkened])
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    96
            errorTo:((FilteringLineStream writingTo:out) filter:[:line | line colorizeAllWith:Color red]).
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
    97
                                                                [exEnd]
988
e7e70b439226 example added
md
parents: 885
diff changeset
    98
e7e70b439226 example added
md
parents: 885
diff changeset
    99
e7e70b439226 example added
md
parents: 885
diff changeset
   100
  filter through an ActorStream:
3437
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   101
                                                                [exBegin]
988
e7e70b439226 example added
md
parents: 885
diff changeset
   102
    |lineNr in pusher actorPerLine|
e7e70b439226 example added
md
parents: 885
diff changeset
   103
e7e70b439226 example added
md
parents: 885
diff changeset
   104
    lineNr := 0.
e7e70b439226 example added
md
parents: 885
diff changeset
   105
e7e70b439226 example added
md
parents: 885
diff changeset
   106
    actorPerLine := ActorStream new.
e7e70b439226 example added
md
parents: 885
diff changeset
   107
    actorPerLine nextPutLineBlock:[:line | lineNr := lineNr + 1. Transcript show:lineNr; showCR:line].
e7e70b439226 example added
md
parents: 885
diff changeset
   108
e7e70b439226 example added
md
parents: 885
diff changeset
   109
    in := 'Makefile' asFilename readStream.
e7e70b439226 example added
md
parents: 885
diff changeset
   110
    pusher := FilteringLineStream readingFrom:in writingTo:actorPerLine.
e7e70b439226 example added
md
parents: 885
diff changeset
   111
    pusher filterUpToEnd
3437
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   112
                                                                [exEnd]
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   113
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   114
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   115
  filter all comments (starting with '#') from a Makefile:
3437
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   116
                                                                [exBegin]
400
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   117
    |in filter|
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   118
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   119
    in := 'Makefile' asFilename readStream.
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   120
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   121
    filter := FilteringLineStream readingFrom:in.
400
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   122
    filter filter:[:line | (line startsWith:'#') ifTrue:[line] ifFalse:[nil]].
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   123
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   124
    filter outputStream:Transcript.
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   125
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   126
    filter filterUpToEnd
3437
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   127
                                                                [exEnd]
400
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   128
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   129
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   130
  the inverse - remove all comments from the Makefile:
3437
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   131
                                                                [exBegin]
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   132
    |in filter|
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   133
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   134
    in := 'Makefile' asFilename readStream.
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   135
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   136
    filter := FilteringLineStream readingFrom:in.
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   137
    filter filter:[:line | (line startsWith:'#') ifTrue:[nil] ifFalse:[line]].
400
f61c18fd77be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   138
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   139
    filter outputStream:Transcript.
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   140
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   141
    filter filterUpToEnd
3437
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   142
                                                                [exEnd]
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   143
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   144
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   145
  feed a second filter from the first filters output;
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   146
  (the remains are all lines starting with '#' and ending with '-'):
3437
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   147
                                                                [exBegin]
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    |in filter1 filter2|
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    in := 'Makefile' asFilename readStream.
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   152
    filter1 := FilteringLineStream readingFrom:in.
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
    filter1 filter:[:line | (line startsWith:'#') ifTrue:[line] ifFalse:[nil]].
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   155
    filter2 := FilteringLineStream readingFrom:filter1.
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   156
    filter2 filter:[:line | (line endsWith:'-') ifTrue:[line] ifFalse:[nil]].
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
    filter2 outputStream:Transcript.
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   160
    filter2 filterUpToEnd
3437
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   161
                                                                [exEnd]
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
"
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
! !
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   165
!FilteringLineStream methodsFor:'access - pull-reading'!
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   166
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   167
filterUpToEnd
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   168
    "pull input from inputStream up to the end,
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   169
     push it filtered into the outputStream."
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   170
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   171
    [inputStream atEnd] whileFalse:[
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 474
diff changeset
   172
	self nextPutLine:(inputStream nextLine)
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   173
    ].
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   174
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   175
    "Created: 11.1.1997 / 16:09:05 / cg"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   176
! !
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   177
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
!FilteringLineStream methodsFor:'access - push-writing'!
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
cr
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
    "finish a line, push it filtered into the outputStream"
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
    |output|
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   185
    lineFilter isNil ifTrue:[
2377
2c8db8ee1b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 988
diff changeset
   186
	outputStream nextPutLine:(lineBuffer ? '')
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   187
    ] ifFalse:[
2377
2c8db8ee1b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 988
diff changeset
   188
	lineBuffer isNil ifTrue:[lineBuffer := ''].
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
2377
2c8db8ee1b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 988
diff changeset
   190
	output := lineFilter value:lineBuffer.
2c8db8ee1b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 988
diff changeset
   191
	output notNil ifTrue:[
2c8db8ee1b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 988
diff changeset
   192
	    outputStream nextPutLine:output.
2c8db8ee1b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 988
diff changeset
   193
	]
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
    ].
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    lineBuffer := ''.
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   197
    "Modified: 11.1.1997 / 16:32:40 / cg"
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
!
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
nextPut:something
5178
61d677db25fb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5161
diff changeset
   201
    "collect a character or line and push it when a cr arrives.
61d677db25fb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5161
diff changeset
   202
     Answer the argument."
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    something == Character cr ifTrue:[
5161
a6ed595625e9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 3437
diff changeset
   205
        self cr
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    ] ifFalse:[
5161
a6ed595625e9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 3437
diff changeset
   207
        lineBuffer isNil ifTrue:[lineBuffer := ''].
a6ed595625e9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 3437
diff changeset
   208
        lineBuffer := lineBuffer copyWith:something.
a6ed595625e9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 3437
diff changeset
   209
    ].
a6ed595625e9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 3437
diff changeset
   210
    ^ something
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    "Created: 2.7.1996 / 20:54:38 / cg"
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
    "Modified: 2.7.1996 / 21:03:26 / cg"
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
!
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
nextPutAll:something
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
    "collect a line and push it when a cr arrives"
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   219
    lineBuffer isNil ifTrue:[
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 474
diff changeset
   220
	lineBuffer := something
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   221
    ] ifFalse:[
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 474
diff changeset
   222
	lineBuffer := lineBuffer , something.
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   223
    ]
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   224
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   225
    "Modified: 11.1.1997 / 16:31:28 / cg"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   226
! !
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   227
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   228
!FilteringLineStream methodsFor:'accessing'!
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   230
filter
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   231
    "return the filter"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   232
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   233
    ^ lineFilter
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   234
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   235
    "Created: 11.1.1997 / 16:13:15 / cg"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   236
!
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   237
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   238
filter:aBlock
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   239
    "set the filter"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   240
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   241
    lineFilter := aBlock
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   242
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 473
diff changeset
   243
    "Created: 11.1.1997 / 16:13:25 / cg"
2787
a0285176d2b6 added: #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2377
diff changeset
   244
!
a0285176d2b6 added: #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2377
diff changeset
   245
3437
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   246
isBinary
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   247
    ^ (inputStream ? outputStream) isBinary
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   248
!
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   249
2787
a0285176d2b6 added: #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2377
diff changeset
   250
size
a0285176d2b6 added: #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2377
diff changeset
   251
    "mhmh - please use isEmpty; anything else is unknown"
a0285176d2b6 added: #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2377
diff changeset
   252
a0285176d2b6 added: #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2377
diff changeset
   253
    self error:'size of input is unknown (due to filtering)'
a0285176d2b6 added: #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2377
diff changeset
   254
a0285176d2b6 added: #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2377
diff changeset
   255
    "Created: / 06-08-2012 / 08:21:12 / cg"
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
! !
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
473
cb46b0ba9934 comment
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   258
!FilteringLineStream class methodsFor:'documentation'!
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
version
5161
a6ed595625e9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 3437
diff changeset
   261
    ^ '$Header$'
2377
2c8db8ee1b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 988
diff changeset
   262
!
2c8db8ee1b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 988
diff changeset
   263
2c8db8ee1b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 988
diff changeset
   264
version_CVS
5161
a6ed595625e9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 3437
diff changeset
   265
    ^ '$Header$'
399
7007796f7a34 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
! !
3437
1e3c96378a00 class: FilteringLineStream
Claus Gittinger <cg@exept.de>
parents: 2787
diff changeset
   267