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