author | Claus Gittinger <cg@exept.de> |
Mon, 13 Feb 2017 20:45:15 +0100 | |
changeset 21439 | 5a7a395dc9b7 |
parent 20479 | ee9742d20db6 |
child 22278 | dd1e56c2ad85 |
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 |
" |
|
20479 | 41 |
StringCollection is a 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:[ |
21439 | 191 |
"/ check if it's a return-delimited string |
14244
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" |
21439 | 216 |
"Modified (format): / 13-02-2017 / 20:31:40 / cg" |
968 | 217 |
! ! |
218 |
||
219 |
!StringCollection methodsFor:'copying'! |
|
220 |
||
221 |
copyEmpty:size |
|
14111 | 222 |
"we have to redefine this, since 'self class new:size' |
223 |
does allocate size nil lines (it does an implicit #grow: size). |
|
224 |
In order to get #collect: working, we should not perform this implicit grow" |
|
968 | 225 |
|
14111 | 226 |
^ super copyEmpty:0. |
968 | 227 |
|
228 |
"Created: 14.2.1996 / 11:05:47 / stefan" |
|
10452 | 229 |
! |
230 |
||
14111 | 231 |
copyEmptyAndGrow:size |
232 |
"performance optimization: |
|
233 |
StringCollections are always grown to size after #new: / #copyEmpty:" |
|
234 |
||
235 |
^ super copyEmpty:size. |
|
236 |
! |
|
237 |
||
19873 | 238 |
withoutLeadingAndTrailingBlankLines |
239 |
"return a copy of the receiver with leading and trailing blank lines removed. |
|
240 |
If there are no trailing blank lines, the original receiver is returned. |
|
241 |
If all lines are blank, an empty string collection is returned." |
|
242 |
||
243 |
^ self withoutLeadingBlankLines withoutTrailingBlankLines. |
|
244 |
||
245 |
" |
|
246 |
'1 |
|
247 |
2 |
|
248 |
3' asStringCollection withoutLeadingAndTrailingBlankLines |
|
249 |
" |
|
250 |
||
251 |
" |
|
252 |
' |
|
253 |
||
254 |
2 |
|
255 |
3 |
|
256 |
||
257 |
' asStringCollection withoutLeadingAndTrailingBlankLines |
|
258 |
" |
|
259 |
! |
|
260 |
||
10452 | 261 |
withoutLeadingBlankLines |
262 |
"return a copy of the receiver with leading blank lines removed. |
|
263 |
If there are no leading blank lines, the original receiver is returned. |
|
264 |
If all lines are blank, an empty string collection is returned." |
|
265 |
||
266 |
|indexOfFirstNonBlankLine| |
|
267 |
||
11702 | 268 |
indexOfFirstNonBlankLine := self findFirst:[:line | line notEmptyOrNil and:[line isBlank not]]. |
269 |
indexOfFirstNonBlankLine == 0 ifTrue:[ ^ self copyEmpty ]. |
|
270 |
indexOfFirstNonBlankLine == 1 ifTrue:[ ^ self ]. |
|
271 |
^ self copyFrom:indexOfFirstNonBlankLine |
|
10452 | 272 |
|
273 |
" |
|
274 |
'1 |
|
275 |
2 |
|
276 |
3' asStringCollection withoutLeadingBlankLines |
|
277 |
" |
|
278 |
||
279 |
" |
|
280 |
' |
|
281 |
2 |
|
282 |
3' asStringCollection withoutLeadingBlankLines |
|
283 |
" |
|
284 |
||
285 |
" |
|
286 |
' |
|
287 |
||
11702 | 288 |
' asStringCollection withoutLeadingBlankLines |
289 |
" |
|
290 |
! |
|
291 |
||
292 |
withoutTrailingBlankLines |
|
293 |
"return a copy of the receiver with trailing blank lines removed. |
|
294 |
If there are no trailing blank lines, the original receiver is returned. |
|
295 |
If all lines are blank, an empty string collection is returned." |
|
296 |
||
297 |
|indexOfLastNonBlankLine| |
|
298 |
||
299 |
indexOfLastNonBlankLine := self findLast:[:line | line notEmptyOrNil and:[line isBlank not]]. |
|
300 |
indexOfLastNonBlankLine == 0 ifTrue:[ ^ self copyEmpty ]. |
|
301 |
indexOfLastNonBlankLine == self size ifTrue:[ ^ self ]. |
|
302 |
^ self copyTo:indexOfLastNonBlankLine |
|
303 |
||
304 |
" |
|
305 |
'1 |
|
306 |
2 |
|
17083 | 307 |
3' asStringCollection withoutTrailingBlankLines |
11702 | 308 |
" |
309 |
||
310 |
" |
|
311 |
' |
|
312 |
2 |
|
313 |
3 |
|
314 |
' asStringCollection withoutTrailingBlankLines |
|
315 |
" |
|
316 |
||
317 |
" |
|
318 |
' |
|
17083 | 319 |
2 |
320 |
3 |
|
321 |
||
322 |
||
323 |
' asStringCollection withoutTrailingBlankLines |
|
324 |
" |
|
325 |
" |
|
326 |
' |
|
11702 | 327 |
|
328 |
' asStringCollection withoutTrailingBlankLines |
|
10452 | 329 |
" |
608 | 330 |
! ! |
331 |
||
14111 | 332 |
|
5251 | 333 |
!StringCollection methodsFor:'printing & storing'! |
1 | 334 |
|
10909
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
335 |
printOn:aStream |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
336 |
"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
|
337 |
|
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
338 |
self do:[:eachString| |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
339 |
eachString printOn:aStream. |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
340 |
aStream cr. |
5f5e63c29ae2
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
10452
diff
changeset
|
341 |
]. |
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 |
|
1 | 344 |
printString |
19466 | 345 |
"return the receiver's printString" |
284 | 346 |
|
1 | 347 |
^ self asString |
348 |
! ! |
|
349 |
||
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
350 |
!StringCollection methodsFor:'queries'! |
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
351 |
|
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
352 |
encoding |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
353 |
"the encoding; ask my first line" |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
354 |
|
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
355 |
self do:[:l | l notNil ifTrue:[^ l encoding]]. |
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
356 |
"/ sigh |
14173 | 357 |
^ #unicode |
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
358 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
359 |
"Modified (comment): / 25-07-2012 / 18:09:15 / cg" |
13331 | 360 |
! |
361 |
||
362 |
stringSize |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
363 |
"the size of the string if I was converted" |
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
364 |
|
13331 | 365 |
^ self inject:0 into:[:sizeSoFar :eachLine | |
366 |
sizeSoFar + eachLine size + 1 |
|
367 |
] |
|
14244
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
368 |
|
d107839eb01b
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
14204
diff
changeset
|
369 |
"Modified (comment): / 25-07-2012 / 18:02:19 / cg" |
7899
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
370 |
! ! |
7577df77ba95
character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents:
7829
diff
changeset
|
371 |
|
246 | 372 |
!StringCollection methodsFor:'searching'! |
1 | 373 |
|
374 |
indexOfLineStartingWith:aString |
|
375 |
"return the index of the first line starting with the argument, aString" |
|
376 |
||
16460 | 377 |
^ self findFirst:[:l | l notNil and:[l startsWith:aString]] ifNone:0. |
1 | 378 |
|
16460 | 379 |
"/ |sz "{ Class:SmallInteger }" |
380 |
"/ l| |
|
381 |
"/ |
|
382 |
"/ sz := self size. |
|
383 |
"/ 1 to:sz do:[:index | |
|
384 |
"/ l := self at:index. |
|
385 |
"/ (l notNil and:[l startsWith:aString]) ifTrue:[ |
|
386 |
"/ ^ index |
|
387 |
"/ ]. |
|
388 |
"/ ]. |
|
389 |
"/ ^ 0 |
|
1009
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
390 |
|
a0354f2fea61
care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents:
968
diff
changeset
|
391 |
"Modified: 24.2.1996 / 19:08:47 / cg" |
1 | 392 |
! ! |
608 | 393 |
|
1064 | 394 |
!StringCollection methodsFor:'special converting'! |
395 |
||
14204 | 396 |
decodeFrom: encodingSymbol |
397 |
"given the receiver encoded as described by encodingSymbol, |
|
398 |
convert it into internal ST/X (unicode) encoding and return a |
|
399 |
corresponding StringCollection." |
|
400 |
||
401 |
|myEncoding encoder| |
|
402 |
||
403 |
encodingSymbol isNil ifTrue:[^ self]. |
|
404 |
||
405 |
encoder := CharacterEncoder encoderToEncodeFrom:#unicode into:encodingSymbol. |
|
406 |
encoder isNil ifTrue:[^ self]. |
|
407 |
||
408 |
^ self |
|
409 |
collect:[:eachLineOrNil | |
|
410 |
eachLineOrNil isNil ifTrue:[ |
|
411 |
eachLineOrNil |
|
412 |
] ifFalse:[ |
|
413 |
encoder decodeString: eachLineOrNil |
|
414 |
] |
|
415 |
] |
|
416 |
||
417 |
"Created: / 12-07-2012 / 14:30:25 / cg" |
|
418 |
! |
|
419 |
||
1064 | 420 |
withTabs |
19466 | 421 |
"return a new stringCollection consisting of the receiver's lines, |
1064 | 422 |
where leading spaces are replaced by tabulator characters (assuming 8-col tabs). |
423 |
Notice: lines which do not contain leading spaces, are copied by reference to the |
|
424 |
new stringCollection (i.e. shared); |
|
425 |
otherwise new strings is created. |
|
426 |
Limitation: only the very first spaces are replaced" |
|
427 |
||
428 |
^ self collect:[:string| |
|
429 |
string notNil ifTrue:[ |
|
430 |
string withTabs |
|
431 |
] ifFalse:[ |
|
432 |
string |
|
433 |
] |
|
434 |
] |
|
435 |
||
436 |
" |
|
437 |
(' abcd ') asStringCollection withTabs |
|
438 |
" |
|
439 |
||
440 |
"Created: 4.3.1996 / 17:09:07 / cg" |
|
441 |
"Modified: 4.3.1996 / 17:10:37 / cg" |
|
442 |
! |
|
443 |
||
444 |
withTabsExpanded |
|
19466 | 445 |
"return a new stringCollection consisting of the receiver's lines, |
1064 | 446 |
where tabs are replaced by space characters (assuming 8-col tabs). |
447 |
Notice: lines which do not contain any tab, are copied by reference to the |
|
448 |
new stringCollection (i.e. shared); |
|
449 |
otherwise new strings is created." |
|
450 |
||
15752 | 451 |
^ self withTabsExpanded:8 |
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 |
||
464 |
withTabsExpanded:n |
|
19466 | 465 |
"return a new stringCollection consisting of the receiver's lines, |
15753 | 466 |
where tabs are replaced by space characters (assuming n-col tabs). |
15752 | 467 |
Notice: lines which do not contain any tab, are copied by reference to the |
468 |
new stringCollection (i.e. shared); |
|
469 |
otherwise new strings is created." |
|
470 |
||
1064 | 471 |
^ self collect:[:string| |
472 |
string notNil ifTrue:[ |
|
15752 | 473 |
string withTabsExpanded:n |
1064 | 474 |
] ifFalse:[ |
475 |
string |
|
476 |
] |
|
477 |
] |
|
478 |
||
479 |
" |
|
480 |
|tab| |
|
481 |
tab := String with:Character tab. |
|
482 |
('abcd', tab, 'tef', tab, 'tgh') asStringCollection withTabsExpanded |
|
483 |
" |
|
484 |
||
485 |
"Created: 12.2.1996 / 22:25:56 / stefan" |
|
486 |
"Modified: 14.2.1996 / 11:13:01 / stefan" |
|
487 |
"Modified: 4.3.1996 / 17:10:22 / cg" |
|
488 |
! ! |
|
489 |
||
4007 | 490 |
!StringCollection methodsFor:'testing'! |
491 |
||
492 |
isStringCollection |
|
493 |
"return true, if the receiver is some kind of stringCollection; |
|
494 |
true is returned here - the method is redefined from Object." |
|
495 |
||
496 |
^ true |
|
497 |
||
498 |
||
499 |
! ! |
|
500 |
||
633 | 501 |
!StringCollection class methodsFor:'documentation'! |
502 |
||
503 |
version |
|
19466 | 504 |
^ '$Header$' |
13331 | 505 |
! |
506 |
||
507 |
version_CVS |
|
19466 | 508 |
^ '$Header$' |
633 | 509 |
! ! |
15752 | 510 |