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