author | Claus Gittinger <cg@exept.de> |
Wed, 25 Jul 2012 19:12:38 +0200 | |
changeset 14245 | 1921581b87a9 |
parent 14244 | d107839eb01b |
child 15752 | fc4ed047850e |
child 18011 | deb0c3355881 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
160 | 3 |
All Rights Reserved |
1 | 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 |
" |
|
6561 | 12 |
"{ Package: 'stx:libbasic' }" |
6176 | 13 |
|
647 | 14 |
OrderedCollection subclass:#StringCollection |
968 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Collections-Text' |
|
1 | 19 |
! |
20 |
||
246 | 21 |
!StringCollection class methodsFor:'documentation'! |
89 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
160 | 26 |
All Rights Reserved |
1 | 27 |
|
89 | 28 |
This software is furnished under a license and may be used |
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
1 | 36 |
|
89 | 37 |
documentation |
38 |
" |
|
262 | 39 |
StringCollection is an variable sized array of lines which are strings. |
160 | 40 |
WARNING: |
1290 | 41 |
This class is temporary (a historic leftover) - it may change or |
42 |
even vanish in the future. Use OrderedCollections or other standard |
|
43 |
classes to represent collections of strings. |
|
89 | 44 |
|
262 | 45 |
StringCollection used to be called Text, but this is a very bad name |
46 |
- there is something totally different also named Text in ST-80 ... |
|
1290 | 47 |
|
48 |
[author:] |
|
49 |
Claus Gittinger |
|
89 | 50 |
" |
51 |
! ! |
|
1 | 52 |
|
246 | 53 |
!StringCollection class methodsFor:'instance creation'! |
1 | 54 |
|
55 |
from:aString |
|
11596 | 56 |
<resource: #obsolete> |
1 | 57 |
"return a new text object with lines taken from the argument, aString" |
58 |
||
8375
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
59 |
self obsoleteMethodWarning:'use #fromString:'. |
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
60 |
^ self fromString:aString. |
1 | 61 |
! |
62 |
||
63 |
fromArray:anArray |
|
64 |
"return a new text object with lines taken from the argument, an array |
|
65 |
of strings" |
|
66 |
||
246 | 67 |
|newStringCollection |
1 | 68 |
size "{ Class: SmallInteger }" | |
69 |
||
70 |
size := anArray size. |
|
246 | 71 |
newStringCollection := self new:size. |
1 | 72 |
1 to:size do:[:line | |
246 | 73 |
newStringCollection at:line put:(anArray at:line) |
1 | 74 |
]. |
246 | 75 |
^ newStringCollection |
731 | 76 |
! |
77 |
||
8375
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
78 |
fromString:aString |
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
79 |
"return a new text object with lines taken from the argument, aString" |
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
80 |
|
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
81 |
^ (self new:1) fromString:aString |
14245 | 82 |
|
83 |
"Modified: / 25-07-2012 / 18:52:47 / cg" |
|
8375
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
84 |
! |
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
85 |
|
731 | 86 |
new:size |
87 |
"return a new string collection with size empty lines" |
|
88 |
||
89 |
^ (super new:size) grow:size |
|
9161 | 90 |
! |
91 |
||
92 |
withSize:size |
|
93 |
"return a new string collection with size empty lines" |
|
94 |
||
95 |
^ (super new:size) grow:size |
|
1 | 96 |
! ! |
97 |
||
246 | 98 |
!StringCollection methodsFor:'converting'! |
1 | 99 |
|
100 |
asString |
|
101 |
"return myself as a string with embedded cr's" |
|
102 |
||
7829 | 103 |
^ self |
104 |
asStringWith:Character cr |
|
105 |
from:1 to:(self size) |
|
106 |
compressTabs:false |
|
107 |
final:Character cr |
|
87 | 108 |
! |
109 |
||
608 | 110 |
asStringCollection |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
111 |
"return the receiver as a stringCollection - that's easy" |
608 | 112 |
|
113 |
^ self |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
114 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
115 |
"Modified (comment): / 25-07-2012 / 18:11:14 / cg" |
608 | 116 |
! |
117 |
||
3601
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
118 |
asStringWithoutEmphasis |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
119 |
"return myself as a string with embedded cr's, but drop any emphasis" |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
120 |
|
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
121 |
^ self |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
122 |
asStringWith:Character cr |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
123 |
from:1 to:(self size) |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
124 |
compressTabs:false |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
125 |
final:Character cr |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
126 |
withEmphasis:false |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
127 |
|
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
128 |
"Created: / 17.6.1998 / 12:32:48 / cg" |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
129 |
! |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
130 |
|
7829 | 131 |
asStringWithoutFinalCR |
132 |
"return myself as a string with embedded cr's |
|
133 |
but do not add a final CR" |
|
134 |
||
135 |
^ self |
|
136 |
asStringWith:Character cr |
|
137 |
from:1 to:(self size) |
|
138 |
compressTabs:false |
|
139 |
final:nil |
|
140 |
! |
|
141 |
||
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
142 |
encodeFrom:oldEncoding into:newEncoding |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
143 |
"encode each line" |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
144 |
|
7916 | 145 |
|enc| |
146 |
||
147 |
enc := CharacterEncoder encoderToEncodeFrom:oldEncoding into:newEncoding. |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
148 |
^ self |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
149 |
collect:[:line | |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
150 |
line isNil |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
151 |
ifTrue:[ nil ] |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
152 |
ifFalse:[ enc encodeString:line] |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
153 |
] |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
154 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
155 |
"Modified (comment): / 25-07-2012 / 18:09:40 / cg" |
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
156 |
! |
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
157 |
|
1 | 158 |
from:aString |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
159 |
"setup my contents from the argument, aString" |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
160 |
|
11596 | 161 |
<resource: #obsolete> |
1 | 162 |
|
8375
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
163 |
self obsoleteMethodWarning:'use #fromString:'. |
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
164 |
^ self fromString:aString |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
165 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
166 |
"Modified (format): / 25-07-2012 / 18:02:34 / cg" |
8375
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
167 |
! |
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
168 |
|
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
169 |
fromString:aString |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
170 |
"setup my contents from the argument, aString. |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
171 |
AString should be delimited by newline characters" |
8375
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
172 |
|
1 | 173 |
|numberOfLines "{ Class:SmallInteger }" |
174 |
start "{ Class:SmallInteger }" |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
175 |
stop "{ Class:SmallInteger }" |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
176 |
delimiter |
6176 | 177 |
| |
1 | 178 |
|
14245 | 179 |
aString isEmpty ifTrue:[self grow:0. ^ self ]. |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
180 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
181 |
delimiter := Character cr. |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
182 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
183 |
numberOfLines := aString occurrencesOf:delimiter. |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
184 |
numberOfLines == 0 ifTrue:[ |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
185 |
"/ check if its a return-delimited string |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
186 |
(aString occurrencesOf:(Character return)) > 0 ifTrue:[ |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
187 |
delimiter := Character return. |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
188 |
]. |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
189 |
]. |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
190 |
aString last == delimiter ifFalse:[ |
6176 | 191 |
numberOfLines := numberOfLines + 1. |
203 | 192 |
]. |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
193 |
|
1 | 194 |
self grow:numberOfLines. |
6176 | 195 |
|
1 | 196 |
start := 1. |
197 |
1 to:numberOfLines do:[:lineNr | |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
198 |
stop := aString indexOf:delimiter startingAt:start. |
6176 | 199 |
stop == 0 ifTrue:[ |
200 |
self at:lineNr put:(aString copyFrom:start). |
|
201 |
self from:lineNr+1 to:numberOfLines put:''. |
|
202 |
^ self. |
|
203 |
]. |
|
10 | 204 |
|
6176 | 205 |
self at:lineNr put:(aString copyFrom:start to:stop-1). |
206 |
start := stop + 1 |
|
1 | 207 |
] |
6176 | 208 |
|
14245 | 209 |
"Modified: / 25-07-2012 / 18:52:58 / cg" |
968 | 210 |
! ! |
211 |
||
212 |
!StringCollection methodsFor:'copying'! |
|
213 |
||
214 |
copyEmpty:size |
|
14111 | 215 |
"we have to redefine this, since 'self class new:size' |
216 |
does allocate size nil lines (it does an implicit #grow: size). |
|
217 |
In order to get #collect: working, we should not perform this implicit grow" |
|
968 | 218 |
|
14111 | 219 |
^ super copyEmpty:0. |
968 | 220 |
|
221 |
"Created: 14.2.1996 / 11:05:47 / stefan" |
|
10452 | 222 |
! |
223 |
||
14111 | 224 |
copyEmptyAndGrow:size |
225 |
"performance optimization: |
|
226 |
StringCollections are always grown to size after #new: / #copyEmpty:" |
|
227 |
||
228 |
^ super copyEmpty:size. |
|
229 |
! |
|
230 |
||
10452 | 231 |
withoutLeadingBlankLines |
232 |
"return a copy of the receiver with leading blank lines removed. |
|
233 |
If there are no leading blank lines, the original receiver is returned. |
|
234 |
If all lines are blank, an empty string collection is returned." |
|
235 |
||
236 |
|indexOfFirstNonBlankLine| |
|
237 |
||
11702 | 238 |
indexOfFirstNonBlankLine := self findFirst:[:line | line notEmptyOrNil and:[line isBlank not]]. |
239 |
indexOfFirstNonBlankLine == 0 ifTrue:[ ^ self copyEmpty ]. |
|
240 |
indexOfFirstNonBlankLine == 1 ifTrue:[ ^ self ]. |
|
241 |
^ self copyFrom:indexOfFirstNonBlankLine |
|
10452 | 242 |
|
243 |
" |
|
244 |
'1 |
|
245 |
2 |
|
246 |
3' asStringCollection withoutLeadingBlankLines |
|
247 |
" |
|
248 |
||
249 |
" |
|
250 |
' |
|
251 |
2 |
|
252 |
3' asStringCollection withoutLeadingBlankLines |
|
253 |
" |
|
254 |
||
255 |
" |
|
256 |
' |
|
257 |
||
11702 | 258 |
' asStringCollection withoutLeadingBlankLines |
259 |
" |
|
260 |
! |
|
261 |
||
262 |
withoutTrailingBlankLines |
|
263 |
"return a copy of the receiver with trailing blank lines removed. |
|
264 |
If there are no trailing blank lines, the original receiver is returned. |
|
265 |
If all lines are blank, an empty string collection is returned." |
|
266 |
||
267 |
|indexOfLastNonBlankLine| |
|
268 |
||
269 |
indexOfLastNonBlankLine := self findLast:[:line | line notEmptyOrNil and:[line isBlank not]]. |
|
270 |
indexOfLastNonBlankLine == 0 ifTrue:[ ^ self copyEmpty ]. |
|
271 |
indexOfLastNonBlankLine == self size ifTrue:[ ^ self ]. |
|
272 |
^ self copyTo:indexOfLastNonBlankLine |
|
273 |
||
274 |
" |
|
275 |
'1 |
|
276 |
2 |
|
277 |
3' asStringCollection withoutTrailingBlankLines |
|
278 |
" |
|
279 |
||
280 |
" |
|
281 |
' |
|
282 |
2 |
|
283 |
3 |
|
284 |
' asStringCollection withoutTrailingBlankLines |
|
285 |
" |
|
286 |
||
287 |
" |
|
288 |
' |
|
289 |
||
290 |
' asStringCollection withoutTrailingBlankLines |
|
10452 | 291 |
" |
608 | 292 |
! ! |
293 |
||
14111 | 294 |
|
5251 | 295 |
!StringCollection methodsFor:'printing & storing'! |
1 | 296 |
|
10909
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
297 |
printOn:aStream |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
298 |
"print myself on aStream with embedded cr's" |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
299 |
|
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
300 |
self do:[:eachString| |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
301 |
eachString printOn:aStream. |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
302 |
aStream cr. |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
303 |
]. |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
304 |
! |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
305 |
|
1 | 306 |
printString |
284 | 307 |
"return the receivers printString" |
308 |
||
1 | 309 |
^ self asString |
310 |
! ! |
|
311 |
||
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
312 |
!StringCollection methodsFor:'queries'! |
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
313 |
|
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
314 |
encoding |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
315 |
"the encoding; ask my first line" |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
316 |
|
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
317 |
self do:[:l | l notNil ifTrue:[^ l encoding]]. |
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
318 |
"/ sigh |
14173 | 319 |
^ #unicode |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
320 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
321 |
"Modified (comment): / 25-07-2012 / 18:09:15 / cg" |
13331 | 322 |
! |
323 |
||
324 |
stringSize |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
325 |
"the size of the string if I was converted" |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
326 |
|
13331 | 327 |
^ self inject:0 into:[:sizeSoFar :eachLine | |
328 |
sizeSoFar + eachLine size + 1 |
|
329 |
] |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
330 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
331 |
"Modified (comment): / 25-07-2012 / 18:02:19 / cg" |
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
332 |
! ! |
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
333 |
|
246 | 334 |
!StringCollection methodsFor:'searching'! |
1 | 335 |
|
336 |
indexOfLineStartingWith:aString |
|
337 |
"return the index of the first line starting with the argument, aString" |
|
338 |
||
1009
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
339 |
|index "{ Class:SmallInteger }" |
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
340 |
l| |
1 | 341 |
|
342 |
index := 1. |
|
343 |
[index <= self size] whileTrue:[ |
|
1009
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
344 |
l := self at:index. |
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
345 |
(l notNil and:[l startsWith:aString]) ifTrue:[ |
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
346 |
^ index |
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
347 |
]. |
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
348 |
index := index + 1 |
1 | 349 |
]. |
350 |
^ 0 |
|
1009
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
351 |
|
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
352 |
"Modified: 24.2.1996 / 19:08:47 / cg" |
1 | 353 |
! ! |
608 | 354 |
|
1064 | 355 |
!StringCollection methodsFor:'special converting'! |
356 |
||
14204 | 357 |
decodeFrom: encodingSymbol |
358 |
"given the receiver encoded as described by encodingSymbol, |
|
359 |
convert it into internal ST/X (unicode) encoding and return a |
|
360 |
corresponding StringCollection." |
|
361 |
||
362 |
|myEncoding encoder| |
|
363 |
||
364 |
encodingSymbol isNil ifTrue:[^ self]. |
|
365 |
||
366 |
encoder := CharacterEncoder encoderToEncodeFrom:#unicode into:encodingSymbol. |
|
367 |
encoder isNil ifTrue:[^ self]. |
|
368 |
||
369 |
^ self |
|
370 |
collect:[:eachLineOrNil | |
|
371 |
eachLineOrNil isNil ifTrue:[ |
|
372 |
eachLineOrNil |
|
373 |
] ifFalse:[ |
|
374 |
encoder decodeString: eachLineOrNil |
|
375 |
] |
|
376 |
] |
|
377 |
||
378 |
"Created: / 12-07-2012 / 14:30:25 / cg" |
|
379 |
! |
|
380 |
||
1064 | 381 |
withTabs |
382 |
"return a new stringCollection consisting of the receivers lines, |
|
383 |
where leading spaces are replaced by tabulator characters (assuming 8-col tabs). |
|
384 |
Notice: lines which do not contain leading spaces, are copied by reference to the |
|
385 |
new stringCollection (i.e. shared); |
|
386 |
otherwise new strings is created. |
|
387 |
Limitation: only the very first spaces are replaced" |
|
388 |
||
389 |
^ self collect:[:string| |
|
390 |
string notNil ifTrue:[ |
|
391 |
string withTabs |
|
392 |
] ifFalse:[ |
|
393 |
string |
|
394 |
] |
|
395 |
] |
|
396 |
||
397 |
" |
|
398 |
(' abcd ') asStringCollection withTabs |
|
399 |
" |
|
400 |
||
401 |
"Created: 4.3.1996 / 17:09:07 / cg" |
|
402 |
"Modified: 4.3.1996 / 17:10:37 / cg" |
|
403 |
! |
|
404 |
||
405 |
withTabsExpanded |
|
406 |
"return a new stringCollection consisting of the receivers lines, |
|
407 |
where tabs are replaced by space characters (assuming 8-col tabs). |
|
408 |
Notice: lines which do not contain any tab, are copied by reference to the |
|
409 |
new stringCollection (i.e. shared); |
|
410 |
otherwise new strings is created." |
|
411 |
||
412 |
^ self collect:[:string| |
|
413 |
string notNil ifTrue:[ |
|
414 |
string withTabsExpanded |
|
415 |
] ifFalse:[ |
|
416 |
string |
|
417 |
] |
|
418 |
] |
|
419 |
||
420 |
" |
|
421 |
|tab| |
|
422 |
tab := String with:Character tab. |
|
423 |
('abcd', tab, 'tef', tab, 'tgh') asStringCollection withTabsExpanded |
|
424 |
" |
|
425 |
||
426 |
"Created: 12.2.1996 / 22:25:56 / stefan" |
|
427 |
"Modified: 14.2.1996 / 11:13:01 / stefan" |
|
428 |
"Modified: 4.3.1996 / 17:10:22 / cg" |
|
429 |
! ! |
|
430 |
||
4007 | 431 |
!StringCollection methodsFor:'testing'! |
432 |
||
433 |
isStringCollection |
|
434 |
"return true, if the receiver is some kind of stringCollection; |
|
435 |
true is returned here - the method is redefined from Object." |
|
436 |
||
437 |
^ true |
|
438 |
||
439 |
||
440 |
! ! |
|
441 |
||
633 | 442 |
!StringCollection class methodsFor:'documentation'! |
443 |
||
444 |
version |
|
14245 | 445 |
^ '$Header: /cvs/stx/stx/libbasic/StringCollection.st,v 1.46 2012-07-25 17:12:38 cg Exp $' |
13331 | 446 |
! |
447 |
||
448 |
version_CVS |
|
14245 | 449 |
^ '$Header: /cvs/stx/stx/libbasic/StringCollection.st,v 1.46 2012-07-25 17:12:38 cg Exp $' |
633 | 450 |
! ! |