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