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