0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
42
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
ArrayedCollection subclass:#VariableString
|
|
14 |
instanceVariableNames:'contents'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
42
|
17 |
category:'Collections-Text'
|
0
|
18 |
!
|
|
19 |
|
|
20 |
VariableString comment:'
|
31
|
21 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
42
|
22 |
All Rights Reserved
|
36
|
23 |
|
53
|
24 |
$Header: /cvs/stx/stx/libbasic2/VariableString.st,v 1.10 1995-02-11 14:10:16 claus Exp $
|
31
|
25 |
'!
|
0
|
26 |
|
31
|
27 |
!VariableString class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
42
|
32 |
All Rights Reserved
|
0
|
33 |
|
31
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
0
|
42 |
|
31
|
43 |
version
|
|
44 |
"
|
53
|
45 |
$Header: /cvs/stx/stx/libbasic2/VariableString.st,v 1.10 1995-02-11 14:10:16 claus Exp $
|
31
|
46 |
"
|
|
47 |
!
|
22
|
48 |
|
31
|
49 |
documentation
|
|
50 |
"
|
|
51 |
VariableStrings can grow and shrink - in contrast to Strings which are
|
|
52 |
fixed in size - this may change in the future.
|
|
53 |
|
|
54 |
WARNING: This class is a historic leftover and will vanish soon.
|
42
|
55 |
Dont use it.
|
31
|
56 |
"
|
|
57 |
! !
|
0
|
58 |
|
|
59 |
!VariableString class methodsFor:'initialization'!
|
|
60 |
|
|
61 |
initialize
|
1
|
62 |
"clear my superclass - this makes all messages be misunderstood"
|
0
|
63 |
|
1
|
64 |
self setSuperclass: nil
|
0
|
65 |
! !
|
|
66 |
|
|
67 |
!VariableString class methodsFor:'instance creation'!
|
|
68 |
|
|
69 |
new
|
|
70 |
"return a new VariableString - with size 0"
|
|
71 |
|
|
72 |
^ self new:0
|
|
73 |
!
|
|
74 |
|
|
75 |
new:size
|
|
76 |
"return a new VariableString"
|
|
77 |
|
|
78 |
^ (self basicNew) setContents:(String new:size)
|
|
79 |
!
|
|
80 |
|
|
81 |
copyFrom:aString
|
|
82 |
"return a new VariableString with contents copied from the argument"
|
|
83 |
|
|
84 |
^ self basicNew setContents:(String copyFrom:aString)
|
|
85 |
! !
|
|
86 |
|
|
87 |
!VariableString methodsFor:'accessing'!
|
|
88 |
|
|
89 |
at:index
|
|
90 |
"return the element at index"
|
|
91 |
|
|
92 |
^ contents at:index
|
|
93 |
!
|
|
94 |
|
|
95 |
at:index put:anObject
|
|
96 |
"set the element at index"
|
|
97 |
|
|
98 |
^ contents at:index put:anObject
|
|
99 |
! !
|
|
100 |
|
|
101 |
!VariableString methodsFor:'queries'!
|
|
102 |
|
|
103 |
size
|
|
104 |
^ contents size
|
|
105 |
!
|
|
106 |
|
|
107 |
isFixedSize
|
|
108 |
"return true if the receiver cannot grow - this will vanish once
|
|
109 |
Arrays and Strings learn how to grow ..."
|
|
110 |
|
|
111 |
^ false
|
|
112 |
! !
|
|
113 |
|
|
114 |
!VariableString methodsFor:'filling & replacing'!
|
|
115 |
|
|
116 |
replaceFrom:start to:stop with:aCollection startingAt:repStart
|
|
117 |
"reimplemented for speed
|
|
118 |
- can use Strings fast replace if aCollection
|
|
119 |
is String or VariableString"
|
|
120 |
|
|
121 |
|col|
|
|
122 |
|
|
123 |
col := aCollection.
|
|
124 |
(aCollection isKindOf:VariableString) ifTrue:[
|
42
|
125 |
((stop - start + repStart) <= aCollection size) ifTrue:[
|
|
126 |
col := aCollection getContents
|
|
127 |
]
|
0
|
128 |
].
|
|
129 |
(col isMemberOf:String) ifTrue:[
|
42
|
130 |
(stop <= (contents size)) ifTrue:[
|
|
131 |
contents replaceFrom:start to:stop with:col startingAt:repStart.
|
28
|
132 |
^ self
|
42
|
133 |
]
|
0
|
134 |
].
|
|
135 |
^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
|
|
136 |
! !
|
|
137 |
|
|
138 |
!VariableString methodsFor:'converting'!
|
|
139 |
|
53
|
140 |
asStringCollection
|
|
141 |
^ contents asStringCollection
|
0
|
142 |
! !
|
|
143 |
|
42
|
144 |
!VariableString methodsFor:'copying'!
|
0
|
145 |
|
42
|
146 |
postCopy
|
|
147 |
contents := contents copy
|
0
|
148 |
! !
|
|
149 |
|
|
150 |
!VariableString methodsFor:'private'!
|
|
151 |
|
|
152 |
getContents
|
|
153 |
"return the contents array"
|
|
154 |
|
|
155 |
^ contents
|
|
156 |
!
|
|
157 |
|
|
158 |
setContents:aString
|
|
159 |
"set the contents"
|
|
160 |
|
|
161 |
contents := aString
|
|
162 |
! !
|
|
163 |
|
|
164 |
!VariableString methodsFor:'error handling'!
|
|
165 |
|
|
166 |
doesNotUnderstand:aMessage
|
|
167 |
"this is funny: all message we do not understand, are passed
|
|
168 |
on to the string - so we do not have to care for all
|
|
169 |
possible messages ...(thanks to the Message class)"
|
|
170 |
|
|
171 |
^ contents perform:(aMessage selector)
|
42
|
172 |
withArguments:(aMessage arguments)
|
0
|
173 |
! !
|
|
174 |
|
|
175 |
!VariableString methodsFor:'grow & shrink'!
|
|
176 |
|
|
177 |
grow:newSize
|
|
178 |
|old oldSize|
|
|
179 |
|
|
180 |
oldSize := contents size.
|
|
181 |
(newSize < oldSize) ifTrue:[
|
42
|
182 |
contents := contents copyTo:newSize
|
0
|
183 |
] ifFalse:[
|
42
|
184 |
(newSize > oldSize) ifTrue:[
|
|
185 |
old := contents.
|
|
186 |
(newSize > (oldSize * 2)) ifTrue:[
|
|
187 |
contents := String new:newSize
|
|
188 |
] ifFalse:[
|
|
189 |
contents := String new:(oldSize * 2)
|
|
190 |
].
|
|
191 |
contents replaceFrom:1 to:oldSize
|
|
192 |
with:old startingAt:1
|
|
193 |
]
|
0
|
194 |
]
|
|
195 |
! !
|