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