author | Claus Gittinger <cg@exept.de> |
Tue, 29 Aug 2000 17:12:09 +0200 | |
changeset 5565 | a815d6b86ace |
parent 5557 | f5f8d236027c |
child 5648 | 5bc58204662e |
permissions | -rw-r--r-- |
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 |
||
5407 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
3989 | 15 |
CharacterArray variableByteSubclass:#String |
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
16 |
instanceVariableNames:'' |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
17 |
classVariableNames:'' |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
18 |
poolDictionaries:'' |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
19 |
category:'Collections-Text' |
88 | 20 |
! |
21 |
||
216 | 22 |
!String primitiveDefinitions! |
88 | 23 |
%{ |
2894 | 24 |
|
3809
dd1df62365ee
use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
25 |
#include <stdio.h> |
dd1df62365ee
use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
26 |
#define _STDIO_H_INCLUDED_ |
437 | 27 |
|
88 | 28 |
#include <ctype.h> |
359 | 29 |
|
273 | 30 |
#ifdef LINUX |
359 | 31 |
# define __STRINGDEFS__ |
32 |
# include <linuxIntern.h> |
|
302 | 33 |
#else |
34 |
extern char *strchr(); |
|
273 | 35 |
#endif |
95 | 36 |
|
37 |
/* |
|
38 |
* old st/x creates strings with spaces in it; |
|
39 |
* new st/x will fill it with zeros (for st-80 compatibility) |
|
40 |
* the define below sets old behavior. |
|
41 |
*/ |
|
42 |
#define INITIALIZE_WITH_SPACE |
|
88 | 43 |
%} |
216 | 44 |
! ! |
88 | 45 |
|
608 | 46 |
!String class methodsFor:'documentation'! |
47 |
||
48 |
copyright |
|
49 |
" |
|
50 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
51 |
All Rights Reserved |
|
52 |
||
53 |
This software is furnished under a license and may be used |
|
54 |
only in accordance with the terms of that license and with the |
|
55 |
inclusion of the above copyright notice. This software may not |
|
56 |
be provided or otherwise made available to, or used by, any |
|
57 |
other person. No title to or ownership of the software is |
|
58 |
hereby transferred. |
|
59 |
" |
|
60 |
! |
|
3 | 61 |
|
608 | 62 |
documentation |
63 |
" |
|
64 |
Strings are ByteArrays storing Characters. |
|
65 |
||
66 |
Strings are kind of kludgy: to allow for easy handling by c-functions, |
|
67 |
there is always one 0-byte added at the end, which is not counted |
|
4800
118dff933bf3
docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
68 |
in the strings size, and is not accessable from the smalltalk level. |
118dff933bf3
docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
69 |
This guarantees, that a smalltalk string can always be passed to a |
118dff933bf3
docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
70 |
C- or a system api function without danger (of course, this does not |
118dff933bf3
docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
71 |
prevent a nonsense contents ...) |
3 | 72 |
|
608 | 73 |
You cannot add any instvars to String, since the the run time system & compiler |
74 |
creates literal strings and knows that strings have no named instvars. |
|
3809
dd1df62365ee
use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
75 |
If you really need strings with instVars, you have to create a subclass |
608 | 76 |
of String (the access functions defined here can handle this). |
77 |
A little warning though: not all smalltalk systems allow subclassing String, |
|
78 |
so your program may become unportable if you do so. |
|
1290 | 79 |
|
80 |
[author:] |
|
4800
118dff933bf3
docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
81 |
Claus Gittinger |
1310 | 82 |
|
83 |
[see also:] |
|
4800
118dff933bf3
docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
84 |
Text StringCollection TwoByteString JISEncodedString |
118dff933bf3
docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
85 |
Symbol |
608 | 86 |
" |
3 | 87 |
! ! |
88 |
||
1 | 89 |
!String class methodsFor:'instance creation'! |
90 |
||
91 |
basicNew:anInteger |
|
4802 | 92 |
"return a new empty string with anInteger characters. |
93 |
In contrast to other smalltalks, this returns a string filled |
|
94 |
with spaces (instead of a string filled with 0-bytes). |
|
95 |
This makes much more sense, in that a freshly created string |
|
96 |
can be directly used as separator or for formatting." |
|
1 | 97 |
|
98 |
%{ /* NOCONTEXT */ |
|
99 |
||
100 |
OBJ newString; |
|
101 |
REGISTER int len; |
|
102 |
REGISTER unsigned char *cp; |
|
103 |
REGISTER OBJ *op; |
|
104 |
int nInstVars, instsize; |
|
105 |
||
252 | 106 |
if (__isSmallInteger(anInteger)) { |
4802 | 107 |
len = __intVal(anInteger); |
108 |
if (len >= 0) { |
|
109 |
instsize = OHDR_SIZE + len + 1; |
|
110 |
if (self == String) { |
|
111 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
|
112 |
/* |
|
113 |
* the most common case |
|
114 |
*/ |
|
115 |
__qCheckedNew(newString, instsize); |
|
116 |
__InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */ |
|
117 |
__qSTORE(newString, self); |
|
118 |
||
119 |
cp = __stringVal(newString); |
|
2862 | 120 |
|
357 | 121 |
#if defined(memset4) && !defined(NON_ASCII) |
4802 | 122 |
{ |
123 |
/* |
|
124 |
* no sizeof(int) here please - |
|
125 |
* - memset4 (if defined) fills 4-bytes on ALL machines |
|
126 |
*/ |
|
127 |
int l4 = len >> 2; |
|
128 |
||
129 |
if (len & 3) l4++; |
|
130 |
memset4(cp, 0x20202020, l4); |
|
131 |
cp[len] = '\0'; |
|
132 |
} |
|
95 | 133 |
#else |
357 | 134 |
# ifdef FAST_MEMSET |
4802 | 135 |
memset(cp, ' ', len); |
136 |
cp[len] = '\0'; |
|
357 | 137 |
# else |
4802 | 138 |
while (len >= 8) { |
3449
84160615c630
oops - basicNew was bad for subclasses of String.
Claus Gittinger <cg@exept.de>
parents:
3403
diff
changeset
|
139 |
# ifndef NON_ASCII /* i.e. EBCDIC */ |
2954 | 140 |
# ifdef INT64 |
4802 | 141 |
((INT64 *)cp)[0] = 0x2020202020202020L; |
2862 | 142 |
# else |
4802 | 143 |
((int *)cp)[0] = 0x20202020; |
144 |
((int *)cp)[1] = 0x20202020; |
|
2862 | 145 |
# endif |
357 | 146 |
# else |
4802 | 147 |
cp[0] = cp[1] = cp[2] = cp[3] = ' '; |
148 |
cp[4] = cp[5] = cp[6] = cp[7] = ' '; |
|
357 | 149 |
# endif |
4802 | 150 |
cp += 8; |
151 |
len -= 8; |
|
152 |
} |
|
153 |
while (len--) |
|
154 |
*cp++ = ' '; |
|
155 |
*cp = '\0'; |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
156 |
# endif /* not FAST_MEMSET */ |
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
157 |
#endif /* not memset4 */ |
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
158 |
|
4802 | 159 |
RETURN (newString); |
160 |
} |
|
161 |
nInstVars = 0; |
|
162 |
} else { |
|
163 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
|
164 |
instsize += __OBJS2BYTES__(nInstVars); |
|
165 |
} |
|
166 |
||
167 |
__PROTECT_CONTEXT__; |
|
168 |
__qNew(newString, instsize); /* OBJECT ALLOCATION */ |
|
169 |
__UNPROTECT_CONTEXT__; |
|
170 |
||
171 |
if (newString == nil) goto fail; |
|
172 |
||
173 |
__InstPtr(newString)->o_class = self; |
|
174 |
__qSTORE(newString, self); |
|
175 |
||
176 |
if (nInstVars) { |
|
177 |
/* |
|
178 |
* nil-out instvars |
|
179 |
*/ |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
180 |
#if defined(memset4) |
4802 | 181 |
memset4(__InstPtr(newString)->i_instvars, nil, nInstVars); |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
182 |
#else |
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
183 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
4802 | 184 |
/* |
185 |
* knowing that nil is 0 |
|
186 |
*/ |
|
187 |
memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars)); |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
188 |
# else |
4802 | 189 |
op = __InstPtr(newString)->i_instvars; |
190 |
do { |
|
191 |
*op++ = nil; |
|
192 |
} while (--nInstVars); |
|
357 | 193 |
# endif |
95 | 194 |
#endif |
4802 | 195 |
cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars); |
196 |
} else { |
|
197 |
cp = __stringVal(newString); |
|
198 |
} |
|
199 |
||
200 |
/* |
|
201 |
* fill with spaces |
|
202 |
*/ |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
203 |
#ifdef FAST_MEMSET |
4802 | 204 |
memset(cp, ' ', len); |
205 |
*(cp + len) = '\0'; |
|
1 | 206 |
#else |
4802 | 207 |
while (len >= 8) { |
357 | 208 |
# ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
2954 | 209 |
# ifdef INT64 |
4802 | 210 |
((INT64 *)cp)[0] = 0x2020202020202020L; |
2862 | 211 |
# else |
4802 | 212 |
((int *)cp)[0] = 0x20202020; |
213 |
((int *)cp)[1] = 0x20202020; |
|
2862 | 214 |
# endif |
357 | 215 |
# else |
4802 | 216 |
cp[0] = cp[1] = cp[2] = cp[3] = ' '; |
217 |
cp[4] = cp[5] = cp[6] = cp[7] = ' '; |
|
357 | 218 |
# endif |
4802 | 219 |
cp += 8; |
220 |
len -= 8; |
|
221 |
} |
|
222 |
while (len--) |
|
223 |
*cp++ = ' '; |
|
224 |
*cp = '\0'; |
|
1 | 225 |
#endif |
4802 | 226 |
RETURN (newString); |
227 |
} |
|
1 | 228 |
} |
95 | 229 |
fail: ;; |
1019 | 230 |
%}. |
95 | 231 |
" |
232 |
invalid argument, or out-of-memory: |
|
233 |
use error handling in superclass |
|
234 |
" |
|
5407 | 235 |
^ (super basicNew:anInteger+1) atAllPut:(Character space) |
1 | 236 |
! |
237 |
||
608 | 238 |
new:n |
4802 | 239 |
"return a new empty string with anInteger characters. |
240 |
In contrast to other smalltalks, this returns a string filled |
|
241 |
with spaces (instead of a string filled with 0-bytes). |
|
242 |
This makes much more sense, in that a freshly created string |
|
243 |
can be directly used as separator or for formatting." |
|
244 |
||
608 | 245 |
^ self basicNew:n |
347 | 246 |
! |
247 |
||
248 |
readFrom:aStream onError:exceptionBlock |
|
249 |
"read & return the next String from the (character-)stream aStream; |
|
250 |
skipping all whitespace first; return the value of exceptionBlock, |
|
251 |
if no string can be read. The sequence of characters as read from the |
|
252 |
stream must be one as stored via storeOn: or storeString." |
|
253 |
||
254 |
|collected char| |
|
255 |
||
256 |
" |
|
257 |
this method is not to be inherited |
|
258 |
(i.e. not ok for subclasses; Symbol, for example) |
|
259 |
" |
|
260 |
self ~~ String ifTrue:[ |
|
3451 | 261 |
^ super readFrom:aStream onError:exceptionBlock |
347 | 262 |
]. |
263 |
||
264 |
"skip whiteSpace" |
|
265 |
aStream skipSeparators. |
|
266 |
(aStream next == $') ifTrue:[ |
|
3451 | 267 |
collected := WriteStream on:(String new). |
268 |
[true] whileTrue:[ |
|
269 |
aStream atEnd ifTrue:[ |
|
270 |
"/ mhmh - reached the end without a closing quote |
|
271 |
"/ looks like an error to me ... |
|
272 |
^ exceptionBlock value |
|
273 |
]. |
|
274 |
char := aStream next. |
|
275 |
char == $' ifTrue:[ |
|
276 |
"/ look for another quote |
|
277 |
aStream peekOrNil == $' ifFalse:[ |
|
278 |
^ collected contents |
|
279 |
]. |
|
280 |
aStream next. |
|
281 |
]. |
|
282 |
collected nextPut:char |
|
283 |
] |
|
347 | 284 |
]. |
285 |
^ exceptionBlock value |
|
286 |
||
287 |
" |
|
288 |
String readFrom:('''hello world''' readStream) |
|
289 |
String readFrom:('''hello '''' world''' readStream) |
|
290 |
String readFrom:('1 ''hello'' ' readStream) |
|
291 |
String readFrom:('1 ''hello'' ' readStream) onError:['foobar'] |
|
3376 | 292 |
" |
293 |
||
294 |
"Modified: / 14.4.1998 / 18:46:26 / cg" |
|
608 | 295 |
! |
296 |
||
297 |
unititializedNew:anInteger |
|
298 |
"redefine it back - strings must have a 0-byte at the end" |
|
299 |
||
300 |
^ self basicNew:anInteger |
|
301 |
! ! |
|
302 |
||
4981 | 303 |
!String class methodsFor:'Compatibility - Squeak'! |
304 |
||
305 |
cr |
|
4994 | 306 |
"return a string consisting of the cr-Character" |
4993 | 307 |
|
4981 | 308 |
^ Character cr asString |
4993 | 309 |
|
4994 | 310 |
"Modified: / 13.11.1999 / 13:53:36 / cg" |
4981 | 311 |
! ! |
312 |
||
608 | 313 |
!String class methodsFor:'binary storage'! |
314 |
||
315 |
binaryDefinitionFrom:stream manager:manager |
|
3085 | 316 |
"read a binary representation from stream. This is only invoked |
317 |
for long strings. Short strings are stored with 1byte length." |
|
318 |
||
319 |
|s len| |
|
608 | 320 |
|
3085 | 321 |
"take care of subclasses ..." |
322 |
((self == String) or:[self == Symbol]) ifTrue:[ |
|
3111 | 323 |
len := stream nextNumber:4. |
324 |
s := String basicNew:len. |
|
325 |
stream nextBytes:len into:s startingAt:1. |
|
326 |
^ s |
|
3085 | 327 |
]. |
328 |
^ super binaryDefinitionFrom:stream manager:manager |
|
329 |
||
330 |
"Modified: / 2.11.1997 / 16:18:37 / cg" |
|
608 | 331 |
! ! |
332 |
||
333 |
!String class methodsFor:'queries'! |
|
334 |
||
2680
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
335 |
defaultPlatformClass |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
336 |
"dummy for ST-80 compatibility" |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
337 |
|
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
338 |
^ self |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
339 |
|
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
340 |
"Created: 6.6.1997 / 18:25:56 / cg" |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
341 |
! |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
342 |
|
608 | 343 |
isBuiltInClass |
1264 | 344 |
"return true if this class is known by the run-time-system. |
345 |
Here, true is returned for myself, false for subclasses." |
|
608 | 346 |
|
347 |
^ self == String |
|
1264 | 348 |
|
349 |
"Modified: 23.4.1996 / 16:00:38 / cg" |
|
1 | 350 |
! ! |
351 |
||
5312 | 352 |
!String methodsFor:'Compatibility - CampSmalltalk'! |
353 |
||
354 |
asQualifiedReference |
|
355 |
^ QualifiedName for:self |
|
356 |
! ! |
|
357 |
||
4993 | 358 |
!String methodsFor:'ID extensions'! |
359 |
||
360 |
ideCharAt: anInteger |
|
361 |
"Return the character stored at anInteger. Will convert to |
|
362 |
charAt() in Java." |
|
363 |
||
364 |
^self at: anInteger! |
|
365 |
||
366 |
ideLength |
|
367 |
"Return the receiver's length. Will convert to |
|
368 |
length() in Java." |
|
369 |
||
370 |
^self size! |
|
371 |
||
372 |
idePrintPrimitive |
|
373 |
"Return a string representation of the receiver. This |
|
374 |
calls #asString in Smalltalk (to strip out the single quote |
|
375 |
characters) and nothing in Java (see implementation |
|
376 |
in Object)." |
|
377 |
||
378 |
^self asString! |
|
379 |
||
380 |
ideStringTest: aString |
|
381 |
"Return true if the receiver equals aString, |
|
382 |
else return false. This translates to equals() in |
|
383 |
Java. Identity testing two symbols is 50% faster |
|
384 |
on IBM Smalltalk than this method, however |
|
385 |
sending asSymbol once is 850 times slower than |
|
386 |
sending = once. |
|
387 |
||
388 |
Use == if you know both are Symbols, or this method |
|
389 |
if you know both are Strings. This method is usually |
|
390 |
faster overall and provides better unicode string |
|
391 |
matching support in Java." |
|
392 |
||
393 |
^self = aString asString! ! |
|
394 |
||
1 | 395 |
!String methodsFor:'accessing'! |
396 |
||
329 | 397 |
at:index |
398 |
"return the character at position index, an Integer. |
|
345 | 399 |
Reimplemented here to avoid the additional at:->basicAt: send |
400 |
(which we can do here, since at: is obviously not redefined in a subclass). |
|
329 | 401 |
This method is the same as at:." |
402 |
||
403 |
%{ /* NOCONTEXT */ |
|
404 |
||
405 |
REGISTER int indx; |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
406 |
REGISTER OBJ slf, cls; |
329 | 407 |
|
408 |
if (__isSmallInteger(index)) { |
|
5407 | 409 |
slf = self; |
410 |
cls = __qClass(slf); |
|
411 |
indx = __intVal(index) - 1; |
|
412 |
if (cls != String) { |
|
413 |
if (indx < 0) goto badIndex; |
|
414 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
415 |
} |
|
416 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
417 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
|
418 |
} |
|
329 | 419 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
420 |
badIndex: ; |
329 | 421 |
%}. |
5407 | 422 |
^ self basicAt:index |
1 | 423 |
! |
424 |
||
329 | 425 |
at:index put:aCharacter |
426 |
"store the argument, aCharacter at position index, an Integer. |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
427 |
Return aCharacter (sigh). |
345 | 428 |
Reimplemented here to avoid the additional at:put:->basicAt:put: send |
429 |
(but only for Strings, since subclasses may redefine basicAt:put:). |
|
329 | 430 |
This method is the same as basicAt:put:." |
431 |
||
432 |
%{ /* NOCONTEXT */ |
|
433 |
||
434 |
REGISTER int value, indx; |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
435 |
REGISTER OBJ slf; |
329 | 436 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
437 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
438 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
439 |
if (__isString(slf)) { |
5407 | 440 |
if (__isCharacter(aCharacter)) { |
441 |
value = __intVal(_characterVal(aCharacter)); |
|
442 |
if (((unsigned)value <= 0xFF) |
|
443 |
&& __isSmallInteger(index)) { |
|
444 |
indx = __intVal(index) - 1; |
|
445 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
446 |
__stringVal(slf)[indx] = value; |
|
447 |
RETURN ( aCharacter ); |
|
448 |
} |
|
449 |
} |
|
450 |
} |
|
329 | 451 |
} |
452 |
%}. |
|
5407 | 453 |
^ self basicAt:index put:aCharacter |
329 | 454 |
! |
455 |
||
608 | 456 |
basicAt:index |
457 |
"return the character at position index, an Integer |
|
458 |
- reimplemented here since we return characters" |
|
459 |
||
460 |
%{ /* NOCONTEXT */ |
|
461 |
||
462 |
REGISTER int indx; |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
463 |
REGISTER OBJ slf, cls; |
608 | 464 |
|
465 |
if (__isSmallInteger(index)) { |
|
5407 | 466 |
slf = self; |
467 |
cls = __qClass(slf); |
|
468 |
indx = __intVal(index) - 1; |
|
469 |
if (cls != String) { |
|
470 |
if (indx < 0) goto badIndex; |
|
471 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
472 |
} |
|
473 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
474 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
|
475 |
} |
|
608 | 476 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
477 |
badIndex: ; |
608 | 478 |
%}. |
3451 | 479 |
index isInteger ifFalse:[ |
5407 | 480 |
^ self indexNotInteger:index |
3451 | 481 |
]. |
5407 | 482 |
index == super basicSize ifTrue:[ |
483 |
^ self subscriptBoundsError:index |
|
484 |
]. |
|
485 |
^ Character value:(super basicAt:index) |
|
608 | 486 |
! |
487 |
||
1 | 488 |
basicAt:index put:aCharacter |
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
489 |
"store the argument, aCharacter at position index, an Integer. |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
490 |
Returns aCharacter (sigh). |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
491 |
- reimplemented here since we store characters" |
1 | 492 |
|
493 |
%{ /* NOCONTEXT */ |
|
494 |
||
495 |
REGISTER int value, indx; |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
496 |
REGISTER OBJ slf; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
497 |
REGISTER OBJ cls; |
1 | 498 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
499 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
500 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
501 |
if (__isCharacter(aCharacter)) { |
5407 | 502 |
value = __intVal(_characterVal(aCharacter)); |
503 |
if (((unsigned)value <= 0xFF) |
|
504 |
&& __isSmallInteger(index)) { |
|
505 |
cls = __qClass(slf); |
|
506 |
indx = __intVal(index) - 1; |
|
507 |
if (cls != String) { |
|
508 |
if (indx < 0) goto badIndex; |
|
509 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
510 |
} |
|
511 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
512 |
__stringVal(slf)[indx] = value; |
|
513 |
RETURN ( aCharacter ); |
|
514 |
} |
|
515 |
} |
|
1 | 516 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
517 |
badIndex: ; |
159 | 518 |
%}. |
1 | 519 |
(aCharacter isMemberOf:Character) ifFalse:[ |
5407 | 520 |
" |
521 |
tried to store something which is not a character |
|
522 |
" |
|
523 |
^ self elementNotCharacter |
|
299 | 524 |
]. |
525 |
(aCharacter asciiValue between:1 and:255) ifFalse:[ |
|
5407 | 526 |
" |
527 |
tried to store a multibyte character |
|
528 |
" |
|
529 |
^ self elementBoundsError |
|
299 | 530 |
]. |
531 |
" |
|
532 |
invalid index |
|
533 |
" |
|
3451 | 534 |
index isInteger ifFalse:[ |
5407 | 535 |
^ self indexNotInteger:index |
3451 | 536 |
]. |
5407 | 537 |
index == super basicSize ifTrue:[ |
538 |
^ self subscriptBoundsError:index |
|
539 |
]. |
|
540 |
super basicAt:index put:aCharacter asciiValue. |
|
541 |
^ aCharacter |
|
542 |
||
2 | 543 |
! ! |
544 |
||
3085 | 545 |
!String methodsFor:'binary storage'! |
546 |
||
547 |
storeBinaryDefinitionOn:stream manager:manager |
|
548 |
"append a binary representation of the receiver onto stream. |
|
549 |
Redefined since short Strings can be stored with a special type code |
|
550 |
in a more compact way. |
|
551 |
This is an internal interface for the binary storage mechanism." |
|
552 |
||
553 |
|myClass myBasicSize| |
|
554 |
||
555 |
"/ not for subclasses with named instVars. |
|
556 |
(myClass := self class) instSize ~~ 0 ifTrue:[ |
|
3111 | 557 |
^ super storeBinaryDefinitionOn:stream manager:manager |
3085 | 558 |
]. |
559 |
||
560 |
myBasicSize := self basicSize. |
|
561 |
||
562 |
"/ can use a more compact representation; |
|
563 |
"/ but not for subclasses ... |
|
564 |
||
565 |
((myClass == String) |
|
566 |
and:[myBasicSize <= 255]) ifTrue:[ |
|
3111 | 567 |
"/ special encoding: <codeForString> <len> <bytes> ... |
568 |
stream nextPut:(manager codeForString); nextPut:myBasicSize. |
|
3085 | 569 |
] ifFalse:[ |
3111 | 570 |
manager putIdOfClass:myClass on:stream. |
571 |
stream nextNumber:4 put:myBasicSize. |
|
3085 | 572 |
]. |
573 |
stream nextPutBytes:myBasicSize from:self startingAt:1. |
|
574 |
||
575 |
"Modified: / 2.11.1997 / 15:28:56 / cg" |
|
576 |
! ! |
|
577 |
||
53 | 578 |
!String methodsFor:'character searching'! |
1 | 579 |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
580 |
identityIndexOf:aCharacter |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
581 |
"return the index of the first occurrences of the argument, aCharacter |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
582 |
in the receiver or 0 if not found - reimplemented here for speed." |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
583 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
584 |
%{ /* NOCONTEXT */ |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
585 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
586 |
REGISTER unsigned char *cp; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
587 |
#ifdef FAST_STRCHR |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
588 |
char *strchr(); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
589 |
#else |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
590 |
REGISTER unsigned byteValue; |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
591 |
REGISTER int index; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
592 |
char c; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
593 |
#endif |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
594 |
OBJ cls; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
595 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
596 |
if (__isCharacter(aCharacter)) { |
5407 | 597 |
cp = __stringVal(self); |
598 |
if ((cls = __qClass(self)) != String) |
|
599 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
600 |
#ifdef FAST_STRCHR |
5407 | 601 |
cp = (unsigned char *) strchr(cp, __intVal(_characterVal(aCharacter))); |
602 |
if (cp) { |
|
603 |
RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) ); |
|
604 |
} |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
605 |
#else |
5407 | 606 |
byteValue = __intVal(_characterVal(aCharacter)); |
607 |
index = 1; |
|
608 |
while (c = *cp++) { |
|
609 |
if (c == byteValue) { RETURN ( __MKSMALLINT(index) ); } |
|
610 |
index++; |
|
611 |
} |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
612 |
#endif |
5407 | 613 |
RETURN ( __MKSMALLINT(0)); |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
614 |
} |
5407 | 615 |
/* with identity compares, only characters can be in myself */ |
616 |
RETURN ( __MKSMALLINT(0)); |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
617 |
%}. |
5407 | 618 |
^ self primitiveFailed |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
619 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
620 |
" |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
621 |
'hello world' indexOf:(Character space) |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
622 |
'hello world' indexOf:$A |
5407 | 623 |
'hello world' indexOf:1 |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
624 |
" |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
625 |
! |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
626 |
|
1 | 627 |
includes:aCharacter |
628 |
"return true if the argument, aCharacter is included in the receiver |
|
629 |
- reimplemented here for speed" |
|
630 |
||
631 |
%{ /* NOCONTEXT */ |
|
632 |
||
633 |
REGISTER unsigned char *cp; |
|
634 |
REGISTER int byteValue; |
|
53 | 635 |
OBJ cls; |
1 | 636 |
|
53 | 637 |
if (__isCharacter(aCharacter)) { |
3111 | 638 |
byteValue = __intVal(_characterVal(aCharacter)); |
639 |
cp = __stringVal(self); |
|
640 |
if ((cls = __qClass(self)) != String) |
|
641 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1 | 642 |
#ifdef FAST_STRCHR |
3111 | 643 |
cp = (unsigned char *) strchr(cp, __intVal(_characterVal(aCharacter))); |
644 |
if (cp) { |
|
645 |
RETURN ( true ); |
|
646 |
} |
|
1 | 647 |
#else |
3111 | 648 |
while (*cp) { |
649 |
if (*cp == byteValue) { |
|
650 |
RETURN ( true ); |
|
651 |
} |
|
652 |
cp++; |
|
653 |
} |
|
1 | 654 |
#endif |
3111 | 655 |
RETURN (false); |
1 | 656 |
} |
299 | 657 |
%}. |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
658 |
^ super includes:aCharacter |
53 | 659 |
|
95 | 660 |
" |
661 |
'hello world' includes:$a |
|
662 |
'hello world' includes:$o |
|
663 |
'hello world' includes:$x |
|
664 |
'hello world' includes:1 |
|
299 | 665 |
'hello world' asTwoByteString includes:$o |
95 | 666 |
" |
1 | 667 |
! |
668 |
||
10 | 669 |
includesAny:aCollection |
670 |
"return true, if the receiver includes any of the characters in the |
|
53 | 671 |
argument, aCollection. |
672 |
- redefined for speed if the argument is a String." |
|
10 | 673 |
|
674 |
%{ /* NOCONTEXT */ |
|
675 |
||
676 |
REGISTER unsigned char *cp; |
|
677 |
REGISTER unsigned char *matchP; |
|
53 | 678 |
OBJ cls; |
10 | 679 |
|
53 | 680 |
if (__isString(aCollection)) { |
5407 | 681 |
matchP = __stringVal(aCollection); |
682 |
cp = __stringVal(self); |
|
683 |
if ((cls = __qClass(self)) != String) |
|
684 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
685 |
||
686 |
while (*cp) { |
|
687 |
if (strchr(matchP, *cp)) { |
|
688 |
RETURN ( true ); |
|
689 |
} |
|
690 |
cp++; |
|
691 |
} |
|
692 |
RETURN ( false ); |
|
10 | 693 |
} |
5407 | 694 |
%}. |
10 | 695 |
^ super includesAny:aCollection |
95 | 696 |
|
697 |
" |
|
698 |
'hello world' includesAny:'abcd' |
|
699 |
'hello world' includesAny:'xyz' |
|
700 |
'hello world' includesAny:(Array with:$a with:$b with:$d) |
|
701 |
'hello world' includesAny:(Array with:$x with:$y) |
|
702 |
'hello world' includesAny:(Array with:1 with:2) |
|
703 |
" |
|
10 | 704 |
! |
705 |
||
1 | 706 |
indexOf:aCharacter |
707 |
"return the index of the first occurrences of the argument, aCharacter |
|
708 |
in the receiver or 0 if not found - reimplemented here for speed." |
|
709 |
||
710 |
%{ /* NOCONTEXT */ |
|
711 |
||
712 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
713 |
REGISTER unsigned byteValue; |
2530 | 714 |
REGISTER int index; |
1 | 715 |
#ifdef FAST_STRCHR |
716 |
char *strchr(); |
|
2529
f33167bc7b23
Define vars for #ifdef FAST_STRCHR.
Stefan Vogel <sv@exept.de>
parents:
2528
diff
changeset
|
717 |
#else |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
718 |
unsigned char c; |
1 | 719 |
#endif |
53 | 720 |
OBJ cls; |
1 | 721 |
|
53 | 722 |
if (__isCharacter(aCharacter)) { |
3111 | 723 |
cp = __stringVal(self); |
724 |
if ((cls = __qClass(self)) != String) |
|
725 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
726 |
|
3111 | 727 |
byteValue = __intVal(_characterVal(aCharacter)); |
728 |
if (byteValue == 0) { |
|
729 |
index = strlen(cp); |
|
730 |
if (index >= __stringSize(self)) { |
|
731 |
index = 0; |
|
732 |
} else { |
|
733 |
index++; |
|
734 |
} |
|
735 |
RETURN ( __MKSMALLINT(index) ); |
|
736 |
} |
|
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
737 |
|
1 | 738 |
#ifdef FAST_STRCHR |
3111 | 739 |
cp = (unsigned char *) strchr(cp, byteValue); |
740 |
if (cp) { |
|
741 |
RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) ); |
|
742 |
} |
|
1 | 743 |
#else |
3111 | 744 |
index = 1; |
745 |
while (c = *cp++) { |
|
746 |
if (c == byteValue) { RETURN ( __MKSMALLINT(index) ); } |
|
747 |
index++; |
|
748 |
} |
|
1 | 749 |
#endif |
3111 | 750 |
RETURN ( __MKSMALLINT(0)); |
1 | 751 |
} |
370 | 752 |
%}. |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
753 |
^ super indexOf:aCharacter |
95 | 754 |
|
755 |
" |
|
756 |
'hello world' indexOf:(Character space) |
|
757 |
'hello world' indexOf:$A |
|
758 |
" |
|
1 | 759 |
! |
760 |
||
761 |
indexOf:aCharacter startingAt:start |
|
762 |
"return the index of the first occurrence of the argument, aCharacter |
|
763 |
in myself starting at start, anInteger or 0 if not found; |
|
764 |
- reimplemented here for speed" |
|
765 |
||
766 |
%{ /* NOCONTEXT */ |
|
767 |
||
768 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
769 |
REGISTER int index; |
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
770 |
REGISTER unsigned byteValue; |
1 | 771 |
#ifdef FAST_STRCHR |
772 |
char *strchr(); |
|
370 | 773 |
#else |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
774 |
unsigned char c; |
1 | 775 |
#endif |
776 |
int len; |
|
53 | 777 |
OBJ cls; |
1 | 778 |
|
252 | 779 |
if (__isSmallInteger(start)) { |
3111 | 780 |
if (__isCharacter(aCharacter)) { |
781 |
byteValue = __intVal(_characterVal(aCharacter)); |
|
782 |
index = __intVal(start); |
|
783 |
if (index <= 0) |
|
784 |
index = 1; |
|
785 |
if ((cls = __qClass(self)) != String) |
|
786 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
787 |
len = __stringSize(self); |
|
788 |
if (index <= len) { |
|
789 |
cp = __stringVal(self) + index - 1; |
|
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
790 |
|
3111 | 791 |
if (byteValue == 0) { |
792 |
index += strlen(cp); |
|
793 |
if (index > len) { |
|
794 |
index = 0; |
|
795 |
} |
|
796 |
RETURN ( __MKSMALLINT(index) ); |
|
797 |
} |
|
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
798 |
|
1 | 799 |
#ifdef FAST_STRCHR |
3111 | 800 |
cp = (unsigned char *) strchr(cp, byteValue); |
801 |
if (cp) { |
|
802 |
RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) ); |
|
803 |
} |
|
1 | 804 |
#else |
3111 | 805 |
while (c = *cp++) { |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
806 |
|
3111 | 807 |
if (c == byteValue) { |
808 |
RETURN ( __MKSMALLINT(index) ); |
|
809 |
} |
|
810 |
index++; |
|
811 |
} |
|
1 | 812 |
#endif |
3111 | 813 |
} |
814 |
} |
|
815 |
RETURN ( __MKSMALLINT(0) ); |
|
1 | 816 |
} |
370 | 817 |
%}. |
1 | 818 |
^ super indexOf:aCharacter startingAt:start |
53 | 819 |
|
95 | 820 |
" |
821 |
'hello world' indexOf:$l startingAt:1 |
|
822 |
'hello world' indexOf:$l startingAt:5 |
|
823 |
" |
|
1 | 824 |
! |
825 |
||
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
826 |
indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
827 |
"return the index of the first occurrence of any character in aCollectionOfCharacters, |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
828 |
in myself starting at start, anInteger or 0 if not found; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
829 |
- reimplemented here for speed if aCollectionOfCharacters is a string." |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
830 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
831 |
%{ /* NOCONTEXT */ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
832 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
833 |
REGISTER unsigned char *ccp; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
834 |
REGISTER unsigned char *cp; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
835 |
REGISTER int index; |
2894 | 836 |
unsigned char *matchP; |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
837 |
unsigned char c; |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
838 |
int len; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
839 |
OBJ cls; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
840 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
841 |
if (__isSmallInteger(start) |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
842 |
&& __isString(aCollectionOfCharacters)) { |
3111 | 843 |
matchP = __stringVal(aCollectionOfCharacters); |
844 |
index = __intVal(start); |
|
845 |
if (index <= 0) |
|
846 |
index = 1; |
|
847 |
if ((cls = __qClass(self)) != String) |
|
848 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
849 |
len = __stringSize(self); |
|
850 |
if (index <= len) { |
|
851 |
cp = __stringVal(self) + index - 1; |
|
852 |
while (c = *cp++) { |
|
853 |
for (ccp = matchP; *ccp ; ccp++) { |
|
854 |
if (*ccp == c) { |
|
855 |
RETURN ( __MKSMALLINT(index) ); |
|
856 |
} |
|
857 |
} |
|
858 |
index++; |
|
859 |
} |
|
860 |
} |
|
861 |
RETURN ( __MKSMALLINT(0) ); |
|
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
862 |
} |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
863 |
%}. |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
864 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
865 |
"/ fallback: 1st argument not a string or error |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
866 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
867 |
^ super indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
868 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
869 |
" |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
870 |
'hello world' indexOfAny:'eoa' startingAt:1 |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
871 |
'hello world' indexOfAny:'eoa' startingAt:6 |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
872 |
'hello world' indexOfAny:'AOE' startingAt:1 |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
873 |
" |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
874 |
! |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
875 |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
876 |
indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
877 |
"return the index of the next control character; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
878 |
that is a character with asciiValue < 32. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
879 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
880 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
881 |
%{ /* NOCONTEXT */ |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
882 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
883 |
#ifndef NON_ASCII /* i.e. not EBCDIC ;-) */ |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
884 |
REGISTER unsigned char *cp; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
885 |
REGISTER unsigned char c; |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
886 |
REGISTER unsigned char *cpEnd; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
887 |
int len, index; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
888 |
OBJ cls; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
889 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
890 |
index = __intVal(start); |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
891 |
if (index <= 0) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
892 |
index = 1; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
893 |
} |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
894 |
if ((cls = __qClass(self)) != String) |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
895 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
896 |
len = __stringSize(self); |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
897 |
cpEnd = __stringVal(self) + len; |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
898 |
cp = __stringVal(self) + index - 1; |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
899 |
if (cp < cpEnd) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
900 |
while (cp < cpEnd) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
901 |
if (*cp++ < ' ') { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
902 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
903 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
904 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
905 |
RETURN ( __MKSMALLINT(0) ); |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
906 |
} |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
907 |
#endif |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
908 |
%}. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
909 |
^ super indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
910 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
911 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
912 |
'hello world' indexOfControlCharacterStartingAt:1 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
913 |
'hello world\foo' withCRs indexOfControlCharacterStartingAt:1 |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
914 |
'1\' withCRs indexOfControlCharacterStartingAt:1 |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
915 |
'1\' withCRs indexOfControlCharacterStartingAt:2 |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
916 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
917 |
! |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
918 |
|
3403 | 919 |
indexOfNonSeparatorStartingAt:start |
920 |
"return the index of the next non-whiteSpace character" |
|
921 |
||
922 |
%{ /* NOCONTEXT */ |
|
923 |
||
924 |
REGISTER unsigned char *cp; |
|
925 |
REGISTER unsigned char c; |
|
926 |
int len, index; |
|
927 |
OBJ cls; |
|
928 |
||
929 |
index = __intVal(start); |
|
930 |
if (index <= 0) { |
|
5407 | 931 |
index = 1; |
3403 | 932 |
} |
933 |
if ((cls = __qClass(self)) != String) |
|
5407 | 934 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3403 | 935 |
len = __stringSize(self); |
936 |
if (index > len) { |
|
5407 | 937 |
RETURN ( __MKSMALLINT(0) ); |
3403 | 938 |
} |
939 |
cp = __stringVal(self) + index - 1; |
|
940 |
while (c = *cp++) { |
|
941 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
|
5407 | 942 |
if (c > ' ') |
3403 | 943 |
#endif |
5407 | 944 |
if ((c != ' ') && (c != '\t') && (c != '\n') |
945 |
&& (c != '\r') && (c != '\f')) { |
|
946 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
|
947 |
} |
|
3403 | 948 |
} |
5407 | 949 |
RETURN ( __MKSMALLINT(0) ); |
3403 | 950 |
%}. |
5407 | 951 |
^ super indexOfNonSeparatorStartingAt:start |
3403 | 952 |
|
953 |
" |
|
954 |
'hello world' indexOfNonWhiteSpaceStartingAt:3 |
|
955 |
'hello world' indexOfNonWhiteSpaceStartingAt:7 |
|
956 |
" |
|
957 |
! |
|
958 |
||
1 | 959 |
indexOfSeparatorStartingAt:start |
960 |
"return the index of the next separator character" |
|
961 |
||
962 |
%{ /* NOCONTEXT */ |
|
963 |
||
964 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
965 |
REGISTER unsigned char c; |
1 | 966 |
int len, index; |
53 | 967 |
OBJ cls; |
1 | 968 |
|
1134 | 969 |
index = __intVal(start); |
1 | 970 |
if (index <= 0) { |
5407 | 971 |
index = 1; |
1 | 972 |
} |
329 | 973 |
if ((cls = __qClass(self)) != String) |
5407 | 974 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1134 | 975 |
len = __stringSize(self); |
1 | 976 |
if (index > len) { |
5407 | 977 |
RETURN ( __MKSMALLINT(0) ); |
1 | 978 |
} |
1134 | 979 |
cp = __stringVal(self) + index - 1; |
1 | 980 |
while (c = *cp++) { |
329 | 981 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
5407 | 982 |
if (c <= ' ') |
1 | 983 |
#endif |
5407 | 984 |
if ((c == ' ') || (c == '\t') || (c == '\n') |
985 |
|| (c == '\r') || (c == '\f')) { |
|
986 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
|
987 |
} |
|
1 | 988 |
} |
5407 | 989 |
RETURN ( __MKSMALLINT(0) ); |
990 |
%}. |
|
991 |
^ super indexOfSeparatorStartingAt:start |
|
53 | 992 |
|
95 | 993 |
" |
994 |
'hello world' indexOfSeparatorStartingAt:3 |
|
995 |
'hello world' indexOfSeparatorStartingAt:7 |
|
996 |
" |
|
608 | 997 |
! |
998 |
||
999 |
occurrencesOf:aCharacter |
|
1000 |
"count the occurrences of the argument, aCharacter in myself |
|
1001 |
- reimplemented here for speed" |
|
1002 |
||
1003 |
%{ /* NOCONTEXT */ |
|
1004 |
||
1005 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1006 |
REGISTER unsigned byteValue; |
608 | 1007 |
REGISTER int count; |
1008 |
OBJ cls; |
|
1009 |
||
1010 |
if (__isCharacter(aCharacter)) { |
|
3111 | 1011 |
count = 0; |
1012 |
byteValue = __intVal(_characterVal(aCharacter)); |
|
1013 |
cp = __stringVal(self); |
|
1014 |
if ((cls = __qClass(self)) != String) |
|
1015 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1016 |
while (*cp) { |
|
1017 |
if (*cp++ == byteValue) count++; |
|
1018 |
} |
|
1019 |
RETURN ( __MKSMALLINT(count) ); |
|
608 | 1020 |
} |
1021 |
%}. |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
1022 |
^ super occurrencesOf:aCharacter |
608 | 1023 |
|
1024 |
" |
|
1025 |
'hello world' occurrencesOf:$a |
|
1026 |
'hello world' occurrencesOf:$w |
|
1027 |
'hello world' occurrencesOf:$l |
|
1028 |
'hello world' occurrencesOf:$x |
|
1029 |
'hello world' occurrencesOf:1 |
|
1030 |
" |
|
53 | 1031 |
! ! |
1032 |
||
608 | 1033 |
!String methodsFor:'comparing'! |
2 | 1034 |
|
608 | 1035 |
= aString |
1036 |
"Compare the receiver with the argument and return true if the |
|
1037 |
receiver is equal to the argument. Otherwise return false. |
|
1038 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
|
1039 |
Use sameAs: to compare with case ignored." |
|
1 | 1040 |
|
375 | 1041 |
%{ /* NOCONTEXT */ |
1042 |
||
608 | 1043 |
int l1, l2; |
1044 |
REGISTER OBJ s = aString; |
|
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1045 |
unsigned char *cp1, *cp2; |
608 | 1046 |
OBJ cls; |
3111 | 1047 |
OBJ myCls; |
3335 | 1048 |
INT addrDelta; |
608 | 1049 |
|
1050 |
if (s == self) { |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1051 |
RETURN ( true ); |
608 | 1052 |
} |
1053 |
if (! __isNonNilObject(s)) { |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1054 |
RETURN ( false ); |
608 | 1055 |
} |
1 | 1056 |
|
3111 | 1057 |
cls = __qClass(s); |
1058 |
myCls = __qClass(self); |
|
608 | 1059 |
|
3111 | 1060 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1061 |
cp2 = __stringVal(s); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1062 |
l2 = __stringSize(s); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1063 |
/* |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1064 |
* care for instances of subclasses ... |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1065 |
*/ |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1066 |
if (cls != String) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1067 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1068 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1069 |
cp2 += n; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1070 |
l2 -= n; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1071 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1072 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1073 |
cp1 = __stringVal(self); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1074 |
l1 = __stringSize(self); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1075 |
/* |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1076 |
* care for instances of subclasses ... |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1077 |
*/ |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1078 |
if (myCls != String) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1079 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1080 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1081 |
cp1 += n; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1082 |
l1 -= n; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1083 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1084 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1085 |
if (l1 != l2) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1086 |
RETURN ( false ); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1087 |
} |
3111 | 1088 |
#ifdef FAST_STRNCMP |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1089 |
RETURN ( (strncmp(cp1, cp2, l1) == 0) ? true : false ); |
3111 | 1090 |
#else |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1091 |
addrDelta = cp2 - cp1; |
3989 | 1092 |
# ifdef UNROLL_LOOPS |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1093 |
while (l1 >= (sizeof(unsigned INT)*4)) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1094 |
if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1095 |
RETURN (false); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1096 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1097 |
if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1098 |
RETURN (false); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1099 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1100 |
if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1101 |
RETURN (false); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1102 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1103 |
if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1104 |
RETURN (false); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1105 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1106 |
l1 -= (sizeof(unsigned INT) * 4); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1107 |
cp1 += (sizeof(unsigned INT) * 4); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1108 |
} |
3989 | 1109 |
# endif /* UNROLL_LOOPS */ |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1110 |
while (l1 >= sizeof(unsigned INT)) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1111 |
if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1112 |
RETURN (false); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1113 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1114 |
l1 -= sizeof(unsigned INT); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1115 |
cp1 += sizeof(unsigned INT); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1116 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1117 |
if (l1 >= sizeof(unsigned short)) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1118 |
if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1119 |
RETURN (false); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1120 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1121 |
l1 -= sizeof(unsigned short); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1122 |
cp1 += sizeof(unsigned short); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1123 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1124 |
while (l1) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1125 |
if (*cp1 != *(cp1+addrDelta)) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1126 |
RETURN (false); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1127 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1128 |
l1--; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1129 |
cp1++; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1130 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1131 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1132 |
RETURN (true); |
3111 | 1133 |
#endif |
1 | 1134 |
} |
3111 | 1135 |
%}. |
608 | 1136 |
^ super = aString |
1 | 1137 |
|
95 | 1138 |
" |
608 | 1139 |
'foo' = 'Foo' |
1140 |
'foo' sameAs: 'Foo' |
|
95 | 1141 |
" |
1 | 1142 |
! |
1143 |
||
608 | 1144 |
> aString |
1145 |
"Compare the receiver with the argument and return true if the |
|
1146 |
receiver is greater than the argument. Otherwise return false. |
|
1147 |
No national variants are honored; use after: for this. |
|
1148 |
In contrast to ST-80, case differences are NOT ignored, thus |
|
1149 |
'foo' > 'Foo' will return true. |
|
1150 |
This may change." |
|
1 | 1151 |
|
375 | 1152 |
%{ /* NOCONTEXT */ |
1153 |
||
608 | 1154 |
int len1, len2, cmp; |
1155 |
REGISTER OBJ s = aString; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1156 |
unsigned char *cp1, *cp2; |
608 | 1157 |
OBJ cls; |
3111 | 1158 |
OBJ myCls; |
1 | 1159 |
|
3111 | 1160 |
if (__isNonNilObject(s)) { |
1161 |
cls = __qClass(s); |
|
1162 |
myCls = __qClass(self); |
|
608 | 1163 |
|
3111 | 1164 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
1165 |
cp2 = __stringVal(s); |
|
1166 |
len2 = __stringSize(s); |
|
1167 |
/* |
|
1168 |
* care for instances of subclasses ... |
|
1169 |
*/ |
|
1170 |
if (cls != String) { |
|
1171 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
608 | 1172 |
|
3111 | 1173 |
cp2 += n; |
1174 |
len2 -= n; |
|
1175 |
} |
|
375 | 1176 |
|
3111 | 1177 |
cp1 = __stringVal(self); |
1178 |
len1 = __stringSize(self); |
|
1179 |
/* |
|
1180 |
* care for instances of subclasses ... |
|
1181 |
*/ |
|
1182 |
if (myCls != String) { |
|
1183 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
|
608 | 1184 |
|
3111 | 1185 |
cp1 += n; |
1186 |
len1 -= n; |
|
1187 |
} |
|
608 | 1188 |
|
3111 | 1189 |
if (len1 <= len2) |
1190 |
cmp = strncmp(cp1, cp2, len1); |
|
1191 |
else |
|
1192 |
cmp = strncmp(cp1, cp2, len2); |
|
608 | 1193 |
|
3111 | 1194 |
if (cmp > 0) { |
1195 |
RETURN ( true ); |
|
1196 |
} |
|
1197 |
if ((cmp == 0) && (len1 > len2)) { |
|
1198 |
RETURN ( true ); |
|
1199 |
} |
|
1200 |
RETURN ( false ); |
|
1201 |
} |
|
1 | 1202 |
} |
370 | 1203 |
%}. |
608 | 1204 |
^ super > aString |
1205 |
! |
|
1 | 1206 |
|
608 | 1207 |
after:aString |
1208 |
"Compare the receiver with the argument and return true if the |
|
1209 |
receiver should come after the argument in a sorted list. |
|
1210 |
Otherwise return false. |
|
1211 |
The comparison is language specific, depending on the value of |
|
1368 | 1212 |
LC_COLLATE, which is initialized from the environment. |
1213 |
||
1214 |
STUPID: |
|
1486 | 1215 |
#after has a completely different meaning in SeqColl ..." |
1 | 1216 |
|
1251 | 1217 |
^ (self compareCollatingWith:aString) > 0 |
1218 |
||
1219 |
" |
|
1220 |
'max' > 'mäx' |
|
1221 |
'man' > 'mäx' |
|
1222 |
'max' after:'mäx' |
|
1223 |
'man' after:'mäx' |
|
1224 |
" |
|
1225 |
||
1368 | 1226 |
"Modified: 10.5.1996 / 14:02:45 / cg" |
1251 | 1227 |
! |
1228 |
||
1229 |
compareCollatingWith:aString |
|
1230 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
1231 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
1232 |
The comparison is language specific, depending on the value of |
|
1233 |
LC_COLLATE, which is in the shell environment." |
|
1234 |
||
1 | 1235 |
%{ /* NOCONTEXT */ |
1236 |
||
608 | 1237 |
int cmp; |
1238 |
REGISTER OBJ s = aString; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1239 |
unsigned char *cp1, *cp2; |
53 | 1240 |
OBJ cls; |
3111 | 1241 |
OBJ myCls; |
608 | 1242 |
|
3111 | 1243 |
if (__isNonNilObject(s)) { |
1244 |
cls = __qClass(s); |
|
1245 |
myCls = __qClass(self); |
|
1246 |
||
1247 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
|
1248 |
cp1 = __stringVal(self); |
|
608 | 1249 |
|
3111 | 1250 |
/* |
1251 |
* care for instances of subclasses ... |
|
1252 |
*/ |
|
1253 |
if (myCls != String) { |
|
1254 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
|
1255 |
||
1256 |
cp1 += n; |
|
1257 |
} |
|
1 | 1258 |
|
3111 | 1259 |
cp2 = __stringVal(s); |
1260 |
/* |
|
1261 |
* care for instances of subclasses ... |
|
1262 |
*/ |
|
1263 |
if (cls != String) { |
|
1264 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
608 | 1265 |
|
3111 | 1266 |
cp2 += n; |
1267 |
} |
|
608 | 1268 |
|
1269 |
#ifdef HAS_STRCOLL |
|
3111 | 1270 |
cmp = strcoll(cp1, cp2); |
608 | 1271 |
#else |
3111 | 1272 |
cmp = strcmp(cp1, cp2); |
608 | 1273 |
#endif |
1274 |
||
3111 | 1275 |
if (cmp > 0) { |
1276 |
RETURN ( __MKSMALLINT(1) ); |
|
1277 |
} |
|
1278 |
if (cmp < 0) { |
|
1279 |
RETURN ( __MKSMALLINT(-1) ); |
|
1280 |
} |
|
1281 |
RETURN ( __MKSMALLINT(0) ); |
|
1282 |
} |
|
370 | 1283 |
} |
329 | 1284 |
%}. |
608 | 1285 |
" |
1286 |
currently, this operation is only defined for strings, symbols |
|
1287 |
and subclasses. |
|
1288 |
" |
|
1251 | 1289 |
^ self primitiveFailed |
1 | 1290 |
! |
1291 |
||
608 | 1292 |
~= aString |
1293 |
"Compare the receiver with the argument and return true if the |
|
1294 |
receiver is not equal to the argument. Otherwise return false. |
|
3111 | 1295 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
1296 |
Actually, there is no need to redefine that method here, |
|
1297 |
the default (= not as inherited) works ok. |
|
1298 |
However, this may be heavily used and the redefinition saves an |
|
1299 |
extra message send." |
|
1 | 1300 |
|
608 | 1301 |
%{ /* NOCONTEXT */ |
1302 |
||
1 | 1303 |
int l1, l2; |
608 | 1304 |
REGISTER OBJ s = aString; |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1305 |
unsigned char *cp1, *cp2; |
3111 | 1306 |
OBJ cls, myCls; |
3335 | 1307 |
INT addrDelta; |
1 | 1308 |
|
608 | 1309 |
if (s == self) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1310 |
RETURN ( false ); |
608 | 1311 |
} |
1312 |
if (! __isNonNilObject(s)) { |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1313 |
RETURN ( true ); |
608 | 1314 |
} |
3111 | 1315 |
|
1316 |
cls = __qClass(s); |
|
1317 |
myCls = __qClass(self); |
|
1318 |
||
1319 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1320 |
cp1 = __stringVal(self); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1321 |
l1 = __stringSize(self); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1322 |
/* |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1323 |
* care for instances of subclasses ... |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1324 |
*/ |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1325 |
if (myCls != String) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1326 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1327 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1328 |
cp1 += n; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1329 |
l1 -= n; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1330 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1331 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1332 |
cp2 = __stringVal(s); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1333 |
l2 = __stringSize(s); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1334 |
/* |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1335 |
* care for instances of subclasses ... |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1336 |
*/ |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1337 |
if (cls != String) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1338 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1339 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1340 |
cp2 += n; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1341 |
l2 -= n; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1342 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1343 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1344 |
if (l1 != l2) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1345 |
RETURN ( true ); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1346 |
} |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1347 |
|
3111 | 1348 |
#ifdef FAST_STRNCMP |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1349 |
RETURN ( (strncmp(cp1, cp2, l1) == 0) ? false : true ); |
3111 | 1350 |
#else |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1351 |
addrDelta = cp2 - cp1; |
3989 | 1352 |
# ifdef UNROLL_LOOPS |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1353 |
while (l1 >= (sizeof(unsigned INT)*4)) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1354 |
if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1355 |
RETURN (true); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1356 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1357 |
if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1358 |
RETURN (true); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1359 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1360 |
if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1361 |
RETURN (true); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1362 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1363 |
if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1364 |
RETURN (true); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1365 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1366 |
l1 -= (sizeof(unsigned INT) * 4); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1367 |
cp1 += (sizeof(unsigned INT) * 4); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1368 |
} |
3989 | 1369 |
# endif /* UNROLL_LOOPS */ |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1370 |
while (l1 >= sizeof(unsigned INT)) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1371 |
if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1372 |
RETURN (true); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1373 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1374 |
l1 -= sizeof(unsigned INT); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1375 |
cp1 += sizeof(unsigned INT); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1376 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1377 |
if (l1 >= sizeof(unsigned short)) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1378 |
if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1379 |
RETURN (true); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1380 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1381 |
l1 -= sizeof(unsigned short); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1382 |
cp1 += sizeof(unsigned short); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1383 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1384 |
while (l1) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1385 |
if (*cp1 != *(cp1+addrDelta)) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1386 |
RETURN (true); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1387 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1388 |
l1--; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1389 |
cp1++; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1390 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1391 |
RETURN (false); |
3111 | 1392 |
#endif |
608 | 1393 |
} |
3111 | 1394 |
%}. |
608 | 1395 |
^ super ~= aString |
1396 |
! ! |
|
1397 |
||
1398 |
!String methodsFor:'converting'! |
|
1399 |
||
3281
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1400 |
asBoldText |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1401 |
"return self as a bold text" |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1402 |
|
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1403 |
^Text string: self emphasis: #bold |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1404 |
! |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1405 |
|
2856 | 1406 |
asString |
1407 |
"I am a string" |
|
1408 |
||
1409 |
^ self |
|
1410 |
||
1411 |
"Created: 14.8.1997 / 11:37:03 / stefan" |
|
1412 |
! |
|
1413 |
||
608 | 1414 |
asSymbol |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1415 |
"return a unique symbol with the name taken from my characters." |
608 | 1416 |
%{ |
1417 |
OBJ newSymbol; |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1418 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1419 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1420 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1421 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1422 |
if (cls != String) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1423 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1424 |
} else { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1425 |
indx = 0; |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1426 |
} |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1427 |
newSymbol = __MKSYMBOL(__stringVal(self) + indx, (OBJ *)0); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1428 |
if (newSymbol) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1429 |
RETURN ( newSymbol); |
608 | 1430 |
} |
1431 |
%}. |
|
1432 |
^ ObjectMemory allocationFailureSignal raise. |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1433 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1434 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1435 |
'hello' asSymbol |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1436 |
" |
608 | 1437 |
! |
1438 |
||
1439 |
asSymbolIfInterned |
|
1440 |
"if a symbol with the receivers characters is already known, return it. |
|
1441 |
Otherwise, return nil. This can be used to query for an existing |
|
1442 |
symbol and is the same as |
|
5407 | 1443 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
608 | 1444 |
but slightly faster, since the symbol lookup operation is only |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1445 |
performed once." |
1 | 1446 |
|
608 | 1447 |
%{ /* NOCONTEXT */ |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1448 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1449 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1450 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1451 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1452 |
if (cls != String) { |
5407 | 1453 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1454 |
} else { |
5407 | 1455 |
indx = 0; |
608 | 1456 |
} |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1457 |
RETURN ( __SYMBOL_OR_NIL(__stringVal(self) + indx)); |
5407 | 1458 |
%}. |
1459 |
self primitiveFailed |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1460 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1461 |
'hello' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1462 |
'fooBarBaz' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1463 |
" |
608 | 1464 |
! |
1465 |
||
2416 | 1466 |
decodeAsLiteralArray |
1467 |
"given a literalEncoding in the receiver, |
|
1468 |
create & return the corresponding object. |
|
1469 |
The inverse operation to #literalArrayEncoding." |
|
1470 |
||
1471 |
^ self |
|
1472 |
||
1473 |
"Created: 25.2.1997 / 19:18:19 / cg" |
|
1474 |
! |
|
1475 |
||
608 | 1476 |
literalArrayEncoding |
1246 | 1477 |
"encode myself as an array literal, from which a copy of the receiver |
1478 |
can be reconstructed with #decodeAsLiteralArray." |
|
608 | 1479 |
|
1480 |
^ self |
|
1481 |
||
1482 |
"Modified: 1.9.1995 / 02:25:45 / claus" |
|
1246 | 1483 |
"Modified: 22.4.1996 / 13:00:50 / cg" |
608 | 1484 |
! |
1485 |
||
1486 |
withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1487 |
"return a string with the characters of the receiver where all tabulator characters |
608 | 1488 |
are expanded into spaces (assuming 8-col tabs). |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1489 |
Notice: if the receiver does not contain any tabs, it is returned unchanged; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1490 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1491 |
This does handle multiline strings. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1492 |
Rewritten for speed - because this is very heavily used when reading |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1493 |
big files in the FileBrowser (and therefore speeds up fileReading considerably)." |
1138
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
1494 |
|
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
1495 |
%{ /* STACK:700 */ |
2894 | 1496 |
unsigned char buffer[80*8 + 10]; |
1497 |
unsigned char *srcP, *dstP, *cp0; |
|
608 | 1498 |
int idx, sz; |
1499 |
int any = 0; |
|
1500 |
OBJ newString; |
|
1501 |
char c; |
|
1502 |
||
1503 |
if (__qClass(self) == String) { |
|
1504 |
/* |
|
1505 |
* for small strings (< 80), do it without a prescan ... |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1506 |
* the buffer is large enough to even convert a |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1507 |
* receiver consisting fully of tabs. |
608 | 1508 |
*/ |
1509 |
if (__stringSize(self) < 80) { |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1510 |
idx = 1; |
608 | 1511 |
for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) { |
1512 |
if (c == '\t') { |
|
1513 |
any = 1; |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1514 |
while (idx % 8) { |
608 | 1515 |
idx++; |
1516 |
*dstP++ = ' '; |
|
159 | 1517 |
} |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1518 |
idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1519 |
*dstP++ = ' '; |
608 | 1520 |
} else { |
1521 |
*dstP++ = c; |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1522 |
idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1523 |
if (c == '\n') { |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1524 |
idx = 1; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1525 |
} |
608 | 1526 |
} |
1527 |
} |
|
1528 |
if (! any) RETURN(self); |
|
1529 |
*dstP = '\0'; |
|
1530 |
RETURN (__MKSTRING_L(buffer, (dstP-buffer))); |
|
1531 |
} |
|
1532 |
/* |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1533 |
* for large strings, we compute the new size, allocate a new string |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1534 |
* and expand it. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1535 |
* |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1536 |
* first, scan for size ... |
608 | 1537 |
*/ |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1538 |
idx = 1; |
608 | 1539 |
for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) { |
1540 |
if (c == '\t') { |
|
1541 |
any = 1; |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1542 |
while (idx % 8) { |
608 | 1543 |
idx++; |
1544 |
sz++; |
|
1545 |
} |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1546 |
idx++; sz ++; |
608 | 1547 |
} else { |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1548 |
sz++; idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1549 |
if (c == '\n') { |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1550 |
idx = 1; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1551 |
} |
159 | 1552 |
} |
1553 |
} |
|
608 | 1554 |
if (! any) RETURN(self); |
1 | 1555 |
|
608 | 1556 |
/* |
1557 |
* get the string |
|
1558 |
*/ |
|
1559 |
sz = OHDR_SIZE + sz + 1; |
|
3111 | 1560 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
608 | 1561 |
if (newString != nil) { |
1134 | 1562 |
__InstPtr(newString)->o_class = String; |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1563 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1564 |
/* |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1565 |
* expand |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1566 |
*/ |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1567 |
idx = 1; |
608 | 1568 |
for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) { |
1569 |
if (c == '\t') { |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1570 |
while (idx % 8) { |
608 | 1571 |
idx++; |
1572 |
*dstP++ = ' '; |
|
1573 |
} |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1574 |
idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1575 |
*dstP++ = ' '; |
608 | 1576 |
} else { |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1577 |
*dstP++ = c; idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1578 |
if (c == '\n') { |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1579 |
idx = 1; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1580 |
} |
608 | 1581 |
} |
1582 |
} |
|
1583 |
*dstP++ = '\0'; |
|
1584 |
RETURN (newString); |
|
1585 |
} |
|
1586 |
} |
|
1587 |
%}. |
|
1588 |
^ super withTabsExpanded |
|
1 | 1589 |
! ! |
1590 |
||
1591 |
!String methodsFor:'copying'! |
|
1592 |
||
1593 |
, aString |
|
2 | 1594 |
"return the concatenation of myself and the argument, aString as |
1595 |
a String. |
|
1 | 1596 |
- reimplemented here for speed" |
1597 |
||
1598 |
%{ |
|
95 | 1599 |
int l1, l2, sz; |
1 | 1600 |
REGISTER OBJ s = aString; |
329 | 1601 |
REGISTER OBJ _string = String; |
13 | 1602 |
OBJ myClass, argClass, newString; |
1 | 1603 |
|
329 | 1604 |
if (__isNonNilObject(s)) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1605 |
myClass = __qClass(self); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1606 |
argClass = __qClass(s); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1607 |
/* |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1608 |
* can do it here if both are Strings/Symbols: |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1609 |
*/ |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1610 |
if (((myClass == _string) || (myClass == Symbol)) |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1611 |
&& ((argClass == _string) || (argClass == Symbol))) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1612 |
l1 = __stringSize(self); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1613 |
l2 = __stringSize(s); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1614 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1615 |
sz = OHDR_SIZE + l1 + l2 + 1; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1616 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1617 |
if (newString != nil) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1618 |
char *cp1, *cp2; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1619 |
REGISTER unsigned char *dstp; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1620 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1621 |
__InstPtr(newString)->o_class = String; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1622 |
dstp = __stringVal(newString); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1623 |
cp1 = (char *) __stringVal(self); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1624 |
cp2 = (char *) __stringVal(aString); |
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1625 |
|
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1626 |
#ifdef bcopy4 |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1627 |
/* knowing that allocation is 4-byte aligned and |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1628 |
* size rounded up to next 4-byte, the first copy |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1629 |
* can be done word-wise. |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1630 |
* that speeds up size-10-string , size-10-string |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1631 |
* by 10% on a P5/200. |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1632 |
*/ |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1633 |
{ |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1634 |
int nw = l1 >> 2; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1635 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1636 |
if (l1 & 3) nw++; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1637 |
bcopy4(cp1, dstp, nw); |
3673 | 1638 |
dstp += l1; |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1639 |
} |
3673 | 1640 |
#else |
1641 |
# ifdef FAST_MEMCPY |
|
1642 |
bcopy(cp1, dstp, l1); |
|
1643 |
dstp += l1; |
|
1644 |
# else |
|
1645 |
# ifdef FAST_STRCPY |
|
1646 |
strncpy(dstp, cp1, l1); |
|
1647 |
dstp += l1; |
|
1648 |
# else |
|
3975 | 1649 |
while (l1 >= 4) { |
1650 |
*(int *)dstp = *(int *)cp1; |
|
1651 |
dstp += 4; cp1 += 4; |
|
1652 |
l1 -= 4; |
|
1653 |
} |
|
3673 | 1654 |
while (l1--) *dstp++ = *cp1++; |
1655 |
# endif |
|
1656 |
# endif |
|
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1657 |
#endif |
2862 | 1658 |
|
3673 | 1659 |
#ifdef bcopy4 |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1660 |
if (((INT)dstp & 3) == 0) { |
3673 | 1661 |
int nw = l2 >> 2; |
1662 |
||
1663 |
if (l2 & 3) nw++; |
|
1664 |
bcopy4(cp2, dstp, nw); |
|
1665 |
*(dstp + l2) = '\0'; |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1666 |
RETURN ( newString ); |
3673 | 1667 |
} |
1668 |
#endif |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1669 |
|
1 | 1670 |
#ifdef FAST_MEMCPY |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1671 |
bcopy(cp2, dstp, l2+1); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1672 |
dstp[l2] = '\0'; |
1 | 1673 |
#else |
1674 |
# ifdef FAST_STRCPY |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1675 |
strncpy(dstp, cp2, l2); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1676 |
dstp[l2] = '\0'; |
1 | 1677 |
# else |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1678 |
while (l2--) *dstp++ = *cp2++; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1679 |
*dstp = '\0'; |
1 | 1680 |
# endif |
1681 |
#endif |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1682 |
RETURN ( newString ); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1683 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1684 |
} |
1 | 1685 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1686 |
%}. |
1 | 1687 |
^ super , aString |
1688 |
! |
|
1689 |
||
1690 |
concatenate:string1 and:string2 |
|
1691 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
1692 |
This is equivalent to self , string1 , string2 |
|
1693 |
- generated by compiler when such a construct is detected" |
|
1694 |
||
1695 |
|newString| |
|
2862 | 1696 |
|
1 | 1697 |
%{ |
95 | 1698 |
int len1, len2, len3, sz; |
1 | 1699 |
#if !defined(FAST_MEMCPY) && !defined(FAST_STRCPY) |
1700 |
REGISTER unsigned char *srcp; |
|
1701 |
#endif |
|
1702 |
REGISTER unsigned char *dstp; |
|
1703 |
||
53 | 1704 |
if ((__isString(self) || __isSymbol(self)) |
1705 |
&& (__isString(string1) || __isSymbol(string1)) |
|
1706 |
&& (__isString(string2) || __isSymbol(string2))) { |
|
1134 | 1707 |
len1 = __stringSize(self); |
1708 |
len2 = __stringSize(string1); |
|
1709 |
len3 = __stringSize(string2); |
|
95 | 1710 |
sz = OHDR_SIZE + len1 + len2 + len3 + 1; |
3111 | 1711 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
159 | 1712 |
if (newString != nil) { |
1134 | 1713 |
__InstPtr(newString)->o_class = String; |
1714 |
dstp = __stringVal(newString); |
|
1 | 1715 |
#ifdef FAST_MEMCPY |
1134 | 1716 |
bcopy(__stringVal(self), dstp, len1); |
1717 |
bcopy(__stringVal(string1), dstp + len1, len2); |
|
1718 |
bcopy(__stringVal(string2), dstp + len1 + len2, len3+1); |
|
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1719 |
*(dstp + len1 + len2 + len3) = '\0'; |
1 | 1720 |
#else |
1721 |
# ifdef FAST_STRCPY |
|
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1722 |
strncpy(dstp, __stringVal(self), len1); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1723 |
strncpy(dstp + len1, __stringVal(string1), len2); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1724 |
strncpy(dstp + len1 + len2, __stringVal(string2), len3); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1725 |
*(dstp + len1 + len2 + len3) = '\0'; |
1 | 1726 |
# else |
1134 | 1727 |
srcp = __stringVal(self); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1728 |
while (len1--) *dstp++ = *srcp++; |
1134 | 1729 |
srcp = __stringVal(string1); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1730 |
while (len2--) *dstp++ = *srcp++; |
1134 | 1731 |
srcp = __stringVal(string2); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1732 |
while (len3--) *dstp++ = *srcp++; |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1733 |
*dstp = '\0'; |
1 | 1734 |
# endif |
1735 |
#endif |
|
159 | 1736 |
RETURN ( newString ); |
1737 |
} |
|
1 | 1738 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1739 |
%}. |
1 | 1740 |
^ super , string1 , string2 |
1741 |
! |
|
1742 |
||
1743 |
concatenate:string1 and:string2 and:string3 |
|
1744 |
"return the concatenation of myself and the string arguments. |
|
1745 |
This is equivalent to self , string1 , string2 , string3 |
|
1746 |
- generated by compiler when such a construct is detected" |
|
1747 |
||
1748 |
|newString| |
|
2862 | 1749 |
|
1 | 1750 |
%{ |
95 | 1751 |
int len1, len2, len3, len4, sz; |
1 | 1752 |
#if !defined(FAST_MEMCPY) && !defined(FAST_STRCPY) |
1753 |
REGISTER unsigned char *srcp; |
|
1754 |
#endif |
|
1755 |
REGISTER unsigned char *dstp; |
|
1756 |
||
53 | 1757 |
if ((__isString(self) || __isSymbol(self)) |
1758 |
&& (__isString(string1) || __isSymbol(string1)) |
|
1759 |
&& (__isString(string2) || __isSymbol(string2)) |
|
1760 |
&& (__isString(string3) || __isSymbol(string3))) { |
|
1134 | 1761 |
len1 = __stringSize(self); |
1762 |
len2 = __stringSize(string1); |
|
1763 |
len3 = __stringSize(string2); |
|
1764 |
len4 = __stringSize(string3); |
|
95 | 1765 |
sz = OHDR_SIZE + len1 + len2 + len3 + len4 + 1; |
3111 | 1766 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
159 | 1767 |
if (newString != nil) { |
1134 | 1768 |
__InstPtr(newString)->o_class = String; |
1769 |
dstp = __stringVal(newString); |
|
1 | 1770 |
#ifdef FAST_MEMCPY |
1134 | 1771 |
bcopy(__stringVal(self), dstp, len1); |
1772 |
bcopy(__stringVal(string1), dstp + len1, len2); |
|
1773 |
bcopy(__stringVal(string2), dstp + len1 + len2, len3); |
|
1774 |
bcopy(__stringVal(string3), dstp + len1 + len2 + len3, len4+1); |
|
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1775 |
*(dstp + len1 + len2 + len3 + len4) = '\0'; |
1 | 1776 |
#else |
1777 |
# ifdef FAST_STRCPY |
|
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1778 |
strncpy(dstp, __stringVal(self), len1); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1779 |
strncpy(dstp + len1, __stringVal(string1), len2); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1780 |
strncpy(dstp + len1 + len2, __stringVal(string2), len3); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1781 |
strncpy(dstp + len1 + len2 + len3, __stringVal(string3), len4); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1782 |
*(dstp + len1 + len2 + len3 + len4) = '\0'; |
1 | 1783 |
# else |
1134 | 1784 |
srcp = __stringVal(self); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1785 |
while (len1--) *dstp++ = *srcp++; |
1134 | 1786 |
srcp = __stringVal(string1); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1787 |
while (len2--) *dstp++ = *srcp++; |
1134 | 1788 |
srcp = __stringVal(string2); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1789 |
while (len3--) *dstp++ = *srcp++; |
1134 | 1790 |
srcp = __stringVal(string3); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1791 |
while (len4--) *dstp++ = *srcp++; |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1792 |
*dstp = '\0'; |
1 | 1793 |
# endif |
1794 |
#endif |
|
159 | 1795 |
RETURN ( newString ); |
1796 |
} |
|
1 | 1797 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1798 |
%}. |
1 | 1799 |
^ super , string1 , string2 , string3 |
1800 |
! |
|
1801 |
||
4745 | 1802 |
copy |
1803 |
"return a copy of the receiver" |
|
1804 |
||
1805 |
(self isMemberOf:String) ifTrue:[ |
|
1806 |
^ self copyFrom:1 |
|
1807 |
]. |
|
1808 |
^ super copy |
|
1809 |
! |
|
1810 |
||
608 | 1811 |
copyFrom:start |
1812 |
"return the substring from start, anInteger to the end. |
|
1813 |
This method will always return a string, even if the receiver |
|
1814 |
is a subclass-instance. This might change if there is a need. |
|
1815 |
- reimplemented here for speed" |
|
1 | 1816 |
|
13 | 1817 |
%{ /* NOCONTEXT */ |
1 | 1818 |
|
608 | 1819 |
#if !defined(FAST_MEMCPY) |
1820 |
REGISTER unsigned char *srcp; |
|
1821 |
#endif |
|
1 | 1822 |
REGISTER unsigned char *dstp; |
608 | 1823 |
REGISTER int count; |
1824 |
int len, index1, sz; |
|
1825 |
OBJ newString; |
|
2862 | 1826 |
OBJ myClass; |
608 | 1827 |
|
2862 | 1828 |
myClass = __qClass(self); |
1829 |
||
2894 | 1830 |
#ifndef NO_PRIM_STRING |
2862 | 1831 |
if (__isSmallInteger(start) |
1832 |
&& ((myClass==String) || (myClass==Symbol))) { |
|
1134 | 1833 |
len = __stringSize(self); |
1834 |
index1 = __intVal(start); |
|
608 | 1835 |
if (index1 > 0) { |
1836 |
if (index1 <= len) { |
|
1837 |
count = len - index1 + 1; |
|
2862 | 1838 |
sz = OHDR_SIZE + count + 1; |
1839 |
||
834 | 1840 |
__PROTECT_CONTEXT__ |
3111 | 1841 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
834 | 1842 |
__UNPROTECT_CONTEXT__ |
2862 | 1843 |
|
608 | 1844 |
if (newString != nil) { |
1134 | 1845 |
__InstPtr(newString)->o_class = String; |
1846 |
dstp = __stringVal(newString); |
|
1 | 1847 |
#ifdef FAST_MEMCPY |
1134 | 1848 |
bcopy(__stringVal(self) + index1 - 1, dstp, count); |
608 | 1849 |
dstp[count] = '\0'; |
1 | 1850 |
#else |
1851 |
# ifdef FAST_STRCPY |
|
1134 | 1852 |
strncpy(dstp, __stringVal(self) + index1 - 1, count); |
608 | 1853 |
dstp[count] = '\0'; |
1 | 1854 |
# else |
1134 | 1855 |
srcp = __stringVal(self) + index1 - 1; |
608 | 1856 |
while (count--) { |
1857 |
*dstp++ = *srcp++; |
|
1858 |
} |
|
1859 |
*dstp = '\0'; |
|
1 | 1860 |
# endif |
1861 |
#endif |
|
608 | 1862 |
RETURN ( newString ); |
1863 |
} |
|
1864 |
} |
|
159 | 1865 |
} |
13 | 1866 |
} |
2894 | 1867 |
#endif |
51 | 1868 |
%}. |
608 | 1869 |
"fall back in case of non-integer index or out-of-bound index; |
1870 |
will eventually lead to an out-of-bound signal raise" |
|
51 | 1871 |
|
608 | 1872 |
^ super copyFrom:start |
1 | 1873 |
! |
1874 |
||
1875 |
copyFrom:start to:stop |
|
1876 |
"return the substring starting at index start, anInteger and ending |
|
53 | 1877 |
at stop, anInteger. This method will always return a string, even |
1878 |
if the receiver is a subclass-instance. This might change if there is a need. |
|
1 | 1879 |
- reimplemented here for speed" |
1880 |
||
13 | 1881 |
%{ /* NOCONTEXT */ |
1882 |
||
1 | 1883 |
REGISTER unsigned char *srcp; |
1884 |
REGISTER unsigned char *dstp; |
|
1885 |
REGISTER int count; |
|
95 | 1886 |
int len, sz, index1, index2; |
13 | 1887 |
OBJ newString; |
2862 | 1888 |
OBJ myClass; |
1 | 1889 |
|
2862 | 1890 |
myClass = __qClass(self); |
1891 |
||
2894 | 1892 |
#ifndef NO_PRIM_STRING |
2862 | 1893 |
if (__bothSmallInteger(start, stop) |
1894 |
&& ((myClass==String) || (myClass==Symbol))) { |
|
1134 | 1895 |
len = __stringSize(self); |
1896 |
index1 = __intVal(start); |
|
1897 |
index2 = __intVal(stop); |
|
1 | 1898 |
|
159 | 1899 |
if ((index1 <= index2) && (index1 > 0)) { |
1900 |
if (index2 <= len) { |
|
1901 |
count = index2 - index1 + 1; |
|
1399 | 1902 |
sz = OHDR_SIZE + count + 1; |
2862 | 1903 |
|
834 | 1904 |
__PROTECT_CONTEXT__ |
3111 | 1905 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
834 | 1906 |
__UNPROTECT_CONTEXT__ |
1399 | 1907 |
|
159 | 1908 |
if (newString != nil) { |
1134 | 1909 |
__InstPtr(newString)->o_class = String; |
1910 |
dstp = __stringVal(newString); |
|
2894 | 1911 |
srcp = __stringVal(self) + index1 - 1; |
1912 |
#ifdef bcopy4 |
|
3111 | 1913 |
{ |
1914 |
int nw = count >> 2; |
|
2894 | 1915 |
|
3111 | 1916 |
if (count & 3) { |
1917 |
nw++; |
|
1918 |
} |
|
1919 |
bcopy4(srcp, dstp, nw); |
|
1920 |
dstp[count] = '\0'; |
|
1921 |
} |
|
1 | 1922 |
#else |
2894 | 1923 |
# ifdef FAST_MEMCPY |
1924 |
bcopy(srcp, dstp, count); |
|
209 | 1925 |
dstp[count] = '\0'; |
1926 |
# else |
|
2894 | 1927 |
# ifdef FAST_STRCPY |
1928 |
strncpy(dstp, srcp, count); |
|
1929 |
dstp[count] = '\0'; |
|
1930 |
# else |
|
159 | 1931 |
while (count--) { |
1932 |
*dstp++ = *srcp++; |
|
1933 |
} |
|
1934 |
*dstp = '\0'; |
|
2894 | 1935 |
# endif |
209 | 1936 |
# endif |
13 | 1937 |
#endif |
159 | 1938 |
RETURN ( newString ); |
1939 |
} |
|
1940 |
} |
|
1941 |
} |
|
375 | 1942 |
/* |
1943 |
* allow empty copy |
|
1944 |
*/ |
|
1945 |
if (index1 > index2) { |
|
834 | 1946 |
__PROTECT_CONTEXT__ |
3111 | 1947 |
__qNew(newString, OHDR_SIZE+1); /* OBJECT ALLOCATION */ |
834 | 1948 |
__UNPROTECT_CONTEXT__ |
375 | 1949 |
if (newString != nil) { |
1134 | 1950 |
__InstPtr(newString)->o_class = String; |
2894 | 1951 |
(__stringVal(newString))[0] = '\0'; |
375 | 1952 |
RETURN ( newString ); |
1953 |
} |
|
1954 |
} |
|
1 | 1955 |
} |
2894 | 1956 |
#endif |
51 | 1957 |
%}. |
1958 |
"fall back in case of non-integer index or out-of-bound index; |
|
1959 |
will eventually lead to an out-of-bound signal raise" |
|
1960 |
||
1 | 1961 |
^ super copyFrom:start to:stop |
1962 |
! |
|
1963 |
||
608 | 1964 |
copyWith:aCharacter |
1965 |
"return a new string containing the receivers characters |
|
1966 |
and the single new character, aCharacter. |
|
1967 |
This is different from concatentation, which expects another string |
|
1968 |
as argument, but equivalent to copy-and-addLast. |
|
1969 |
Reimplemented here for more speed" |
|
1970 |
||
1971 |
%{ /* NOCONTEXT */ |
|
1972 |
||
2887 | 1973 |
int count; |
608 | 1974 |
int sz; |
1975 |
REGISTER unsigned char *dstp; |
|
1976 |
OBJ cls, newString; |
|
2862 | 1977 |
OBJ myClass; |
608 | 1978 |
|
2862 | 1979 |
myClass = __qClass(self); |
1980 |
||
2894 | 1981 |
#ifndef NO_PRIM_STRING |
2862 | 1982 |
if (__isCharacter(aCharacter) |
1983 |
&& ((myClass==String) || (myClass==Symbol))) { |
|
2887 | 1984 |
count = __stringSize(self); |
1985 |
sz = OHDR_SIZE + count + 1 + 1; |
|
608 | 1986 |
|
834 | 1987 |
__PROTECT_CONTEXT__ |
3111 | 1988 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
834 | 1989 |
__UNPROTECT_CONTEXT__ |
2862 | 1990 |
|
608 | 1991 |
if (newString) { |
1134 | 1992 |
__InstPtr(newString)->o_class = String; |
1993 |
dstp = __stringVal(newString); |
|
2862 | 1994 |
|
2887 | 1995 |
#ifdef bcopy4 |
1996 |
{ |
|
1997 |
int nw = count >> 2; |
|
1998 |
char *srcp = (char *)__stringVal(self); |
|
1999 |
||
2000 |
if (count & 3) { |
|
2001 |
nw++; |
|
2002 |
} |
|
2003 |
bcopy4(srcp, dstp, nw); |
|
2004 |
dstp += count; |
|
2005 |
} |
|
608 | 2006 |
#else |
2887 | 2007 |
# ifdef FAST_MEMCPY |
2008 |
bcopy(__stringVal(self), dstp, count); |
|
2009 |
dstp += count; |
|
608 | 2010 |
# else |
2887 | 2011 |
# ifdef FAST_STRCPY |
2012 |
strncpy(dstp, __stringVal(self), count); |
|
2013 |
dstp += count; |
|
2014 |
# else |
|
608 | 2015 |
{ |
2016 |
REGISTER unsigned char *srcp; |
|
2017 |
||
2862 | 2018 |
srcp = __stringVal(self); |
608 | 2019 |
while ((*dstp = *srcp++) != '\0') |
2020 |
dstp++; |
|
2021 |
} |
|
2887 | 2022 |
# endif |
608 | 2023 |
# endif |
2887 | 2024 |
# endif |
1134 | 2025 |
*dstp++ = __intVal(_characterVal(aCharacter)); |
608 | 2026 |
*dstp = '\0'; |
2027 |
RETURN (newString ); |
|
2028 |
} |
|
2029 |
} |
|
2894 | 2030 |
#endif |
608 | 2031 |
%}. |
2032 |
"fall back in case of non-character arg; |
|
2033 |
will eventually lead to an bad element signal raise" |
|
2034 |
||
2035 |
^ super copyWith:aCharacter |
|
2036 |
! |
|
2037 |
||
2886 | 2038 |
deepCopy |
2039 |
"return a copy of the receiver" |
|
608 | 2040 |
|
2041 |
" |
|
2042 |
could be an instance of a subclass which needs deepCopy |
|
2043 |
of its named instvars ... |
|
2044 |
" |
|
2045 |
(self isMemberOf:String) ifTrue:[ |
|
2046 |
^ self copyFrom:1 |
|
2047 |
]. |
|
2048 |
^ super deepCopy |
|
2049 |
! |
|
2050 |
||
2886 | 2051 |
deepCopyUsing:aDictionary |
608 | 2052 |
"return a copy of the receiver - reimplemented to be a bit faster" |
2053 |
||
2054 |
" |
|
2055 |
could be an instance of a subclass which needs deepCopy |
|
2056 |
of its named instvars ... |
|
2057 |
" |
|
2058 |
(self isMemberOf:String) ifTrue:[ |
|
2059 |
^ self copyFrom:1 |
|
2060 |
]. |
|
2061 |
^ super deepCopy |
|
2062 |
! |
|
2063 |
||
2886 | 2064 |
shallowCopy |
2065 |
"return a copy of the receiver" |
|
608 | 2066 |
|
2067 |
(self isMemberOf:String) ifTrue:[ |
|
2068 |
^ self copyFrom:1 |
|
2069 |
]. |
|
2070 |
^ super shallowCopy |
|
2071 |
! |
|
2072 |
||
2886 | 2073 |
simpleDeepCopy |
2074 |
"return a copy of the receiver" |
|
608 | 2075 |
|
2076 |
" |
|
2077 |
could be an instance of a subclass which needs deepCopy |
|
2078 |
of its named instvars ... |
|
2079 |
" |
|
2080 |
(self isMemberOf:String) ifTrue:[ |
|
2081 |
^ self copyFrom:1 |
|
2082 |
]. |
|
2083 |
^ super deepCopy |
|
2084 |
! ! |
|
2085 |
||
4154 | 2086 |
!String methodsFor:'filling & replacing'! |
608 | 2087 |
|
2886 | 2088 |
atAllPut:aCharacter |
608 | 2089 |
"replace all elements with aCharacter |
1 | 2090 |
- reimplemented here for speed" |
2091 |
||
13 | 2092 |
%{ /* NOCONTEXT */ |
2093 |
||
608 | 2094 |
#ifndef FAST_MEMSET |
2095 |
REGISTER unsigned char *dst; |
|
2096 |
REGISTER int l; |
|
1 | 2097 |
#endif |
608 | 2098 |
REGISTER int byteValue; |
1 | 2099 |
|
608 | 2100 |
if (__isCharacter(aCharacter) && __isString(self)) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2101 |
byteValue = __intVal(_characterVal(aCharacter)); |
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2102 |
|
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2103 |
#ifdef FAST_MEMSET |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2104 |
memset(__stringVal(self), byteValue, __stringSize(self)); |
608 | 2105 |
#else |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2106 |
{ |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2107 |
INT v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2108 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2109 |
v = (byteValue << 8) | byteValue; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2110 |
v = (v << 16) | v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2111 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2112 |
dst = __stringVal(self); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2113 |
l = __stringSize(self); |
3712 | 2114 |
|
2115 |
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */ |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2116 |
memset4(dst, v, l>>2); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2117 |
l = l & 3; |
3712 | 2118 |
# else |
2119 |
# ifdef UINT64 |
|
4247 | 2120 |
{ |
2121 |
UINT64 v64; |
|
2122 |
||
4660 | 2123 |
v64 = v; |
4247 | 2124 |
v64 = (v64 << 32) | v; |
4660 | 2125 |
while (l >= 8) { |
4247 | 2126 |
((UINT64 *)dst)[0] = v64; |
2127 |
dst += 8; |
|
2128 |
l -= 8; |
|
2129 |
} |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2130 |
} |
3712 | 2131 |
# else /* no UINT64 */ |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2132 |
while (l >= 16) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2133 |
((int *)dst)[0] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2134 |
((int *)dst)[1] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2135 |
((int *)dst)[2] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2136 |
((int *)dst)[3] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2137 |
dst += 16; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2138 |
l -= 16; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2139 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2140 |
if (l >= 8) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2141 |
((int *)dst)[0] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2142 |
((int *)dst)[1] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2143 |
dst += 8; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2144 |
l -= 8; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2145 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2146 |
if (l >= 4) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2147 |
((int *)dst)[0] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2148 |
dst += 4; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2149 |
l -= 4; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2150 |
} |
3712 | 2151 |
# if 0 |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2152 |
if (l >= 2) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2153 |
((short *)dst)[0] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2154 |
dst += 2; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2155 |
l -= 2; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2156 |
} |
3712 | 2157 |
# endif |
2158 |
||
2159 |
# endif |
|
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2160 |
# endif |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2161 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2162 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2163 |
/* |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2164 |
* remaining bytes |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2165 |
*/ |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2166 |
while (l--) |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2167 |
*dst++ = byteValue; |
3712 | 2168 |
|
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2169 |
#endif /* no FAST_MEMSET */ |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2170 |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2171 |
RETURN ( self ); |
608 | 2172 |
} |
2862 | 2173 |
%}. |
608 | 2174 |
^ super atAllPut:aCharacter |
1 | 2175 |
|
608 | 2176 |
" |
3712 | 2177 |
(String new:10) atAllPut:$* |
608 | 2178 |
String new:10 withAll:$* |
2179 |
" |
|
2180 |
! |
|
2181 |
||
2929 | 2182 |
replaceAll:oldCharacter with:newCharacter |
4120 | 2183 |
"replace all oldCharacters by newCharacter in the receiver. |
2184 |
||
2185 |
Notice: This operation modifies the receiver, NOT a copy; |
|
2186 |
therefore the change may affect all others referencing the receiver." |
|
608 | 2187 |
|
2188 |
%{ /* NOCONTEXT */ |
|
2189 |
||
2190 |
REGISTER unsigned char *srcp; |
|
2191 |
REGISTER unsigned oldVal, newVal; |
|
4120 | 2192 |
unsigned char c, cNext; |
608 | 2193 |
|
2194 |
if (__isCharacter(oldCharacter) |
|
2195 |
&& __isCharacter(newCharacter) |
|
2196 |
&& __isString(self)) { |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2197 |
srcp = (unsigned char *)__stringVal(self); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2198 |
oldVal = __intVal(_characterVal(oldCharacter)); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2199 |
newVal = __intVal(_characterVal(newCharacter)); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2200 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2201 |
cNext = *srcp; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2202 |
while ((c = cNext) != '\0') { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2203 |
cNext = srcp[1]; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2204 |
if (c == oldVal) |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2205 |
*srcp = newVal; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2206 |
srcp++; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2207 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2208 |
RETURN ( self ); |
1 | 2209 |
} |
2862 | 2210 |
%}. |
2929 | 2211 |
^ super replaceAll:oldCharacter with:newCharacter |
51 | 2212 |
|
608 | 2213 |
" |
4120 | 2214 |
'helloWorld' copy replaceAll:$o with:$O |
2215 |
'helloWorld' copy replaceAll:$d with:$* |
|
2216 |
'helloWorld' copy replaceAll:$h with:$* |
|
608 | 2217 |
" |
2218 |
! |
|
1 | 2219 |
|
2886 | 2220 |
replaceFrom:start to:stop with:aString startingAt:repStart |
1 | 2221 |
"replace the characters starting at index start, anInteger and ending |
2222 |
at stop, anInteger with characters from aString starting at repStart. |
|
3234 | 2223 |
Return the receiver. |
1 | 2224 |
|
2225 |
- reimplemented here for speed" |
|
2226 |
||
2227 |
%{ /* NOCONTEXT */ |
|
2228 |
||
2229 |
REGISTER unsigned char *srcp, *dstp; |
|
2230 |
REGISTER int count; |
|
2231 |
int len, index1, index2; |
|
2232 |
int repLen, repIndex; |
|
2233 |
||
2894 | 2234 |
#ifndef NO_PRIM_STRING |
53 | 2235 |
if ((__isString(aString) || __isSymbol(aString)) |
2236 |
&& __isString(self) |
|
252 | 2237 |
&& __bothSmallInteger(start, stop)) { |
3451 | 2238 |
len = __stringSize(self); |
2239 |
index1 = __intVal(start); |
|
2240 |
index2 = __intVal(stop); |
|
2241 |
count = index2 - index1 + 1; |
|
2242 |
if (count <= 0) { |
|
2243 |
RETURN (self); |
|
2244 |
} |
|
2245 |
if ((index2 <= len) && (index1 > 0)) { |
|
2246 |
repLen = __stringSize(aString); |
|
2247 |
repIndex = __intVal(repStart); |
|
2248 |
if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) { |
|
2249 |
srcp = __stringVal(aString) + repIndex - 1; |
|
2250 |
dstp = __stringVal(self) + index1 - 1; |
|
2251 |
if (aString == self) { |
|
2252 |
/* take care of overlapping copy */ |
|
2253 |
if (srcp < dstp) { |
|
2254 |
/* must do a reverse copy */ |
|
2255 |
srcp += count; |
|
2256 |
dstp += count; |
|
2257 |
while (count-- > 0) { |
|
2258 |
*--dstp = *--srcp; |
|
2259 |
} |
|
2260 |
RETURN (self); |
|
2261 |
} |
|
2262 |
} |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2263 |
#ifdef bcopy4 |
3451 | 2264 |
/* copy quadbytes if pointers are aligned */ |
2265 |
/* |
|
2266 |
* no sizeof(int) here please - |
|
2267 |
* - bcopy4 (if defined) copies 4-bytes on ALL machines |
|
2268 |
*/ |
|
2269 |
if ((count > 12) |
|
2270 |
&& (((unsigned INT)srcp & 3) == 0) |
|
2271 |
&& (((unsigned INT)dstp & 3) == 0)) { |
|
2272 |
int n; |
|
2273 |
||
2274 |
n = count >> 2; /* make it quads */ |
|
2275 |
bcopy4(srcp, dstp, n); |
|
2276 |
n <<= 2; /* back to chars */ |
|
2277 |
dstp += n; |
|
2278 |
srcp += n; |
|
2279 |
count -= n; |
|
2280 |
} |
|
2281 |
while (count-- > 0) { |
|
2282 |
*dstp++ = *srcp++; |
|
2283 |
} |
|
1 | 2284 |
#else |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2285 |
# ifdef FAST_MEMCPY |
3451 | 2286 |
bcopy(srcp, dstp, count); |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2287 |
# else |
3451 | 2288 |
/* copy longs if pointers are aligned */ |
2289 |
if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0) |
|
2290 |
&& (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) { |
|
2291 |
while (count >= sizeof(INT)) { |
|
2292 |
*((unsigned INT *)dstp) = *((unsigned INT *)srcp); |
|
2293 |
dstp += sizeof(INT); |
|
2294 |
srcp += sizeof(INT); |
|
2295 |
count -= sizeof(INT); |
|
2296 |
} |
|
2297 |
} |
|
2298 |
while (count-- > 0) { |
|
2299 |
*dstp++ = *srcp++; |
|
2300 |
} |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2301 |
# endif |
1 | 2302 |
#endif |
3451 | 2303 |
RETURN (self); |
2304 |
} |
|
2305 |
} |
|
1 | 2306 |
} |
2894 | 2307 |
#endif |
2862 | 2308 |
%}. |
1 | 2309 |
^ super replaceFrom:start to:stop with:aString startingAt:repStart |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2310 |
|
1 | 2311 |
! |
2312 |
||
2886 | 2313 |
reverse |
2314 |
"in-place reverse the characters of the string." |
|
53 | 2315 |
|
2316 |
"Q: is there a need to redefine it here ?" |
|
1 | 2317 |
|
2318 |
%{ /* NOCONTEXT */ |
|
2319 |
||
2320 |
REGISTER char c; |
|
2321 |
REGISTER unsigned char *hip, *lowp; |
|
2322 |
||
53 | 2323 |
if (__isString(self)) { |
1134 | 2324 |
lowp = __stringVal(self); |
2325 |
hip = lowp + __stringSize(self) - 1; |
|
159 | 2326 |
while (lowp < hip) { |
2327 |
c = *lowp; |
|
2328 |
*lowp = *hip; |
|
2329 |
*hip = c; |
|
2330 |
lowp++; |
|
2331 |
hip--; |
|
2332 |
} |
|
2333 |
RETURN ( self ); |
|
1 | 2334 |
} |
2862 | 2335 |
%}. |
1 | 2336 |
^ super reverse |
2337 |
! |
|
2338 |
||
2339 |
withoutSeparators |
|
2862 | 2340 |
"return a string containing the chars of myself |
2341 |
without leading and trailing whitespace. |
|
2342 |
If there is no whitespace, the receiver is returned. |
|
95 | 2343 |
Notice, this is different from String>>withoutSpaces." |
1 | 2344 |
|
42 | 2345 |
|startIndex "{ Class: SmallInteger }" |
51 | 2346 |
endIndex "{ Class: SmallInteger }" |
2347 |
sz| |
|
2348 |
||
53 | 2349 |
startIndex := 0. |
2862 | 2350 |
|
51 | 2351 |
%{ |
2884 | 2352 |
REGISTER unsigned char *cp; |
2353 |
REGISTER unsigned char *ep; |
|
2354 |
REGISTER unsigned char c; |
|
51 | 2355 |
REGISTER unsigned char *cp0; |
2884 | 2356 |
REGISTER unsigned char *ep0; |
1 | 2357 |
|
51 | 2358 |
/* ignore instances of subclasses ... */ |
329 | 2359 |
if (__qClass(self) == String) { |
3111 | 2360 |
cp = cp0 = __stringVal(self); |
2862 | 2361 |
|
3111 | 2362 |
/* |
2363 |
* find first non-whiteSpace from beginning |
|
2364 |
*/ |
|
2862 | 2365 |
#ifndef NON_ASCII |
2954 | 2366 |
# ifdef UINT64 |
3111 | 2367 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
2368 |
cp += 8; |
|
2369 |
} |
|
2862 | 2370 |
# endif |
3111 | 2371 |
while (*((unsigned *)cp) == 0x20202020) { |
2372 |
cp += 4; |
|
2373 |
} |
|
2862 | 2374 |
#endif |
3111 | 2375 |
while ((c = *cp) |
329 | 2376 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
3111 | 2377 |
&& (c <= ' ') |
329 | 2378 |
#endif |
3111 | 2379 |
&& ((c == ' ') || (c == '\n') || (c == '\t') |
2380 |
|| (c == '\r') || (c == '\f')) |
|
2381 |
) { |
|
2382 |
cp++; |
|
2383 |
} |
|
2884 | 2384 |
|
3111 | 2385 |
/* |
2386 |
* find first non-whiteSpace from end |
|
2387 |
*/ |
|
2388 |
ep = ep0 = cp0 + __stringSize(self) - 1; |
|
2389 |
while ((ep >= cp) && (*ep == ' ')) ep--; |
|
2390 |
c = *ep; |
|
2391 |
while ((ep >= cp) && |
|
2862 | 2392 |
#ifndef NON_ASCII |
3111 | 2393 |
(c <= ' ') && |
329 | 2394 |
#endif |
3111 | 2395 |
((c == ' ') || (c == '\n') || (c == '\t') |
2396 |
|| (c == '\r') || (c == '\f'))) { |
|
2397 |
ep--; |
|
2398 |
c = *ep; |
|
2399 |
} |
|
2884 | 2400 |
|
3111 | 2401 |
/* |
2402 |
* no whiteSpace ? |
|
2403 |
*/ |
|
2404 |
if ((cp == cp0) && (ep == ep0)) { |
|
2405 |
RETURN(self); |
|
2406 |
} |
|
2884 | 2407 |
|
3111 | 2408 |
startIndex = __MKSMALLINT(cp - cp0 + 1); |
2409 |
endIndex = __MKSMALLINT(ep - cp0 + 1); |
|
51 | 2410 |
} |
202 | 2411 |
%}. |
2412 |
startIndex == 0 ifTrue:[^ super withoutSeparators]. |
|
2413 |
||
2414 |
startIndex > endIndex ifTrue:[^ '']. |
|
1 | 2415 |
^ self copyFrom:startIndex to:endIndex |
2884 | 2416 |
|
2417 |
" |
|
2418 |
'hello' withoutSeparators |
|
2419 |
' hello' withoutSeparators |
|
2420 |
' hello ' withoutSeparators |
|
2421 |
' hello ' withoutSeparators |
|
2422 |
' hello ' withoutSeparators |
|
2423 |
' hello ' withoutSeparators |
|
2424 |
' ' withoutSeparators |
|
2425 |
" |
|
2426 |
||
608 | 2427 |
! |
2428 |
||
2429 |
withoutSpaces |
|
2862 | 2430 |
"return a string containing the characters of myself |
2431 |
without leading and trailing spaces. |
|
2884 | 2432 |
If there are no spaces, the receiver is returned unchanged. |
608 | 2433 |
Notice, this is different from String>>withoutSeparators." |
2434 |
||
2435 |
|startIndex "{ Class: SmallInteger }" |
|
2436 |
endIndex "{ Class: SmallInteger }" |
|
2437 |
sz blank| |
|
2438 |
||
2439 |
startIndex := 0. |
|
2440 |
%{ |
|
2441 |
REGISTER unsigned char *cp; |
|
2884 | 2442 |
REGISTER unsigned char *ep; |
2443 |
unsigned char *cp0; |
|
2444 |
unsigned char *ep0; |
|
608 | 2445 |
|
2446 |
/* ignore instances of subclasses ... */ |
|
2447 |
if (__qClass(self) == String) { |
|
3111 | 2448 |
cp = cp0 = __stringVal(self); |
2862 | 2449 |
|
3111 | 2450 |
/* |
2451 |
* find first non-blank from beginning |
|
2452 |
*/ |
|
2862 | 2453 |
#ifndef NON_ASCII |
2954 | 2454 |
# ifdef UINT64 |
3111 | 2455 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
2456 |
cp += 8; |
|
2457 |
} |
|
2954 | 2458 |
# endif /* UINT64 */ |
3111 | 2459 |
while (*((unsigned *)cp) == 0x20202020) { |
2460 |
cp += 4; |
|
2461 |
} |
|
2862 | 2462 |
#endif |
3111 | 2463 |
while (*cp == ' ') cp++; |
2884 | 2464 |
|
3111 | 2465 |
/* |
2466 |
* find first non-blank from end |
|
2467 |
*/ |
|
2468 |
ep = ep0 = cp0 + __stringSize(self) - 1; |
|
2469 |
while ((ep >= cp) && (*ep == ' ')) ep--; |
|
2862 | 2470 |
|
3111 | 2471 |
/* |
2472 |
* no blanks ? |
|
2473 |
*/ |
|
2474 |
if ((cp == cp0) && (ep == ep0)) { |
|
2475 |
RETURN(self); |
|
2476 |
} |
|
2884 | 2477 |
|
3111 | 2478 |
startIndex = __MKSMALLINT(cp - cp0 + 1); |
2479 |
endIndex = __MKSMALLINT(ep - cp0 + 1); |
|
608 | 2480 |
} |
2481 |
%}. |
|
2482 |
startIndex == 0 ifTrue:[^ super withoutSpaces]. |
|
2483 |
||
2484 |
startIndex > endIndex ifTrue:[^ '']. |
|
2886 | 2485 |
((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self]. |
608 | 2486 |
^ self copyFrom:startIndex to:endIndex |
2884 | 2487 |
|
2488 |
" |
|
2489 |
' hello' withoutSpaces |
|
2490 |
' hello ' withoutSpaces |
|
2491 |
' hello ' withoutSpaces |
|
2492 |
' hello ' withoutSpaces |
|
2493 |
' hello ' withoutSpaces |
|
2494 |
' ' withoutSpaces |
|
2495 |
" |
|
608 | 2496 |
! ! |
2497 |
||
2498 |
!String methodsFor:'printing & storing'! |
|
2499 |
||
2886 | 2500 |
isLiteral |
4660 | 2501 |
"return true, if the receiver can be used as a literal constant in ST syntax |
608 | 2502 |
(i.e. can be used in constant arrays)" |
2503 |
||
2504 |
^ true |
|
2505 |
! |
|
2506 |
||
2886 | 2507 |
|
2508 |
"print the receiver on standard output. |
|
4631 | 2509 |
This method does NOT (by purpose) use the stream classes and |
2510 |
will therefore work even in case of emergency." |
|
608 | 2511 |
|
2512 |
%{ /* NOCONTEXT */ |
|
2513 |
||
2514 |
if (__qClass(self) == String) { |
|
1486 | 2515 |
#ifdef WIN32 |
4660 | 2516 |
fprintf(stdout, "%s" , __stringVal(self)); |
1486 | 2517 |
#else |
4631 | 2518 |
/*cg: used to have fputs here, but that seems to be NOT prepared |
2519 |
* for eintr arriving and thus sometimes sends the string twice ... |
|
2520 |
* |
|
2521 |
* fputs(__stringVal(self), stdout); |
|
2522 |
*/ |
|
4660 | 2523 |
fwrite(__stringVal(self), 1, __stringSize(self), stdout); |
2524 |
fflush(stdout); |
|
1486 | 2525 |
#endif |
4660 | 2526 |
RETURN (self); |
608 | 2527 |
} |
3751 | 2528 |
%}. |
608 | 2529 |
^ super print |
2530 |
! |
|
2531 |
||
3751 | 2532 |
printCR |
2533 |
"print the receiver on standard output, followed by a cr. |
|
4631 | 2534 |
This method does NOT (by purpose) use the stream classes and |
2535 |
will therefore work even in case of emergency." |
|
3751 | 2536 |
|
2537 |
%{ /* NOCONTEXT */ |
|
2538 |
||
2539 |
if (__qClass(self) == String) { |
|
2540 |
#ifdef WIN32 |
|
4660 | 2541 |
fprintf(stderr, "%s\n" , __stringVal(self)); |
3751 | 2542 |
#else |
4631 | 2543 |
/*cg: used to have fputs here, but that seems to be NOT prepared |
2544 |
* for eintr arriving and thus sometimes sends the string twice ... |
|
2545 |
* |
|
2546 |
* fputs(__stringVal(self), stdout); fputs("\n", stdout); |
|
2547 |
*/ |
|
4660 | 2548 |
fwrite(__stringVal(self), 1, __stringSize(self), stdout); |
2549 |
fwrite("\n", 1, 1, stdout); |
|
2550 |
fflush(stdout); |
|
3751 | 2551 |
#endif |
4660 | 2552 |
RETURN (self); |
3751 | 2553 |
} |
2554 |
%}. |
|
2555 |
^ super printCR |
|
2556 |
! |
|
2557 |
||
2886 | 2558 |
printfPrintString:formatString |
608 | 2559 |
"non-portable but sometimes useful. |
2560 |
Return a printed representation of the receiver as specified by formatString, |
|
2561 |
which is defined by printf. |
|
2562 |
No checking on buffer overrun is done; the resulting string may not |
|
2563 |
be larger than 799 characters. |
|
2564 |
This method is NONSTANDARD and may be removed without notice." |
|
2565 |
||
2566 |
%{ /* STACK: 1000 */ |
|
2567 |
||
2568 |
char buffer[800]; |
|
2569 |
char *cp; |
|
2570 |
OBJ s; |
|
2571 |
||
2572 |
if (__isString(formatString)) { |
|
2573 |
/* |
|
2574 |
* actually only needed on sparc: since thisContext is |
|
2575 |
* in a global register, which gets destroyed by printf, |
|
2576 |
* manually save it here - very stupid ... |
|
2577 |
*/ |
|
2578 |
||
1134 | 2579 |
cp = (char *)__stringVal(self); |
608 | 2580 |
if (__qClass(self) != String) |
1134 | 2581 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
608 | 2582 |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
2583 |
__BEGIN_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
2584 |
|
1134 | 2585 |
sprintf(buffer, (char *)__stringVal(formatString), cp); |
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
2586 |
|
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
2587 |
__END_PROTECT_REGISTERS__ |
608 | 2588 |
|
833 | 2589 |
s = __MKSTRING(buffer COMMA_SND); |
608 | 2590 |
if (s != nil) { |
2591 |
RETURN (s); |
|
2592 |
} |
|
2593 |
} |
|
2594 |
%}. |
|
2595 |
self primitiveFailed |
|
2596 |
||
2597 |
" |
|
2598 |
'hello' printfPrintString:'%%s -> %s' |
|
2599 |
'hello' printfPrintString:'%%10s -> %10s' |
|
2600 |
'hello' printfPrintString:'%%-10s -> %-10s' |
|
2601 |
" |
|
2602 |
! |
|
2603 |
||
2886 | 2604 |
storeOn:aStream |
608 | 2605 |
"put the storeString of myself on aStream" |
2606 |
||
2607 |
aStream nextPut: $'. |
|
2608 |
(self includes:$') ifTrue:[ |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2609 |
self printWithQuotesDoubledOn:aStream |
608 | 2610 |
] ifFalse:[ |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2611 |
aStream nextPutAll:self |
608 | 2612 |
]. |
2613 |
aStream nextPut:$' |
|
3579 | 2614 |
|
2615 |
"Modified: / 15.6.1998 / 17:21:51 / cg" |
|
608 | 2616 |
! |
2617 |
||
2886 | 2618 |
storeString |
2619 |
"return a String for storing myself" |
|
608 | 2620 |
|
2621 |
|s n index| |
|
2622 |
||
2623 |
n := self occurrencesOf:$'. |
|
2624 |
n == 0 ifFalse:[ |
|
2625 |
s := String new:(n + 2 + self size). |
|
2626 |
s at:1 put:$'. |
|
2627 |
index := 2. |
|
2628 |
self do:[:thisChar | |
|
2629 |
(thisChar == $') ifTrue:[ |
|
2630 |
s at:index put:thisChar. |
|
2631 |
index := index + 1. |
|
2632 |
]. |
|
2633 |
s at:index put:thisChar. |
|
2634 |
index := index + 1. |
|
2635 |
]. |
|
2636 |
s at:index put:$'. |
|
2637 |
^ s |
|
2638 |
]. |
|
2639 |
^ '''' , self , '''' |
|
1 | 2640 |
! ! |
2641 |
||
2642 |
!String methodsFor:'queries'! |
|
2643 |
||
5557 | 2644 |
basicSize |
2645 |
"return the number of characters in myself. |
|
2646 |
Redefined here to exclude the 0-byte at the end." |
|
2647 |
||
2648 |
%{ /* NOCONTEXT */ |
|
2649 |
REGISTER OBJ slf, cls; |
|
2650 |
||
2651 |
slf = self; |
|
2652 |
||
2653 |
cls = __qClass(slf); |
|
2654 |
if (cls == String) { |
|
2655 |
RETURN ( __MKSMALLINT(__stringSize(slf)) ); |
|
2656 |
} |
|
2657 |
RETURN ( __MKSMALLINT(__stringSize(slf) |
|
2658 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
|
2659 |
%}. |
|
2660 |
^ super basicSize - 1 |
|
2661 |
||
2662 |
! |
|
2663 |
||
2886 | 2664 |
bitsPerCharacter |
1239 | 2665 |
"return the number of bits each character has. |
2666 |
Here, 8 is returned (storing single byte characters)." |
|
2667 |
||
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2668 |
^ 8 |
1239 | 2669 |
|
2670 |
"Modified: 20.4.1996 / 23:08:42 / cg" |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2671 |
! |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2672 |
|
2886 | 2673 |
knownAsSymbol |
2674 |
"return true, if there is a symbol with same characters in the |
|
2862 | 2675 |
system. |
2676 |
Can be used to check for existance of a symbol without creating one" |
|
608 | 2677 |
|
2678 |
%{ /* NOCONTEXT */ |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2679 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2680 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2681 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2682 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2683 |
if (cls != String) { |
5407 | 2684 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2685 |
} else { |
5407 | 2686 |
indx = 0; |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2687 |
} |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2688 |
RETURN ( __KNOWNASSYMBOL(__stringVal(self) + indx) ); |
5407 | 2689 |
%}. |
2690 |
self primitiveFailed |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2691 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2692 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2693 |
'hello' knownAsSymbol |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2694 |
'fooBarBaz' knownAsSymbol |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2695 |
" |
5557 | 2696 |
! |
2697 |
||
2698 |
size |
|
2699 |
"return the number of characters in myself. |
|
2700 |
Reimplemented here to avoid the additional size->basicSize send |
|
2701 |
(which we can do here, since size is obviously not redefined in a subclass). |
|
2702 |
This method is the same as basicSize." |
|
2703 |
||
2704 |
%{ /* NOCONTEXT */ |
|
2705 |
REGISTER OBJ cls, slf; |
|
2706 |
||
2707 |
slf = self; |
|
2708 |
cls = __qClass(slf); |
|
2709 |
if (cls == String) { |
|
2710 |
RETURN ( __MKSMALLINT(__stringSize(slf)) ); |
|
2711 |
} |
|
2712 |
RETURN ( __MKSMALLINT(__stringSize(slf) |
|
2713 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
|
2714 |
%}. |
|
2715 |
^ self basicSize |
|
1 | 2716 |
! ! |
608 | 2717 |
|
2670 | 2718 |
!String methodsFor:'regular expression matching'! |
2719 |
||
2886 | 2720 |
asRegex |
2721 |
"Compile the receiver as a regex matcher. May raise RxParser>>syntaxErrorSignal |
|
2670 | 2722 |
or RxParser>>compilationErrorSignal. |
2723 |
||| This is a part of the Regular Expression Matcher package, (c) Vassili Bykov, 1996. |
|
2724 |
||| Refer to `documentation' protocol of RxParser class for details." |
|
2725 |
||
2726 |
^ Regex::RxParser preferredMatcherClass for: (Regex::RxParser new parse: self) |
|
2727 |
||
2728 |
"Modified: 3.6.1997 / 11:25:25 / cg" |
|
2729 |
! |
|
2730 |
||
2886 | 2731 |
matchesRegex: regexString |
2670 | 2732 |
"Test if the receiver matches a regex. May raise RxParser>>regexErrorSignal or |
2733 |
child signals. |
|
2734 |
||| This is a part of the Regular Expression Matcher package, (c) Vassili Bykov, 1996. |
|
2735 |
||| Refer to `documentation' protocol of RxParser class for details." |
|
2736 |
||
2737 |
^regexString asRegex matches: self |
|
2738 |
||
2739 |
"Modified: 3.6.1997 / 11:25:30 / cg" |
|
2740 |
! |
|
2741 |
||
2886 | 2742 |
prefixMatchesRegex: regexString |
2670 | 2743 |
"Test if the receiver's prefix matches a regex. |
2744 |
May raise RxParser class>>regexErrorSignal or child signals. |
|
2745 |
||| This is a part of the Regular Expression Matcher package, (c) Vassili Bykov, 1996. |
|
2746 |
||| Refer to `documentation' protocol of RxParser class for details." |
|
2747 |
||
2748 |
^regexString asRegex matchesPrefix: self |
|
2749 |
||
2750 |
"Modified: 3.6.1997 / 11:25:34 / cg" |
|
2751 |
! ! |
|
2752 |
||
608 | 2753 |
!String methodsFor:'testing'! |
2754 |
||
2886 | 2755 |
endsWith:aStringOrChar |
2862 | 2756 |
"return true, if the receiver ends with something, aStringOrChar." |
1380 | 2757 |
|
2758 |
%{ /* NOCONTEXT */ |
|
2759 |
||
2760 |
int len1, len2; |
|
2761 |
REGISTER unsigned char *src1, *src2; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
2762 |
unsigned char c; |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2763 |
REGISTER OBJ slf = self; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2764 |
|
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2765 |
if ((__isString(slf) || __isSymbol(slf)) |
2862 | 2766 |
&& (__isString(aStringOrChar) || __isSymbol(aStringOrChar))) { |
4660 | 2767 |
len1 = __qSize(slf); |
2768 |
len2 = __qSize(aStringOrChar); |
|
2769 |
if (len1 < len2) { |
|
2770 |
RETURN ( false ); |
|
2771 |
} |
|
2772 |
||
2773 |
src1 = __stringVal(slf) + (len1 - len2); |
|
2774 |
src2 = __stringVal(aStringOrChar); |
|
2775 |
while (c = *src2++) { |
|
2776 |
if (c != *src1++) { |
|
2777 |
RETURN ( false ); |
|
2778 |
} |
|
2779 |
} |
|
2780 |
RETURN (true); |
|
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2781 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2782 |
if (__isCharacter(aStringOrChar)) { |
4660 | 2783 |
int val; |
2784 |
||
2785 |
val = __intVal(_characterVal(aStringOrChar)); |
|
2786 |
if ((unsigned)val <= 255) { |
|
2787 |
len1 = __stringSize(slf); |
|
2788 |
if (len1 > 0) { |
|
2789 |
RETURN ( (__stringVal(slf)[len1-1] == val) ? true : false); |
|
2790 |
} |
|
2791 |
} |
|
2792 |
RETURN ( false ); |
|
1380 | 2793 |
} |
2794 |
%}. |
|
2862 | 2795 |
^ super endsWith:aStringOrChar |
1380 | 2796 |
|
2797 |
" |
|
2798 |
'hello world' endsWith:'world' |
|
2799 |
'hello world' endsWith:'earth' |
|
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2800 |
'hello world' endsWith:$d |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2801 |
'hello world' endsWith:$e |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2802 |
'' endsWith:$d |
1380 | 2803 |
'hello world' endsWith:#($r $l $d) |
4389
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4388
diff
changeset
|
2804 |
'hello world' endsWith:'' |
1380 | 2805 |
" |
2806 |
! |
|
2807 |
||
2886 | 2808 |
isBlank |
2809 |
"return true, if the receivers size is 0 or if it contains only spaces. |
|
608 | 2810 |
Q: should we care for whiteSpace in general here ?" |
2811 |
||
2812 |
%{ /* NOCONTEXT */ |
|
2813 |
||
2814 |
REGISTER unsigned char *src; |
|
2815 |
REGISTER unsigned char c; |
|
2816 |
OBJ cls; |
|
2817 |
||
1134 | 2818 |
src = __stringVal(self); |
608 | 2819 |
if ((cls = __qClass(self)) != String) |
5407 | 2820 |
src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
608 | 2821 |
|
2822 |
#ifndef NON_ASCII |
|
2954 | 2823 |
# ifdef UINT64 |
2824 |
while (*((UINT64 *)src) == 0x2020202020202020L) { |
|
5407 | 2825 |
src += 8; |
2862 | 2826 |
} |
2954 | 2827 |
# endif /* UINT64 */ |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2828 |
|
608 | 2829 |
while (*((unsigned *)src) == 0x20202020) { |
5407 | 2830 |
src += 4; |
608 | 2831 |
} |
2862 | 2832 |
#endif /* ascii */ |
2833 |
||
2834 |
while (c = *src++) { |
|
5407 | 2835 |
if (c != ' ') { |
2836 |
RETURN ( false ); |
|
2837 |
} |
|
2862 | 2838 |
} |
5407 | 2839 |
RETURN ( true ); |
608 | 2840 |
%}. |
5407 | 2841 |
^ super isBlank |
608 | 2842 |
! |
2843 |
||
5556 | 2844 |
isEmpty |
2845 |
"return true if the receiver is empty (i.e. if size == 0) |
|
2846 |
Redefined here for performance" |
|
2847 |
||
2848 |
%{ /* NOCONTEXT */ |
|
2849 |
OBJ cls; |
|
2850 |
||
2851 |
cls = __qClass(self); |
|
2852 |
if ((cls == String) || (cls == Symbol)) { |
|
2853 |
RETURN ( (__stringSize(self) == 0) ? true : false); |
|
2854 |
} |
|
2855 |
%}. |
|
2856 |
^ self size == 0 |
|
2857 |
! |
|
2858 |
||
2886 | 2859 |
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight |
608 | 2860 |
"parametrized levenshtein. arguments are the costs for |
2861 |
substitution, case-change, insertion and deletion of a character." |
|
2862 |
||
1138
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
2863 |
%{ /* STACK: 2000 */ |
608 | 2864 |
|
2865 |
/* |
|
2866 |
* this is very heavy used when correcting errors |
|
2867 |
* (all symbols are searched for best match) - therefore it must be fast |
|
2868 |
*/ |
|
2869 |
{ |
|
2870 |
unsigned short *data; |
|
2871 |
int l1, l2; |
|
2872 |
REGISTER int sz; |
|
2873 |
unsigned char *s1, *s2; |
|
2874 |
int v1, v2, v3, m; |
|
2875 |
REGISTER unsigned short *dp; |
|
2876 |
REGISTER int delta; |
|
2877 |
REGISTER int j; |
|
2878 |
int i; |
|
2879 |
int iW, cW, sW, dW; |
|
1486 | 2880 |
# define FASTSIZE 30 /* increase STACK if you increase this ... */ |
608 | 2881 |
unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)]; |
2882 |
||
2883 |
if ((__isString(self) || __isSymbol(self)) |
|
2884 |
&& (__isString(aString) || __isSymbol(aString)) |
|
2885 |
&& __bothSmallInteger(insrtWeight, caseWeight) |
|
2886 |
&& __bothSmallInteger(substWeight, deleteWeight)) { |
|
1134 | 2887 |
iW = __intVal(insrtWeight); |
2888 |
cW = __intVal(caseWeight); |
|
2889 |
sW = __intVal(substWeight); |
|
2890 |
dW = __intVal(deleteWeight); |
|
2891 |
s1 = __stringVal(self); |
|
2892 |
s2 = __stringVal(aString); |
|
608 | 2893 |
l1 = strlen(s1); |
2894 |
l2 = strlen(s2); |
|
2895 |
||
2896 |
sz = (l1 < l2) ? l2 : l1; |
|
2897 |
delta = sz + 1; |
|
2898 |
if (sz <= FASTSIZE) { |
|
2899 |
data = fastData; |
|
2900 |
} else { |
|
2901 |
/* add ifdef ALLOCA here ... */ |
|
2902 |
data = (unsigned short *)malloc(delta * delta * sizeof(short)); |
|
2903 |
if (! data) goto mallocFailed; |
|
2904 |
} |
|
2905 |
||
2906 |
data[0] = 0; |
|
2907 |
dp = data+1; |
|
2908 |
for (j=1, dp=data+1; j<=sz; j++, dp++) |
|
2909 |
*dp = *(dp-1) + iW; |
|
2910 |
||
2911 |
for (i=1, dp=data+delta; i<=sz; i++, dp+=delta) |
|
2912 |
*dp = *(dp-delta) + dW; |
|
2913 |
||
2914 |
for (i=1; i<=l1; i++) { |
|
2915 |
for (j=1; j<=l2; j++) { |
|
2916 |
dp = data + (i*delta) + j; |
|
2917 |
if (s1[i] != s2[j]) { |
|
2918 |
if (tolower(s1[i]) == tolower(s2[j])) { |
|
2919 |
m = cW; |
|
2920 |
} else { |
|
2921 |
m = sW; |
|
2922 |
} |
|
2923 |
} else |
|
2924 |
m = 0; |
|
2925 |
||
2926 |
v2 = *(dp - 1) + iW; |
|
2927 |
v3 = *(dp - delta) + dW; |
|
2928 |
v1 = *(dp - delta - 1) + m; |
|
2929 |
if (v1 < v2) |
|
2930 |
if (v1 < v3) |
|
2931 |
m = v1; |
|
2932 |
else |
|
2933 |
m = v3; |
|
2934 |
else |
|
2935 |
if (v2 < v3) |
|
2936 |
m = v2; |
|
2937 |
else |
|
2938 |
m = v3; |
|
2939 |
*dp = m; |
|
2940 |
} |
|
2941 |
} |
|
2942 |
m = data[l1 * delta + l2]; |
|
2943 |
if (sz > FASTSIZE) |
|
2944 |
free(data); |
|
1134 | 2945 |
RETURN ( __MKSMALLINT(m) ); |
608 | 2946 |
} |
2947 |
mallocFailed: ; |
|
2948 |
} |
|
2949 |
%}. |
|
2950 |
||
2951 |
^ super levenshteinTo:aString |
|
2952 |
s:substWeight c:caseWeight |
|
2953 |
i:insrtWeight d:deleteWeight |
|
2954 |
||
2955 |
"'ocmprt' levenshteinTo:'computer' |
|
2956 |
'computer' levenshteinTo:'computer' |
|
2957 |
'ocmputer' levenshteinTo:'computer' |
|
2958 |
'cmputer' levenshteinTo:'computer' |
|
2959 |
'Computer' levenshteinTo:'computer'" |
|
1380 | 2960 |
! |
2961 |
||
5556 | 2962 |
notEmpty |
2963 |
"return true if the receiver is not empty (i.e. if size ~~ 0) |
|
2964 |
Redefined here for performance" |
|
2965 |
||
2966 |
%{ /* NOCONTEXT */ |
|
2967 |
OBJ cls; |
|
2968 |
||
2969 |
cls = __qClass(self); |
|
2970 |
if ((cls == String) || (cls == Symbol)) { |
|
2971 |
RETURN ( (__stringSize(self) != 0) ? true : false); |
|
2972 |
} |
|
2973 |
%}. |
|
2974 |
^ self size ~~ 0 |
|
2975 |
! |
|
2976 |
||
2886 | 2977 |
startsWith:aStringOrChar |
4389
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4388
diff
changeset
|
2978 |
"return true, if the receiver starts with something, aStringOrChar. |
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4388
diff
changeset
|
2979 |
If the argument is empty, true is returned." |
1380 | 2980 |
|
2981 |
%{ /* NOCONTEXT */ |
|
2982 |
||
2983 |
int len1, len2; |
|
2984 |
REGISTER unsigned char *src1, *src2; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
2985 |
unsigned char c; |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2986 |
REGISTER OBJ slf = self; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2987 |
|
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2988 |
if (((__qClass(slf)==String) || (__qClass(slf)==Symbol)) |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
2989 |
&& __isNonNilObject(aStringOrChar) |
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
2990 |
&& ((__qClass(aStringOrChar)==String) || (__qClass(aStringOrChar)==Symbol))) { |
4660 | 2991 |
src1 = __stringVal(slf); |
2992 |
src2 = __stringVal(aStringOrChar); |
|
2993 |
||
2994 |
if (src1[0] != src2[0]) { |
|
2995 |
if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) { |
|
2996 |
RETURN (true); |
|
2997 |
} |
|
2998 |
RETURN ( false ); |
|
2999 |
} |
|
3000 |
||
3001 |
len1 = __qSize(slf); |
|
3002 |
len2 = __qSize(aStringOrChar); |
|
3003 |
if (len1 < len2) { |
|
3004 |
RETURN ( false ); |
|
3005 |
} |
|
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3006 |
|
4247 | 3007 |
#ifdef UINT64 |
4660 | 3008 |
while (len2 > (OHDR_SIZE+sizeof(UINT64))) { |
3009 |
if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) { |
|
3010 |
RETURN (false); |
|
3011 |
} |
|
3012 |
len2 -= sizeof(UINT64); |
|
3013 |
src1 += sizeof(UINT64); |
|
3014 |
src2 += sizeof(UINT64); |
|
3015 |
} |
|
4247 | 3016 |
#else |
3017 |
# ifdef UNROLL_LOOPS |
|
4660 | 3018 |
while (len2 > (OHDR_SIZE+sizeof(INT)*4)) { |
3019 |
if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) { |
|
3020 |
RETURN (false); |
|
3021 |
} |
|
3022 |
if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) { |
|
3023 |
RETURN (false); |
|
3024 |
} |
|
3025 |
if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) { |
|
3026 |
RETURN (false); |
|
3027 |
} |
|
3028 |
if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) { |
|
3029 |
RETURN (false); |
|
3030 |
} |
|
3031 |
len2 -= sizeof(INT)*4; |
|
3032 |
src1 += sizeof(INT)*4; |
|
3033 |
src2 += sizeof(INT)*4; |
|
3034 |
} |
|
4247 | 3035 |
# endif /* UNROLL_LOOPS */ |
3036 |
#endif /* UINT64 */ |
|
3546
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
3037 |
|
4660 | 3038 |
while (len2 > (OHDR_SIZE+sizeof(INT))) { |
3039 |
if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) { |
|
3040 |
RETURN (false); |
|
3041 |
} |
|
3042 |
len2 -= sizeof(INT); |
|
3043 |
src1 += sizeof(INT); |
|
3044 |
src2 += sizeof(INT); |
|
3045 |
} |
|
3046 |
||
3047 |
while (c = *src2++) { |
|
3048 |
if (c != *src1) { |
|
3049 |
RETURN ( false ); |
|
3050 |
} |
|
3051 |
src1++; |
|
3052 |
} |
|
3053 |
RETURN (true); |
|
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3054 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3055 |
if (__isCharacter(aStringOrChar)) { |
4660 | 3056 |
int val; |
3057 |
||
3058 |
val = __intVal(_characterVal(aStringOrChar)); |
|
3059 |
if ((unsigned)val <= 255) { |
|
3060 |
len1 = __stringSize(slf); |
|
3061 |
if (len1 > 0) { |
|
3062 |
RETURN ( (__stringVal(slf)[0] == val) ? true : false); |
|
3063 |
} |
|
3064 |
} |
|
3065 |
RETURN ( false ); |
|
1380 | 3066 |
} |
3067 |
%}. |
|
2862 | 3068 |
^ super startsWith:aStringOrChar |
1380 | 3069 |
|
3070 |
" |
|
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
3071 |
'hello world' startsWith:'hello' |
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
3072 |
'hello world' startsWith:'hella' |
1380 | 3073 |
'hello world' startsWith:'hi' |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3074 |
'hello world' startsWith:$h |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3075 |
'hello world' startsWith:$H |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3076 |
'hello world' startsWith:(Character value:16rFF00) |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3077 |
'hello world' startsWith:60 |
1380 | 3078 |
'hello world' startsWith:#($h $e $l) |
4389
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4388
diff
changeset
|
3079 |
'hello world' startsWith:'' |
1380 | 3080 |
" |
608 | 3081 |
! ! |
3082 |
||
4660 | 3083 |
!String methodsFor:'tracing'! |
3084 |
||
4682 | 3085 |
traceInto:aRequestor level:level from:referrer |
4660 | 3086 |
"double dispatch into tracer, passing my type implicitely in the selector" |
3087 |
||
4682 | 3088 |
^ aRequestor traceString:self level:level from:referrer |
4660 | 3089 |
|
3090 |
||
3091 |
! ! |
|
3092 |
||
633 | 3093 |
!String class methodsFor:'documentation'! |
3094 |
||
2886 | 3095 |
version |
5557 | 3096 |
^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.154 2000-08-22 13:57:30 cg Exp $' |
633 | 3097 |
! ! |