author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 01 Feb 2012 00:56:17 +0000 | |
changeset 103 | 726bf2ca0b99 |
parent 67 | a87e5ce04545 |
child 109 | 9587e2df7029 |
permissions | -rw-r--r-- |
4 | 1 |
"{ Package: 'stx:goodies/xtreams/substreams' }" |
2 |
||
3 |
"{ NameSpace: Xtreams }" |
|
4 |
||
5 |
ReadSubstream subclass:#TestReadSubstream |
|
6 |
instanceVariableNames:'substreamAtEnd test inclusive' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
22
e0653bbdbe61
added XtreamsPool to fix DefaultBufferSize; set proper category names
mkobetic
parents:
4
diff
changeset
|
9 |
category:'Xtreams-Substreams' |
4 | 10 |
! |
11 |
||
12 |
TestReadSubstream comment:'This is a substream bounded by an element matching the @test criteria. |
|
13 |
||
14 |
Instance Variables |
|
15 |
substreamAtEnd <Boolean> is this substream at end |
|
16 |
test <BlockClosure> the bounding criteria |
|
17 |
inclusive <Boolean> is the boundary part of the substream contents |
|
18 |
||
19 |
' |
|
20 |
! |
|
21 |
||
22 |
||
23 |
!TestReadSubstream class methodsFor:'instance creation'! |
|
24 |
||
25 |
on: aSource test: testBlock inclusive: aBoolean |
|
26 |
^self new on: aSource test: testBlock inclusive: aBoolean |
|
27 |
! ! |
|
28 |
||
29 |
!TestReadSubstream methodsFor:'accessing'! |
|
30 |
||
31 |
get |
|
32 |
| object | |
|
33 |
substreamAtEnd ifTrue: [Incomplete zero raise]. |
|
34 |
object := [source get] on: Incomplete do: [:incomplete | sourceAtEnd := substreamAtEnd := true. incomplete pass]. |
|
35 |
(substreamAtEnd := test value: object) ifTrue: |
|
36 |
[inclusive ifTrue: [^object]. |
|
37 |
Incomplete zero raise]. |
|
38 |
^object |
|
39 |
! |
|
40 |
||
41 |
read: anInteger into: aSequenceableCollection at: startIndex |
|
42 |
| object count | |
|
43 |
||
44 |
substreamAtEnd ifTrue: [(Incomplete on: aSequenceableCollection count: 0 at: startIndex) raise]. |
|
45 |
count := 0. |
|
46 |
[[count = anInteger or: [substreamAtEnd]] whileFalse: |
|
47 |
[object := source get. |
|
48 |
((substreamAtEnd := test value: object) not or: [inclusive]) ifTrue: |
|
49 |
[aSequenceableCollection at: startIndex + count put: object. |
|
50 |
count := count + 1]]] |
|
51 |
on: Incomplete do: [sourceAtEnd := substreamAtEnd := true. (Incomplete on: aSequenceableCollection count: count at: startIndex) raise]. |
|
52 |
count < anInteger ifTrue: [(Incomplete on: aSequenceableCollection count: count at: startIndex) raise]. |
|
53 |
^anInteger |
|
54 |
! ! |
|
55 |
||
56 |
!TestReadSubstream methodsFor:'initialize-release'! |
|
57 |
||
58 |
on: aSource test: testBlock inclusive: aBoolean |
|
59 |
self on: aSource. |
|
60 |
test := testBlock. |
|
61 |
inclusive := aBoolean. |
|
62 |
substreamAtEnd := false |
|
63 |
! |
|
64 |
||
65 |
subseekend |
|
66 |
| object | |
|
67 |
substreamAtEnd ifTrue: [^self]. |
|
68 |
[[substreamAtEnd] whileFalse: |
|
69 |
[object := source get. |
|
70 |
substreamAtEnd := test value: object]] |
|
71 |
on: Incomplete do: [sourceAtEnd := substreamAtEnd := true] |
|
72 |
! ! |
|
73 |
||
74 |
!TestReadSubstream methodsFor:'private'! |
|
75 |
||
76 |
streamingWrite: anInteger into: aWriteStream |
|
77 |
| object count | |
|
78 |
||
79 |
substreamAtEnd ifTrue: [Incomplete zero raise]. |
|
80 |
count := 0. |
|
81 |
[[count = anInteger or: [substreamAtEnd]] whileFalse: |
|
82 |
[object := source get. |
|
83 |
((substreamAtEnd := test value: object) not or: [inclusive]) ifTrue: |
|
84 |
[aWriteStream put: object. |
|
85 |
count := count + 1]]] |
|
86 |
on: Incomplete do: [sourceAtEnd := substreamAtEnd := true. (Incomplete count: count) raise]. |
|
87 |
count < anInteger ifTrue: [(Incomplete count: count) raise]. |
|
88 |
^anInteger |
|
89 |
! |
|
90 |
||
91 |
streamingWriteInto: aWriteStream |
|
92 |
| object count | |
|
93 |
substreamAtEnd ifTrue: [^0]. |
|
94 |
count := 0. |
|
95 |
^[ [ substreamAtEnd |
|
96 |
] whileFalse: [ |
|
97 |
object := source get. |
|
98 |
(substreamAtEnd := test value: object) |
|
99 |
ifTrue: [inclusive ifTrue: [aWriteStream put: object. count := count + 1]] |
|
100 |
ifFalse: [aWriteStream put: object. count := count + 1]]. |
|
101 |
count |
|
102 |
] on: Incomplete do: [sourceAtEnd := substreamAtEnd := true. count ] |
|
103 |
! ! |
|
104 |
||
105 |
!TestReadSubstream methodsFor:'seeking'! |
|
106 |
||
107 |
-= anInteger |
|
108 |
^anInteger isZero |
|
109 |
ifTrue: [self subseekend. 0] |
|
110 |
ifFalse: [super -= anInteger] |
|
111 |
! ! |
|
112 |
||
113 |
!TestReadSubstream methodsFor:'testing'! |
|
114 |
||
115 |
isPositionable |
|
116 |
^false |
|
117 |
! ! |
|
118 |
||
119 |
!TestReadSubstream class methodsFor:'documentation'! |
|
120 |
||
121 |
version_SVN |
|
122 |
^ '$Id$' |
|
123 |
! ! |