1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
159
|
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 |
"
|
|
12 |
|
255
|
13 |
CharacterArray subclass:#String
|
1
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Collections-Text'
|
|
18 |
!
|
|
19 |
|
|
20 |
String comment:'
|
5
|
21 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
159
|
22 |
All Rights Reserved
|
95
|
23 |
|
429
|
24 |
$Header: /cvs/stx/stx/libbasic/String.st,v 1.46 1995-09-10 22:31:43 claus Exp $
|
1
|
25 |
'!
|
|
26 |
|
88
|
27 |
!String class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
159
|
32 |
All Rights Reserved
|
1
|
33 |
|
88
|
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 |
"
|
429
|
45 |
$Header: /cvs/stx/stx/libbasic/String.st,v 1.46 1995-09-10 22:31:43 claus Exp $
|
88
|
46 |
"
|
|
47 |
!
|
1
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
68
|
51 |
Strings are ByteArrays storing Characters.
|
|
52 |
|
|
53 |
Strings are kind of kludgy: to allow for easy handling by c-functions,
|
|
54 |
there is always one 0-byte added at the end, which is not counted
|
|
55 |
in size. also, the at:put: method does not allow for storing 0-bytes.
|
|
56 |
(to do this, the basicAt:put: and basicNew: methods are redefined)
|
1
|
57 |
|
68
|
58 |
You cannot add any instvars to String, since the the run time system & compiler
|
|
59 |
creates literal strings and knows that strings have no named instvars.
|
1
|
60 |
|
68
|
61 |
If you really need strings with instVars, you have to create a subclass
|
|
62 |
of String (the access functions defined here can handle this).
|
|
63 |
A little warning though: not all smalltalk systems allow subclassing String,
|
|
64 |
so your program may become unportable if you do so.
|
1
|
65 |
"
|
|
66 |
! !
|
|
67 |
|
216
|
68 |
!String primitiveDefinitions!
|
|
69 |
|
88
|
70 |
%{
|
|
71 |
#include <stdio.h>
|
|
72 |
#include <ctype.h>
|
359
|
73 |
|
273
|
74 |
#ifdef LINUX
|
359
|
75 |
# define __STRINGDEFS__
|
|
76 |
# include <linuxIntern.h>
|
302
|
77 |
#else
|
|
78 |
extern char *strchr();
|
273
|
79 |
#endif
|
95
|
80 |
|
|
81 |
/*
|
|
82 |
* old st/x creates strings with spaces in it;
|
|
83 |
* new st/x will fill it with zeros (for st-80 compatibility)
|
|
84 |
* the define below sets old behavior.
|
|
85 |
*/
|
|
86 |
#define INITIALIZE_WITH_SPACE
|
88
|
87 |
%}
|
216
|
88 |
! !
|
88
|
89 |
|
3
|
90 |
!String class methodsFor:'queries'!
|
|
91 |
|
|
92 |
isBuiltInClass
|
|
93 |
"this class is known by the run-time-system"
|
|
94 |
|
|
95 |
^ self == String
|
|
96 |
! !
|
|
97 |
|
1
|
98 |
!String class methodsFor:'instance creation'!
|
|
99 |
|
357
|
100 |
new:n
|
|
101 |
^ self basicNew:n
|
|
102 |
!
|
|
103 |
|
1
|
104 |
basicNew:anInteger
|
|
105 |
"return a new empty string with anInteger characters"
|
|
106 |
|
|
107 |
%{ /* NOCONTEXT */
|
|
108 |
|
|
109 |
OBJ newString;
|
|
110 |
REGISTER int len;
|
|
111 |
REGISTER unsigned char *cp;
|
|
112 |
REGISTER OBJ *op;
|
|
113 |
int nInstVars, instsize;
|
|
114 |
|
252
|
115 |
if (__isSmallInteger(anInteger)) {
|
159
|
116 |
len = _intVal(anInteger);
|
|
117 |
if (len >= 0) {
|
95
|
118 |
if (self == String) {
|
|
119 |
instsize = OHDR_SIZE + len + 1;
|
|
120 |
if (_CanDoQuickNew(instsize)) {
|
|
121 |
/*
|
|
122 |
* the most common case
|
|
123 |
*/
|
159
|
124 |
_qCheckedNew(newString, instsize);
|
|
125 |
_InstPtr(newString)->o_class = self;
|
368
|
126 |
__qSTORE(newString, self);
|
|
127 |
|
159
|
128 |
cp = _stringVal(newString);
|
357
|
129 |
#if defined(memset4) && !defined(NON_ASCII)
|
|
130 |
instsize = len >> 2;
|
|
131 |
if (len & 3) instsize++;
|
|
132 |
memset4(cp, 0x20202020, instsize);
|
159
|
133 |
*(cp + len) = '\0';
|
95
|
134 |
#else
|
357
|
135 |
# ifdef FAST_MEMSET
|
|
136 |
memset(cp, ' ', len);
|
|
137 |
*(cp + len) = '\0';
|
|
138 |
# else
|
159
|
139 |
while (len >= 8) {
|
357
|
140 |
# ifndef NON_ASCII /* i.e. EBCDIC ;-) */
|
|
141 |
((int *)cp)[0] = 0x20202020;
|
|
142 |
((int *)cp)[1] = 0x20202020;
|
|
143 |
# else
|
159
|
144 |
cp[0] = cp[1] = cp[2] = cp[3] = ' ';
|
|
145 |
cp[4] = cp[5] = cp[6] = cp[7] = ' ';
|
357
|
146 |
# endif
|
159
|
147 |
cp += 8;
|
95
|
148 |
len -= 8;
|
159
|
149 |
}
|
|
150 |
while (len--)
|
|
151 |
*cp++ = ' ';
|
|
152 |
*cp = '\0';
|
357
|
153 |
# endif
|
95
|
154 |
#endif
|
159
|
155 |
RETURN (newString);
|
95
|
156 |
}
|
|
157 |
nInstVars = 0;
|
|
158 |
} else {
|
|
159 |
nInstVars = _intVal(_ClassInstPtr(self)->c_ninstvars);
|
159
|
160 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + len + 1;
|
95
|
161 |
}
|
|
162 |
|
159
|
163 |
PROTECT_CONTEXT
|
|
164 |
_qNew(newString, instsize, SENDER);
|
|
165 |
UNPROTECT_CONTEXT
|
|
166 |
if (newString == nil) goto fail;
|
|
167 |
_InstPtr(newString)->o_class = self;
|
368
|
168 |
__qSTORE(newString, self);
|
1
|
169 |
|
95
|
170 |
if (nInstVars) {
|
1
|
171 |
#if defined(memset4)
|
159
|
172 |
memset4(_InstPtr(newString)->i_instvars, nil, nInstVars);
|
1
|
173 |
#else
|
|
174 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
159
|
175 |
/*
|
|
176 |
* knowing that nil is 0
|
|
177 |
*/
|
|
178 |
memset(_InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
|
1
|
179 |
# else
|
159
|
180 |
op = _InstPtr(newString)->i_instvars;
|
|
181 |
do {
|
|
182 |
*op++ = nil;
|
|
183 |
} while (--nInstVars);
|
1
|
184 |
# endif
|
|
185 |
#endif
|
159
|
186 |
cp = _stringVal(newString) + __OBJS2BYTES__(nInstVars);
|
|
187 |
} else {
|
95
|
188 |
cp = _stringVal(newString);
|
|
189 |
}
|
1
|
190 |
|
|
191 |
#ifdef FAST_MEMSET
|
159
|
192 |
memset(cp, ' ', len);
|
|
193 |
*(cp + len) = '\0';
|
1
|
194 |
#else
|
159
|
195 |
while (len >= 8) {
|
357
|
196 |
# ifndef NON_ASCII /* i.e. EBCDIC ;-) */
|
|
197 |
((int *)cp)[0] = 0x20202020;
|
|
198 |
((int *)cp)[1] = 0x20202020;
|
|
199 |
# else
|
159
|
200 |
cp[0] = cp[1] = cp[2] = cp[3] = ' ';
|
|
201 |
cp[4] = cp[5] = cp[6] = cp[7] = ' ';
|
357
|
202 |
# endif
|
159
|
203 |
cp += 8;
|
|
204 |
len -= 8;
|
|
205 |
}
|
|
206 |
while (len--)
|
|
207 |
*cp++ = ' ';
|
|
208 |
*cp = '\0';
|
1
|
209 |
#endif
|
159
|
210 |
RETURN (newString);
|
|
211 |
}
|
1
|
212 |
}
|
95
|
213 |
fail: ;;
|
1
|
214 |
%}
|
|
215 |
.
|
95
|
216 |
"
|
|
217 |
invalid argument, or out-of-memory:
|
|
218 |
use error handling in superclass
|
|
219 |
"
|
1
|
220 |
^ (super basicNew:anInteger) atAllPut:(Character space)
|
|
221 |
!
|
|
222 |
|
|
223 |
unititializedNew:anInteger
|
|
224 |
"redefine it back - strings must have a 0-byte at the end"
|
|
225 |
|
|
226 |
^ self basicNew:anInteger
|
347
|
227 |
!
|
|
228 |
|
|
229 |
readFrom:aStream onError:exceptionBlock
|
|
230 |
"read & return the next String from the (character-)stream aStream;
|
|
231 |
skipping all whitespace first; return the value of exceptionBlock,
|
|
232 |
if no string can be read. The sequence of characters as read from the
|
|
233 |
stream must be one as stored via storeOn: or storeString."
|
|
234 |
|
|
235 |
|collected char|
|
|
236 |
|
|
237 |
"
|
|
238 |
this method is not to be inherited
|
|
239 |
(i.e. not ok for subclasses; Symbol, for example)
|
|
240 |
"
|
|
241 |
self ~~ String ifTrue:[
|
|
242 |
^ super readFrom:aStream onError:exceptionBlock
|
|
243 |
].
|
|
244 |
|
|
245 |
"skip whiteSpace"
|
|
246 |
aStream skipSeparators.
|
|
247 |
(aStream next == $') ifTrue:[
|
|
248 |
collected := WriteStream on:(String new).
|
|
249 |
[true] whileTrue:[
|
|
250 |
aStream atEnd ifTrue:[
|
|
251 |
"/ mhmh - reached the end without a closing quote
|
|
252 |
"/ looks like an error to me ...
|
|
253 |
^ exceptionBlock value
|
|
254 |
].
|
|
255 |
char := aStream next.
|
|
256 |
char == $' ifTrue:[
|
|
257 |
"/ look for another quote
|
|
258 |
aStream peek == $' ifFalse:[
|
|
259 |
^ collected contents
|
|
260 |
].
|
|
261 |
aStream next.
|
|
262 |
].
|
|
263 |
collected nextPut:char
|
|
264 |
]
|
|
265 |
].
|
|
266 |
^ exceptionBlock value
|
|
267 |
|
|
268 |
"
|
|
269 |
String readFrom:('''hello world''' readStream)
|
|
270 |
String readFrom:('''hello '''' world''' readStream)
|
|
271 |
String readFrom:('1 ''hello'' ' readStream)
|
|
272 |
String readFrom:('1 ''hello'' ' readStream) onError:['foobar']
|
|
273 |
"
|
1
|
274 |
! !
|
|
275 |
|
|
276 |
!String methodsFor:'accessing'!
|
|
277 |
|
329
|
278 |
size
|
|
279 |
"return the number of characters in myself.
|
345
|
280 |
Reimplemented here to avoid the additional size->basicSize send
|
|
281 |
(which we can do here, since size is obviously not redefined in a subclass).
|
329
|
282 |
This method is the same as basicSize."
|
|
283 |
|
|
284 |
%{ /* NOCONTEXT */
|
|
285 |
REGISTER OBJ cls;
|
|
286 |
|
|
287 |
cls = __qClass(self);
|
|
288 |
if (cls == String) {
|
|
289 |
RETURN ( _MKSMALLINT(_stringSize(self)) );
|
|
290 |
}
|
|
291 |
RETURN ( _MKSMALLINT(_stringSize(self)
|
|
292 |
- __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars))));
|
|
293 |
%}
|
|
294 |
!
|
|
295 |
|
1
|
296 |
basicSize
|
2
|
297 |
"return the number of characters in myself.
|
|
298 |
Redefined here to exclude the 0-byte at the end."
|
1
|
299 |
|
|
300 |
%{ /* NOCONTEXT */
|
329
|
301 |
REGISTER OBJ cls;
|
1
|
302 |
|
329
|
303 |
cls = __qClass(self);
|
|
304 |
if (cls == String) {
|
159
|
305 |
RETURN ( _MKSMALLINT(_stringSize(self)) );
|
1
|
306 |
}
|
329
|
307 |
RETURN ( _MKSMALLINT(_stringSize(self)
|
|
308 |
- __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars))));
|
345
|
309 |
%}
|
329
|
310 |
!
|
|
311 |
|
|
312 |
at:index
|
|
313 |
"return the character at position index, an Integer.
|
345
|
314 |
Reimplemented here to avoid the additional at:->basicAt: send
|
|
315 |
(which we can do here, since at: is obviously not redefined in a subclass).
|
329
|
316 |
This method is the same as at:."
|
|
317 |
|
|
318 |
%{ /* NOCONTEXT */
|
|
319 |
|
|
320 |
REGISTER int indx;
|
|
321 |
REGISTER OBJ cls;
|
|
322 |
|
|
323 |
if (__isSmallInteger(index)) {
|
|
324 |
indx = _intVal(index);
|
|
325 |
if (indx > 0) {
|
|
326 |
cls = __qClass(self);
|
|
327 |
if (cls != String)
|
345
|
328 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
329
|
329 |
if (indx <= (_stringSize(self))) {
|
345
|
330 |
RETURN ( _MKCHARACTER(_stringVal(self)[indx-1] & 0xFF) );
|
329
|
331 |
}
|
|
332 |
}
|
|
333 |
}
|
|
334 |
%}.
|
|
335 |
^ self subscriptBoundsError:index
|
1
|
336 |
!
|
|
337 |
|
|
338 |
basicAt:index
|
|
339 |
"return the character at position index, an Integer
|
|
340 |
- reimplemented here since we return characters"
|
|
341 |
|
|
342 |
%{ /* NOCONTEXT */
|
|
343 |
|
|
344 |
REGISTER int indx;
|
329
|
345 |
REGISTER OBJ cls;
|
1
|
346 |
|
252
|
347 |
if (__isSmallInteger(index)) {
|
159
|
348 |
indx = _intVal(index);
|
329
|
349 |
if (indx > 0) {
|
|
350 |
cls = __qClass(self);
|
|
351 |
if (cls != String)
|
345
|
352 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
329
|
353 |
if (indx <= (_stringSize(self))) {
|
345
|
354 |
RETURN ( _MKCHARACTER(_stringVal(self)[indx-1] & 0xFF) );
|
329
|
355 |
}
|
159
|
356 |
}
|
1
|
357 |
}
|
159
|
358 |
%}.
|
|
359 |
^ self subscriptBoundsError:index
|
1
|
360 |
!
|
|
361 |
|
329
|
362 |
at:index put:aCharacter
|
|
363 |
"store the argument, aCharacter at position index, an Integer.
|
345
|
364 |
Reimplemented here to avoid the additional at:put:->basicAt:put: send
|
|
365 |
(but only for Strings, since subclasses may redefine basicAt:put:).
|
329
|
366 |
This method is the same as basicAt:put:."
|
|
367 |
|
|
368 |
%{ /* NOCONTEXT */
|
|
369 |
|
|
370 |
REGISTER int value, indx;
|
|
371 |
|
345
|
372 |
if (__isString(self)) {
|
|
373 |
if (__isCharacter(aCharacter)) {
|
|
374 |
value = _intVal(_characterVal(aCharacter));
|
422
|
375 |
#ifdef OLD
|
345
|
376 |
if ((value > 0)
|
|
377 |
&& (value <= 255)
|
422
|
378 |
#else
|
|
379 |
if (((value & ~0xFF) == 0)
|
|
380 |
#endif
|
345
|
381 |
&& __isSmallInteger(index)) {
|
|
382 |
indx = _intVal(index);
|
|
383 |
if (indx > 0) {
|
|
384 |
if (indx <= (_stringSize(self))) {
|
|
385 |
_stringVal(self)[indx-1] = value;
|
|
386 |
RETURN ( aCharacter );
|
|
387 |
}
|
329
|
388 |
}
|
|
389 |
}
|
|
390 |
}
|
|
391 |
}
|
|
392 |
%}.
|
345
|
393 |
(self isMemberOf:String) ifFalse:[
|
|
394 |
^ super at:index put:aCharacter
|
|
395 |
].
|
|
396 |
|
329
|
397 |
(aCharacter isMemberOf:Character) ifFalse:[
|
|
398 |
"
|
|
399 |
tried to store something which is not a character
|
|
400 |
"
|
|
401 |
^ self elementNotCharacter
|
|
402 |
].
|
|
403 |
(aCharacter asciiValue between:1 and:255) ifFalse:[
|
|
404 |
"
|
|
405 |
tried to store a multibyte character
|
|
406 |
"
|
|
407 |
^ self elementBoundsError
|
|
408 |
].
|
|
409 |
"
|
|
410 |
invalid index
|
|
411 |
"
|
|
412 |
^ self subscriptBoundsError:index
|
|
413 |
!
|
|
414 |
|
1
|
415 |
basicAt:index put:aCharacter
|
|
416 |
"store the argument, aCharacter at position index, an Integer
|
345
|
417 |
- reimplemented here since we store characters
|
|
418 |
(but only for Strings, since subclasses may redefine basicAt:put:)."
|
1
|
419 |
|
|
420 |
%{ /* NOCONTEXT */
|
|
421 |
|
|
422 |
REGISTER int value, indx;
|
|
423 |
|
345
|
424 |
if (__isString(self)) {
|
|
425 |
if (__isCharacter(aCharacter)) {
|
|
426 |
value = _intVal(_characterVal(aCharacter));
|
|
427 |
if ((value > 0)
|
|
428 |
&& (value <= 255)
|
|
429 |
&& __isSmallInteger(index)) {
|
|
430 |
indx = _intVal(index);
|
|
431 |
if (indx > 0) {
|
|
432 |
if (indx <= (_stringSize(self))) {
|
|
433 |
_stringVal(self)[indx-1] = value;
|
|
434 |
RETURN ( aCharacter );
|
|
435 |
}
|
329
|
436 |
}
|
159
|
437 |
}
|
|
438 |
}
|
1
|
439 |
}
|
159
|
440 |
%}.
|
345
|
441 |
(self isMemberOf:String) ifFalse:[
|
|
442 |
^ super basicAt:index put:aCharacter
|
|
443 |
].
|
|
444 |
|
1
|
445 |
(aCharacter isMemberOf:Character) ifFalse:[
|
299
|
446 |
"
|
|
447 |
tried to store something which is not a character
|
|
448 |
"
|
159
|
449 |
^ self elementNotCharacter
|
299
|
450 |
].
|
|
451 |
(aCharacter asciiValue between:1 and:255) ifFalse:[
|
|
452 |
"
|
|
453 |
tried to store a multibyte character
|
|
454 |
"
|
|
455 |
^ self elementBoundsError
|
|
456 |
].
|
|
457 |
"
|
|
458 |
invalid index
|
|
459 |
"
|
|
460 |
^ self subscriptBoundsError:index
|
1
|
461 |
! !
|
|
462 |
|
|
463 |
!String methodsFor:'converting'!
|
|
464 |
|
|
465 |
asSymbol
|
345
|
466 |
"return a unique symbol with the name taken from myself.
|
|
467 |
The receiver must be a String, subclass instances are (currently)
|
|
468 |
not allowed."
|
1
|
469 |
%{
|
329
|
470 |
if (__qClass(self) == String) {
|
159
|
471 |
RETURN ( _MKSYMBOL(_stringVal(self), (OBJ *)0, __context) );
|
1
|
472 |
}
|
267
|
473 |
%}.
|
|
474 |
self primitiveFailed
|
|
475 |
!
|
|
476 |
|
|
477 |
asSymbolIfInterned
|
|
478 |
"if a symbol with the receivers characters is already known, return it.
|
|
479 |
Otherwise, return nil. This can be used to query for an existing
|
|
480 |
symbol and is the same as
|
|
481 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil]
|
|
482 |
but slightly faster, since the symbol lookup operation is only
|
345
|
483 |
performed once.
|
|
484 |
The receiver must be a String, subclass instances are (currently)
|
|
485 |
not allowed."
|
267
|
486 |
|
|
487 |
%{ /* NOCONTEXT */
|
329
|
488 |
OBJ __SYMBOL_OR_NIL();
|
267
|
489 |
|
329
|
490 |
if (__qClass(self) == String) {
|
|
491 |
RETURN ( __SYMBOL_OR_NIL(_stringVal(self)));
|
267
|
492 |
}
|
|
493 |
%}.
|
1
|
494 |
self primitiveFailed
|
421
|
495 |
!
|
|
496 |
|
|
497 |
literalArrayEncoding
|
|
498 |
"encode myself as an array literal."
|
|
499 |
|
|
500 |
^ self
|
|
501 |
|
|
502 |
"Modified: 1.9.1995 / 02:25:45 / claus"
|
429
|
503 |
!
|
|
504 |
|
|
505 |
withTabsExpanded
|
|
506 |
"return a copy of the receiver where all tabulator characters
|
|
507 |
are expanded into spaces (assuming 8-col tabs).
|
|
508 |
rewritten for speed - this is very heavily used when reading
|
|
509 |
big files in the FileBrowser."
|
|
510 |
%{
|
|
511 |
char buffer[80*8];
|
|
512 |
char *srcP, *dstP, *cp0;
|
|
513 |
int idx, sz;
|
|
514 |
int any = 0;
|
|
515 |
OBJ newString;
|
|
516 |
char c;
|
|
517 |
|
|
518 |
if (__qClass(self) == String) {
|
|
519 |
/*
|
|
520 |
* for small strings (< 80), do it without a prescan ...
|
|
521 |
*/
|
|
522 |
if (__stringSize(self) < 80) {
|
|
523 |
for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) {
|
|
524 |
if (c == '\t') {
|
|
525 |
any = 1;
|
|
526 |
idx = (dstP-buffer+1) % 8;
|
|
527 |
while (idx <= 8) {
|
|
528 |
idx++;
|
|
529 |
*dstP++ = ' ';
|
|
530 |
}
|
|
531 |
} else {
|
|
532 |
*dstP++ = c;
|
|
533 |
}
|
|
534 |
}
|
|
535 |
if (! any) RETURN(self);
|
|
536 |
*dstP++ = '\0';
|
|
537 |
RETURN (__MKSTRING(buffer));
|
|
538 |
}
|
|
539 |
/*
|
|
540 |
* scan for size ...
|
|
541 |
*/
|
|
542 |
for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) {
|
|
543 |
if (c == '\t') {
|
|
544 |
any = 1;
|
|
545 |
idx = (dstP-buffer+1) % 8;
|
|
546 |
while (idx <= 8) {
|
|
547 |
idx++;
|
|
548 |
dstP++;
|
|
549 |
}
|
|
550 |
} else {
|
|
551 |
dstP++;
|
|
552 |
}
|
|
553 |
}
|
|
554 |
if (! any) RETURN(self);
|
|
555 |
|
|
556 |
/*
|
|
557 |
* get the string
|
|
558 |
*/
|
|
559 |
sz = OHDR_SIZE + (dstP-buffer) + 1;
|
|
560 |
_qNew(newString, sz, __context);
|
|
561 |
if (newString != nil) {
|
|
562 |
_InstPtr(newString)->o_class = String;
|
|
563 |
for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) {
|
|
564 |
if (c == '\t') {
|
|
565 |
idx = (dstP-cp0+1) % 8;
|
|
566 |
while (idx <= 8) {
|
|
567 |
idx++;
|
|
568 |
*dstP++ = ' ';
|
|
569 |
}
|
|
570 |
} else {
|
|
571 |
*dstP++ = c;
|
|
572 |
}
|
|
573 |
}
|
|
574 |
*dstP++ = '\0';
|
|
575 |
RETURN (newString);
|
|
576 |
}
|
|
577 |
}
|
|
578 |
%}.
|
|
579 |
^ super withTabsExpanded
|
1
|
580 |
! !
|
|
581 |
|
2
|
582 |
!String class methodsFor:'binary storage'!
|
|
583 |
|
276
|
584 |
binaryDefinitionFrom:stream manager:manager
|
|
585 |
"read a binary representation from stream."
|
|
586 |
|
|
587 |
^ (stream next:(stream nextNumber: 4)) asString
|
2
|
588 |
! !
|
|
589 |
|
276
|
590 |
!String methodsFor:'binary storage'!
|
|
591 |
|
|
592 |
storeBinaryOn:stream manager:manager
|
|
593 |
"append a binary representation of the receiver onto stream.
|
|
594 |
Redefined to store short Strings in a more compact way with a
|
|
595 |
special type code."
|
|
596 |
|
286
|
597 |
|sz "{ Class: SmallInteger }"|
|
|
598 |
|
|
599 |
sz := self size.
|
276
|
600 |
"not, if I am a thingy of a subclass"
|
286
|
601 |
((self class ~~ String) or:[sz > 255]) ifTrue:[
|
276
|
602 |
^ super storeBinaryOn:stream manager:manager
|
|
603 |
].
|
|
604 |
stream nextPut:manager codeForString.
|
286
|
605 |
stream nextPut:sz.
|
|
606 |
1 to:sz do:[:index |
|
276
|
607 |
stream nextPut:(self basicAt:index) asciiValue
|
|
608 |
]
|
|
609 |
!
|
|
610 |
|
1
|
611 |
!String methodsFor:'printing & storing'!
|
|
612 |
|
13
|
613 |
isLiteral
|
41
|
614 |
"return true, if the receiver can be used as a literal
|
|
615 |
(i.e. can be used in constant arrays)"
|
13
|
616 |
|
|
617 |
^ true
|
|
618 |
!
|
|
619 |
|
1
|
620 |
print
|
62
|
621 |
"print the receiver on standard output.
|
|
622 |
This method does NOT use the stream classes and will therefore work
|
|
623 |
even in case of emergency."
|
1
|
624 |
|
|
625 |
%{ /* NOCONTEXT */
|
|
626 |
|
329
|
627 |
if (__qClass(self) == String) {
|
159
|
628 |
printf("%s", _stringVal(self));
|
|
629 |
RETURN (self);
|
1
|
630 |
}
|
|
631 |
%}
|
|
632 |
.
|
53
|
633 |
^ super print
|
1
|
634 |
!
|
|
635 |
|
|
636 |
printfPrintString:formatString
|
|
637 |
"non-portable but sometimes useful.
|
13
|
638 |
Return a printed representation of the receiver as specified by formatString,
|
|
639 |
which is defined by printf.
|
299
|
640 |
No checking on buffer overrun is done; the resulting string may not
|
|
641 |
be larger than 799 characters.
|
62
|
642 |
This method is NONSTANDARD and may be removed without notice."
|
1
|
643 |
|
32
|
644 |
%{ /* STACK: 1000 */
|
1
|
645 |
|
32
|
646 |
char buffer[800];
|
1
|
647 |
char *cp;
|
314
|
648 |
OBJ s;
|
1
|
649 |
|
53
|
650 |
if (__isString(formatString)) {
|
368
|
651 |
#ifdef THISCONTEXT_IN_REGISTER
|
370
|
652 |
/*
|
|
653 |
* actually only needed on sparc: since thisContext is
|
|
654 |
* in a global register, which gets destroyed by printf,
|
|
655 |
* manually save it here - very stupid ...
|
|
656 |
*/
|
|
657 |
extern OBJ __thisContext__;
|
|
658 |
__thisContext__ = __thisContext;
|
368
|
659 |
#endif
|
32
|
660 |
|
159
|
661 |
cp = (char *)_stringVal(self);
|
329
|
662 |
if (__qClass(self) != String)
|
|
663 |
cp += __OBJS2BYTES__(_intVal(_ClassInstPtr(__qClass(self))->c_ninstvars));
|
1
|
664 |
|
159
|
665 |
sprintf(buffer, (char *)_stringVal(formatString), cp);
|
368
|
666 |
#ifdef THISCONTEXT_IN_REGISTER
|
|
667 |
__thisContext = __thisContext__;
|
|
668 |
__thisContext__ = nil;
|
|
669 |
#endif
|
314
|
670 |
|
|
671 |
s = _MKSTRING(buffer COMMA_SND);
|
|
672 |
if (s != nil) {
|
|
673 |
RETURN (s);
|
|
674 |
}
|
1
|
675 |
}
|
314
|
676 |
%}.
|
1
|
677 |
self primitiveFailed
|
|
678 |
|
299
|
679 |
"
|
|
680 |
'hello' printfPrintString:'%%s -> %s'
|
|
681 |
'hello' printfPrintString:'%%10s -> %10s'
|
|
682 |
'hello' printfPrintString:'%%-10s -> %-10s'
|
|
683 |
"
|
1
|
684 |
!
|
|
685 |
|
|
686 |
storeString
|
|
687 |
"return a String for storing myself"
|
|
688 |
|
51
|
689 |
|s n index|
|
1
|
690 |
|
51
|
691 |
n := self occurrencesOf:$'.
|
|
692 |
n == 0 ifFalse:[
|
159
|
693 |
s := String new:(n + 2 + self size).
|
|
694 |
s at:1 put:$'.
|
|
695 |
index := 2.
|
|
696 |
self do:[:thisChar |
|
|
697 |
(thisChar == $') ifTrue:[
|
|
698 |
s at:index put:thisChar.
|
|
699 |
index := index + 1.
|
|
700 |
].
|
|
701 |
s at:index put:thisChar.
|
|
702 |
index := index + 1.
|
|
703 |
].
|
|
704 |
s at:index put:$'.
|
|
705 |
^ s
|
1
|
706 |
].
|
53
|
707 |
^ '''' , self , ''''
|
1
|
708 |
!
|
|
709 |
|
|
710 |
storeOn:aStream
|
|
711 |
"put the storeString of myself on aStream"
|
|
712 |
|
|
713 |
aStream nextPut: $'.
|
|
714 |
(self includes:$') ifTrue:[
|
159
|
715 |
self do:[:thisChar |
|
|
716 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar].
|
|
717 |
aStream nextPut:thisChar
|
|
718 |
]
|
1
|
719 |
] ifFalse:[
|
159
|
720 |
aStream nextPutAll:self
|
1
|
721 |
].
|
|
722 |
aStream nextPut:$'
|
|
723 |
! !
|
|
724 |
|
|
725 |
!String methodsFor:'comparing'!
|
|
726 |
|
|
727 |
> aString
|
|
728 |
"Compare the receiver with the argument and return true if the
|
62
|
729 |
receiver is greater than the argument. Otherwise return false.
|
299
|
730 |
No national variants are honored; use after: for this.
|
62
|
731 |
In contrast to ST-80, case differences are NOT ignored, thus
|
|
732 |
'foo' > 'Foo' will return true.
|
|
733 |
This may change."
|
1
|
734 |
|
|
735 |
%{ /* NOCONTEXT */
|
|
736 |
|
|
737 |
int len1, len2, cmp;
|
|
738 |
REGISTER OBJ s = aString;
|
|
739 |
char *cp1, *cp2;
|
53
|
740 |
OBJ cls;
|
1
|
741 |
|
329
|
742 |
if (__isNonNilObject(s)
|
|
743 |
&& (((cls = __qClass(s)) == String) || (cls == Symbol) || (cls == __qClass(self)))) {
|
159
|
744 |
cp1 = (char *) _stringVal(self);
|
|
745 |
len1 = _stringSize(self);
|
53
|
746 |
|
159
|
747 |
/*
|
|
748 |
* care for instances of subclasses ...
|
|
749 |
*/
|
329
|
750 |
if (__qClass(self) != String) {
|
|
751 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(__qClass(self))->c_ninstvars));
|
1
|
752 |
|
159
|
753 |
cp1 += n;
|
|
754 |
len1 -= n;
|
|
755 |
}
|
1
|
756 |
|
159
|
757 |
cp2 = (char *) _stringVal(s);
|
|
758 |
len2 = _stringSize(s);
|
|
759 |
/*
|
|
760 |
* care for instances of subclasses ...
|
|
761 |
*/
|
|
762 |
if (cls != String) {
|
|
763 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
1
|
764 |
|
159
|
765 |
cp2 += n;
|
|
766 |
len2 -= n;
|
|
767 |
}
|
1
|
768 |
|
159
|
769 |
if (len1 <= len2)
|
|
770 |
cmp = strncmp(cp1, cp2, len1);
|
|
771 |
else
|
|
772 |
cmp = strncmp(cp1, cp2, len2);
|
1
|
773 |
|
159
|
774 |
if (cmp > 0) {
|
|
775 |
RETURN ( true );
|
|
776 |
}
|
|
777 |
if ((cmp == 0) && (len1 > len2)) {
|
|
778 |
RETURN ( true );
|
|
779 |
}
|
|
780 |
RETURN ( false );
|
1
|
781 |
}
|
299
|
782 |
%}.
|
1
|
783 |
^ super > aString
|
|
784 |
!
|
|
785 |
|
|
786 |
= aString
|
|
787 |
"Compare the receiver with the argument and return true if the
|
95
|
788 |
receiver is equal to the argument. Otherwise return false.
|
299
|
789 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo').
|
|
790 |
Use sameAs: to compare with case ignored."
|
1
|
791 |
|
|
792 |
%{ /* NOCONTEXT */
|
|
793 |
|
|
794 |
int l1, l2;
|
|
795 |
REGISTER OBJ s = aString;
|
|
796 |
char *cp1, *cp2;
|
53
|
797 |
OBJ cls;
|
1
|
798 |
|
|
799 |
if (s == self) {
|
159
|
800 |
RETURN ( true );
|
1
|
801 |
}
|
329
|
802 |
if (! __isNonNilObject(s)) {
|
159
|
803 |
RETURN ( false );
|
1
|
804 |
}
|
|
805 |
|
329
|
806 |
if (((cls = __qClass(s)) == String) || (cls == Symbol) || (cls == __qClass(self))) {
|
159
|
807 |
cp1 = (char *) _stringVal(self);
|
|
808 |
l1 = _stringSize(self);
|
|
809 |
/*
|
|
810 |
* care for instances of subclasses ...
|
|
811 |
*/
|
329
|
812 |
if (__qClass(self) != String) {
|
|
813 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(__qClass(self))->c_ninstvars));
|
1
|
814 |
|
159
|
815 |
cp1 += n;
|
|
816 |
l1 -= n;
|
|
817 |
}
|
1
|
818 |
|
159
|
819 |
cp2 = (char *) _stringVal(s);
|
|
820 |
l2 = _stringSize(s);
|
|
821 |
/*
|
|
822 |
* care for instances of subclasses ...
|
|
823 |
*/
|
|
824 |
if (cls != String) {
|
|
825 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
1
|
826 |
|
159
|
827 |
cp2 += n;
|
|
828 |
l2 -= n;
|
|
829 |
}
|
1
|
830 |
|
159
|
831 |
if (l1 != l2) {
|
|
832 |
RETURN ( false );
|
|
833 |
}
|
|
834 |
RETURN ( (strncmp(cp1, cp2, l1) == 0) ? true : false );
|
1
|
835 |
}
|
|
836 |
%}
|
|
837 |
.
|
|
838 |
^ super = aString
|
299
|
839 |
|
|
840 |
"
|
|
841 |
'foo' = 'Foo'
|
|
842 |
'foo' sameAs: 'Foo'
|
|
843 |
"
|
1
|
844 |
!
|
|
845 |
|
|
846 |
~= aString
|
|
847 |
"Compare the receiver with the argument and return true if the
|
95
|
848 |
receiver is not equal to the argument. Otherwise return false.
|
|
849 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo')"
|
1
|
850 |
|
|
851 |
%{ /* NOCONTEXT */
|
|
852 |
|
|
853 |
int l1, l2;
|
|
854 |
REGISTER OBJ s = aString;
|
|
855 |
char *cp1, *cp2;
|
53
|
856 |
OBJ cls;
|
1
|
857 |
|
|
858 |
if (s == self) {
|
159
|
859 |
RETURN ( false );
|
1
|
860 |
}
|
329
|
861 |
if (! __isNonNilObject(s)) {
|
159
|
862 |
RETURN ( true );
|
1
|
863 |
}
|
329
|
864 |
if (((cls = __qClass(s)) == String) || (cls == Symbol) || (cls == __qClass(self))) {
|
159
|
865 |
cp1 = (char *) _stringVal(self);
|
|
866 |
l1 = _stringSize(self);
|
|
867 |
/*
|
|
868 |
* care for instances of subclasses ...
|
|
869 |
*/
|
329
|
870 |
if (__qClass(self) != String) {
|
|
871 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(__qClass(self))->c_ninstvars));
|
1
|
872 |
|
159
|
873 |
cp1 += n;
|
|
874 |
l1 -= n;
|
|
875 |
}
|
1
|
876 |
|
159
|
877 |
cp2 = (char *) _stringVal(s);
|
|
878 |
l2 = _stringSize(s);
|
|
879 |
/*
|
|
880 |
* care for instances of subclasses ...
|
|
881 |
*/
|
|
882 |
if (cls != String) {
|
|
883 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
1
|
884 |
|
159
|
885 |
cp2 += n;
|
|
886 |
l2 -= n;
|
|
887 |
}
|
1
|
888 |
|
159
|
889 |
if (l1 != l2) {
|
|
890 |
RETURN ( true );
|
|
891 |
}
|
|
892 |
RETURN ( (strncmp(cp1, cp2, l1) == 0) ? false : true );
|
1
|
893 |
}
|
|
894 |
%}
|
|
895 |
.
|
|
896 |
^ super ~= aString
|
95
|
897 |
!
|
|
898 |
|
|
899 |
after:aString
|
|
900 |
"Compare the receiver with the argument and return true if the
|
|
901 |
receiver should come after the argument in a sorted list.
|
|
902 |
Otherwise return false.
|
|
903 |
The comparison is language specific, depending on the value of
|
|
904 |
LC_COLLATE, which is initialized from the environment."
|
|
905 |
|
|
906 |
%{ /* NOCONTEXT */
|
|
907 |
|
|
908 |
int cmp;
|
|
909 |
REGISTER OBJ s = aString;
|
|
910 |
char *cp1, *cp2;
|
|
911 |
OBJ cls;
|
|
912 |
|
329
|
913 |
if (__isNonNilObject(s)
|
|
914 |
&& (((cls = __qClass(s)) == String) || (cls == Symbol) || (cls == __qClass(self)))) {
|
159
|
915 |
cp1 = (char *) _stringVal(self);
|
95
|
916 |
|
159
|
917 |
/*
|
|
918 |
* care for instances of subclasses ...
|
|
919 |
*/
|
329
|
920 |
if (__qClass(self) != String) {
|
|
921 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(__qClass(self))->c_ninstvars));
|
95
|
922 |
|
159
|
923 |
cp1 += n;
|
|
924 |
}
|
95
|
925 |
|
159
|
926 |
cp2 = (char *) _stringVal(s);
|
|
927 |
/*
|
|
928 |
* care for instances of subclasses ...
|
|
929 |
*/
|
|
930 |
if (cls != String) {
|
|
931 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
95
|
932 |
|
159
|
933 |
cp2 += n;
|
|
934 |
}
|
95
|
935 |
|
|
936 |
#ifdef HAS_STRCOLL
|
159
|
937 |
cmp = strcoll(cp1, cp2);
|
95
|
938 |
#else
|
159
|
939 |
cmp = strcmp(cp1, cp2);
|
95
|
940 |
#endif
|
|
941 |
|
159
|
942 |
if (cmp > 0) {
|
|
943 |
RETURN ( true );
|
|
944 |
}
|
|
945 |
RETURN ( false );
|
95
|
946 |
}
|
|
947 |
%}.
|
|
948 |
"
|
|
949 |
currently, this operation is only defined for strings, symbols
|
|
950 |
and subclasses.
|
|
951 |
"
|
|
952 |
self primitiveFailed
|
1
|
953 |
! !
|
|
954 |
|
53
|
955 |
!String methodsFor:'character searching'!
|
1
|
956 |
|
|
957 |
occurrencesOf:aCharacter
|
|
958 |
"count the occurrences of the argument, aCharacter in myself
|
|
959 |
- reimplemented here for speed"
|
|
960 |
|
|
961 |
%{ /* NOCONTEXT */
|
|
962 |
|
|
963 |
REGISTER unsigned char *cp;
|
|
964 |
REGISTER int byteValue;
|
|
965 |
REGISTER int count;
|
53
|
966 |
OBJ cls;
|
1
|
967 |
|
53
|
968 |
if (__isCharacter(aCharacter)) {
|
159
|
969 |
count = 0;
|
|
970 |
byteValue = _intVal(_characterVal(aCharacter));
|
|
971 |
cp = _stringVal(self);
|
329
|
972 |
if ((cls = __qClass(self)) != String)
|
159
|
973 |
cp += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
974 |
while (*cp) {
|
|
975 |
if (*cp++ == byteValue) count++;
|
|
976 |
}
|
|
977 |
RETURN ( _MKSMALLINT(count) );
|
1
|
978 |
}
|
299
|
979 |
%}.
|
1
|
980 |
^ 0
|
53
|
981 |
|
95
|
982 |
"
|
|
983 |
'hello world' occurrencesOf:$a
|
|
984 |
'hello world' occurrencesOf:$w
|
|
985 |
'hello world' occurrencesOf:$l
|
|
986 |
'hello world' occurrencesOf:$x
|
|
987 |
'hello world' occurrencesOf:1
|
|
988 |
"
|
1
|
989 |
!
|
|
990 |
|
|
991 |
includes:aCharacter
|
|
992 |
"return true if the argument, aCharacter is included in the receiver
|
|
993 |
- reimplemented here for speed"
|
|
994 |
|
|
995 |
%{ /* NOCONTEXT */
|
|
996 |
|
|
997 |
REGISTER unsigned char *cp;
|
|
998 |
REGISTER int byteValue;
|
53
|
999 |
OBJ cls;
|
1
|
1000 |
|
53
|
1001 |
if (__isCharacter(aCharacter)) {
|
159
|
1002 |
byteValue = _intVal(_characterVal(aCharacter));
|
|
1003 |
cp = _stringVal(self);
|
329
|
1004 |
if ((cls = __qClass(self)) != String)
|
159
|
1005 |
cp += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
1
|
1006 |
#ifdef FAST_STRCHR
|
159
|
1007 |
cp = (unsigned char *) strchr(cp, _intVal(_characterVal(aCharacter)));
|
|
1008 |
if (cp) {
|
|
1009 |
RETURN ( true );
|
|
1010 |
}
|
1
|
1011 |
#else
|
159
|
1012 |
while (*cp) {
|
|
1013 |
if (*cp == byteValue) {
|
|
1014 |
RETURN ( true );
|
|
1015 |
}
|
|
1016 |
cp++;
|
|
1017 |
}
|
1
|
1018 |
#endif
|
|
1019 |
}
|
299
|
1020 |
%}.
|
1
|
1021 |
^ false
|
53
|
1022 |
|
95
|
1023 |
"
|
|
1024 |
'hello world' includes:$a
|
|
1025 |
'hello world' includes:$o
|
|
1026 |
'hello world' includes:$x
|
|
1027 |
'hello world' includes:1
|
299
|
1028 |
'hello world' asTwoByteString includes:$o
|
95
|
1029 |
"
|
1
|
1030 |
!
|
|
1031 |
|
10
|
1032 |
includesAny:aCollection
|
|
1033 |
"return true, if the receiver includes any of the characters in the
|
53
|
1034 |
argument, aCollection.
|
|
1035 |
- redefined for speed if the argument is a String."
|
10
|
1036 |
|
|
1037 |
%{ /* NOCONTEXT */
|
|
1038 |
|
|
1039 |
REGISTER unsigned char *cp;
|
|
1040 |
REGISTER unsigned char *matchP;
|
53
|
1041 |
OBJ cls;
|
10
|
1042 |
|
53
|
1043 |
if (__isString(aCollection)) {
|
159
|
1044 |
matchP = _stringVal(aCollection);
|
|
1045 |
cp = _stringVal(self);
|
329
|
1046 |
if ((cls = __qClass(self)) != String)
|
159
|
1047 |
cp += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
53
|
1048 |
|
159
|
1049 |
while (*cp) {
|
329
|
1050 |
if (strchr(matchP, *cp)) {
|
159
|
1051 |
RETURN ( true );
|
|
1052 |
}
|
|
1053 |
cp++;
|
|
1054 |
}
|
|
1055 |
RETURN ( false );
|
10
|
1056 |
}
|
|
1057 |
%}
|
|
1058 |
.
|
|
1059 |
^ super includesAny:aCollection
|
95
|
1060 |
|
|
1061 |
"
|
|
1062 |
'hello world' includesAny:'abcd'
|
|
1063 |
'hello world' includesAny:'xyz'
|
|
1064 |
'hello world' includesAny:(Array with:$a with:$b with:$d)
|
|
1065 |
'hello world' includesAny:(Array with:$x with:$y)
|
|
1066 |
'hello world' includesAny:(Array with:1 with:2)
|
|
1067 |
"
|
10
|
1068 |
!
|
|
1069 |
|
1
|
1070 |
indexOf:aCharacter
|
|
1071 |
"return the index of the first occurrences of the argument, aCharacter
|
|
1072 |
in the receiver or 0 if not found - reimplemented here for speed."
|
|
1073 |
|
|
1074 |
%{ /* NOCONTEXT */
|
|
1075 |
|
|
1076 |
REGISTER unsigned char *cp;
|
|
1077 |
#ifdef FAST_STRCHR
|
|
1078 |
char *strchr();
|
|
1079 |
#else
|
|
1080 |
REGISTER int byteValue;
|
|
1081 |
REGISTER int index;
|
370
|
1082 |
char c;
|
1
|
1083 |
#endif
|
53
|
1084 |
OBJ cls;
|
1
|
1085 |
|
53
|
1086 |
if (__isCharacter(aCharacter)) {
|
159
|
1087 |
cp = _stringVal(self);
|
329
|
1088 |
if ((cls = __qClass(self)) != String)
|
159
|
1089 |
cp += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
1
|
1090 |
#ifdef FAST_STRCHR
|
159
|
1091 |
cp = (unsigned char *) strchr(cp, _intVal(_characterVal(aCharacter)));
|
|
1092 |
if (cp) {
|
|
1093 |
RETURN ( _MKSMALLINT(cp - _stringVal(self) + 1) );
|
|
1094 |
}
|
1
|
1095 |
#else
|
159
|
1096 |
byteValue = _intVal(_characterVal(aCharacter));
|
|
1097 |
index = 1;
|
370
|
1098 |
while (c = *cp++) {
|
|
1099 |
if (c == byteValue) { RETURN ( _MKSMALLINT(index) ); }
|
159
|
1100 |
index++;
|
|
1101 |
}
|
1
|
1102 |
#endif
|
|
1103 |
}
|
370
|
1104 |
%}.
|
|
1105 |
"/ cannot include anything but characters ...
|
1
|
1106 |
^ 0
|
95
|
1107 |
|
|
1108 |
"
|
|
1109 |
'hello world' indexOf:(Character space)
|
|
1110 |
'hello world' indexOf:$A
|
|
1111 |
"
|
1
|
1112 |
!
|
|
1113 |
|
|
1114 |
indexOf:aCharacter startingAt:start
|
|
1115 |
"return the index of the first occurrence of the argument, aCharacter
|
|
1116 |
in myself starting at start, anInteger or 0 if not found;
|
|
1117 |
- reimplemented here for speed"
|
|
1118 |
|
|
1119 |
%{ /* NOCONTEXT */
|
|
1120 |
|
|
1121 |
REGISTER unsigned char *cp;
|
|
1122 |
REGISTER int index, byteValue;
|
|
1123 |
#ifdef FAST_STRCHR
|
|
1124 |
char *strchr();
|
370
|
1125 |
#else
|
|
1126 |
char c;
|
1
|
1127 |
#endif
|
|
1128 |
int len;
|
53
|
1129 |
OBJ cls;
|
1
|
1130 |
|
252
|
1131 |
if (__isSmallInteger(start)) {
|
159
|
1132 |
if (__isCharacter(aCharacter)) {
|
|
1133 |
byteValue = _intVal(_characterVal(aCharacter));
|
|
1134 |
index = _intVal(start);
|
|
1135 |
if (index <= 0)
|
|
1136 |
index = 1;
|
329
|
1137 |
if ((cls = __qClass(self)) != String)
|
159
|
1138 |
index += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
1139 |
len = _stringSize(self);
|
|
1140 |
if (index <= len) {
|
|
1141 |
cp = _stringVal(self) + index - 1;
|
1
|
1142 |
#ifdef FAST_STRCHR
|
159
|
1143 |
cp = (unsigned char *) strchr(cp, byteValue);
|
|
1144 |
if (cp) {
|
|
1145 |
RETURN ( _MKSMALLINT(cp - _stringVal(self) + 1) );
|
|
1146 |
}
|
1
|
1147 |
#else
|
370
|
1148 |
while (c = *cp++) {
|
|
1149 |
if (c == byteValue) {
|
159
|
1150 |
RETURN ( _MKSMALLINT(index) );
|
|
1151 |
}
|
|
1152 |
index++;
|
|
1153 |
}
|
1
|
1154 |
#endif
|
159
|
1155 |
}
|
|
1156 |
}
|
|
1157 |
RETURN ( _MKSMALLINT(0) );
|
1
|
1158 |
}
|
370
|
1159 |
%}.
|
1
|
1160 |
^ super indexOf:aCharacter startingAt:start
|
53
|
1161 |
|
95
|
1162 |
"
|
|
1163 |
'hello world' indexOf:$l startingAt:1
|
|
1164 |
'hello world' indexOf:$l startingAt:5
|
|
1165 |
"
|
1
|
1166 |
!
|
|
1167 |
|
|
1168 |
indexOfSeparatorStartingAt:start
|
|
1169 |
"return the index of the next separator character"
|
|
1170 |
|
|
1171 |
%{ /* NOCONTEXT */
|
|
1172 |
|
|
1173 |
REGISTER unsigned char *cp;
|
|
1174 |
REGISTER char c;
|
|
1175 |
int len, index;
|
53
|
1176 |
OBJ cls;
|
1
|
1177 |
|
|
1178 |
index = _intVal(start);
|
|
1179 |
if (index <= 0) {
|
159
|
1180 |
index = 1;
|
1
|
1181 |
}
|
329
|
1182 |
if ((cls = __qClass(self)) != String)
|
159
|
1183 |
index += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
1
|
1184 |
len = _stringSize(self);
|
|
1185 |
if (index > len) {
|
159
|
1186 |
RETURN ( _MKSMALLINT(0) );
|
1
|
1187 |
}
|
|
1188 |
cp = _stringVal(self) + index - 1;
|
|
1189 |
while (c = *cp++) {
|
329
|
1190 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */
|
159
|
1191 |
if (c <= ' ')
|
1
|
1192 |
#endif
|
159
|
1193 |
if ((c == ' ') || (c == '\t') || (c == '\n')
|
|
1194 |
|| (c == '\r') || (c == '\f')) {
|
|
1195 |
RETURN ( _MKSMALLINT(cp - _stringVal(self)) );
|
|
1196 |
}
|
1
|
1197 |
}
|
|
1198 |
%}
|
|
1199 |
.
|
|
1200 |
^ 0
|
53
|
1201 |
|
95
|
1202 |
"
|
|
1203 |
'hello world' indexOfSeparatorStartingAt:3
|
|
1204 |
'hello world' indexOfSeparatorStartingAt:7
|
|
1205 |
"
|
53
|
1206 |
! !
|
|
1207 |
|
|
1208 |
!String methodsFor:'pattern matching'!
|
2
|
1209 |
|
1
|
1210 |
startsWith:aString
|
62
|
1211 |
"return true, if the receiver starts with something, aString."
|
1
|
1212 |
|
375
|
1213 |
%{ /* NOCONTEXT */
|
|
1214 |
|
1
|
1215 |
int len1, len2;
|
|
1216 |
REGISTER unsigned char *src1, *src2;
|
370
|
1217 |
char c;
|
1
|
1218 |
|
375
|
1219 |
if ((__isString(self) || __isSymbol(self))
|
|
1220 |
&& (__isString(aString) || __isSymbol(aString))) {
|
379
|
1221 |
len1 = __qSize(self);
|
|
1222 |
len2 = __qSize(aString);
|
|
1223 |
if (len1 < len2) {
|
375
|
1224 |
RETURN ( false );
|
379
|
1225 |
}
|
375
|
1226 |
|
379
|
1227 |
src1 = _stringVal(self);
|
|
1228 |
src2 = _stringVal(aString);
|
|
1229 |
while (c = *src2++) {
|
375
|
1230 |
if (c != *src1++) {
|
379
|
1231 |
RETURN ( false );
|
375
|
1232 |
}
|
|
1233 |
}
|
|
1234 |
RETURN (true);
|
1
|
1235 |
}
|
375
|
1236 |
%}.
|
|
1237 |
(aString isMemberOf:Character) ifTrue:[
|
379
|
1238 |
self size == 0 ifTrue:[^ false].
|
|
1239 |
^ (self at:1) == aString
|
375
|
1240 |
].
|
|
1241 |
^ super startsWith:aString
|
1
|
1242 |
|
95
|
1243 |
"
|
|
1244 |
'hello world' startsWith:'hello'
|
|
1245 |
'hello world' startsWith:'hi'
|
375
|
1246 |
'hello world' startsWith:$h
|
|
1247 |
'hello world' startsWith:#($h $e $l)
|
95
|
1248 |
"
|
1
|
1249 |
!
|
|
1250 |
|
|
1251 |
endsWith:aString
|
62
|
1252 |
"return true, if the receiver end with something, aString."
|
1
|
1253 |
|
375
|
1254 |
%{ /* NOCONTEXT */
|
|
1255 |
|
1
|
1256 |
int len1, len2;
|
|
1257 |
REGISTER unsigned char *src1, *src2;
|
370
|
1258 |
char c;
|
1
|
1259 |
|
375
|
1260 |
if ((__isString(self) || __isSymbol(self))
|
|
1261 |
&& (__isString(aString) || __isSymbol(aString))) {
|
379
|
1262 |
len1 = __qSize(self);
|
|
1263 |
len2 = __qSize(aString);
|
|
1264 |
if (len1 < len2) {
|
375
|
1265 |
RETURN ( false );
|
379
|
1266 |
}
|
375
|
1267 |
|
379
|
1268 |
src1 = _stringVal(self) + len1 - len2;
|
|
1269 |
src2 = _stringVal(aString);
|
|
1270 |
while (c = *src2++) {
|
375
|
1271 |
if (c != *src1++) {
|
379
|
1272 |
RETURN ( false );
|
375
|
1273 |
}
|
|
1274 |
}
|
|
1275 |
RETURN (true);
|
1
|
1276 |
}
|
370
|
1277 |
%}.
|
375
|
1278 |
(aString isMemberOf:Character) ifTrue:[
|
|
1279 |
self size == 0 ifTrue:[^ false].
|
|
1280 |
^ (self at:(self size)) == aString
|
|
1281 |
].
|
|
1282 |
^ super endsWith:aString
|
1
|
1283 |
|
95
|
1284 |
"
|
|
1285 |
'hello world' endsWith:'world'
|
|
1286 |
'hello world' endsWith:'earth'
|
375
|
1287 |
'hello world' endsWith:$d
|
|
1288 |
'hello world' endsWith:#($r $l $d)
|
95
|
1289 |
"
|
53
|
1290 |
! !
|
|
1291 |
|
|
1292 |
!String methodsFor:'testing'!
|
1
|
1293 |
|
|
1294 |
isBlank
|
370
|
1295 |
"return true, if the receivers size is 0 or if it contains only spaces.
|
|
1296 |
Q: should we care for whiteSpace in general here ?"
|
1
|
1297 |
|
|
1298 |
%{ /* NOCONTEXT */
|
|
1299 |
|
|
1300 |
REGISTER unsigned char *src;
|
329
|
1301 |
REGISTER unsigned char c;
|
53
|
1302 |
OBJ cls;
|
1
|
1303 |
|
|
1304 |
src = _stringVal(self);
|
329
|
1305 |
if ((cls = __qClass(self)) != String)
|
159
|
1306 |
src += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
1
|
1307 |
|
370
|
1308 |
#ifndef NON_ASCII
|
|
1309 |
while (*((unsigned *)src) == 0x20202020) {
|
|
1310 |
src += 4;
|
|
1311 |
}
|
|
1312 |
#endif
|
329
|
1313 |
while (c = *src++)
|
|
1314 |
if (c != ' ') {
|
159
|
1315 |
RETURN ( false );
|
|
1316 |
}
|
329
|
1317 |
%}.
|
1
|
1318 |
^ true
|
|
1319 |
!
|
|
1320 |
|
|
1321 |
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight
|
|
1322 |
"parametrized levenshtein. arguments are the costs for
|
|
1323 |
substitution, case-change, insertion and deletion of a character."
|
|
1324 |
|
13
|
1325 |
%{ /* STACK: 4000 */
|
1
|
1326 |
|
|
1327 |
/*
|
|
1328 |
* this is very heavy used when correcting errors
|
|
1329 |
* (all symbols are searched for best match) - therefore it must be fast
|
|
1330 |
*/
|
|
1331 |
{
|
|
1332 |
unsigned short *data;
|
|
1333 |
int l1, l2;
|
|
1334 |
REGISTER int sz;
|
|
1335 |
unsigned char *s1, *s2;
|
|
1336 |
int v1, v2, v3, m;
|
|
1337 |
REGISTER unsigned short *dp;
|
|
1338 |
REGISTER int delta;
|
|
1339 |
REGISTER int j;
|
|
1340 |
int i;
|
|
1341 |
int iW, cW, sW, dW;
|
|
1342 |
# define FASTSIZE 30
|
2
|
1343 |
unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)];
|
1
|
1344 |
|
53
|
1345 |
if ((__isString(self) || __isSymbol(self))
|
|
1346 |
&& (__isString(aString) || __isSymbol(aString))
|
252
|
1347 |
&& __bothSmallInteger(insrtWeight, caseWeight)
|
|
1348 |
&& __bothSmallInteger(substWeight, deleteWeight)) {
|
159
|
1349 |
iW = _intVal(insrtWeight);
|
|
1350 |
cW = _intVal(caseWeight);
|
|
1351 |
sW = _intVal(substWeight);
|
|
1352 |
dW = _intVal(deleteWeight);
|
|
1353 |
s1 = _stringVal(self);
|
|
1354 |
s2 = _stringVal(aString);
|
|
1355 |
l1 = strlen(s1);
|
|
1356 |
l2 = strlen(s2);
|
1
|
1357 |
|
159
|
1358 |
sz = (l1 < l2) ? l2 : l1;
|
|
1359 |
delta = sz + 1;
|
|
1360 |
if (sz <= FASTSIZE) {
|
|
1361 |
data = fastData;
|
|
1362 |
} else {
|
|
1363 |
/* add ifdef ALLOCA here ... */
|
|
1364 |
data = (unsigned short *)malloc(delta * delta * sizeof(short));
|
244
|
1365 |
if (! data) goto mallocFailed;
|
159
|
1366 |
}
|
62
|
1367 |
|
159
|
1368 |
data[0] = 0;
|
|
1369 |
dp = data+1;
|
|
1370 |
for (j=1, dp=data+1; j<=sz; j++, dp++)
|
|
1371 |
*dp = *(dp-1) + iW;
|
62
|
1372 |
|
159
|
1373 |
for (i=1, dp=data+delta; i<=sz; i++, dp+=delta)
|
|
1374 |
*dp = *(dp-delta) + dW;
|
1
|
1375 |
|
159
|
1376 |
for (i=1; i<=l1; i++) {
|
|
1377 |
for (j=1; j<=l2; j++) {
|
|
1378 |
dp = data + (i*delta) + j;
|
|
1379 |
if (s1[i] != s2[j]) {
|
|
1380 |
if (tolower(s1[i]) == tolower(s2[j])) {
|
|
1381 |
m = cW;
|
|
1382 |
} else {
|
|
1383 |
m = sW;
|
|
1384 |
}
|
|
1385 |
} else
|
|
1386 |
m = 0;
|
1
|
1387 |
|
159
|
1388 |
v2 = *(dp - 1) + iW;
|
|
1389 |
v3 = *(dp - delta) + dW;
|
|
1390 |
v1 = *(dp - delta - 1) + m;
|
|
1391 |
if (v1 < v2)
|
|
1392 |
if (v1 < v3)
|
|
1393 |
m = v1;
|
|
1394 |
else
|
|
1395 |
m = v3;
|
|
1396 |
else
|
|
1397 |
if (v2 < v3)
|
|
1398 |
m = v2;
|
|
1399 |
else
|
|
1400 |
m = v3;
|
|
1401 |
*dp = m;
|
|
1402 |
}
|
|
1403 |
}
|
|
1404 |
m = data[l1 * delta + l2];
|
|
1405 |
if (sz > FASTSIZE)
|
|
1406 |
free(data);
|
|
1407 |
RETURN ( _MKSMALLINT(m) );
|
1
|
1408 |
}
|
244
|
1409 |
mallocFailed: ;
|
1
|
1410 |
}
|
244
|
1411 |
%}.
|
1
|
1412 |
|
62
|
1413 |
^ super levenshteinTo:aString
|
159
|
1414 |
s:substWeight c:caseWeight
|
|
1415 |
i:insrtWeight d:deleteWeight
|
1
|
1416 |
|
|
1417 |
"'ocmprt' levenshteinTo:'computer'
|
|
1418 |
'computer' levenshteinTo:'computer'
|
|
1419 |
'ocmputer' levenshteinTo:'computer'
|
|
1420 |
'cmputer' levenshteinTo:'computer'
|
|
1421 |
'Computer' levenshteinTo:'computer'"
|
|
1422 |
! !
|
|
1423 |
|
|
1424 |
!String methodsFor:'copying'!
|
|
1425 |
|
|
1426 |
shallowCopy
|
2
|
1427 |
"return a copy of the receiver"
|
1
|
1428 |
|
2
|
1429 |
(self isMemberOf:String) ifTrue:[
|
159
|
1430 |
^ self copyFrom:1
|
2
|
1431 |
].
|
|
1432 |
^ super shallowCopy
|
1
|
1433 |
!
|
|
1434 |
|
13
|
1435 |
deepCopyUsing:aDictionary
|
|
1436 |
"return a copy of the receiver - reimplemented to be a bit faster"
|
|
1437 |
|
159
|
1438 |
"
|
|
1439 |
could be an instance of a subclass which needs deepCopy
|
|
1440 |
of its named instvars ...
|
|
1441 |
"
|
13
|
1442 |
(self isMemberOf:String) ifTrue:[
|
159
|
1443 |
^ self copyFrom:1
|
13
|
1444 |
].
|
|
1445 |
^ super deepCopy
|
|
1446 |
!
|
|
1447 |
|
|
1448 |
simpleDeepCopy
|
|
1449 |
"return a copy of the receiver"
|
|
1450 |
|
159
|
1451 |
"
|
|
1452 |
could be an instance of a subclass which needs deepCopy
|
|
1453 |
of its named instvars ...
|
|
1454 |
"
|
13
|
1455 |
(self isMemberOf:String) ifTrue:[
|
159
|
1456 |
^ self copyFrom:1
|
13
|
1457 |
].
|
|
1458 |
^ super deepCopy
|
|
1459 |
!
|
|
1460 |
|
1
|
1461 |
deepCopy
|
2
|
1462 |
"return a copy of the receiver"
|
1
|
1463 |
|
159
|
1464 |
"
|
|
1465 |
could be an instance of a subclass which needs deepCopy
|
|
1466 |
of its named instvars ...
|
|
1467 |
"
|
2
|
1468 |
(self isMemberOf:String) ifTrue:[
|
159
|
1469 |
^ self copyFrom:1
|
2
|
1470 |
].
|
|
1471 |
^ super deepCopy
|
1
|
1472 |
!
|
|
1473 |
|
|
1474 |
, aString
|
2
|
1475 |
"return the concatenation of myself and the argument, aString as
|
|
1476 |
a String.
|
1
|
1477 |
- reimplemented here for speed"
|
|
1478 |
|
|
1479 |
%{
|
95
|
1480 |
int l1, l2, sz;
|
1
|
1481 |
char *cp1, *cp2;
|
|
1482 |
REGISTER unsigned char *dstp;
|
|
1483 |
REGISTER OBJ s = aString;
|
329
|
1484 |
REGISTER OBJ _string = String;
|
13
|
1485 |
OBJ myClass, argClass, newString;
|
1
|
1486 |
|
329
|
1487 |
if (__isNonNilObject(s)) {
|
|
1488 |
myClass = __qClass(self);
|
|
1489 |
argClass = __qClass(s);
|
95
|
1490 |
/*
|
368
|
1491 |
* can do it here if
|
95
|
1492 |
* either same class or both Strings/Symbols:
|
|
1493 |
*/
|
159
|
1494 |
if ((myClass == argClass)
|
329
|
1495 |
|| (((myClass == _string) || (myClass == Symbol))
|
|
1496 |
&& ((argClass == _string) || (argClass == Symbol)))) {
|
159
|
1497 |
cp1 = (char *) _stringVal(self);
|
|
1498 |
l1 = _stringSize(self);
|
329
|
1499 |
if (myClass != _string) {
|
|
1500 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(__qClass(self))->c_ninstvars));
|
1
|
1501 |
|
159
|
1502 |
cp1 += n;
|
|
1503 |
l1 -= n;
|
|
1504 |
}
|
1
|
1505 |
|
159
|
1506 |
cp2 = (char *) _stringVal(s);
|
|
1507 |
l2 = _stringSize(s);
|
329
|
1508 |
if (argClass != _string) {
|
|
1509 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(__qClass(s))->c_ninstvars));
|
1
|
1510 |
|
159
|
1511 |
cp2 += n;
|
|
1512 |
l2 -= n;
|
|
1513 |
}
|
1
|
1514 |
|
95
|
1515 |
sz = OHDR_SIZE + l1 + l2 + 1;
|
159
|
1516 |
_qNew(newString, sz, __context);
|
|
1517 |
if (newString != nil) {
|
|
1518 |
_InstPtr(newString)->o_class = String;
|
|
1519 |
dstp = _stringVal(newString);
|
95
|
1520 |
/*
|
|
1521 |
* refetch in case of a GC
|
|
1522 |
*/
|
|
1523 |
cp1 = (char *) _stringVal(self);
|
209
|
1524 |
cp2 = (char *) _stringVal(aString);
|
1
|
1525 |
#ifdef FAST_MEMCPY
|
159
|
1526 |
bcopy(cp1, dstp, l1);
|
|
1527 |
bcopy(cp2, dstp + l1, l2+1);
|
1
|
1528 |
#else
|
|
1529 |
# ifdef FAST_STRCPY
|
159
|
1530 |
strcpy(dstp, cp1);
|
|
1531 |
strcpy(dstp + l1, cp2);
|
1
|
1532 |
# else
|
159
|
1533 |
while ((*dstp++ = *cp1++) != '\0') ;
|
|
1534 |
dstp--;
|
|
1535 |
while ((*dstp++ = *cp2++) != '\0') ;
|
1
|
1536 |
# endif
|
|
1537 |
#endif
|
159
|
1538 |
RETURN ( newString );
|
|
1539 |
}
|
|
1540 |
}
|
1
|
1541 |
}
|
|
1542 |
%}
|
|
1543 |
.
|
|
1544 |
^ super , aString
|
|
1545 |
!
|
|
1546 |
|
|
1547 |
concatenate:string1 and:string2
|
|
1548 |
"return the concatenation of myself and the arguments, string1 and string2.
|
|
1549 |
This is equivalent to self , string1 , string2
|
|
1550 |
- generated by compiler when such a construct is detected"
|
|
1551 |
|
|
1552 |
|newString|
|
|
1553 |
%{
|
95
|
1554 |
int len1, len2, len3, sz;
|
1
|
1555 |
#if !defined(FAST_MEMCPY) && !defined(FAST_STRCPY)
|
|
1556 |
REGISTER unsigned char *srcp;
|
|
1557 |
#endif
|
|
1558 |
REGISTER unsigned char *dstp;
|
|
1559 |
|
53
|
1560 |
if ((__isString(self) || __isSymbol(self))
|
|
1561 |
&& (__isString(string1) || __isSymbol(string1))
|
|
1562 |
&& (__isString(string2) || __isSymbol(string2))) {
|
159
|
1563 |
len1 = _stringSize(self);
|
|
1564 |
len2 = _stringSize(string1);
|
|
1565 |
len3 = _stringSize(string2);
|
95
|
1566 |
sz = OHDR_SIZE + len1 + len2 + len3 + 1;
|
159
|
1567 |
_qNew(newString, sz, __context);
|
|
1568 |
if (newString != nil) {
|
|
1569 |
_InstPtr(newString)->o_class = String;
|
|
1570 |
dstp = _stringVal(newString);
|
1
|
1571 |
#ifdef FAST_MEMCPY
|
159
|
1572 |
bcopy(_stringVal(self), dstp, len1);
|
|
1573 |
bcopy(_stringVal(string1), dstp + len1, len2);
|
|
1574 |
bcopy(_stringVal(string2), dstp + len1 + len2, len3+1);
|
1
|
1575 |
#else
|
|
1576 |
# ifdef FAST_STRCPY
|
159
|
1577 |
strcpy(dstp, _stringVal(self));
|
|
1578 |
strcpy(dstp + len1, _stringVal(string1));
|
|
1579 |
strcpy(dstp + len1 + len2, _stringVal(string2));
|
1
|
1580 |
# else
|
159
|
1581 |
srcp = _stringVal(self);
|
|
1582 |
while ((*dstp++ = *srcp++) != '\0') ;
|
|
1583 |
dstp--;
|
|
1584 |
srcp = _stringVal(string1);
|
|
1585 |
while ((*dstp++ = *srcp++) != '\0') ;
|
|
1586 |
dstp--;
|
|
1587 |
srcp = _stringVal(string2);
|
|
1588 |
while ((*dstp++ = *srcp++) != '\0') ;
|
1
|
1589 |
# endif
|
|
1590 |
#endif
|
159
|
1591 |
RETURN ( newString );
|
|
1592 |
}
|
1
|
1593 |
}
|
|
1594 |
%}
|
|
1595 |
.
|
|
1596 |
^ super , string1 , string2
|
|
1597 |
!
|
|
1598 |
|
|
1599 |
concatenate:string1 and:string2 and:string3
|
|
1600 |
"return the concatenation of myself and the string arguments.
|
|
1601 |
This is equivalent to self , string1 , string2 , string3
|
|
1602 |
- generated by compiler when such a construct is detected"
|
|
1603 |
|
|
1604 |
|newString|
|
|
1605 |
%{
|
95
|
1606 |
int len1, len2, len3, len4, sz;
|
1
|
1607 |
#if !defined(FAST_MEMCPY) && !defined(FAST_STRCPY)
|
|
1608 |
REGISTER unsigned char *srcp;
|
|
1609 |
#endif
|
|
1610 |
REGISTER unsigned char *dstp;
|
|
1611 |
|
53
|
1612 |
if ((__isString(self) || __isSymbol(self))
|
|
1613 |
&& (__isString(string1) || __isSymbol(string1))
|
|
1614 |
&& (__isString(string2) || __isSymbol(string2))
|
|
1615 |
&& (__isString(string3) || __isSymbol(string3))) {
|
159
|
1616 |
len1 = _stringSize(self);
|
|
1617 |
len2 = _stringSize(string1);
|
|
1618 |
len3 = _stringSize(string2);
|
|
1619 |
len4 = _stringSize(string3);
|
95
|
1620 |
sz = OHDR_SIZE + len1 + len2 + len3 + len4 + 1;
|
159
|
1621 |
_qNew(newString, sz, __context);
|
|
1622 |
if (newString != nil) {
|
|
1623 |
_InstPtr(newString)->o_class = String;
|
|
1624 |
dstp = _stringVal(newString);
|
1
|
1625 |
#ifdef FAST_MEMCPY
|
159
|
1626 |
bcopy(_stringVal(self), dstp, len1);
|
|
1627 |
bcopy(_stringVal(string1), dstp + len1, len2);
|
|
1628 |
bcopy(_stringVal(string2), dstp + len1 + len2, len3);
|
|
1629 |
bcopy(_stringVal(string3), dstp + len1 + len2 + len3, len4+1);
|
1
|
1630 |
#else
|
|
1631 |
# ifdef FAST_STRCPY
|
159
|
1632 |
strcpy(dstp, _stringVal(self));
|
|
1633 |
strcpy(dstp + len1, _stringVal(string1));
|
|
1634 |
strcpy(dstp + len1 + len2, _stringVal(string2));
|
|
1635 |
strcpy(dstp + len1 + len2 + len3, _stringVal(string3));
|
1
|
1636 |
# else
|
159
|
1637 |
srcp = _stringVal(self);
|
|
1638 |
while ((*dstp++ = *srcp++) != '\0') ;
|
|
1639 |
dstp--;
|
|
1640 |
srcp = _stringVal(string1);
|
|
1641 |
while ((*dstp++ = *srcp++) != '\0') ;
|
|
1642 |
dstp--;
|
|
1643 |
srcp = _stringVal(string2);
|
|
1644 |
while ((*dstp++ = *srcp++) != '\0') ;
|
|
1645 |
dstp--;
|
|
1646 |
srcp = _stringVal(string3);
|
|
1647 |
while ((*dstp++ = *srcp++) != '\0') ;
|
1
|
1648 |
# endif
|
|
1649 |
#endif
|
159
|
1650 |
RETURN ( newString );
|
|
1651 |
}
|
1
|
1652 |
}
|
|
1653 |
%}
|
|
1654 |
.
|
|
1655 |
^ super , string1 , string2 , string3
|
|
1656 |
!
|
|
1657 |
|
|
1658 |
copyWith:aCharacter
|
233
|
1659 |
"return a new string containing the receivers characters
|
|
1660 |
and the single new character, aCharacter.
|
|
1661 |
This is different from concatentation, which expects another string
|
|
1662 |
as argument, but equivalent to copy-and-addLast.
|
|
1663 |
Reimplemented here for more speed"
|
1
|
1664 |
|
13
|
1665 |
%{ /* NOCONTEXT */
|
1
|
1666 |
|
|
1667 |
int sz;
|
|
1668 |
REGISTER unsigned char *dstp;
|
|
1669 |
int offs;
|
53
|
1670 |
OBJ cls, newString;
|
1
|
1671 |
|
53
|
1672 |
if (__isCharacter(aCharacter)) {
|
329
|
1673 |
sz = __qSize(self) + 1;
|
|
1674 |
if ((cls = __qClass(self)) != String) {
|
159
|
1675 |
offs = __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
1676 |
sz -= offs;
|
|
1677 |
} else
|
|
1678 |
offs = 0;
|
1
|
1679 |
|
159
|
1680 |
PROTECT_CONTEXT
|
|
1681 |
_qNew(newString, sz, SENDER);
|
|
1682 |
UNPROTECT_CONTEXT
|
|
1683 |
if (newString) {
|
|
1684 |
_InstPtr(newString)->o_class = String;
|
|
1685 |
dstp = _stringVal(newString);
|
1
|
1686 |
#ifdef FAST_MEMCPY
|
159
|
1687 |
sz = sz - OHDR_SIZE - 1 - 1;
|
|
1688 |
bcopy(_stringVal(self) + offs, dstp, sz);
|
|
1689 |
dstp += sz;
|
1
|
1690 |
#else
|
|
1691 |
# ifdef FAST_STRCPY
|
159
|
1692 |
strcpy(dstp, _stringVal(self) + offs);
|
|
1693 |
dstp += sz - OHDR_SIZE - 1 - 1;
|
1
|
1694 |
# else
|
159
|
1695 |
{
|
|
1696 |
REGISTER unsigned char *srcp;
|
1
|
1697 |
|
159
|
1698 |
srcp = _stringVal(self) + offs;
|
|
1699 |
while ((*dstp = *srcp++) != '\0')
|
|
1700 |
dstp++;
|
|
1701 |
}
|
1
|
1702 |
# endif
|
|
1703 |
#endif
|
159
|
1704 |
*dstp++ = _intVal(_characterVal(aCharacter));
|
|
1705 |
*dstp = '\0';
|
|
1706 |
RETURN (newString );
|
|
1707 |
}
|
13
|
1708 |
}
|
51
|
1709 |
%}.
|
|
1710 |
"fall back in case of non-character arg;
|
|
1711 |
will eventually lead to an bad element signal raise"
|
|
1712 |
|
13
|
1713 |
^ super copyWith:aCharacter
|
1
|
1714 |
!
|
|
1715 |
|
|
1716 |
copyFrom:start to:stop
|
|
1717 |
"return the substring starting at index start, anInteger and ending
|
53
|
1718 |
at stop, anInteger. This method will always return a string, even
|
|
1719 |
if the receiver is a subclass-instance. This might change if there is a need.
|
1
|
1720 |
- reimplemented here for speed"
|
|
1721 |
|
13
|
1722 |
%{ /* NOCONTEXT */
|
|
1723 |
|
1
|
1724 |
#if !defined(FAST_MEMCPY)
|
|
1725 |
REGISTER unsigned char *srcp;
|
|
1726 |
#endif
|
|
1727 |
REGISTER unsigned char *dstp;
|
|
1728 |
REGISTER int count;
|
95
|
1729 |
int len, sz, index1, index2;
|
13
|
1730 |
OBJ newString;
|
1
|
1731 |
|
252
|
1732 |
if (__bothSmallInteger(start, stop)) {
|
159
|
1733 |
len = _stringSize(self);
|
|
1734 |
index1 = _intVal(start);
|
|
1735 |
index2 = _intVal(stop);
|
1
|
1736 |
|
159
|
1737 |
if ((index1 <= index2) && (index1 > 0)) {
|
329
|
1738 |
if (__qClass(self) != String) {
|
|
1739 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(__qClass(self))->c_ninstvars));
|
1
|
1740 |
|
159
|
1741 |
index1 += n;
|
|
1742 |
index2 += n;
|
|
1743 |
}
|
|
1744 |
if (index2 <= len) {
|
|
1745 |
count = index2 - index1 + 1;
|
|
1746 |
PROTECT_CONTEXT
|
95
|
1747 |
sz = OHDR_SIZE + count + 1;
|
159
|
1748 |
_qNew(newString, sz, SENDER);
|
|
1749 |
UNPROTECT_CONTEXT
|
|
1750 |
if (newString != nil) {
|
|
1751 |
_InstPtr(newString)->o_class = String;
|
|
1752 |
dstp = _stringVal(newString);
|
1
|
1753 |
#ifdef FAST_MEMCPY
|
159
|
1754 |
bcopy(_stringVal(self) + index1 - 1, dstp, count);
|
|
1755 |
dstp[count] = '\0';
|
1
|
1756 |
#else
|
209
|
1757 |
# ifdef FAST_STRCPY
|
|
1758 |
strncpy(dstp, _stringVal(self) + index1 - 1, count);
|
|
1759 |
dstp[count] = '\0';
|
|
1760 |
# else
|
159
|
1761 |
srcp = _stringVal(self) + index1 - 1;
|
|
1762 |
while (count--) {
|
|
1763 |
*dstp++ = *srcp++;
|
|
1764 |
}
|
|
1765 |
*dstp = '\0';
|
209
|
1766 |
# endif
|
13
|
1767 |
#endif
|
159
|
1768 |
RETURN ( newString );
|
|
1769 |
}
|
|
1770 |
}
|
|
1771 |
}
|
375
|
1772 |
/*
|
|
1773 |
* allow empty copy
|
|
1774 |
*/
|
|
1775 |
if (index1 > index2) {
|
|
1776 |
PROTECT_CONTEXT
|
|
1777 |
_qNew(newString, OHDR_SIZE+1, SENDER);
|
|
1778 |
UNPROTECT_CONTEXT
|
|
1779 |
if (newString != nil) {
|
|
1780 |
_InstPtr(newString)->o_class = String;
|
|
1781 |
__stringVal(newString)[0] = '\0';
|
|
1782 |
RETURN ( newString );
|
|
1783 |
}
|
|
1784 |
}
|
1
|
1785 |
}
|
51
|
1786 |
%}.
|
|
1787 |
"fall back in case of non-integer index or out-of-bound index;
|
|
1788 |
will eventually lead to an out-of-bound signal raise"
|
|
1789 |
|
1
|
1790 |
^ super copyFrom:start to:stop
|
|
1791 |
!
|
|
1792 |
|
|
1793 |
copyFrom:start
|
53
|
1794 |
"return the substring from start, anInteger to the end.
|
|
1795 |
This method will always return a string, even if the receiver
|
|
1796 |
is a subclass-instance. This might change if there is a need.
|
1
|
1797 |
- reimplemented here for speed"
|
|
1798 |
|
13
|
1799 |
%{ /* NOCONTEXT */
|
|
1800 |
|
1
|
1801 |
#if !defined(FAST_MEMCPY)
|
|
1802 |
REGISTER unsigned char *srcp;
|
|
1803 |
#endif
|
|
1804 |
REGISTER unsigned char *dstp;
|
|
1805 |
REGISTER int count;
|
95
|
1806 |
int len, index1, sz;
|
13
|
1807 |
OBJ newString;
|
1
|
1808 |
|
252
|
1809 |
if (__isSmallInteger(start)) {
|
159
|
1810 |
len = _stringSize(self);
|
|
1811 |
index1 = _intVal(start);
|
|
1812 |
if (index1 > 0) {
|
329
|
1813 |
if (__qClass(self) != String) {
|
|
1814 |
int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(__qClass(self))->c_ninstvars));
|
1
|
1815 |
|
159
|
1816 |
index1 += n;
|
|
1817 |
}
|
|
1818 |
if (index1 <= len) {
|
|
1819 |
count = len - index1 + 1;
|
|
1820 |
PROTECT_CONTEXT
|
95
|
1821 |
sz = OHDR_SIZE + count + 1;
|
159
|
1822 |
_qNew(newString, sz, SENDER);
|
|
1823 |
UNPROTECT_CONTEXT
|
|
1824 |
if (newString != nil) {
|
|
1825 |
_InstPtr(newString)->o_class = String;
|
|
1826 |
dstp = _stringVal(newString);
|
1
|
1827 |
#ifdef FAST_MEMCPY
|
159
|
1828 |
bcopy(_stringVal(self) + index1 - 1, dstp, count);
|
|
1829 |
dstp[count] = '\0';
|
1
|
1830 |
#else
|
209
|
1831 |
# ifdef FAST_STRCPY
|
|
1832 |
strncpy(dstp, _stringVal(self) + index1 - 1, count);
|
|
1833 |
dstp[count] = '\0';
|
|
1834 |
# else
|
159
|
1835 |
srcp = _stringVal(self) + index1 - 1;
|
|
1836 |
while (count--) {
|
|
1837 |
*dstp++ = *srcp++;
|
|
1838 |
}
|
|
1839 |
*dstp = '\0';
|
209
|
1840 |
# endif
|
13
|
1841 |
#endif
|
159
|
1842 |
RETURN ( newString );
|
|
1843 |
}
|
|
1844 |
}
|
|
1845 |
}
|
1
|
1846 |
}
|
51
|
1847 |
%}.
|
|
1848 |
"fall back in case of non-integer index or out-of-bound index;
|
|
1849 |
will eventually lead to an out-of-bound signal raise"
|
|
1850 |
|
1
|
1851 |
^ super copyFrom:start
|
|
1852 |
! !
|
|
1853 |
|
|
1854 |
!String methodsFor:'filling and replacing'!
|
|
1855 |
|
|
1856 |
replaceFrom:start to:stop with:aString startingAt:repStart
|
|
1857 |
"replace the characters starting at index start, anInteger and ending
|
|
1858 |
at stop, anInteger with characters from aString starting at repStart.
|
|
1859 |
|
|
1860 |
- reimplemented here for speed"
|
|
1861 |
|
|
1862 |
%{ /* NOCONTEXT */
|
|
1863 |
|
|
1864 |
REGISTER unsigned char *srcp, *dstp;
|
|
1865 |
REGISTER int count;
|
|
1866 |
int len, index1, index2;
|
|
1867 |
int repLen, repIndex;
|
|
1868 |
|
53
|
1869 |
if ((__isString(aString) || __isSymbol(aString))
|
|
1870 |
&& __isString(self)
|
252
|
1871 |
&& __bothSmallInteger(start, stop)) {
|
159
|
1872 |
len = _stringSize(self);
|
|
1873 |
index1 = _intVal(start);
|
|
1874 |
index2 = _intVal(stop);
|
|
1875 |
count = index2 - index1 + 1;
|
|
1876 |
if (count <= 0) {
|
|
1877 |
RETURN (self);
|
|
1878 |
}
|
|
1879 |
if ((index2 <= len) && (index1 > 0)) {
|
|
1880 |
repLen = _stringSize(aString);
|
|
1881 |
repIndex = _intVal(repStart);
|
|
1882 |
if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
|
|
1883 |
srcp = _stringVal(aString) + repIndex - 1;
|
|
1884 |
dstp = _stringVal(self) + index1 - 1;
|
|
1885 |
if (aString == self) {
|
|
1886 |
/* take care of overlapping copy */
|
|
1887 |
if (srcp < dstp) {
|
|
1888 |
/* must do a reverse copy */
|
|
1889 |
srcp += count;
|
|
1890 |
dstp += count;
|
|
1891 |
while (count-- > 0) {
|
|
1892 |
*--dstp = *--srcp;
|
|
1893 |
}
|
|
1894 |
RETURN (self);
|
|
1895 |
}
|
|
1896 |
}
|
1
|
1897 |
#ifdef FAST_MEMCPY
|
159
|
1898 |
bcopy(srcp, dstp, count);
|
1
|
1899 |
#else
|
159
|
1900 |
while (count-- > 0) {
|
|
1901 |
*dstp++ = *srcp++;
|
|
1902 |
}
|
1
|
1903 |
#endif
|
159
|
1904 |
RETURN (self);
|
|
1905 |
}
|
|
1906 |
}
|
1
|
1907 |
}
|
|
1908 |
%}
|
|
1909 |
.
|
|
1910 |
^ super replaceFrom:start to:stop with:aString startingAt:repStart
|
|
1911 |
!
|
|
1912 |
|
|
1913 |
replaceAll:oldCharacter by:newCharacter
|
|
1914 |
"replace all oldCharacters by newCharacter in the receiver"
|
|
1915 |
|
|
1916 |
%{ /* NOCONTEXT */
|
|
1917 |
|
|
1918 |
REGISTER unsigned char *srcp;
|
|
1919 |
REGISTER unsigned oldVal, newVal;
|
|
1920 |
|
53
|
1921 |
if (__isCharacter(oldCharacter)
|
|
1922 |
&& __isCharacter(newCharacter)
|
|
1923 |
&& __isString(self)) {
|
159
|
1924 |
srcp = (unsigned char *)_stringVal(self);
|
|
1925 |
oldVal = _intVal(_characterVal(oldCharacter));
|
|
1926 |
newVal = _intVal(_characterVal(newCharacter));
|
|
1927 |
while (*srcp) {
|
|
1928 |
if (*srcp == oldVal)
|
|
1929 |
*srcp = newVal;
|
|
1930 |
srcp++;
|
|
1931 |
}
|
|
1932 |
RETURN ( self );
|
1
|
1933 |
}
|
|
1934 |
%}
|
|
1935 |
.
|
|
1936 |
^ super replaceAll:oldCharacter by:newCharacter
|
202
|
1937 |
|
|
1938 |
"
|
|
1939 |
'helloWorld' copy replaceAll:$o by:$O
|
|
1940 |
"
|
1
|
1941 |
!
|
|
1942 |
|
|
1943 |
reverse
|
53
|
1944 |
"in-place reverse the characters of the string."
|
|
1945 |
|
|
1946 |
"Q: is there a need to redefine it here ?"
|
1
|
1947 |
|
|
1948 |
%{ /* NOCONTEXT */
|
|
1949 |
|
|
1950 |
REGISTER char c;
|
|
1951 |
REGISTER unsigned char *hip, *lowp;
|
|
1952 |
|
53
|
1953 |
if (__isString(self)) {
|
159
|
1954 |
lowp = _stringVal(self);
|
|
1955 |
hip = lowp + _stringSize(self) - 1;
|
|
1956 |
while (lowp < hip) {
|
|
1957 |
c = *lowp;
|
|
1958 |
*lowp = *hip;
|
|
1959 |
*hip = c;
|
|
1960 |
lowp++;
|
|
1961 |
hip--;
|
|
1962 |
}
|
|
1963 |
RETURN ( self );
|
1
|
1964 |
}
|
|
1965 |
%}
|
|
1966 |
.
|
|
1967 |
^ super reverse
|
|
1968 |
!
|
|
1969 |
|
|
1970 |
atAllPut:aCharacter
|
209
|
1971 |
"replace all elements with aCharacter
|
1
|
1972 |
- reimplemented here for speed"
|
|
1973 |
|
|
1974 |
%{ /* NOCONTEXT */
|
|
1975 |
|
|
1976 |
#ifndef FAST_MEMSET
|
|
1977 |
REGISTER unsigned char *dst;
|
95
|
1978 |
REGISTER int l;
|
1
|
1979 |
#endif
|
368
|
1980 |
REGISTER int byteValue;
|
1
|
1981 |
|
53
|
1982 |
if (__isCharacter(aCharacter) && __isString(self)) {
|
159
|
1983 |
byteValue = _intVal(_characterVal(aCharacter));
|
1
|
1984 |
#ifdef FAST_MEMSET
|
329
|
1985 |
memset(_stringVal(self), byteValue, __qSize(self) - OHDR_SIZE - 1);
|
1
|
1986 |
#else
|
159
|
1987 |
dst = _stringVal(self);
|
329
|
1988 |
l = __qSize(self) - OHDR_SIZE - 1;
|
95
|
1989 |
while (l >= 8) {
|
159
|
1990 |
dst[0] = dst[1] = dst[2] = dst[3] = byteValue;
|
|
1991 |
dst[4] = dst[5] = dst[6] = dst[7] = byteValue;
|
95
|
1992 |
dst += 8;
|
|
1993 |
l -= 8;
|
|
1994 |
}
|
159
|
1995 |
while (l--)
|
|
1996 |
*dst++ = byteValue;
|
1
|
1997 |
#endif
|
159
|
1998 |
RETURN ( self );
|
1
|
1999 |
}
|
|
2000 |
%}
|
|
2001 |
.
|
|
2002 |
^ super atAllPut:aCharacter
|
95
|
2003 |
|
|
2004 |
"
|
|
2005 |
(String new:10) atAllPut:$*
|
|
2006 |
String new:10 withAll:$*
|
|
2007 |
"
|
1
|
2008 |
!
|
|
2009 |
|
|
2010 |
withoutSpaces
|
95
|
2011 |
"return a copy of myself without leading and trailing spaces.
|
|
2012 |
Notice, this is different from String>>withoutSeparators."
|
1
|
2013 |
|
42
|
2014 |
|startIndex "{ Class: SmallInteger }"
|
|
2015 |
endIndex "{ Class: SmallInteger }"
|
51
|
2016 |
sz blank|
|
|
2017 |
|
53
|
2018 |
startIndex := 0.
|
51
|
2019 |
%{
|
|
2020 |
REGISTER unsigned char *cp0;
|
|
2021 |
REGISTER unsigned char *cp;
|
1
|
2022 |
|
51
|
2023 |
/* ignore instances of subclasses ... */
|
329
|
2024 |
if (__qClass(self) == String) {
|
159
|
2025 |
cp = cp0 = _stringVal(self);
|
|
2026 |
while (*cp == ' ') cp++;
|
|
2027 |
startIndex = _MKSMALLINT(cp - cp0 + 1);
|
|
2028 |
cp = cp + strlen(cp) - 1;
|
|
2029 |
while ((cp >= cp0) && (*cp == ' ')) cp--;
|
|
2030 |
endIndex = _MKSMALLINT(cp - cp0 + 1);
|
51
|
2031 |
}
|
202
|
2032 |
%}.
|
|
2033 |
startIndex == 0 ifTrue:[^ super withoutSpaces].
|
|
2034 |
|
|
2035 |
startIndex > endIndex ifTrue:[^ ''].
|
|
2036 |
((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self].
|
1
|
2037 |
^ self copyFrom:startIndex to:endIndex
|
|
2038 |
!
|
|
2039 |
|
|
2040 |
withoutSeparators
|
95
|
2041 |
"return a copy of myself without leading and trailing whitespace.
|
|
2042 |
Notice, this is different from String>>withoutSpaces."
|
1
|
2043 |
|
42
|
2044 |
|startIndex "{ Class: SmallInteger }"
|
51
|
2045 |
endIndex "{ Class: SmallInteger }"
|
|
2046 |
sz|
|
|
2047 |
|
53
|
2048 |
startIndex := 0.
|
51
|
2049 |
%{
|
|
2050 |
REGISTER unsigned char *cp0;
|
|
2051 |
REGISTER unsigned char *cp;
|
|
2052 |
REGISTER unsigned char c;
|
1
|
2053 |
|
51
|
2054 |
/* ignore instances of subclasses ... */
|
329
|
2055 |
if (__qClass(self) == String) {
|
159
|
2056 |
cp = cp0 = _stringVal(self);
|
379
|
2057 |
while ((c = *cp)
|
329
|
2058 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */
|
379
|
2059 |
&& (c <= ' ')
|
329
|
2060 |
#endif
|
379
|
2061 |
&& ((c == ' ') || (c == '\n') || (c == '\t')
|
329
|
2062 |
|| (c == '\r') || (c == '\f'))
|
|
2063 |
) {
|
159
|
2064 |
cp++;
|
|
2065 |
}
|
|
2066 |
startIndex = _MKSMALLINT(cp - cp0 + 1);
|
|
2067 |
cp = cp + strlen(cp) - 1;
|
|
2068 |
while ((cp >= cp0) && (*cp == ' ')) cp--;
|
|
2069 |
c = *cp;
|
|
2070 |
while ((cp >= cp0) &&
|
329
|
2071 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */
|
|
2072 |
(c <= ' ') &&
|
|
2073 |
#endif
|
159
|
2074 |
((c == ' ') || (c == '\n') || (c == '\t')
|
|
2075 |
|| (c == '\r') || (c == '\f'))) {
|
|
2076 |
cp--;
|
|
2077 |
c = *cp;
|
|
2078 |
}
|
|
2079 |
endIndex = _MKSMALLINT(cp - cp0 + 1);
|
51
|
2080 |
}
|
202
|
2081 |
%}.
|
|
2082 |
startIndex == 0 ifTrue:[^ super withoutSeparators].
|
|
2083 |
|
|
2084 |
startIndex > endIndex ifTrue:[^ ''].
|
|
2085 |
((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self].
|
1
|
2086 |
^ self copyFrom:startIndex to:endIndex
|
|
2087 |
! !
|
|
2088 |
|
|
2089 |
!String methodsFor:'queries'!
|
|
2090 |
|
|
2091 |
encoding
|
|
2092 |
"assume iso8859 encoding"
|
|
2093 |
|
|
2094 |
^ #iso8859
|
|
2095 |
!
|
|
2096 |
|
|
2097 |
knownAsSymbol
|
|
2098 |
"return true, if there is a symbol with same characters in the
|
|
2099 |
system - use to check for existance of a symbol without creating one"
|
|
2100 |
|
|
2101 |
%{ /* NOCONTEXT */
|
329
|
2102 |
extern OBJ __KNOWNASSYMBOL();
|
1
|
2103 |
|
329
|
2104 |
RETURN ( __KNOWNASSYMBOL(_stringVal(self)) );
|
1
|
2105 |
%}
|
68
|
2106 |
!
|
|
2107 |
|
|
2108 |
isEmpty
|
|
2109 |
"return true if the receiver is empty (i.e. if size == 0)
|
|
2110 |
Redefined here for performance"
|
|
2111 |
|
|
2112 |
%{ /* NOCONTEXT */
|
|
2113 |
OBJ cls;
|
|
2114 |
|
329
|
2115 |
cls = __qClass(self);
|
68
|
2116 |
if ((cls == String) || (cls == Symbol)) {
|
159
|
2117 |
RETURN ( (_stringSize(self) == 0) ? true : false);
|
68
|
2118 |
}
|
|
2119 |
%}
|
|
2120 |
.
|
|
2121 |
^ super isEmpty
|
1
|
2122 |
! !
|