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