author | Claus Gittinger <cg@exept.de> |
Sat, 06 Jun 2015 14:42:18 +0200 | |
changeset 18452 | 5724547da8de |
parent 17083 | 38bc33e2583b |
child 18120 | e3a375d5f6a8 |
child 19466 | c9b3fe03005f |
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 |
|
16712 | 90 |
|
91 |
" |
|
92 |
StringCollection new:10 |
|
93 |
" |
|
9161 | 94 |
! |
95 |
||
16712 | 96 |
newWithSize:size |
9161 | 97 |
"return a new string collection with size empty lines" |
98 |
||
16712 | 99 |
^ self new:size "/ already does what we want |
1 | 100 |
! ! |
101 |
||
246 | 102 |
!StringCollection methodsFor:'converting'! |
1 | 103 |
|
104 |
asString |
|
105 |
"return myself as a string with embedded cr's" |
|
106 |
||
7829 | 107 |
^ self |
108 |
asStringWith:Character cr |
|
109 |
from:1 to:(self size) |
|
110 |
compressTabs:false |
|
111 |
final:Character cr |
|
87 | 112 |
! |
113 |
||
608 | 114 |
asStringCollection |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
115 |
"return the receiver as a stringCollection - that's easy" |
608 | 116 |
|
117 |
^ self |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
118 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
119 |
"Modified (comment): / 25-07-2012 / 18:11:14 / cg" |
608 | 120 |
! |
121 |
||
3601
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
122 |
asStringWithoutEmphasis |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
123 |
"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
|
124 |
|
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
125 |
^ self |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
126 |
asStringWith:Character cr |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
127 |
from:1 to:(self size) |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
128 |
compressTabs:false |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
129 |
final:Character cr |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
130 |
withEmphasis:false |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
131 |
|
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
132 |
"Created: / 17.6.1998 / 12:32:48 / cg" |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
133 |
! |
c879b9a15f38
added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
134 |
|
7829 | 135 |
asStringWithoutFinalCR |
136 |
"return myself as a string with embedded cr's |
|
137 |
but do not add a final CR" |
|
138 |
||
139 |
^ self |
|
140 |
asStringWith:Character cr |
|
141 |
from:1 to:(self size) |
|
142 |
compressTabs:false |
|
143 |
final:nil |
|
144 |
! |
|
145 |
||
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
146 |
encodeFrom:oldEncoding into:newEncoding |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
147 |
"encode each line" |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
148 |
|
7916 | 149 |
|enc| |
150 |
||
151 |
enc := CharacterEncoder encoderToEncodeFrom:oldEncoding into:newEncoding. |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
152 |
^ self |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
153 |
collect:[:line | |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
154 |
line isNil |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
155 |
ifTrue:[ nil ] |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
156 |
ifFalse:[ enc encodeString:line] |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
157 |
] |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
158 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
159 |
"Modified (comment): / 25-07-2012 / 18:09:40 / cg" |
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
160 |
! |
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
161 |
|
1 | 162 |
from:aString |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
163 |
"setup my contents from the argument, aString" |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
164 |
|
11596 | 165 |
<resource: #obsolete> |
1 | 166 |
|
8375
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
167 |
self obsoleteMethodWarning:'use #fromString:'. |
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
168 |
^ self fromString:aString |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
169 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
170 |
"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
|
171 |
! |
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
172 |
|
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
173 |
fromString:aString |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
174 |
"setup my contents from the argument, aString. |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
175 |
AString should be delimited by newline characters" |
8375
b43b5d1c494d
from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
176 |
|
1 | 177 |
|numberOfLines "{ Class:SmallInteger }" |
178 |
start "{ Class:SmallInteger }" |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
179 |
stop "{ Class:SmallInteger }" |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
180 |
delimiter |
6176 | 181 |
| |
1 | 182 |
|
14245 | 183 |
aString isEmpty ifTrue:[self grow:0. ^ self ]. |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
184 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
185 |
delimiter := Character cr. |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
186 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
187 |
numberOfLines := aString occurrencesOf:delimiter. |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
188 |
numberOfLines == 0 ifTrue:[ |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
189 |
"/ check if its a return-delimited string |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
190 |
(aString occurrencesOf:(Character return)) > 0 ifTrue:[ |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
191 |
delimiter := Character return. |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
192 |
]. |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
193 |
]. |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
194 |
aString last == delimiter ifFalse:[ |
6176 | 195 |
numberOfLines := numberOfLines + 1. |
203 | 196 |
]. |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
197 |
|
1 | 198 |
self grow:numberOfLines. |
6176 | 199 |
|
1 | 200 |
start := 1. |
201 |
1 to:numberOfLines do:[:lineNr | |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
202 |
stop := aString indexOf:delimiter startingAt:start. |
6176 | 203 |
stop == 0 ifTrue:[ |
204 |
self at:lineNr put:(aString copyFrom:start). |
|
205 |
self from:lineNr+1 to:numberOfLines put:''. |
|
206 |
^ self. |
|
207 |
]. |
|
10 | 208 |
|
6176 | 209 |
self at:lineNr put:(aString copyFrom:start to:stop-1). |
210 |
start := stop + 1 |
|
1 | 211 |
] |
6176 | 212 |
|
14245 | 213 |
"Modified: / 25-07-2012 / 18:52:58 / cg" |
968 | 214 |
! ! |
215 |
||
216 |
!StringCollection methodsFor:'copying'! |
|
217 |
||
218 |
copyEmpty:size |
|
14111 | 219 |
"we have to redefine this, since 'self class new:size' |
220 |
does allocate size nil lines (it does an implicit #grow: size). |
|
221 |
In order to get #collect: working, we should not perform this implicit grow" |
|
968 | 222 |
|
14111 | 223 |
^ super copyEmpty:0. |
968 | 224 |
|
225 |
"Created: 14.2.1996 / 11:05:47 / stefan" |
|
10452 | 226 |
! |
227 |
||
14111 | 228 |
copyEmptyAndGrow:size |
229 |
"performance optimization: |
|
230 |
StringCollections are always grown to size after #new: / #copyEmpty:" |
|
231 |
||
232 |
^ super copyEmpty:size. |
|
233 |
! |
|
234 |
||
10452 | 235 |
withoutLeadingBlankLines |
236 |
"return a copy of the receiver with leading blank lines removed. |
|
237 |
If there are no leading blank lines, the original receiver is returned. |
|
238 |
If all lines are blank, an empty string collection is returned." |
|
239 |
||
240 |
|indexOfFirstNonBlankLine| |
|
241 |
||
11702 | 242 |
indexOfFirstNonBlankLine := self findFirst:[:line | line notEmptyOrNil and:[line isBlank not]]. |
243 |
indexOfFirstNonBlankLine == 0 ifTrue:[ ^ self copyEmpty ]. |
|
244 |
indexOfFirstNonBlankLine == 1 ifTrue:[ ^ self ]. |
|
245 |
^ self copyFrom:indexOfFirstNonBlankLine |
|
10452 | 246 |
|
247 |
" |
|
248 |
'1 |
|
249 |
2 |
|
250 |
3' asStringCollection withoutLeadingBlankLines |
|
251 |
" |
|
252 |
||
253 |
" |
|
254 |
' |
|
255 |
2 |
|
256 |
3' asStringCollection withoutLeadingBlankLines |
|
257 |
" |
|
258 |
||
259 |
" |
|
260 |
' |
|
261 |
||
11702 | 262 |
' asStringCollection withoutLeadingBlankLines |
263 |
" |
|
264 |
! |
|
265 |
||
266 |
withoutTrailingBlankLines |
|
267 |
"return a copy of the receiver with trailing blank lines removed. |
|
268 |
If there are no trailing blank lines, the original receiver is returned. |
|
269 |
If all lines are blank, an empty string collection is returned." |
|
270 |
||
271 |
|indexOfLastNonBlankLine| |
|
272 |
||
273 |
indexOfLastNonBlankLine := self findLast:[:line | line notEmptyOrNil and:[line isBlank not]]. |
|
274 |
indexOfLastNonBlankLine == 0 ifTrue:[ ^ self copyEmpty ]. |
|
275 |
indexOfLastNonBlankLine == self size ifTrue:[ ^ self ]. |
|
276 |
^ self copyTo:indexOfLastNonBlankLine |
|
277 |
||
278 |
" |
|
279 |
'1 |
|
280 |
2 |
|
17083 | 281 |
3' asStringCollection withoutTrailingBlankLines |
11702 | 282 |
" |
283 |
||
284 |
" |
|
285 |
' |
|
286 |
2 |
|
287 |
3 |
|
288 |
' asStringCollection withoutTrailingBlankLines |
|
289 |
" |
|
290 |
||
291 |
" |
|
292 |
' |
|
17083 | 293 |
2 |
294 |
3 |
|
295 |
||
296 |
||
297 |
' asStringCollection withoutTrailingBlankLines |
|
298 |
" |
|
299 |
" |
|
300 |
' |
|
11702 | 301 |
|
302 |
' asStringCollection withoutTrailingBlankLines |
|
10452 | 303 |
" |
608 | 304 |
! ! |
305 |
||
14111 | 306 |
|
5251 | 307 |
!StringCollection methodsFor:'printing & storing'! |
1 | 308 |
|
10909
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
309 |
printOn:aStream |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
310 |
"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
|
311 |
|
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
312 |
self do:[:eachString| |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
313 |
eachString printOn:aStream. |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
314 |
aStream cr. |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
315 |
]. |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
316 |
! |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
317 |
|
1 | 318 |
printString |
284 | 319 |
"return the receivers printString" |
320 |
||
1 | 321 |
^ self asString |
322 |
! ! |
|
323 |
||
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
324 |
!StringCollection methodsFor:'queries'! |
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
325 |
|
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
326 |
encoding |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
327 |
"the encoding; ask my first line" |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
328 |
|
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
329 |
self do:[:l | l notNil ifTrue:[^ l encoding]]. |
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
330 |
"/ sigh |
14173 | 331 |
^ #unicode |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
332 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
333 |
"Modified (comment): / 25-07-2012 / 18:09:15 / cg" |
13331 | 334 |
! |
335 |
||
336 |
stringSize |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
337 |
"the size of the string if I was converted" |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
338 |
|
13331 | 339 |
^ self inject:0 into:[:sizeSoFar :eachLine | |
340 |
sizeSoFar + eachLine size + 1 |
|
341 |
] |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
342 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
343 |
"Modified (comment): / 25-07-2012 / 18:02:19 / cg" |
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
344 |
! ! |
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
345 |
|
246 | 346 |
!StringCollection methodsFor:'searching'! |
1 | 347 |
|
348 |
indexOfLineStartingWith:aString |
|
349 |
"return the index of the first line starting with the argument, aString" |
|
350 |
||
16460 | 351 |
^ self findFirst:[:l | l notNil and:[l startsWith:aString]] ifNone:0. |
1 | 352 |
|
16460 | 353 |
"/ |sz "{ Class:SmallInteger }" |
354 |
"/ l| |
|
355 |
"/ |
|
356 |
"/ sz := self size. |
|
357 |
"/ 1 to:sz do:[:index | |
|
358 |
"/ l := self at:index. |
|
359 |
"/ (l notNil and:[l startsWith:aString]) ifTrue:[ |
|
360 |
"/ ^ index |
|
361 |
"/ ]. |
|
362 |
"/ ]. |
|
363 |
"/ ^ 0 |
|
1009
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
364 |
|
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
365 |
"Modified: 24.2.1996 / 19:08:47 / cg" |
1 | 366 |
! ! |
608 | 367 |
|
1064 | 368 |
!StringCollection methodsFor:'special converting'! |
369 |
||
14204 | 370 |
decodeFrom: encodingSymbol |
371 |
"given the receiver encoded as described by encodingSymbol, |
|
372 |
convert it into internal ST/X (unicode) encoding and return a |
|
373 |
corresponding StringCollection." |
|
374 |
||
375 |
|myEncoding encoder| |
|
376 |
||
377 |
encodingSymbol isNil ifTrue:[^ self]. |
|
378 |
||
379 |
encoder := CharacterEncoder encoderToEncodeFrom:#unicode into:encodingSymbol. |
|
380 |
encoder isNil ifTrue:[^ self]. |
|
381 |
||
382 |
^ self |
|
383 |
collect:[:eachLineOrNil | |
|
384 |
eachLineOrNil isNil ifTrue:[ |
|
385 |
eachLineOrNil |
|
386 |
] ifFalse:[ |
|
387 |
encoder decodeString: eachLineOrNil |
|
388 |
] |
|
389 |
] |
|
390 |
||
391 |
"Created: / 12-07-2012 / 14:30:25 / cg" |
|
392 |
! |
|
393 |
||
1064 | 394 |
withTabs |
395 |
"return a new stringCollection consisting of the receivers lines, |
|
396 |
where leading spaces are replaced by tabulator characters (assuming 8-col tabs). |
|
397 |
Notice: lines which do not contain leading spaces, are copied by reference to the |
|
398 |
new stringCollection (i.e. shared); |
|
399 |
otherwise new strings is created. |
|
400 |
Limitation: only the very first spaces are replaced" |
|
401 |
||
402 |
^ self collect:[:string| |
|
403 |
string notNil ifTrue:[ |
|
404 |
string withTabs |
|
405 |
] ifFalse:[ |
|
406 |
string |
|
407 |
] |
|
408 |
] |
|
409 |
||
410 |
" |
|
411 |
(' abcd ') asStringCollection withTabs |
|
412 |
" |
|
413 |
||
414 |
"Created: 4.3.1996 / 17:09:07 / cg" |
|
415 |
"Modified: 4.3.1996 / 17:10:37 / cg" |
|
416 |
! |
|
417 |
||
418 |
withTabsExpanded |
|
419 |
"return a new stringCollection consisting of the receivers lines, |
|
420 |
where tabs are replaced by space characters (assuming 8-col tabs). |
|
421 |
Notice: lines which do not contain any tab, are copied by reference to the |
|
422 |
new stringCollection (i.e. shared); |
|
423 |
otherwise new strings is created." |
|
424 |
||
15752 | 425 |
^ self withTabsExpanded:8 |
426 |
||
427 |
" |
|
428 |
|tab| |
|
429 |
tab := String with:Character tab. |
|
430 |
('abcd', tab, 'tef', tab, 'tgh') asStringCollection withTabsExpanded |
|
431 |
" |
|
432 |
||
433 |
"Created: 12.2.1996 / 22:25:56 / stefan" |
|
434 |
"Modified: 14.2.1996 / 11:13:01 / stefan" |
|
435 |
"Modified: 4.3.1996 / 17:10:22 / cg" |
|
436 |
! |
|
437 |
||
438 |
withTabsExpanded:n |
|
439 |
"return a new stringCollection consisting of the receivers lines, |
|
15753 | 440 |
where tabs are replaced by space characters (assuming n-col tabs). |
15752 | 441 |
Notice: lines which do not contain any tab, are copied by reference to the |
442 |
new stringCollection (i.e. shared); |
|
443 |
otherwise new strings is created." |
|
444 |
||
1064 | 445 |
^ self collect:[:string| |
446 |
string notNil ifTrue:[ |
|
15752 | 447 |
string withTabsExpanded:n |
1064 | 448 |
] ifFalse:[ |
449 |
string |
|
450 |
] |
|
451 |
] |
|
452 |
||
453 |
" |
|
454 |
|tab| |
|
455 |
tab := String with:Character tab. |
|
456 |
('abcd', tab, 'tef', tab, 'tgh') asStringCollection withTabsExpanded |
|
457 |
" |
|
458 |
||
459 |
"Created: 12.2.1996 / 22:25:56 / stefan" |
|
460 |
"Modified: 14.2.1996 / 11:13:01 / stefan" |
|
461 |
"Modified: 4.3.1996 / 17:10:22 / cg" |
|
462 |
! ! |
|
463 |
||
4007 | 464 |
!StringCollection methodsFor:'testing'! |
465 |
||
466 |
isStringCollection |
|
467 |
"return true, if the receiver is some kind of stringCollection; |
|
468 |
true is returned here - the method is redefined from Object." |
|
469 |
||
470 |
^ true |
|
471 |
||
472 |
||
473 |
! ! |
|
474 |
||
633 | 475 |
!StringCollection class methodsFor:'documentation'! |
476 |
||
477 |
version |
|
17083 | 478 |
^ '$Header: /cvs/stx/stx/libbasic/StringCollection.st,v 1.51 2014-11-19 15:42:58 cg Exp $' |
13331 | 479 |
! |
480 |
||
481 |
version_CVS |
|
17083 | 482 |
^ '$Header: /cvs/stx/stx/libbasic/StringCollection.st,v 1.51 2014-11-19 15:42:58 cg Exp $' |
633 | 483 |
! ! |
15752 | 484 |