64
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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 |
"
|
|
12 |
|
|
13 |
ByteArray subclass:#AbstractString
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Collections-Text'
|
|
18 |
!
|
|
19 |
|
|
20 |
AbstractString comment:'
|
|
21 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
82
|
22 |
All Rights Reserved
|
92
|
23 |
|
|
24 |
$Header: /cvs/stx/stx/libbasic/Attic/CharArray.st,v 1.5 1994-08-05 00:53:36 claus Exp $
|
64
|
25 |
'!
|
|
26 |
|
|
27 |
!AbstractString class methodsFor:'documentation'!
|
|
28 |
|
82
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
92
|
45 |
$Header: /cvs/stx/stx/libbasic/Attic/CharArray.st,v 1.5 1994-08-05 00:53:36 claus Exp $
|
82
|
46 |
"
|
|
47 |
!
|
|
48 |
|
64
|
49 |
documentation
|
|
50 |
"
|
68
|
51 |
AbstractString is a superclass for all kinds of Strings (i.e.
|
|
52 |
(singleByte-)Strings, TwoByteStrings and whatever comes in the future.
|
64
|
53 |
"
|
|
54 |
! !
|
|
55 |
|
|
56 |
!AbstractString class methodsFor:'instance creation'!
|
|
57 |
|
|
58 |
basicNew
|
|
59 |
"return a new empty string"
|
|
60 |
|
|
61 |
^ self basicNew:0
|
|
62 |
!
|
|
63 |
|
|
64 |
new
|
|
65 |
"return a new empty string"
|
|
66 |
|
|
67 |
^ self basicNew:0
|
|
68 |
!
|
|
69 |
|
|
70 |
fromString:aString
|
|
71 |
"return a copy of the argument, aString"
|
|
72 |
|
68
|
73 |
^ (self basicNew:(aString size)) replaceFrom:1 with:aString
|
|
74 |
|
|
75 |
"TwoByteString fromString:'hello'"
|
64
|
76 |
! !
|
|
77 |
|
|
78 |
!AbstractString methodsFor:'converting'!
|
|
79 |
|
|
80 |
asUppercase
|
|
81 |
"return a copy of myself in uppercase letters"
|
|
82 |
|
|
83 |
|newStr
|
|
84 |
mySize "{ Class: SmallInteger }" |
|
|
85 |
|
|
86 |
mySize := self size.
|
|
87 |
newStr := self species new:mySize.
|
|
88 |
1 to:mySize do:[:i |
|
|
89 |
newStr at:i put:(self at:i) asUppercase
|
|
90 |
].
|
|
91 |
^newStr
|
|
92 |
!
|
|
93 |
|
|
94 |
asLowercase
|
|
95 |
"return a copy of myself in lowercase letters"
|
|
96 |
|
|
97 |
|newStr
|
|
98 |
mySize "{ Class: SmallInteger }" |
|
|
99 |
|
|
100 |
mySize := self size.
|
|
101 |
newStr := self species new:mySize.
|
|
102 |
1 to:mySize do:[:i |
|
|
103 |
newStr at:i put:(self at:i) asLowercase
|
|
104 |
].
|
|
105 |
^newStr
|
|
106 |
!
|
|
107 |
|
|
108 |
asString
|
|
109 |
"return myself - I am a string"
|
|
110 |
|
|
111 |
^ self
|
|
112 |
!
|
|
113 |
|
68
|
114 |
asTwoByteString
|
|
115 |
"return the receiver converted to a two-byte string"
|
|
116 |
|
|
117 |
^ TwoByteString fromString:self
|
|
118 |
!
|
|
119 |
|
|
120 |
asSingleByteString
|
|
121 |
"return the receiver converted to a 'normal' string"
|
|
122 |
|
|
123 |
^ String fromString:self
|
|
124 |
!
|
|
125 |
|
64
|
126 |
asText
|
68
|
127 |
"return a Text-object (collection of lines) from myself.
|
|
128 |
BIG warning: Text is totally misnamed here
|
|
129 |
- ST/X's Text has nothing to do with PP's Text.
|
82
|
130 |
Therefore it will be removed/renamed soon."
|
64
|
131 |
|
|
132 |
^ Text from:self
|
|
133 |
!
|
|
134 |
|
|
135 |
asNumber
|
|
136 |
"read a number from the receiver"
|
|
137 |
|
|
138 |
^ Number readFromString:self
|
|
139 |
|
92
|
140 |
"
|
|
141 |
'123' asNumber
|
|
142 |
'123.567' asNumber
|
|
143 |
'(5/6)' asNumber
|
|
144 |
"
|
|
145 |
!
|
|
146 |
|
|
147 |
asInteger
|
|
148 |
"read an integer from the receiver"
|
|
149 |
|
|
150 |
^ Integer readFromString:self
|
|
151 |
|
|
152 |
"
|
|
153 |
'12345678901234567890' asInteger
|
|
154 |
'-1234' asInteger
|
|
155 |
'0.123' asInteger <- reader stops at ., returning 0 here
|
|
156 |
'0.123' asNumber <- returns what you expect
|
|
157 |
"
|
|
158 |
!
|
|
159 |
|
|
160 |
asFloat
|
|
161 |
"read an float from the receiver"
|
|
162 |
|
|
163 |
^ (Number readFromString:self) asFloat
|
|
164 |
|
|
165 |
"
|
|
166 |
'0.123' asFloat
|
|
167 |
'12345' asFloat
|
|
168 |
'(1/5)' asFloat
|
|
169 |
"
|
64
|
170 |
!
|
|
171 |
|
|
172 |
asFilename
|
|
173 |
"return a Filename with pathname taken from the receiver"
|
|
174 |
|
|
175 |
^ Filename named:self
|
|
176 |
!
|
|
177 |
|
|
178 |
asCollectionOfWords
|
|
179 |
"return a collection containing the words (separated by whitespace)
|
|
180 |
of the receiver"
|
|
181 |
|
68
|
182 |
|words ch
|
|
183 |
start "{ Class:SmallInteger }"
|
|
184 |
stop "{ Class:SmallInteger }"
|
|
185 |
mySize "{ Class:SmallInteger }"|
|
64
|
186 |
|
|
187 |
words := OrderedCollection new.
|
|
188 |
start := 1.
|
|
189 |
mySize := self size.
|
|
190 |
[start <= mySize] whileTrue:[
|
92
|
191 |
start := self indexOfNonSeparatorStartingAt:start.
|
|
192 |
start == 0 ifTrue:[
|
|
193 |
^ words
|
|
194 |
].
|
|
195 |
stop := self indexOfSeparatorStartingAt:start.
|
|
196 |
stop == 0 ifTrue:[
|
|
197 |
words add:(self copyFrom:start to:mySize).
|
|
198 |
^ words
|
|
199 |
].
|
|
200 |
words add:(self copyFrom:start to:(stop - 1)).
|
|
201 |
start := stop
|
|
202 |
|
|
203 |
"/ ch := self at:start.
|
|
204 |
"/ ((ch == Character space) or:[ch isSeparator]) ifTrue:[
|
|
205 |
"/ start := start + 1
|
|
206 |
"/ ] ifFalse:[
|
|
207 |
"/ stop := self indexOfSeparatorStartingAt:start.
|
|
208 |
"/ stop == 0 ifTrue:[
|
|
209 |
"/ words add:(self copyFrom:start to:mySize).
|
|
210 |
"/ ^ words
|
|
211 |
"/ ].
|
|
212 |
"/ words add:(self copyFrom:start to:(stop - 1)).
|
|
213 |
"/ start := stop
|
|
214 |
"/ ]
|
64
|
215 |
].
|
|
216 |
^ words
|
|
217 |
|
92
|
218 |
"
|
|
219 |
'hello world isnt this nice' asCollectionOfWords
|
|
220 |
' hello world isnt this nice ' asCollectionOfWords
|
|
221 |
'hello' asCollectionOfWords
|
|
222 |
'' asCollectionOfWords
|
|
223 |
' ' asCollectionOfWords
|
|
224 |
"
|
68
|
225 |
!
|
|
226 |
|
|
227 |
asCollectionOfLines
|
|
228 |
"return a collection containing the lines (separated by cr)
|
|
229 |
of the receiver."
|
|
230 |
|
|
231 |
|lines myClass
|
|
232 |
numberOfLines "{ Class:SmallInteger }"
|
|
233 |
startIndex "{ Class:SmallInteger }"
|
|
234 |
stopIndex "{ Class:SmallInteger }" |
|
|
235 |
|
|
236 |
"count first, to avoid regrowing"
|
|
237 |
|
|
238 |
numberOfLines := (self occurrencesOf:Character cr) + 1.
|
|
239 |
lines := OrderedCollection new:numberOfLines.
|
|
240 |
myClass := self species.
|
|
241 |
|
|
242 |
startIndex := 1.
|
|
243 |
1 to:numberOfLines do:[:lineNr |
|
|
244 |
stopIndex := self indexOf:(Character cr) startingAt:startIndex.
|
|
245 |
stopIndex == 0 ifTrue:[
|
|
246 |
stopIndex := self size
|
|
247 |
] ifFalse: [
|
|
248 |
stopIndex := stopIndex - 1.
|
|
249 |
].
|
|
250 |
|
|
251 |
(stopIndex < startIndex) ifTrue: [
|
|
252 |
lines add:(myClass new:0)
|
|
253 |
] ifFalse: [
|
|
254 |
lines add:(self copyFrom:startIndex to:stopIndex)
|
|
255 |
].
|
|
256 |
startIndex := stopIndex + 2
|
|
257 |
].
|
|
258 |
^ lines
|
|
259 |
|
|
260 |
"
|
|
261 |
'1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines
|
|
262 |
'1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfWords
|
|
263 |
"
|
92
|
264 |
!
|
|
265 |
|
|
266 |
asArrayOfSubstrings
|
|
267 |
"return an array of substrings from the receiver, interpreting
|
|
268 |
separators (i.e. spaces & newlines) as work-delimiters.
|
|
269 |
This is a compatibility method - the actual work is done in
|
|
270 |
asCollectionOfWords."
|
|
271 |
|
|
272 |
^ self asCollectionOfWords asArray
|
|
273 |
|
|
274 |
"
|
|
275 |
'1 one two three four 5 five' asArrayOfSubstrings
|
|
276 |
"
|
|
277 |
! !
|
|
278 |
|
|
279 |
!AbstractString methodsFor:'ST/V compatibility'!
|
|
280 |
|
|
281 |
replChar:oldChar with:newChar
|
|
282 |
"return a copy of the receiver, with all oldChars replaced
|
|
283 |
by newChar"
|
|
284 |
|
|
285 |
^ self copy replaceAll:oldChar by:newChar
|
|
286 |
|
|
287 |
"
|
|
288 |
'12345678901234567890' replChar:$0 with:$*
|
|
289 |
"
|
|
290 |
!
|
|
291 |
|
|
292 |
replChar:oldChar withString:newString
|
|
293 |
"return a copy of the receiver, with all oldChars replaced
|
|
294 |
by newString (i.e. slice in the newString in place of the oldChar)"
|
|
295 |
|
|
296 |
|tmpStream|
|
|
297 |
|
|
298 |
tmpStream := WriteStream on:(self class new).
|
|
299 |
self do:[:element |
|
|
300 |
element = oldChar ifTrue:[
|
|
301 |
tmpStream nextPutAll:newString
|
|
302 |
] ifFalse:[
|
|
303 |
tmpStream nextPut:element
|
|
304 |
].
|
|
305 |
].
|
|
306 |
^ tmpStream contents
|
|
307 |
|
|
308 |
"
|
|
309 |
'12345678901234567890' replChar:$0 withString:'foo'
|
|
310 |
'a string with spaces' replChar:$ withString:' foo '
|
|
311 |
"
|
|
312 |
!
|
|
313 |
|
|
314 |
trimBlanks
|
|
315 |
"return a copy of the receiver without leading
|
|
316 |
and trailing spaces"
|
|
317 |
|
|
318 |
^ self withoutSpaces
|
|
319 |
|
|
320 |
"
|
|
321 |
' spaces at beginning' trimBlanks
|
|
322 |
'spaces at end ' trimBlanks
|
|
323 |
' spaces at beginning and end ' trimBlanks
|
|
324 |
'no spaces' trimBlanks
|
|
325 |
"
|
|
326 |
!
|
|
327 |
|
|
328 |
byteAt:index put:aByte
|
|
329 |
"store a byte at given index"
|
|
330 |
|
|
331 |
(aByte == 0) ifTrue:[
|
|
332 |
"store a space instead"
|
|
333 |
^ super basicAt:index put:(Character space)
|
|
334 |
].
|
|
335 |
^ super at:index put:(Character value:aByte)
|
64
|
336 |
! !
|
|
337 |
|
|
338 |
!AbstractString methodsFor:'printing & storing'!
|
|
339 |
|
82
|
340 |
article
|
|
341 |
"return an article string"
|
|
342 |
|
|
343 |
|firstChar|
|
|
344 |
|
|
345 |
firstChar := (self at:1) asLowercase.
|
|
346 |
(firstChar isVowel or:[firstChar == $x]) ifTrue:[
|
|
347 |
^ 'an'
|
|
348 |
].
|
|
349 |
^ 'a'
|
|
350 |
!
|
|
351 |
|
64
|
352 |
printOn:aStream
|
|
353 |
"print the receiver on aStream"
|
|
354 |
|
|
355 |
aStream nextPutAll:self
|
|
356 |
!
|
|
357 |
|
|
358 |
printString
|
|
359 |
"return a string for printing - thats myself"
|
|
360 |
|
|
361 |
^ self
|
|
362 |
!
|
|
363 |
|
|
364 |
displayString
|
|
365 |
"return a string to display the receiver - use storeString to have
|
|
366 |
quotes around"
|
|
367 |
|
|
368 |
^ self storeString
|
|
369 |
! !
|
|
370 |
|
|
371 |
!AbstractString methodsFor:'comparing'!
|
|
372 |
|
|
373 |
hash
|
|
374 |
"return an integer useful as a hash-key"
|
|
375 |
|
|
376 |
%{ /* NOCONTEXT */
|
|
377 |
|
|
378 |
REGISTER int g, val;
|
|
379 |
REGISTER unsigned char *cp, *cp0;
|
|
380 |
int l;
|
|
381 |
|
|
382 |
cp = _stringVal(self);
|
|
383 |
l = _stringSize(self);
|
|
384 |
if (_qClass(self) != String) {
|
92
|
385 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(_qClass(self))->c_ninstvars));
|
64
|
386 |
|
|
387 |
cp += n;
|
|
388 |
l -= n;
|
|
389 |
}
|
|
390 |
|
|
391 |
/*
|
|
392 |
* this is the dragon-book algorithm with a funny start
|
|
393 |
* value (to give short strings a number above 8192)
|
|
394 |
*/
|
|
395 |
val = 12345;
|
|
396 |
for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) {
|
|
397 |
val = (val << 5) + (*cp & 0x1F);
|
|
398 |
if (g = (val & 0x3E000000))
|
|
399 |
val ^= g >> 25 /* 23 */ /* 25 */;
|
|
400 |
val &= 0x3FFFFFFF;
|
|
401 |
}
|
|
402 |
|
|
403 |
if (l) {
|
|
404 |
l |= 1;
|
|
405 |
val = (val * l) & 0x3FFFFFFF;
|
|
406 |
}
|
|
407 |
|
|
408 |
RETURN ( _MKSMALLINT(val) );
|
|
409 |
%}
|
|
410 |
!
|
|
411 |
|
|
412 |
<= something
|
|
413 |
"Compare the receiver with the argument and return true if the
|
|
414 |
receiver is less than or equal to the argument. Otherwise return false."
|
|
415 |
|
|
416 |
^ (self > something) not
|
|
417 |
!
|
|
418 |
|
|
419 |
< something
|
|
420 |
"Compare the receiver with the argument and return true if the
|
|
421 |
receiver is less than the argument. Otherwise return false."
|
|
422 |
|
|
423 |
^ (something > self)
|
|
424 |
!
|
|
425 |
|
|
426 |
>= something
|
|
427 |
"Compare the receiver with the argument and return true if the
|
|
428 |
receiver is greater than or equal to the argument.
|
|
429 |
Otherwise return false."
|
|
430 |
|
|
431 |
^ (something > self) not
|
|
432 |
!
|
|
433 |
|
|
434 |
> aString
|
|
435 |
"Compare the receiver with the argument and return true if the
|
|
436 |
receiver is greater than the argument. Otherwise return false.
|
|
437 |
In contrast to ST-80, case differences are NOT ignored, thus
|
|
438 |
'foo' > 'Foo' will return true.
|
|
439 |
This may change."
|
|
440 |
|
92
|
441 |
|mySize "{ Class: SmallInteger }"
|
|
442 |
otherSize "{ Class: SmallInteger }"
|
|
443 |
c1 c2|
|
64
|
444 |
|
|
445 |
mySize := self size.
|
|
446 |
otherSize := aString size.
|
|
447 |
|
|
448 |
1 to:(mySize min:otherSize) do:[:index |
|
|
449 |
c1 := self at:index.
|
|
450 |
c2 := aString at:index.
|
|
451 |
c1 > c2 ifTrue:[^ true].
|
|
452 |
c1 < c2 ifTrue:[^ false].
|
|
453 |
].
|
|
454 |
^ mySize > otherSize
|
|
455 |
!
|
|
456 |
|
|
457 |
= aString
|
|
458 |
"Compare the receiver with the argument and return true if the
|
92
|
459 |
receiver is equal to the argument. Otherwise return false.
|
|
460 |
This compare doe NOT ignore case differences,
|
|
461 |
therefore 'foo' = 'Foo' will return false."
|
64
|
462 |
|
92
|
463 |
|mySize "{ Class: SmallInteger }"
|
|
464 |
otherSize |
|
64
|
465 |
|
|
466 |
mySize := self size.
|
|
467 |
otherSize := aString size.
|
|
468 |
mySize == otherSize ifFalse:[^ false].
|
|
469 |
|
|
470 |
1 to:mySize do:[:index |
|
|
471 |
(self at:index) = (aString at:index) ifFalse:[^ false].
|
|
472 |
].
|
|
473 |
^ true
|
92
|
474 |
|
|
475 |
"
|
|
476 |
'foo' = 'Foo'
|
|
477 |
'foo' = 'bar'
|
|
478 |
'foo' = 'foo'
|
|
479 |
"
|
64
|
480 |
!
|
|
481 |
|
|
482 |
sameAs:aString
|
|
483 |
"Compare the receiver with the argument like =, but ignore
|
|
484 |
case differences. Return true or false"
|
|
485 |
|
92
|
486 |
|mySize "{ Class: SmallInteger }"
|
|
487 |
otherSize c1 c2|
|
64
|
488 |
|
|
489 |
mySize := self size.
|
|
490 |
otherSize := aString size.
|
|
491 |
mySize == otherSize ifFalse:[^ false].
|
|
492 |
|
|
493 |
1 to:mySize do:[:index |
|
92
|
494 |
c1 := self at:index.
|
|
495 |
c2 := aString at:index.
|
|
496 |
c1 == c2 ifFalse:[
|
|
497 |
c1 asLowercase = c2 asLowercase ifFalse:[^ false].
|
|
498 |
]
|
64
|
499 |
].
|
|
500 |
^ true
|
92
|
501 |
|
|
502 |
"
|
|
503 |
'foo' sameAs: 'Foo'
|
|
504 |
'foo' sameAs: 'bar'
|
|
505 |
'foo' sameAs: 'foo'
|
|
506 |
"
|
64
|
507 |
! !
|
|
508 |
|
|
509 |
!AbstractString methodsFor:'character searching'!
|
|
510 |
|
|
511 |
includesMatchCharacters
|
|
512 |
"return true if the receiver includes any meta characters (i.e. $* or $#)
|
|
513 |
for match operations; false if not"
|
|
514 |
|
|
515 |
^ self includesAny:'*#['
|
|
516 |
!
|
|
517 |
|
68
|
518 |
indexOfSeparator
|
|
519 |
"return the index of the first whitespace character"
|
|
520 |
|
|
521 |
^ self indexOfSeparatorStartingAt:1
|
|
522 |
|
|
523 |
"'hello world' indexOfSeparator"
|
|
524 |
!
|
|
525 |
|
92
|
526 |
indexOfSeparatorStartingAt:startIndex
|
68
|
527 |
"return the index of the next whitespace character"
|
64
|
528 |
|
92
|
529 |
|start "{ Class: SmallInteger }"
|
|
530 |
mySize "{ Class: SmallInteger }"|
|
|
531 |
|
|
532 |
start := startIndex.
|
|
533 |
mySize := self size.
|
|
534 |
|
|
535 |
start to:mySize do:[:index |
|
64
|
536 |
(self at:index) isSeparator ifTrue:[^ index]
|
|
537 |
].
|
|
538 |
^ 0
|
|
539 |
|
|
540 |
"'hello world' indexOfSeparatorStartingAt:3"
|
92
|
541 |
!
|
|
542 |
|
|
543 |
indexOfNonSeparatorStartingAt:startIndex
|
|
544 |
"return the index of the next non-whitespace character"
|
|
545 |
|
|
546 |
|start "{ Class: SmallInteger }"
|
|
547 |
mySize "{ Class: SmallInteger }"|
|
|
548 |
|
|
549 |
start := startIndex.
|
|
550 |
mySize := self size.
|
|
551 |
|
|
552 |
start to:mySize do:[:index |
|
|
553 |
(self at:index) isSeparator ifFalse:[^ index]
|
|
554 |
].
|
|
555 |
^ 0
|
|
556 |
|
|
557 |
"
|
|
558 |
' hello world' indexOfNonSeparatorStartingAt:1
|
|
559 |
"
|
|
560 |
"
|
|
561 |
|s index1 index2|
|
|
562 |
s := ' foo bar baz'.
|
|
563 |
index1 := s indexOfNonSeparatorStartingAt:1.
|
|
564 |
index2 := s indexOfSeparatorStartingAt:index1.
|
|
565 |
s copyFrom:index1 to:index2 - 1
|
|
566 |
"
|
64
|
567 |
! !
|
|
568 |
|
|
569 |
!AbstractString methodsFor:'substring searching'!
|
|
570 |
|
|
571 |
findString:subString
|
|
572 |
"find a substring. if found, return the index;
|
92
|
573 |
if not found, return 0."
|
64
|
574 |
|
|
575 |
^ self findString:subString startingAt:1 ifAbsent:[0]
|
|
576 |
|
92
|
577 |
"
|
|
578 |
'hello world' findString:'llo'
|
|
579 |
'hello world' findString:'ole'
|
|
580 |
"
|
64
|
581 |
!
|
|
582 |
|
|
583 |
findString:subString startingAt:index
|
|
584 |
"find a substring, starting at index. if found, return the index;
|
92
|
585 |
if not found, return 0."
|
64
|
586 |
|
|
587 |
^ self findString:subString startingAt:index ifAbsent:[0]
|
|
588 |
|
92
|
589 |
"
|
|
590 |
'hello yello' findString:'llo' startingAt:1
|
|
591 |
'hello yello' findString:'llo' startingAt:5
|
|
592 |
'hello yello' findString:'llo' startingAt:15
|
|
593 |
"
|
64
|
594 |
!
|
|
595 |
|
|
596 |
findString:subString startingAt:index ifAbsent:exceptionBlock
|
|
597 |
"find a substring, starting at index. if found, return the index;
|
|
598 |
if not found, return the result of evaluating exceptionBlock.
|
|
599 |
This is a q&d hack - not very efficient"
|
|
600 |
|
|
601 |
|firstChar found
|
|
602 |
startIndex "{ Class: SmallInteger }"
|
|
603 |
subSize "{ Class: SmallInteger }"
|
|
604 |
mySize "{ Class: SmallInteger }"
|
|
605 |
runIdx "{ Class: SmallInteger }" |
|
|
606 |
|
|
607 |
subSize := subString size.
|
|
608 |
subSize == 0 ifTrue:[^ index]. "empty string matches"
|
|
609 |
mySize := self size.
|
|
610 |
firstChar := subString at:1.
|
|
611 |
startIndex := self indexOf:firstChar startingAt:index.
|
|
612 |
[startIndex == 0] whileFalse:[
|
|
613 |
runIdx := startIndex.
|
|
614 |
found := true.
|
|
615 |
1 to:subSize do:[:i |
|
|
616 |
runIdx > mySize ifTrue:[
|
|
617 |
found := false
|
|
618 |
] ifFalse:[
|
|
619 |
(subString at:i) ~~ (self at:runIdx) ifTrue:[
|
|
620 |
found := false
|
|
621 |
]
|
|
622 |
].
|
|
623 |
runIdx := runIdx + 1
|
|
624 |
].
|
|
625 |
found ifTrue:[
|
|
626 |
^ startIndex
|
|
627 |
].
|
|
628 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1)
|
|
629 |
].
|
|
630 |
^ exceptionBlock value
|
|
631 |
! !
|
|
632 |
|
|
633 |
!AbstractString methodsFor:'pattern matching'!
|
|
634 |
|
|
635 |
from:matchStart to:matchStop match:aString from:start to:stop
|
|
636 |
"helper for match; return true if the characters from start to stop in
|
|
637 |
aString are matching the receivers characters from matchStart to matchStop.
|
|
638 |
The receiver may contain meta-match characters $* (to match any string)
|
92
|
639 |
or $# (to match any character) or [...] (to match from a set of characters).
|
|
640 |
This algorithm is not very efficient; for heavy duty pattern matching,
|
|
641 |
an interface (primitive) to the regex pattern matching package should be
|
|
642 |
added."
|
64
|
643 |
|
|
644 |
|matchChar
|
|
645 |
mStart "{ Class: SmallInteger }"
|
|
646 |
mStop "{ Class: SmallInteger }"
|
|
647 |
sStart "{ Class: SmallInteger }"
|
|
648 |
sStop "{ Class: SmallInteger }"
|
|
649 |
mSize "{ Class: SmallInteger }"
|
|
650 |
sSize "{ Class: SmallInteger }"
|
|
651 |
index cont matchLast
|
|
652 |
matchSet c1 c2|
|
|
653 |
|
|
654 |
mStart := matchStart.
|
|
655 |
mStop := matchStop.
|
|
656 |
sStart := start.
|
|
657 |
sStop := stop.
|
|
658 |
|
|
659 |
[true] whileTrue:[
|
|
660 |
mSize := mStop - mStart + 1.
|
|
661 |
sSize := sStop - sStart + 1.
|
|
662 |
|
|
663 |
"empty strings match"
|
|
664 |
(mSize == 0) ifTrue:[^ (sSize == 0)].
|
|
665 |
|
|
666 |
matchChar := self at:mStart.
|
|
667 |
|
|
668 |
(matchChar == $#) ifTrue:[
|
|
669 |
"testString empty -> no match"
|
|
670 |
(sSize == 0) ifTrue:[^ false].
|
|
671 |
"# matches single character"
|
|
672 |
((sSize == 1) and:[mSize == 1]) ifTrue:[^ true].
|
|
673 |
"cut off 1st chars and continue"
|
|
674 |
mStart := mStart + 1.
|
|
675 |
sStart := sStart + 1
|
|
676 |
] ifFalse:[
|
|
677 |
(matchChar == $[) ifTrue:[
|
|
678 |
"testString empty -> no match"
|
|
679 |
(sSize == 0) ifTrue:[^ false].
|
|
680 |
|
|
681 |
matchSet := Set new.
|
|
682 |
c1 := nil.
|
|
683 |
[matchChar == $]] whileFalse:[
|
|
684 |
mStart := mStart + 1.
|
|
685 |
mSize := mSize - 1.
|
|
686 |
matchChar := self at:mStart.
|
|
687 |
((matchChar == $-) and:[c1 notNil]) ifTrue:[
|
|
688 |
mStart := mStart + 1.
|
|
689 |
mSize := mSize - 1.
|
|
690 |
c2 := self at:mStart.
|
|
691 |
(c1 to:c2) do:[:c | matchSet add:c].
|
|
692 |
c1 := nil
|
|
693 |
] ifFalse:[
|
|
694 |
(matchChar == $]) ifFalse:[
|
|
695 |
matchSet add:matchChar.
|
|
696 |
c1 := matchChar.
|
|
697 |
].
|
|
698 |
].
|
|
699 |
].
|
|
700 |
mStart := mStart + 1.
|
|
701 |
mSize := mSize - 1.
|
|
702 |
(matchSet includes:(aString at:sStart)) ifFalse:[^ false].
|
|
703 |
((sSize == 1) and:[mSize == 0]) ifTrue:[^ true].
|
|
704 |
"cut off 1st char and continue"
|
|
705 |
sStart := sStart + 1
|
|
706 |
] ifFalse:[
|
|
707 |
(matchChar == $*) ifTrue:[
|
|
708 |
"* matches anything"
|
|
709 |
(mSize == 1) ifTrue:[^ true].
|
|
710 |
"testString empty -> matchString not we have no match"
|
|
711 |
(sSize == 0) ifTrue:[^ false].
|
|
712 |
|
|
713 |
"try to avoid some of the recursion by checking last
|
|
714 |
character and continue with shortened strings if possible"
|
|
715 |
cont := false.
|
|
716 |
(mStop >= mStart) ifTrue:[
|
|
717 |
matchLast := self at:mStop.
|
|
718 |
(matchLast ~~ $*) ifTrue:[
|
|
719 |
(matchLast == $#) ifTrue:[
|
|
720 |
cont := true
|
|
721 |
] ifFalse:[
|
|
722 |
(matchLast == (aString at:sStop)) ifTrue:[
|
|
723 |
cont := true
|
|
724 |
]
|
|
725 |
]
|
|
726 |
]
|
|
727 |
].
|
|
728 |
cont ifFalse:[
|
|
729 |
index := sStart.
|
|
730 |
[index <= sStop] whileTrue:[
|
|
731 |
(self from:(mStart + 1) to:mStop match:aString
|
|
732 |
from:index to:sStop) ifTrue:[
|
|
733 |
^ true
|
|
734 |
].
|
|
735 |
index := index + 1
|
|
736 |
].
|
|
737 |
^ false
|
|
738 |
].
|
|
739 |
mStop := mStop - 1.
|
|
740 |
sStop := sStop - 1
|
|
741 |
] ifFalse:[
|
|
742 |
|
|
743 |
"testString empty ?"
|
|
744 |
(sSize == 0) ifTrue:[^ false].
|
|
745 |
|
|
746 |
"first characters equal ?"
|
|
747 |
((aString at:sStart) ~~ matchChar) ifTrue:[^ false].
|
|
748 |
|
|
749 |
"avoid recursion if possible"
|
|
750 |
((sSize == mSize) and:[self = aString]) ifTrue:[^ true].
|
|
751 |
|
|
752 |
"cut off 1st chars and continue"
|
|
753 |
mStart := mStart + 1.
|
|
754 |
sStart := sStart + 1
|
|
755 |
]
|
|
756 |
]
|
|
757 |
]
|
|
758 |
]
|
|
759 |
!
|
|
760 |
|
|
761 |
match:aString
|
|
762 |
"return true if aString matches self, where self may contain meta-match
|
|
763 |
characters $* (to match any string) or $# (to match any character)."
|
|
764 |
|
|
765 |
^ self from:1 to:(self size) match:aString from:1 to:(aString size)
|
|
766 |
|
92
|
767 |
"
|
|
768 |
'*ute*' match:'computer'
|
|
769 |
'*uter' match:'computer'
|
|
770 |
'uter*' match:'computer'
|
|
771 |
'*ute*' match:''
|
|
772 |
'[abcd]*' match:'computer'
|
|
773 |
'[abcd]*' match:'komputer'
|
|
774 |
'*some*compl*ern*' match:'this is some more complicated pattern match'
|
|
775 |
'*some*compl*ern*' match:'this is another complicated pattern match'
|
|
776 |
"
|
64
|
777 |
! !
|
|
778 |
|
|
779 |
!AbstractString methodsFor:'testing'!
|
|
780 |
|
|
781 |
isBlank
|
|
782 |
"return true, if the receiver contains spaces only"
|
|
783 |
|
|
784 |
self do:[:char |
|
|
785 |
char ~~ Character space ifTrue:[^ false].
|
|
786 |
].
|
|
787 |
^ true
|
|
788 |
!
|
|
789 |
|
|
790 |
countWords
|
|
791 |
"return the number of words, which are separated by separators"
|
|
792 |
|
92
|
793 |
|tally "{ Class: SmallInteger }"
|
|
794 |
start "{ Class: SmallInteger }"
|
|
795 |
mySize "{ Class: SmallInteger }"
|
|
796 |
stop ch|
|
64
|
797 |
|
|
798 |
tally := 0.
|
|
799 |
start := 1.
|
|
800 |
mySize := self size.
|
|
801 |
[start <= mySize] whileTrue:[
|
|
802 |
ch := self at:start.
|
|
803 |
ch isSeparator ifTrue:[
|
|
804 |
start := start + 1
|
|
805 |
] ifFalse:[
|
|
806 |
stop := self indexOfSeparatorStartingAt:start.
|
|
807 |
(stop == 0) ifTrue:[
|
|
808 |
stop := mySize + 1
|
|
809 |
].
|
|
810 |
tally := tally + 1.
|
|
811 |
start := stop
|
|
812 |
]
|
|
813 |
].
|
|
814 |
^ tally
|
|
815 |
|
92
|
816 |
"
|
|
817 |
'hello world isnt this nice' countWords'
|
|
818 |
"
|
64
|
819 |
!
|
|
820 |
|
|
821 |
nArgsIfSelector
|
77
|
822 |
"treating the receiver as a message selector, return how many arguments would it take"
|
64
|
823 |
|
|
824 |
|binopChars|
|
|
825 |
|
|
826 |
(self size > 2) ifFalse:[
|
|
827 |
binopChars := '|&-+=*/\<>~@,'.
|
|
828 |
(self size == 1) ifTrue:[
|
|
829 |
((binopChars occurrencesOf:(self at:1)) == 0) ifTrue:[^ 0].
|
|
830 |
^ 1
|
|
831 |
].
|
|
832 |
((binopChars occurrencesOf:(self at:1)) == 0) ifFalse:[
|
|
833 |
((binopChars occurrencesOf:(self at:2)) == 0) ifFalse:[^ 1]
|
|
834 |
]
|
|
835 |
].
|
|
836 |
^ self occurrencesOf:$:
|
|
837 |
|
77
|
838 |
"
|
92
|
839 |
'foo:bar:' nArgsIfSelector
|
|
840 |
#foo:bar: nArgsIfSelector
|
77
|
841 |
'hello' nArgsIfSelector
|
|
842 |
'+' nArgsIfSelector
|
|
843 |
"
|
|
844 |
!
|
|
845 |
|
|
846 |
partsIfSelector
|
|
847 |
"treat the receiver as a message selector, return a collection of parts."
|
|
848 |
|
92
|
849 |
|idx1 "{ Class: SmallInteger }"
|
|
850 |
coll idx2 sz|
|
77
|
851 |
|
|
852 |
coll := OrderedCollection new.
|
|
853 |
idx1 := 1.
|
|
854 |
sz := self size.
|
|
855 |
[true] whileTrue:[
|
|
856 |
idx2 := self indexOf:$: startingAt:idx1 + 1.
|
|
857 |
(idx2 == 0 or:[idx2 == sz]) ifTrue:[
|
|
858 |
coll add:(self copyFrom:idx1).
|
|
859 |
^ coll
|
|
860 |
].
|
|
861 |
coll add:(self copyFrom:idx1 to:idx2).
|
|
862 |
idx1 := idx2 + 1
|
|
863 |
].
|
|
864 |
|
|
865 |
"
|
|
866 |
'foo:bar:' partsIfSelector
|
|
867 |
#foo:bar: partsIfSelector
|
|
868 |
'hello' partsIfSelector
|
|
869 |
'+' partsIfSelector
|
|
870 |
"
|
64
|
871 |
!
|
|
872 |
|
|
873 |
levenshteinTo:aString
|
|
874 |
"return the levenshtein distance to the argument, aString;
|
|
875 |
this value corrensponds to the number of replacements that have to be
|
|
876 |
made to get aString from the receiver.
|
|
877 |
see IEEE transactions on Computers 1976 Pg 172 ff."
|
|
878 |
|
|
879 |
^ self levenshteinTo:aString s:4 c:1 i:2 d:6
|
|
880 |
!
|
|
881 |
|
|
882 |
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight
|
|
883 |
"parametrized levenshtein. arguments are the costs for
|
|
884 |
substitution, case-change, insertion and deletion of a character."
|
|
885 |
|
|
886 |
|d "delta matrix"
|
|
887 |
len1 len2 dim prevRow row col dimPlus1
|
|
888 |
min pp c1 c2|
|
|
889 |
|
|
890 |
len1 := self size.
|
|
891 |
len2 := aString size.
|
|
892 |
|
|
893 |
"create the help-matrix"
|
|
894 |
|
|
895 |
dim := len1 max:len2.
|
|
896 |
dimPlus1 := dim + 1.
|
|
897 |
|
|
898 |
d := Array new:dimPlus1.
|
|
899 |
1 to:dimPlus1 do:[:i |
|
|
900 |
d at:i put:(Array new:dimPlus1)
|
|
901 |
].
|
|
902 |
|
|
903 |
"init help-matrix"
|
|
904 |
|
|
905 |
(d at:1) at:1 put:0.
|
|
906 |
row := d at:1.
|
|
907 |
1 to:dim do:[:j |
|
|
908 |
row at:(j + 1) put:( (row at:j) + insrtWeight )
|
|
909 |
].
|
|
910 |
|
|
911 |
1 to:dim do:[:i |
|
|
912 |
(d at:(i + 1)) at:1 put:( ((d at:i) at:1) + deleteWeight )
|
|
913 |
].
|
|
914 |
|
|
915 |
1 to:len1 do:[:i |
|
|
916 |
c1 := self at:i.
|
|
917 |
1 to:len2 do:[:j |
|
|
918 |
c2 := aString at:j.
|
|
919 |
(c1 == c2) ifTrue:[
|
|
920 |
pp := 0
|
|
921 |
] ifFalse:[
|
|
922 |
(c1 asLowercase == c2 asLowercase) ifTrue:[
|
|
923 |
pp := caseWeight
|
|
924 |
] ifFalse:[
|
|
925 |
pp := substWeight
|
|
926 |
]
|
|
927 |
].
|
|
928 |
prevRow := d at:i.
|
|
929 |
row := d at:(i + 1).
|
|
930 |
col := j + 1.
|
|
931 |
min := (prevRow at:j) + pp.
|
|
932 |
min := min min:( (row at:j) + insrtWeight).
|
|
933 |
min := min min:( (prevRow at:col) + deleteWeight).
|
|
934 |
row at:col put: min
|
|
935 |
]
|
|
936 |
].
|
|
937 |
|
|
938 |
^ (d at:(len1 + 1)) at:(len2 + 1)
|
|
939 |
|
|
940 |
"'ocmprt' levenshteinTo:'computer'
|
|
941 |
'computer' levenshteinTo:'computer'
|
|
942 |
'ocmputer' levenshteinTo:'computer'
|
|
943 |
'cmputer' levenshteinTo:'computer'
|
|
944 |
'Computer' levenshteinTo:'computer'"
|
|
945 |
!
|
|
946 |
|
|
947 |
spellAgainst: aString
|
|
948 |
"return an integer between 0 and 100 indicating how similar
|
|
949 |
the argument is to the receiver. No case conversion is done."
|
|
950 |
|
|
951 |
| i1 "{ Class: SmallInteger }"
|
|
952 |
i2 "{ Class: SmallInteger }"
|
|
953 |
size1 "{ Class: SmallInteger }"
|
|
954 |
size2 "{ Class: SmallInteger }"
|
|
955 |
score "{ Class: SmallInteger }"
|
|
956 |
maxLen "{ Class: SmallInteger }" |
|
|
957 |
|
|
958 |
size1 := self size.
|
|
959 |
size2 := aString size.
|
|
960 |
maxLen := size1 max: size2.
|
|
961 |
score := 0.
|
|
962 |
i1 := i2 := 1.
|
|
963 |
[i1 <= size1 and: [i2 <= size2]] whileTrue:[
|
|
964 |
(self at: i1) == (aString at: i2) ifTrue: [
|
|
965 |
score := score+1.
|
|
966 |
i1 := i1+1.
|
|
967 |
i2 := i2+1
|
|
968 |
] ifFalse: [
|
|
969 |
(i2 < size2 and: [(self at: i1) == (aString at: i2+1)]) ifTrue: [
|
|
970 |
i2 := i2+1
|
|
971 |
] ifFalse: [
|
|
972 |
(i1 < size1 and: [(self at: i1+1) == (aString at: i2)]) ifTrue: [
|
|
973 |
i1 := i1+1
|
|
974 |
] ifFalse: [
|
|
975 |
i1 := i1+1.
|
|
976 |
i2 := i2+1
|
|
977 |
]
|
|
978 |
]
|
|
979 |
]
|
|
980 |
].
|
|
981 |
|
|
982 |
score = maxLen ifTrue: [^100].
|
|
983 |
^100*score//maxLen
|
|
984 |
|
|
985 |
" 'Smalltalk' spellAgainst: 'Smalltlak' "
|
|
986 |
" 'Smalltalk' spellAgainst: 'smalltlak' "
|
|
987 |
" 'Smalltalk' spellAgainst: 'smalltalk' "
|
|
988 |
" 'Smalltalk' spellAgainst: 'smalltlk' "
|
|
989 |
" 'Smalltalk' spellAgainst: 'Smalltolk' "
|
|
990 |
! !
|
|
991 |
|
68
|
992 |
!AbstractString methodsFor:'padded copying'!
|
|
993 |
|
|
994 |
paddedTo:newSize with:padCharacter
|
|
995 |
"return a new string consisting of the receivers characters,
|
92
|
996 |
plus pad characters up to length.
|
|
997 |
If the receivers size is larger than the legth argument, it
|
|
998 |
is returned unchanged."
|
68
|
999 |
|
|
1000 |
|s len|
|
|
1001 |
|
|
1002 |
len := self size.
|
|
1003 |
len < newSize ifTrue:[
|
|
1004 |
s := self species new:newSize withAll:padCharacter.
|
|
1005 |
s replaceFrom:1 to:len with:self.
|
|
1006 |
^ s
|
|
1007 |
]
|
|
1008 |
|
92
|
1009 |
"
|
|
1010 |
'foo' paddedTo:10 with:$.
|
|
1011 |
123 printString paddedTo:10 with:$*
|
|
1012 |
(Float pi printString) paddedTo:15 with:(Character space)
|
|
1013 |
(Float pi printString) paddedTo:15 with:$-
|
|
1014 |
(Float pi class name , ' ') paddedTo:15 with:$.
|
|
1015 |
"
|
68
|
1016 |
!
|
|
1017 |
|
|
1018 |
leftPaddedTo:size with:padCharacter
|
|
1019 |
"return a new string of length size, which contains the receiver
|
|
1020 |
right-adjusted (i.e. padded on the left).
|
|
1021 |
characters on the left are filled with padCharacter.
|
|
1022 |
If the receivers size is larger than the legth argument, it
|
|
1023 |
is returned unchanged."
|
|
1024 |
|
|
1025 |
|len s|
|
|
1026 |
|
|
1027 |
len := self size.
|
|
1028 |
(len < size) ifTrue:[
|
|
1029 |
s := self species new:size withAll:padCharacter.
|
|
1030 |
s replaceFrom:(size - len + 1) with:self.
|
|
1031 |
^ s
|
|
1032 |
]
|
|
1033 |
|
92
|
1034 |
"
|
|
1035 |
'foo' leftPaddedTo:10 with:$.
|
|
1036 |
123 printString leftPaddedTo:10 with:$.
|
|
1037 |
(Float pi printString) leftPaddedTo:15 with:(Character space)
|
|
1038 |
(Float pi printString) leftPaddedTo:15 with:$-
|
|
1039 |
(' ' , Float pi class name) leftPaddedTo:15 with:$.
|
|
1040 |
"
|
68
|
1041 |
! !
|
|
1042 |
|
64
|
1043 |
!AbstractString methodsFor:'copying'!
|
|
1044 |
|
|
1045 |
concatenate:string1 and:string2
|
|
1046 |
"return the concatenation of myself and the arguments, string1 and string2.
|
|
1047 |
This is equivalent to self , string1 , string2
|
|
1048 |
- generated by compiler when such a construct is detected"
|
|
1049 |
|
|
1050 |
^ self , string1 , string2
|
|
1051 |
!
|
|
1052 |
|
|
1053 |
concatenate:string1 and:string2 and:string3
|
|
1054 |
"return the concatenation of myself and the string arguments.
|
|
1055 |
This is equivalent to self , string1 , string2 , string3
|
|
1056 |
- generated by compiler when such a construct is detected"
|
|
1057 |
|
|
1058 |
^ self , string1 , string2 , string3
|
|
1059 |
! !
|
|
1060 |
|
|
1061 |
!AbstractString methodsFor:'filling and replacing'!
|
|
1062 |
|
|
1063 |
withoutSpaces
|
92
|
1064 |
"return a copy of myself without leading and trailing spaces.
|
|
1065 |
Notice: this does NOT remove tabs, newline or any other whitespace.
|
|
1066 |
Use withoutSeparators for this."
|
64
|
1067 |
|
|
1068 |
|startIndex "{ Class: SmallInteger }"
|
|
1069 |
endIndex "{ Class: SmallInteger }"
|
|
1070 |
sz blank|
|
|
1071 |
|
|
1072 |
startIndex := 0.
|
|
1073 |
sz := self size.
|
|
1074 |
startIndex == 0 ifTrue:[
|
|
1075 |
startIndex := 1.
|
|
1076 |
endIndex := sz.
|
|
1077 |
blank := Character space.
|
|
1078 |
[(startIndex < endIndex) and:[(self at:startIndex) == blank]] whileTrue:[
|
|
1079 |
startIndex := startIndex + 1
|
|
1080 |
].
|
|
1081 |
[(endIndex > 1) and:[(self at:endIndex) == blank]] whileTrue:[
|
|
1082 |
endIndex := endIndex - 1
|
|
1083 |
]
|
|
1084 |
].
|
|
1085 |
startIndex > endIndex ifTrue:[
|
|
1086 |
^ ''
|
|
1087 |
].
|
|
1088 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[
|
|
1089 |
^ self
|
|
1090 |
].
|
|
1091 |
^ self copyFrom:startIndex to:endIndex
|
92
|
1092 |
|
|
1093 |
"
|
|
1094 |
' foo ' withoutSpaces
|
|
1095 |
(' foo' , Character tab asString , ' ') withoutSpaces inspect
|
|
1096 |
"
|
64
|
1097 |
!
|
|
1098 |
|
|
1099 |
withoutSeparators
|
92
|
1100 |
"return a copy of myself without leading and trailing whitespace.
|
|
1101 |
Whitespace is space, tab, newline, formfeed.
|
|
1102 |
Use withoutSpaces, if you want to remove spaces only."
|
64
|
1103 |
|
|
1104 |
|startIndex "{ Class: SmallInteger }"
|
|
1105 |
endIndex "{ Class: SmallInteger }"
|
|
1106 |
sz|
|
|
1107 |
|
|
1108 |
startIndex := 0.
|
|
1109 |
sz := self size.
|
|
1110 |
startIndex == 0 ifTrue:[
|
|
1111 |
startIndex := 1.
|
|
1112 |
endIndex := self size.
|
|
1113 |
[(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[
|
|
1114 |
startIndex := startIndex + 1
|
|
1115 |
].
|
|
1116 |
[(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[
|
|
1117 |
endIndex := endIndex - 1
|
|
1118 |
].
|
|
1119 |
].
|
|
1120 |
startIndex > endIndex ifTrue:[
|
|
1121 |
^ ''
|
|
1122 |
].
|
|
1123 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[
|
|
1124 |
^ self
|
|
1125 |
].
|
|
1126 |
^ self copyFrom:startIndex to:endIndex
|
92
|
1127 |
|
|
1128 |
"
|
|
1129 |
' foo ' withoutSeparators
|
|
1130 |
(' foo' , Character tab asString , ' ') withoutSeparators inspect
|
|
1131 |
"
|
64
|
1132 |
! !
|
|
1133 |
|
|
1134 |
!AbstractString methodsFor:'queries'!
|
|
1135 |
|
|
1136 |
isString
|
|
1137 |
"return true, if the receiver is some kind of string;
|
|
1138 |
true is returned here - redefinition of Object>>isString."
|
|
1139 |
|
|
1140 |
^ true
|
|
1141 |
!
|
|
1142 |
|
|
1143 |
encoding
|
|
1144 |
^ #unknown
|
|
1145 |
! !
|