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