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