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