author | Claus Gittinger <cg@exept.de> |
Thu, 15 May 2014 19:20:43 +0200 | |
changeset 16457 | c25394c44436 |
parent 16393 | 4d56dffdd2ca |
child 16543 | fcdac85d5bee |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
9473 | 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 |
" |
|
5407 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
3989 | 14 |
CharacterArray variableByteSubclass:#String |
9473 | 15 |
instanceVariableNames:'' |
14330 | 16 |
classVariableNames:'CRLF CR LF TAB' |
9473 | 17 |
poolDictionaries:'' |
18 |
category:'Collections-Text' |
|
88 | 19 |
! |
20 |
||
216 | 21 |
!String primitiveDefinitions! |
88 | 22 |
%{ |
2894 | 23 |
|
3809
dd1df62365ee
use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
24 |
#include <stdio.h> |
dd1df62365ee
use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
25 |
#define _STDIO_H_INCLUDED_ |
14752
201d3e649814
include stdlib.h to define malloc() prototypes
Stefan Vogel <sv@exept.de>
parents:
14664
diff
changeset
|
26 |
#include <stdlib.h> |
88 | 27 |
#include <ctype.h> |
359 | 28 |
|
273 | 29 |
#ifdef LINUX |
359 | 30 |
# define __STRINGDEFS__ |
31 |
# include <linuxIntern.h> |
|
273 | 32 |
#endif |
95 | 33 |
|
34 |
/* |
|
35 |
* old st/x creates strings with spaces in it; |
|
36 |
* new st/x will fill it with zeros (for st-80 compatibility) |
|
37 |
* the define below sets old behavior. |
|
38 |
*/ |
|
39 |
#define INITIALIZE_WITH_SPACE |
|
6370 | 40 |
|
41 |
#ifdef FAST_MEMCHR |
|
42 |
char *memchr(); |
|
43 |
#endif |
|
88 | 44 |
%} |
216 | 45 |
! ! |
88 | 46 |
|
8647 | 47 |
!String primitiveFunctions! |
48 |
%{ |
|
49 |
||
8898 | 50 |
static int |
10371 | 51 |
nextOnKeyboard(char1, char2) |
52 |
{ |
|
8647 | 53 |
/* compare two characters if they are next to each other on a (US-) keyboard */ |
10370 | 54 |
|
55 |
static char *us_keys[] = { "1234567890-", |
|
9473 | 56 |
"*qwertyuiop", |
57 |
"**asdfghjkl:", |
|
58 |
"***zxcvbnm", |
|
59 |
0 }; |
|
10370 | 60 |
static char *de_keys[] = { "1234567890-", |
61 |
"*qwertzuiop", |
|
62 |
"**asdfghjkl:", |
|
63 |
"***yxcvbnm", |
|
64 |
0 }; |
|
10371 | 65 |
char **keys = us_keys; |
8647 | 66 |
char **line1, **line2; |
67 |
char *col1, *col2; |
|
68 |
int diff; |
|
69 |
||
70 |
for (line1 = keys; *line1 != 0; line1++) { |
|
9473 | 71 |
for (col1 = *line1; *col1 != 0 && *col1 != char1; col1++) |
72 |
continue; |
|
8647 | 73 |
} |
74 |
if (*col1 == 0) |
|
9473 | 75 |
return(0); |
8647 | 76 |
|
77 |
for (line2 = keys; *line2 != 0; line2++) { |
|
9473 | 78 |
for (col2 = *line2; *col2 != 0 && *col2 != char2; col2++) |
79 |
continue; |
|
8647 | 80 |
} |
81 |
if (*col2 == 0) |
|
9473 | 82 |
return(0); |
8647 | 83 |
|
84 |
diff = col1 - col2; |
|
85 |
if (diff > 1 || diff < -1) |
|
9473 | 86 |
return(0); |
8647 | 87 |
|
88 |
diff = line1 - line2; |
|
89 |
if (diff > 1 || diff < -1) |
|
9473 | 90 |
return(0); |
8647 | 91 |
return(1); |
92 |
} |
|
93 |
||
94 |
%} |
|
95 |
! ! |
|
96 |
||
608 | 97 |
!String class methodsFor:'documentation'! |
98 |
||
99 |
copyright |
|
100 |
" |
|
101 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
9473 | 102 |
All Rights Reserved |
608 | 103 |
|
104 |
This software is furnished under a license and may be used |
|
105 |
only in accordance with the terms of that license and with the |
|
106 |
inclusion of the above copyright notice. This software may not |
|
107 |
be provided or otherwise made available to, or used by, any |
|
108 |
other person. No title to or ownership of the software is |
|
109 |
hereby transferred. |
|
110 |
" |
|
111 |
! |
|
3 | 112 |
|
608 | 113 |
documentation |
114 |
" |
|
115 |
Strings are ByteArrays storing Characters. |
|
116 |
||
117 |
Strings are kind of kludgy: to allow for easy handling by c-functions, |
|
118 |
there is always one 0-byte added at the end, which is not counted |
|
4800
118dff933bf3
docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
119 |
in the strings size, and is not accessable from the smalltalk level. |
118dff933bf3
docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
120 |
This guarantees, that a smalltalk string can always be passed to a |
118dff933bf3
docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
121 |
C- or a system api function without danger (of course, this does not |
118dff933bf3
docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
122 |
prevent a nonsense contents ...) |
3 | 123 |
|
608 | 124 |
You cannot add any instvars to String, since the the run time system & compiler |
125 |
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
|
126 |
If you really need strings with instVars, you have to create a subclass |
608 | 127 |
of String (the access functions defined here can handle this). |
128 |
A little warning though: not all smalltalk systems allow subclassing String, |
|
129 |
so your program may become unportable if you do so. |
|
1290 | 130 |
|
7895 | 131 |
Strings have an implicit (assumed) encoding of iso8859-1. |
132 |
For strings with other encodings, either keep the encoding separately, |
|
133 |
or use instances of encodedString. |
|
134 |
||
1290 | 135 |
[author:] |
9473 | 136 |
Claus Gittinger |
1310 | 137 |
|
138 |
[see also:] |
|
9473 | 139 |
Text StringCollection TwoByteString JISEncodedString |
140 |
Symbol |
|
608 | 141 |
" |
3 | 142 |
! ! |
143 |
||
1 | 144 |
!String class methodsFor:'instance creation'! |
145 |
||
146 |
basicNew:anInteger |
|
4802 | 147 |
"return a new empty string with anInteger characters. |
148 |
In contrast to other smalltalks, this returns a string filled |
|
149 |
with spaces (instead of a string filled with 0-bytes). |
|
150 |
This makes much more sense, in that a freshly created string |
|
151 |
can be directly used as separator or for formatting." |
|
1 | 152 |
|
153 |
%{ /* NOCONTEXT */ |
|
154 |
||
155 |
OBJ newString; |
|
156 |
REGISTER int len; |
|
157 |
REGISTER unsigned char *cp; |
|
158 |
REGISTER OBJ *op; |
|
159 |
int nInstVars, instsize; |
|
160 |
||
252 | 161 |
if (__isSmallInteger(anInteger)) { |
9473 | 162 |
len = __intVal(anInteger); |
163 |
if (len >= 0) { |
|
164 |
instsize = OHDR_SIZE + len + 1; |
|
165 |
if (self == String) { |
|
166 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
|
167 |
/* |
|
168 |
* the most common case |
|
169 |
*/ |
|
170 |
__qCheckedNew(newString, instsize); |
|
171 |
__InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */ |
|
172 |
__qSTORE(newString, self); |
|
173 |
||
174 |
cp = __stringVal(newString); |
|
2862 | 175 |
|
357 | 176 |
#if defined(memset4) && !defined(NON_ASCII) |
9473 | 177 |
{ |
178 |
/* |
|
179 |
* no sizeof(int) here please - |
|
180 |
* - memset4 (if defined) fills 4-bytes on ALL machines |
|
181 |
*/ |
|
182 |
int l4 = len >> 2; |
|
183 |
||
184 |
if (len & 3) l4++; |
|
185 |
memset4(cp, 0x20202020, l4); |
|
186 |
cp[len] = '\0'; |
|
187 |
} |
|
95 | 188 |
#else |
357 | 189 |
# ifdef FAST_MEMSET |
9473 | 190 |
memset(cp, ' ', len); |
191 |
cp[len] = '\0'; |
|
357 | 192 |
# else |
9473 | 193 |
while (len >= 8) { |
3449
84160615c630
oops - basicNew was bad for subclasses of String.
Claus Gittinger <cg@exept.de>
parents:
3403
diff
changeset
|
194 |
# ifndef NON_ASCII /* i.e. EBCDIC */ |
2954 | 195 |
# ifdef INT64 |
9473 | 196 |
((INT64 *)cp)[0] = 0x2020202020202020L; |
2862 | 197 |
# else |
9473 | 198 |
((int *)cp)[0] = 0x20202020; |
199 |
((int *)cp)[1] = 0x20202020; |
|
2862 | 200 |
# endif |
357 | 201 |
# else |
9473 | 202 |
cp[0] = cp[1] = cp[2] = cp[3] = ' '; |
203 |
cp[4] = cp[5] = cp[6] = cp[7] = ' '; |
|
357 | 204 |
# endif |
9473 | 205 |
cp += 8; |
206 |
len -= 8; |
|
207 |
} |
|
208 |
while (len--) |
|
209 |
*cp++ = ' '; |
|
210 |
*cp = '\0'; |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
211 |
# endif /* not FAST_MEMSET */ |
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
212 |
#endif /* not memset4 */ |
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
213 |
|
9473 | 214 |
RETURN (newString); |
215 |
} |
|
216 |
nInstVars = 0; |
|
217 |
} else { |
|
218 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
|
219 |
instsize += __OBJS2BYTES__(nInstVars); |
|
220 |
} |
|
221 |
||
222 |
__PROTECT_CONTEXT__; |
|
223 |
__qNew(newString, instsize); /* OBJECT ALLOCATION */ |
|
224 |
__UNPROTECT_CONTEXT__; |
|
225 |
||
226 |
if (newString == nil) goto fail; |
|
227 |
||
228 |
__InstPtr(newString)->o_class = self; |
|
229 |
__qSTORE(newString, self); |
|
230 |
||
231 |
cp = __stringVal(newString); |
|
232 |
if (nInstVars) { |
|
233 |
cp += __OBJS2BYTES__(nInstVars); |
|
234 |
||
235 |
/* |
|
236 |
* nil-out instvars |
|
237 |
*/ |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
238 |
#if defined(memset4) |
9473 | 239 |
memset4(__InstPtr(newString)->i_instvars, nil, nInstVars); |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
240 |
#else |
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
241 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
9473 | 242 |
/* |
243 |
* knowing that nil is 0 |
|
244 |
*/ |
|
245 |
memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars)); |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
246 |
# else |
9473 | 247 |
op = __InstPtr(newString)->i_instvars; |
248 |
do { |
|
249 |
*op++ = nil; |
|
250 |
} while (--nInstVars); |
|
357 | 251 |
# endif |
95 | 252 |
#endif |
9473 | 253 |
} |
254 |
||
255 |
/* |
|
256 |
* fill with spaces |
|
257 |
*/ |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
258 |
#ifdef FAST_MEMSET |
9473 | 259 |
memset(cp, ' ', len); |
260 |
*(cp + len) = '\0'; |
|
1 | 261 |
#else |
9473 | 262 |
while (len >= 8) { |
357 | 263 |
# ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
2954 | 264 |
# ifdef INT64 |
9473 | 265 |
((INT64 *)cp)[0] = 0x2020202020202020L; |
2862 | 266 |
# else |
9473 | 267 |
((int *)cp)[0] = 0x20202020; |
268 |
((int *)cp)[1] = 0x20202020; |
|
2862 | 269 |
# endif |
357 | 270 |
# else |
9473 | 271 |
cp[0] = cp[1] = cp[2] = cp[3] = ' '; |
272 |
cp[4] = cp[5] = cp[6] = cp[7] = ' '; |
|
357 | 273 |
# endif |
9473 | 274 |
cp += 8; |
275 |
len -= 8; |
|
276 |
} |
|
277 |
while (len--) |
|
278 |
*cp++ = ' '; |
|
279 |
*cp = '\0'; |
|
1 | 280 |
#endif |
9473 | 281 |
RETURN (newString); |
282 |
} |
|
1 | 283 |
} |
95 | 284 |
fail: ;; |
1019 | 285 |
%}. |
95 | 286 |
" |
287 |
invalid argument, or out-of-memory: |
|
288 |
use error handling in superclass |
|
289 |
" |
|
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
290 |
(anInteger < 0) ifTrue:[ |
9473 | 291 |
" |
292 |
the argument is negative, |
|
293 |
" |
|
294 |
self error:'bad (negative) argument to new:'. |
|
295 |
^ nil |
|
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
296 |
]. |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
297 |
|
5407 | 298 |
^ (super basicNew:anInteger+1) atAllPut:(Character space) |
1 | 299 |
! |
300 |
||
608 | 301 |
new:n |
4802 | 302 |
"return a new empty string with anInteger characters. |
303 |
In contrast to other smalltalks, this returns a string filled |
|
304 |
with spaces (instead of a string filled with 0-bytes). |
|
305 |
This makes much more sense, in that a freshly created string |
|
306 |
can be directly used as separator or for formatting." |
|
307 |
||
608 | 308 |
^ self basicNew:n |
347 | 309 |
! |
310 |
||
6599
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
311 |
readFrom:aStreamOrString onError:exceptionBlock |
347 | 312 |
"read & return the next String from the (character-)stream aStream; |
313 |
skipping all whitespace first; return the value of exceptionBlock, |
|
8898 | 314 |
if no string can be read. The sequence of characters as read from the |
347 | 315 |
stream must be one as stored via storeOn: or storeString." |
316 |
||
317 |
" |
|
318 |
this method is not to be inherited |
|
319 |
(i.e. not ok for subclasses; Symbol, for example) |
|
320 |
" |
|
321 |
self ~~ String ifTrue:[ |
|
10352 | 322 |
^ super readFrom:aStreamOrString onError:exceptionBlock |
347 | 323 |
]. |
9426 | 324 |
^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
347 | 325 |
|
326 |
" |
|
8898 | 327 |
String readFrom:('''hello world''' readStream) |
328 |
String readFrom:('''hello '''' world''' readStream) |
|
347 | 329 |
String readFrom:('1 ''hello'' ' readStream) |
8898 | 330 |
String readFrom:('1 ''hello'' ' readStream) onError:['foobar'] |
3376 | 331 |
" |
332 |
||
9426 | 333 |
"Modified: / 05-07-2006 / 16:41:29 / cg" |
9473 | 334 |
"Modified: / 07-08-2006 / 15:03:09 / fm" |
608 | 335 |
! |
336 |
||
7684 | 337 |
uninitializedNew:anInteger |
338 |
"return a new string with anInteger characters but undefined contents. |
|
339 |
Use this, if the string is filled anyway with new data, for example, if |
|
340 |
used as a stream buffer." |
|
341 |
||
342 |
%{ /* NOCONTEXT */ |
|
343 |
||
344 |
OBJ newString; |
|
345 |
REGISTER int len; |
|
346 |
REGISTER unsigned char *cp; |
|
347 |
REGISTER OBJ *op; |
|
348 |
int nInstVars, instsize; |
|
349 |
||
350 |
if (__isSmallInteger(anInteger)) { |
|
9473 | 351 |
len = __intVal(anInteger); |
352 |
if (len >= 0) { |
|
353 |
instsize = OHDR_SIZE + len + 1; |
|
354 |
if (self == String) { |
|
355 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
|
356 |
/* |
|
357 |
* the most common case |
|
358 |
*/ |
|
359 |
__qCheckedNew(newString, instsize); |
|
360 |
__InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */ |
|
361 |
__qSTORE(newString, self); |
|
362 |
||
363 |
cp = __stringVal(newString); |
|
364 |
cp[len] = '\0'; |
|
365 |
RETURN (newString); |
|
366 |
} |
|
367 |
nInstVars = 0; |
|
368 |
} else { |
|
369 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
|
370 |
instsize += __OBJS2BYTES__(nInstVars); |
|
371 |
} |
|
372 |
||
373 |
__PROTECT_CONTEXT__; |
|
374 |
__qNew(newString, instsize); /* OBJECT ALLOCATION */ |
|
375 |
__UNPROTECT_CONTEXT__; |
|
376 |
||
377 |
if (newString == nil) goto fail; |
|
378 |
||
379 |
__InstPtr(newString)->o_class = self; |
|
380 |
__qSTORE(newString, self); |
|
381 |
||
382 |
if (nInstVars) { |
|
383 |
/* |
|
384 |
* nil-out instvars |
|
385 |
*/ |
|
7684 | 386 |
#if defined(memset4) |
9473 | 387 |
memset4(__InstPtr(newString)->i_instvars, nil, nInstVars); |
7684 | 388 |
#else |
389 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
|
9473 | 390 |
/* |
391 |
* knowing that nil is 0 |
|
392 |
*/ |
|
393 |
memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars)); |
|
7684 | 394 |
# else |
9473 | 395 |
op = __InstPtr(newString)->i_instvars; |
396 |
do { |
|
397 |
*op++ = nil; |
|
398 |
} while (--nInstVars); |
|
7684 | 399 |
# endif |
400 |
#endif |
|
9473 | 401 |
cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars); |
402 |
} else { |
|
403 |
cp = __stringVal(newString); |
|
404 |
} |
|
405 |
||
406 |
*(cp + len) = '\0'; |
|
407 |
RETURN (newString); |
|
408 |
} |
|
7684 | 409 |
} |
410 |
fail: ;; |
|
411 |
%}. |
|
412 |
" |
|
413 |
invalid argument, or out-of-memory: |
|
414 |
use error handling in superclass |
|
415 |
" |
|
416 |
(anInteger < 0) ifTrue:[ |
|
9473 | 417 |
" |
418 |
the argument is negative, |
|
419 |
" |
|
420 |
self error:'bad (negative) argument to new:'. |
|
421 |
^ nil |
|
7684 | 422 |
]. |
608 | 423 |
|
424 |
^ self basicNew:anInteger |
|
7684 | 425 |
|
426 |
" |
|
427 |
String uninitializedNew:100 |
|
428 |
" |
|
608 | 429 |
! ! |
430 |
||
8438
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
431 |
!String class methodsFor:'Compatibility-Dolphin'! |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
432 |
|
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
433 |
lineDelimiter |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
434 |
"Dolphin compatibility: answer CR LF" |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
435 |
|
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
436 |
^ self crlf |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
437 |
! ! |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
438 |
|
7302 | 439 |
!String class methodsFor:'Compatibility-Squeak'! |
4981 | 440 |
|
441 |
cr |
|
4994 | 442 |
"return a string consisting of the cr-Character" |
4993 | 443 |
|
14330 | 444 |
CR isNil ifTrue:[ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
445 |
CR := String with:Character return |
14330 | 446 |
]. |
447 |
^ CR |
|
4993 | 448 |
|
4994 | 449 |
"Modified: / 13.11.1999 / 13:53:36 / cg" |
7282 | 450 |
! |
451 |
||
452 |
crlf |
|
453 |
"return a string consisting of the cr-lf Characters" |
|
454 |
||
455 |
CRLF isNil ifTrue:[ |
|
9473 | 456 |
CRLF := String |
457 |
with:Character return |
|
458 |
with:Character linefeed |
|
7282 | 459 |
]. |
460 |
^ CRLF |
|
461 |
! |
|
462 |
||
463 |
lf |
|
464 |
"return a string consisting of the lf Character" |
|
465 |
||
466 |
LF isNil ifTrue:[ |
|
9473 | 467 |
LF := String with:Character linefeed |
7282 | 468 |
]. |
469 |
^ LF |
|
11856 | 470 |
! |
471 |
||
12344
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
472 |
stringHash:aString initialHash:speciesHash |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
473 |
"for squeak compatibility only; this is NOT the same hash as my instances use" |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
474 |
|
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
475 |
| stringSize hash low | |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
476 |
|
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
477 |
stringSize := aString size. |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
478 |
hash := speciesHash bitAnd: 16rFFFFFFF. |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
479 |
1 to: stringSize do: [:pos | |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
480 |
hash := hash + (aString at: pos) asInteger. |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
481 |
"Begin hashMultiply" |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
482 |
low := hash bitAnd: 16383. |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
483 |
hash := (16r260D * low + ((16r260D * (hash bitShift: -14) + (16r0065 * low) bitAnd: 16383) * 16384)) bitAnd: 16r0FFFFFFF. |
12344
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
484 |
]. |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
485 |
^ hash. |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
486 |
! |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
487 |
|
11856 | 488 |
tab |
489 |
"return a string consisting of the tab-Character" |
|
490 |
||
14330 | 491 |
TAB isNil ifTrue:[ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
492 |
TAB := String with:Character tab |
14330 | 493 |
]. |
494 |
^ TAB |
|
4981 | 495 |
! ! |
496 |
||
13182 | 497 |
|
16253 | 498 |
|
499 |
||
608 | 500 |
!String class methodsFor:'queries'! |
501 |
||
2680
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
502 |
defaultPlatformClass |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
503 |
"dummy for ST-80 compatibility" |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
504 |
|
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
505 |
^ self |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
506 |
|
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
507 |
"Created: 6.6.1997 / 18:25:56 / cg" |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
508 |
! |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
509 |
|
608 | 510 |
isBuiltInClass |
1264 | 511 |
"return true if this class is known by the run-time-system. |
512 |
Here, true is returned for myself, false for subclasses." |
|
608 | 513 |
|
514 |
^ self == String |
|
1264 | 515 |
|
516 |
"Modified: 23.4.1996 / 16:00:38 / cg" |
|
1 | 517 |
! ! |
518 |
||
14384
1082868a753c
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14353
diff
changeset
|
519 |
|
16253 | 520 |
|
521 |
||
16457 | 522 |
|
523 |
||
9182 | 524 |
!String methodsFor:'Compatibility-VW5.4'! |
525 |
||
526 |
asGUID |
|
13204 | 527 |
"return self as a GUID (or UUID if not present)" |
528 |
||
529 |
GUID notNil ifTrue:[ ^ GUID fromString:self ]. |
|
9182 | 530 |
^ self asUUID |
531 |
||
532 |
" |
|
533 |
'{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' asGUID |
|
534 |
" |
|
13204 | 535 |
|
536 |
"Modified: / 12-01-2011 / 12:33:58 / cg" |
|
9182 | 537 |
! ! |
538 |
||
1 | 539 |
!String methodsFor:'accessing'! |
540 |
||
329 | 541 |
at:index |
542 |
"return the character at position index, an Integer. |
|
345 | 543 |
Reimplemented here to avoid the additional at:->basicAt: send |
544 |
(which we can do here, since at: is obviously not redefined in a subclass). |
|
329 | 545 |
This method is the same as at:." |
546 |
||
547 |
%{ /* NOCONTEXT */ |
|
548 |
||
549 |
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
|
550 |
REGISTER OBJ slf, cls; |
329 | 551 |
|
552 |
if (__isSmallInteger(index)) { |
|
9473 | 553 |
slf = self; |
554 |
cls = __qClass(slf); |
|
555 |
indx = __intVal(index) - 1; |
|
556 |
if (cls != String) { |
|
557 |
if (indx < 0) goto badIndex; |
|
558 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
559 |
} |
|
560 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
561 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
|
562 |
} |
|
329 | 563 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
564 |
badIndex: ; |
329 | 565 |
%}. |
5407 | 566 |
^ self basicAt:index |
1 | 567 |
! |
568 |
||
329 | 569 |
at:index put:aCharacter |
570 |
"store the argument, aCharacter at position index, an Integer. |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
571 |
Return aCharacter (sigh). |
345 | 572 |
Reimplemented here to avoid the additional at:put:->basicAt:put: send |
573 |
(but only for Strings, since subclasses may redefine basicAt:put:). |
|
329 | 574 |
This method is the same as basicAt:put:." |
575 |
||
576 |
%{ /* NOCONTEXT */ |
|
577 |
||
578 |
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
|
579 |
REGISTER OBJ slf; |
329 | 580 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
581 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
582 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
583 |
if (__isString(slf)) { |
9473 | 584 |
if (__isCharacter(aCharacter)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
585 |
value = __intVal(__characterVal(aCharacter)); |
9473 | 586 |
if (((unsigned)value <= 0xFF) |
587 |
&& __isSmallInteger(index)) { |
|
588 |
indx = __intVal(index) - 1; |
|
589 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
590 |
__stringVal(slf)[indx] = value; |
|
591 |
RETURN ( aCharacter ); |
|
592 |
} |
|
593 |
} |
|
594 |
} |
|
329 | 595 |
} |
596 |
%}. |
|
5407 | 597 |
^ self basicAt:index put:aCharacter |
329 | 598 |
! |
599 |
||
608 | 600 |
basicAt:index |
601 |
"return the character at position index, an Integer |
|
602 |
- reimplemented here since we return characters" |
|
603 |
||
604 |
%{ /* NOCONTEXT */ |
|
605 |
||
606 |
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
|
607 |
REGISTER OBJ slf, cls; |
608 | 608 |
|
609 |
if (__isSmallInteger(index)) { |
|
9473 | 610 |
slf = self; |
611 |
cls = __qClass(slf); |
|
612 |
indx = __intVal(index) - 1; |
|
613 |
if (cls != String) { |
|
614 |
if (indx < 0) goto badIndex; |
|
615 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
616 |
} |
|
617 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
618 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
|
619 |
} |
|
608 | 620 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
621 |
badIndex: ; |
608 | 622 |
%}. |
3451 | 623 |
index isInteger ifFalse:[ |
9473 | 624 |
^ self indexNotInteger:index |
3451 | 625 |
]. |
5407 | 626 |
index == super basicSize ifTrue:[ |
9473 | 627 |
^ self subscriptBoundsError:index |
5407 | 628 |
]. |
629 |
^ Character value:(super basicAt:index) |
|
608 | 630 |
! |
631 |
||
1 | 632 |
basicAt:index put:aCharacter |
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
633 |
"store the argument, aCharacter at position index, an Integer. |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
634 |
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
|
635 |
- reimplemented here since we store characters" |
1 | 636 |
|
637 |
%{ /* NOCONTEXT */ |
|
638 |
||
639 |
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
|
640 |
REGISTER OBJ slf; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
641 |
REGISTER OBJ cls; |
1 | 642 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
643 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
644 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
645 |
if (__isCharacter(aCharacter)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
646 |
value = __intVal(__characterVal(aCharacter)); |
9473 | 647 |
if (((unsigned)value <= 0xFF) |
648 |
&& __isSmallInteger(index)) { |
|
649 |
cls = __qClass(slf); |
|
650 |
indx = __intVal(index) - 1; |
|
651 |
if (cls != String) { |
|
652 |
if (indx < 0) goto badIndex; |
|
653 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
654 |
} |
|
655 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
656 |
__stringVal(slf)[indx] = value; |
|
657 |
RETURN ( aCharacter ); |
|
658 |
} |
|
659 |
} |
|
1 | 660 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
661 |
badIndex: ; |
159 | 662 |
%}. |
1 | 663 |
(aCharacter isMemberOf:Character) ifFalse:[ |
9473 | 664 |
" |
665 |
tried to store something which is not a character |
|
666 |
" |
|
667 |
^ self elementNotCharacter |
|
299 | 668 |
]. |
8093
8ca1e24688d8
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
669 |
(aCharacter codePoint between:1 and:255) ifFalse:[ |
9473 | 670 |
" |
671 |
tried to store a multibyte character |
|
672 |
" |
|
673 |
^ self elementBoundsError:aCharacter |
|
299 | 674 |
]. |
675 |
" |
|
676 |
invalid index |
|
677 |
" |
|
3451 | 678 |
index isInteger ifFalse:[ |
9473 | 679 |
^ self indexNotInteger:index |
3451 | 680 |
]. |
5407 | 681 |
index == super basicSize ifTrue:[ |
9473 | 682 |
^ self subscriptBoundsError:index |
5407 | 683 |
]. |
8093
8ca1e24688d8
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
684 |
super basicAt:index put:aCharacter codePoint. |
8898 | 685 |
^ aCharacter |
12716 | 686 |
! |
687 |
||
688 |
first |
|
689 |
"return the first character. |
|
690 |
Reimplemented here for speed" |
|
691 |
||
692 |
%{ /* NOCONTEXT */ |
|
693 |
||
694 |
REGISTER int indx; |
|
695 |
REGISTER OBJ slf, cls; |
|
696 |
||
697 |
slf = self; |
|
698 |
cls = __qClass(slf); |
|
699 |
indx = 0; |
|
700 |
if (cls != String) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
701 |
if (indx < 0) goto badIndex; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
702 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
12716 | 703 |
} |
704 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
705 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
12716 | 706 |
} |
707 |
badIndex: ; |
|
708 |
%}. |
|
709 |
^ super first |
|
710 |
||
711 |
" |
|
712 |
'abc' first |
|
713 |
'' first |
|
714 |
" |
|
2 | 715 |
! ! |
716 |
||
13182 | 717 |
|
53 | 718 |
!String methodsFor:'character searching'! |
1 | 719 |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
720 |
identityIndexOf:aCharacter |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
721 |
"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
|
722 |
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
|
723 |
|
13920 | 724 |
^ self indexOf:aCharacter |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
725 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
726 |
" |
8898 | 727 |
'hello world' identityIndexOf:(Character space) |
728 |
'hello world' identityIndexOf:$d |
|
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
729 |
'hello world' identityIndexOf:1 |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
730 |
#[0 0 1 0 0] asString identityIndexOf:(Character value:1) |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
731 |
#[0 0 1 0 0] asString identityIndexOf:(Character value:0) |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
732 |
" |
13920 | 733 |
|
734 |
"Modified: / 10-01-2012 / 17:07:12 / cg" |
|
1 | 735 |
! |
736 |
||
13923
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
737 |
identityIndexOf:aCharacter startingAt:index |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
738 |
"return the index of the first occurrences of the argument, aCharacter |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
739 |
in the receiver or 0 if not found - reimplemented here for speed." |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
740 |
|
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
741 |
^ self indexOf:aCharacter startingAt:index |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
742 |
|
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
743 |
" |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
744 |
'hello world' identityIndexOf:(Character space) |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
745 |
'hello world' identityIndexOf:$d |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
746 |
'hello world' identityIndexOf:1 |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
747 |
#[0 0 1 0 0] asString identityIndexOf:(Character value:1) |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
748 |
#[0 0 1 0 0] asString identityIndexOf:(Character value:0) |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
749 |
" |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
750 |
|
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
751 |
"Created: / 10-01-2012 / 17:10:54 / cg" |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
752 |
! |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
753 |
|
10 | 754 |
includesAny:aCollection |
755 |
"return true, if the receiver includes any of the characters in the |
|
53 | 756 |
argument, aCollection. |
757 |
- redefined for speed if the argument is a String." |
|
10 | 758 |
|
759 |
%{ /* NOCONTEXT */ |
|
760 |
||
761 |
REGISTER unsigned char *cp; |
|
762 |
REGISTER unsigned char *matchP; |
|
53 | 763 |
OBJ cls; |
10 | 764 |
|
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
765 |
if (__isStringLike(aCollection)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
766 |
matchP = __stringVal(aCollection); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
767 |
cp = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
768 |
if ((cls = __qClass(self)) != String) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
769 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
770 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
771 |
switch (__stringSize(aCollection)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
772 |
case 3: |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
773 |
/* three character search */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
774 |
if (strchr(cp, matchP[2])) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
775 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
776 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
777 |
/* fall into */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
778 |
case 2: |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
779 |
/* two character search */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
780 |
if (strchr(cp, matchP[1])) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
781 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
782 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
783 |
/* fall into */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
784 |
case 1: |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
785 |
/* single character search */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
786 |
if (strchr(cp, matchP[0])) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
787 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
788 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
789 |
/* fall into */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
790 |
case 0: |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
791 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
792 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
793 |
while (*cp) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
794 |
if (strchr(matchP, *cp)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
795 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
796 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
797 |
cp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
798 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
799 |
RETURN ( false ); |
10 | 800 |
} |
5407 | 801 |
%}. |
10 | 802 |
^ super includesAny:aCollection |
95 | 803 |
|
804 |
" |
|
8898 | 805 |
'hello world' includesAny:'abcd' |
806 |
'hello world' includesAny:'xyz' |
|
807 |
'hello world' includesAny:'xz' |
|
808 |
'hello world' includesAny:'od' |
|
809 |
'hello world' includesAny:'xd' |
|
810 |
'hello world' includesAny:'dx' |
|
811 |
'hello world' includesAny:(Array with:$a with:$b with:$d) |
|
812 |
'hello world' includesAny:(Array with:$x with:$y) |
|
813 |
'hello world' includesAny:(Array with:1 with:2) |
|
95 | 814 |
" |
10 | 815 |
! |
816 |
||
1 | 817 |
indexOf:aCharacter startingAt:start |
818 |
"return the index of the first occurrence of the argument, aCharacter |
|
819 |
in myself starting at start, anInteger or 0 if not found; |
|
820 |
- reimplemented here for speed" |
|
821 |
||
822 |
%{ /* NOCONTEXT */ |
|
13920 | 823 |
#undef __UNROLL_LOOPS__ |
824 |
#undef FAST_MEMCHR |
|
13922
b693795611ea
changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13921
diff
changeset
|
825 |
#define V2 |
13920 | 826 |
|
1 | 827 |
REGISTER unsigned char *cp; |
8923 | 828 |
#ifdef FAST_MEMCHR |
829 |
REGISTER unsigned char *ncp; |
|
8925 | 830 |
#endif |
8913 | 831 |
REGISTER INT index; |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
832 |
REGISTER unsigned byteValue; |
8924 | 833 |
int last; |
53 | 834 |
OBJ cls; |
1 | 835 |
|
252 | 836 |
if (__isSmallInteger(start)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
837 |
index = __intVal(start); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
838 |
if (index > 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
839 |
if (__isCharacter(aCharacter)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
840 |
byteValue = __intVal(__characterVal(aCharacter)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
841 |
if (byteValue <= 0xFF) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
842 |
last = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
843 |
cp = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
844 |
if ((cls = __qClass(self)) != String) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
845 |
int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
846 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
847 |
cp += numInstBytes; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
848 |
last -= numInstBytes; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
849 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
850 |
if (index <= last) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
851 |
#ifdef FAST_MEMCHR |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
852 |
ncp = (unsigned char *) memchr(cp+index-1, byteValue, last+1-index); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
853 |
if (ncp) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
854 |
RETURN ( __mkSmallInteger(ncp - cp + 1) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
855 |
} |
1 | 856 |
#else |
8928 | 857 |
# ifdef __UNROLL_LOOPS__ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
858 |
{ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
859 |
int last3 = last-3; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
860 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
861 |
for (; index <= last3; index += 4) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
862 |
if (cp[index-1] == byteValue) { RETURN ( __mkSmallInteger(index) ); } |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
863 |
if (cp[index-1+1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); } |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
864 |
if (cp[index-1+2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); } |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
865 |
if (cp[index-1+3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); } |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
866 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
867 |
} |
13920 | 868 |
# endif |
869 |
# ifdef V1 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
870 |
for (; index <= last; index++) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
871 |
if (cp[index-1] == byteValue) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
872 |
RETURN ( __mkSmallInteger(index) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
873 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
874 |
} |
8928 | 875 |
# endif |
13922
b693795611ea
changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13921
diff
changeset
|
876 |
# ifdef V2 |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
877 |
{ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
878 |
// see bit twiddling hacks |
13920 | 879 |
# define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL) |
880 |
# define hasByteM(v,m) hasZeroByte( (v) ^ m) |
|
881 |
||
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
882 |
// the following loop checks four bytes at once |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
883 |
if (((index-1) & 0x3) == 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
884 |
int last4 = last-4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
885 |
int m = (~0UL/255 * (byteValue)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
886 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
887 |
while (index <= last4) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
888 |
unsigned int v = *(unsigned int *)(cp+index-1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
889 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
890 |
if (hasByteM(v,m)) break; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
891 |
index += 4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
892 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
893 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
894 |
while (index <= last) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
895 |
if (cp[index-1] == byteValue) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
896 |
RETURN ( __mkSmallInteger(index) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
897 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
898 |
index++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
899 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
900 |
} |
13920 | 901 |
# endif |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
902 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
903 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
904 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
905 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
906 |
RETURN ( __mkSmallInteger(0) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
907 |
} |
1 | 908 |
} |
13922
b693795611ea
changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13921
diff
changeset
|
909 |
#undef V2 |
370 | 910 |
%}. |
1 | 911 |
^ super indexOf:aCharacter startingAt:start |
53 | 912 |
|
95 | 913 |
" |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
914 |
'hello world' indexOf:$0 startingAt:1 |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
915 |
'hello world' indexOf:$l startingAt:1 |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
916 |
'hello world' indexOf:$l startingAt:5 |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
917 |
'hello world' indexOf:$d startingAt:5 |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
918 |
#[0 0 1 0 0] asString indexOf:(Character value:1) startingAt:1 |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
919 |
#[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3 |
13920 | 920 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
921 |
'1234567890123456a' indexOf:$a |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
922 |
'1234567890123456a' indexOf:$b |
13920 | 923 |
|
924 |
|s| |
|
925 |
s := '12345678901234b'. |
|
926 |
self assert:(s indexOf:$x) == 0. |
|
927 |
self assert:(s indexOf:$1) == 1. |
|
928 |
self assert:(s indexOf:$2) == 2. |
|
929 |
self assert:(s indexOf:$3) == 3. |
|
930 |
self assert:(s indexOf:$4) == 4. |
|
931 |
self assert:(s indexOf:$5) == 5. |
|
932 |
self assert:(s indexOf:$0) == 10. |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
933 |
self assert:(s indexOf:$b) == 15. |
13920 | 934 |
|
935 |
|s| |
|
936 |
s := ''. |
|
937 |
self assert:(s indexOf:$1) == 0. |
|
938 |
s := '1'. |
|
939 |
self assert:(s indexOf:$1) == 1. |
|
940 |
self assert:(s indexOf:$2) == 0. |
|
941 |
s := '12'. |
|
942 |
self assert:(s indexOf:$1) == 1. |
|
943 |
self assert:(s indexOf:$2) == 2. |
|
944 |
self assert:(s indexOf:$3) == 0. |
|
945 |
s := '123'. |
|
946 |
self assert:(s indexOf:$1) == 1. |
|
947 |
self assert:(s indexOf:$2) == 2. |
|
948 |
self assert:(s indexOf:$3) == 3. |
|
949 |
self assert:(s indexOf:$4) == 0. |
|
950 |
s := '1234'. |
|
951 |
self assert:(s indexOf:$1) == 1. |
|
952 |
self assert:(s indexOf:$2) == 2. |
|
953 |
self assert:(s indexOf:$3) == 3. |
|
954 |
self assert:(s indexOf:$4) == 4. |
|
955 |
self assert:(s indexOf:$5) == 0. |
|
956 |
s := '12345'. |
|
957 |
self assert:(s indexOf:$1) == 1. |
|
958 |
self assert:(s indexOf:$2) == 2. |
|
959 |
self assert:(s indexOf:$3) == 3. |
|
960 |
self assert:(s indexOf:$4) == 4. |
|
961 |
self assert:(s indexOf:$5) == 5. |
|
962 |
self assert:(s indexOf:$6) == 0. |
|
963 |
s := '123456'. |
|
964 |
self assert:(s indexOf:$1) == 1. |
|
965 |
self assert:(s indexOf:$2) == 2. |
|
966 |
self assert:(s indexOf:$3) == 3. |
|
967 |
self assert:(s indexOf:$4) == 4. |
|
968 |
self assert:(s indexOf:$5) == 5. |
|
969 |
self assert:(s indexOf:$6) == 6. |
|
970 |
self assert:(s indexOf:$7) == 0. |
|
971 |
s := '1234567'. |
|
972 |
self assert:(s indexOf:$1) == 1. |
|
973 |
self assert:(s indexOf:$2) == 2. |
|
974 |
self assert:(s indexOf:$3) == 3. |
|
975 |
self assert:(s indexOf:$4) == 4. |
|
976 |
self assert:(s indexOf:$5) == 5. |
|
977 |
self assert:(s indexOf:$6) == 6. |
|
978 |
self assert:(s indexOf:$7) == 7. |
|
979 |
self assert:(s indexOf:$8) == 0. |
|
980 |
s := '12345678'. |
|
981 |
self assert:(s indexOf:$1) == 1. |
|
982 |
self assert:(s indexOf:$2) == 2. |
|
983 |
self assert:(s indexOf:$3) == 3. |
|
984 |
self assert:(s indexOf:$4) == 4. |
|
985 |
self assert:(s indexOf:$5) == 5. |
|
986 |
self assert:(s indexOf:$6) == 6. |
|
987 |
self assert:(s indexOf:$7) == 7. |
|
988 |
self assert:(s indexOf:$8) == 8. |
|
989 |
self assert:(s indexOf:$9) == 0. |
|
990 |
s := '123456789'. |
|
991 |
self assert:(s indexOf:$1) == 1. |
|
992 |
self assert:(s indexOf:$2) == 2. |
|
993 |
self assert:(s indexOf:$3) == 3. |
|
994 |
self assert:(s indexOf:$4) == 4. |
|
995 |
self assert:(s indexOf:$5) == 5. |
|
996 |
self assert:(s indexOf:$6) == 6. |
|
997 |
self assert:(s indexOf:$7) == 7. |
|
998 |
self assert:(s indexOf:$8) == 8. |
|
999 |
self assert:(s indexOf:$9) == 9. |
|
1000 |
||
1001 |
self assert:(s indexOf:$0) == 0. |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1002 |
self assert:(s indexOf:$b) == 0. |
13920 | 1003 |
|
1004 |
|s| |
|
1005 |
s := String new:1024. |
|
1006 |
s atAllPut:$a. |
|
1007 |
s at:512 put:(Character space). |
|
1008 |
Time millisecondsToRun:[ |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1009 |
1000000 timesRepeat:[ s indexOf:(Character space) ] |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1010 |
] |
13920 | 1011 |
|
1012 |
timing (ms): |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1013 |
v1: 1763 normal |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1014 |
2340 +unroll |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1015 |
3308 memsrch !! |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1016 |
v2: 1045 |
95 | 1017 |
" |
13920 | 1018 |
|
13922
b693795611ea
changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13921
diff
changeset
|
1019 |
"Modified: / 10-01-2012 / 17:09:34 / cg" |
1 | 1020 |
! |
1021 |
||
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1022 |
indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1023 |
"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
|
1024 |
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
|
1025 |
- 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
|
1026 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1027 |
%{ /* NOCONTEXT */ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1028 |
|
13116
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1029 |
unsigned char *ccp; |
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1030 |
unsigned char *cp; |
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1031 |
INT index; |
2894 | 1032 |
unsigned char *matchP; |
8006 | 1033 |
unsigned char c, min, max; |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1034 |
int len; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1035 |
OBJ cls; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1036 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1037 |
if (__isSmallInteger(start) |
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
1038 |
&& __isStringLike(aCollectionOfCharacters)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1039 |
matchP = __stringVal(aCollectionOfCharacters); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1040 |
index = __intVal(start); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1041 |
if (index > 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1042 |
cp = __stringVal(self) + index - 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1043 |
if ((cls = __qClass(self)) != String) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1044 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1045 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1046 |
len = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1047 |
if (index <= len) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1048 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1049 |
if (matchP[0] == 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1050 |
/* matchSet is empty */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1051 |
RETURN ( __mkSmallInteger(0) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1052 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1053 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1054 |
if (matchP[1] == 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1055 |
/* only a single character match */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1056 |
unsigned char m = matchP[0]; |
13116
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1057 |
|
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1058 |
#ifdef FAST_MEMCHR |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1059 |
ccp = (unsigned char *) memchr(cp, m, len+1-index); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1060 |
if (ccp) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1061 |
RETURN ( __mkSmallInteger((ccp - cp) + index + 1) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1062 |
} |
13116
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1063 |
#else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1064 |
while (c = *cp++) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1065 |
if (c == m) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1066 |
RETURN ( __mkSmallInteger(index) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1067 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1068 |
index++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1069 |
} |
13116
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1070 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1071 |
RETURN ( __mkSmallInteger(0) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1072 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1073 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1074 |
if (matchP[2] == 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1075 |
/* two character matches */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1076 |
unsigned char m1 = matchP[0]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1077 |
unsigned char m2 = matchP[1]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1078 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1079 |
while (c = *cp++) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1080 |
if ((c == m1) || (c == m2)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1081 |
RETURN ( __mkSmallInteger(index) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1082 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1083 |
index++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1084 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1085 |
RETURN ( __mkSmallInteger(0) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1086 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1087 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1088 |
min = max = matchP[0]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1089 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1090 |
for (ccp = matchP+1; *ccp ; ccp++) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1091 |
unsigned char c = *ccp; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1092 |
if (c < min) min = c; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1093 |
else if (c > max) max = c; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1094 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1095 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1096 |
while (c = *cp++) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1097 |
if ((c >= min) && (c <= max)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1098 |
for (ccp = matchP; *ccp ; ccp++) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1099 |
if (*ccp == c) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1100 |
RETURN ( __mkSmallInteger(index) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1101 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1102 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1103 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1104 |
index++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1105 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1106 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1107 |
RETURN ( __mkSmallInteger(0) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1108 |
} |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1109 |
} |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1110 |
%}. |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1111 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1112 |
"/ 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
|
1113 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1114 |
^ super indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1115 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1116 |
" |
8898 | 1117 |
'hello world' indexOfAny:'eoa' startingAt:1 |
1118 |
'hello world' indexOfAny:'eoa' startingAt:6 |
|
1119 |
'hello world' indexOfAny:'AOE' startingAt:1 |
|
1120 |
'hello world' indexOfAny:'o' startingAt:6 |
|
1121 |
'hello world' indexOfAny:'o' startingAt:6 |
|
14968 | 1122 |
'hello world§' indexOfAny:'#§$' startingAt:6 |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1123 |
" |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1124 |
! |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1125 |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1126 |
indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1127 |
"return the index of the next control character; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1128 |
that is a character with asciiValue < 32. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1129 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1130 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1131 |
%{ /* NOCONTEXT */ |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1132 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1133 |
#ifndef NON_ASCII /* i.e. not EBCDIC ;-) */ |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1134 |
REGISTER unsigned char *cp; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1135 |
REGISTER unsigned char c; |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
1136 |
REGISTER unsigned char *cpEnd; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1137 |
int len, index; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1138 |
OBJ cls; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1139 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1140 |
index = __intVal(start); |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1141 |
if (index <= 0) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1142 |
index = 1; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1143 |
} |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1144 |
len = __stringSize(self); |
15044 | 1145 |
cp = __stringVal(self); |
1146 |
if ((cls = __qClass(self)) != String) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1147 |
int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1148 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1149 |
cp += numInstBytes; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1150 |
len -= numInstBytes; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1151 |
} |
15044 | 1152 |
while (index <= len) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1153 |
REGISTER unsigned char c; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1154 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1155 |
c = cp[index - 1]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1156 |
if (c < ' ') { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1157 |
RETURN ( __mkSmallInteger(index) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1158 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1159 |
index++; |
15044 | 1160 |
} |
1161 |
RETURN ( __mkSmallInteger(0) ); |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1162 |
#endif |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1163 |
%}. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1164 |
^ super indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1165 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1166 |
" |
8898 | 1167 |
'hello world' indexOfControlCharacterStartingAt:1 |
1168 |
'hello world\foo' withCRs indexOfControlCharacterStartingAt:1 |
|
1169 |
'1\' withCRs indexOfControlCharacterStartingAt:1 |
|
1170 |
'1\' withCRs indexOfControlCharacterStartingAt:2 |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1171 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1172 |
! |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1173 |
|
3403 | 1174 |
indexOfNonSeparatorStartingAt:start |
1175 |
"return the index of the next non-whiteSpace character" |
|
1176 |
||
1177 |
%{ /* NOCONTEXT */ |
|
1178 |
||
1179 |
REGISTER unsigned char *cp; |
|
1180 |
REGISTER unsigned char c; |
|
1181 |
int len, index; |
|
1182 |
OBJ cls; |
|
1183 |
||
1184 |
index = __intVal(start); |
|
1185 |
if (index <= 0) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1186 |
index = 1; |
3403 | 1187 |
} |
1188 |
len = __stringSize(self); |
|
15044 | 1189 |
cp = __stringVal(self); |
1190 |
if ((cls = __qClass(self)) != String) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1191 |
int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1192 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1193 |
cp += numInstBytes; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1194 |
len -= numInstBytes; |
3403 | 1195 |
} |
15044 | 1196 |
while (index <= len) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1197 |
REGISTER unsigned char c; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1198 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1199 |
c = cp[index - 1]; |
3403 | 1200 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1201 |
if (c > ' ') |
3403 | 1202 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1203 |
if ((c != ' ') && (c != '\t') && (c != '\n') |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1204 |
&& (c != '\r') && (c != '\f')) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1205 |
RETURN ( __mkSmallInteger(index) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1206 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1207 |
index++; |
3403 | 1208 |
} |
8913 | 1209 |
RETURN ( __mkSmallInteger(0) ); |
3403 | 1210 |
%}. |
1211 |
||
1212 |
" |
|
8898 | 1213 |
'hello world' indexOfNonWhiteSpaceStartingAt:3 |
1214 |
'hello world' indexOfNonWhiteSpaceStartingAt:7 |
|
3403 | 1215 |
" |
1216 |
! |
|
1217 |
||
1 | 1218 |
indexOfSeparatorStartingAt:start |
1219 |
"return the index of the next separator character" |
|
1220 |
||
1221 |
%{ /* NOCONTEXT */ |
|
1222 |
||
1223 |
REGISTER unsigned char *cp; |
|
1224 |
int len, index; |
|
53 | 1225 |
OBJ cls; |
1 | 1226 |
|
1134 | 1227 |
index = __intVal(start); |
1 | 1228 |
if (index <= 0) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1229 |
index = 1; |
1 | 1230 |
} |
1134 | 1231 |
len = __stringSize(self); |
15044 | 1232 |
cp = __stringVal(self); |
1233 |
if ((cls = __qClass(self)) != String) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1234 |
int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1235 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1236 |
cp += numInstBytes; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1237 |
len -= numInstBytes; |
1 | 1238 |
} |
15044 | 1239 |
while (index <= len) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1240 |
REGISTER unsigned char c; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1241 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1242 |
c = cp[index - 1]; |
329 | 1243 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1244 |
if (c <= ' ') |
1 | 1245 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1246 |
if ((c == ' ') || (c == '\t') || (c == '\n') |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1247 |
|| (c == '\r') || (c == '\f')) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1248 |
RETURN ( __mkSmallInteger(index) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1249 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1250 |
index++; |
1 | 1251 |
} |
8913 | 1252 |
RETURN ( __mkSmallInteger(0) ); |
5407 | 1253 |
%}. |
53 | 1254 |
|
95 | 1255 |
" |
8898 | 1256 |
'hello world' indexOfSeparatorStartingAt:3 |
1257 |
'hello world' indexOfSeparatorStartingAt:7 |
|
95 | 1258 |
" |
608 | 1259 |
! |
1260 |
||
1261 |
occurrencesOf:aCharacter |
|
1262 |
"count the occurrences of the argument, aCharacter in myself |
|
1263 |
- reimplemented here for speed" |
|
1264 |
||
1265 |
%{ /* NOCONTEXT */ |
|
1266 |
||
1267 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1268 |
REGISTER unsigned byteValue; |
8913 | 1269 |
REGISTER INT count, limit; |
608 | 1270 |
OBJ cls; |
1271 |
||
1272 |
if (__isCharacter(aCharacter)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1273 |
limit = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1274 |
count = 0; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1275 |
byteValue = __intVal(__characterVal(aCharacter)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1276 |
if (byteValue <= 0xFF) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1277 |
cp = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1278 |
if ((cls = __qClass(self)) != String) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1279 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1280 |
limit -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1281 |
cp += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1282 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1283 |
/* loop unrolled and software-pipelined |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1284 |
* (gives 30-40% speedup on Intel-DUO using borland bcc55) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1285 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1286 |
while (limit >= 4) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1287 |
register unsigned char c1, c2; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1288 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1289 |
c1 = cp[0]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1290 |
limit -= 4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1291 |
c2 = cp[1]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1292 |
if (c1 == byteValue) count++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1293 |
c1 = cp[2]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1294 |
if (c2 == byteValue) count++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1295 |
c2 = cp[3]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1296 |
if (c1 == byteValue) count++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1297 |
cp += 4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1298 |
if (c2 == byteValue) count++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1299 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1300 |
while (limit > 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1301 |
register unsigned char c1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1302 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1303 |
c1 = cp[0]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1304 |
limit--; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1305 |
if (c1 == byteValue) count++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1306 |
cp ++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1307 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1308 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1309 |
RETURN ( __mkSmallInteger(count) ); |
608 | 1310 |
} |
1311 |
%}. |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
1312 |
^ super occurrencesOf:aCharacter |
608 | 1313 |
|
1314 |
" |
|
1315 |
'hello world' occurrencesOf:$a |
|
1316 |
'hello world' occurrencesOf:$w |
|
8898 | 1317 |
'hello world' occurrencesOf:$l |
1318 |
'hello world' occurrencesOf:$x |
|
1319 |
'hello world' occurrencesOf:1 |
|
11418 | 1320 |
Time millisecondsToRun:[ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1321 |
1000000 timesRepeat:[ 'abcdefghijklmn' occurrencesOf:$x ] |
11418 | 1322 |
]. 219 203 156 203 204 204 219 172 187 187 141 |
608 | 1323 |
" |
53 | 1324 |
! ! |
1325 |
||
608 | 1326 |
!String methodsFor:'comparing'! |
2 | 1327 |
|
8312 | 1328 |
< aString |
1329 |
"Compare the receiver with the argument and return true if the |
|
1330 |
receiver is greater than the argument. Otherwise return false. |
|
1331 |
No national variants are honored; use after: for this. |
|
1332 |
In contrast to ST-80, case differences are NOT ignored, thus |
|
8898 | 1333 |
'foo' < 'Foo' will return false. |
8312 | 1334 |
This may change." |
1335 |
||
1336 |
%{ /* NOCONTEXT */ |
|
1337 |
||
1338 |
int len1, len2, cmp; |
|
1339 |
unsigned char *cp1, *cp2; |
|
14664 | 1340 |
int argIsString; |
1341 |
||
1342 |
if (__isNonNilObject(aString)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1343 |
argIsString = __qIsStringLike(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1344 |
if (argIsString || __qClass(aString) == __qClass(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1345 |
cp2 = __stringVal(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1346 |
len2 = __stringSize(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1347 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1348 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1349 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1350 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1351 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1352 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1353 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1354 |
len2 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1355 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1356 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1357 |
cp1 = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1358 |
len1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1359 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1360 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1361 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1362 |
if (!__qIsStringLike(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1363 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1364 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1365 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1366 |
len1 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1367 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1368 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1369 |
if (len1 <= len2) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1370 |
cmp = strncmp(cp1, cp2, len1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1371 |
else |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1372 |
cmp = strncmp(cp1, cp2, len2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1373 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1374 |
if (cmp < 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1375 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1376 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1377 |
if ((cmp == 0) && (len1 < len2)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1378 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1379 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1380 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1381 |
} |
8312 | 1382 |
} |
1383 |
%}. |
|
1384 |
^ super < aString |
|
1385 |
! |
|
1386 |
||
608 | 1387 |
= aString |
1388 |
"Compare the receiver with the argument and return true if the |
|
1389 |
receiver is equal to the argument. Otherwise return false. |
|
1390 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
|
1391 |
Use sameAs: to compare with case ignored." |
|
1 | 1392 |
|
375 | 1393 |
%{ /* NOCONTEXT */ |
1394 |
||
608 | 1395 |
int l1, l2; |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1396 |
unsigned char *cp1, *cp2; |
3335 | 1397 |
INT addrDelta; |
14664 | 1398 |
int argIsString; |
1399 |
||
1400 |
if (aString == self) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1401 |
RETURN ( true ); |
608 | 1402 |
} |
14664 | 1403 |
if (! __isNonNilObject(aString)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1404 |
RETURN ( false ); |
608 | 1405 |
} |
1 | 1406 |
|
14664 | 1407 |
argIsString = __qIsStringLike(aString); |
1408 |
if (argIsString || __qClass(aString) == __qClass(self)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1409 |
cp2 = __stringVal(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1410 |
l2 = __stringSize(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1411 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1412 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1413 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1414 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1415 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1416 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1417 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1418 |
l2 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1419 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1420 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1421 |
cp1 = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1422 |
l1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1423 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1424 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1425 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1426 |
if (!__qIsStringLike(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1427 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1428 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1429 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1430 |
l1 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1431 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1432 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1433 |
if (l1 != l2) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1434 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1435 |
} |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1436 |
#ifdef FAST_MEMCMP |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1437 |
RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false ); |
3111 | 1438 |
#else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1439 |
addrDelta = cp2 - cp1; |
8919 | 1440 |
# ifdef __UNROLL_LOOPS__ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1441 |
while (l1 >= (sizeof(unsigned INT)*4)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1442 |
if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1443 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1444 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1445 |
if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1446 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1447 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1448 |
if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1449 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1450 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1451 |
if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1452 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1453 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1454 |
l1 -= (sizeof(unsigned INT) * 4); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1455 |
cp1 += (sizeof(unsigned INT) * 4); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1456 |
} |
8919 | 1457 |
# endif /* __UNROLL_LOOPS__ */ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1458 |
while (l1 >= sizeof(unsigned INT)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1459 |
if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1460 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1461 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1462 |
l1 -= sizeof(unsigned INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1463 |
cp1 += sizeof(unsigned INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1464 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1465 |
if (l1 >= sizeof(unsigned short)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1466 |
if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1467 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1468 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1469 |
l1 -= sizeof(unsigned short); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1470 |
cp1 += sizeof(unsigned short); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1471 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1472 |
while (l1) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1473 |
if (*cp1 != *(cp1+addrDelta)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1474 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1475 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1476 |
l1--; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1477 |
cp1++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1478 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1479 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1480 |
RETURN (true); |
3111 | 1481 |
#endif |
1 | 1482 |
} |
3111 | 1483 |
%}. |
608 | 1484 |
^ super = aString |
1 | 1485 |
|
95 | 1486 |
" |
8898 | 1487 |
'foo' = 'Foo' |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1488 |
'foo' sameAs: 'Foo' |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1489 |
#[0 0 1 0 0] asString = #[0 0 1 0 0] asString |
95 | 1490 |
" |
7868 | 1491 |
" |
1492 |
|tEmpty tCmp| |
|
1493 |
||
1494 |
tEmpty := Time millisecondsToRun:[ |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1495 |
1000000 timesRepeat:[] |
7868 | 1496 |
]. |
1497 |
tCmp := Time millisecondsToRun:[ |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1498 |
1000000 timesRepeat:[ '1234567890' = '1234567890' ] |
7868 | 1499 |
]. |
8898 | 1500 |
tCmp - tEmpty |
7868 | 1501 |
" |
1 | 1502 |
! |
1503 |
||
608 | 1504 |
> aString |
1505 |
"Compare the receiver with the argument and return true if the |
|
1506 |
receiver is greater than the argument. Otherwise return false. |
|
1507 |
No national variants are honored; use after: for this. |
|
1508 |
In contrast to ST-80, case differences are NOT ignored, thus |
|
8898 | 1509 |
'foo' > 'Foo' will return true. |
608 | 1510 |
This may change." |
1 | 1511 |
|
375 | 1512 |
%{ /* NOCONTEXT */ |
1513 |
||
608 | 1514 |
int len1, len2, cmp; |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1515 |
unsigned char *cp1, *cp2; |
14664 | 1516 |
int argIsString; |
1517 |
||
1518 |
if (__isNonNilObject(aString)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1519 |
argIsString = __qIsStringLike(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1520 |
if (argIsString || __qClass(aString) == __qClass(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1521 |
cp2 = __stringVal(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1522 |
len2 = __stringSize(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1523 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1524 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1525 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1526 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1527 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1528 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1529 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1530 |
len2 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1531 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1532 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1533 |
cp1 = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1534 |
len1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1535 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1536 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1537 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1538 |
if (!__qIsStringLike(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1539 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1540 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1541 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1542 |
len1 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1543 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1544 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1545 |
if (len1 <= len2) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1546 |
cmp = strncmp(cp1, cp2, len1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1547 |
else |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1548 |
cmp = strncmp(cp1, cp2, len2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1549 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1550 |
if (cmp > 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1551 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1552 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1553 |
if ((cmp == 0) && (len1 > len2)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1554 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1555 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1556 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1557 |
} |
1 | 1558 |
} |
370 | 1559 |
%}. |
608 | 1560 |
^ super > aString |
1561 |
! |
|
1 | 1562 |
|
1251 | 1563 |
compareCollatingWith:aString |
1564 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
8898 | 1565 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
1251 | 1566 |
The comparison is language specific, depending on the value of |
1567 |
LC_COLLATE, which is in the shell environment." |
|
1568 |
||
1 | 1569 |
%{ /* NOCONTEXT */ |
1570 |
||
608 | 1571 |
int cmp; |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1572 |
unsigned char *cp1, *cp2; |
14664 | 1573 |
int argIsString; |
1574 |
||
1575 |
if (__isNonNilObject(aString)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1576 |
argIsString = __qIsStringLike(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1577 |
if (argIsString || __qClass(aString) == __qClass(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1578 |
cp1 = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1579 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1580 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1581 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1582 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1583 |
if (!__qIsStringLike(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1584 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1585 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1586 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1587 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1588 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1589 |
cp2 = __stringVal(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1590 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1591 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1592 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1593 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1594 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1595 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1596 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1597 |
} |
608 | 1598 |
|
1599 |
#ifdef HAS_STRCOLL |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1600 |
cmp = strcoll(cp1, cp2); |
608 | 1601 |
#else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1602 |
cmp = strcmp(cp1, cp2); |
608 | 1603 |
#endif |
1604 |
||
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1605 |
if (cmp > 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1606 |
RETURN ( __mkSmallInteger(1) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1607 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1608 |
if (cmp < 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1609 |
RETURN ( __mkSmallInteger(-1) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1610 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1611 |
RETURN ( __mkSmallInteger(0) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1612 |
} |
370 | 1613 |
} |
329 | 1614 |
%}. |
608 | 1615 |
" |
1616 |
currently, this operation is only defined for strings, symbols |
|
1617 |
and subclasses. |
|
1618 |
" |
|
1251 | 1619 |
^ self primitiveFailed |
1 | 1620 |
! |
1621 |
||
14664 | 1622 |
compareWith:aString |
1623 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
1624 |
greater, 0 if equal and -1 if less than the argument. |
|
1625 |
This comparison is based on the elements' codepoints - |
|
1626 |
i.e. upper/lowercase & national characters are NOT treated specially. |
|
1627 |
'foo' compareWith: 'Foo' will return 1. |
|
1628 |
while 'foo' sameAs:'Foo' will return true" |
|
1629 |
||
1630 |
%{ /* NOCONTEXT */ |
|
1631 |
||
1632 |
int cmp; |
|
1633 |
unsigned char *cp1, *cp2; |
|
1634 |
int argIsString; |
|
1635 |
||
1636 |
if (__isNonNilObject(aString)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1637 |
argIsString = __qIsStringLike(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1638 |
if (argIsString || __qClass(aString) == __qClass(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1639 |
cp1 = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1640 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1641 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1642 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1643 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1644 |
if (!__qIsStringLike(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1645 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1646 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1647 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1648 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1649 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1650 |
cp2 = __stringVal(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1651 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1652 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1653 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1654 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1655 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1656 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1657 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1658 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1659 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1660 |
cmp = strcmp(cp1, cp2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1661 |
if (cmp > 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1662 |
RETURN ( __mkSmallInteger(1) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1663 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1664 |
if (cmp < 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1665 |
RETURN ( __mkSmallInteger(-1) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1666 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1667 |
RETURN ( __mkSmallInteger(0) ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1668 |
} |
14664 | 1669 |
} |
1670 |
%}. |
|
1671 |
" |
|
1672 |
currently, this operation is only defined for strings, symbols |
|
1673 |
and subclasses. |
|
1674 |
" |
|
1675 |
^ self primitiveFailed |
|
1676 |
! |
|
1677 |
||
14653 | 1678 |
hash |
1679 |
"return an integer useful as a hash-key" |
|
1680 |
||
1681 |
%{ /* NOCONTEXT */ |
|
1682 |
||
1683 |
REGISTER unsigned INT val; |
|
1684 |
REGISTER unsigned char *cp; |
|
1685 |
int l; |
|
1686 |
||
1687 |
cp = __stringVal(self); |
|
1688 |
l = __stringSize(self); |
|
1689 |
if (!__qIsStringLike(self)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1690 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1691 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1692 |
cp += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1693 |
l -= n; |
14653 | 1694 |
} |
1695 |
||
1696 |
/* |
|
1697 |
* this is the sdbm algorithm |
|
1698 |
*/ |
|
1699 |
val = 0; |
|
1700 |
while (l >= 4) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1701 |
l -= 4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1702 |
val = ((val * 65599) & _MAX_INT) + cp[0]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1703 |
val = ((val * 65599) & _MAX_INT) + cp[1]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1704 |
val = ((val * 65599) & _MAX_INT) + cp[2]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1705 |
val = ((val * 65599) & _MAX_INT) + cp[3]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1706 |
cp += 4; |
14653 | 1707 |
} |
1708 |
while (l--) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1709 |
val = ((val * 65599) & _MAX_INT) + *cp++; |
14653 | 1710 |
} |
1711 |
RETURN ( __mkSmallInteger(val & _MAX_INT)); |
|
1712 |
%} |
|
1713 |
||
1714 |
" |
|
1715 |
'a' hash |
|
1716 |
'ab' hash = 'ab' asUnicode16String hash |
|
1717 |
" |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1718 |
|
14653 | 1719 |
"Created: / 26-12-2011 / 13:53:09 / cg" |
1720 |
! |
|
1721 |
||
13880 | 1722 |
hash_dragonBook |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1723 |
"return an integer useful as a hash-key" |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1724 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1725 |
%{ /* NOCONTEXT */ |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1726 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1727 |
REGISTER unsigned g, val; |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1728 |
REGISTER unsigned char *cp, *cp0; |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1729 |
int l; |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1730 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1731 |
cp = __stringVal(self); |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1732 |
l = __stringSize(self); |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1733 |
if (__qClass(self) != @global(String)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1734 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1735 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1736 |
cp += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1737 |
l -= n; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1738 |
} |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1739 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1740 |
/* |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1741 |
* this is the dragon-book algorithm |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1742 |
*/ |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1743 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1744 |
val = 0; |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1745 |
switch (l) { |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1746 |
default: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1747 |
for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1748 |
val = (val << 4) + *cp; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1749 |
if (g = (val & 0xF0000000)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1750 |
val ^= g >> 24; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1751 |
val ^= g; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1752 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1753 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1754 |
break; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1755 |
case 6: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1756 |
val = cp[5] << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1757 |
case 5: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1758 |
val = (val + cp[4]) << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1759 |
case 4: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1760 |
val = (val + cp[3]) << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1761 |
case 3: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1762 |
val = (val + cp[2]) << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1763 |
case 2: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1764 |
val = (val + cp[1]) << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1765 |
case 1: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1766 |
val = val + cp[0]; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1767 |
case 0: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1768 |
break; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1769 |
} |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1770 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1771 |
/* |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1772 |
* multiply by large prime to spread values |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1773 |
* This speeds up Set and Dictionary by a factor of 10! |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1774 |
*/ |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1775 |
val *= 31415821; |
12763 | 1776 |
RETURN ( __mkSmallInteger(val & _MAX_INT)); |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1777 |
%} |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1778 |
! |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
1779 |
|
608 | 1780 |
~= aString |
1781 |
"Compare the receiver with the argument and return true if the |
|
1782 |
receiver is not equal to the argument. Otherwise return false. |
|
3111 | 1783 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
1784 |
Actually, there is no need to redefine that method here, |
|
1785 |
the default (= not as inherited) works ok. |
|
1786 |
However, this may be heavily used and the redefinition saves an |
|
1787 |
extra message send." |
|
1 | 1788 |
|
608 | 1789 |
%{ /* NOCONTEXT */ |
1790 |
||
1 | 1791 |
int l1, l2; |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1792 |
unsigned char *cp1, *cp2; |
3111 | 1793 |
OBJ cls, myCls; |
3335 | 1794 |
INT addrDelta; |
14664 | 1795 |
int argIsString; |
1796 |
||
1797 |
if (aString == self) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1798 |
RETURN ( false ); |
608 | 1799 |
} |
14664 | 1800 |
if (! __isNonNilObject(aString)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1801 |
RETURN ( true ); |
608 | 1802 |
} |
3111 | 1803 |
|
14664 | 1804 |
argIsString = __qIsStringLike(aString); |
1805 |
if (argIsString || __qClass(aString) == __qClass(self)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1806 |
cp1 = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1807 |
l1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1808 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1809 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1810 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1811 |
if (!__qIsStringLike(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1812 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1813 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1814 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1815 |
l1 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1816 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1817 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1818 |
cp2 = __stringVal(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1819 |
l2 = __stringSize(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1820 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1821 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1822 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1823 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1824 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1825 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1826 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1827 |
l2 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1828 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1829 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1830 |
if (l1 != l2) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1831 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1832 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1833 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1834 |
addrDelta = cp2 - cp1; |
8919 | 1835 |
# ifdef __UNROLL_LOOPS__ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1836 |
while (l1 >= (sizeof(unsigned INT)*4)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1837 |
if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1838 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1839 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1840 |
if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1841 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1842 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1843 |
if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1844 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1845 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1846 |
if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1847 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1848 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1849 |
l1 -= (sizeof(unsigned INT) * 4); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1850 |
cp1 += (sizeof(unsigned INT) * 4); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1851 |
} |
8919 | 1852 |
# endif /* __UNROLL_LOOPS__ */ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1853 |
while (l1 >= sizeof(unsigned INT)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1854 |
if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1855 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1856 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1857 |
l1 -= sizeof(unsigned INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1858 |
cp1 += sizeof(unsigned INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1859 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1860 |
if (l1 >= sizeof(unsigned short)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1861 |
if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1862 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1863 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1864 |
l1 -= sizeof(unsigned short); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1865 |
cp1 += sizeof(unsigned short); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1866 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1867 |
while (l1) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1868 |
if (*cp1 != *(cp1+addrDelta)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1869 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1870 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1871 |
l1--; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1872 |
cp1++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1873 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1874 |
RETURN (false); |
608 | 1875 |
} |
3111 | 1876 |
%}. |
608 | 1877 |
^ super ~= aString |
1878 |
! ! |
|
1879 |
||
1880 |
!String methodsFor:'converting'! |
|
1881 |
||
6830 | 1882 |
asArrayOfSubstrings |
11906 | 1883 |
"Answer an array with all the substrings of the receiver separated by |
1884 |
separator characters (space, cr, tab, linefeed, formfeed, etc). |
|
1885 |
CG: This is ported Squeak code, and I am not sure if it is more efficient than |
|
16457 | 1886 |
the inherited one... after all: who added it anyway ?" |
1887 |
||
1888 |
| substrings start end stop | |
|
11906 | 1889 |
|
1890 |
substrings := OrderedCollection new. |
|
1891 |
start := 1. |
|
16457 | 1892 |
stop := self size. |
1893 |
[start <= stop] whileTrue: [ |
|
1894 |
(self at: start) isSeparator ifFalse: [ |
|
1895 |
end := start + 1. |
|
1896 |
[end <= stop and: [(self at: end) isSeparator not]] |
|
1897 |
whileTrue: [end := end + 1]. |
|
1898 |
substrings add: (self copyFrom: start to: end - 1). |
|
1899 |
start := end - 1 |
|
1900 |
]. |
|
1901 |
start := start + 1 |
|
11906 | 1902 |
]. |
1903 |
^ substrings asArray |
|
6830 | 1904 |
! |
1905 |
||
11882 | 1906 |
asAsciiZ |
1907 |
"if the receiver does not end with a 0-valued character, return a copy of it, |
|
1908 |
with an additional 0-character. Otherwise return the receiver. This is sometimes |
|
1909 |
needed when a string has to be passed to C, which needs 0-terminated strings. |
|
1910 |
Notice, that all singleByte strings are already 0-terminated in ST/X, whereas wide |
|
1911 |
strings are not." |
|
1912 |
||
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1913 |
^ self |
11882 | 1914 |
|
1915 |
" |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1916 |
'abc' asAsciiZ |
11882 | 1917 |
'abc' asWideString asAsciiZ |
1918 |
" |
|
1919 |
! |
|
1920 |
||
3281
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1921 |
asBoldText |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1922 |
"return self as a bold text" |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1923 |
|
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1924 |
^Text string: self emphasis: #bold |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1925 |
! |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1926 |
|
10594 | 1927 |
asByteArray |
15938 | 1928 |
"return a new ByteArray with the receiver's elements. |
1929 |
This redefined method is faster than Collection>>#asByteArray" |
|
10594 | 1930 |
|
1931 |
|bytes sz| |
|
1932 |
||
1933 |
sz := self size. |
|
1934 |
bytes := ByteArray new:sz . |
|
1935 |
bytes replaceFrom:1 to:sz with:self startingAt:1. |
|
1936 |
^ bytes |
|
1937 |
||
1938 |
" |
|
16019
b204c9d6ce6d
no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents:
15938
diff
changeset
|
1939 |
'fooBar' asByteArray. |
10594 | 1940 |
" |
14260
c8e2fa654d6d
comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents:
14217
diff
changeset
|
1941 |
|
c8e2fa654d6d
comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents:
14217
diff
changeset
|
1942 |
"Modified (comment): / 26-07-2012 / 22:55:26 / cg" |
10594 | 1943 |
! |
1944 |
||
9472 | 1945 |
asExternalBytes |
1946 |
|bytes sz| |
|
1947 |
||
1948 |
sz := self size. |
|
1949 |
bytes := ExternalBytes new:(sz + 1). |
|
1950 |
bytes replaceFrom:1 to:sz with:self startingAt:1. |
|
1951 |
bytes at:(sz + 1) put:0. |
|
1952 |
^ bytes |
|
1953 |
||
1954 |
" |
|
1955 |
|x| |
|
1956 |
x := 'fooBar' asExternalBytes. |
|
1957 |
x unprotectFromGC. |
|
1958 |
ObjectMemory garbageCollect |
|
1959 |
" |
|
1960 |
||
1961 |
"Modified: / 03-08-2006 / 14:45:32 / fm" |
|
1962 |
! |
|
1963 |
||
14156 | 1964 |
asExternalBytesUnprotected |
1965 |
"Like asExternalBytes, but does not register the bytes so |
|
15837 | 1966 |
bytes are GARBAGE-COLLECTED!!" |
14156 | 1967 |
|
1968 |
|bytes sz| |
|
1969 |
||
1970 |
sz := self size. |
|
15837 | 1971 |
bytes := ExternalBytes unprotectedNew:(sz + 1). |
14156 | 1972 |
bytes replaceFrom:1 to:sz with:self startingAt:1. |
1973 |
bytes at:(sz + 1) put:0. |
|
1974 |
^ bytes |
|
1975 |
||
1976 |
" |
|
1977 |
|x| |
|
1978 |
x := 'fooBar' asExternalBytesUnprotected. |
|
1979 |
ObjectMemory garbageCollect |
|
1980 |
" |
|
1981 |
||
1982 |
"Created: / 05-06-2012 / 14:12:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
15837 | 1983 |
"Modified: / 30-11-2013 / 11:41:40 / cg" |
14156 | 1984 |
! |
1985 |
||
12454 | 1986 |
asImmutableString |
1987 |
"return a write-protected copy of myself" |
|
1988 |
||
1989 |
^ self copy changeClassTo:ImmutableString |
|
1990 |
! |
|
1991 |
||
16185 | 1992 |
asMutator |
16226 | 1993 |
"return a corresponding setter method's selector" |
16185 | 1994 |
|
1995 |
^ (self,':') asSymbol |
|
1996 |
! |
|
1997 |
||
9574 | 1998 |
asPackageId |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1999 |
"given a package-string as receiver, return a packageId object. |
14566 | 2000 |
packageIds hide the details of module/directory handling inside the path. |
2001 |
See PackageId for the required format of those strings." |
|
12184
e91c375c7ea9
comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents:
11922
diff
changeset
|
2002 |
|
14571 | 2003 |
^ PackageId from: self |
9574 | 2004 |
|
2005 |
" |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2006 |
'stx:libbasic' asPackageId |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2007 |
'stx:goodies/net/ssl' asPackageId |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2008 |
'stx:hello' asPackageId |
9574 | 2009 |
" |
2010 |
||
2011 |
"Created: / 18-08-2006 / 12:19:54 / cg" |
|
2012 |
! |
|
2013 |
||
7877
bef56f06d2f8
asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents:
7869
diff
changeset
|
2014 |
asSingleByteString |
5760 | 2015 |
"I am a string" |
2016 |
||
2017 |
^ self |
|
2018 |
! |
|
2019 |
||
11287 | 2020 |
asSingleByteStringIfPossible |
2021 |
"I am a single-byte string" |
|
2022 |
||
2023 |
^ self |
|
2024 |
! |
|
2025 |
||
9473 | 2026 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
11883 | 2027 |
"return the receiver converted to a 'normal' string, |
2028 |
with invalid characters replaced by replacementCharacter. |
|
2029 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
2030 |
and replace characters above code-255 with some replacement. |
|
2031 |
Dummy here, because I am already a single byte string." |
|
2032 |
||
9473 | 2033 |
^ self |
2034 |
||
2035 |
"Modified: / 07-08-2006 / 15:04:45 / fm" |
|
2036 |
! |
|
2037 |
||
608 | 2038 |
asSymbol |
9233 | 2039 |
"Return a unique symbol with the name taken from the receivers characters." |
7869 | 2040 |
|
2041 |
%{ /* NOCONTEXT */ |
|
608 | 2042 |
OBJ newSymbol; |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2043 |
OBJ cls; |
7869 | 2044 |
char *cp = __stringVal(self); |
2045 |
||
2046 |
/* care for instances of a subclass with instVars */ |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2047 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2048 |
if (cls != String) { |
10352 | 2049 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2050 |
} |
7869 | 2051 |
newSymbol = __MKSYMBOL(cp, (OBJ *)0); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2052 |
if (newSymbol) { |
10352 | 2053 |
RETURN ( newSymbol); |
608 | 2054 |
} |
2055 |
%}. |
|
2056 |
^ ObjectMemory allocationFailureSignal raise. |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2057 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2058 |
" |
8898 | 2059 |
'hello' asSymbol |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2060 |
" |
608 | 2061 |
! |
2062 |
||
2063 |
asSymbolIfInterned |
|
10352 | 2064 |
"If a symbol with the receivers characters is already known, return it. Otherwise, return nil. |
9233 | 2065 |
This can be used to query for an existing symbol and is the same as: |
10352 | 2066 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
608 | 2067 |
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
|
2068 |
performed once." |
1 | 2069 |
|
608 | 2070 |
%{ /* NOCONTEXT */ |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2071 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2072 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2073 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2074 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2075 |
if (cls != String) { |
10352 | 2076 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2077 |
} else { |
10352 | 2078 |
indx = 0; |
608 | 2079 |
} |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2080 |
RETURN ( __SYMBOL_OR_NIL(__stringVal(self) + indx)); |
5407 | 2081 |
%}. |
2082 |
self primitiveFailed |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2083 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2084 |
'hello' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2085 |
'fooBarBaz' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2086 |
" |
608 | 2087 |
! |
2088 |
||
9182 | 2089 |
asUUID |
2090 |
"return self as a UUID" |
|
2091 |
||
14968 | 2092 |
^ UUID fromString:self |
9182 | 2093 |
|
2094 |
" |
|
2095 |
'{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' asUUID |
|
10677 | 2096 |
'EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B' asUUID |
14968 | 2097 |
'EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B quatsch' asUUID |
9182 | 2098 |
" |
10677 | 2099 |
|
2100 |
"Modified: / 02-08-2007 / 16:43:29 / cg" |
|
9182 | 2101 |
! |
2102 |
||
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2103 |
withTabsExpanded:numSpaces |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
2104 |
"return a string with the characters of the receiver where all tabulator characters |
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2105 |
are expanded into spaces (assuming numSpaces-col tabs). |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
2106 |
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
|
2107 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
2108 |
This does handle multiline strings. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
2109 |
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
|
2110 |
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
|
2111 |
|
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
2112 |
%{ /* STACK:700 */ |
2894 | 2113 |
unsigned char buffer[80*8 + 10]; |
2114 |
unsigned char *srcP, *dstP, *cp0; |
|
608 | 2115 |
int idx, sz; |
2116 |
int any = 0; |
|
2117 |
OBJ newString; |
|
2118 |
char c; |
|
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2119 |
int n; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2120 |
|
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2121 |
if ((__qClass(self) == String) |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2122 |
&& __isSmallInteger(numSpaces)) { |
9473 | 2123 |
n = __intVal(numSpaces); |
2124 |
||
2125 |
/* |
|
2126 |
* for small strings (< 80), do it without a prescan ... |
|
2127 |
* the buffer is large enough to even convert a |
|
2128 |
* receiver consisting fully of tabs. |
|
2129 |
*/ |
|
2130 |
if (__stringSize(self) < 80) { |
|
2131 |
idx = 1; |
|
2132 |
for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) { |
|
2133 |
if (c == '\t') { |
|
2134 |
any = 1; |
|
2135 |
while (idx % n) { |
|
2136 |
idx++; |
|
2137 |
*dstP++ = ' '; |
|
2138 |
} |
|
2139 |
idx++; |
|
2140 |
*dstP++ = ' '; |
|
2141 |
} else { |
|
2142 |
*dstP++ = c; |
|
2143 |
idx++; |
|
2144 |
if (c == '\n') { |
|
2145 |
idx = 1; |
|
2146 |
} |
|
2147 |
} |
|
2148 |
} |
|
2149 |
if (! any) RETURN(self); |
|
2150 |
*dstP = '\0'; |
|
2151 |
RETURN (__MKSTRING_L(buffer, (dstP-buffer))); |
|
2152 |
} |
|
2153 |
/* |
|
2154 |
* for large strings, we compute the new size, allocate a new string |
|
2155 |
* and expand it. |
|
2156 |
* |
|
2157 |
* first, scan for size ... |
|
2158 |
*/ |
|
2159 |
idx = 1; |
|
2160 |
for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) { |
|
2161 |
if (c == '\t') { |
|
2162 |
any = 1; |
|
2163 |
while (idx % n) { |
|
2164 |
idx++; |
|
2165 |
sz++; |
|
2166 |
} |
|
2167 |
idx++; sz ++; |
|
2168 |
} else { |
|
2169 |
sz++; idx++; |
|
2170 |
if (c == '\n') { |
|
2171 |
idx = 1; |
|
2172 |
} |
|
2173 |
} |
|
2174 |
} |
|
2175 |
if (! any) RETURN(self); |
|
2176 |
||
2177 |
/* |
|
2178 |
* get the string |
|
2179 |
*/ |
|
2180 |
sz = OHDR_SIZE + sz + 1; |
|
2181 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
|
2182 |
if (newString != nil) { |
|
2183 |
__InstPtr(newString)->o_class = String; |
|
2184 |
__qSTORE(newString, String); |
|
2185 |
||
2186 |
/* |
|
2187 |
* expand |
|
2188 |
*/ |
|
2189 |
idx = 1; |
|
2190 |
for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) { |
|
2191 |
if (c == '\t') { |
|
2192 |
while (idx % n) { |
|
2193 |
idx++; |
|
2194 |
*dstP++ = ' '; |
|
2195 |
} |
|
2196 |
idx++; |
|
2197 |
*dstP++ = ' '; |
|
2198 |
} else { |
|
2199 |
*dstP++ = c; idx++; |
|
2200 |
if (c == '\n') { |
|
2201 |
idx = 1; |
|
2202 |
} |
|
2203 |
} |
|
2204 |
} |
|
2205 |
*dstP++ = '\0'; |
|
2206 |
RETURN (newString); |
|
2207 |
} |
|
608 | 2208 |
} |
2209 |
%}. |
|
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2210 |
^ super withTabsExpanded:numSpaces |
1 | 2211 |
! ! |
2212 |
||
2213 |
!String methodsFor:'copying'! |
|
2214 |
||
2215 |
, aString |
|
14074 | 2216 |
"return the concatenation of myself and the argument, aString as a String. |
1 | 2217 |
- reimplemented here for speed" |
2218 |
||
2219 |
%{ |
|
95 | 2220 |
int l1, l2, sz; |
14664 | 2221 |
OBJ newString; |
2222 |
||
2223 |
if (__isNonNilObject(aString)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2224 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2225 |
* can do it here if both are Strings/Symbols: |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2226 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2227 |
if (__qIsStringLike(self) && __qIsStringLike(aString)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2228 |
l1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2229 |
l2 = __stringSize(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2230 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2231 |
sz = OHDR_SIZE + l1 + l2 + 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2232 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2233 |
if (newString != nil) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2234 |
char *cp1, *cp2; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2235 |
REGISTER unsigned char *dstp; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2236 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2237 |
__InstPtr(newString)->o_class = String; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2238 |
__qSTORE(newString, String); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2239 |
dstp = __stringVal(newString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2240 |
cp1 = (char *) __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2241 |
cp2 = (char *) __stringVal(aString); |
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
2242 |
|
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
2243 |
#ifdef bcopy4 |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2244 |
/* knowing that allocation is 4-byte aligned and |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2245 |
* size rounded up to next 4-byte, the first copy |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2246 |
* can be done word-wise. |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2247 |
* that speeds up size-10-string , size-10-string |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2248 |
* by 10% on a P5/200. |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2249 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2250 |
{ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2251 |
int nw = l1 >> 2; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2252 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2253 |
if (l1 & 3) nw++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2254 |
bcopy4(cp1, dstp, nw); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2255 |
dstp += l1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2256 |
} |
3673 | 2257 |
#else |
2258 |
# ifdef FAST_MEMCPY |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2259 |
memcpy(dstp, cp1, l1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2260 |
dstp += l1; |
3673 | 2261 |
# else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2262 |
while (l1 >= 4) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2263 |
*(int *)dstp = *(int *)cp1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2264 |
dstp += 4; cp1 += 4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2265 |
l1 -= 4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2266 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2267 |
while (l1--) *dstp++ = *cp1++; |
3673 | 2268 |
# endif |
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
2269 |
#endif |
2862 | 2270 |
|
3673 | 2271 |
#ifdef bcopy4 |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2272 |
if (((INT)dstp & 3) == 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2273 |
int nw = l2 >> 2; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2274 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2275 |
if (l2 & 3) nw++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2276 |
bcopy4(cp2, dstp, nw); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2277 |
*(dstp + l2) = '\0'; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2278 |
RETURN ( newString ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2279 |
} |
3673 | 2280 |
#endif |
8898 | 2281 |
|
1 | 2282 |
#ifdef FAST_MEMCPY |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2283 |
memcpy(dstp, cp2, l2+1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2284 |
dstp[l2] = '\0'; |
1 | 2285 |
#else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2286 |
while (l2--) *dstp++ = *cp2++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2287 |
*dstp = '\0'; |
1 | 2288 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2289 |
RETURN ( newString ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2290 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2291 |
} |
1 | 2292 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
2293 |
%}. |
1 | 2294 |
^ super , aString |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2295 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2296 |
" |
14664 | 2297 |
'hello' , 'world' asImmutableString |
2298 |
'hello' , #world |
|
8898 | 2299 |
#[0 0 0 1] asString, #[0 0 0 2 0] asString |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2300 |
" |
14074 | 2301 |
|
2302 |
"Modified: / 01-04-2012 / 13:19:44 / cg" |
|
1 | 2303 |
! |
2304 |
||
2305 |
concatenate:string1 and:string2 |
|
2306 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
2307 |
This is equivalent to self , string1 , string2 |
|
2308 |
- generated by compiler when such a construct is detected" |
|
2309 |
||
2310 |
|newString| |
|
2862 | 2311 |
|
1 | 2312 |
%{ |
95 | 2313 |
int len1, len2, len3, sz; |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2314 |
#if !defined(FAST_MEMCPY) |
1 | 2315 |
REGISTER unsigned char *srcp; |
2316 |
#endif |
|
2317 |
REGISTER unsigned char *dstp; |
|
2318 |
||
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2319 |
if (__qIsStringLike(self) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2320 |
&& __isStringLike(string1) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2321 |
&& __isStringLike(string2)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2322 |
len1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2323 |
len2 = __stringSize(string1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2324 |
len3 = __stringSize(string2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2325 |
sz = OHDR_SIZE + len1 + len2 + len3 + 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2326 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2327 |
if (newString != nil) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2328 |
__InstPtr(newString)->o_class = String; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2329 |
__qSTORE(newString, String); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2330 |
dstp = __stringVal(newString); |
1 | 2331 |
#ifdef FAST_MEMCPY |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2332 |
memcpy(dstp, __stringVal(self), len1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2333 |
memcpy(dstp + len1, __stringVal(string1), len2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2334 |
memcpy(dstp + len1 + len2, __stringVal(string2), len3+1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2335 |
*(dstp + len1 + len2 + len3) = '\0'; |
1 | 2336 |
#else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2337 |
srcp = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2338 |
while (len1--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2339 |
srcp = __stringVal(string1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2340 |
while (len2--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2341 |
srcp = __stringVal(string2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2342 |
while (len3--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2343 |
*dstp = '\0'; |
1 | 2344 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2345 |
RETURN ( newString ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2346 |
} |
1 | 2347 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
2348 |
%}. |
1 | 2349 |
^ super , string1 , string2 |
2350 |
! |
|
2351 |
||
2352 |
concatenate:string1 and:string2 and:string3 |
|
2353 |
"return the concatenation of myself and the string arguments. |
|
2354 |
This is equivalent to self , string1 , string2 , string3 |
|
2355 |
- generated by compiler when such a construct is detected" |
|
2356 |
||
2357 |
|newString| |
|
2862 | 2358 |
|
1 | 2359 |
%{ |
95 | 2360 |
int len1, len2, len3, len4, sz; |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2361 |
#if !defined(FAST_MEMCPY) |
1 | 2362 |
REGISTER unsigned char *srcp; |
2363 |
#endif |
|
2364 |
REGISTER unsigned char *dstp; |
|
2365 |
||
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2366 |
if (__qIsStringLike(self) |
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
2367 |
&& __isStringLike(string1) |
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
2368 |
&& __isStringLike(string2) |
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
2369 |
&& __isStringLike(string3)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2370 |
len1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2371 |
len2 = __stringSize(string1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2372 |
len3 = __stringSize(string2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2373 |
len4 = __stringSize(string3); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2374 |
sz = OHDR_SIZE + len1 + len2 + len3 + len4 + 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2375 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2376 |
if (newString != nil) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2377 |
__InstPtr(newString)->o_class = String; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2378 |
__qSTORE(newString, String); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2379 |
dstp = __stringVal(newString); |
1 | 2380 |
#ifdef FAST_MEMCPY |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2381 |
memcpy(dstp, __stringVal(self), len1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2382 |
memcpy(dstp + len1, __stringVal(string1), len2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2383 |
memcpy(dstp + len1 + len2, __stringVal(string2), len3); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2384 |
memcpy(dstp + len1 + len2 + len3, __stringVal(string3), len4+1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2385 |
*(dstp + len1 + len2 + len3 + len4) = '\0'; |
1 | 2386 |
#else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2387 |
srcp = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2388 |
while (len1--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2389 |
srcp = __stringVal(string1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2390 |
while (len2--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2391 |
srcp = __stringVal(string2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2392 |
while (len3--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2393 |
srcp = __stringVal(string3); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2394 |
while (len4--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2395 |
*dstp = '\0'; |
1 | 2396 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2397 |
RETURN ( newString ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2398 |
} |
1 | 2399 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
2400 |
%}. |
1 | 2401 |
^ super , string1 , string2 , string3 |
2402 |
! |
|
2403 |
||
4745 | 2404 |
copy |
2405 |
"return a copy of the receiver" |
|
2406 |
||
2407 |
(self isMemberOf:String) ifTrue:[ |
|
9473 | 2408 |
^ self copyFrom:1 |
4745 | 2409 |
]. |
2410 |
^ super copy |
|
2411 |
! |
|
2412 |
||
608 | 2413 |
copyFrom:start |
9233 | 2414 |
"return a new collection consisting of receivers elements from startIndex to the end of the collection. |
8898 | 2415 |
This method will always return a string, even if the receiver |
608 | 2416 |
is a subclass-instance. This might change if there is a need. |
2417 |
- reimplemented here for speed" |
|
1 | 2418 |
|
13 | 2419 |
%{ /* NOCONTEXT */ |
1 | 2420 |
|
608 | 2421 |
#if !defined(FAST_MEMCPY) |
2422 |
REGISTER unsigned char *srcp; |
|
2423 |
#endif |
|
1 | 2424 |
REGISTER unsigned char *dstp; |
608 | 2425 |
REGISTER int count; |
2426 |
int len, index1, sz; |
|
2427 |
OBJ newString; |
|
2862 | 2428 |
OBJ myClass; |
608 | 2429 |
|
2862 | 2430 |
myClass = __qClass(self); |
2431 |
||
2894 | 2432 |
#ifndef NO_PRIM_STRING |
2862 | 2433 |
if (__isSmallInteger(start) |
2434 |
&& ((myClass==String) || (myClass==Symbol))) { |
|
10352 | 2435 |
len = __stringSize(self); |
2436 |
index1 = __intVal(start); |
|
2437 |
if (index1 > 0) { |
|
2438 |
if (index1 <= len) { |
|
2439 |
count = len - index1 + 1; |
|
2440 |
sz = OHDR_SIZE + count + 1; |
|
2441 |
||
2442 |
__PROTECT_CONTEXT__ |
|
2443 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
|
2444 |
__UNPROTECT_CONTEXT__ |
|
2445 |
||
2446 |
if (newString != nil) { |
|
2447 |
__InstPtr(newString)->o_class = String; |
|
2448 |
__qSTORE(newString, String); |
|
2449 |
dstp = __stringVal(newString); |
|
1 | 2450 |
#ifdef FAST_MEMCPY |
10352 | 2451 |
memcpy(dstp, __stringVal(self) + index1 - 1, count); |
2452 |
dstp[count] = '\0'; |
|
1 | 2453 |
#else |
10352 | 2454 |
srcp = __stringVal(self) + index1 - 1; |
2455 |
while (count--) { |
|
2456 |
*dstp++ = *srcp++; |
|
2457 |
} |
|
2458 |
*dstp = '\0'; |
|
1 | 2459 |
#endif |
10352 | 2460 |
RETURN ( newString ); |
2461 |
} |
|
2462 |
} |
|
2463 |
} |
|
13 | 2464 |
} |
2894 | 2465 |
#endif |
51 | 2466 |
%}. |
608 | 2467 |
"fall back in case of non-integer index or out-of-bound index; |
2468 |
will eventually lead to an out-of-bound signal raise" |
|
51 | 2469 |
|
608 | 2470 |
^ super copyFrom:start |
1 | 2471 |
! |
2472 |
||
2473 |
copyFrom:start to:stop |
|
2474 |
"return the substring starting at index start, anInteger and ending |
|
53 | 2475 |
at stop, anInteger. This method will always return a string, even |
2476 |
if the receiver is a subclass-instance. This might change if there is a need. |
|
1 | 2477 |
- reimplemented here for speed" |
2478 |
||
13 | 2479 |
%{ /* NOCONTEXT */ |
2480 |
||
1 | 2481 |
REGISTER unsigned char *srcp; |
2482 |
REGISTER unsigned char *dstp; |
|
2483 |
REGISTER int count; |
|
95 | 2484 |
int len, sz, index1, index2; |
13 | 2485 |
OBJ newString; |
2862 | 2486 |
OBJ myClass; |
1 | 2487 |
|
2862 | 2488 |
myClass = __qClass(self); |
2489 |
||
2894 | 2490 |
#ifndef NO_PRIM_STRING |
2862 | 2491 |
if (__bothSmallInteger(start, stop) |
2492 |
&& ((myClass==String) || (myClass==Symbol))) { |
|
9473 | 2493 |
len = __stringSize(self); |
2494 |
index1 = __intVal(start); |
|
2495 |
index2 = __intVal(stop); |
|
2496 |
||
2497 |
if ((index1 <= index2) && (index1 > 0)) { |
|
2498 |
if (index2 <= len) { |
|
2499 |
count = index2 - index1 + 1; |
|
2500 |
sz = OHDR_SIZE + count + 1; |
|
2501 |
||
2502 |
__PROTECT_CONTEXT__ |
|
2503 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
|
2504 |
__UNPROTECT_CONTEXT__ |
|
2505 |
||
2506 |
if (newString != nil) { |
|
2507 |
__InstPtr(newString)->o_class = String; |
|
2508 |
__qSTORE(newString, String); |
|
2509 |
dstp = __stringVal(newString); |
|
2510 |
srcp = __stringVal(self) + index1 - 1; |
|
2894 | 2511 |
#ifdef bcopy4 |
9473 | 2512 |
{ |
2513 |
int nw = count >> 2; |
|
2514 |
||
2515 |
if (count & 3) { |
|
2516 |
nw++; |
|
2517 |
} |
|
2518 |
bcopy4(srcp, dstp, nw); |
|
2519 |
dstp[count] = '\0'; |
|
2520 |
} |
|
1 | 2521 |
#else |
2894 | 2522 |
# ifdef FAST_MEMCPY |
9473 | 2523 |
memcpy(dstp, srcp, count); |
2524 |
dstp[count] = '\0'; |
|
209 | 2525 |
# else |
9473 | 2526 |
while (count--) { |
2527 |
*dstp++ = *srcp++; |
|
2528 |
} |
|
2529 |
*dstp = '\0'; |
|
209 | 2530 |
# endif |
13 | 2531 |
#endif |
9473 | 2532 |
RETURN ( newString ); |
2533 |
} |
|
2534 |
} |
|
2535 |
} |
|
2536 |
/* |
|
2537 |
* allow empty copy |
|
2538 |
*/ |
|
2539 |
if (index1 > index2) { |
|
2540 |
__PROTECT_CONTEXT__ |
|
2541 |
__qNew(newString, OHDR_SIZE+1); /* OBJECT ALLOCATION */ |
|
2542 |
__UNPROTECT_CONTEXT__ |
|
2543 |
if (newString != nil) { |
|
2544 |
__InstPtr(newString)->o_class = String; |
|
2545 |
(__stringVal(newString))[0] = '\0'; |
|
2546 |
RETURN ( newString ); |
|
2547 |
} |
|
2548 |
} |
|
1 | 2549 |
} |
2894 | 2550 |
#endif |
51 | 2551 |
%}. |
2552 |
"fall back in case of non-integer index or out-of-bound index; |
|
2553 |
will eventually lead to an out-of-bound signal raise" |
|
2554 |
||
1 | 2555 |
^ super copyFrom:start to:stop |
2556 |
! |
|
2557 |
||
608 | 2558 |
copyWith:aCharacter |
2559 |
"return a new string containing the receivers characters |
|
8898 | 2560 |
and the single new character, aCharacter. |
608 | 2561 |
This is different from concatentation, which expects another string |
2562 |
as argument, but equivalent to copy-and-addLast. |
|
2563 |
Reimplemented here for more speed" |
|
2564 |
||
2565 |
%{ /* NOCONTEXT */ |
|
2566 |
||
2887 | 2567 |
int count; |
608 | 2568 |
int sz; |
2569 |
REGISTER unsigned char *dstp; |
|
2570 |
OBJ cls, newString; |
|
2862 | 2571 |
OBJ myClass; |
608 | 2572 |
|
2862 | 2573 |
myClass = __qClass(self); |
2574 |
||
2894 | 2575 |
#ifndef NO_PRIM_STRING |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2576 |
if (__isCharacter(aCharacter)) { |
9473 | 2577 |
unsigned int cVal = __intVal(__characterVal(aCharacter)); |
2578 |
||
2579 |
if ((cVal <= 0xFF) |
|
2580 |
&& ((myClass==String) || (myClass==Symbol))) { |
|
2581 |
count = __stringSize(self); |
|
2582 |
sz = OHDR_SIZE + count + 1 + 1; |
|
2583 |
||
2584 |
__PROTECT_CONTEXT__ |
|
2585 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
|
2586 |
__UNPROTECT_CONTEXT__ |
|
2587 |
||
2588 |
if (newString) { |
|
2589 |
__InstPtr(newString)->o_class = String; |
|
2590 |
__qSTORE(newString, String); |
|
2591 |
dstp = __stringVal(newString); |
|
2862 | 2592 |
|
2887 | 2593 |
#ifdef bcopy4 |
9473 | 2594 |
{ |
2595 |
int nw = count >> 2; |
|
2596 |
char *srcp = (char *)__stringVal(self); |
|
2597 |
||
2598 |
if (count & 3) { |
|
2599 |
nw++; |
|
2600 |
} |
|
2601 |
bcopy4(srcp, dstp, nw); |
|
2602 |
dstp += count; |
|
2603 |
} |
|
608 | 2604 |
#else |
2887 | 2605 |
# ifdef FAST_MEMCPY |
9473 | 2606 |
memcpy(dstp, __stringVal(self), count); |
2607 |
dstp += count; |
|
608 | 2608 |
# else |
9473 | 2609 |
{ |
2610 |
REGISTER unsigned char *srcp; |
|
2611 |
||
2612 |
srcp = __stringVal(self); |
|
2613 |
while ((*dstp = *srcp++) != '\0') |
|
2614 |
dstp++; |
|
2615 |
} |
|
608 | 2616 |
# endif |
2887 | 2617 |
# endif |
9473 | 2618 |
*dstp++ = cVal; |
2619 |
*dstp = '\0'; |
|
2620 |
RETURN (newString ); |
|
2621 |
} |
|
2622 |
} |
|
608 | 2623 |
} |
2894 | 2624 |
#endif |
608 | 2625 |
%}. |
2626 |
"fall back in case of non-character arg; |
|
2627 |
will eventually lead to an bad element signal raise" |
|
2628 |
||
2629 |
^ super copyWith:aCharacter |
|
2630 |
! |
|
2631 |
||
2886 | 2632 |
deepCopy |
2633 |
"return a copy of the receiver" |
|
608 | 2634 |
|
2635 |
" |
|
2636 |
could be an instance of a subclass which needs deepCopy |
|
2637 |
of its named instvars ... |
|
2638 |
" |
|
2639 |
(self isMemberOf:String) ifTrue:[ |
|
9473 | 2640 |
^ self copyFrom:1 |
608 | 2641 |
]. |
2642 |
^ super deepCopy |
|
2643 |
! |
|
2644 |
||
10951 | 2645 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
8383 | 2646 |
"return a deep copy of the receiver - reimplemented to be a bit faster" |
608 | 2647 |
|
2648 |
" |
|
2649 |
could be an instance of a subclass which needs deepCopy |
|
2650 |
of its named instvars ... |
|
2651 |
" |
|
2652 |
(self isMemberOf:String) ifTrue:[ |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2653 |
^ self copyFrom:1 |
608 | 2654 |
]. |
10951 | 2655 |
^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector |
608 | 2656 |
! |
2657 |
||
2886 | 2658 |
shallowCopy |
2659 |
"return a copy of the receiver" |
|
608 | 2660 |
|
2661 |
(self isMemberOf:String) ifTrue:[ |
|
9473 | 2662 |
^ self copyFrom:1 |
608 | 2663 |
]. |
2664 |
^ super shallowCopy |
|
2665 |
! |
|
2666 |
||
2886 | 2667 |
simpleDeepCopy |
2668 |
"return a copy of the receiver" |
|
608 | 2669 |
|
2670 |
" |
|
2671 |
could be an instance of a subclass which needs deepCopy |
|
2672 |
of its named instvars ... |
|
2673 |
" |
|
2674 |
(self isMemberOf:String) ifTrue:[ |
|
9473 | 2675 |
^ self copyFrom:1 |
608 | 2676 |
]. |
7881 | 2677 |
^ super simpleDeepCopy |
608 | 2678 |
! ! |
2679 |
||
14384
1082868a753c
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14353
diff
changeset
|
2680 |
|
4154 | 2681 |
!String methodsFor:'filling & replacing'! |
608 | 2682 |
|
2886 | 2683 |
atAllPut:aCharacter |
608 | 2684 |
"replace all elements with aCharacter |
1 | 2685 |
- reimplemented here for speed" |
2686 |
||
13 | 2687 |
%{ /* NOCONTEXT */ |
2688 |
||
608 | 2689 |
#ifndef FAST_MEMSET |
2690 |
REGISTER unsigned char *dst; |
|
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
2691 |
#endif |
608 | 2692 |
REGISTER int l; |
2693 |
REGISTER int byteValue; |
|
1 | 2694 |
|
608 | 2695 |
if (__isCharacter(aCharacter) && __isString(self)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2696 |
byteValue = __intVal(__characterVal(aCharacter)); |
9473 | 2697 |
if ((unsigned)byteValue <= 0xFF) { |
2698 |
l = __stringSize(self); |
|
8898 | 2699 |
|
2700 |
#ifdef FAST_MEMSET |
|
9473 | 2701 |
if (l > 0) { |
2702 |
memset(__stringVal(self), byteValue, l); |
|
2703 |
} |
|
608 | 2704 |
#else |
9473 | 2705 |
{ |
2706 |
INT v; |
|
2707 |
||
2708 |
v = (byteValue << 8) | byteValue; |
|
2709 |
v = (v << 16) | v; |
|
2710 |
||
2711 |
dst = __stringVal(self); |
|
3712 | 2712 |
|
2713 |
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */ |
|
9473 | 2714 |
if (l > 0) { |
2715 |
memset4(dst, v, l>>2); |
|
2716 |
l = l & 3; |
|
2717 |
} |
|
3712 | 2718 |
# else |
2719 |
# ifdef UINT64 |
|
9473 | 2720 |
{ |
2721 |
UINT64 v64; |
|
2722 |
||
2723 |
v64 = v; |
|
2724 |
v64 = (v64 << 32) | v; |
|
2725 |
while (l >= 8) { |
|
2726 |
((UINT64 *)dst)[0] = v64; |
|
2727 |
dst += 8; |
|
2728 |
l -= 8; |
|
2729 |
} |
|
2730 |
} |
|
3712 | 2731 |
# else /* no UINT64 */ |
9473 | 2732 |
while (l >= 16) { |
2733 |
((int *)dst)[0] = v; |
|
2734 |
((int *)dst)[1] = v; |
|
2735 |
((int *)dst)[2] = v; |
|
2736 |
((int *)dst)[3] = v; |
|
2737 |
dst += 16; |
|
2738 |
l -= 16; |
|
2739 |
} |
|
2740 |
if (l >= 8) { |
|
2741 |
((int *)dst)[0] = v; |
|
2742 |
((int *)dst)[1] = v; |
|
2743 |
dst += 8; |
|
2744 |
l -= 8; |
|
2745 |
} |
|
2746 |
if (l >= 4) { |
|
2747 |
((int *)dst)[0] = v; |
|
2748 |
dst += 4; |
|
2749 |
l -= 4; |
|
2750 |
} |
|
3712 | 2751 |
# if 0 |
9473 | 2752 |
if (l >= 2) { |
2753 |
((short *)dst)[0] = v; |
|
2754 |
dst += 2; |
|
2755 |
l -= 2; |
|
2756 |
} |
|
3712 | 2757 |
# endif |
2758 |
||
5648 | 2759 |
# endif /* UINT64 */ |
2760 |
# endif /* FAST_MEMSET4 */ |
|
9473 | 2761 |
} |
2762 |
||
2763 |
/* |
|
2764 |
* remaining bytes |
|
2765 |
*/ |
|
2766 |
while (l-- > 0) |
|
2767 |
*dst++ = byteValue; |
|
3712 | 2768 |
|
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2769 |
#endif /* no FAST_MEMSET */ |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2770 |
|
9473 | 2771 |
RETURN ( self ); |
2772 |
} |
|
608 | 2773 |
} |
2862 | 2774 |
%}. |
608 | 2775 |
^ super atAllPut:aCharacter |
1 | 2776 |
|
608 | 2777 |
" |
8898 | 2778 |
(String new:10) atAllPut:$* |
2779 |
String new:10 withAll:$* |
|
608 | 2780 |
" |
2781 |
! |
|
2782 |
||
2929 | 2783 |
replaceAll:oldCharacter with:newCharacter |
4120 | 2784 |
"replace all oldCharacters by newCharacter in the receiver. |
2785 |
||
2786 |
Notice: This operation modifies the receiver, NOT a copy; |
|
2787 |
therefore the change may affect all others referencing the receiver." |
|
608 | 2788 |
|
2789 |
%{ /* NOCONTEXT */ |
|
2790 |
||
2791 |
REGISTER unsigned char *srcp; |
|
2792 |
REGISTER unsigned oldVal, newVal; |
|
4120 | 2793 |
unsigned char c, cNext; |
608 | 2794 |
|
2795 |
if (__isCharacter(oldCharacter) |
|
2796 |
&& __isCharacter(newCharacter) |
|
2797 |
&& __isString(self)) { |
|
16203 | 2798 |
srcp = (unsigned char *)__stringVal(self); |
2799 |
oldVal = __intVal(__characterVal(oldCharacter)); |
|
2800 |
newVal = __intVal(__characterVal(newCharacter)); |
|
2801 |
if ((oldVal <= 0xFF) |
|
2802 |
&& (newVal <= 0xFF)) { |
|
2803 |
cNext = *srcp; |
|
2804 |
while ((c = cNext) != '\0') { |
|
2805 |
cNext = srcp[1]; |
|
2806 |
if (c == oldVal) |
|
2807 |
*srcp = newVal; |
|
2808 |
srcp++; |
|
2809 |
} |
|
2810 |
} |
|
2811 |
RETURN ( self ); |
|
1 | 2812 |
} |
2862 | 2813 |
%}. |
16203 | 2814 |
newCharacter isCharacter ifFalse:[self halt:'please change the sender']. |
2929 | 2815 |
^ super replaceAll:oldCharacter with:newCharacter |
51 | 2816 |
|
608 | 2817 |
" |
8898 | 2818 |
'helloWorld' copy replaceAll:$o with:$O |
2819 |
'helloWorld' copy replaceAll:$d with:$* |
|
2820 |
'helloWorld' copy replaceAll:$h with:$* |
|
608 | 2821 |
" |
2822 |
! |
|
1 | 2823 |
|
2886 | 2824 |
replaceFrom:start to:stop with:aString startingAt:repStart |
1 | 2825 |
"replace the characters starting at index start, anInteger and ending |
2826 |
at stop, anInteger with characters from aString starting at repStart. |
|
3234 | 2827 |
Return the receiver. |
1 | 2828 |
|
2829 |
- reimplemented here for speed" |
|
2830 |
||
2831 |
%{ /* NOCONTEXT */ |
|
2832 |
||
2833 |
REGISTER unsigned char *srcp, *dstp; |
|
2834 |
REGISTER int count; |
|
2835 |
int len, index1, index2; |
|
2836 |
int repLen, repIndex; |
|
2837 |
||
2894 | 2838 |
#ifndef NO_PRIM_STRING |
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
2839 |
if (__isStringLike(aString) |
53 | 2840 |
&& __isString(self) |
252 | 2841 |
&& __bothSmallInteger(start, stop)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2842 |
len = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2843 |
index1 = __intVal(start); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2844 |
index2 = __intVal(stop); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2845 |
count = index2 - index1 + 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2846 |
if (count <= 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2847 |
RETURN (self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2848 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2849 |
if ((index2 <= len) && (index1 > 0)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2850 |
repLen = __stringSize(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2851 |
repIndex = __intVal(repStart); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2852 |
if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2853 |
srcp = __stringVal(aString) + repIndex - 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2854 |
dstp = __stringVal(self) + index1 - 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2855 |
if (aString == self) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2856 |
/* take care of overlapping copy */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2857 |
if (srcp < dstp) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2858 |
/* must do a reverse copy */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2859 |
srcp += count; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2860 |
dstp += count; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2861 |
while (count-- > 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2862 |
*--dstp = *--srcp; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2863 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2864 |
RETURN (self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2865 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2866 |
} |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2867 |
#ifdef bcopy4 |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2868 |
/* copy quadbytes if pointers are aligned */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2869 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2870 |
* no sizeof(int) here please - |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2871 |
* - bcopy4 (if defined) copies 4-bytes on ALL machines |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2872 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2873 |
if ((count > 12) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2874 |
&& (((unsigned INT)srcp & 3) == 0) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2875 |
&& (((unsigned INT)dstp & 3) == 0)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2876 |
int n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2877 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2878 |
n = count >> 2; /* make it quads */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2879 |
bcopy4(srcp, dstp, n); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2880 |
n <<= 2; /* back to chars */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2881 |
dstp += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2882 |
srcp += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2883 |
count -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2884 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2885 |
while (count-- > 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2886 |
*dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2887 |
} |
1 | 2888 |
#else |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2889 |
# ifdef FAST_MEMCPY |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2890 |
bcopy(srcp, dstp, count); |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2891 |
# else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2892 |
/* copy longs if pointers are aligned */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2893 |
if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2894 |
&& (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2895 |
while (count >= sizeof(INT)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2896 |
*((unsigned INT *)dstp) = *((unsigned INT *)srcp); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2897 |
dstp += sizeof(INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2898 |
srcp += sizeof(INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2899 |
count -= sizeof(INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2900 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2901 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2902 |
while (count-- > 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2903 |
*dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2904 |
} |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2905 |
# endif |
1 | 2906 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2907 |
RETURN (self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2908 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2909 |
} |
1 | 2910 |
} |
2894 | 2911 |
#endif |
2862 | 2912 |
%}. |
1 | 2913 |
^ super replaceFrom:start to:stop with:aString startingAt:repStart |
2914 |
! |
|
2915 |
||
2916 |
withoutSeparators |
|
8898 | 2917 |
"return a string containing the chars of myself |
2862 | 2918 |
without leading and trailing whitespace. |
2919 |
If there is no whitespace, the receiver is returned. |
|
95 | 2920 |
Notice, this is different from String>>withoutSpaces." |
1 | 2921 |
|
42 | 2922 |
|startIndex "{ Class: SmallInteger }" |
8898 | 2923 |
endIndex "{ Class: SmallInteger }" |
51 | 2924 |
sz| |
2925 |
||
53 | 2926 |
startIndex := 0. |
2862 | 2927 |
|
51 | 2928 |
%{ |
2884 | 2929 |
REGISTER unsigned char *cp; |
2930 |
REGISTER unsigned char *ep; |
|
2931 |
REGISTER unsigned char c; |
|
51 | 2932 |
REGISTER unsigned char *cp0; |
2884 | 2933 |
REGISTER unsigned char *ep0; |
1 | 2934 |
|
51 | 2935 |
/* ignore instances of subclasses ... */ |
329 | 2936 |
if (__qClass(self) == String) { |
9473 | 2937 |
cp = cp0 = __stringVal(self); |
2938 |
||
2939 |
/* |
|
2940 |
* find first non-whiteSpace from beginning |
|
2941 |
*/ |
|
2862 | 2942 |
#ifndef NON_ASCII |
2954 | 2943 |
# ifdef UINT64 |
9473 | 2944 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
2945 |
cp += 8; |
|
2946 |
} |
|
2862 | 2947 |
# endif |
9473 | 2948 |
while (*((unsigned *)cp) == 0x20202020) { |
2949 |
cp += 4; |
|
2950 |
} |
|
2862 | 2951 |
#endif |
9473 | 2952 |
while ((c = *cp) |
329 | 2953 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
9473 | 2954 |
&& (c <= ' ') |
329 | 2955 |
#endif |
9473 | 2956 |
&& ((c == ' ') || (c == '\n') || (c == '\t') |
2957 |
|| (c == '\r') || (c == '\f')) |
|
2958 |
) { |
|
2959 |
cp++; |
|
2960 |
} |
|
2961 |
||
2962 |
/* |
|
2963 |
* find first non-whiteSpace from end |
|
2964 |
*/ |
|
2965 |
ep = ep0 = cp0 + __stringSize(self) - 1; |
|
2966 |
while ((ep >= cp) && (*ep == ' ')) ep--; |
|
2967 |
c = *ep; |
|
2968 |
while ((ep >= cp) && |
|
2862 | 2969 |
#ifndef NON_ASCII |
9473 | 2970 |
(c <= ' ') && |
329 | 2971 |
#endif |
9473 | 2972 |
((c == ' ') || (c == '\n') || (c == '\t') |
2973 |
|| (c == '\r') || (c == '\f'))) { |
|
2974 |
ep--; |
|
2975 |
c = *ep; |
|
2976 |
} |
|
2977 |
||
2978 |
/* |
|
2979 |
* no whiteSpace ? |
|
2980 |
*/ |
|
2981 |
if ((cp == cp0) && (ep == ep0)) { |
|
2982 |
RETURN(self); |
|
2983 |
} |
|
2984 |
||
2985 |
startIndex = __mkSmallInteger(cp - cp0 + 1); |
|
2986 |
endIndex = __mkSmallInteger(ep - cp0 + 1); |
|
51 | 2987 |
} |
202 | 2988 |
%}. |
2989 |
startIndex == 0 ifTrue:[^ super withoutSeparators]. |
|
2990 |
||
2991 |
startIndex > endIndex ifTrue:[^ '']. |
|
1 | 2992 |
^ self copyFrom:startIndex to:endIndex |
2884 | 2993 |
|
2994 |
" |
|
8898 | 2995 |
'hello' withoutSeparators |
2996 |
' hello' withoutSeparators |
|
2997 |
' hello ' withoutSeparators |
|
2998 |
' hello ' withoutSeparators |
|
2999 |
' hello ' withoutSeparators |
|
2884 | 3000 |
' hello ' withoutSeparators |
8898 | 3001 |
' ' withoutSeparators |
2884 | 3002 |
" |
3003 |
||
608 | 3004 |
! |
3005 |
||
3006 |
withoutSpaces |
|
8898 | 3007 |
"return a string containing the characters of myself |
2862 | 3008 |
without leading and trailing spaces. |
2884 | 3009 |
If there are no spaces, the receiver is returned unchanged. |
608 | 3010 |
Notice, this is different from String>>withoutSeparators." |
3011 |
||
3012 |
|startIndex "{ Class: SmallInteger }" |
|
8898 | 3013 |
endIndex "{ Class: SmallInteger }" |
608 | 3014 |
sz blank| |
3015 |
||
3016 |
startIndex := 0. |
|
3017 |
%{ |
|
3018 |
REGISTER unsigned char *cp; |
|
2884 | 3019 |
REGISTER unsigned char *ep; |
3020 |
unsigned char *cp0; |
|
3021 |
unsigned char *ep0; |
|
608 | 3022 |
|
3023 |
/* ignore instances of subclasses ... */ |
|
3024 |
if (__qClass(self) == String) { |
|
9473 | 3025 |
cp = cp0 = __stringVal(self); |
3026 |
||
3027 |
/* |
|
3028 |
* find first non-blank from beginning |
|
3029 |
*/ |
|
2862 | 3030 |
#ifndef NON_ASCII |
2954 | 3031 |
# ifdef UINT64 |
9473 | 3032 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
3033 |
cp += 8; |
|
3034 |
} |
|
2954 | 3035 |
# endif /* UINT64 */ |
9473 | 3036 |
while (*((unsigned *)cp) == 0x20202020) { |
3037 |
cp += 4; |
|
3038 |
} |
|
2862 | 3039 |
#endif |
9473 | 3040 |
while (*cp == ' ') cp++; |
3041 |
||
3042 |
/* |
|
3043 |
* find first non-blank from end |
|
3044 |
*/ |
|
3045 |
ep = ep0 = cp0 + __stringSize(self) - 1; |
|
3046 |
while ((ep >= cp) && (*ep == ' ')) ep--; |
|
3047 |
||
3048 |
/* |
|
3049 |
* no blanks ? |
|
3050 |
*/ |
|
3051 |
if ((cp == cp0) && (ep == ep0)) { |
|
3052 |
RETURN(self); |
|
3053 |
} |
|
3054 |
||
3055 |
startIndex = __mkSmallInteger(cp - cp0 + 1); |
|
3056 |
endIndex = __mkSmallInteger(ep - cp0 + 1); |
|
608 | 3057 |
} |
3058 |
%}. |
|
3059 |
startIndex == 0 ifTrue:[^ super withoutSpaces]. |
|
3060 |
||
3061 |
startIndex > endIndex ifTrue:[^ '']. |
|
2886 | 3062 |
((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self]. |
608 | 3063 |
^ self copyFrom:startIndex to:endIndex |
2884 | 3064 |
|
3065 |
" |
|
8898 | 3066 |
' hello' withoutSpaces |
3067 |
' hello ' withoutSpaces |
|
3068 |
' hello ' withoutSpaces |
|
3069 |
' hello ' withoutSpaces |
|
2884 | 3070 |
' hello ' withoutSpaces |
8898 | 3071 |
' ' withoutSpaces |
2884 | 3072 |
" |
608 | 3073 |
! ! |
3074 |
||
3075 |
!String methodsFor:'printing & storing'! |
|
3076 |
||
16393 | 3077 |
displayString |
3078 |
"return a string used when displaying the receiver in a view." |
|
3079 |
||
3080 |
^ self. |
|
3081 |
! |
|
3082 |
||
14163 | 3083 |
errorPrint |
15536 | 3084 |
"print the receiver on standard error, if the global Stderr is nil; |
3085 |
otherwise, fall back to the inherited errorPrint, which sends the string to |
|
3086 |
the Stderr stream. |
|
14163 | 3087 |
This method does NOT (by purpose) use the stream classes and |
15536 | 3088 |
will therefore work even in case of emergency during early startup |
3089 |
(but only, as long as Stderr is nil, which is set later after startup)." |
|
14163 | 3090 |
|
3091 |
%{ /* NOCONTEXT */ |
|
3092 |
||
15440 | 3093 |
if (@global(Stderr) == nil) { |
16253 | 3094 |
if (__qIsStringLike(self)) { |
3095 |
console_fprintf(stderr, "%s" , __stringVal(self)); |
|
3096 |
console_fflush(stderr); |
|
3097 |
RETURN (self); |
|
3098 |
} |
|
14163 | 3099 |
} |
3100 |
%}. |
|
16253 | 3101 |
super errorPrint |
14664 | 3102 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3103 |
" |
14664 | 3104 |
'hello world' asUnicode16String errorPrint |
3105 |
(Character value:356) asString errorPrint |
|
14968 | 3106 |
'Bönnigheim' errorPrint |
3107 |
'Bönnigheim' asUnicodeString errorPrint |
|
14664 | 3108 |
" |
14163 | 3109 |
! |
3110 |
||
3111 |
errorPrintCR |
|
15536 | 3112 |
"print the receiver on standard error, followed by a cr, |
3113 |
if the global Stderr is nil; otherwise, fall back to the inherited errorPrintCR, |
|
3114 |
which sends the string to the Stderr stream. |
|
14163 | 3115 |
This method does NOT (by purpose) use the stream classes and |
15536 | 3116 |
will therefore work even in case of emergency during early startup |
3117 |
(but only, as long as Stderr is nil, which is set later after startup)." |
|
14163 | 3118 |
|
3119 |
%{ /* NOCONTEXT */ |
|
3120 |
||
15440 | 3121 |
if (@global(Stderr) == nil) { |
16253 | 3122 |
if (__qIsStringLike(self)) { |
3123 |
console_fprintf(stderr, "%s\n" , __stringVal(self)); |
|
3124 |
console_fflush(stderr); |
|
3125 |
RETURN (self); |
|
3126 |
} |
|
14163 | 3127 |
} |
3128 |
%}. |
|
16253 | 3129 |
super errorPrintCR |
14163 | 3130 |
! |
3131 |
||
2886 | 3132 |
|
15536 | 3133 |
"print the receiver on standard output, if the global Stdout is nil; |
3134 |
otherwise, fall back to the inherited errorPrint, which sends the string to |
|
3135 |
the Stdout stream. |
|
8898 | 3136 |
This method does NOT (by purpose) use the stream classes and |
15536 | 3137 |
will therefore work even in case of emergency during early startup |
3138 |
(but only, as long as Stdout is nil, which is set later after startup)." |
|
608 | 3139 |
|
3140 |
%{ /* NOCONTEXT */ |
|
3141 |
||
15440 | 3142 |
if (@global(Stdout) == nil) { |
16253 | 3143 |
if (__qIsStringLike(self)) { |
3144 |
console_fprintf(stdout, "%s" , __stringVal(self)); |
|
3145 |
console_fflush(stdout); |
|
3146 |
RETURN (self); |
|
3147 |
} |
|
608 | 3148 |
} |
3751 | 3149 |
%}. |
16253 | 3150 |
super print |
608 | 3151 |
! |
3152 |
||
3751 | 3153 |
printCR |
15536 | 3154 |
"print the receiver on standard output, followed by a cr, |
3155 |
if the global Stdout is nil; otherwise, fall back to the inherited errorPrintCR, |
|
3156 |
which sends the string to the Stdout stream. |
|
8898 | 3157 |
This method does NOT (by purpose) use the stream classes and |
15536 | 3158 |
will therefore work even in case of emergency during early startup |
3159 |
(but only, as long as Stdout is nil, which is set later after startup)." |
|
3751 | 3160 |
|
3161 |
%{ /* NOCONTEXT */ |
|
3162 |
||
15440 | 3163 |
if (@global(Stdout) == nil) { |
16253 | 3164 |
if (__qIsStringLike(self)) { |
3165 |
console_fprintf(stdout, "%s\n" , __stringVal(self)); |
|
3166 |
console_fflush(stdout); |
|
3167 |
RETURN (self); |
|
3168 |
} |
|
3751 | 3169 |
} |
3170 |
%}. |
|
16253 | 3171 |
super printCR |
3751 | 3172 |
! |
3173 |
||
2886 | 3174 |
printfPrintString:formatString |
7746 | 3175 |
"non-standard but sometimes useful. |
8898 | 3176 |
Return a printed representation of the receiver as specified by formatString, |
608 | 3177 |
which is defined by printf. |
11921 | 3178 |
This method is NONSTANDARD and may be removed without notice. |
15536 | 3179 |
WARNNG: this goes directly to the C-printf function and may therefore be inherently unsafe. |
11921 | 3180 |
Please use the printf: method, which is safe as it is completely implemented in Smalltalk." |
608 | 3181 |
|
3182 |
%{ /* STACK: 1000 */ |
|
3183 |
||
3184 |
char buffer[800]; |
|
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3185 |
char *buf = buffer; |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3186 |
int bufsize = sizeof(buffer); |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3187 |
char *mallocbuf = NULL; |
608 | 3188 |
char *cp; |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3189 |
int len; |
608 | 3190 |
OBJ s; |
8898 | 3191 |
extern void *malloc(); |
608 | 3192 |
|
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
3193 |
if (__isStringLike(formatString)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3194 |
cp = (char *)__stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3195 |
if (__qClass(self) != String) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3196 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3197 |
} |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3198 |
again: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3199 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3200 |
* actually only needed on sparc: since thisContext is |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3201 |
* in a global register, which gets destroyed by printf, |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3202 |
* manually save it here - very stupid ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3203 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3204 |
__BEGIN_PROTECT_REGISTERS__ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3205 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3206 |
len = snprintf(buf, bufsize, (char *)__stringVal(formatString), cp); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3207 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3208 |
__END_PROTECT_REGISTERS__ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3209 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3210 |
if ((len < 0) || (len > bufsize)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3211 |
if (len < 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3212 |
bufsize = bufsize * 2; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3213 |
} else { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3214 |
bufsize = len + 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3215 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3216 |
if (mallocbuf) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3217 |
free(mallocbuf); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3218 |
buf = mallocbuf = malloc(bufsize); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3219 |
if (buf == NULL) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3220 |
goto fail; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3221 |
goto again; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3222 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3223 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3224 |
s = __MKSTRING_L(buf, len); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3225 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3226 |
if (mallocbuf) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3227 |
free(mallocbuf); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3228 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3229 |
if (s != nil) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3230 |
RETURN (s); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3231 |
} |
608 | 3232 |
} |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3233 |
fail:; |
608 | 3234 |
%}. |
3235 |
self primitiveFailed |
|
3236 |
||
3237 |
" |
|
8898 | 3238 |
'hello' printfPrintString:'%%s -> %s' |
3239 |
(String new:900) printfPrintString:'%%s -> %s' |
|
3240 |
'hello' printfPrintString:'%%10s -> %10s' |
|
3241 |
'hello' printfPrintString:'%%-10s -> %-10s' |
|
3242 |
'hello' printfPrintString:'%%900s -> %900s' |
|
3243 |
'hello' printfPrintString:'%%-900s -> %-900s' |
|
608 | 3244 |
" |
3245 |
! |
|
3246 |
||
2886 | 3247 |
storeOn:aStream |
608 | 3248 |
"put the storeString of myself on aStream" |
3249 |
||
7599
188489aaaacd
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7338
diff
changeset
|
3250 |
aStream nextPut:$'. |
608 | 3251 |
(self includes:$') ifTrue:[ |
9473 | 3252 |
self printWithQuotesDoubledOn:aStream |
608 | 3253 |
] ifFalse:[ |
9473 | 3254 |
aStream nextPutAll:self |
608 | 3255 |
]. |
3256 |
aStream nextPut:$' |
|
3579 | 3257 |
|
3258 |
"Modified: / 15.6.1998 / 17:21:51 / cg" |
|
608 | 3259 |
! |
3260 |
||
2886 | 3261 |
storeString |
3262 |
"return a String for storing myself" |
|
608 | 3263 |
|
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8038
diff
changeset
|
3264 |
^ self basicStoreString. |
1 | 3265 |
! ! |
3266 |
||
3267 |
!String methodsFor:'queries'! |
|
3268 |
||
5557 | 3269 |
basicSize |
3270 |
"return the number of characters in myself. |
|
3271 |
Redefined here to exclude the 0-byte at the end." |
|
3272 |
||
3273 |
%{ /* NOCONTEXT */ |
|
3274 |
REGISTER OBJ slf, cls; |
|
3275 |
||
3276 |
slf = self; |
|
3277 |
||
3278 |
cls = __qClass(slf); |
|
3279 |
if (cls == String) { |
|
9473 | 3280 |
RETURN ( __mkSmallInteger(__stringSize(slf)) ); |
5557 | 3281 |
} |
8913 | 3282 |
RETURN ( __mkSmallInteger(__stringSize(slf) |
9473 | 3283 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
5557 | 3284 |
%}. |
3285 |
^ super basicSize - 1 |
|
3286 |
||
3287 |
! |
|
3288 |
||
2886 | 3289 |
bitsPerCharacter |
1239 | 3290 |
"return the number of bits each character has. |
3291 |
Here, 8 is returned (storing single byte characters)." |
|
3292 |
||
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
3293 |
^ 8 |
1239 | 3294 |
|
3295 |
"Modified: 20.4.1996 / 23:08:42 / cg" |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
3296 |
! |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
3297 |
|
8458 | 3298 |
contains8BitCharacters |
8898 | 3299 |
"return true, if the underlying string contains 8BitCharacters (or widers) |
8458 | 3300 |
(i.e. if it is non-ascii)" |
3301 |
||
3302 |
%{ /* NOCONTEXT */ |
|
3303 |
||
3304 |
REGISTER unsigned char *cp; |
|
3305 |
REGISTER unsigned char *last; |
|
3306 |
OBJ cls; |
|
3307 |
||
3308 |
cp = __stringVal(self); |
|
8915
eb2652ce257d
fixed includes/indexOf for subclasses of string with instVars;
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
3309 |
last = cp + __stringSize(self); |
8458 | 3310 |
if ((cls = __qClass(self)) != String) { |
10352 | 3311 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
9268
0d06a0818b52
contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents:
9233
diff
changeset
|
3312 |
} |
10371 | 3313 |
#if __POINTER_SIZE__ == 8 |
3314 |
/* assume sizeof(long) == 4 |
|
3315 |
* if __POINTER_SIZE__ == 4 |
|
3316 |
*/ |
|
9268
0d06a0818b52
contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents:
9233
diff
changeset
|
3317 |
if (sizeof(long) == 8) { |
10352 | 3318 |
while ((cp+8) <= last) { |
3319 |
if (*(unsigned long *)cp & 0x8080808080808080) { |
|
3320 |
RETURN ( true ); |
|
3321 |
} |
|
3322 |
cp += 8; |
|
3323 |
} |
|
8458 | 3324 |
} |
10371 | 3325 |
#endif |
9268
0d06a0818b52
contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents:
9233
diff
changeset
|
3326 |
if (sizeof(int) == 4) { |
10352 | 3327 |
while ((cp+4) <= last) { |
3328 |
if (*(unsigned int *)cp & 0x80808080) { |
|
3329 |
RETURN ( true ); |
|
3330 |
} |
|
3331 |
cp += 4; |
|
3332 |
} |
|
9268
0d06a0818b52
contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents:
9233
diff
changeset
|
3333 |
} |
0d06a0818b52
contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents:
9233
diff
changeset
|
3334 |
while ((cp+2) <= last) { |
10352 | 3335 |
if (*(unsigned short *)cp & 0x8080) { |
3336 |
RETURN ( true ); |
|
3337 |
} |
|
3338 |
cp += 2; |
|
8915
eb2652ce257d
fixed includes/indexOf for subclasses of string with instVars;
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
3339 |
} |
eb2652ce257d
fixed includes/indexOf for subclasses of string with instVars;
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
3340 |
while (cp < last) { |
10352 | 3341 |
if (*cp & 0x80) { |
3342 |
RETURN ( true ); |
|
3343 |
} |
|
3344 |
cp++; |
|
8458 | 3345 |
} |
3346 |
RETURN (false); |
|
3347 |
%}. |
|
3348 |
||
3349 |
" |
|
8898 | 3350 |
'hello world' contains8BitCharacters |
3351 |
'hello world' asTwoByteString contains8BitCharacters |
|
3352 |
('hello world' , (Character value:16r88) asString) contains8BitCharacters |
|
8458 | 3353 |
" |
3354 |
! |
|
3355 |
||
14556 | 3356 |
isWideString |
3357 |
^ false |
|
3358 |
! |
|
3359 |
||
2886 | 3360 |
knownAsSymbol |
3361 |
"return true, if there is a symbol with same characters in the |
|
2862 | 3362 |
system. |
3363 |
Can be used to check for existance of a symbol without creating one" |
|
608 | 3364 |
|
3365 |
%{ /* NOCONTEXT */ |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3366 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3367 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3368 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3369 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3370 |
if (cls != String) { |
9473 | 3371 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3372 |
} else { |
9473 | 3373 |
indx = 0; |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3374 |
} |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3375 |
RETURN ( __KNOWNASSYMBOL(__stringVal(self) + indx) ); |
5407 | 3376 |
%}. |
6007 | 3377 |
"/ ^ self asSymbolIfInterned notNil. |
5407 | 3378 |
self primitiveFailed |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3379 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3380 |
" |
8898 | 3381 |
'hello' knownAsSymbol |
3382 |
'fooBarBaz' knownAsSymbol |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3383 |
" |
5557 | 3384 |
! |
3385 |
||
10820 | 3386 |
referencesAny:aCollection |
10822 | 3387 |
"redefined to speed up searching when many string instances are present" |
3388 |
||
10820 | 3389 |
self class == String ifTrue:[^ false]. |
3390 |
^ super referencesAny:aCollection |
|
3391 |
! |
|
3392 |
||
5557 | 3393 |
size |
3394 |
"return the number of characters in myself. |
|
3395 |
Reimplemented here to avoid the additional size->basicSize send |
|
3396 |
(which we can do here, since size is obviously not redefined in a subclass). |
|
3397 |
This method is the same as basicSize." |
|
3398 |
||
3399 |
%{ /* NOCONTEXT */ |
|
3400 |
REGISTER OBJ cls, slf; |
|
3401 |
||
3402 |
slf = self; |
|
3403 |
cls = __qClass(slf); |
|
3404 |
if (cls == String) { |
|
9473 | 3405 |
RETURN ( __mkSmallInteger(__stringSize(slf)) ); |
5557 | 3406 |
} |
8913 | 3407 |
RETURN ( __mkSmallInteger(__stringSize(slf) |
9473 | 3408 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
5557 | 3409 |
%}. |
3410 |
^ self basicSize |
|
8038 | 3411 |
! |
3412 |
||
3413 |
stringSpecies |
|
15525 | 3414 |
^ self species |
1 | 3415 |
! ! |
608 | 3416 |
|
11267 | 3417 |
!String methodsFor:'sorting & reordering'! |
3418 |
||
3419 |
reverse |
|
3420 |
"in-place reverse the characters of the string. |
|
3421 |
WARNING: this is a destructive operation, which modifies the receiver. |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3422 |
Please use reversed (with a d) for a functional version." |
11267 | 3423 |
|
3424 |
"Q: is there a need to redefine it here ?" |
|
3425 |
||
3426 |
%{ /* NOCONTEXT */ |
|
3427 |
||
3428 |
REGISTER char c; |
|
3429 |
REGISTER unsigned char *hip, *lowp; |
|
3430 |
||
3431 |
if (__isString(self)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3432 |
lowp = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3433 |
hip = lowp + __stringSize(self) - 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3434 |
while (lowp < hip) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3435 |
c = *lowp; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3436 |
*lowp = *hip; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3437 |
*hip = c; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3438 |
lowp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3439 |
hip--; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3440 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3441 |
RETURN ( self ); |
11267 | 3442 |
} |
3443 |
%}. |
|
3444 |
^ super reverse |
|
3445 |
! ! |
|
10820 | 3446 |
|
16253 | 3447 |
|
11346 | 3448 |
!String methodsFor:'substring searching'! |
3449 |
||
3450 |
indexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive |
|
11347
7819f5148ca1
Boyer Moore algorithm for fast string search.
Claus Gittinger <cg@exept.de>
parents:
11346
diff
changeset
|
3451 |
"redefined as primitive for maximum speed (BM)" |
11346 | 3452 |
|
3453 |
|notFound| |
|
3454 |
||
14384
1082868a753c
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14353
diff
changeset
|
3455 |
%{ /* STACK:4000 */ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3456 |
if (__qIsStringLike(self) |
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
3457 |
&& __isStringLike(aSubString) |
11346 | 3458 |
&& (caseSensitive == true) |
3459 |
&& (__isSmallInteger(startIndex)) |
|
3460 |
&& (__intVal(startIndex) > 0) |
|
3461 |
) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3462 |
unsigned char *y = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3463 |
unsigned char *x = __stringVal(aSubString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3464 |
int m = __stringSize(aSubString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3465 |
int n = __stringSize(self); |
14301
d8e7b4196d5e
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14297
diff
changeset
|
3466 |
# define MAX_PATTERN_SIZE 128 |
11346 | 3467 |
# define XSIZE 256 |
3468 |
# define ASIZE 256 |
|
3469 |
# define MAX(a,b) (a>b ? a : b) |
|
3470 |
||
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3471 |
if (m == 0) { |
11824
20754d2d3b37
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11418
diff
changeset
|
3472 |
#if 1 |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3473 |
/* empty string does not match */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3474 |
RETURN(__mkSmallInteger(0)); |
11824
20754d2d3b37
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11418
diff
changeset
|
3475 |
#else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3476 |
/* empty string matches */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3477 |
RETURN(startIndex); |
11824
20754d2d3b37
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11418
diff
changeset
|
3478 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3479 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3480 |
if (m <= XSIZE) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3481 |
int i, j; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3482 |
static int lastPatternSize = 0; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3483 |
static char lastPattern[MAX_PATTERN_SIZE+1] = { 0 }; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3484 |
static int bmGs[XSIZE+1], bmBc[ASIZE]; |
11346 | 3485 |
|
3486 |
# define preBmBc(x, m, bmBc) { \ |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3487 |
int i; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3488 |
\ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3489 |
for (i = 0; i < ASIZE; ++i) \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3490 |
bmBc[i] = m; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3491 |
for (i = 0; i < m - 1; ++i) \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3492 |
bmBc[x[i]] = m - i - 1; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3493 |
} |
11346 | 3494 |
|
3495 |
# define suffixes(x, m, suff) { \ |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3496 |
int f, g, i; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3497 |
\ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3498 |
suff[m - 1] = m; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3499 |
g = m - 1; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3500 |
for (i = m - 2; i >= 0; --i) { \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3501 |
if (i > g && suff[i + m - 1 - f] < i - g) \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3502 |
suff[i] = suff[i + m - 1 - f]; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3503 |
else { \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3504 |
if (i < g) \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3505 |
g = i; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3506 |
f = i; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3507 |
while (g >= 0 && x[g] == x[g + m - 1 - f]) \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3508 |
--g; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3509 |
suff[i] = f - g; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3510 |
} \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3511 |
} \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3512 |
} |
11346 | 3513 |
|
3514 |
# define preBmGs(x, m, bmGs) { \ |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3515 |
int i, j, suff[XSIZE]; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3516 |
\ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3517 |
suffixes(x, m, suff); \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3518 |
\ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3519 |
for (i = 0; i < m; ++i) \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3520 |
bmGs[i] = m; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3521 |
j = 0; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3522 |
for (i = m - 1; i >= 0; --i) \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3523 |
if (suff[i] == i + 1) \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3524 |
for (; j < m - 1 - i; ++j) \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3525 |
if (bmGs[j] == m) \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3526 |
bmGs[j] = m - 1 - i; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3527 |
for (i = 0; i <= m - 2; ++i) \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3528 |
bmGs[m - 1 - suff[i]] = m - 1 - i; \ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3529 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3530 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3531 |
/* tables only depend on pattern; so we can cache them in case the same string is searched again */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3532 |
if ((m == lastPatternSize) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3533 |
&& (strcmp(lastPattern, x) == 0)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3534 |
/* tables are still valid */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3535 |
// printf("valid: \"%s\"\n", lastPattern); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3536 |
} else { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3537 |
/* Preprocessing */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3538 |
// printf("compute: \"%s\"\n", lastPattern); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3539 |
preBmGs(x, m, bmGs); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3540 |
preBmBc(x, m, bmBc); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3541 |
if (m <= MAX_PATTERN_SIZE) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3542 |
// printf("cache for: \"%s\"\n", lastPattern); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3543 |
strcpy(lastPattern, x); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3544 |
lastPatternSize = m; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3545 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3546 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3547 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3548 |
/* Searching */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3549 |
j = __intVal(startIndex) - 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3550 |
while (j <= n - m) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3551 |
for (i = m - 1; i >= 0 && x[i] == y[i + j]; --i); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3552 |
if (i < 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3553 |
RETURN (__mkSmallInteger(j+1)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3554 |
j += bmGs[0]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3555 |
} else { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3556 |
int s1 = bmGs[i]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3557 |
int s2 = bmBc[y[i + j]] - m + 1 + i; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3558 |
j += MAX(s1, s2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3559 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3560 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3561 |
notFound = true; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3562 |
} |
11346 | 3563 |
} |
3564 |
%}. |
|
3565 |
notFound == true ifTrue:[ |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3566 |
^ exceptionValue value. |
11346 | 3567 |
]. |
3568 |
^ super indexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive |
|
14301
d8e7b4196d5e
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14297
diff
changeset
|
3569 |
|
d8e7b4196d5e
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14297
diff
changeset
|
3570 |
"Modified: / 05-08-2012 / 12:27:31 / cg" |
11346 | 3571 |
! ! |
3572 |
||
608 | 3573 |
!String methodsFor:'testing'! |
3574 |
||
2886 | 3575 |
endsWith:aStringOrChar |
16174 | 3576 |
"return true, if the receiver ends with something, aStringOrChar. |
3577 |
If aStringOrChar is an empty string, true is returned" |
|
1380 | 3578 |
|
3579 |
%{ /* NOCONTEXT */ |
|
3580 |
||
3581 |
int len1, len2; |
|
3582 |
REGISTER unsigned char *src1, *src2; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
3583 |
unsigned char c; |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3584 |
REGISTER OBJ slf = self; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3585 |
|
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
3586 |
if (__isStringLike(slf) && __isStringLike(aStringOrChar)) { |
16174 | 3587 |
len1 = __qSize(slf); |
3588 |
len2 = __qSize(aStringOrChar); |
|
3589 |
if (len1 < len2) { |
|
3590 |
RETURN ( false ); |
|
3591 |
} |
|
3592 |
||
3593 |
src1 = __stringVal(slf) + (len1 - len2); |
|
3594 |
src2 = __stringVal(aStringOrChar); |
|
3595 |
while (c = *src2++) { |
|
3596 |
if (c != *src1++) { |
|
3597 |
RETURN ( false ); |
|
3598 |
} |
|
3599 |
} |
|
3600 |
RETURN (true); |
|
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3601 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3602 |
if (__isCharacter(aStringOrChar)) { |
16174 | 3603 |
int val; |
3604 |
||
3605 |
val = __intVal(__characterVal(aStringOrChar)); |
|
3606 |
if ((unsigned)val <= 0xFF) { |
|
3607 |
len1 = __stringSize(slf); |
|
3608 |
if (len1 > 0) { |
|
3609 |
RETURN ( (__stringVal(slf)[len1-1] == val) ? true : false); |
|
3610 |
} |
|
3611 |
} |
|
3612 |
RETURN ( false ); |
|
1380 | 3613 |
} |
3614 |
%}. |
|
2862 | 3615 |
^ super endsWith:aStringOrChar |
1380 | 3616 |
|
3617 |
" |
|
3618 |
'hello world' endsWith:'world' |
|
3619 |
'hello world' endsWith:'earth' |
|
8898 | 3620 |
'hello world' endsWith:$d |
3621 |
'hello world' endsWith:$e |
|
3622 |
'' endsWith:$d |
|
1380 | 3623 |
'hello world' endsWith:#($r $l $d) |
8898 | 3624 |
'hello world' endsWith:'' |
1380 | 3625 |
" |
3626 |
! |
|
3627 |
||
2886 | 3628 |
isBlank |
3629 |
"return true, if the receivers size is 0 or if it contains only spaces. |
|
608 | 3630 |
Q: should we care for whiteSpace in general here ?" |
3631 |
||
3632 |
%{ /* NOCONTEXT */ |
|
3633 |
||
3634 |
REGISTER unsigned char *src; |
|
3635 |
REGISTER unsigned char c; |
|
3636 |
OBJ cls; |
|
3637 |
||
1134 | 3638 |
src = __stringVal(self); |
608 | 3639 |
if ((cls = __qClass(self)) != String) |
9473 | 3640 |
src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
608 | 3641 |
|
3642 |
#ifndef NON_ASCII |
|
2954 | 3643 |
# ifdef UINT64 |
3644 |
while (*((UINT64 *)src) == 0x2020202020202020L) { |
|
9473 | 3645 |
src += 8; |
2862 | 3646 |
} |
2954 | 3647 |
# endif /* UINT64 */ |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3648 |
|
608 | 3649 |
while (*((unsigned *)src) == 0x20202020) { |
9473 | 3650 |
src += 4; |
608 | 3651 |
} |
2862 | 3652 |
#endif /* ascii */ |
3653 |
||
3654 |
while (c = *src++) { |
|
9473 | 3655 |
if (c != ' ') { |
3656 |
RETURN ( false ); |
|
3657 |
} |
|
2862 | 3658 |
} |
5407 | 3659 |
RETURN ( true ); |
608 | 3660 |
%}. |
5407 | 3661 |
^ super isBlank |
608 | 3662 |
! |
3663 |
||
5556 | 3664 |
isEmpty |
3665 |
"return true if the receiver is empty (i.e. if size == 0) |
|
3666 |
Redefined here for performance" |
|
3667 |
||
3668 |
%{ /* NOCONTEXT */ |
|
3669 |
OBJ cls; |
|
3670 |
||
3671 |
cls = __qClass(self); |
|
3672 |
if ((cls == String) || (cls == Symbol)) { |
|
9473 | 3673 |
RETURN ( (__stringSize(self) == 0) ? true : false); |
5556 | 3674 |
} |
3675 |
%}. |
|
3676 |
^ self size == 0 |
|
3677 |
! |
|
3678 |
||
10958 | 3679 |
isLiteral |
3680 |
"return true, if the receiver can be used as a literal constant in ST syntax |
|
3681 |
(i.e. can be used in constant arrays)" |
|
3682 |
||
3683 |
^ true |
|
3684 |
! |
|
3685 |
||
8647 | 3686 |
levenshteinTo:aString s:substWeight k:kbdTypoWeight c:caseWeight i:insrtWeight d:deleteWeight |
608 | 3687 |
"parametrized levenshtein. arguments are the costs for |
3688 |
substitution, case-change, insertion and deletion of a character." |
|
3689 |
||
1138
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
3690 |
%{ /* STACK: 2000 */ |
608 | 3691 |
|
8898 | 3692 |
/* |
3693 |
* this is very heavy used when correcting errors |
|
608 | 3694 |
* (all symbols are searched for best match) - therefore it must be fast |
3695 |
*/ |
|
8647 | 3696 |
|
608 | 3697 |
unsigned short *data; |
3698 |
int l1, l2; |
|
3699 |
REGISTER int sz; |
|
3700 |
unsigned char *s1, *s2; |
|
8913 | 3701 |
int v1, v2, v3; |
3702 |
INT m; |
|
608 | 3703 |
REGISTER unsigned short *dp; |
8647 | 3704 |
REGISTER int rowDelta; |
608 | 3705 |
REGISTER int j; |
3706 |
int i; |
|
8647 | 3707 |
int iW, cW, sW, kW, dW; |
1486 | 3708 |
# define FASTSIZE 30 /* increase STACK if you increase this ... */ |
608 | 3709 |
unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)]; |
8898 | 3710 |
extern void *malloc(); |
608 | 3711 |
|
14664 | 3712 |
if (__qIsStringLike(self) && __isStringLike(aString) |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3713 |
&& __bothSmallInteger(insrtWeight, caseWeight) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3714 |
&& __bothSmallInteger(substWeight, deleteWeight) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3715 |
&& __isSmallInteger(kbdTypoWeight) |
8647 | 3716 |
) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3717 |
iW = __intVal(insrtWeight); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3718 |
cW = __intVal(caseWeight); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3719 |
sW = __intVal(substWeight); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3720 |
kW = __intVal(kbdTypoWeight); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3721 |
dW = __intVal(deleteWeight); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3722 |
s1 = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3723 |
s2 = __stringVal(aString); |
16019
b204c9d6ce6d
no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents:
15938
diff
changeset
|
3724 |
l1 = __stringSize(self); |
b204c9d6ce6d
no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents:
15938
diff
changeset
|
3725 |
l2 = __stringSize(aString); |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3726 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3727 |
sz = (l1 < l2) ? l2 : l1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3728 |
rowDelta = sz + 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3729 |
if (sz <= FASTSIZE) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3730 |
data = fastData; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3731 |
} else { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3732 |
/* add ifdef ALLOCA here ... */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3733 |
data = (unsigned short *)malloc(rowDelta * rowDelta * sizeof(short)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3734 |
if (! data) goto mallocFailed; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3735 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3736 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3737 |
data[0] = 0; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3738 |
for (j=1, dp=data+1; j<=sz; j++, dp++) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3739 |
*dp = dp[-1] + iW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3740 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3741 |
for (i=1, dp=data+rowDelta; i<=sz; i++, dp+=rowDelta) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3742 |
*dp = dp[-rowDelta] + dW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3743 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3744 |
for (i=0; i<l1; i++) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3745 |
for (j=0; j<l2; j++) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3746 |
if (s1[i] == s2[j]) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3747 |
m = 0; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3748 |
else if (tolower(s1[i]) == tolower(s2[j])) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3749 |
m = cW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3750 |
else if (sW != kW && nextOnKeyboard(tolower(s1[i]), tolower(s2[j]))) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3751 |
m = kW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3752 |
else |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3753 |
m = sW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3754 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3755 |
dp = data + ((i+1)*rowDelta) + j; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3756 |
v2 = dp[0] + iW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3757 |
v1 = dp[-rowDelta] + m; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3758 |
v3 = dp[-rowDelta+1] + dW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3759 |
if (v1 < v2) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3760 |
if (v1 < v3) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3761 |
m = v1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3762 |
else |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3763 |
m = v3; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3764 |
} else { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3765 |
if (v2 < v3) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3766 |
m = v2; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3767 |
else |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3768 |
m = v3; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3769 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3770 |
dp[1] = m; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3771 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3772 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3773 |
m = data[l1*rowDelta + l2]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3774 |
if (sz > FASTSIZE) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3775 |
free(data); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3776 |
RETURN ( __mkSmallInteger(m) ); |
608 | 3777 |
} |
3778 |
mallocFailed: ; |
|
3779 |
%}. |
|
3780 |
||
8898 | 3781 |
^ super levenshteinTo:aString |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3782 |
s:substWeight k:kbdTypoWeight c:caseWeight |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3783 |
i:insrtWeight d:deleteWeight |
8647 | 3784 |
|
3785 |
" |
|
3786 |
'ocmprt' levenshteinTo:'computer' |
|
608 | 3787 |
'computer' levenshteinTo:'computer' |
3788 |
'ocmputer' levenshteinTo:'computer' |
|
3789 |
'cmputer' levenshteinTo:'computer' |
|
8647 | 3790 |
'computer' levenshteinTo:'cmputer' |
3791 |
'computer' levenshteinTo:'vomputer' |
|
3792 |
'computer' levenshteinTo:'bomputer' |
|
3793 |
'Computer' levenshteinTo:'computer' |
|
3794 |
" |
|
1380 | 3795 |
! |
3796 |
||
5556 | 3797 |
notEmpty |
3798 |
"return true if the receiver is not empty (i.e. if size ~~ 0) |
|
3799 |
Redefined here for performance" |
|
3800 |
||
3801 |
%{ /* NOCONTEXT */ |
|
3802 |
OBJ cls; |
|
3803 |
||
3804 |
cls = __qClass(self); |
|
3805 |
if ((cls == String) || (cls == Symbol)) { |
|
9473 | 3806 |
RETURN ( (__stringSize(self) != 0) ? true : false); |
5556 | 3807 |
} |
3808 |
%}. |
|
3809 |
^ self size ~~ 0 |
|
3810 |
! |
|
3811 |
||
2886 | 3812 |
startsWith:aStringOrChar |
4389
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4388
diff
changeset
|
3813 |
"return true, if the receiver starts with something, aStringOrChar. |
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4388
diff
changeset
|
3814 |
If the argument is empty, true is returned." |
1380 | 3815 |
|
3816 |
%{ /* NOCONTEXT */ |
|
3817 |
||
3818 |
int len1, len2; |
|
3819 |
REGISTER unsigned char *src1, *src2; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
3820 |
unsigned char c; |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3821 |
REGISTER OBJ slf = self; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3822 |
|
14217 | 3823 |
if (__qIsStringLike(slf) &&__isStringLike(aStringOrChar)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3824 |
src1 = __stringVal(slf); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3825 |
src2 = __stringVal(aStringOrChar); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3826 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3827 |
if (src1[0] != src2[0]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3828 |
if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3829 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3830 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3831 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3832 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3833 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3834 |
len1 = __qSize(slf); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3835 |
len2 = __qSize(aStringOrChar); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3836 |
if (len1 < len2) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3837 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3838 |
} |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3839 |
|
4247 | 3840 |
#ifdef UINT64 |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3841 |
while (len2 > (OHDR_SIZE+sizeof(UINT64))) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3842 |
if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3843 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3844 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3845 |
len2 -= sizeof(UINT64); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3846 |
src1 += sizeof(UINT64); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3847 |
src2 += sizeof(UINT64); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3848 |
} |
4247 | 3849 |
#else |
8919 | 3850 |
# ifdef __UNROLL_LOOPS__ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3851 |
while (len2 > (OHDR_SIZE+sizeof(INT)*4)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3852 |
if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3853 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3854 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3855 |
if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3856 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3857 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3858 |
if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3859 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3860 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3861 |
if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3862 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3863 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3864 |
len2 -= sizeof(INT)*4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3865 |
src1 += sizeof(INT)*4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3866 |
src2 += sizeof(INT)*4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3867 |
} |
8919 | 3868 |
# endif /* __UNROLL_LOOPS__ */ |
4247 | 3869 |
#endif /* UINT64 */ |
3546
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
3870 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3871 |
while (len2 > (OHDR_SIZE+sizeof(INT))) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3872 |
if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3873 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3874 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3875 |
len2 -= sizeof(INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3876 |
src1 += sizeof(INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3877 |
src2 += sizeof(INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3878 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3879 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3880 |
while (c = *src2++) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3881 |
if (c != *src1) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3882 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3883 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3884 |
src1++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3885 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3886 |
RETURN (true); |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3887 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3888 |
if (__isCharacter(aStringOrChar)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3889 |
int val; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3890 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3891 |
val = __intVal(__characterVal(aStringOrChar)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3892 |
if ((unsigned)val <= 0xFF) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3893 |
len1 = __stringSize(slf); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3894 |
if (len1 > 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3895 |
RETURN ( (__stringVal(slf)[0] == val) ? true : false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3896 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3897 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3898 |
RETURN ( false ); |
1380 | 3899 |
} |
3900 |
%}. |
|
2862 | 3901 |
^ super startsWith:aStringOrChar |
1380 | 3902 |
|
3903 |
" |
|
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
3904 |
'hello world' startsWith:'hello' |
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
3905 |
'hello world' startsWith:'hella' |
8898 | 3906 |
'hello world' startsWith:'hi' |
3907 |
'hello world' startsWith:$h |
|
3908 |
'hello world' startsWith:$H |
|
3909 |
'hello world' startsWith:(Character value:16rFF00) |
|
3910 |
'hello world' startsWith:60 |
|
1380 | 3911 |
'hello world' startsWith:#($h $e $l) |
8898 | 3912 |
'hello world' startsWith:'' |
1380 | 3913 |
" |
608 | 3914 |
! ! |
3915 |
||
4660 | 3916 |
!String methodsFor:'tracing'! |
3917 |
||
4682 | 3918 |
traceInto:aRequestor level:level from:referrer |
4660 | 3919 |
"double dispatch into tracer, passing my type implicitely in the selector" |
3920 |
||
4682 | 3921 |
^ aRequestor traceString:self level:level from:referrer |
4660 | 3922 |
|
3923 |
||
3924 |
! ! |
|
3925 |
||
16253 | 3926 |
|
633 | 3927 |
!String class methodsFor:'documentation'! |
3928 |
||
2886 | 3929 |
version |
16457 | 3930 |
^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.318 2014-05-15 17:20:43 cg Exp $' |
12184
e91c375c7ea9
comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents:
11922
diff
changeset
|
3931 |
! |
e91c375c7ea9
comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents:
11922
diff
changeset
|
3932 |
|
e91c375c7ea9
comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents:
11922
diff
changeset
|
3933 |
version_CVS |
16457 | 3934 |
^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.318 2014-05-15 17:20:43 cg Exp $' |
633 | 3935 |
! ! |
16174 | 3936 |