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