author | Claus Gittinger <cg@exept.de> |
Thu, 27 Jun 2019 16:34:40 +0200 | |
changeset 24379 | 852be153b0ec |
parent 24233 | 9db9068aed81 |
child 24478 | 5138e2ba3e6c |
permissions | -rw-r--r-- |
19839 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1988 by Claus Gittinger |
9473 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5407 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17370 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
3989 | 18 |
CharacterArray variableByteSubclass:#String |
9473 | 19 |
instanceVariableNames:'' |
14330 | 20 |
classVariableNames:'CRLF CR LF TAB' |
9473 | 21 |
poolDictionaries:'' |
22 |
category:'Collections-Text' |
|
88 | 23 |
! |
24 |
||
216 | 25 |
!String primitiveDefinitions! |
88 | 26 |
%{ |
2894 | 27 |
|
22491 | 28 |
#ifndef _STDIO_H_INCLUDED_ |
29 |
# include <stdio.h> |
|
30 |
# define _STDIO_H_INCLUDED_ |
|
31 |
#endif |
|
32 |
||
33 |
#ifndef _STDLIB_H_INCLUDED_ |
|
34 |
# include <stdlib.h> |
|
35 |
# define _STDLIB_H_INCLUDED_ |
|
36 |
#endif |
|
37 |
||
38 |
#ifndef _CTYPE_H_INCLUDED_ |
|
39 |
# include <ctype.h> |
|
40 |
# define _CTYPE_H_INCLUDED_ |
|
41 |
#endif |
|
359 | 42 |
|
273 | 43 |
#ifdef LINUX |
359 | 44 |
# define __STRINGDEFS__ |
45 |
# include <linuxIntern.h> |
|
273 | 46 |
#endif |
95 | 47 |
|
22491 | 48 |
#if defined(__osx__) || defined(__MINGW__) |
49 |
# ifndef _STRING_H_INCLUDED_ |
|
50 |
# include <string.h> |
|
51 |
# define _STRING_H_INCLUDED_ |
|
52 |
# endif |
|
19877 | 53 |
#endif |
54 |
||
95 | 55 |
/* |
56 |
* old st/x creates strings with spaces in it; |
|
57 |
* new st/x will fill it with zeros (for st-80 compatibility) |
|
58 |
* the define below sets old behavior. |
|
59 |
*/ |
|
60 |
#define INITIALIZE_WITH_SPACE |
|
6370 | 61 |
|
19107 | 62 |
#ifdef FAST_MEMCHR |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
63 |
// # if !defined(__osx__) && !defined(__win32__) |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
64 |
// extern void *memchr(); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
65 |
// # endif |
6370 | 66 |
#endif |
88 | 67 |
%} |
216 | 68 |
! ! |
88 | 69 |
|
8647 | 70 |
!String primitiveFunctions! |
71 |
%{ |
|
72 |
||
8898 | 73 |
static int |
19878 | 74 |
nextOnKeyboard(int char1, int char2) |
10371 | 75 |
{ |
8647 | 76 |
/* compare two characters if they are next to each other on a (US-) keyboard */ |
10370 | 77 |
|
78 |
static char *us_keys[] = { "1234567890-", |
|
9473 | 79 |
"*qwertyuiop", |
80 |
"**asdfghjkl:", |
|
81 |
"***zxcvbnm", |
|
82 |
0 }; |
|
10370 | 83 |
static char *de_keys[] = { "1234567890-", |
84 |
"*qwertzuiop", |
|
85 |
"**asdfghjkl:", |
|
86 |
"***yxcvbnm", |
|
87 |
0 }; |
|
10371 | 88 |
char **keys = us_keys; |
8647 | 89 |
char **line1, **line2; |
90 |
char *col1, *col2; |
|
91 |
int diff; |
|
92 |
||
93 |
for (line1 = keys; *line1 != 0; line1++) { |
|
9473 | 94 |
for (col1 = *line1; *col1 != 0 && *col1 != char1; col1++) |
95 |
continue; |
|
8647 | 96 |
} |
97 |
if (*col1 == 0) |
|
9473 | 98 |
return(0); |
8647 | 99 |
|
100 |
for (line2 = keys; *line2 != 0; line2++) { |
|
9473 | 101 |
for (col2 = *line2; *col2 != 0 && *col2 != char2; col2++) |
102 |
continue; |
|
8647 | 103 |
} |
104 |
if (*col2 == 0) |
|
9473 | 105 |
return(0); |
8647 | 106 |
|
107 |
diff = col1 - col2; |
|
108 |
if (diff > 1 || diff < -1) |
|
9473 | 109 |
return(0); |
8647 | 110 |
|
111 |
diff = line1 - line2; |
|
112 |
if (diff > 1 || diff < -1) |
|
9473 | 113 |
return(0); |
8647 | 114 |
return(1); |
115 |
} |
|
116 |
||
117 |
%} |
|
118 |
! ! |
|
119 |
||
608 | 120 |
!String class methodsFor:'documentation'! |
121 |
||
122 |
copyright |
|
123 |
" |
|
124 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
9473 | 125 |
All Rights Reserved |
608 | 126 |
|
127 |
This software is furnished under a license and may be used |
|
128 |
only in accordance with the terms of that license and with the |
|
129 |
inclusion of the above copyright notice. This software may not |
|
130 |
be provided or otherwise made available to, or used by, any |
|
131 |
other person. No title to or ownership of the software is |
|
132 |
hereby transferred. |
|
133 |
" |
|
134 |
! |
|
3 | 135 |
|
608 | 136 |
documentation |
137 |
" |
|
138 |
Strings are ByteArrays storing Characters. |
|
139 |
||
19910 | 140 |
Strings are kind of kludgy: to allow for easy handling by C functions, |
608 | 141 |
there is always one 0-byte added at the end, which is not counted |
19305 | 142 |
in the strings size, and is not accessible from the smalltalk level. |
4800
118dff933bf3
docu fixed - yes, String does allow storing 0-bytes.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
143 |
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
|
144 |
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
|
145 |
prevent a nonsense contents ...) |
3 | 146 |
|
19305 | 147 |
You cannot add any instvars to String, since the run time system & compiler |
608 | 148 |
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
|
149 |
If you really need strings with instVars, you have to create a subclass |
608 | 150 |
of String (the access functions defined here can handle this). |
151 |
A little warning though: not all smalltalk systems allow subclassing String, |
|
152 |
so your program may become unportable if you do so. |
|
1290 | 153 |
|
20003 | 154 |
Strings have an implicit (assumed) encoding of ISO-8859-1. |
7895 | 155 |
For strings with other encodings, either keep the encoding separately, |
156 |
or use instances of encodedString. |
|
157 |
||
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
158 |
Be careful when using the 0-byte in a String. This is not prohibited, but |
19910 | 159 |
the implementations of some String methods use C functions and may |
160 |
therefore yield unexpected results (e.g. compareWith:collating:) when |
|
161 |
processing a String containing the 0-byte. |
|
162 |
||
1290 | 163 |
[author:] |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
164 |
Claus Gittinger |
1310 | 165 |
|
166 |
[see also:] |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
167 |
Text StringCollection TwoByteString JISEncodedString |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
168 |
Symbol |
608 | 169 |
" |
3 | 170 |
! ! |
171 |
||
1 | 172 |
!String class methodsFor:'instance creation'! |
173 |
||
174 |
basicNew:anInteger |
|
4802 | 175 |
"return a new empty string with anInteger characters. |
176 |
In contrast to other smalltalks, this returns a string filled |
|
177 |
with spaces (instead of a string filled with 0-bytes). |
|
178 |
This makes much more sense, in that a freshly created string |
|
179 |
can be directly used as separator or for formatting." |
|
1 | 180 |
|
181 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
182 |
#ifdef __SCHTEAM__ |
18236 | 183 |
return context._RETURN( self.basicNew( anInteger.intValue() )); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
184 |
#else |
1 | 185 |
OBJ newString; |
18581 | 186 |
REGISTER INT len, instsize; |
1 | 187 |
REGISTER unsigned char *cp; |
18581 | 188 |
int nInstVars; |
1 | 189 |
|
23960 | 190 |
// fetch first; check later |
191 |
// (if not a smallInteger, value will be ignored anyway) |
|
192 |
len = __intVal(anInteger); |
|
193 |
instsize = OHDR_SIZE + len + 1; |
|
252 | 194 |
if (__isSmallInteger(anInteger)) { |
23960 | 195 |
if (len >= 0) { |
196 |
if (self == String || self == ImmutableString) { |
|
197 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
|
198 |
/* |
|
199 |
* the most common case |
|
200 |
*/ |
|
201 |
__qCheckedNew(newString, instsize); |
|
202 |
__InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */ |
|
203 |
__qSTORE(newString, self); |
|
204 |
||
205 |
cp = __stringVal(newString); |
|
206 |
fillIt: |
|
207 |
// fill bytes at cp |
|
19748 | 208 |
# if defined(memset4) |
23960 | 209 |
{ |
210 |
/* |
|
211 |
* no sizeof(int) here please - |
|
212 |
* - memset4 (if defined) fills 4-bytes on ALL machines |
|
213 |
*/ |
|
214 |
int l4 = len >> 2; |
|
215 |
||
216 |
if (len & 3) l4++; |
|
217 |
memset4(cp, 0x20202020, l4); |
|
218 |
cp[len] = '\0'; |
|
219 |
} |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
220 |
# else |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
221 |
# ifdef FAST_MEMSET |
23960 | 222 |
memset(cp, ' ', len); |
223 |
cp[len] = '\0'; |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
224 |
# else |
23960 | 225 |
for ( ; len >= 8; cp += 8, len -= 8) { |
19748 | 226 |
# ifdef INT64 |
23960 | 227 |
((INT64 *)cp)[0] = 0x2020202020202020L; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
228 |
# else |
23960 | 229 |
((int *)cp)[0] = 0x20202020; |
230 |
((int *)cp)[1] = 0x20202020; |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
231 |
# endif |
23960 | 232 |
} |
233 |
while (len--) |
|
234 |
*cp++ = ' '; |
|
235 |
*cp = '\0'; |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
236 |
# endif /* not FAST_MEMSET */ |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
237 |
# endif /* not memset4 */ |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
238 |
|
23960 | 239 |
RETURN (newString); |
240 |
} |
|
241 |
nInstVars = 0; |
|
242 |
} else { |
|
243 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
|
244 |
instsize += __OBJS2BYTES__(nInstVars); |
|
245 |
} |
|
246 |
||
247 |
__PROTECT_CONTEXT__; |
|
248 |
__qNew(newString, instsize); /* OBJECT ALLOCATION */ |
|
249 |
__UNPROTECT_CONTEXT__; |
|
250 |
||
251 |
if (newString == nil) goto fail; |
|
252 |
||
253 |
__InstPtr(newString)->o_class = self; |
|
254 |
__qSTORE(newString, self); |
|
255 |
||
256 |
cp = __stringVal(newString); |
|
257 |
if (nInstVars) { |
|
258 |
OBJ *op; |
|
259 |
cp += __OBJS2BYTES__(nInstVars); |
|
260 |
||
261 |
/* |
|
262 |
* nil-out instvars |
|
263 |
*/ |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
264 |
# if defined(memset4) |
23960 | 265 |
memset4(__InstPtr(newString)->i_instvars, nil, nInstVars); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
266 |
# else |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
267 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
23960 | 268 |
/* |
269 |
* knowing that nil is 0 |
|
270 |
*/ |
|
271 |
memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars)); |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
272 |
# else |
23960 | 273 |
op = __InstPtr(newString)->i_instvars; |
274 |
do { |
|
275 |
*op++ = nil; |
|
276 |
} while (--nInstVars); |
|
19748 | 277 |
# endif /* !FAST_MEMSET */ |
357 | 278 |
# endif |
23960 | 279 |
} |
280 |
goto fillIt; |
|
281 |
} |
|
1 | 282 |
} |
95 | 283 |
fail: ;; |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
284 |
#endif /* not __SCHTEAM__ */ |
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:[ |
23960 | 291 |
" |
292 |
the argument is negative, |
|
293 |
" |
|
294 |
self argumentError:'bad (negative) argument to new:' with:anInteger. |
|
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) |
23279 | 299 |
|
23960 | 300 |
"Modified: / 24-03-2019 / 10:07:43 / Claus Gittinger" |
1 | 301 |
! |
302 |
||
608 | 303 |
new:n |
20193 | 304 |
"return a new empty string with n characters. |
4802 | 305 |
In contrast to other smalltalks, this returns a string filled |
306 |
with spaces (instead of a string filled with 0-bytes). |
|
307 |
This makes much more sense, in that a freshly created string |
|
20272 | 308 |
can be directly used as separator or for formatting. |
309 |
||
310 |
Redefined here with exactly the same code as in Behavior for |
|
311 |
better performance. " |
|
4802 | 312 |
|
608 | 313 |
^ self basicNew:n |
347 | 314 |
! |
315 |
||
6599
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
316 |
readFrom:aStreamOrString onError:exceptionBlock |
347 | 317 |
"read & return the next String from the (character-)stream aStream; |
318 |
skipping all whitespace first; return the value of exceptionBlock, |
|
8898 | 319 |
if no string can be read. The sequence of characters as read from the |
347 | 320 |
stream must be one as stored via storeOn: or storeString." |
321 |
||
322 |
" |
|
323 |
this method is not to be inherited |
|
324 |
(i.e. not ok for subclasses; Symbol, for example) |
|
325 |
" |
|
326 |
self ~~ String ifTrue:[ |
|
10352 | 327 |
^ super readFrom:aStreamOrString onError:exceptionBlock |
347 | 328 |
]. |
9426 | 329 |
^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
347 | 330 |
|
331 |
" |
|
8898 | 332 |
String readFrom:('''hello world''' readStream) |
333 |
String readFrom:('''hello '''' world''' readStream) |
|
347 | 334 |
String readFrom:('1 ''hello'' ' readStream) |
8898 | 335 |
String readFrom:('1 ''hello'' ' readStream) onError:['foobar'] |
3376 | 336 |
" |
337 |
||
9426 | 338 |
"Modified: / 05-07-2006 / 16:41:29 / cg" |
9473 | 339 |
"Modified: / 07-08-2006 / 15:03:09 / fm" |
608 | 340 |
! |
341 |
||
7684 | 342 |
uninitializedNew:anInteger |
343 |
"return a new string with anInteger characters but undefined contents. |
|
344 |
Use this, if the string is filled anyway with new data, for example, if |
|
345 |
used as a stream buffer." |
|
346 |
||
347 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
348 |
#ifdef __SCHTEAM__ |
18236 | 349 |
return context._RETURN( self.basicNew( anInteger.intValue() )); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
350 |
#else |
7684 | 351 |
OBJ newString; |
352 |
REGISTER int len; |
|
353 |
REGISTER unsigned char *cp; |
|
354 |
REGISTER OBJ *op; |
|
355 |
int nInstVars, instsize; |
|
356 |
||
23960 | 357 |
// fetch first; check later |
358 |
// (if not a smallInteger, value will be ignored anyway) |
|
359 |
len = __intVal(anInteger); |
|
360 |
instsize = OHDR_SIZE + len + 1; |
|
7684 | 361 |
if (__isSmallInteger(anInteger)) { |
23960 | 362 |
if (len >= 0) { |
363 |
if (self == String) { |
|
364 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
|
365 |
/* |
|
366 |
* the most common case |
|
367 |
*/ |
|
368 |
__qCheckedNew(newString, instsize); |
|
369 |
__InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */ |
|
370 |
__qSTORE(newString, self); |
|
371 |
||
372 |
cp = __stringVal(newString); |
|
373 |
cp[len] = '\0'; |
|
374 |
RETURN (newString); |
|
375 |
} |
|
376 |
nInstVars = 0; |
|
377 |
} else { |
|
378 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
|
379 |
instsize += __OBJS2BYTES__(nInstVars); |
|
380 |
} |
|
381 |
||
382 |
__PROTECT_CONTEXT__; |
|
383 |
__qNew(newString, instsize); /* OBJECT ALLOCATION */ |
|
384 |
__UNPROTECT_CONTEXT__; |
|
385 |
||
386 |
if (newString == nil) goto fail; |
|
387 |
||
388 |
__InstPtr(newString)->o_class = self; |
|
389 |
__qSTORE(newString, self); |
|
390 |
||
391 |
if (nInstVars) { |
|
392 |
/* |
|
393 |
* nil-out instvars |
|
394 |
*/ |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
395 |
# if defined(memset4) |
23960 | 396 |
memset4(__InstPtr(newString)->i_instvars, nil, nInstVars); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
397 |
# else |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
398 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
23960 | 399 |
/* |
400 |
* knowing that nil is 0 |
|
401 |
*/ |
|
402 |
memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars)); |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
403 |
# else |
23960 | 404 |
op = __InstPtr(newString)->i_instvars; |
405 |
do { |
|
406 |
*op++ = nil; |
|
407 |
} while (--nInstVars); |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
408 |
# endif |
7684 | 409 |
# endif |
23960 | 410 |
cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars); |
411 |
} else { |
|
412 |
cp = __stringVal(newString); |
|
413 |
} |
|
414 |
||
415 |
cp[len] = '\0'; |
|
416 |
RETURN (newString); |
|
417 |
} |
|
7684 | 418 |
} |
419 |
fail: ;; |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
420 |
#endif /* not __SCHTEAM__ */ |
7684 | 421 |
%}. |
422 |
" |
|
423 |
invalid argument, or out-of-memory: |
|
424 |
use error handling in superclass |
|
425 |
" |
|
426 |
(anInteger < 0) ifTrue:[ |
|
23960 | 427 |
" |
428 |
the argument is negative, |
|
429 |
" |
|
430 |
self argumentError:'bad (negative) argument to new:' with:anInteger. |
|
431 |
^ nil |
|
7684 | 432 |
]. |
608 | 433 |
|
434 |
^ self basicNew:anInteger |
|
7684 | 435 |
|
436 |
" |
|
437 |
String uninitializedNew:100 |
|
438 |
" |
|
23279 | 439 |
|
23960 | 440 |
"Modified: / 24-03-2019 / 10:08:04 / Claus Gittinger" |
608 | 441 |
! ! |
442 |
||
8438
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
443 |
!String class methodsFor:'Compatibility-Dolphin'! |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
444 |
|
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
445 |
lineDelimiter |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
446 |
"Dolphin compatibility: answer CR LF" |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
447 |
|
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
448 |
^ self crlf |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
449 |
! ! |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
450 |
|
7302 | 451 |
!String class methodsFor:'Compatibility-Squeak'! |
4981 | 452 |
|
453 |
cr |
|
4994 | 454 |
"return a string consisting of the cr-Character" |
4993 | 455 |
|
19503 | 456 |
"/ ATTENTION: you get a NL (for compatibility) here!! |
457 |
"/ please use String return / String lf |
|
22931 | 458 |
self breakPoint:'please make it explicit, if a return or a linefeed is wanted.'. |
19503 | 459 |
"/ for now. |
460 |
"/ will be changed, when the historic UNIX baggage is removed |
|
461 |
"/ and all cr's are really returns (instead of nl's). |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
462 |
|
19503 | 463 |
^ self lf |
7282 | 464 |
! |
465 |
||
466 |
crlf |
|
467 |
"return a string consisting of the cr-lf Characters" |
|
468 |
||
469 |
CRLF isNil ifTrue:[ |
|
9473 | 470 |
CRLF := String |
471 |
with:Character return |
|
472 |
with:Character linefeed |
|
7282 | 473 |
]. |
474 |
^ CRLF |
|
475 |
! |
|
476 |
||
477 |
lf |
|
478 |
"return a string consisting of the lf Character" |
|
479 |
||
480 |
LF isNil ifTrue:[ |
|
9473 | 481 |
LF := String with:Character linefeed |
7282 | 482 |
]. |
483 |
^ LF |
|
11856 | 484 |
! |
485 |
||
19503 | 486 |
return |
487 |
"return a string consisting of the cr-Character" |
|
488 |
||
489 |
CR isNil ifTrue:[ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
490 |
CR := String with:Character return |
19503 | 491 |
]. |
492 |
^ CR |
|
493 |
! |
|
494 |
||
22006 | 495 |
space |
496 |
"return a string consisting of a single space Character" |
|
497 |
||
498 |
^ ' ' |
|
499 |
||
500 |
"Created: / 13-07-2017 / 12:46:21 / cg" |
|
501 |
! |
|
502 |
||
12344
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
503 |
stringHash:aString initialHash:speciesHash |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
504 |
"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
|
505 |
|
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
506 |
| stringSize hash low | |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
507 |
|
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
508 |
stringSize := aString size. |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
509 |
hash := speciesHash bitAnd: 16rFFFFFFF. |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
510 |
1 to: stringSize do: [:pos | |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
511 |
hash := hash + (aString at: pos) asInteger. |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
512 |
"Begin hashMultiply" |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
513 |
low := hash bitAnd: 16383. |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
514 |
hash := (16r260D * low + ((16r260D * (hash bitShift: -14) + (16r0065 * low) bitAnd: 16383) * 16384)) bitAnd: 16r0FFFFFFF. |
12344
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
515 |
]. |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
516 |
^ hash. |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
517 |
! |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
518 |
|
11856 | 519 |
tab |
520 |
"return a string consisting of the tab-Character" |
|
521 |
||
14330 | 522 |
TAB isNil ifTrue:[ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
523 |
TAB := String with:Character tab |
14330 | 524 |
]. |
525 |
^ TAB |
|
4981 | 526 |
! ! |
527 |
||
13182 | 528 |
|
608 | 529 |
!String class methodsFor:'queries'! |
530 |
||
2680
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
531 |
defaultPlatformClass |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
532 |
"dummy for ST-80 compatibility" |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
533 |
|
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
534 |
^ self |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
535 |
|
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
536 |
"Created: 6.6.1997 / 18:25:56 / cg" |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
537 |
! |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
538 |
|
608 | 539 |
isBuiltInClass |
1264 | 540 |
"return true if this class is known by the run-time-system. |
541 |
Here, true is returned for myself, false for subclasses." |
|
608 | 542 |
|
543 |
^ self == String |
|
1264 | 544 |
|
545 |
"Modified: 23.4.1996 / 16:00:38 / cg" |
|
1 | 546 |
! ! |
547 |
||
14384
1082868a753c
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14353
diff
changeset
|
548 |
|
1 | 549 |
!String methodsFor:'accessing'! |
550 |
||
329 | 551 |
at:index |
552 |
"return the character at position index, an Integer. |
|
345 | 553 |
Reimplemented here to avoid the additional at:->basicAt: send |
554 |
(which we can do here, since at: is obviously not redefined in a subclass). |
|
329 | 555 |
This method is the same as at:." |
556 |
||
557 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
558 |
#ifdef __SCHTEAM__ |
18236 | 559 |
if (index.isSmallInteger()) { |
18215 | 560 |
int idx1Based = context.stArg(0).intValue(); // st index is 1 based |
18404 | 561 |
return context._RETURN( self.basicAt( idx1Based )); |
18215 | 562 |
} |
563 |
#else |
|
329 | 564 |
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
|
565 |
REGISTER OBJ slf, cls; |
329 | 566 |
|
567 |
if (__isSmallInteger(index)) { |
|
9473 | 568 |
slf = self; |
569 |
cls = __qClass(slf); |
|
570 |
indx = __intVal(index) - 1; |
|
571 |
if (cls != String) { |
|
572 |
if (indx < 0) goto badIndex; |
|
573 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
574 |
} |
|
575 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
576 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
|
577 |
} |
|
329 | 578 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
579 |
badIndex: ; |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
580 |
#endif /* ! __SCHTEAM__ */ |
329 | 581 |
%}. |
5407 | 582 |
^ self basicAt:index |
1 | 583 |
! |
584 |
||
329 | 585 |
at:index put:aCharacter |
586 |
"store the argument, aCharacter at position index, an Integer. |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
587 |
Return aCharacter (sigh). |
345 | 588 |
Reimplemented here to avoid the additional at:put:->basicAt:put: send |
589 |
(but only for Strings, since subclasses may redefine basicAt:put:). |
|
329 | 590 |
This method is the same as basicAt:put:." |
591 |
||
592 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
593 |
#ifdef __SCHTEAM__ |
18236 | 594 |
if (index.isSmallInteger()) { |
23948 | 595 |
int idx1Based = index.intValue(); // st index is 1 based |
596 |
||
597 |
self.basicAt_put(idx1Based, aCharacter ); |
|
598 |
return context._RETURN( aCharacter ); |
|
18215 | 599 |
} |
600 |
#else |
|
329 | 601 |
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
|
602 |
REGISTER OBJ slf; |
329 | 603 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
604 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
605 |
|
23948 | 606 |
/* not __isStringLike here, because that includes Symbol and ImutableString, |
607 |
* which are not writable |
|
608 |
*/ |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
609 |
if (__isString(slf)) { |
23948 | 610 |
if (__isCharacter(aCharacter)) { |
611 |
value = __intVal(__characterVal(aCharacter)); |
|
612 |
if (((unsigned)value <= 0xFF) |
|
613 |
&& __isSmallInteger(index)) { |
|
614 |
indx = __intVal(index) - 1; |
|
615 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
616 |
__stringVal(slf)[indx] = value; |
|
617 |
RETURN ( aCharacter ); |
|
618 |
} |
|
619 |
} |
|
620 |
} |
|
329 | 621 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
622 |
#endif /* ! __SCHTEAM__ */ |
329 | 623 |
%}. |
5407 | 624 |
^ self basicAt:index put:aCharacter |
23948 | 625 |
|
626 |
"Modified: / 22-03-2019 / 03:04:21 / Claus Gittinger" |
|
329 | 627 |
! |
628 |
||
608 | 629 |
basicAt:index |
630 |
"return the character at position index, an Integer |
|
631 |
- reimplemented here since we return characters" |
|
632 |
||
633 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
634 |
#ifdef __SCHTEAM__ |
18236 | 635 |
if (index.isSmallInteger()) { |
636 |
int idx1Based = index.intValue(); // st index is 1 based |
|
18404 | 637 |
return context._RETURN( self.basicAt( idx1Based )); |
18215 | 638 |
} |
639 |
#else |
|
608 | 640 |
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
|
641 |
REGISTER OBJ slf, cls; |
608 | 642 |
|
643 |
if (__isSmallInteger(index)) { |
|
9473 | 644 |
slf = self; |
645 |
cls = __qClass(slf); |
|
646 |
indx = __intVal(index) - 1; |
|
647 |
if (cls != String) { |
|
648 |
if (indx < 0) goto badIndex; |
|
649 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
650 |
} |
|
651 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
652 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
|
653 |
} |
|
608 | 654 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
655 |
badIndex: ; |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
656 |
#endif /* not __SCHTEAM__ */ |
608 | 657 |
%}. |
3451 | 658 |
index isInteger ifFalse:[ |
9473 | 659 |
^ self indexNotInteger:index |
3451 | 660 |
]. |
5407 | 661 |
index == super basicSize ifTrue:[ |
9473 | 662 |
^ self subscriptBoundsError:index |
5407 | 663 |
]. |
664 |
^ Character value:(super basicAt:index) |
|
608 | 665 |
! |
666 |
||
1 | 667 |
basicAt:index put:aCharacter |
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
668 |
"store the argument, aCharacter at position index, an Integer. |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
669 |
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
|
670 |
- reimplemented here since we store characters" |
1 | 671 |
|
672 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
673 |
#ifdef __SCHTEAM__ |
18236 | 674 |
if (index.isSmallInteger()) { |
675 |
int idx1Based = index.intValue(); // st index is 1 based |
|
676 |
||
18286 | 677 |
self.basicAt_put(idx1Based, aCharacter ); |
18404 | 678 |
return context._RETURN( aCharacter ); |
18215 | 679 |
} |
680 |
#else |
|
1 | 681 |
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
|
682 |
REGISTER OBJ slf; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
683 |
REGISTER OBJ cls; |
1 | 684 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
685 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
686 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
687 |
if (__isCharacter(aCharacter)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
688 |
value = __intVal(__characterVal(aCharacter)); |
9473 | 689 |
if (((unsigned)value <= 0xFF) |
690 |
&& __isSmallInteger(index)) { |
|
691 |
cls = __qClass(slf); |
|
692 |
indx = __intVal(index) - 1; |
|
693 |
if (cls != String) { |
|
694 |
if (indx < 0) goto badIndex; |
|
695 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
696 |
} |
|
697 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
698 |
__stringVal(slf)[indx] = value; |
|
699 |
RETURN ( aCharacter ); |
|
700 |
} |
|
701 |
} |
|
1 | 702 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
703 |
badIndex: ; |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
704 |
#endif /* not __SCHTEAM__ */ |
159 | 705 |
%}. |
1 | 706 |
(aCharacter isMemberOf:Character) ifFalse:[ |
9473 | 707 |
" |
708 |
tried to store something which is not a character |
|
709 |
" |
|
710 |
^ self elementNotCharacter |
|
299 | 711 |
]. |
8093
8ca1e24688d8
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
712 |
(aCharacter codePoint between:1 and:255) ifFalse:[ |
9473 | 713 |
" |
714 |
tried to store a multibyte character |
|
715 |
" |
|
716 |
^ self elementBoundsError:aCharacter |
|
299 | 717 |
]. |
718 |
" |
|
719 |
invalid index |
|
720 |
" |
|
3451 | 721 |
index isInteger ifFalse:[ |
9473 | 722 |
^ self indexNotInteger:index |
3451 | 723 |
]. |
5407 | 724 |
index == super basicSize ifTrue:[ |
9473 | 725 |
^ self subscriptBoundsError:index |
5407 | 726 |
]. |
8093
8ca1e24688d8
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
727 |
super basicAt:index put:aCharacter codePoint. |
8898 | 728 |
^ aCharacter |
12716 | 729 |
! |
730 |
||
731 |
first |
|
732 |
"return the first character. |
|
733 |
Reimplemented here for speed" |
|
734 |
||
735 |
%{ /* NOCONTEXT */ |
|
736 |
||
737 |
REGISTER int indx; |
|
738 |
REGISTER OBJ slf, cls; |
|
739 |
||
740 |
slf = self; |
|
741 |
cls = __qClass(slf); |
|
742 |
indx = 0; |
|
743 |
if (cls != String) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
744 |
if (indx < 0) goto badIndex; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
745 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
12716 | 746 |
} |
747 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
748 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
12716 | 749 |
} |
750 |
badIndex: ; |
|
751 |
%}. |
|
752 |
^ super first |
|
753 |
||
754 |
" |
|
755 |
'abc' first |
|
756 |
'' first |
|
757 |
" |
|
2 | 758 |
! ! |
759 |
||
13182 | 760 |
|
53 | 761 |
!String methodsFor:'character searching'! |
1 | 762 |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
763 |
identityIndexOf:aCharacter |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
764 |
"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
|
765 |
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
|
766 |
|
19744 | 767 |
^ self indexOf:aCharacter startingAt:1. |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
768 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
769 |
" |
8898 | 770 |
'hello world' identityIndexOf:(Character space) |
771 |
'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
|
772 |
'hello world' identityIndexOf:1 |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
773 |
#[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
|
774 |
#[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
|
775 |
" |
13920 | 776 |
|
777 |
"Modified: / 10-01-2012 / 17:07:12 / cg" |
|
1 | 778 |
! |
779 |
||
13923
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
780 |
identityIndexOf:aCharacter startingAt:index |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
781 |
"return the index of the first occurrences of the argument, aCharacter |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
782 |
in the receiver or 0 if not found - reimplemented here for speed." |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
783 |
|
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
784 |
^ self indexOf:aCharacter startingAt:index |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
785 |
|
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
786 |
" |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
787 |
'hello world' identityIndexOf:(Character space) |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
788 |
'hello world' identityIndexOf:$d |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
789 |
'hello world' identityIndexOf:1 |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
790 |
#[0 0 1 0 0] asString identityIndexOf:(Character value:1) |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
791 |
#[0 0 1 0 0] asString identityIndexOf:(Character value:0) |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
792 |
" |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
793 |
|
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
794 |
"Created: / 10-01-2012 / 17:10:54 / cg" |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
795 |
! |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
796 |
|
20384 | 797 |
includes:aCharacter |
798 |
"return true, if the receiver includes aCharacter. |
|
799 |
- redefined here for speed" |
|
800 |
||
801 |
%{ /* NOCONTEXT */ |
|
802 |
#ifdef FAST_MEMCHR |
|
803 |
REGISTER unsigned char *cp; |
|
804 |
REGISTER unsigned byteValue; |
|
805 |
int last; |
|
806 |
OBJ cls; |
|
807 |
||
808 |
if (__isCharacter(aCharacter)) { |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
809 |
byteValue = __intVal(__characterVal(aCharacter)); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
810 |
if (byteValue <= 0xFF) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
811 |
last = __stringSize(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
812 |
cp = __stringVal(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
813 |
if ((cls = __qClass(self)) != String) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
814 |
int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
815 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
816 |
cp += numInstBytes; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
817 |
last -= numInstBytes; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
818 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
819 |
cp = (unsigned char *) memchr(cp, byteValue, last); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
820 |
RETURN ( (cp == NULL) ? false : true ); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
821 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
822 |
RETURN (false); |
20384 | 823 |
} |
824 |
#endif |
|
825 |
%}. |
|
826 |
^ (self indexOf:aCharacter startingAt:1) ~~ 0 |
|
827 |
||
828 |
" |
|
829 |
'hello world' includes:$l |
|
830 |
'hello world' includes:$W |
|
831 |
||
832 |
|s| |
|
833 |
s := String new:1024. |
|
834 |
s atAllPut:$a. |
|
835 |
s at:512 put:(Character space). |
|
836 |
Time millisecondsToRun:[ |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
837 |
1000000 timesRepeat:[ s includes:(Character space) ] |
20384 | 838 |
] |
839 |
||
840 |
timing (ms): |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
841 |
bcc OSX(2007 powerbook) |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
842 |
110 |
20384 | 843 |
" |
844 |
! |
|
845 |
||
10 | 846 |
includesAny:aCollection |
847 |
"return true, if the receiver includes any of the characters in the |
|
53 | 848 |
argument, aCollection. |
17573 | 849 |
- redefined for speed if the argument is a String; especially optimized, |
850 |
if the searched collection has less than 6 characters." |
|
10 | 851 |
|
852 |
%{ /* NOCONTEXT */ |
|
853 |
||
854 |
REGISTER unsigned char *cp; |
|
855 |
REGISTER unsigned char *matchP; |
|
53 | 856 |
OBJ cls; |
19748 | 857 |
int index, last; |
10 | 858 |
|
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
859 |
if (__isStringLike(aCollection)) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
860 |
matchP = __stringVal(aCollection); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
861 |
last = __stringSize(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
862 |
cp = __stringVal(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
863 |
if ((cls = __qClass(self)) != String) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
864 |
int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
865 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
866 |
cp += numInstBytes; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
867 |
last -= numInstBytes; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
868 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
869 |
index = 0; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
870 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
871 |
switch (__stringSize(aCollection)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
872 |
case 5: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
873 |
/* five character search */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
874 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
875 |
unsigned char c1 = matchP[0]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
876 |
unsigned char c2 = matchP[1]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
877 |
unsigned char c3 = matchP[2]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
878 |
unsigned char c4 = matchP[3]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
879 |
unsigned char c5 = matchP[4]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
880 |
unsigned char ch; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
881 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
882 |
while (index < last) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
883 |
ch = cp[index]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
884 |
if ((ch == c1) || (ch == c2) || (ch == c3) || (ch == c4) || (ch == c5)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
885 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
886 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
887 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
888 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
889 |
RETURN (false); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
890 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
891 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
892 |
case 4: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
893 |
/* four character search */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
894 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
895 |
unsigned char c1 = matchP[0]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
896 |
unsigned char c2 = matchP[1]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
897 |
unsigned char c3 = matchP[2]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
898 |
unsigned char c4 = matchP[3]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
899 |
unsigned char ch; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
900 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
901 |
while (index < last) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
902 |
ch = cp[index]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
903 |
if ((ch == c1) || (ch == c2) || (ch == c3) || (ch == c4)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
904 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
905 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
906 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
907 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
908 |
RETURN (false); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
909 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
910 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
911 |
case 3: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
912 |
/* three character search */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
913 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
914 |
unsigned char c1 = matchP[0]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
915 |
unsigned char c2 = matchP[1]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
916 |
unsigned char c3 = matchP[2]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
917 |
unsigned char ch; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
918 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
919 |
while (index < last) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
920 |
ch = cp[index]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
921 |
if ((ch == c1) || (ch == c2) || (ch == c3)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
922 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
923 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
924 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
925 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
926 |
RETURN (false); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
927 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
928 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
929 |
case 2: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
930 |
/* two character search */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
931 |
{ |
19748 | 932 |
#if 0 |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
933 |
// this is roughly 10% slower (on OSX/64bit clang') |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
934 |
if (last < 2000) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
935 |
if (strchr(cp, matchP[0])) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
936 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
937 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
938 |
if (strchr(cp, matchP[1])) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
939 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
940 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
941 |
} |
19748 | 942 |
#endif |
943 |
||
944 |
#if 1 |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
945 |
// this is 30 %faster ! |
19748 | 946 |
# define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL) |
947 |
# define hasByteM(v,m) hasZeroByte( (v) ^ m) |
|
948 |
||
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
949 |
unsigned char c1 = matchP[0]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
950 |
unsigned char c2 = matchP[1]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
951 |
int last4 = last-4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
952 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
953 |
int m1 = (~0UL/255 * (c1)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
954 |
int m2 = (~0UL/255 * (c2)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
955 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
956 |
while (index < last4) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
957 |
unsigned int v = *(unsigned int *)(cp+index); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
958 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
959 |
if (hasByteM(v,m1)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
960 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
961 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
962 |
if (hasByteM(v,m2)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
963 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
964 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
965 |
index += 4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
966 |
} |
19748 | 967 |
|
968 |
# undef hasZeroByte |
|
969 |
# undef hasByteM |
|
970 |
#else |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
971 |
while (index < last4) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
972 |
unsigned char ch; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
973 |
int any; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
974 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
975 |
ch = cp[index]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
976 |
any = ((ch == c1) || (ch == c2)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
977 |
ch = cp[index+1]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
978 |
any |= ((ch == c1) || (ch == c2)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
979 |
ch = cp[index+2]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
980 |
any |= ((ch == c1) || (ch == c2)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
981 |
ch = cp[index+3]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
982 |
any |= ((ch == c1) || (ch == c2)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
983 |
if (any) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
984 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
985 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
986 |
index += 4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
987 |
} |
19748 | 988 |
#endif |
989 |
||
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
990 |
while (index < last) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
991 |
unsigned char ch; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
992 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
993 |
ch = cp[index]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
994 |
if ((ch == c1) || (ch == c2)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
995 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
996 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
997 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
998 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
999 |
RETURN (false); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1000 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1001 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1002 |
case 1: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1003 |
/* single character search */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1004 |
if (strchr(cp, matchP[0])) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1005 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1006 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1007 |
RETURN ( false ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1008 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1009 |
case 0: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1010 |
RETURN ( false ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1011 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1012 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1013 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1014 |
unsigned char ch; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1015 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1016 |
while (index < last) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1017 |
ch = cp[index]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1018 |
if (strchr(matchP, ch)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1019 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1020 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1021 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1022 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1023 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1024 |
RETURN ( false ); |
10 | 1025 |
} |
5407 | 1026 |
%}. |
10 | 1027 |
^ super includesAny:aCollection |
95 | 1028 |
|
1029 |
" |
|
8898 | 1030 |
'hello world' includesAny:'abcd' |
1031 |
'hello world' includesAny:'xyz' |
|
1032 |
'hello world' includesAny:'xz' |
|
1033 |
'hello world' includesAny:'od' |
|
1034 |
'hello world' includesAny:'xd' |
|
1035 |
'hello world' includesAny:'dx' |
|
1036 |
'hello world' includesAny:(Array with:$a with:$b with:$d) |
|
1037 |
'hello world' includesAny:(Array with:$x with:$y) |
|
1038 |
'hello world' includesAny:(Array with:1 with:2) |
|
19748 | 1039 |
|
1040 |
|s| |
|
1041 |
s := String new:1000 withAll:$a. |
|
1042 |
Time millisecondsToRun:[ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1043 |
1000000 timesRepeat:[ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1044 |
s includesAny:'12' |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1045 |
] |
19748 | 1046 |
].540 680 550 850 890 850 |
1047 |
||
1048 |
|s| |
|
1049 |
s := String new:2000 withAll:$a. |
|
1050 |
Time millisecondsToRun:[ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1051 |
1000000 timesRepeat:[ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1052 |
s includesAny:'12' |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1053 |
] |
19748 | 1054 |
]. 1030 1060 1650 1690 |
1055 |
||
1056 |
|s| |
|
1057 |
s := 'hello world'. |
|
1058 |
Time millisecondsToRun:[ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1059 |
1000000 timesRepeat:[ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1060 |
s includesAny:'12' |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1061 |
] |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1062 |
].70 60 |
95 | 1063 |
" |
10 | 1064 |
! |
1065 |
||
1 | 1066 |
indexOf:aCharacter startingAt:start |
1067 |
"return the index of the first occurrence of the argument, aCharacter |
|
1068 |
in myself starting at start, anInteger or 0 if not found; |
|
1069 |
- reimplemented here for speed" |
|
1070 |
||
1071 |
%{ /* NOCONTEXT */ |
|
18306 | 1072 |
#ifdef __SCHTEAM__ |
1073 |
if (start.isSmallInteger() |
|
1074 |
&& aCharacter.isSTCharacter()) { |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1075 |
int idx1Based = start.intValue(); // st index is 1 based |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1076 |
int jIdx = self.asString().indexOf(aCharacter.charValue(), idx1Based-1); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1077 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1078 |
return context._RETURN( jIdx+1 ); // st index is 1 based |
18306 | 1079 |
} |
1080 |
||
1081 |
#else |
|
19772
9dad3602ce7d
ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents:
19759
diff
changeset
|
1082 |
|
19745 | 1083 |
# if defined(__BORLANDC__) || defined(__VISUALC__) |
1084 |
# undef __UNROLL_LOOPS__ |
|
1085 |
# undef FAST_MEMCHR |
|
1086 |
# define V2 |
|
1087 |
# endif |
|
13920 | 1088 |
|
1 | 1089 |
REGISTER unsigned char *cp; |
8913 | 1090 |
REGISTER INT index; |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1091 |
REGISTER unsigned byteValue; |
8924 | 1092 |
int last; |
53 | 1093 |
OBJ cls; |
1 | 1094 |
|
252 | 1095 |
if (__isSmallInteger(start)) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1096 |
index = __intVal(start); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1097 |
if (index > 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1098 |
if (__isCharacter(aCharacter)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1099 |
byteValue = __intVal(__characterVal(aCharacter)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1100 |
if (byteValue <= 0xFF) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1101 |
last = __stringSize(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1102 |
cp = __stringVal(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1103 |
if ((cls = __qClass(self)) != String) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1104 |
int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1105 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1106 |
cp += numInstBytes; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1107 |
last -= numInstBytes; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1108 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1109 |
if (index <= last) { |
18306 | 1110 |
# ifdef FAST_MEMCHR |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1111 |
REGISTER unsigned char *ncp; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1112 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1113 |
ncp = (unsigned char *) memchr(cp+index-1, byteValue, last+1-index); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1114 |
if (ncp) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1115 |
RETURN ( __mkSmallInteger(ncp - cp + 1) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1116 |
} |
18306 | 1117 |
# else |
19772
9dad3602ce7d
ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents:
19759
diff
changeset
|
1118 |
|
18306 | 1119 |
# ifdef V2 |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1120 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1121 |
// see bit twiddling hacks |
13920 | 1122 |
# define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL) |
1123 |
# define hasByteM(v,m) hasZeroByte( (v) ^ m) |
|
18909 | 1124 |
# if __POINTER_SIZE__ == 8 |
1125 |
# define hasZeroByte8(v) (((v) - 0x0101010101010101ULL) & ~(v) & 0x8080808080808080ULL) |
|
1126 |
# define hasByteM8(v,m) hasZeroByte8( (v) ^ m) |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1127 |
// the following loop checks eight bytes at once |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1128 |
if (((index-1) & 0x7) == 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1129 |
int last8 = last-8; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1130 |
INT m = (~0ULL/255 * (byteValue)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1131 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1132 |
while (index <= last8) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1133 |
unsigned INT v = *(unsigned INT *)(cp+index-1); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1134 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1135 |
if (hasByteM8(v,m)) break; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1136 |
index += 8; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1137 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1138 |
} |
18909 | 1139 |
# endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1140 |
// the following loop checks four bytes at once |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1141 |
if (((index-1) & 0x3) == 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1142 |
int last4 = last-4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1143 |
int m = (~0UL/255 * (byteValue)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1144 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1145 |
while (index <= last4) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1146 |
unsigned int v = *(unsigned int *)(cp+index-1); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1147 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1148 |
if (hasByteM(v,m)) break; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1149 |
index += 4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1150 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1151 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1152 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1153 |
# else |
19772
9dad3602ce7d
ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents:
19759
diff
changeset
|
1154 |
|
9dad3602ce7d
ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents:
19759
diff
changeset
|
1155 |
# ifdef __UNROLL_LOOPS__ |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1156 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1157 |
int last4 = last-4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1158 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1159 |
for (; index <= last4; index += 4) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1160 |
if (cp[index-1] == byteValue) { RETURN ( __mkSmallInteger(index) ); } |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1161 |
if (cp[index-1+1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); } |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1162 |
if (cp[index-1+2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); } |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1163 |
if (cp[index-1+3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); } |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1164 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1165 |
} |
19772
9dad3602ce7d
ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents:
19759
diff
changeset
|
1166 |
# endif |
9dad3602ce7d
ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents:
19759
diff
changeset
|
1167 |
# endif /* V2 */ |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1168 |
while (index <= last) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1169 |
if (cp[index-1] == byteValue) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1170 |
RETURN ( __mkSmallInteger(index) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1171 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1172 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1173 |
} |
13920 | 1174 |
# endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1175 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1176 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1177 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1178 |
RETURN ( __mkSmallInteger(0) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1179 |
} |
1 | 1180 |
} |
18306 | 1181 |
# undef V2 |
1182 |
#endif /* not SCHTEAM */ |
|
370 | 1183 |
%}. |
1 | 1184 |
^ super indexOf:aCharacter startingAt:start |
53 | 1185 |
|
95 | 1186 |
" |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1187 |
'hello world' indexOf:$0 startingAt:1 |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1188 |
'hello world' indexOf:$l startingAt:1 |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1189 |
'hello world' indexOf:$l startingAt:5 |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1190 |
'hello world' indexOf:$d startingAt:5 |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1191 |
#[0 0 1 0 0] asString indexOf:(Character value:1) startingAt:1 |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1192 |
#[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3 |
13920 | 1193 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1194 |
'1234567890123456a' indexOf:$a |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1195 |
'1234567890123456a' indexOf:$b |
13920 | 1196 |
|
1197 |
|s| |
|
1198 |
s := '12345678901234b'. |
|
1199 |
self assert:(s indexOf:$x) == 0. |
|
1200 |
self assert:(s indexOf:$1) == 1. |
|
1201 |
self assert:(s indexOf:$2) == 2. |
|
1202 |
self assert:(s indexOf:$3) == 3. |
|
1203 |
self assert:(s indexOf:$4) == 4. |
|
1204 |
self assert:(s indexOf:$5) == 5. |
|
1205 |
self assert:(s indexOf:$0) == 10. |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1206 |
self assert:(s indexOf:$b) == 15. |
13920 | 1207 |
|
1208 |
|s| |
|
1209 |
s := ''. |
|
1210 |
self assert:(s indexOf:$1) == 0. |
|
1211 |
s := '1'. |
|
1212 |
self assert:(s indexOf:$1) == 1. |
|
1213 |
self assert:(s indexOf:$2) == 0. |
|
1214 |
s := '12'. |
|
1215 |
self assert:(s indexOf:$1) == 1. |
|
1216 |
self assert:(s indexOf:$2) == 2. |
|
1217 |
self assert:(s indexOf:$3) == 0. |
|
1218 |
s := '123'. |
|
1219 |
self assert:(s indexOf:$1) == 1. |
|
1220 |
self assert:(s indexOf:$2) == 2. |
|
1221 |
self assert:(s indexOf:$3) == 3. |
|
1222 |
self assert:(s indexOf:$4) == 0. |
|
1223 |
s := '1234'. |
|
1224 |
self assert:(s indexOf:$1) == 1. |
|
1225 |
self assert:(s indexOf:$2) == 2. |
|
1226 |
self assert:(s indexOf:$3) == 3. |
|
1227 |
self assert:(s indexOf:$4) == 4. |
|
1228 |
self assert:(s indexOf:$5) == 0. |
|
1229 |
s := '12345'. |
|
1230 |
self assert:(s indexOf:$1) == 1. |
|
1231 |
self assert:(s indexOf:$2) == 2. |
|
1232 |
self assert:(s indexOf:$3) == 3. |
|
1233 |
self assert:(s indexOf:$4) == 4. |
|
1234 |
self assert:(s indexOf:$5) == 5. |
|
1235 |
self assert:(s indexOf:$6) == 0. |
|
1236 |
s := '123456'. |
|
1237 |
self assert:(s indexOf:$1) == 1. |
|
1238 |
self assert:(s indexOf:$2) == 2. |
|
1239 |
self assert:(s indexOf:$3) == 3. |
|
1240 |
self assert:(s indexOf:$4) == 4. |
|
1241 |
self assert:(s indexOf:$5) == 5. |
|
1242 |
self assert:(s indexOf:$6) == 6. |
|
1243 |
self assert:(s indexOf:$7) == 0. |
|
1244 |
s := '1234567'. |
|
1245 |
self assert:(s indexOf:$1) == 1. |
|
1246 |
self assert:(s indexOf:$2) == 2. |
|
1247 |
self assert:(s indexOf:$3) == 3. |
|
1248 |
self assert:(s indexOf:$4) == 4. |
|
1249 |
self assert:(s indexOf:$5) == 5. |
|
1250 |
self assert:(s indexOf:$6) == 6. |
|
1251 |
self assert:(s indexOf:$7) == 7. |
|
1252 |
self assert:(s indexOf:$8) == 0. |
|
1253 |
s := '12345678'. |
|
1254 |
self assert:(s indexOf:$1) == 1. |
|
1255 |
self assert:(s indexOf:$2) == 2. |
|
1256 |
self assert:(s indexOf:$3) == 3. |
|
1257 |
self assert:(s indexOf:$4) == 4. |
|
1258 |
self assert:(s indexOf:$5) == 5. |
|
1259 |
self assert:(s indexOf:$6) == 6. |
|
1260 |
self assert:(s indexOf:$7) == 7. |
|
1261 |
self assert:(s indexOf:$8) == 8. |
|
1262 |
self assert:(s indexOf:$9) == 0. |
|
1263 |
s := '123456789'. |
|
1264 |
self assert:(s indexOf:$1) == 1. |
|
1265 |
self assert:(s indexOf:$2) == 2. |
|
1266 |
self assert:(s indexOf:$3) == 3. |
|
1267 |
self assert:(s indexOf:$4) == 4. |
|
1268 |
self assert:(s indexOf:$5) == 5. |
|
1269 |
self assert:(s indexOf:$6) == 6. |
|
1270 |
self assert:(s indexOf:$7) == 7. |
|
1271 |
self assert:(s indexOf:$8) == 8. |
|
1272 |
self assert:(s indexOf:$9) == 9. |
|
1273 |
||
1274 |
self assert:(s indexOf:$0) == 0. |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1275 |
self assert:(s indexOf:$b) == 0. |
13920 | 1276 |
|
1277 |
|s| |
|
1278 |
s := String new:1024. |
|
1279 |
s atAllPut:$a. |
|
1280 |
s at:512 put:(Character space). |
|
1281 |
Time millisecondsToRun:[ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1282 |
1000000 timesRepeat:[ s indexOf:(Character space) ] |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1283 |
] |
13920 | 1284 |
|
1285 |
timing (ms): |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1286 |
bcc OSX(2007 powerbook) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1287 |
v1: 1763 normal |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1288 |
2340 +unroll |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1289 |
3308 memsrch !! 90 |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1290 |
v2: 1045 150 |
95 | 1291 |
" |
13920 | 1292 |
|
13922
b693795611ea
changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13921
diff
changeset
|
1293 |
"Modified: / 10-01-2012 / 17:09:34 / cg" |
1 | 1294 |
! |
1295 |
||
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1296 |
indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1297 |
"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
|
1298 |
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
|
1299 |
- 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
|
1300 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1301 |
%{ /* NOCONTEXT */ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1302 |
|
13116
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1303 |
unsigned char *ccp; |
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1304 |
unsigned char *cp; |
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1305 |
INT index; |
2894 | 1306 |
unsigned char *matchP; |
8006 | 1307 |
unsigned char c, min, max; |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1308 |
int len; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1309 |
OBJ cls; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1310 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1311 |
if (__isSmallInteger(start) |
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
1312 |
&& __isStringLike(aCollectionOfCharacters)) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1313 |
matchP = __stringVal(aCollectionOfCharacters); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1314 |
index = __intVal(start); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1315 |
if (index > 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1316 |
cp = __stringVal(self) + index - 1; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1317 |
if ((cls = __qClass(self)) != String) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1318 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1319 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1320 |
len = __stringSize(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1321 |
if (index <= len) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1322 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1323 |
if (matchP[0] == 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1324 |
/* matchSet is empty */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1325 |
RETURN ( __mkSmallInteger(0) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1326 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1327 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1328 |
if (matchP[1] == 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1329 |
/* only a single character match */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1330 |
unsigned char m = matchP[0]; |
13116
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1331 |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1332 |
# ifdef FAST_MEMCHR |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1333 |
ccp = (unsigned char *) memchr(cp, m, len+1-index); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1334 |
if (ccp) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1335 |
RETURN ( __mkSmallInteger((ccp - cp) + index) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1336 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1337 |
# else |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1338 |
while ((c = *cp++) != '\0') { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1339 |
if (c == m) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1340 |
RETURN ( __mkSmallInteger(index) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1341 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1342 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1343 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1344 |
# endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1345 |
RETURN ( __mkSmallInteger(0) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1346 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1347 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1348 |
if (matchP[2] == 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1349 |
/* two character matches */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1350 |
unsigned char m1 = matchP[0]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1351 |
unsigned char m2 = matchP[1]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1352 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1353 |
while ((c = *cp++) != '\0') { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1354 |
if ((c == m1) || (c == m2)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1355 |
RETURN ( __mkSmallInteger(index) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1356 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1357 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1358 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1359 |
RETURN ( __mkSmallInteger(0) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1360 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1361 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1362 |
min = max = matchP[0]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1363 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1364 |
for (ccp = matchP+1; *ccp ; ccp++) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1365 |
unsigned char c = *ccp; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1366 |
if (c < min) min = c; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1367 |
else if (c > max) max = c; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1368 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1369 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1370 |
while ((c = *cp++) != '\0') { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1371 |
if ((c >= min) && (c <= max)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1372 |
for (ccp = matchP; *ccp ; ccp++) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1373 |
if (*ccp == c) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1374 |
RETURN ( __mkSmallInteger(index) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1375 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1376 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1377 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1378 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1379 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1380 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1381 |
RETURN ( __mkSmallInteger(0) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1382 |
} |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1383 |
} |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1384 |
%}. |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1385 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1386 |
"/ 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
|
1387 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1388 |
^ super indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1389 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1390 |
" |
8898 | 1391 |
'hello world' indexOfAny:'eoa' startingAt:1 |
1392 |
'hello world' indexOfAny:'eoa' startingAt:6 |
|
1393 |
'hello world' indexOfAny:'AOE' startingAt:1 |
|
1394 |
'hello world' indexOfAny:'o' startingAt:6 |
|
1395 |
'hello world' indexOfAny:'o' startingAt:6 |
|
19839 | 1396 |
'hello world§' indexOfAny:'#§$' startingAt:6 |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1397 |
" |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1398 |
! |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1399 |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1400 |
indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1401 |
"return the index of the next control character; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1402 |
that is a character with asciiValue < 32. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1403 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1404 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1405 |
%{ /* NOCONTEXT */ |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1406 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1407 |
REGISTER unsigned char *cp; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1408 |
REGISTER unsigned char c; |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
1409 |
REGISTER unsigned char *cpEnd; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1410 |
int len, index; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1411 |
OBJ cls; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1412 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1413 |
index = __intVal(start); |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1414 |
if (index <= 0) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1415 |
index = 1; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1416 |
} |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1417 |
len = __stringSize(self); |
15044 | 1418 |
cp = __stringVal(self); |
1419 |
if ((cls = __qClass(self)) != String) { |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1420 |
int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1421 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1422 |
cp += numInstBytes; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1423 |
len -= numInstBytes; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1424 |
} |
15044 | 1425 |
while (index <= len) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1426 |
REGISTER unsigned char c; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1427 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1428 |
c = cp[index - 1]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1429 |
if (c < ' ') { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1430 |
RETURN ( __mkSmallInteger(index) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1431 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1432 |
index++; |
15044 | 1433 |
} |
1434 |
RETURN ( __mkSmallInteger(0) ); |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1435 |
%}. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1436 |
^ super indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1437 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1438 |
" |
8898 | 1439 |
'hello world' indexOfControlCharacterStartingAt:1 |
1440 |
'hello world\foo' withCRs indexOfControlCharacterStartingAt:1 |
|
1441 |
'1\' withCRs indexOfControlCharacterStartingAt:1 |
|
1442 |
'1\' withCRs indexOfControlCharacterStartingAt:2 |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1443 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1444 |
! |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1445 |
|
3403 | 1446 |
indexOfNonSeparatorStartingAt:start |
21618 | 1447 |
"return the index of the next non-whiteSpace character, 0 if none found" |
3403 | 1448 |
|
1449 |
%{ /* NOCONTEXT */ |
|
1450 |
||
1451 |
REGISTER unsigned char *cp; |
|
1452 |
REGISTER unsigned char c; |
|
1453 |
int len, index; |
|
1454 |
OBJ cls; |
|
1455 |
||
1456 |
index = __intVal(start); |
|
1457 |
if (index <= 0) { |
|
23862 | 1458 |
index = 1; |
3403 | 1459 |
} |
1460 |
len = __stringSize(self); |
|
15044 | 1461 |
cp = __stringVal(self); |
1462 |
if ((cls = __qClass(self)) != String) { |
|
23862 | 1463 |
int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1464 |
||
1465 |
cp += numInstBytes; |
|
1466 |
len -= numInstBytes; |
|
3403 | 1467 |
} |
15044 | 1468 |
while (index <= len) { |
23862 | 1469 |
REGISTER unsigned char c; |
1470 |
||
1471 |
c = cp[index - 1]; |
|
1472 |
if (c > ' ') { |
|
1473 |
if ((c != ' ') && (c != '\t') && (c != '\n') |
|
1474 |
&& (c != '\r') && (c != '\f')) { |
|
1475 |
RETURN ( __mkSmallInteger(index) ); |
|
1476 |
} |
|
1477 |
} |
|
1478 |
index++; |
|
3403 | 1479 |
} |
8913 | 1480 |
RETURN ( __mkSmallInteger(0) ); |
3403 | 1481 |
%}. |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1482 |
^ super indexOfNonSeparatorStartingAt:start |
3403 | 1483 |
|
1484 |
" |
|
8898 | 1485 |
'hello world' indexOfNonWhiteSpaceStartingAt:3 |
1486 |
'hello world' indexOfNonWhiteSpaceStartingAt:7 |
|
3403 | 1487 |
" |
21618 | 1488 |
|
1489 |
"Modified: / 01-03-2017 / 15:25:40 / cg" |
|
3403 | 1490 |
! |
1491 |
||
1 | 1492 |
indexOfSeparatorStartingAt:start |
21618 | 1493 |
"return the index of the next separator (whitespace) character; 0 if none found" |
1 | 1494 |
|
1495 |
%{ /* NOCONTEXT */ |
|
1496 |
||
19748 | 1497 |
if (__isSmallInteger(start)) { |
23862 | 1498 |
REGISTER unsigned char *cp; |
1499 |
int len, index; |
|
1500 |
OBJ cls; |
|
1501 |
||
1502 |
index = __intVal(start)-1; |
|
1503 |
// is this a good idea? |
|
1504 |
if (index < 0) { |
|
1505 |
index = 0; |
|
1506 |
} |
|
1507 |
len = __stringSize(self); |
|
1508 |
cp = __stringVal(self); |
|
1509 |
||
1510 |
// care for subclasses of string |
|
1511 |
if ((cls = __qClass(self)) != String) { |
|
1512 |
int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1513 |
||
1514 |
cp += numInstBytes; |
|
1515 |
len -= numInstBytes; |
|
1516 |
} |
|
1517 |
||
1518 |
// these pre-loops do fast skip over non-separators |
|
1519 |
// (anything above 0x32) |
|
19748 | 1520 |
#if __POINTER_SIZE__ == 8 |
23862 | 1521 |
if ((index & 7) == 0) { |
1522 |
int len8 = len-8; |
|
1523 |
while (index < len8) { |
|
1524 |
REGISTER unsigned INT eightChars; |
|
1525 |
REGISTER unsigned INT eightCharsMasked; |
|
1526 |
||
1527 |
eightChars = ((unsigned INT *)(cp+index))[0]; |
|
1528 |
eightCharsMasked = eightChars & 0xE0E0E0E0E0E0E0E0ULL; |
|
1529 |
||
1530 |
// any control char? |
|
1531 |
// (these are 0..31 and also the space); |
|
1532 |
// so we need two compares. |
|
19748 | 1533 |
# define hasZeroByte(v) (((v) - 0x0101010101010101ULL) & ~(v) & 0x8080808080808080ULL) |
1534 |
# define hasByteM(v,m) hasZeroByte( (v) ^ m) |
|
19790 | 1535 |
# define maskSpace (~0ULL/255 * (32)) |
1536 |
||
23862 | 1537 |
if (hasByteM(eightChars, maskSpace)) break; |
1538 |
if (hasZeroByte(eightCharsMasked)) break; |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1539 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1540 |
# undef hasZeroByte |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1541 |
# undef hasByteM |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1542 |
# undef maskSpace |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1543 |
|
23862 | 1544 |
index += 8; |
1545 |
} |
|
1546 |
} |
|
19748 | 1547 |
#endif /* POINTER_SIZE == 8*/ |
1548 |
||
23862 | 1549 |
if ((index & 3) == 0) { |
1550 |
int len4 = len-4; |
|
1551 |
while (index < len4) { |
|
1552 |
REGISTER unsigned int fourChars; |
|
1553 |
REGISTER unsigned int fourCharsMasked; |
|
1554 |
||
1555 |
fourChars = ((unsigned int *)(cp+index))[0]; |
|
1556 |
fourCharsMasked = fourChars & 0xE0E0E0E0UL; |
|
1557 |
||
1558 |
// any control char? |
|
1559 |
// (these are 0..31 and also the space); |
|
1560 |
// so we need two compares. |
|
19748 | 1561 |
# define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL) |
1562 |
# define hasByteM(v,m) hasZeroByte( (v) ^ m) |
|
1563 |
# define maskSpace (~0UL/255 * (32)) |
|
1564 |
||
23862 | 1565 |
if (hasByteM(fourChars, maskSpace)) break; |
1566 |
if (hasZeroByte(fourCharsMasked)) break; |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1567 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1568 |
# undef hasZeroByte |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1569 |
# undef hasByteM |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1570 |
# undef maskSpace |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1571 |
|
23862 | 1572 |
index += 4; |
1573 |
} |
|
1574 |
} |
|
1575 |
||
1576 |
while (index < len) { |
|
1577 |
REGISTER unsigned char c; |
|
1578 |
||
1579 |
c = cp[index]; |
|
1580 |
if (c <= ' ') { |
|
1581 |
if ((c == ' ') || (c == '\t') || (c == '\n') |
|
1582 |
|| (c == '\r') || (c == '\f')) { |
|
1583 |
RETURN ( __mkSmallInteger(index+1) ); |
|
1584 |
} |
|
1585 |
} |
|
1586 |
index++; |
|
1587 |
} |
|
1588 |
RETURN ( __mkSmallInteger(0) ); |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1589 |
} |
5407 | 1590 |
%}. |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1591 |
^ super indexOfSeparatorStartingAt:start |
53 | 1592 |
|
19748 | 1593 |
" 123456789012 |
1594 |
'hello world ' indexOfSeparatorStartingAt:1 -> 6 |
|
1595 |
'hello world ' indexOfSeparatorStartingAt:3 -> 6 |
|
1596 |
'hello world ' indexOfSeparatorStartingAt:7 -> 12 |
|
1597 |
'hello world' indexOfSeparatorStartingAt:7 -> 0 |
|
1598 |
'helloworld' indexOfSeparatorStartingAt:1 -> 0 |
|
95 | 1599 |
" |
19748 | 1600 |
|
1601 |
" |
|
1602 |
|s| |
|
1603 |
s := String new:1000 withAll:$a. |
|
1604 |
self assert:(s indexOfSeparatorStartingAt:1) == 0. |
|
1605 |
Time millisecondsToRun:[ |
|
23862 | 1606 |
1000000 timesRepeat:[ s indexOfSeparatorStartingAt:1 ] |
19748 | 1607 |
] |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1608 |
original (char-wise):760 760 750 |
19748 | 1609 |
with 4-byte at a time: 640 650 620 |
1610 |
with 8-byte at a time: 300 290 320 |
|
1611 |
" |
|
1612 |
" |
|
1613 |
|s| |
|
1614 |
s := String new:1000 withAll:$a. |
|
1615 |
s at:400 put:(Character return). |
|
1616 |
self assert:(s indexOfSeparatorStartingAt:1) == 400. |
|
1617 |
Time millisecondsToRun:[ |
|
23862 | 1618 |
1000000 timesRepeat:[ s indexOfSeparatorStartingAt:1 ] |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1619 |
] |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1620 |
original (char-wise):340 350 |
19748 | 1621 |
with 4-byte at a time: 310 290 280 |
1622 |
with 8-byte at a time: 150 140 140 |
|
1623 |
" |
|
1624 |
" |
|
1625 |
|s| |
|
1626 |
s := String new:1000 withAll:$a. |
|
1627 |
s at:999 put:(Character space). |
|
1628 |
self assert:(s indexOfSeparatorStartingAt:1) == 999. |
|
1629 |
Time millisecondsToRun:[ |
|
23862 | 1630 |
1000000 timesRepeat:[ s indexOfSeparatorStartingAt:1 ] |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1631 |
] |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1632 |
original (char-wise): 750 750 790 |
19748 | 1633 |
with 4-byte at a time: 640 640 620 |
1634 |
with 8-byte at a time: 280 290 300 |
|
95 | 1635 |
" |
21618 | 1636 |
|
1637 |
"Modified: / 01-03-2017 / 15:26:01 / cg" |
|
608 | 1638 |
! |
1639 |
||
1640 |
occurrencesOf:aCharacter |
|
1641 |
"count the occurrences of the argument, aCharacter in myself |
|
1642 |
- reimplemented here for speed" |
|
1643 |
||
1644 |
%{ /* NOCONTEXT */ |
|
1645 |
||
1646 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1647 |
REGISTER unsigned byteValue; |
8913 | 1648 |
REGISTER INT count, limit; |
608 | 1649 |
OBJ cls; |
1650 |
||
1651 |
if (__isCharacter(aCharacter)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1652 |
limit = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1653 |
count = 0; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1654 |
byteValue = __intVal(__characterVal(aCharacter)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1655 |
if (byteValue <= 0xFF) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1656 |
cp = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1657 |
if ((cls = __qClass(self)) != String) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1658 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1659 |
limit -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1660 |
cp += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1661 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1662 |
/* loop unrolled and software-pipelined |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1663 |
* (gives 30-40% speedup on Intel-DUO using borland bcc55) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1664 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1665 |
while (limit >= 4) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1666 |
register unsigned char c1, c2; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1667 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1668 |
c1 = cp[0]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1669 |
limit -= 4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1670 |
c2 = cp[1]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1671 |
if (c1 == byteValue) count++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1672 |
c1 = cp[2]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1673 |
if (c2 == byteValue) count++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1674 |
c2 = cp[3]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1675 |
if (c1 == byteValue) count++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1676 |
cp += 4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1677 |
if (c2 == byteValue) count++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1678 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1679 |
while (limit > 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1680 |
register unsigned char c1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1681 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1682 |
c1 = cp[0]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1683 |
limit--; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1684 |
if (c1 == byteValue) count++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1685 |
cp ++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1686 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1687 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1688 |
RETURN ( __mkSmallInteger(count) ); |
608 | 1689 |
} |
1690 |
%}. |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
1691 |
^ super occurrencesOf:aCharacter |
608 | 1692 |
|
1693 |
" |
|
1694 |
'hello world' occurrencesOf:$a |
|
1695 |
'hello world' occurrencesOf:$w |
|
8898 | 1696 |
'hello world' occurrencesOf:$l |
1697 |
'hello world' occurrencesOf:$x |
|
1698 |
'hello world' occurrencesOf:1 |
|
11418 | 1699 |
Time millisecondsToRun:[ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1700 |
1000000 timesRepeat:[ 'abcdefghijklmn' occurrencesOf:$x ] |
11418 | 1701 |
]. 219 203 156 203 204 204 219 172 187 187 141 |
608 | 1702 |
" |
53 | 1703 |
! ! |
1704 |
||
608 | 1705 |
!String methodsFor:'comparing'! |
2 | 1706 |
|
8312 | 1707 |
< aString |
1708 |
"Compare the receiver with the argument and return true if the |
|
1709 |
receiver is greater than the argument. Otherwise return false. |
|
1710 |
No national variants are honored; use after: for this. |
|
1711 |
In contrast to ST-80, case differences are NOT ignored, thus |
|
8898 | 1712 |
'foo' < 'Foo' will return false. |
8312 | 1713 |
This may change." |
1714 |
||
1715 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
1716 |
#ifdef __SCHTEAM__ |
18236 | 1717 |
return context._RETURN( self.stringLtP(aString) ); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1718 |
/* NOTREACHED */ |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1719 |
#else |
8312 | 1720 |
int len1, len2, cmp; |
1721 |
unsigned char *cp1, *cp2; |
|
14664 | 1722 |
int argIsString; |
1723 |
||
1724 |
if (__isNonNilObject(aString)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1725 |
argIsString = __qIsStringLike(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1726 |
if (argIsString || __qClass(aString) == __qClass(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1727 |
cp2 = __stringVal(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1728 |
len2 = __stringSize(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1729 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1730 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1731 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1732 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1733 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1734 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1735 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1736 |
len2 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1737 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1738 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1739 |
cp1 = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1740 |
len1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1741 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1742 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1743 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1744 |
if (!__qIsStringLike(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1745 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1746 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1747 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1748 |
len1 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1749 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1750 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1751 |
if (len1 <= len2) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1752 |
cmp = strncmp(cp1, cp2, len1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1753 |
else |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1754 |
cmp = strncmp(cp1, cp2, len2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1755 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1756 |
if (cmp < 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1757 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1758 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1759 |
if ((cmp == 0) && (len1 < len2)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1760 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1761 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1762 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1763 |
} |
8312 | 1764 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1765 |
#endif |
8312 | 1766 |
%}. |
1767 |
^ super < aString |
|
1768 |
! |
|
1769 |
||
608 | 1770 |
= aString |
1771 |
"Compare the receiver with the argument and return true if the |
|
1772 |
receiver is equal to the argument. Otherwise return false. |
|
1773 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
|
1774 |
Use sameAs: to compare with case ignored." |
|
1 | 1775 |
|
375 | 1776 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
1777 |
#ifdef __SCHTEAM__ |
18347 | 1778 |
if (aString == self) { |
1779 |
return __c__._RETURN_true(); |
|
1780 |
} |
|
1781 |
if (aString.isStringLike()) { |
|
18700 | 1782 |
return __c__._RETURN( self.isStringEqual(aString) ? STObject.True : STObject.False ); |
18347 | 1783 |
} |
18700 | 1784 |
if (aString == STObject.Nil) { |
1785 |
return __c__._RETURN_false(); |
|
1786 |
} |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1787 |
#else |
608 | 1788 |
int l1, l2; |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1789 |
unsigned char *cp1, *cp2; |
3335 | 1790 |
INT addrDelta; |
14664 | 1791 |
int argIsString; |
1792 |
||
1793 |
if (aString == self) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1794 |
RETURN ( true ); |
608 | 1795 |
} |
14664 | 1796 |
if (! __isNonNilObject(aString)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1797 |
RETURN ( false ); |
608 | 1798 |
} |
1 | 1799 |
|
14664 | 1800 |
argIsString = __qIsStringLike(aString); |
1801 |
if (argIsString || __qClass(aString) == __qClass(self)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1802 |
cp2 = __stringVal(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1803 |
l2 = __stringSize(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1804 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1805 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1806 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1807 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1808 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1809 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1810 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1811 |
l2 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1812 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1813 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1814 |
cp1 = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1815 |
l1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1816 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1817 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1818 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1819 |
if (!__qIsStringLike(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1820 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1821 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1822 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1823 |
l1 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1824 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1825 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1826 |
if (l1 != l2) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1827 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1828 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1829 |
# ifdef FAST_MEMCMP |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1830 |
RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false ); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1831 |
# else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1832 |
addrDelta = cp2 - cp1; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1833 |
# ifdef __UNROLL_LOOPS__ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1834 |
while (l1 >= (sizeof(unsigned INT)*4)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1835 |
if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1836 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1837 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1838 |
if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1839 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1840 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1841 |
if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1842 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1843 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1844 |
if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1845 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1846 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1847 |
l1 -= (sizeof(unsigned INT) * 4); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1848 |
cp1 += (sizeof(unsigned INT) * 4); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1849 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1850 |
# endif /* __UNROLL_LOOPS__ */ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1851 |
while (l1 >= sizeof(unsigned INT)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1852 |
if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1853 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1854 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1855 |
l1 -= sizeof(unsigned INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1856 |
cp1 += sizeof(unsigned INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1857 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1858 |
if (l1 >= sizeof(unsigned short)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1859 |
if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1860 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1861 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1862 |
l1 -= sizeof(unsigned short); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1863 |
cp1 += sizeof(unsigned short); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1864 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1865 |
while (l1) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1866 |
if (*cp1 != *(cp1+addrDelta)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1867 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1868 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1869 |
l1--; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1870 |
cp1++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1871 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1872 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1873 |
RETURN (true); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1874 |
# endif |
1 | 1875 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
1876 |
#endif /* not __SCHTEAM__ */ |
3111 | 1877 |
%}. |
608 | 1878 |
^ super = aString |
1 | 1879 |
|
95 | 1880 |
" |
8898 | 1881 |
'foo' = 'Foo' |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1882 |
'foo' sameAs: 'Foo' |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1883 |
#[0 0 1 0 0] asString = #[0 0 1 0 0] asString |
95 | 1884 |
" |
7868 | 1885 |
" |
1886 |
|tEmpty tCmp| |
|
1887 |
||
1888 |
tEmpty := Time millisecondsToRun:[ |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1889 |
1000000 timesRepeat:[] |
7868 | 1890 |
]. |
1891 |
tCmp := Time millisecondsToRun:[ |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1892 |
1000000 timesRepeat:[ '1234567890' = '1234567890' ] |
7868 | 1893 |
]. |
8898 | 1894 |
tCmp - tEmpty |
7868 | 1895 |
" |
1 | 1896 |
! |
1897 |
||
608 | 1898 |
> aString |
1899 |
"Compare the receiver with the argument and return true if the |
|
1900 |
receiver is greater than the argument. Otherwise return false. |
|
1901 |
No national variants are honored; use after: for this. |
|
1902 |
In contrast to ST-80, case differences are NOT ignored, thus |
|
8898 | 1903 |
'foo' > 'Foo' will return true. |
608 | 1904 |
This may change." |
1 | 1905 |
|
375 | 1906 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
1907 |
#ifdef __SCHTEAM__ |
18236 | 1908 |
return context._RETURN( aString.stringLtP( self ) ); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1909 |
/* NOTREACHED */ |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1910 |
#else |
608 | 1911 |
int len1, len2, cmp; |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1912 |
unsigned char *cp1, *cp2; |
14664 | 1913 |
int argIsString; |
1914 |
||
1915 |
if (__isNonNilObject(aString)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1916 |
argIsString = __qIsStringLike(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1917 |
if (argIsString || __qClass(aString) == __qClass(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1918 |
cp2 = __stringVal(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1919 |
len2 = __stringSize(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1920 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1921 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1922 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1923 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1924 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1925 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1926 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1927 |
len2 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1928 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1929 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1930 |
cp1 = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1931 |
len1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1932 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1933 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1934 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1935 |
if (!__qIsStringLike(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1936 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1937 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1938 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1939 |
len1 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1940 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1941 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1942 |
if (len1 <= len2) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1943 |
cmp = strncmp(cp1, cp2, len1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1944 |
else |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1945 |
cmp = strncmp(cp1, cp2, len2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1946 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1947 |
if (cmp > 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1948 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1949 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1950 |
if ((cmp == 0) && (len1 > len2)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1951 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1952 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1953 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1954 |
} |
1 | 1955 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
1956 |
#endif /* not __SCHTEAM__ */ |
370 | 1957 |
%}. |
608 | 1958 |
^ super > aString |
1959 |
! |
|
1 | 1960 |
|
24233 | 1961 |
compareCaselessWith:aString |
1962 |
"Compare the receiver against the argument, ignoring case. |
|
1963 |
Return 1 if the receiver is greater, 0 if equal and -1 if less than the argument." |
|
1964 |
||
1965 |
%{ /* NOCONTEXT */ |
|
1966 |
||
1967 |
int cmp; |
|
1968 |
||
1969 |
if (__isNonNilObject(aString)) { |
|
1970 |
int argIsString = __qIsStringLike(aString); |
|
1971 |
||
1972 |
if (argIsString || __qClass(aString) == __qClass(self)) { |
|
1973 |
unsigned char *cp1, *cp2; |
|
1974 |
unsigned char ch1, ch2; |
|
1975 |
||
1976 |
// |
|
1977 |
// care for instances of subclasses ... |
|
1978 |
// |
|
1979 |
cp1 = __stringVal(self); |
|
1980 |
if (!__qIsStringLike(self)) { |
|
1981 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
|
1982 |
||
1983 |
cp1 += n; |
|
1984 |
} |
|
1985 |
||
1986 |
// |
|
1987 |
// care for instances of subclasses ... |
|
1988 |
// |
|
1989 |
cp2 = __stringVal(aString); |
|
1990 |
if (!argIsString) { |
|
1991 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars)); |
|
1992 |
||
1993 |
cp2 += n; |
|
1994 |
} |
|
1995 |
||
1996 |
while (1) { |
|
1997 |
while ((ch1 = *cp1++) == (ch2 = *cp2++)) { |
|
1998 |
if (ch1 == 0) { |
|
1999 |
RETURN( __mkSmallInteger( 0 ) ); |
|
2000 |
} |
|
2001 |
} |
|
2002 |
||
2003 |
// first difference |
|
2004 |
if (ch1 == 0) { |
|
2005 |
// receiver shorter |
|
2006 |
RETURN( __mkSmallInteger( -1 ) ); |
|
2007 |
} |
|
2008 |
if (ch2 == 0) { |
|
2009 |
// arg shorter |
|
2010 |
RETURN( __mkSmallInteger( 1 ) ); |
|
2011 |
} |
|
2012 |
||
2013 |
if (((ch1 >= 'A') && (ch1 <= 'Z')) |
|
2014 |
|| ((ch1 >= 0xC0) && (ch1 <= 0xDE) && (ch1 != 0xD7))) { |
|
2015 |
ch1 += 'a'-'A'; |
|
2016 |
} |
|
2017 |
if (((ch2 >= 'A') && (ch2 <= 'Z')) |
|
2018 |
|| ((ch2 >= 0xC0) && (ch2 <= 0xDE) && (ch2 != 0xD7))) { |
|
2019 |
ch2 += 'a'-'A'; |
|
2020 |
} |
|
2021 |
if (ch1 != ch2) { |
|
2022 |
if (ch1 < ch2) { |
|
2023 |
RETURN( __mkSmallInteger( -1 ) ); |
|
2024 |
} |
|
2025 |
RETURN( __mkSmallInteger( 1 ) ); |
|
2026 |
} |
|
2027 |
} |
|
2028 |
} |
|
2029 |
} |
|
2030 |
getOutOfHere: ; |
|
2031 |
%}. |
|
2032 |
" |
|
2033 |
currently, this operation is only defined for strings, symbols and subclasses. |
|
2034 |
allow for an implementation in Smalltalk |
|
2035 |
" |
|
2036 |
^ super compareCaselessWith:aString |
|
2037 |
||
2038 |
" |
|
2039 |
'aaa' compareCaselessWith:'aaaa' -1 |
|
2040 |
'aaaa' compareCaselessWith:'aaa' 1 |
|
2041 |
||
2042 |
'aaaa' compareCaselessWith:'aaaA' 0 |
|
2043 |
'aaaA' compareCaselessWith:'aaaa' 0 |
|
2044 |
'aaaAB' compareCaselessWith:'aaaa' 1 |
|
2045 |
'aaaaB' compareCaselessWith:'aaaA' 1 |
|
2046 |
'aaaa' compareCaselessWith:'aaaAB' -1 |
|
2047 |
'aaaA' compareCaselessWith:'aaaaB' -1 |
|
2048 |
'aaaa' compareCaselessWith:'aaax' -1 |
|
2049 |
'aaaa' compareCaselessWith:'aaaX' -1 |
|
2050 |
" |
|
2051 |
||
2052 |
"Created: / 29-05-2019 / 10:48:39 / Claus Gittinger" |
|
2053 |
! |
|
2054 |
||
1251 | 2055 |
compareCollatingWith:aString |
2056 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
8898 | 2057 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
1251 | 2058 |
The comparison is language specific, depending on the value of |
2059 |
LC_COLLATE, which is in the shell environment." |
|
2060 |
||
23117 | 2061 |
^ self compareWith:aString collating:true |
19741 | 2062 |
|
608 | 2063 |
" |
19839 | 2064 |
'hallo' compareWith:'hällo' |
2065 |
'hbllo' compareWith:'hällo' |
|
2066 |
||
2067 |
'hallo' compareCollatingWith:'hällo' |
|
2068 |
'hbllo' compareCollatingWith:'hällo' |
|
608 | 2069 |
" |
23117 | 2070 |
|
2071 |
"Modified (format): / 20-06-2018 / 10:14:09 / Claus Gittinger" |
|
1 | 2072 |
! |
2073 |
||
14664 | 2074 |
compareWith:aString |
2075 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2076 |
greater, 0 if equal and -1 if less than the argument. |
|
2077 |
This comparison is based on the elements' codepoints - |
|
2078 |
i.e. upper/lowercase & national characters are NOT treated specially. |
|
2079 |
'foo' compareWith: 'Foo' will return 1. |
|
2080 |
while 'foo' sameAs:'Foo' will return true" |
|
2081 |
||
19741 | 2082 |
^ self compareWith:aString collating:false |
2083 |
! |
|
2084 |
||
2085 |
compareWith:aString collating:collatingBoolean |
|
2086 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2087 |
greater, 0 if equal and -1 if less than the argument. |
|
2088 |
If the collatingBoolean is true, the comparison will be based on the |
|
2089 |
current setting of LC_COLLATE in the locale (which is set in the shell environment); |
|
2090 |
otherwise, it will be a simple string-compare. |
|
2091 |
This comparison is based on the elements' codepoints - |
|
2092 |
i.e. upper/lowercase & national characters are NOT treated specially. |
|
2093 |
'foo' compareWith: 'Foo' will return 1. |
|
2094 |
while 'foo' sameAs:'Foo' will return true" |
|
2095 |
||
14664 | 2096 |
%{ /* NOCONTEXT */ |
2097 |
||
2098 |
int cmp; |
|
2099 |
unsigned char *cp1, *cp2; |
|
2100 |
int argIsString; |
|
2101 |
||
2102 |
if (__isNonNilObject(aString)) { |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2103 |
argIsString = __qIsStringLike(aString); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2104 |
if (argIsString || __qClass(aString) == __qClass(self)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2105 |
// |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2106 |
// care for instances of subclasses ... |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2107 |
// |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2108 |
cp1 = __stringVal(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2109 |
if (!__qIsStringLike(self)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2110 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2111 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2112 |
cp1 += n; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2113 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2114 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2115 |
// |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2116 |
// care for instances of subclasses ... |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2117 |
// |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2118 |
cp2 = __stringVal(aString); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2119 |
if (!argIsString) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2120 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2121 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2122 |
cp2 += n; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2123 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2124 |
if (collatingBoolean == true) { |
19741 | 2125 |
#ifdef HAS_STRCOLL |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2126 |
cmp = strcoll(cp1, cp2); |
19741 | 2127 |
#else |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2128 |
// bail out, to give programmer a chance to do it in Smalltalk (inherited) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2129 |
goto getOutOfHere; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2130 |
#endif |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2131 |
} else { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2132 |
cmp = strcmp(cp1, cp2); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2133 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2134 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2135 |
// int signum = (cmp>0) ? 1 : ((cmp<0) ? -1 : 0); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2136 |
int signum = (cmp > 0) - (cmp < 0); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2137 |
RETURN( __mkSmallInteger( signum ) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2138 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2139 |
} |
14664 | 2140 |
} |
19741 | 2141 |
getOutOfHere: ; |
14664 | 2142 |
%}. |
2143 |
" |
|
19741 | 2144 |
currently, this operation is only defined for strings, symbols and subclasses. |
2145 |
allow for an implementation in Smalltalk |
|
14664 | 2146 |
" |
19741 | 2147 |
^ super compareWith:aString collating:collatingBoolean |
14664 | 2148 |
! |
2149 |
||
22376 | 2150 |
endsWith:aStringOrChar |
2151 |
"return true, if the receiver ends with something, aStringOrChar. |
|
2152 |
If aStringOrChar is an empty string, true is returned" |
|
2153 |
||
2154 |
%{ /* NOCONTEXT */ |
|
2155 |
#ifndef __SCHTEAM__ |
|
2156 |
int len1, len2; |
|
2157 |
REGISTER unsigned char *src1, *src2; |
|
2158 |
unsigned char c; |
|
2159 |
REGISTER OBJ slf = self; |
|
2160 |
||
2161 |
if (__isStringLike(slf) && __isStringLike(aStringOrChar)) { |
|
2162 |
len1 = __qSize(slf); |
|
2163 |
len2 = __qSize(aStringOrChar); |
|
2164 |
if (len1 < len2) { |
|
2165 |
RETURN ( false ); |
|
2166 |
} |
|
2167 |
||
2168 |
src1 = __stringVal(slf) + (len1 - len2); |
|
2169 |
src2 = __stringVal(aStringOrChar); |
|
2170 |
while ((c = *src2++) != '\0') { |
|
2171 |
if (c != *src1++) { |
|
2172 |
RETURN ( false ); |
|
2173 |
} |
|
2174 |
} |
|
2175 |
RETURN (true); |
|
2176 |
} |
|
2177 |
if (__isCharacter(aStringOrChar)) { |
|
2178 |
int val; |
|
2179 |
||
2180 |
val = __intVal(__characterVal(aStringOrChar)); |
|
2181 |
if ((unsigned)val <= 0xFF) { |
|
2182 |
len1 = __stringSize(slf); |
|
2183 |
if (len1 > 0) { |
|
2184 |
RETURN ( (__stringVal(slf)[len1-1] == val) ? true : false); |
|
2185 |
} |
|
2186 |
} |
|
2187 |
RETURN ( false ); |
|
2188 |
} |
|
2189 |
#endif /* ! __SCHTEAM__ */ |
|
2190 |
%}. |
|
2191 |
^ super endsWith:aStringOrChar |
|
2192 |
||
2193 |
" |
|
2194 |
'hello world' endsWith:'world' |
|
2195 |
'hello world' endsWith:'earth' |
|
2196 |
'hello world' endsWith:$d |
|
2197 |
'hello world' endsWith:$e |
|
2198 |
'' endsWith:$d |
|
2199 |
'hello world' endsWith:#($r $l $d) |
|
2200 |
'hello world' endsWith:'' |
|
2201 |
" |
|
2202 |
! |
|
2203 |
||
14653 | 2204 |
hash |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2205 |
"return an integer useful as a hash-key. |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2206 |
This default method uses whichever hash algorithm |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2207 |
used in the ST/X VM (which is actually fnv-1a)" |
14653 | 2208 |
|
2209 |
%{ /* NOCONTEXT */ |
|
18343 | 2210 |
#ifdef __SCHTEAM__ |
2211 |
STString me = self.asSTString(); |
|
2212 |
long h = me.hash_fnv1a(); |
|
2213 |
return __c__._RETURN(STInteger._new(h)); |
|
2214 |
#else |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2215 |
extern unsigned int __symbolHash(char *); |
18581 | 2216 |
unsigned char *cp = __stringVal(self); |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2217 |
unsigned int h; |
14653 | 2218 |
|
2219 |
if (!__qIsStringLike(self)) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2220 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
14653 | 2221 |
} |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2222 |
h = __symbolHash(cp); |
16891
93560afff48f
oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents:
16889
diff
changeset
|
2223 |
// make sure, it fits into a smallInt |
93560afff48f
oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents:
16889
diff
changeset
|
2224 |
h = (h ^ (h >> 30)) & 0x3FFFFFFF; |
93560afff48f
oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents:
16889
diff
changeset
|
2225 |
RETURN(__mkSmallInteger(h)); |
18343 | 2226 |
#endif /* not SCHTEAM */ |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2227 |
%}. |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2228 |
^ self primitiveFailed |
14653 | 2229 |
|
2230 |
" |
|
2231 |
'a' hash |
|
2232 |
'ab' hash = 'ab' asUnicode16String hash |
|
2233 |
" |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2234 |
|
14653 | 2235 |
"Created: / 26-12-2011 / 13:53:09 / cg" |
2236 |
! |
|
2237 |
||
13880 | 2238 |
hash_dragonBook |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2239 |
"return an integer useful as a hash-key. |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2240 |
This method implements the dragon-book algorithm (aho, ullman)." |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2241 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2242 |
%{ /* NOCONTEXT */ |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2243 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2244 |
REGISTER unsigned g, val; |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2245 |
REGISTER unsigned char *cp, *cp0; |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2246 |
int l; |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2247 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2248 |
cp = __stringVal(self); |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2249 |
l = __stringSize(self); |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2250 |
if (__qClass(self) != @global(String)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2251 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2252 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2253 |
cp += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2254 |
l -= n; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2255 |
} |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2256 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2257 |
/* |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2258 |
* this is the dragon-book algorithm |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2259 |
*/ |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2260 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2261 |
val = 0; |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2262 |
switch (l) { |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2263 |
default: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2264 |
for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2265 |
val = (val << 4) + *cp; |
18551
7f43475b5613
eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents:
18405
diff
changeset
|
2266 |
if ((g = (val & 0xF0000000)) != 0) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2267 |
val ^= g >> 24; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2268 |
val ^= g; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2269 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2270 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2271 |
break; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2272 |
case 6: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2273 |
val = cp[5] << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2274 |
case 5: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2275 |
val = (val + cp[4]) << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2276 |
case 4: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2277 |
val = (val + cp[3]) << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2278 |
case 3: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2279 |
val = (val + cp[2]) << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2280 |
case 2: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2281 |
val = (val + cp[1]) << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2282 |
case 1: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2283 |
val = val + cp[0]; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2284 |
case 0: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2285 |
break; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2286 |
} |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2287 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2288 |
/* |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2289 |
* multiply by large prime to spread values |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2290 |
* This speeds up Set and Dictionary by a factor of 10! |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2291 |
*/ |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2292 |
val *= 31415821; |
12763 | 2293 |
RETURN ( __mkSmallInteger(val & _MAX_INT)); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2294 |
%}. |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2295 |
^ self primitiveFailed |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2296 |
! |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2297 |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2298 |
hash_fnv1a |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2299 |
"return an integer useful as a hash-key. |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2300 |
This method uses the fnv-1a algorithm |
23690 | 2301 |
(which is actually a pretty good one). |
23860 | 2302 |
Notice: this returns a 31bit value, |
23862 | 2303 |
even on 64bit CPUs, only small 4-byte hashvalues are returned, |
2304 |
(so hash values are independent from the architecture)" |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2305 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2306 |
%{ /* NOCONTEXT */ |
18343 | 2307 |
#ifdef __SCHTEAM__ |
2308 |
STString me = self.asSTString(); |
|
2309 |
long h = me.hash_fnv1a(); |
|
2310 |
return __c__._RETURN(STInteger._new(h)); |
|
2311 |
#else |
|
18581 | 2312 |
REGISTER unsigned int h = 2166136261u; |
2313 |
REGISTER unsigned char *cp = __stringVal(self); |
|
2314 |
INT l = __stringSize(self); |
|
2315 |
||
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2316 |
if (!__qIsStringLike(self)) { |
23862 | 2317 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
2318 |
||
2319 |
cp += n; |
|
2320 |
l -= n; |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2321 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2322 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2323 |
while (l >= 4) { |
23862 | 2324 |
l -= 4; |
2325 |
h = (h ^ cp[0]) * 16777619; |
|
2326 |
h = (h ^ cp[1]) * 16777619; |
|
2327 |
h = (h ^ cp[2]) * 16777619; |
|
2328 |
h = (h ^ cp[3]) * 16777619; |
|
2329 |
cp += 4; |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2330 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2331 |
while (l--) { |
23862 | 2332 |
h = (h ^ *cp++) * 16777619; |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2333 |
} |
16900
04c111f73292
make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents:
16891
diff
changeset
|
2334 |
// make it a smallInteger |
04c111f73292
make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents:
16891
diff
changeset
|
2335 |
h = (h ^ (h >> 30)) & 0x3FFFFFFF; |
04c111f73292
make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents:
16891
diff
changeset
|
2336 |
RETURN ( __mkSmallInteger(h)); |
18343 | 2337 |
#endif /* not SCHTEAM */ |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2338 |
%}. |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2339 |
^ self primitiveFailed |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2340 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2341 |
" |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2342 |
'a' hash_fnv1a |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2343 |
" |
23690 | 2344 |
|
2345 |
"Modified: / 10-02-2019 / 14:05:47 / Claus Gittinger" |
|
23860 | 2346 |
"Modified (comment): / 09-03-2019 / 20:55:23 / Claus Gittinger" |
2347 |
! |
|
2348 |
||
2349 |
hash_fnv1a_64 |
|
2350 |
"return an integer useful as a hash-key. |
|
2351 |
This method uses the fnv-1a algorithm |
|
2352 |
(which is actually a pretty good one). |
|
2353 |
Notice: this returns 64 bit hashvalues" |
|
2354 |
||
2355 |
%{ /* NOCONTEXT */ |
|
2356 |
#ifndef __SCHTEAM__ |
|
23862 | 2357 |
# ifndef __BORLANDC__ |
23864
908e62ca4254
Fix unsigned long long int warning.
Stefan Vogel <sv@exept.de>
parents:
23862
diff
changeset
|
2358 |
unsigned long long h = 14695981039346656037LLU; |
908e62ca4254
Fix unsigned long long int warning.
Stefan Vogel <sv@exept.de>
parents:
23862
diff
changeset
|
2359 |
unsigned char *cp = __stringVal(self); |
23860 | 2360 |
INT l = __stringSize(self); |
2361 |
||
2362 |
if (!__qIsStringLike(self)) { |
|
23862 | 2363 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
2364 |
||
2365 |
cp += n; |
|
2366 |
l -= n; |
|
23860 | 2367 |
} |
2368 |
||
2369 |
while (l >= 4) { |
|
23862 | 2370 |
l -= 4; |
2371 |
h = (h ^ cp[0]) * 1099511628211LL; |
|
2372 |
h = (h ^ cp[1]) * 1099511628211LL; |
|
2373 |
h = (h ^ cp[2]) * 1099511628211LL; |
|
2374 |
h = (h ^ cp[3]) * 1099511628211LL; |
|
2375 |
cp += 4; |
|
23860 | 2376 |
} |
2377 |
while (l--) { |
|
23862 | 2378 |
h = (h ^ *cp++) * 1099511628211LL; |
23860 | 2379 |
} |
2380 |
// make it a smallInteger |
|
2381 |
h = (h ^ (h >> 30)) & 0x3FFFFFFFFFFFFFFFLL; |
|
2382 |
RETURN ( __mkSmallInteger(h)); |
|
23862 | 2383 |
# endif /* not BORLAND */ |
23860 | 2384 |
#endif /* not SCHTEAM */ |
2385 |
%}. |
|
23862 | 2386 |
^ super hash_fnv1a_64 |
23860 | 2387 |
|
2388 |
" |
|
2389 |
'' hash_fnv1a_64 |
|
2390 |
'a' hash_fnv1a_64 |
|
2391 |
'77kepQFQ8Kl' hash_fnv1a_64 |
|
2392 |
" |
|
2393 |
||
2394 |
"Created: / 09-03-2019 / 08:59:54 / Claus Gittinger" |
|
23861 | 2395 |
"Modified: / 09-03-2019 / 20:56:40 / Claus Gittinger" |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2396 |
! |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2397 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2398 |
hash_java |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2399 |
"return an integer useful as a hash-key. |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2400 |
This method uses the same algorithm as used in |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2401 |
the java virtual machine (which is actually a bad one)." |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2402 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2403 |
%{ /* NOCONTEXT */ |
18343 | 2404 |
#ifdef __SCHTEAM__ |
2405 |
STString me = self.asSTString(); |
|
2406 |
long h = me.hash_java(); |
|
2407 |
return __c__._RETURN(STInteger._new(h)); |
|
2408 |
#else |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2409 |
REGISTER unsigned INT val; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2410 |
REGISTER unsigned char *cp; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2411 |
int l; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2412 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2413 |
cp = __stringVal(self); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2414 |
l = __stringSize(self); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2415 |
if (!__qIsStringLike(self)) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2416 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2417 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2418 |
cp += n; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2419 |
l -= n; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2420 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2421 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2422 |
/* |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2423 |
* this is the jvm algorithm |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2424 |
*/ |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2425 |
val = 0; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2426 |
while (l >= 4) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2427 |
l -= 4; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2428 |
val = ((val * 31) & 0xFFFFFFFF) + cp[0]; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2429 |
val = ((val * 31) & 0xFFFFFFFF) + cp[1]; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2430 |
val = ((val * 31) & 0xFFFFFFFF) + cp[2]; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2431 |
val = ((val * 31) & 0xFFFFFFFF) + cp[3]; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2432 |
cp += 4; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2433 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2434 |
while (l--) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2435 |
val = ((val * 31) & 0xFFFFFFFF) + *cp++; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2436 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2437 |
RETURN ( __MKUINT(val)); |
18343 | 2438 |
#endif /* not SCHTEAM */ |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2439 |
%}. |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2440 |
^ self primitiveFailed |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2441 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2442 |
" |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2443 |
'a' hash_java |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2444 |
" |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2445 |
! |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2446 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2447 |
hash_sdbm |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2448 |
"return an integer useful as a hash-key. |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2449 |
This method implements the sdbm algorithm." |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2450 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2451 |
%{ /* NOCONTEXT */ |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2452 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2453 |
REGISTER unsigned INT val; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2454 |
REGISTER unsigned char *cp; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2455 |
int l; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2456 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2457 |
cp = __stringVal(self); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2458 |
l = __stringSize(self); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2459 |
if (!__qIsStringLike(self)) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2460 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2461 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2462 |
cp += n; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2463 |
l -= n; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2464 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2465 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2466 |
/* |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2467 |
* this is the sdbm algorithm |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2468 |
*/ |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2469 |
val = 0; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2470 |
while (l >= 4) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2471 |
l -= 4; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2472 |
val = ((val * 65599) & _MAX_INT) + cp[0]; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2473 |
val = ((val * 65599) & _MAX_INT) + cp[1]; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2474 |
val = ((val * 65599) & _MAX_INT) + cp[2]; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2475 |
val = ((val * 65599) & _MAX_INT) + cp[3]; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2476 |
cp += 4; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2477 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2478 |
while (l--) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2479 |
val = ((val * 65599) & _MAX_INT) + *cp++; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2480 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2481 |
RETURN ( __mkSmallInteger(val & _MAX_INT)); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2482 |
%}. |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2483 |
^ self primitiveFailed |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2484 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2485 |
" |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2486 |
'a' hash |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2487 |
'ab' hash = 'ab' asUnicode16String hash |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2488 |
" |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2489 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2490 |
"Created: / 26-12-2011 / 13:53:09 / cg" |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2491 |
! |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2492 |
|
22376 | 2493 |
levenshteinTo:aString s:substWeight k:kbdTypoWeight c:caseWeight i:insrtWeight d:deleteWeight |
2494 |
"parametrized levenshtein. arguments are the costs for |
|
2495 |
substitution, case-change, insertion and deletion of a character." |
|
2496 |
||
2497 |
%{ /* STACK: 2000 */ |
|
2498 |
#ifndef __SCHTEAM__ |
|
2499 |
/* |
|
2500 |
* this is very heavy used when correcting errors |
|
2501 |
* (all symbols are searched for best match) - therefore it must be fast |
|
2502 |
*/ |
|
2503 |
||
2504 |
unsigned short *data; |
|
2505 |
int l1, l2; |
|
2506 |
REGISTER int sz; |
|
2507 |
unsigned char *s1, *s2; |
|
2508 |
int v1, v2, v3; |
|
2509 |
INT m; |
|
2510 |
REGISTER unsigned short *dp; |
|
2511 |
REGISTER int rowDelta; |
|
2512 |
REGISTER int j; |
|
2513 |
int i; |
|
2514 |
int iW, cW, sW, kW, dW; |
|
2515 |
# define FASTSIZE 30 /* increase STACK if you increase this ... */ |
|
2516 |
unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)]; |
|
2517 |
extern void *malloc(); |
|
2518 |
||
2519 |
if (__qIsStringLike(self) && __isStringLike(aString) |
|
2520 |
&& __bothSmallInteger(insrtWeight, caseWeight) |
|
2521 |
&& __bothSmallInteger(substWeight, deleteWeight) |
|
2522 |
&& __isSmallInteger(kbdTypoWeight) |
|
2523 |
) { |
|
2524 |
iW = __intVal(insrtWeight); |
|
2525 |
cW = __intVal(caseWeight); |
|
2526 |
sW = __intVal(substWeight); |
|
2527 |
kW = __intVal(kbdTypoWeight); |
|
2528 |
dW = __intVal(deleteWeight); |
|
2529 |
s1 = __stringVal(self); |
|
2530 |
s2 = __stringVal(aString); |
|
2531 |
l1 = __stringSize(self); |
|
2532 |
l2 = __stringSize(aString); |
|
2533 |
||
2534 |
sz = (l1 < l2) ? l2 : l1; |
|
2535 |
rowDelta = sz + 1; |
|
2536 |
if (sz <= FASTSIZE) { |
|
2537 |
data = fastData; |
|
2538 |
} else { |
|
2539 |
/* add ifdef ALLOCA here ... */ |
|
2540 |
data = (unsigned short *)malloc(rowDelta * rowDelta * sizeof(short)); |
|
2541 |
if (! data) goto mallocFailed; |
|
2542 |
} |
|
2543 |
||
2544 |
data[0] = 0; |
|
2545 |
for (j=1, dp=data+1; j<=sz; j++, dp++) |
|
2546 |
*dp = dp[-1] + iW; |
|
2547 |
||
2548 |
for (i=1, dp=data+rowDelta; i<=sz; i++, dp+=rowDelta) |
|
2549 |
*dp = dp[-rowDelta] + dW; |
|
2550 |
||
2551 |
for (i=0; i<l1; i++) { |
|
2552 |
for (j=0; j<l2; j++) { |
|
2553 |
if (s1[i] == s2[j]) |
|
2554 |
m = 0; |
|
2555 |
else if (tolower(s1[i]) == tolower(s2[j])) |
|
2556 |
m = cW; |
|
2557 |
else if (sW != kW && nextOnKeyboard(tolower(s1[i]), tolower(s2[j]))) |
|
2558 |
m = kW; |
|
2559 |
else |
|
2560 |
m = sW; |
|
2561 |
||
2562 |
dp = data + ((i+1)*rowDelta) + j; |
|
2563 |
v2 = dp[0] + iW; |
|
2564 |
v1 = dp[-rowDelta] + m; |
|
2565 |
v3 = dp[-rowDelta+1] + dW; |
|
2566 |
if (v1 < v2) { |
|
2567 |
if (v1 < v3) |
|
2568 |
m = v1; |
|
2569 |
else |
|
2570 |
m = v3; |
|
2571 |
} else { |
|
2572 |
if (v2 < v3) |
|
2573 |
m = v2; |
|
2574 |
else |
|
2575 |
m = v3; |
|
2576 |
} |
|
2577 |
dp[1] = m; |
|
2578 |
} |
|
2579 |
} |
|
2580 |
m = data[l1*rowDelta + l2]; |
|
2581 |
if (sz > FASTSIZE) |
|
2582 |
free(data); |
|
2583 |
RETURN ( __mkSmallInteger(m) ); |
|
2584 |
} |
|
2585 |
mallocFailed: ; |
|
2586 |
#endif /* ! __SCHTEAM__ */ |
|
2587 |
%}. |
|
2588 |
||
2589 |
^ super levenshteinTo:aString |
|
2590 |
s:substWeight k:kbdTypoWeight c:caseWeight |
|
2591 |
i:insrtWeight d:deleteWeight |
|
2592 |
||
2593 |
" |
|
2594 |
'ocmprt' levenshteinTo:'computer' |
|
2595 |
'computer' levenshteinTo:'computer' |
|
2596 |
'ocmputer' levenshteinTo:'computer' |
|
2597 |
'cmputer' levenshteinTo:'computer' |
|
2598 |
'computer' levenshteinTo:'cmputer' |
|
2599 |
'computer' levenshteinTo:'vomputer' |
|
2600 |
'computer' levenshteinTo:'bomputer' |
|
2601 |
'Computer' levenshteinTo:'computer' |
|
2602 |
" |
|
2603 |
! |
|
2604 |
||
23218 | 2605 |
sameAs:aString |
2606 |
"Compare the receiver with the argument like =, but ignore case differences. |
|
2607 |
Return true or false." |
|
2608 |
||
2609 |
%{ /* NOCONTEXT */ |
|
2610 |
OBJ slf = self; |
|
2611 |
OBJ arg = aString; |
|
2612 |
||
2613 |
if (__qIsStringLike(slf) &&__isStringLike(arg)) { |
|
23862 | 2614 |
unsigned char *src1, *src2; |
2615 |
int len; |
|
2616 |
||
2617 |
len = __stringSize(slf); |
|
2618 |
if (len != __stringSize(arg)) { |
|
2619 |
RETURN ( false ); |
|
2620 |
} |
|
2621 |
||
2622 |
src1 = __stringVal(slf); |
|
2623 |
src2 = __stringVal(arg); |
|
2624 |
||
2625 |
// fast skip over same chars |
|
2626 |
while (len >= sizeof(int)) { |
|
2627 |
if ( ((int*)src1)[0] != ((int*)src2)[0] ) break; |
|
2628 |
len -= sizeof(int); |
|
2629 |
src1 += sizeof(int); |
|
2630 |
src2 += sizeof(int); |
|
2631 |
} |
|
2632 |
while (len > 0) { |
|
2633 |
if ( src1[0] != src2[0] ) break; |
|
2634 |
len--; |
|
2635 |
src1++; |
|
2636 |
src2++; |
|
2637 |
} |
|
2638 |
||
2639 |
while (len > 0) { |
|
2640 |
// the trouble is, that it is not as easy as we might thing on first thought; |
|
2641 |
// for plain ascii (i.e. 7bits), we can check for chars being letters and then ignore the 0x20 bit. |
|
2642 |
// this even works for the national characters except for 0xFF / 0xDF |
|
2643 |
unsigned char ch1 = src1[0]; |
|
2644 |
unsigned char ch2 = src2[0]; |
|
2645 |
if (ch1 != ch2) { |
|
2646 |
unsigned char Uch1 = ch1 & ~0x20; // upper cased |
|
2647 |
unsigned char Uch2 = ch2 & ~0x20; // uppÞer cased |
|
2648 |
if ( (Uch1 >= 'A') && (Uch1 <= 'Z') ) { |
|
2649 |
// letter |
|
2650 |
if (Uch1 != Uch2) { |
|
2651 |
RETURN(false); |
|
2652 |
} |
|
2653 |
} else { |
|
2654 |
if ( (Uch1 >= 0xC0) && (Uch1 <= 0xDE) ) { |
|
2655 |
// national letter |
|
2656 |
if (Uch1 != Uch2) { |
|
2657 |
RETURN(false); |
|
2658 |
} |
|
2659 |
} else { |
|
2660 |
// other |
|
2661 |
RETURN(false); |
|
2662 |
} |
|
2663 |
} |
|
2664 |
} |
|
2665 |
len--; |
|
2666 |
src1++; |
|
2667 |
src2++; |
|
2668 |
} |
|
2669 |
RETURN (true); |
|
23218 | 2670 |
} |
2671 |
%}. |
|
2672 |
"use fallback for wide strings" |
|
2673 |
^ super sameAs:aString |
|
2674 |
||
2675 |
" |
|
2676 |
'hello' sameAs:'hello' |
|
2677 |
'hello' sameAs:'Hello' |
|
2678 |
'hello' sameAs:'' |
|
2679 |
'' sameAs:'Hello' |
|
2680 |
'hello' sameAs:'hellO' |
|
2681 |
'hello' sameAs:'Hellx' |
|
2682 |
" |
|
23862 | 2683 |
|
23218 | 2684 |
"Created: / 19-07-2018 / 10:44:07 / Claus Gittinger" |
2685 |
! |
|
2686 |
||
22376 | 2687 |
startsWith:aStringOrChar |
2688 |
"return true, if the receiver starts with something, aStringOrChar. |
|
2689 |
If the argument is empty, true is returned. |
|
2690 |
Notice, that this is similar to, but slightly different from VW's and Squeak's beginsWith:, |
|
2691 |
which are both inconsistent w.r.t. an empty argument." |
|
2692 |
||
2693 |
%{ /* NOCONTEXT */ |
|
2694 |
#ifdef __SCHTEAM__ |
|
2695 |
if (self.isSTString()) { |
|
2696 |
if (aStringOrChar.isSTString()) { |
|
2697 |
java.lang.String me = self.asString(); |
|
2698 |
java.lang.String other = aStringOrChar.asString(); |
|
2699 |
return __c__._RETURN( me.startsWith(other) ? STObject.True : STObject.False); |
|
2700 |
} |
|
2701 |
if (aStringOrChar.isSTCharacter()) { |
|
2702 |
char[] me = self.asSTString().characters; |
|
2703 |
char ch = aStringOrChar.charValue(); |
|
2704 |
return __c__._RETURN( ((me.length > 0) |
|
2705 |
&& (me[0] == ch)) ? STObject.True : STObject.False); |
|
2706 |
} |
|
2707 |
} |
|
2708 |
#else |
|
2709 |
int len1, len2; |
|
2710 |
REGISTER unsigned char *src1, *src2; |
|
2711 |
unsigned char c; |
|
2712 |
REGISTER OBJ slf = self; |
|
2713 |
||
2714 |
if (__qIsStringLike(slf) &&__isStringLike(aStringOrChar)) { |
|
2715 |
src1 = __stringVal(slf); |
|
2716 |
src2 = __stringVal(aStringOrChar); |
|
2717 |
||
2718 |
if (src1[0] != src2[0]) { |
|
2719 |
if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) { |
|
2720 |
RETURN (true); |
|
2721 |
} |
|
2722 |
RETURN ( false ); |
|
2723 |
} |
|
2724 |
||
2725 |
len1 = __qSize(slf); |
|
2726 |
len2 = __qSize(aStringOrChar); |
|
2727 |
if (len1 < len2) { |
|
2728 |
RETURN ( false ); |
|
2729 |
} |
|
2730 |
||
2731 |
# ifdef UINT64 |
|
2732 |
while (len2 > (OHDR_SIZE+sizeof(UINT64))) { |
|
2733 |
if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) { |
|
2734 |
RETURN (false); |
|
2735 |
} |
|
2736 |
len2 -= sizeof(UINT64); |
|
2737 |
src1 += sizeof(UINT64); |
|
2738 |
src2 += sizeof(UINT64); |
|
2739 |
} |
|
2740 |
# else |
|
2741 |
# ifdef __UNROLL_LOOPS__ |
|
2742 |
while (len2 > (OHDR_SIZE+sizeof(INT)*4)) { |
|
2743 |
if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) { |
|
2744 |
RETURN (false); |
|
2745 |
} |
|
2746 |
if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) { |
|
2747 |
RETURN (false); |
|
2748 |
} |
|
2749 |
if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) { |
|
2750 |
RETURN (false); |
|
2751 |
} |
|
2752 |
if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) { |
|
2753 |
RETURN (false); |
|
2754 |
} |
|
2755 |
len2 -= sizeof(INT)*4; |
|
2756 |
src1 += sizeof(INT)*4; |
|
2757 |
src2 += sizeof(INT)*4; |
|
2758 |
} |
|
2759 |
# endif /* __UNROLL_LOOPS__ */ |
|
2760 |
# endif /* UINT64 */ |
|
2761 |
||
2762 |
while (len2 > (OHDR_SIZE+sizeof(INT))) { |
|
2763 |
if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) { |
|
2764 |
RETURN (false); |
|
2765 |
} |
|
2766 |
len2 -= sizeof(INT); |
|
2767 |
src1 += sizeof(INT); |
|
2768 |
src2 += sizeof(INT); |
|
2769 |
} |
|
2770 |
||
2771 |
while ((c = *src2++) != '\0') { |
|
2772 |
if (c != *src1) { |
|
2773 |
RETURN ( false ); |
|
2774 |
} |
|
2775 |
src1++; |
|
2776 |
} |
|
2777 |
RETURN (true); |
|
2778 |
} |
|
2779 |
if (__isCharacter(aStringOrChar)) { |
|
2780 |
int val; |
|
2781 |
||
2782 |
val = __intVal(__characterVal(aStringOrChar)); |
|
2783 |
if ((unsigned)val <= 0xFF) { |
|
2784 |
len1 = __stringSize(slf); |
|
2785 |
if (len1 > 0) { |
|
2786 |
RETURN ( (__stringVal(slf)[0] == val) ? true : false); |
|
2787 |
} |
|
2788 |
} |
|
2789 |
RETURN ( false ); |
|
2790 |
} |
|
2791 |
#endif /* not __SCHTEAM__ */ |
|
2792 |
%}. |
|
2793 |
^ super startsWith:aStringOrChar |
|
2794 |
||
2795 |
" |
|
2796 |
'hello world' startsWith:'hello' |
|
2797 |
'hello world' startsWith:'hella' |
|
2798 |
'hello world' startsWith:'hi' |
|
2799 |
'hello world' startsWith:$h |
|
2800 |
'hello world' startsWith:$H |
|
2801 |
'hello world' startsWith:(Character value:16rFF00) |
|
2802 |
'hello world' startsWith:60 |
|
2803 |
'hello world' startsWith:#($h $e $l) |
|
2804 |
'hello world' startsWith:'' |
|
2805 |
" |
|
2806 |
! |
|
2807 |
||
608 | 2808 |
~= aString |
2809 |
"Compare the receiver with the argument and return true if the |
|
2810 |
receiver is not equal to the argument. Otherwise return false. |
|
3111 | 2811 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
2812 |
Actually, there is no need to redefine that method here, |
|
2813 |
the default (= not as inherited) works ok. |
|
2814 |
However, this may be heavily used and the redefinition saves an |
|
2815 |
extra message send." |
|
1 | 2816 |
|
608 | 2817 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
2818 |
#ifdef __SCHTEAM__ |
18700 | 2819 |
if (aString == self) { |
2820 |
return __c__._RETURN_false(); |
|
2821 |
} |
|
2822 |
if (aString.isStringLike()) { |
|
2823 |
return __c__._RETURN( self.isStringEqual(aString) ? STObject.False : STObject.True ); |
|
2824 |
} |
|
2825 |
if (aString == STObject.Nil) { |
|
2826 |
return __c__._RETURN_true(); |
|
2827 |
} |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2828 |
#else |
1 | 2829 |
int l1, l2; |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
2830 |
unsigned char *cp1, *cp2; |
3111 | 2831 |
OBJ cls, myCls; |
3335 | 2832 |
INT addrDelta; |
14664 | 2833 |
int argIsString; |
2834 |
||
2835 |
if (aString == self) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2836 |
RETURN ( false ); |
608 | 2837 |
} |
14664 | 2838 |
if (! __isNonNilObject(aString)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2839 |
RETURN ( true ); |
608 | 2840 |
} |
3111 | 2841 |
|
14664 | 2842 |
argIsString = __qIsStringLike(aString); |
2843 |
if (argIsString || __qClass(aString) == __qClass(self)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2844 |
cp1 = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2845 |
l1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2846 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2847 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2848 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2849 |
if (!__qIsStringLike(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2850 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2851 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2852 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2853 |
l1 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2854 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2855 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2856 |
cp2 = __stringVal(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2857 |
l2 = __stringSize(aString); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2858 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2859 |
* care for instances of subclasses ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2860 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2861 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2862 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aString))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2863 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2864 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2865 |
l2 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2866 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2867 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2868 |
if (l1 != l2) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2869 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2870 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2871 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2872 |
addrDelta = cp2 - cp1; |
8919 | 2873 |
# ifdef __UNROLL_LOOPS__ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2874 |
while (l1 >= (sizeof(unsigned INT)*4)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2875 |
if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2876 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2877 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2878 |
if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2879 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2880 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2881 |
if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2882 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2883 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2884 |
if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2885 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2886 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2887 |
l1 -= (sizeof(unsigned INT) * 4); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2888 |
cp1 += (sizeof(unsigned INT) * 4); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2889 |
} |
8919 | 2890 |
# endif /* __UNROLL_LOOPS__ */ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2891 |
while (l1 >= sizeof(unsigned INT)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2892 |
if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2893 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2894 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2895 |
l1 -= sizeof(unsigned INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2896 |
cp1 += sizeof(unsigned INT); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2897 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2898 |
if (l1 >= sizeof(unsigned short)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2899 |
if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2900 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2901 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2902 |
l1 -= sizeof(unsigned short); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2903 |
cp1 += sizeof(unsigned short); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2904 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2905 |
while (l1) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2906 |
if (*cp1 != *(cp1+addrDelta)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2907 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2908 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2909 |
l1--; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2910 |
cp1++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2911 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2912 |
RETURN (false); |
608 | 2913 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
2914 |
#endif /* not __SCHTEAM__ */ |
3111 | 2915 |
%}. |
608 | 2916 |
^ super ~= aString |
2917 |
! ! |
|
2918 |
||
2919 |
!String methodsFor:'converting'! |
|
2920 |
||
11882 | 2921 |
asAsciiZ |
2922 |
"if the receiver does not end with a 0-valued character, return a copy of it, |
|
2923 |
with an additional 0-character. Otherwise return the receiver. This is sometimes |
|
2924 |
needed when a string has to be passed to C, which needs 0-terminated strings. |
|
2925 |
Notice, that all singleByte strings are already 0-terminated in ST/X, whereas wide |
|
2926 |
strings are not." |
|
2927 |
||
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2928 |
^ self |
11882 | 2929 |
|
2930 |
" |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2931 |
'abc' asAsciiZ |
11882 | 2932 |
'abc' asWideString asAsciiZ |
2933 |
" |
|
2934 |
! |
|
2935 |
||
10594 | 2936 |
asByteArray |
15938 | 2937 |
"return a new ByteArray with the receiver's elements. |
2938 |
This redefined method is faster than Collection>>#asByteArray" |
|
10594 | 2939 |
|
2940 |
|bytes sz| |
|
2941 |
||
2942 |
sz := self size. |
|
2943 |
bytes := ByteArray new:sz . |
|
2944 |
bytes replaceFrom:1 to:sz with:self startingAt:1. |
|
2945 |
^ bytes |
|
2946 |
||
2947 |
" |
|
16019
b204c9d6ce6d
no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents:
15938
diff
changeset
|
2948 |
'fooBar' asByteArray. |
10594 | 2949 |
" |
14260
c8e2fa654d6d
comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents:
14217
diff
changeset
|
2950 |
|
c8e2fa654d6d
comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents:
14217
diff
changeset
|
2951 |
"Modified (comment): / 26-07-2012 / 22:55:26 / cg" |
10594 | 2952 |
! |
2953 |
||
23972 | 2954 |
asDenseUnicodeString |
2955 |
"return the receiver as single-byte, double byte or 4-byte unicode string, |
|
2956 |
depending on the number of bits required to hold all characters in myself. |
|
2957 |
Use this to extract non-wide parts from a wide string, |
|
2958 |
i.e. after a substring has been copied out of a wide string" |
|
2959 |
||
2960 |
^ self |
|
2961 |
||
2962 |
"Created: / 25-03-2019 / 16:43:07 / Claus Gittinger" |
|
2963 |
! |
|
2964 |
||
9472 | 2965 |
asExternalBytes |
19170 | 2966 |
"return a 0-terminated externalBytes collection containing |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2967 |
my characters. |
19170 | 2968 |
The returned collection is save from being garbage collected; |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2969 |
i.t. it can be handed to a C-function, and must |
19170 | 2970 |
(either there or here) be freed explicitly or unprotectedFromGC" |
2971 |
||
2972 |
^ (ExternalBytes new:(self size + 1)) |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2973 |
replaceNullTerminatedFromString:self |
9472 | 2974 |
|
2975 |
" |
|
2976 |
|x| |
|
2977 |
x := 'fooBar' asExternalBytes. |
|
2978 |
x unprotectFromGC. |
|
2979 |
ObjectMemory garbageCollect |
|
2980 |
" |
|
2981 |
||
2982 |
"Modified: / 03-08-2006 / 14:45:32 / fm" |
|
2983 |
! |
|
2984 |
||
14156 | 2985 |
asExternalBytesUnprotected |
2986 |
"Like asExternalBytes, but does not register the bytes so |
|
15837 | 2987 |
bytes are GARBAGE-COLLECTED!!" |
14156 | 2988 |
|
19170 | 2989 |
^ (ExternalBytes unprotectedNew:(self size + 1)) |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2990 |
replaceNullTerminatedFromString:self |
14156 | 2991 |
|
2992 |
" |
|
2993 |
|x| |
|
2994 |
x := 'fooBar' asExternalBytesUnprotected. |
|
2995 |
ObjectMemory garbageCollect |
|
2996 |
" |
|
2997 |
||
2998 |
"Created: / 05-06-2012 / 14:12:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
15837 | 2999 |
"Modified: / 30-11-2013 / 11:41:40 / cg" |
14156 | 3000 |
! |
3001 |
||
23921 | 3002 |
asImmutableCollection |
3003 |
"return a write-protected copy of myself" |
|
3004 |
||
3005 |
^ self copy changeClassTo:ImmutableString |
|
3006 |
||
3007 |
"Created: / 15-03-2019 / 13:50:08 / Stefan Vogel" |
|
3008 |
! |
|
3009 |
||
12454 | 3010 |
asImmutableString |
3011 |
"return a write-protected copy of myself" |
|
3012 |
||
22651
57af76e8401b
oops - dont make a Symbol into an ImmutableString
Claus Gittinger <cg@exept.de>
parents:
22491
diff
changeset
|
3013 |
self isSymbol ifTrue:[^ self]. |
12454 | 3014 |
^ self copy changeClassTo:ImmutableString |
3015 |
! |
|
3016 |
||
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3017 |
asLowercase |
20109 | 3018 |
"a tuned version for Strings with size < 255. Some apps call this very heavily. |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3019 |
We can do this for 8-bit strings, since the mapping is well known and lowercase chars |
20109 | 3020 |
fit in one byte also." |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3021 |
|
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3022 |
%{ /* NOCONTEXT */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3023 |
#ifndef __SCHTEAM__ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3024 |
REGISTER OBJ slf = self; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3025 |
|
20109 | 3026 |
if (__isStringLike(slf)) { |
23862 | 3027 |
char quickBuffer[256]; |
3028 |
int sz = __stringSize(slf); |
|
3029 |
||
3030 |
if (sz < (sizeof(quickBuffer)-1)) { |
|
3031 |
REGISTER int i = 0; |
|
3032 |
int anyChange = 0; |
|
3033 |
REGISTER unsigned char *cp = __stringVal(slf); |
|
3034 |
||
3035 |
// fast advance |
|
3036 |
// all uppercase chars are in the ranges 0x41 .. 0x5A (A..Z) |
|
3037 |
// or 0xC0 .. 0xDF. |
|
3038 |
// I.e. they have the 0x20 bit clear. |
|
3039 |
// Thus, we can fast skip over lowercase, spaces and some punctuation, |
|
3040 |
// if all bytes of a word have the x20 bit set. |
|
20126 | 3041 |
|
18661 | 3042 |
#if __POINTER_SIZE__ == 8 |
23862 | 3043 |
for (; i < (sz-8); i += 8) { |
3044 |
unsigned INT eightChars = *(unsigned INT *)(cp+i); |
|
3045 |
if ((eightChars & 0x2020202020202020ULL) != 0x2020202020202020ULL) goto convert; |
|
3046 |
*(unsigned INT *)(quickBuffer+i) = eightChars; |
|
3047 |
} |
|
18661 | 3048 |
#endif |
23862 | 3049 |
for (; i < (sz-4); i += 4) { |
3050 |
unsigned int fourChars = *(unsigned int *)(cp+i); |
|
3051 |
if ((fourChars & 0x20202020U) != 0x20202020U) break; |
|
3052 |
*(unsigned int *)(quickBuffer+i) = fourChars; |
|
3053 |
} |
|
20126 | 3054 |
convert: |
23862 | 3055 |
for (; i<sz; i++) { |
3056 |
unsigned char ch = cp[i]; |
|
3057 |
||
3058 |
quickBuffer[i] = ch; |
|
3059 |
if ((ch & 0x60) == 0x40) { |
|
3060 |
if (ch >= 'A' && ch <= 'Z') { |
|
3061 |
quickBuffer[i] = ch - 'A' + 'a'; |
|
3062 |
anyChange = 1; |
|
3063 |
} else { |
|
3064 |
// deal with national latin1 characters |
|
3065 |
if (ch >= 0xC0 && ch <= 0xDE && ch != 0xD7) { |
|
3066 |
quickBuffer[i] = ch + 0x20; |
|
3067 |
anyChange = 1; |
|
3068 |
} |
|
3069 |
} |
|
3070 |
} |
|
3071 |
} |
|
3072 |
if (! anyChange) { |
|
3073 |
RETURN(slf); |
|
3074 |
} |
|
3075 |
quickBuffer[i] = '\0'; |
|
3076 |
RETURN (__MKSTRING_L(quickBuffer, i)); |
|
3077 |
} |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3078 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3079 |
#endif /* ! __SCHTEAM__ */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3080 |
%}. |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3081 |
^ super asLowercase |
20109 | 3082 |
|
3083 |
" |
|
23862 | 3084 |
'Hello WORLD' asLowercase |
3085 |
(String new:300) asLowercase |
|
3086 |
#utf8 asLowercase |
|
20109 | 3087 |
" |
21583 | 3088 |
|
3089 |
"Modified: / 27-02-2017 / 15:54:13 / stefan" |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3090 |
! |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3091 |
|
7877
bef56f06d2f8
asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents:
7869
diff
changeset
|
3092 |
asSingleByteString |
5760 | 3093 |
"I am a string" |
3094 |
||
3095 |
^ self |
|
3096 |
! |
|
3097 |
||
11287 | 3098 |
asSingleByteStringIfPossible |
3099 |
"I am a single-byte string" |
|
3100 |
||
3101 |
^ self |
|
3102 |
! |
|
3103 |
||
9473 | 3104 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
11883 | 3105 |
"return the receiver converted to a 'normal' string, |
3106 |
with invalid characters replaced by replacementCharacter. |
|
3107 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
3108 |
and replace characters above code-255 with some replacement. |
|
3109 |
Dummy here, because I am already a single byte string." |
|
3110 |
||
9473 | 3111 |
^ self |
3112 |
||
3113 |
"Modified: / 07-08-2006 / 15:04:45 / fm" |
|
3114 |
! |
|
3115 |
||
608 | 3116 |
asSymbol |
19748 | 3117 |
"Return a unique symbol with the name taken from the receiver's characters." |
7869 | 3118 |
|
3119 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
3120 |
#ifdef __SCHTEAM__ |
18286 | 3121 |
return context._RETURN( STSymbol._new(self.asString()) ); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3122 |
#else |
608 | 3123 |
OBJ newSymbol; |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3124 |
OBJ cls; |
7869 | 3125 |
char *cp = __stringVal(self); |
3126 |
||
3127 |
/* care for instances of a subclass with instVars */ |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3128 |
cls = __qClass(self); |
22651
57af76e8401b
oops - dont make a Symbol into an ImmutableString
Claus Gittinger <cg@exept.de>
parents:
22491
diff
changeset
|
3129 |
if ((cls != String) && (cls != ImmutableString)) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3130 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3131 |
} |
7869 | 3132 |
newSymbol = __MKSYMBOL(cp, (OBJ *)0); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3133 |
if (newSymbol) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3134 |
RETURN ( newSymbol); |
608 | 3135 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
3136 |
#endif /* not __SCHTEAM__ */ |
608 | 3137 |
%}. |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3138 |
^ AllocationFailure raise. |
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 |
" |
8898 | 3141 |
'hello' asSymbol |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3142 |
" |
608 | 3143 |
! |
3144 |
||
3145 |
asSymbolIfInterned |
|
19748 | 3146 |
"If a symbol with the receiver's characters is already known, return it. Otherwise, return nil. |
9233 | 3147 |
This can be used to query for an existing symbol and is the same as: |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3148 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
608 | 3149 |
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
|
3150 |
performed once." |
1 | 3151 |
|
608 | 3152 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
3153 |
#ifdef __SCHTEAM__ |
18622 | 3154 |
STObject symbolOrNull = STSymbol.asSymbolIfInterned( self.asString() ); |
3155 |
||
3156 |
return context._RETURN( symbolOrNull == null ? STObject.Nil : symbolOrNull ); |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3157 |
#else |
20162 | 3158 |
OBJ cls = __qClass(self); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3159 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3160 |
|
22651
57af76e8401b
oops - dont make a Symbol into an ImmutableString
Claus Gittinger <cg@exept.de>
parents:
22491
diff
changeset
|
3161 |
if ((cls != String) && (cls != ImmutableString)) { |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3162 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3163 |
} else { |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3164 |
indx = 0; |
608 | 3165 |
} |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3166 |
RETURN ( __SYMBOL_OR_NIL(__stringVal(self) + indx)); |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
3167 |
#endif /* not __SCHTEAM__ */ |
5407 | 3168 |
%}. |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3169 |
^ self primitiveFailed |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3170 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3171 |
'hello' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3172 |
'fooBarBaz' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3173 |
" |
608 | 3174 |
! |
3175 |
||
17378 | 3176 |
beImmutable |
3177 |
"make myself write-protected" |
|
3178 |
||
20520 | 3179 |
super beImmutable. |
17378 | 3180 |
self changeClassTo:ImmutableString |
3181 |
! |
|
3182 |
||
24210 | 3183 |
utf16Encoded |
3184 |
"UTF-16 encoding is the same as UCS-2 (Unicode16String)" |
|
3185 |
||
3186 |
^ self asUnicode16String |
|
3187 |
||
3188 |
"Created: / 28-05-2019 / 13:01:17 / Stefan Vogel" |
|
3189 |
"Modified (comment): / 28-05-2019 / 14:33:48 / Stefan Vogel" |
|
3190 |
! |
|
3191 |
||
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
3192 |
withTabsExpanded:numSpaces |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
3193 |
"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
|
3194 |
are expanded into spaces (assuming numSpaces-col tabs). |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
3195 |
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
|
3196 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
3197 |
This does handle multiline strings. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
3198 |
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
|
3199 |
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
|
3200 |
|
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
3201 |
%{ /* STACK:700 */ |
2894 | 3202 |
unsigned char buffer[80*8 + 10]; |
3203 |
unsigned char *srcP, *dstP, *cp0; |
|
608 | 3204 |
int idx, sz; |
3205 |
int any = 0; |
|
3206 |
OBJ newString; |
|
3207 |
char c; |
|
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
3208 |
int n; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
3209 |
|
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
3210 |
if ((__qClass(self) == String) |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
3211 |
&& __isSmallInteger(numSpaces)) { |
9473 | 3212 |
n = __intVal(numSpaces); |
3213 |
||
3214 |
/* |
|
3215 |
* for small strings (< 80), do it without a prescan ... |
|
3216 |
* the buffer is large enough to even convert a |
|
3217 |
* receiver consisting fully of tabs. |
|
3218 |
*/ |
|
3219 |
if (__stringSize(self) < 80) { |
|
3220 |
idx = 1; |
|
3221 |
for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) { |
|
3222 |
if (c == '\t') { |
|
3223 |
any = 1; |
|
3224 |
while (idx % n) { |
|
3225 |
idx++; |
|
3226 |
*dstP++ = ' '; |
|
3227 |
} |
|
3228 |
idx++; |
|
3229 |
*dstP++ = ' '; |
|
3230 |
} else { |
|
3231 |
*dstP++ = c; |
|
3232 |
idx++; |
|
3233 |
if (c == '\n') { |
|
3234 |
idx = 1; |
|
3235 |
} |
|
3236 |
} |
|
3237 |
} |
|
3238 |
if (! any) RETURN(self); |
|
3239 |
*dstP = '\0'; |
|
3240 |
RETURN (__MKSTRING_L(buffer, (dstP-buffer))); |
|
3241 |
} |
|
3242 |
/* |
|
3243 |
* for large strings, we compute the new size, allocate a new string |
|
3244 |
* and expand it. |
|
3245 |
* |
|
3246 |
* first, scan for size ... |
|
3247 |
*/ |
|
3248 |
idx = 1; |
|
3249 |
for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) { |
|
3250 |
if (c == '\t') { |
|
3251 |
any = 1; |
|
3252 |
while (idx % n) { |
|
3253 |
idx++; |
|
3254 |
sz++; |
|
3255 |
} |
|
3256 |
idx++; sz ++; |
|
3257 |
} else { |
|
3258 |
sz++; idx++; |
|
3259 |
if (c == '\n') { |
|
3260 |
idx = 1; |
|
3261 |
} |
|
3262 |
} |
|
3263 |
} |
|
3264 |
if (! any) RETURN(self); |
|
3265 |
||
3266 |
/* |
|
3267 |
* get the string |
|
3268 |
*/ |
|
3269 |
sz = OHDR_SIZE + sz + 1; |
|
3270 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
|
3271 |
if (newString != nil) { |
|
3272 |
__InstPtr(newString)->o_class = String; |
|
3273 |
__qSTORE(newString, String); |
|
3274 |
||
3275 |
/* |
|
3276 |
* expand |
|
3277 |
*/ |
|
3278 |
idx = 1; |
|
3279 |
for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) { |
|
3280 |
if (c == '\t') { |
|
3281 |
while (idx % n) { |
|
3282 |
idx++; |
|
3283 |
*dstP++ = ' '; |
|
3284 |
} |
|
3285 |
idx++; |
|
3286 |
*dstP++ = ' '; |
|
3287 |
} else { |
|
3288 |
*dstP++ = c; idx++; |
|
3289 |
if (c == '\n') { |
|
3290 |
idx = 1; |
|
3291 |
} |
|
3292 |
} |
|
3293 |
} |
|
3294 |
*dstP++ = '\0'; |
|
3295 |
RETURN (newString); |
|
3296 |
} |
|
608 | 3297 |
} |
3298 |
%}. |
|
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
3299 |
^ super withTabsExpanded:numSpaces |
1 | 3300 |
! ! |
3301 |
||
3302 |
!String methodsFor:'copying'! |
|
3303 |
||
20070 | 3304 |
, aStringOrCharacter |
3305 |
"return the concatenation of myself and the argument, aStringOrCharacter as a String. |
|
1 | 3306 |
- reimplemented here for speed" |
3307 |
||
3308 |
%{ |
|
18286 | 3309 |
#ifdef __SCHTEAM__ |
20070 | 3310 |
if ( aStringOrCharacter.isStringLike() && self.isStringLike() ) { |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3311 |
STString me = self.asSTString(); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3312 |
STString other = aStringOrCharacter.asSTString(); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3313 |
int myLength = me.characters.length; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3314 |
int otherLength = other.characters.length; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3315 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3316 |
char[] newChars = new char[myLength + otherLength]; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3317 |
System.arraycopy(me.characters, 0, newChars, 0, myLength); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3318 |
System.arraycopy(other.characters, 0, newChars, myLength, otherLength); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3319 |
return context._RETURN( new STString( newChars )); |
18286 | 3320 |
} |
3321 |
#else |
|
20033 | 3322 |
/* |
3323 |
* can do it here if both are Strings/Symbols: |
|
3324 |
*/ |
|
20070 | 3325 |
if (__qIsStringLike(self)) { |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3326 |
char *cp1 = (char *) __stringVal(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3327 |
int l1 = __stringSize(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3328 |
int l2; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3329 |
char *cp2 = 0; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3330 |
int sz; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3331 |
OBJ newString; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3332 |
char character; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3333 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3334 |
if (__isCharacter(aStringOrCharacter)) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3335 |
if (__intVal(__characterVal(aStringOrCharacter)) <= 0 || __intVal(__characterVal(aStringOrCharacter)) > 255) |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3336 |
goto out; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3337 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3338 |
character = __intVal(__characterVal(aStringOrCharacter)); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3339 |
l2 = 1; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3340 |
cp2 = &character; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3341 |
} else if (__isStringLike(aStringOrCharacter)) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3342 |
l2 = __stringSize(aStringOrCharacter); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3343 |
} else |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3344 |
goto out; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3345 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3346 |
sz = OHDR_SIZE + l1 + l2 + 1; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3347 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3348 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3349 |
cp1 = (char *) __stringVal(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3350 |
if (cp2 == 0) |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3351 |
cp2 = (char *) __stringVal(aStringOrCharacter); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3352 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3353 |
if (newString != nil) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3354 |
REGISTER unsigned char *dstp; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3355 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3356 |
__InstPtr(newString)->o_class = String; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3357 |
__qSTORE(newString, String); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3358 |
dstp = __stringVal(newString); |
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
3359 |
|
20107 | 3360 |
# if defined(bcopy4) |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3361 |
/* knowing that allocation is 4-byte aligned and |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3362 |
* size rounded up to next 4-byte, the first copy |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3363 |
* can be done word-wise. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3364 |
* that speeds up size-10-string , size-10-string |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3365 |
* by 10% on a P5/200. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3366 |
*/ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3367 |
{ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3368 |
int nw = l1 >> 2; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3369 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3370 |
if (l1 & 3) nw++; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3371 |
bcopy4(cp1, dstp, nw); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3372 |
dstp += l1; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3373 |
} |
20107 | 3374 |
# elif defined(FAST_MEMCPY) |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3375 |
memcpy(dstp, cp1, l1); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3376 |
dstp += l1; |
20107 | 3377 |
# else |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3378 |
while (l1 >= 4) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3379 |
*(int *)dstp = *(int *)cp1; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3380 |
dstp += 4; cp1 += 4; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3381 |
l1 -= 4; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3382 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3383 |
while (l1--) *dstp++ = *cp1++; |
3673 | 3384 |
# endif |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3385 |
|
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3386 |
# ifdef bcopy4 |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3387 |
if (((INT)dstp & 3) == 0) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3388 |
int nw = l2 >> 2; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3389 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3390 |
if (l2 & 3) nw++; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3391 |
bcopy4(cp2, dstp, nw); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3392 |
*(dstp + l2) = '\0'; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3393 |
RETURN ( newString ); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3394 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3395 |
# endif |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3396 |
|
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3397 |
# ifdef FAST_MEMCPY |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3398 |
memcpy(dstp, cp2, l2+1); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3399 |
dstp[l2] = '\0'; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3400 |
# else |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3401 |
while (l2--) *dstp++ = *cp2++; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3402 |
*dstp = '\0'; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3403 |
# endif |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3404 |
RETURN ( newString ); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3405 |
} |
1 | 3406 |
} |
20070 | 3407 |
out:; |
18286 | 3408 |
#endif /* not SCHTEAM */ |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
3409 |
%}. |
20070 | 3410 |
^ super , aStringOrCharacter |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
3411 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
3412 |
" |
20070 | 3413 |
'hello' , ' world' asImmutableString |
3414 |
'hello ' , #world |
|
3415 |
'hello ' , $w |
|
8898 | 3416 |
#[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
|
3417 |
" |
14074 | 3418 |
|
3419 |
"Modified: / 01-04-2012 / 13:19:44 / cg" |
|
1 | 3420 |
! |
3421 |
||
3422 |
concatenate:string1 and:string2 |
|
3423 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
3424 |
This is equivalent to self , string1 , string2 |
|
3425 |
- generated by compiler when such a construct is detected" |
|
3426 |
||
3427 |
|newString| |
|
2862 | 3428 |
|
1 | 3429 |
%{ |
95 | 3430 |
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
|
3431 |
#if !defined(FAST_MEMCPY) |
1 | 3432 |
REGISTER unsigned char *srcp; |
3433 |
#endif |
|
3434 |
REGISTER unsigned char *dstp; |
|
3435 |
||
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3436 |
if (__qIsStringLike(self) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3437 |
&& __isStringLike(string1) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3438 |
&& __isStringLike(string2)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3439 |
len1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3440 |
len2 = __stringSize(string1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3441 |
len3 = __stringSize(string2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3442 |
sz = OHDR_SIZE + len1 + len2 + len3 + 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3443 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3444 |
if (newString != nil) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3445 |
__InstPtr(newString)->o_class = String; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3446 |
__qSTORE(newString, String); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3447 |
dstp = __stringVal(newString); |
1 | 3448 |
#ifdef FAST_MEMCPY |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3449 |
memcpy(dstp, __stringVal(self), len1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3450 |
memcpy(dstp + len1, __stringVal(string1), len2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3451 |
memcpy(dstp + len1 + len2, __stringVal(string2), len3+1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3452 |
*(dstp + len1 + len2 + len3) = '\0'; |
1 | 3453 |
#else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3454 |
srcp = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3455 |
while (len1--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3456 |
srcp = __stringVal(string1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3457 |
while (len2--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3458 |
srcp = __stringVal(string2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3459 |
while (len3--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3460 |
*dstp = '\0'; |
1 | 3461 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3462 |
RETURN ( newString ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3463 |
} |
1 | 3464 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
3465 |
%}. |
1 | 3466 |
^ super , string1 , string2 |
3467 |
! |
|
3468 |
||
3469 |
concatenate:string1 and:string2 and:string3 |
|
3470 |
"return the concatenation of myself and the string arguments. |
|
3471 |
This is equivalent to self , string1 , string2 , string3 |
|
3472 |
- generated by compiler when such a construct is detected" |
|
3473 |
||
3474 |
|newString| |
|
2862 | 3475 |
|
1 | 3476 |
%{ |
95 | 3477 |
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
|
3478 |
#if !defined(FAST_MEMCPY) |
1 | 3479 |
REGISTER unsigned char *srcp; |
3480 |
#endif |
|
3481 |
REGISTER unsigned char *dstp; |
|
3482 |
||
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3483 |
if (__qIsStringLike(self) |
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
3484 |
&& __isStringLike(string1) |
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
3485 |
&& __isStringLike(string2) |
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
3486 |
&& __isStringLike(string3)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3487 |
len1 = __stringSize(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3488 |
len2 = __stringSize(string1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3489 |
len3 = __stringSize(string2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3490 |
len4 = __stringSize(string3); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3491 |
sz = OHDR_SIZE + len1 + len2 + len3 + len4 + 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3492 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3493 |
if (newString != nil) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3494 |
__InstPtr(newString)->o_class = String; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3495 |
__qSTORE(newString, String); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3496 |
dstp = __stringVal(newString); |
1 | 3497 |
#ifdef FAST_MEMCPY |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3498 |
memcpy(dstp, __stringVal(self), len1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3499 |
memcpy(dstp + len1, __stringVal(string1), len2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3500 |
memcpy(dstp + len1 + len2, __stringVal(string2), len3); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3501 |
memcpy(dstp + len1 + len2 + len3, __stringVal(string3), len4+1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3502 |
*(dstp + len1 + len2 + len3 + len4) = '\0'; |
1 | 3503 |
#else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3504 |
srcp = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3505 |
while (len1--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3506 |
srcp = __stringVal(string1); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3507 |
while (len2--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3508 |
srcp = __stringVal(string2); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3509 |
while (len3--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3510 |
srcp = __stringVal(string3); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3511 |
while (len4--) *dstp++ = *srcp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3512 |
*dstp = '\0'; |
1 | 3513 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3514 |
RETURN ( newString ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3515 |
} |
1 | 3516 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
3517 |
%}. |
1 | 3518 |
^ super , string1 , string2 , string3 |
3519 |
! |
|
3520 |
||
4745 | 3521 |
copy |
3522 |
"return a copy of the receiver" |
|
3523 |
||
16543 | 3524 |
(self class == String) ifTrue:[ |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3525 |
^ self copyFrom:1 |
4745 | 3526 |
]. |
3527 |
^ super copy |
|
3528 |
! |
|
3529 |
||
608 | 3530 |
copyFrom:start |
19748 | 3531 |
"return a new collection consisting of receiver's elements from startIndex to the end of the collection. |
8898 | 3532 |
This method will always return a string, even if the receiver |
608 | 3533 |
is a subclass-instance. This might change if there is a need. |
3534 |
- reimplemented here for speed" |
|
1 | 3535 |
|
13 | 3536 |
%{ /* NOCONTEXT */ |
1 | 3537 |
|
608 | 3538 |
REGISTER unsigned char *srcp; |
1 | 3539 |
REGISTER unsigned char *dstp; |
608 | 3540 |
REGISTER int count; |
3541 |
int len, index1, sz; |
|
3542 |
OBJ newString; |
|
2862 | 3543 |
|
2894 | 3544 |
#ifndef NO_PRIM_STRING |
20033 | 3545 |
if (__isSmallInteger(start) && __qIsStringLike(self)) { |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3546 |
len = __stringSize(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3547 |
index1 = __intVal(start); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3548 |
if (index1 > 0) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3549 |
if (index1 <= len) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3550 |
count = len - index1 + 1; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3551 |
sz = OHDR_SIZE + count + 1; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3552 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3553 |
__PROTECT_CONTEXT__ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3554 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3555 |
__UNPROTECT_CONTEXT__ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3556 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3557 |
if (newString != nil) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3558 |
__InstPtr(newString)->o_class = String; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3559 |
__qSTORE(newString, String); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3560 |
dstp = __stringVal(newString); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3561 |
srcp = __stringVal(self) + index1 - 1; |
1 | 3562 |
#ifdef FAST_MEMCPY |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3563 |
memcpy(dstp, srcp, count); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3564 |
dstp[count] = '\0'; |
1 | 3565 |
#else |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3566 |
while (count--) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3567 |
*dstp++ = *srcp++; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3568 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3569 |
*dstp = '\0'; |
1 | 3570 |
#endif |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3571 |
RETURN ( newString ); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3572 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3573 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3574 |
} |
13 | 3575 |
} |
2894 | 3576 |
#endif |
51 | 3577 |
%}. |
608 | 3578 |
"fall back in case of non-integer index or out-of-bound index; |
3579 |
will eventually lead to an out-of-bound signal raise" |
|
51 | 3580 |
|
608 | 3581 |
^ super copyFrom:start |
20033 | 3582 |
|
3583 |
" |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3584 |
'12345' copyFrom:3 |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3585 |
'12345678' copyFrom:9 -> empty string |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3586 |
'12345678' copyFrom:0 -> error |
20033 | 3587 |
" |
1 | 3588 |
! |
3589 |
||
3590 |
copyFrom:start to:stop |
|
3591 |
"return the substring starting at index start, anInteger and ending |
|
53 | 3592 |
at stop, anInteger. This method will always return a string, even |
3593 |
if the receiver is a subclass-instance. This might change if there is a need. |
|
1 | 3594 |
- reimplemented here for speed" |
3595 |
||
13 | 3596 |
%{ /* NOCONTEXT */ |
3597 |
||
1 | 3598 |
REGISTER unsigned char *srcp; |
3599 |
REGISTER unsigned char *dstp; |
|
3600 |
REGISTER int count; |
|
95 | 3601 |
int len, sz, index1, index2; |
13 | 3602 |
OBJ newString; |
2862 | 3603 |
|
2894 | 3604 |
#ifndef NO_PRIM_STRING |
20033 | 3605 |
if (__bothSmallInteger(start, stop) && __qIsStringLike(self)) { |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3606 |
len = __stringSize(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3607 |
index1 = __intVal(start); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3608 |
index2 = __intVal(stop); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3609 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3610 |
if ((index1 <= index2) && (index1 > 0)) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3611 |
if (index2 <= len) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3612 |
count = index2 - index1 + 1; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3613 |
sz = OHDR_SIZE + count + 1; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3614 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3615 |
__PROTECT_CONTEXT__ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3616 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3617 |
__UNPROTECT_CONTEXT__ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3618 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3619 |
if (newString != nil) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3620 |
__InstPtr(newString)->o_class = String; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3621 |
__qSTORE(newString, String); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3622 |
dstp = __stringVal(newString); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3623 |
srcp = __stringVal(self) + index1 - 1; |
2894 | 3624 |
#ifdef bcopy4 |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3625 |
{ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3626 |
int nw = count >> 2; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3627 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3628 |
if (count & 3) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3629 |
nw++; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3630 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3631 |
bcopy4(srcp, dstp, nw); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3632 |
dstp[count] = '\0'; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3633 |
} |
1 | 3634 |
#else |
2894 | 3635 |
# ifdef FAST_MEMCPY |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3636 |
memcpy(dstp, srcp, count); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3637 |
dstp[count] = '\0'; |
209 | 3638 |
# else |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3639 |
while (count--) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3640 |
*dstp++ = *srcp++; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3641 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3642 |
*dstp = '\0'; |
209 | 3643 |
# endif |
13 | 3644 |
#endif |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3645 |
RETURN ( newString ); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3646 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3647 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3648 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3649 |
/* |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3650 |
* allow empty copy |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3651 |
*/ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3652 |
if (index1 > index2) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3653 |
__PROTECT_CONTEXT__ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3654 |
__qNew(newString, OHDR_SIZE+1); /* OBJECT ALLOCATION */ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3655 |
__UNPROTECT_CONTEXT__ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3656 |
if (newString != nil) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3657 |
__InstPtr(newString)->o_class = String; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3658 |
(__stringVal(newString))[0] = '\0'; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3659 |
RETURN ( newString ); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3660 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3661 |
} |
1 | 3662 |
} |
2894 | 3663 |
#endif |
51 | 3664 |
%}. |
3665 |
"fall back in case of non-integer index or out-of-bound index; |
|
3666 |
will eventually lead to an out-of-bound signal raise" |
|
3667 |
||
1 | 3668 |
^ super copyFrom:start to:stop |
20033 | 3669 |
|
3670 |
" |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3671 |
'12345678' copyFrom:3 to:7 |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3672 |
'12345678' copyFrom:3 to:3 |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3673 |
'12345678' copyFrom:3 to:2 -> empty string |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3674 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3675 |
'12345678' copyFrom:9 to:9 -> error |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3676 |
'12345678' copyFrom:3 to:9 -> error |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3677 |
'12345678' copyFrom:0 to:8 -> error |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3678 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3679 |
(Unicode16String with:(Character value:16r220) with:$a with:$b with:(Character value:16r221) with:(Character value:16r222)) |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3680 |
copyFrom:2 to:3 |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3681 |
((Unicode16String with:(Character value:16r220) with:$a with:$b with:(Character value:16r221) with:(Character value:16r222)) |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3682 |
copyFrom:2 to:3) asSingleByteString |
20033 | 3683 |
" |
1 | 3684 |
! |
3685 |
||
608 | 3686 |
copyWith:aCharacter |
19748 | 3687 |
"return a new string containing the receiver's characters |
8898 | 3688 |
and the single new character, aCharacter. |
608 | 3689 |
This is different from concatentation, which expects another string |
3690 |
as argument, but equivalent to copy-and-addLast. |
|
3691 |
Reimplemented here for more speed" |
|
3692 |
||
3693 |
%{ /* NOCONTEXT */ |
|
3694 |
||
2887 | 3695 |
int count; |
608 | 3696 |
int sz; |
3697 |
REGISTER unsigned char *dstp; |
|
3698 |
OBJ cls, newString; |
|
2862 | 3699 |
|
2894 | 3700 |
#ifndef NO_PRIM_STRING |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3701 |
if (__isCharacter(aCharacter)) { |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3702 |
unsigned int cVal = __intVal(__characterVal(aCharacter)); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3703 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3704 |
if ((cVal <= 0xFF) && __qIsStringLike(self)) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3705 |
count = __stringSize(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3706 |
sz = OHDR_SIZE + count + 1 + 1; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3707 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3708 |
__PROTECT_CONTEXT__ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3709 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3710 |
__UNPROTECT_CONTEXT__ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3711 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3712 |
if (newString) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3713 |
__InstPtr(newString)->o_class = String; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3714 |
__qSTORE(newString, String); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3715 |
dstp = __stringVal(newString); |
2862 | 3716 |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3717 |
# ifdef bcopy4 |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3718 |
{ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3719 |
int nw = count >> 2; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3720 |
char *srcp = (char *)__stringVal(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3721 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3722 |
if (count & 3) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3723 |
nw++; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3724 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3725 |
bcopy4(srcp, dstp, nw); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3726 |
dstp += count; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3727 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3728 |
# else |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3729 |
# ifdef FAST_MEMCPY |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3730 |
memcpy(dstp, __stringVal(self), count); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3731 |
dstp += count; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3732 |
# else |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3733 |
{ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3734 |
REGISTER unsigned char *srcp; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3735 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3736 |
srcp = __stringVal(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3737 |
while ((*dstp = *srcp++) != '\0') |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3738 |
dstp++; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3739 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3740 |
# endif |
2887 | 3741 |
# endif |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3742 |
*dstp++ = cVal; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3743 |
*dstp = '\0'; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3744 |
RETURN (newString ); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3745 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
3746 |
} |
608 | 3747 |
} |
2894 | 3748 |
#endif |
608 | 3749 |
%}. |
20594 | 3750 |
"fall back in case of non-character arg or non-single-byte character. |
3751 |
will lead to an bad element signal raise or a UnicodeString to be returned" |
|
608 | 3752 |
|
3753 |
^ super copyWith:aCharacter |
|
20594 | 3754 |
|
3755 |
" |
|
3756 |
'1234567' copyWith:$8 |
|
3757 |
'1234567' copyWith:(Character value:16r220) |
|
3758 |
" |
|
608 | 3759 |
! |
3760 |
||
2886 | 3761 |
deepCopy |
3762 |
"return a copy of the receiver" |
|
608 | 3763 |
|
3764 |
" |
|
3765 |
could be an instance of a subclass which needs deepCopy |
|
3766 |
of its named instvars ... |
|
3767 |
" |
|
16543 | 3768 |
(self class == String) ifTrue:[ |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3769 |
^ self copyFrom:1 |
608 | 3770 |
]. |
3771 |
^ super deepCopy |
|
3772 |
! |
|
3773 |
||
10951 | 3774 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
8383 | 3775 |
"return a deep copy of the receiver - reimplemented to be a bit faster" |
608 | 3776 |
|
3777 |
" |
|
3778 |
could be an instance of a subclass which needs deepCopy |
|
3779 |
of its named instvars ... |
|
3780 |
" |
|
16543 | 3781 |
(self class == String) ifTrue:[ |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3782 |
^ self copyFrom:1 |
608 | 3783 |
]. |
10951 | 3784 |
^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector |
608 | 3785 |
! |
3786 |
||
2886 | 3787 |
shallowCopy |
3788 |
"return a copy of the receiver" |
|
608 | 3789 |
|
16543 | 3790 |
(self class == String) ifTrue:[ |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3791 |
^ self copyFrom:1 |
608 | 3792 |
]. |
3793 |
^ super shallowCopy |
|
3794 |
! |
|
3795 |
||
2886 | 3796 |
simpleDeepCopy |
3797 |
"return a copy of the receiver" |
|
608 | 3798 |
|
3799 |
" |
|
3800 |
could be an instance of a subclass which needs deepCopy |
|
3801 |
of its named instvars ... |
|
3802 |
" |
|
16543 | 3803 |
(self class == String) ifTrue:[ |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3804 |
^ self copyFrom:1 |
608 | 3805 |
]. |
7881 | 3806 |
^ super simpleDeepCopy |
608 | 3807 |
! ! |
3808 |
||
14384
1082868a753c
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14353
diff
changeset
|
3809 |
|
4154 | 3810 |
!String methodsFor:'filling & replacing'! |
608 | 3811 |
|
2886 | 3812 |
atAllPut:aCharacter |
608 | 3813 |
"replace all elements with aCharacter |
1 | 3814 |
- reimplemented here for speed" |
3815 |
||
13 | 3816 |
%{ /* NOCONTEXT */ |
3817 |
||
608 | 3818 |
#ifndef FAST_MEMSET |
3819 |
REGISTER unsigned char *dst; |
|
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
3820 |
#endif |
608 | 3821 |
REGISTER int l; |
3822 |
REGISTER int byteValue; |
|
1 | 3823 |
|
608 | 3824 |
if (__isCharacter(aCharacter) && __isString(self)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3825 |
byteValue = __intVal(__characterVal(aCharacter)); |
9473 | 3826 |
if ((unsigned)byteValue <= 0xFF) { |
3827 |
l = __stringSize(self); |
|
8898 | 3828 |
|
3829 |
#ifdef FAST_MEMSET |
|
9473 | 3830 |
if (l > 0) { |
3831 |
memset(__stringVal(self), byteValue, l); |
|
3832 |
} |
|
608 | 3833 |
#else |
9473 | 3834 |
{ |
3835 |
INT v; |
|
3836 |
||
3837 |
v = (byteValue << 8) | byteValue; |
|
3838 |
v = (v << 16) | v; |
|
3839 |
||
3840 |
dst = __stringVal(self); |
|
3712 | 3841 |
|
3842 |
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */ |
|
9473 | 3843 |
if (l > 0) { |
3844 |
memset4(dst, v, l>>2); |
|
3845 |
l = l & 3; |
|
3846 |
} |
|
3712 | 3847 |
# else |
3848 |
# ifdef UINT64 |
|
9473 | 3849 |
{ |
3850 |
UINT64 v64; |
|
3851 |
||
3852 |
v64 = v; |
|
3853 |
v64 = (v64 << 32) | v; |
|
3854 |
while (l >= 8) { |
|
3855 |
((UINT64 *)dst)[0] = v64; |
|
3856 |
dst += 8; |
|
3857 |
l -= 8; |
|
3858 |
} |
|
3859 |
} |
|
3712 | 3860 |
# else /* no UINT64 */ |
9473 | 3861 |
while (l >= 16) { |
3862 |
((int *)dst)[0] = v; |
|
3863 |
((int *)dst)[1] = v; |
|
3864 |
((int *)dst)[2] = v; |
|
3865 |
((int *)dst)[3] = v; |
|
3866 |
dst += 16; |
|
3867 |
l -= 16; |
|
3868 |
} |
|
3869 |
if (l >= 8) { |
|
3870 |
((int *)dst)[0] = v; |
|
3871 |
((int *)dst)[1] = v; |
|
3872 |
dst += 8; |
|
3873 |
l -= 8; |
|
3874 |
} |
|
3875 |
if (l >= 4) { |
|
3876 |
((int *)dst)[0] = v; |
|
3877 |
dst += 4; |
|
3878 |
l -= 4; |
|
3879 |
} |
|
3712 | 3880 |
# if 0 |
9473 | 3881 |
if (l >= 2) { |
3882 |
((short *)dst)[0] = v; |
|
3883 |
dst += 2; |
|
3884 |
l -= 2; |
|
3885 |
} |
|
3712 | 3886 |
# endif |
3887 |
||
5648 | 3888 |
# endif /* UINT64 */ |
3889 |
# endif /* FAST_MEMSET4 */ |
|
9473 | 3890 |
} |
3891 |
||
3892 |
/* |
|
3893 |
* remaining bytes |
|
3894 |
*/ |
|
3895 |
while (l-- > 0) |
|
3896 |
*dst++ = byteValue; |
|
3712 | 3897 |
|
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
3898 |
#endif /* no FAST_MEMSET */ |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
3899 |
|
9473 | 3900 |
RETURN ( self ); |
3901 |
} |
|
608 | 3902 |
} |
2862 | 3903 |
%}. |
608 | 3904 |
^ super atAllPut:aCharacter |
1 | 3905 |
|
608 | 3906 |
" |
8898 | 3907 |
(String new:10) atAllPut:$* |
3908 |
String new:10 withAll:$* |
|
608 | 3909 |
" |
3910 |
! |
|
3911 |
||
23975 | 3912 |
from:start to:stop put:aCharacter |
3913 |
"fill part of the receiver with aCharacter. |
|
3914 |
- reimplemented here for speed" |
|
3915 |
||
3916 |
%{ /* NOCONTEXT */ |
|
3917 |
||
3918 |
REGISTER unsigned char *dstp; |
|
3919 |
REGISTER int count, byteValue; |
|
3920 |
int len, index1, index2; |
|
3921 |
OBJ cls; |
|
3922 |
||
3923 |
// fprintf(stderr, "fill...\n"); |
|
3924 |
if (__isCharacter(aCharacter) |
|
3925 |
&& __bothSmallInteger(start, stop)) { |
|
3926 |
len = __stringSize(self); |
|
3927 |
index1 = __intVal(start); |
|
3928 |
index2 = __intVal(stop); |
|
3929 |
||
3930 |
dstp = __stringVal(self) + index1 - 1; |
|
3931 |
if ((cls = __qClass(self)) != @global(String)) { |
|
3932 |
int nInst; |
|
3933 |
||
3934 |
nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
3935 |
dstp += nInst; |
|
3936 |
len -= nInst; |
|
3937 |
} |
|
3938 |
||
3939 |
byteValue = __intVal(__characterVal(aCharacter)); |
|
3940 |
if (((unsigned)byteValue <= 0xFF) |
|
3941 |
&& (index1 <= index2) |
|
3942 |
&& (index1 > 0)) { |
|
3943 |
if (index2 <= len) { |
|
3944 |
count = index2 - index1 + 1; |
|
3945 |
||
3946 |
#ifdef memset4 |
|
3947 |
if (count > 20) { |
|
3948 |
/* fill unaligned part */ |
|
3949 |
while (((unsigned INT)dstp & 3) != 0) { |
|
3950 |
*dstp++ = byteValue; |
|
3951 |
count--; |
|
3952 |
} |
|
3953 |
/* fill aligned part */ |
|
3954 |
{ |
|
3955 |
int n4 = count & ~3; |
|
3956 |
int v4, nW; |
|
3957 |
||
3958 |
v4 = (byteValue << 8) | byteValue; |
|
3959 |
v4 = (v4 << 16) | v4; |
|
3960 |
nW = n4>>2; |
|
3961 |
memset4(dstp, v4, nW); |
|
3962 |
count -= n4; |
|
3963 |
dstp += n4; |
|
3964 |
} |
|
3965 |
while (count--) { |
|
3966 |
*dstp++ = byteValue; |
|
3967 |
} |
|
3968 |
RETURN (self); |
|
3969 |
} |
|
3970 |
#endif /* memset4 */ |
|
3971 |
||
3972 |
#if (__POINTER_SIZE__ == 8) |
|
3973 |
{ |
|
3974 |
INT v8; |
|
3975 |
||
3976 |
v8 = (byteValue << 8) | byteValue; |
|
3977 |
v8 = (v8 << 16) | v8; |
|
3978 |
v8 = (v8 << 32) | v8; |
|
3979 |
||
3980 |
/* fill unaligned part */ |
|
3981 |
while ((count > 0) && (((unsigned INT)dstp & 3) != 0)) { |
|
3982 |
*dstp++ = byteValue; |
|
3983 |
count--; |
|
3984 |
} |
|
3985 |
||
3986 |
if ((count >= 4) && (((unsigned INT)dstp & 7) != 0)) { |
|
3987 |
((unsigned int *)dstp)[0] = v8; |
|
3988 |
dstp += 4; |
|
3989 |
count -= 4; |
|
3990 |
} |
|
3991 |
||
3992 |
/* fill aligned part */ |
|
3993 |
while (count >= 8) { |
|
3994 |
((unsigned INT *)dstp)[0] = v8; |
|
3995 |
dstp += 8; |
|
3996 |
count -= 8; |
|
3997 |
} |
|
3998 |
||
3999 |
/* fill rest */ |
|
4000 |
if (count >= 4) { |
|
4001 |
((unsigned int *)dstp)[0] = v8; |
|
4002 |
dstp += 4; |
|
4003 |
count -= 4; |
|
4004 |
} |
|
4005 |
if (count >= 2) { |
|
4006 |
((unsigned short *)dstp)[0] = v8; |
|
4007 |
dstp += 2; |
|
4008 |
count -= 2; |
|
4009 |
} |
|
4010 |
if (count) { |
|
4011 |
*dstp = byteValue; |
|
4012 |
} |
|
4013 |
RETURN (self); |
|
4014 |
} |
|
4015 |
#endif /* 64bit */ |
|
4016 |
||
4017 |
#ifdef FAST_MEMSET |
|
4018 |
memset(dstp, byteValue, count); |
|
4019 |
#else |
|
4020 |
# ifdef __UNROLL_LOOPS__ |
|
4021 |
while (count >= 8) { |
|
4022 |
dstp[0] = dstp[1] = dstp[2] = dstp[3] = |
|
4023 |
dstp[4] = dstp[5] = dstp[6] = dstp[7] = byteValue; |
|
4024 |
dstp += 8; |
|
4025 |
count -= 8; |
|
4026 |
} |
|
4027 |
# endif /* __UNROLL_LOOPS__ */ |
|
4028 |
while (count--) { |
|
4029 |
*dstp++ = byteValue; |
|
4030 |
} |
|
4031 |
#endif |
|
4032 |
RETURN (self); |
|
4033 |
} |
|
4034 |
} |
|
4035 |
} |
|
4036 |
%}. |
|
4037 |
" |
|
4038 |
fall back in case of non-integer index or out-of-bound index/value; |
|
4039 |
will eventually lead to an out-of-bound signal raise |
|
4040 |
" |
|
4041 |
^ super from:start to:stop put:aCharacter |
|
4042 |
||
4043 |
" |
|
4044 |
(String new:10) from:1 to:10 put:$a |
|
4045 |
(String new:20) from:10 to:20 put:$b |
|
4046 |
(String new:20) from:1 to:10 put:$c |
|
4047 |
(String new:20) from:1 to:10 put:$c |
|
4048 |
(String new:100) from:2 to:99 put:$c |
|
4049 |
" |
|
4050 |
||
4051 |
"Created: / 26-03-2019 / 11:11:56 / Claus Gittinger" |
|
4052 |
! |
|
4053 |
||
2929 | 4054 |
replaceAll:oldCharacter with:newCharacter |
4120 | 4055 |
"replace all oldCharacters by newCharacter in the receiver. |
4056 |
||
4057 |
Notice: This operation modifies the receiver, NOT a copy; |
|
4058 |
therefore the change may affect all others referencing the receiver." |
|
608 | 4059 |
|
4060 |
%{ /* NOCONTEXT */ |
|
4061 |
||
4062 |
REGISTER unsigned char *srcp; |
|
4063 |
REGISTER unsigned oldVal, newVal; |
|
4120 | 4064 |
unsigned char c, cNext; |
608 | 4065 |
|
4066 |
if (__isCharacter(oldCharacter) |
|
4067 |
&& __isCharacter(newCharacter) |
|
4068 |
&& __isString(self)) { |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4069 |
srcp = (unsigned char *)__stringVal(self); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4070 |
oldVal = __intVal(__characterVal(oldCharacter)); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4071 |
newVal = __intVal(__characterVal(newCharacter)); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4072 |
if ((oldVal <= 0xFF) |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4073 |
&& (newVal <= 0xFF)) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4074 |
cNext = *srcp; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4075 |
while ((c = cNext) != '\0') { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4076 |
cNext = srcp[1]; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4077 |
if (c == oldVal) |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4078 |
*srcp = newVal; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4079 |
srcp++; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4080 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4081 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4082 |
RETURN ( self ); |
1 | 4083 |
} |
2862 | 4084 |
%}. |
16203 | 4085 |
newCharacter isCharacter ifFalse:[self halt:'please change the sender']. |
2929 | 4086 |
^ super replaceAll:oldCharacter with:newCharacter |
51 | 4087 |
|
608 | 4088 |
" |
8898 | 4089 |
'helloWorld' copy replaceAll:$o with:$O |
4090 |
'helloWorld' copy replaceAll:$d with:$* |
|
4091 |
'helloWorld' copy replaceAll:$h with:$* |
|
608 | 4092 |
" |
4093 |
! |
|
1 | 4094 |
|
2886 | 4095 |
replaceFrom:start to:stop with:aString startingAt:repStart |
1 | 4096 |
"replace the characters starting at index start, anInteger and ending |
4097 |
at stop, anInteger with characters from aString starting at repStart. |
|
3234 | 4098 |
Return the receiver. |
1 | 4099 |
|
4100 |
- reimplemented here for speed" |
|
4101 |
||
4102 |
%{ /* NOCONTEXT */ |
|
18286 | 4103 |
#ifdef __SCHTEAM__ |
4104 |
if ( aString.isStringLike() |
|
4105 |
&& self.isStringLike() |
|
4106 |
&& start.isSmallInteger() |
|
4107 |
&& stop.isSmallInteger() |
|
4108 |
&& repStart.isSmallInteger()) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4109 |
STString me = self.asSTString(); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4110 |
STString other = aString.asSTString(); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4111 |
int _start = start.intValue() - 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4112 |
int _stop = stop.intValue() - 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4113 |
int _repStart = repStart.intValue() - 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4114 |
int mySize = me.characters.length; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4115 |
int otherSize = other.characters.length; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4116 |
int count = _stop - _start + 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4117 |
|
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4118 |
if (_start >= 0 |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4119 |
&& _repStart >= 0 |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4120 |
&& _stop < mySize |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4121 |
&& (_repStart + count) <= otherSize) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4122 |
if (count > 0) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4123 |
System.arraycopy(other.characters, _repStart, me.characters, _start, count); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4124 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4125 |
return context._RETURN(self); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4126 |
} |
18286 | 4127 |
} |
4128 |
#else |
|
1 | 4129 |
|
4130 |
REGISTER unsigned char *srcp, *dstp; |
|
4131 |
REGISTER int count; |
|
4132 |
int len, index1, index2; |
|
4133 |
int repLen, repIndex; |
|
4134 |
||
18286 | 4135 |
# ifndef NO_PRIM_STRING |
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
4136 |
if (__isStringLike(aString) |
53 | 4137 |
&& __isString(self) |
252 | 4138 |
&& __bothSmallInteger(start, stop)) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4139 |
len = __stringSize(self); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4140 |
index1 = __intVal(start); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4141 |
index2 = __intVal(stop); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4142 |
count = index2 - index1 + 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4143 |
if (count <= 0) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4144 |
RETURN (self); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4145 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4146 |
if ((index2 <= len) && (index1 > 0)) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4147 |
repLen = __stringSize(aString); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4148 |
repIndex = __intVal(repStart); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4149 |
if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4150 |
srcp = __stringVal(aString) + repIndex - 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4151 |
dstp = __stringVal(self) + index1 - 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4152 |
if (aString == self) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4153 |
/* take care of overlapping copy */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4154 |
memmove(dstp, srcp, count); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4155 |
RETURN (self); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4156 |
} |
18286 | 4157 |
# ifdef bcopy4 |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4158 |
/* copy quadbytes if pointers are aligned */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4159 |
/* |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4160 |
* no sizeof(int) here please - |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4161 |
* - bcopy4 (if defined) copies 4-bytes on ALL machines |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4162 |
*/ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4163 |
if ((count > 12) |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4164 |
&& (((unsigned INT)srcp & 3) == 0) |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4165 |
&& (((unsigned INT)dstp & 3) == 0)) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4166 |
int n; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4167 |
|
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4168 |
n = count >> 2; /* make it quads */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4169 |
bcopy4(srcp, dstp, n); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4170 |
n <<= 2; /* back to chars */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4171 |
dstp += n; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4172 |
srcp += n; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4173 |
count -= n; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4174 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4175 |
while (count-- > 0) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4176 |
*dstp++ = *srcp++; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4177 |
} |
18286 | 4178 |
# else |
4179 |
# ifdef FAST_MEMCPY |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4180 |
memcpy(dstp, srcp, count); |
18286 | 4181 |
# else |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4182 |
/* copy longs if pointers are aligned */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4183 |
if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0) |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4184 |
&& (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4185 |
while (count >= sizeof(INT)) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4186 |
*((unsigned INT *)dstp) = *((unsigned INT *)srcp); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4187 |
dstp += sizeof(INT); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4188 |
srcp += sizeof(INT); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4189 |
count -= sizeof(INT); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4190 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4191 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4192 |
while (count-- > 0) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4193 |
*dstp++ = *srcp++; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4194 |
} |
18286 | 4195 |
# endif |
4196 |
# endif |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4197 |
RETURN (self); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4198 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4199 |
} |
1 | 4200 |
} |
18286 | 4201 |
# endif |
4202 |
#endif /* not SCHTEAM */ |
|
2862 | 4203 |
%}. |
1 | 4204 |
^ super replaceFrom:start to:stop with:aString startingAt:repStart |
4205 |
! |
|
4206 |
||
4207 |
withoutSeparators |
|
8898 | 4208 |
"return a string containing the chars of myself |
2862 | 4209 |
without leading and trailing whitespace. |
4210 |
If there is no whitespace, the receiver is returned. |
|
95 | 4211 |
Notice, this is different from String>>withoutSpaces." |
1 | 4212 |
|
42 | 4213 |
|startIndex "{ Class: SmallInteger }" |
8898 | 4214 |
endIndex "{ Class: SmallInteger }" |
51 | 4215 |
sz| |
4216 |
||
53 | 4217 |
startIndex := 0. |
2862 | 4218 |
|
51 | 4219 |
%{ |
2884 | 4220 |
REGISTER unsigned char *cp; |
4221 |
REGISTER unsigned char *ep; |
|
4222 |
REGISTER unsigned char c; |
|
51 | 4223 |
REGISTER unsigned char *cp0; |
2884 | 4224 |
REGISTER unsigned char *ep0; |
1 | 4225 |
|
51 | 4226 |
/* ignore instances of subclasses ... */ |
329 | 4227 |
if (__qClass(self) == String) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4228 |
cp = cp0 = __stringVal(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4229 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4230 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4231 |
* find first non-whiteSpace from beginning |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4232 |
*/ |
19748 | 4233 |
#ifdef UINT64 |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4234 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4235 |
cp += 8; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4236 |
} |
329 | 4237 |
#endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4238 |
while (*((unsigned *)cp) == 0x20202020) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4239 |
cp += 4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4240 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4241 |
while ((c = *cp) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4242 |
&& (c <= ' ') |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4243 |
&& ((c == ' ') || (c == '\n') || (c == '\t') |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4244 |
|| (c == '\r') || (c == '\f')) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4245 |
) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4246 |
cp++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4247 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4248 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4249 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4250 |
* find first non-whiteSpace from end |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4251 |
*/ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4252 |
ep = ep0 = cp0 + __stringSize(self) - 1; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4253 |
while ((ep >= cp) && (*ep == ' ')) ep--; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4254 |
c = *ep; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4255 |
while ((ep >= cp) && |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4256 |
(c <= ' ') && |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4257 |
((c == ' ') || (c == '\n') || (c == '\t') |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4258 |
|| (c == '\r') || (c == '\f'))) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4259 |
ep--; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4260 |
c = *ep; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4261 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4262 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4263 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4264 |
* no whiteSpace ? |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4265 |
*/ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4266 |
if ((cp == cp0) && (ep == ep0)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4267 |
RETURN(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4268 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4269 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4270 |
startIndex = __mkSmallInteger(cp - cp0 + 1); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4271 |
endIndex = __mkSmallInteger(ep - cp0 + 1); |
51 | 4272 |
} |
202 | 4273 |
%}. |
4274 |
startIndex == 0 ifTrue:[^ super withoutSeparators]. |
|
4275 |
||
4276 |
startIndex > endIndex ifTrue:[^ '']. |
|
1 | 4277 |
^ self copyFrom:startIndex to:endIndex |
2884 | 4278 |
|
4279 |
" |
|
8898 | 4280 |
'hello' withoutSeparators |
4281 |
' hello' withoutSeparators |
|
4282 |
' hello ' withoutSeparators |
|
4283 |
' hello ' withoutSeparators |
|
4284 |
' hello ' withoutSeparators |
|
2884 | 4285 |
' hello ' withoutSeparators |
8898 | 4286 |
' ' withoutSeparators |
2884 | 4287 |
" |
608 | 4288 |
! |
4289 |
||
4290 |
withoutSpaces |
|
8898 | 4291 |
"return a string containing the characters of myself |
2862 | 4292 |
without leading and trailing spaces. |
2884 | 4293 |
If there are no spaces, the receiver is returned unchanged. |
608 | 4294 |
Notice, this is different from String>>withoutSeparators." |
4295 |
||
4296 |
|startIndex "{ Class: SmallInteger }" |
|
8898 | 4297 |
endIndex "{ Class: SmallInteger }" |
608 | 4298 |
sz blank| |
4299 |
||
4300 |
startIndex := 0. |
|
4301 |
%{ |
|
4302 |
REGISTER unsigned char *cp; |
|
2884 | 4303 |
REGISTER unsigned char *ep; |
4304 |
unsigned char *cp0; |
|
4305 |
unsigned char *ep0; |
|
608 | 4306 |
|
4307 |
/* ignore instances of subclasses ... */ |
|
4308 |
if (__qClass(self) == String) { |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4309 |
cp = cp0 = __stringVal(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4310 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4311 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4312 |
* find first non-blank from beginning |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4313 |
*/ |
19748 | 4314 |
#ifdef UINT64 |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4315 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4316 |
cp += 8; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4317 |
} |
19748 | 4318 |
#endif /* UINT64 */ |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4319 |
while (*((unsigned *)cp) == 0x20202020) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4320 |
cp += 4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4321 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4322 |
while (*cp == ' ') cp++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4323 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4324 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4325 |
* find first non-blank from end |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4326 |
*/ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4327 |
ep = ep0 = cp0 + __stringSize(self) - 1; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4328 |
while ((ep >= cp) && (*ep == ' ')) ep--; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4329 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4330 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4331 |
* no blanks ? |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4332 |
*/ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4333 |
if ((cp == cp0) && (ep == ep0)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4334 |
RETURN(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4335 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4336 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4337 |
startIndex = __mkSmallInteger(cp - cp0 + 1); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4338 |
endIndex = __mkSmallInteger(ep - cp0 + 1); |
608 | 4339 |
} |
4340 |
%}. |
|
4341 |
startIndex == 0 ifTrue:[^ super withoutSpaces]. |
|
4342 |
||
4343 |
startIndex > endIndex ifTrue:[^ '']. |
|
2886 | 4344 |
((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self]. |
608 | 4345 |
^ self copyFrom:startIndex to:endIndex |
2884 | 4346 |
|
4347 |
" |
|
8898 | 4348 |
' hello' withoutSpaces |
4349 |
' hello ' withoutSpaces |
|
4350 |
' hello ' withoutSpaces |
|
4351 |
' hello ' withoutSpaces |
|
2884 | 4352 |
' hello ' withoutSpaces |
8898 | 4353 |
' ' withoutSpaces |
2884 | 4354 |
" |
608 | 4355 |
! ! |
4356 |
||
4357 |
!String methodsFor:'printing & storing'! |
|
4358 |
||
20844 | 4359 |
_errorPrint |
4360 |
"Do not use this in user code. |
|
4361 |
Print the receiver on standard error. |
|
4362 |
This method does NOT (by purpose) use the stream classes and |
|
4363 |
will therefore work even in case of emergency during early startup |
|
4364 |
or in a crash situation (MiniDebugger)." |
|
4365 |
||
4366 |
%{ /* NOCONTEXT */ |
|
4367 |
#ifdef __SCHTEAM__ |
|
4368 |
if (self.isStringLike()) { |
|
23862 | 4369 |
org.exept.stj.STSystem.err.print(self.asString()); |
4370 |
return context._RETURN(self); |
|
20844 | 4371 |
} |
4372 |
#else |
|
4373 |
if (__qIsStringLike(self)) { |
|
23862 | 4374 |
console_fprintf(stderr, "%s" , __stringVal(self)); |
4375 |
console_fflush(stderr); |
|
4376 |
RETURN (self); |
|
20844 | 4377 |
} |
4378 |
#endif /* not SCHTEAM */ |
|
4379 |
%}. |
|
4380 |
! |
|
4381 |
||
4382 |
_errorPrintCR |
|
4383 |
"Do not use this in user code. |
|
4384 |
Print the receiver on standard error. |
|
4385 |
This method does NOT (by purpose) use the stream classes and |
|
4386 |
will therefore work even in case of emergency during early startup |
|
4387 |
or in a crash situation (MiniDebugger)." |
|
4388 |
||
4389 |
%{ /* NOCONTEXT */ |
|
4390 |
#ifdef __SCHTEAM__ |
|
4391 |
if (self.isStringLike()) { |
|
23862 | 4392 |
org.exept.stj.STSystem.err.println(self.asString()); |
4393 |
return context._RETURN(self); |
|
20844 | 4394 |
} |
4395 |
#else |
|
4396 |
if (__qIsStringLike(self)) { |
|
23862 | 4397 |
console_fprintf(stderr, "%s\n" , __stringVal(self)); |
4398 |
console_fflush(stderr); |
|
4399 |
RETURN (self); |
|
20844 | 4400 |
} |
4401 |
#endif |
|
4402 |
%}. |
|
4403 |
! |
|
4404 |
||
4405 |
_print |
|
4406 |
"Do not use this in user code. |
|
4407 |
Print the receiver on standard output. |
|
4408 |
This method does NOT (by purpose) use the stream classes and |
|
4409 |
will therefore work even in case of emergency during early startup |
|
4410 |
or in a crash situation (MiniDebugger)." |
|
4411 |
||
4412 |
%{ /* NOCONTEXT */ |
|
4413 |
#ifdef __SCHTEAM__ |
|
4414 |
org.exept.stj.STSystem.out.print(self.toString()); |
|
4415 |
return context._RETURN(self); |
|
4416 |
#else |
|
4417 |
if (__qIsStringLike(self)) { |
|
23862 | 4418 |
console_fprintf(stdout, "%s" , __stringVal(self)); |
4419 |
console_fflush(stdout); |
|
4420 |
RETURN (self); |
|
20844 | 4421 |
} |
4422 |
#endif |
|
4423 |
%}. |
|
4424 |
! |
|
4425 |
||
4426 |
_printCR |
|
4427 |
"Do not use this in user code. |
|
4428 |
Print the receiver on standard output. |
|
4429 |
This method does NOT (by purpose) use the stream classes and |
|
4430 |
will therefore work even in case of emergency during early startup |
|
4431 |
or in a crash situation (MiniDebugger)." |
|
4432 |
||
4433 |
%{ /* NOCONTEXT */ |
|
4434 |
#ifdef __SCHTEAM__ |
|
4435 |
org.exept.stj.STSystem.out.println(self.toString()); |
|
4436 |
return context._RETURN(self); |
|
4437 |
#else |
|
4438 |
if (__qIsStringLike(self)) { |
|
23862 | 4439 |
console_fprintf(stdout, "%s\n" , __stringVal(self)); |
4440 |
console_fflush(stdout); |
|
4441 |
RETURN (self); |
|
20844 | 4442 |
} |
4443 |
#endif |
|
4444 |
%}. |
|
4445 |
! |
|
4446 |
||
16393 | 4447 |
displayString |
4448 |
"return a string used when displaying the receiver in a view." |
|
4449 |
||
18215 | 4450 |
^ super displayString. |
17539 | 4451 |
"/ ^ self storeString. |
4452 |
||
4453 |
" |
|
4454 |
'hello' -> 'hello' |
|
4455 |
" |
|
16393 | 4456 |
! |
4457 |
||
20879 | 4458 |
errorPrint |
4459 |
"print the receiver on standard error, if the global Stderr is nil; |
|
4460 |
otherwise, fall back to the inherited errorPrint, which sends the string to |
|
4461 |
the Stderr stream or to a logger. |
|
23862 | 4462 |
Redefined to be able to print during early startup, |
20879 | 4463 |
when the stream classes have not yet been initialized (i.e. Stderr is nil)." |
4464 |
||
4465 |
Stderr isNil ifTrue:[ |
|
23862 | 4466 |
self _errorPrint |
20879 | 4467 |
] ifFalse:[ |
23862 | 4468 |
super errorPrint |
20879 | 4469 |
]. |
4470 |
||
4471 |
" |
|
4472 |
'hello world' asUnicode16String errorPrint |
|
4473 |
(Character value:356) asString errorPrint |
|
4474 |
'Bönnigheim' errorPrint |
|
4475 |
'Bönnigheim' asUnicodeString errorPrint |
|
4476 |
" |
|
4477 |
! |
|
4478 |
||
4479 |
errorPrintCR |
|
4480 |
"print the receiver on standard error, followed by a cr, |
|
4481 |
if the global Stderr is nil; otherwise, fall back to the inherited errorPrintCR, |
|
4482 |
which sends the string to the Stderr stream or to a logger. |
|
23862 | 4483 |
Redefined to be able to print during early startup, |
20879 | 4484 |
when the stream classes have not yet been initialized (i.e. Stderr is nil)." |
4485 |
||
4486 |
Stderr isNil ifTrue:[ |
|
23862 | 4487 |
self _errorPrintCR |
20879 | 4488 |
] ifFalse:[ |
23862 | 4489 |
super errorPrintCR |
20879 | 4490 |
]. |
4491 |
! |
|
4492 |
||
20494 | 4493 |
lowLevelErrorPrint |
20838 | 4494 |
"Do not use this in user code. |
4495 |
Print the receiver on standard error. |
|
14163 | 4496 |
This method does NOT (by purpose) use the stream classes and |
15536 | 4497 |
will therefore work even in case of emergency during early startup |
20838 | 4498 |
or in a crash situation (MiniDebugger)." |
14163 | 4499 |
|
4500 |
%{ /* NOCONTEXT */ |
|
18286 | 4501 |
#ifdef __SCHTEAM__ |
20494 | 4502 |
if (self.isStringLike()) { |
23862 | 4503 |
org.exept.stj.STSystem.err.print(self.asString()); |
4504 |
return context._RETURN(self); |
|
18286 | 4505 |
} |
4506 |
#else |
|
20494 | 4507 |
if (__qIsStringLike(self)) { |
23862 | 4508 |
console_fprintf(stderr, "%s" , __stringVal(self)); |
4509 |
console_fflush(stderr); |
|
4510 |
RETURN (self); |
|
20494 | 4511 |
} |
4512 |
#endif /* not SCHTEAM */ |
|
4513 |
%}. |
|
4514 |
||
4515 |
" |
|
4516 |
'hello world' asUnicode16String errorPrint |
|
4517 |
(Character value:356) asString errorPrint |
|
4518 |
'Bönnigheim' errorPrint |
|
4519 |
'Bönnigheim' asUnicodeString errorPrint |
|
4520 |
" |
|
4521 |
! |
|
4522 |
||
4523 |
lowLevelErrorPrintCR |
|
20838 | 4524 |
"Do not use this in user code. |
4525 |
Print the receiver on standard error. |
|
20494 | 4526 |
This method does NOT (by purpose) use the stream classes and |
4527 |
will therefore work even in case of emergency during early startup |
|
20838 | 4528 |
or in a crash situation (MiniDebugger)." |
20494 | 4529 |
|
4530 |
%{ /* NOCONTEXT */ |
|
4531 |
#ifdef __SCHTEAM__ |
|
4532 |
if (self.isStringLike()) { |
|
23862 | 4533 |
org.exept.stj.STSystem.err.println(self.asString()); |
4534 |
return context._RETURN(self); |
|
20494 | 4535 |
} |
4536 |
#else |
|
4537 |
if (__qIsStringLike(self)) { |
|
23862 | 4538 |
console_fprintf(stderr, "%s\n" , __stringVal(self)); |
4539 |
console_fflush(stderr); |
|
4540 |
RETURN (self); |
|
14163 | 4541 |
} |
18286 | 4542 |
#endif |
14163 | 4543 |
%}. |
4544 |
! |
|
4545 |
||
20494 | 4546 |
lowLevelPrint |
20838 | 4547 |
"Do not use this in user code. |
4548 |
Print the receiver on standard output. |
|
8898 | 4549 |
This method does NOT (by purpose) use the stream classes and |
15536 | 4550 |
will therefore work even in case of emergency during early startup |
20838 | 4551 |
or in a crash situation (MiniDebugger)." |
608 | 4552 |
|
4553 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4554 |
#ifdef __SCHTEAM__ |
20494 | 4555 |
org.exept.stj.STSystem.out.print(self.toString()); |
4556 |
return context._RETURN(self); |
|
18215 | 4557 |
#else |
20494 | 4558 |
if (__qIsStringLike(self)) { |
23862 | 4559 |
console_fprintf(stdout, "%s" , __stringVal(self)); |
4560 |
console_fflush(stdout); |
|
4561 |
RETURN (self); |
|
608 | 4562 |
} |
18215 | 4563 |
#endif |
3751 | 4564 |
%}. |
20494 | 4565 |
! |
4566 |
||
4567 |
lowLevelPrintCR |
|
20838 | 4568 |
"Do not use this in user code. |
4569 |
Print the receiver on standard output. |
|
20494 | 4570 |
This method does NOT (by purpose) use the stream classes and |
4571 |
will therefore work even in case of emergency during early startup |
|
20838 | 4572 |
or in a crash situation (MiniDebugger)." |
20494 | 4573 |
|
4574 |
%{ /* NOCONTEXT */ |
|
4575 |
#ifdef __SCHTEAM__ |
|
4576 |
org.exept.stj.STSystem.out.println(self.toString()); |
|
4577 |
return context._RETURN(self); |
|
4578 |
#else |
|
4579 |
if (__qIsStringLike(self)) { |
|
23862 | 4580 |
console_fprintf(stdout, "%s\n" , __stringVal(self)); |
4581 |
console_fflush(stdout); |
|
4582 |
RETURN (self); |
|
20494 | 4583 |
} |
4584 |
#endif |
|
4585 |
%}. |
|
4586 |
! |
|
4587 |
||
20879 | 4588 |
|
4589 |
"print the receiver on standard output, if the global Stdout is nil; |
|
4590 |
otherwise, fall back to the inherited print, |
|
4591 |
which sends the string to the Stdout stream. |
|
23862 | 4592 |
Redefined to be able to print during early startup, |
20879 | 4593 |
when the stream classes have not yet been initialized (i.e. Stdout is nil)." |
4594 |
||
4595 |
Stdout isNil ifTrue:[ |
|
23862 | 4596 |
self _print |
20879 | 4597 |
] ifFalse:[ |
23862 | 4598 |
super print |
20879 | 4599 |
]. |
4600 |
! |
|
4601 |
||
4602 |
printCR |
|
4603 |
"print the receiver on standard output, followed by a cr, |
|
4604 |
if the global Stdout is nil; otherwise, fall back to the inherited errorPrintCR, |
|
4605 |
which sends the string to the Stdout stream. |
|
23862 | 4606 |
Redefined to be able to print during early startup, |
20879 | 4607 |
when the stream classes have not yet been initialized (i.e. Stdout is nil)." |
4608 |
||
4609 |
Stdout isNil ifTrue:[ |
|
23862 | 4610 |
self _printCR |
20879 | 4611 |
] ifFalse:[ |
23862 | 4612 |
super printCR |
20879 | 4613 |
]. |
4614 |
! |
|
4615 |
||
2886 | 4616 |
printfPrintString:formatString |
7746 | 4617 |
"non-standard but sometimes useful. |
8898 | 4618 |
Return a printed representation of the receiver as specified by formatString, |
608 | 4619 |
which is defined by printf. |
21908 | 4620 |
|
21948 | 4621 |
If you use this, be aware, that the format string must be correct and something like %s. |
4622 |
||
11921 | 4623 |
This method is NONSTANDARD and may be removed without notice. |
15536 | 4624 |
WARNNG: this goes directly to the C-printf function and may therefore be inherently unsafe. |
23862 | 4625 |
Please use the printf: method, which is both safe |
20838 | 4626 |
and completely implemented in Smalltalk." |
608 | 4627 |
|
4628 |
%{ /* STACK: 1000 */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4629 |
#ifndef __SCHTEAM__ |
608 | 4630 |
char buffer[800]; |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4631 |
char *buf = buffer; |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4632 |
int bufsize = sizeof(buffer); |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4633 |
char *mallocbuf = NULL; |
608 | 4634 |
char *cp; |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4635 |
int len; |
608 | 4636 |
OBJ s; |
8898 | 4637 |
extern void *malloc(); |
608 | 4638 |
|
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
4639 |
if (__isStringLike(formatString)) { |
23862 | 4640 |
cp = (char *)__stringVal(self); |
4641 |
if (__qClass(self) != String) { |
|
4642 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
|
4643 |
} |
|
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4644 |
again: |
23862 | 4645 |
/* |
4646 |
* actually only needed on sparc: since thisContext is |
|
4647 |
* in a global register, which gets destroyed by printf, |
|
4648 |
* manually save it here - very stupid ... |
|
4649 |
*/ |
|
4650 |
__BEGIN_PROTECT_REGISTERS__ |
|
4651 |
||
4652 |
len = snprintf(buf, bufsize, (char *)__stringVal(formatString), cp); |
|
4653 |
||
4654 |
__END_PROTECT_REGISTERS__ |
|
4655 |
||
4656 |
if ((len < 0) || (len > bufsize)) { |
|
4657 |
if (len < 0) { |
|
4658 |
bufsize = bufsize * 2; |
|
4659 |
} else { |
|
4660 |
bufsize = len + 1; |
|
4661 |
} |
|
4662 |
if (mallocbuf) |
|
4663 |
free(mallocbuf); |
|
4664 |
buf = mallocbuf = malloc(bufsize); |
|
4665 |
if (buf == NULL) |
|
4666 |
goto fail; |
|
4667 |
goto again; |
|
4668 |
} |
|
4669 |
||
4670 |
s = __MKSTRING_L(buf, len); |
|
4671 |
||
4672 |
if (mallocbuf) |
|
4673 |
free(mallocbuf); |
|
4674 |
||
4675 |
if (s != nil) { |
|
4676 |
RETURN (s); |
|
4677 |
} |
|
608 | 4678 |
} |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4679 |
fail:; |
18215 | 4680 |
#endif |
608 | 4681 |
%}. |
4682 |
self primitiveFailed |
|
4683 |
||
4684 |
" |
|
8898 | 4685 |
'hello' printfPrintString:'%%s -> %s' |
4686 |
(String new:900) printfPrintString:'%%s -> %s' |
|
4687 |
'hello' printfPrintString:'%%10s -> %10s' |
|
4688 |
'hello' printfPrintString:'%%-10s -> %-10s' |
|
4689 |
'hello' printfPrintString:'%%900s -> %900s' |
|
4690 |
'hello' printfPrintString:'%%-900s -> %-900s' |
|
608 | 4691 |
" |
21908 | 4692 |
|
21948 | 4693 |
"Modified (comment): / 03-07-2017 / 15:12:58 / cg" |
608 | 4694 |
! |
4695 |
||
2886 | 4696 |
storeOn:aStream |
20838 | 4697 |
"put the storeString of myself onto a aStream" |
608 | 4698 |
|
7599
188489aaaacd
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7338
diff
changeset
|
4699 |
aStream nextPut:$'. |
608 | 4700 |
(self includes:$') ifTrue:[ |
23862 | 4701 |
self printWithQuotesDoubledOn:aStream |
608 | 4702 |
] ifFalse:[ |
23862 | 4703 |
aStream nextPutAll:self |
608 | 4704 |
]. |
4705 |
aStream nextPut:$' |
|
3579 | 4706 |
|
4707 |
"Modified: / 15.6.1998 / 17:21:51 / cg" |
|
608 | 4708 |
! |
4709 |
||
2886 | 4710 |
storeString |
4711 |
"return a String for storing myself" |
|
608 | 4712 |
|
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8038
diff
changeset
|
4713 |
^ self basicStoreString. |
1 | 4714 |
! ! |
4715 |
||
4716 |
!String methodsFor:'queries'! |
|
4717 |
||
5557 | 4718 |
basicSize |
4719 |
"return the number of characters in myself. |
|
4720 |
Redefined here to exclude the 0-byte at the end." |
|
4721 |
||
4722 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4723 |
#ifdef __SCHTEAM__ |
18404 | 4724 |
return context._RETURN( STInteger._new( self.basicSize() ) ); |
18215 | 4725 |
#else |
5557 | 4726 |
REGISTER OBJ slf, cls; |
4727 |
||
4728 |
slf = self; |
|
4729 |
cls = __qClass(slf); |
|
4730 |
if (cls == String) { |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
4731 |
RETURN ( __mkSmallInteger(__stringSize(slf)) ); |
5557 | 4732 |
} |
8913 | 4733 |
RETURN ( __mkSmallInteger(__stringSize(slf) |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20688
diff
changeset
|
4734 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
18215 | 4735 |
#endif |
5557 | 4736 |
%}. |
4737 |
^ super basicSize - 1 |
|
4738 |
! |
|
4739 |
||
2886 | 4740 |
bitsPerCharacter |
1239 | 4741 |
"return the number of bits each character has. |
4742 |
Here, 8 is returned (storing single byte characters)." |
|
4743 |
||
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
4744 |
^ 8 |
1239 | 4745 |
|
4746 |
"Modified: 20.4.1996 / 23:08:42 / cg" |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
4747 |
! |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
4748 |
|
19759 | 4749 |
bytesPerCharacter |
4750 |
"return the number of bytes each character has. |
|
4751 |
Here, 1 is returned (storing single byte characters)." |
|
4752 |
||
4753 |
^ 1 |
|
4754 |
! |
|
4755 |
||
23970 | 4756 |
bytesPerCharacterNeeded |
4757 |
"return the actual underlying string's required bytesPerCharacter |
|
4758 |
(i.e. checks if all characters really need that depth)" |
|
4759 |
||
4760 |
^ 1 |
|
4761 |
||
4762 |
"Created: / 25-03-2019 / 16:24:24 / Claus Gittinger" |
|
4763 |
! |
|
4764 |
||
18594 | 4765 |
characterSize |
4766 |
"answer the size in bits of my largest character (actually only 7 or 8)" |
|
4767 |
||
4768 |
%{ /* NOCONTEXT */ |
|
4769 |
||
4770 |
REGISTER unsigned char *cp = __stringVal(self); |
|
4771 |
REGISTER unsigned char *last = cp + __stringSize(self); |
|
4772 |
||
4773 |
if (!__isStringLike(self)) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4774 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
18594 | 4775 |
} |
4776 |
#if __POINTER_SIZE__ == 8 |
|
4777 |
if (sizeof(unsigned INT) == 8) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4778 |
for ( ; (cp+8) <= last; cp += 8) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4779 |
if (*(unsigned INT *)cp & 0x8080808080808080) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4780 |
RETURN ( __mkSmallInteger(8) ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4781 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4782 |
} |
18594 | 4783 |
} |
4784 |
#endif |
|
4785 |
if (sizeof(int) == 4) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4786 |
for ( ; (cp+4) <= last; cp += 4) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4787 |
if (*(unsigned int *)cp & 0x80808080) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4788 |
RETURN ( __mkSmallInteger(8) ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4789 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4790 |
} |
18594 | 4791 |
} |
4792 |
for ( ; (cp+2) <= last; cp += 2) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4793 |
if (*(unsigned short *)cp & 0x8080) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4794 |
RETURN ( __mkSmallInteger(8) ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4795 |
} |
18594 | 4796 |
} |
4797 |
for ( ; cp < last; cp++) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4798 |
if (*cp & 0x80) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4799 |
RETURN ( __mkSmallInteger(8) ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4800 |
} |
18594 | 4801 |
} |
4802 |
RETURN ( __mkSmallInteger(7) ); |
|
4803 |
%}. |
|
4804 |
^ super characterSize |
|
4805 |
||
4806 |
" |
|
4807 |
'hello world' characterSize |
|
4808 |
'hello world' asUnicode16String characterSize |
|
4809 |
('hello world' , (Character value:16r88) asString) characterSize |
|
4810 |
" |
|
18587 | 4811 |
! |
4812 |
||
18594 | 4813 |
containsNon7BitAscii |
8898 | 4814 |
"return true, if the underlying string contains 8BitCharacters (or widers) |
8458 | 4815 |
(i.e. if it is non-ascii)" |
4816 |
||
4817 |
%{ /* NOCONTEXT */ |
|
4818 |
||
18594 | 4819 |
REGISTER unsigned char *cp = __stringVal(self); |
4820 |
REGISTER unsigned char *last = cp + __stringSize(self); |
|
4821 |
||
4822 |
if (!__isStringLike(self)) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4823 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
9268
0d06a0818b52
contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents:
9233
diff
changeset
|
4824 |
} |
10371 | 4825 |
#if __POINTER_SIZE__ == 8 |
18594 | 4826 |
if (sizeof(unsigned INT) == 8) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4827 |
for ( ; (cp+8) <= last; cp += 8) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4828 |
if (*(unsigned INT *)cp & 0x8080808080808080) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4829 |
RETURN ( true ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4830 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4831 |
} |
8458 | 4832 |
} |
10371 | 4833 |
#endif |
9268
0d06a0818b52
contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents:
9233
diff
changeset
|
4834 |
if (sizeof(int) == 4) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4835 |
for ( ; (cp+4) <= last; cp += 4) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4836 |
if (*(unsigned int *)cp & 0x80808080) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4837 |
RETURN ( true ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4838 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4839 |
} |
9268
0d06a0818b52
contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents:
9233
diff
changeset
|
4840 |
} |
18594 | 4841 |
for ( ; (cp+2) <= last; cp += 2) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4842 |
if (*(unsigned short *)cp & 0x8080) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4843 |
RETURN ( true ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4844 |
} |
8915
eb2652ce257d
fixed includes/indexOf for subclasses of string with instVars;
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
4845 |
} |
18594 | 4846 |
for ( ; cp < last; cp++) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4847 |
if (*cp & 0x80) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4848 |
RETURN ( true ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
4849 |
} |
8458 | 4850 |
} |
4851 |
RETURN (false); |
|
4852 |
%}. |
|
18594 | 4853 |
^ super containsNon7BitAscii |
8458 | 4854 |
|
4855 |
" |
|
18594 | 4856 |
'hello world' containsNon7BitAscii |
4857 |
'hello world' asTwoByteString containsNon7BitAscii |
|
4858 |
('hello world' , (Character value:16r88) asString) containsNon7BitAscii |
|
8458 | 4859 |
" |
4860 |
! |
|
4861 |
||
18968 | 4862 |
containsNon8BitElements |
4863 |
"return true, if the underlying string contains elements larger than a single byte" |
|
4864 |
||
4865 |
^ false. |
|
4866 |
! |
|
4867 |
||
23700 | 4868 |
isBlank |
4869 |
"return true, if the receiver's size is 0 or if it contains only spaces. |
|
4870 |
Q: should we care for whiteSpace in general here ?" |
|
4871 |
||
4872 |
%{ /* NOCONTEXT */ |
|
4873 |
#ifndef __SCHTEAM__ |
|
4874 |
REGISTER unsigned char *src; |
|
4875 |
REGISTER unsigned char c; |
|
4876 |
OBJ cls; |
|
4877 |
||
4878 |
src = __stringVal(self); |
|
4879 |
if ((cls = __qClass(self)) != String) |
|
23862 | 4880 |
src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
4881 |
||
4882 |
// hop along in bigger steps if possible |
|
23700 | 4883 |
# ifdef UINT64 |
4884 |
while (*((UINT64 *)src) == 0x2020202020202020L) { |
|
23862 | 4885 |
src += 8; |
23700 | 4886 |
} |
4887 |
# endif /* UINT64 */ |
|
4888 |
while (*((unsigned *)src) == 0x20202020) { |
|
23862 | 4889 |
src += 4; |
23700 | 4890 |
} |
4891 |
while (*((unsigned short *)src) == 0x2020) { |
|
23862 | 4892 |
src += 2; |
23700 | 4893 |
} |
4894 |
||
4895 |
while ((c = *src++) == ' ') |
|
23862 | 4896 |
;; /* just walking along */ |
23700 | 4897 |
if (c != '\0') { |
23862 | 4898 |
RETURN ( false ); |
23700 | 4899 |
} |
4900 |
RETURN ( true ); |
|
4901 |
# endif /* ! __SCHTEAM__ */ |
|
4902 |
%}. |
|
4903 |
^ super isBlank |
|
4904 |
||
4905 |
"Modified: / 24-11-2017 / 08:56:17 / cg" |
|
4906 |
! |
|
4907 |
||
4908 |
isEmpty |
|
4909 |
"return true if the receiver is empty (i.e. if size == 0) |
|
4910 |
Redefined here for performance" |
|
4911 |
||
4912 |
%{ /* NOCONTEXT */ |
|
4913 |
#ifndef __SCHTEAM__ |
|
4914 |
if (__isStringLike(self)) { |
|
23862 | 4915 |
RETURN ( (__stringSize(self) == 0) ? true : false); |
23700 | 4916 |
} |
4917 |
#endif /* ! __SCHTEAM__ */ |
|
4918 |
%}. |
|
4919 |
^ self size == 0 |
|
4920 |
||
4921 |
"Modified: / 16-02-2017 / 14:57:50 / stefan" |
|
4922 |
! |
|
4923 |
||
14556 | 4924 |
isWideString |
19579 | 4925 |
"true if I require more than one byte per character" |
4926 |
||
14556 | 4927 |
^ false |
4928 |
! |
|
4929 |
||
2886 | 4930 |
knownAsSymbol |
4931 |
"return true, if there is a symbol with same characters in the |
|
2862 | 4932 |
system. |
4933 |
Can be used to check for existance of a symbol without creating one" |
|
608 | 4934 |
|
4935 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4936 |
#ifdef __SCHTEAM__ |
18405 | 4937 |
return context._RETURN( (STSymbol.asSymbolIfInterned(self.asSTString().asString()) != null) ? STObject.True : STObject.False ); |
18215 | 4938 |
#else |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4939 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4940 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4941 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4942 |
cls = __qClass(self); |
22651
57af76e8401b
oops - dont make a Symbol into an ImmutableString
Claus Gittinger <cg@exept.de>
parents:
22491
diff
changeset
|
4943 |
if ((cls != String) && (cls != ImmutableString)) { |
9473 | 4944 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4945 |
} else { |
9473 | 4946 |
indx = 0; |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4947 |
} |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4948 |
RETURN ( __KNOWNASSYMBOL(__stringVal(self) + indx) ); |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4949 |
#endif /* ! __SCHTEAM__ */ |
5407 | 4950 |
%}. |
6007 | 4951 |
"/ ^ self asSymbolIfInterned notNil. |
5407 | 4952 |
self primitiveFailed |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4953 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4954 |
" |
8898 | 4955 |
'hello' knownAsSymbol |
4956 |
'fooBarBaz' knownAsSymbol |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4957 |
" |
5557 | 4958 |
! |
4959 |
||
23700 | 4960 |
notEmpty |
4961 |
"return true if the receiver is not empty (i.e. if size ~~ 0) |
|
4962 |
Redefined here for performance" |
|
4963 |
||
4964 |
%{ /* NOCONTEXT */ |
|
4965 |
#ifndef __SCHTEAM__ |
|
4966 |
if (__isStringLike(self)) { |
|
23862 | 4967 |
RETURN ( (__stringSize(self) != 0) ? true : false); |
23700 | 4968 |
} |
4969 |
#endif /* ! __SCHTEAM__ */ |
|
4970 |
%}. |
|
4971 |
^ self size ~~ 0 |
|
4972 |
||
4973 |
"Modified: / 16-02-2017 / 15:00:42 / stefan" |
|
4974 |
! |
|
4975 |
||
5557 | 4976 |
size |
4977 |
"return the number of characters in myself. |
|
4978 |
Reimplemented here to avoid the additional size->basicSize send |
|
4979 |
(which we can do here, since size is obviously not redefined in a subclass). |
|
4980 |
This method is the same as basicSize." |
|
4981 |
||
4982 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4983 |
#ifdef __SCHTEAM__ |
18404 | 4984 |
return context._RETURN( STInteger._new( self.basicSize() ) ); |
18215 | 4985 |
#else |
5557 | 4986 |
REGISTER OBJ cls, slf; |
4987 |
||
4988 |
slf = self; |
|
4989 |
cls = __qClass(slf); |
|
4990 |
if (cls == String) { |
|
9473 | 4991 |
RETURN ( __mkSmallInteger(__stringSize(slf)) ); |
5557 | 4992 |
} |
8913 | 4993 |
RETURN ( __mkSmallInteger(__stringSize(slf) |
9473 | 4994 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
18215 | 4995 |
#endif |
5557 | 4996 |
%}. |
4997 |
^ self basicSize |
|
8038 | 4998 |
! |
4999 |
||
5000 |
stringSpecies |
|
15525 | 5001 |
^ self species |
19839 | 5002 |
! |
5003 |
||
5004 |
utf8DecodedMaxBytes |
|
21376 | 5005 |
<resource: #obsolete> |
5006 |
"return the number of characters needed when this string is |
|
19839 | 5007 |
decoded from UTF-8." |
5008 |
||
21376 | 5009 |
^ self utf8DecodedSize. |
5010 |
||
5011 |
"Modified (comment): / 07-02-2017 / 15:10:33 / stefan" |
|
19839 | 5012 |
! |
5013 |
||
5014 |
utf8DecodedSize |
|
21376 | 5015 |
"return the number of characters needed when this string is |
19839 | 5016 |
decoded from UTF-8." |
5017 |
||
5018 |
%{ /* NOCONTEXT */ |
|
5019 |
||
5020 |
unsigned char *cp = __stringVal(self); |
|
5021 |
unsigned char *last = cp + __stringSize(self); |
|
5022 |
unsigned INT len = 0; |
|
5023 |
||
5024 |
if (!__isStringLike(self)) { |
|
23862 | 5025 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
19839 | 5026 |
} |
5027 |
// count the number of start-bytes |
|
5028 |
for ( ; cp < last; cp++) { |
|
23862 | 5029 |
if ((*cp & 0xC0) != 0x80) len++; |
19839 | 5030 |
} |
5031 |
RETURN (__mkSmallInteger(len)); |
|
5032 |
%}. |
|
5033 |
||
5034 |
" |
|
5035 |
'hello world' utf8DecodedSize |
|
5036 |
'ä' utf8Encoded utf8DecodedSize |
|
5037 |
'äΣΔΨӕἤῴ' utf8Encoded utf8DecodedSize |
|
5038 |
" |
|
21376 | 5039 |
|
5040 |
"Modified: / 07-02-2017 / 15:10:40 / stefan" |
|
1 | 5041 |
! ! |
608 | 5042 |
|
11267 | 5043 |
!String methodsFor:'sorting & reordering'! |
5044 |
||
21738 | 5045 |
reverseFrom:startIndex to:endIndex |
11267 | 5046 |
"in-place reverse the characters of the string. |
5047 |
WARNING: this is a destructive operation, which modifies the receiver. |
|
23862 | 5048 |
Please use reversed (with a d) for a functional version." |
11267 | 5049 |
|
5050 |
"Q: is there a need to redefine it here ?" |
|
5051 |
||
5052 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
5053 |
#ifndef __SCHTEAM__ |
11267 | 5054 |
REGISTER char c; |
5055 |
REGISTER unsigned char *hip, *lowp; |
|
5056 |
||
21738 | 5057 |
if (__isString(self) |
5058 |
&& __isSmallInteger(startIndex) |
|
5059 |
&& __isSmallInteger(endIndex)) { |
|
23862 | 5060 |
int _start = __intVal(startIndex) - 1; |
5061 |
int _end = __intVal(endIndex) - 1; |
|
5062 |
||
5063 |
if ((_start >= 0) |
|
5064 |
&& (_end < __stringSize(self)) |
|
5065 |
&& (_end >= _start)) { |
|
5066 |
lowp = __stringVal(self) + _start; |
|
5067 |
hip = __stringVal(self) + _end; |
|
5068 |
while (lowp < hip) { |
|
5069 |
c = *lowp; |
|
5070 |
*lowp = *hip; |
|
5071 |
*hip = c; |
|
5072 |
lowp++; |
|
5073 |
hip--; |
|
5074 |
} |
|
5075 |
RETURN ( self ); |
|
5076 |
} |
|
11267 | 5077 |
} |
21738 | 5078 |
#endif |
11267 | 5079 |
%}. |
21738 | 5080 |
^ super reverseFrom:startIndex to:endIndex |
5081 |
||
5082 |
" |
|
5083 |
'1234567890' copy reverseFrom:2 to:5 |
|
21739 | 5084 |
'1234567890' copy reverse |
5085 |
'1234567890' copy reversed |
|
21740 | 5086 |
|
5087 |
|t| |
|
5088 |
t := '1234567890abcdefghijk' copy. |
|
5089 |
t reverseFrom:1 to:10. |
|
5090 |
t reverseFrom:11 to:t size. |
|
5091 |
t reverseFrom:1 to:t size. |
|
5092 |
t |
|
5093 |
||
5094 |
|t| |
|
5095 |
t := '1234567890abcdefghijk' copy. |
|
5096 |
t reverseFrom:1 to:2. |
|
5097 |
t reverseFrom:3 to:t size. |
|
5098 |
t reverseFrom:1 to:t size. |
|
5099 |
t |
|
21738 | 5100 |
" |
5101 |
||
5102 |
"Created: / 01-05-2017 / 12:50:18 / cg" |
|
21740 | 5103 |
"Modified (comment): / 01-05-2017 / 14:05:41 / cg" |
11267 | 5104 |
! ! |
10820 | 5105 |
|
11346 | 5106 |
!String methodsFor:'substring searching'! |
5107 |
||
23862 | 5108 |
caseInsensitiveIndexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue |
19715 | 5109 |
"naive search fallback (non-BM). |
21674 | 5110 |
Private method to speed up caseInSensitive searches" |
23862 | 5111 |
|
19715 | 5112 |
|notFound| |
5113 |
||
5114 |
%{ |
|
5115 |
#ifndef __SCHTEAM__ |
|
5116 |
if (__qIsStringLike(self) |
|
5117 |
&& __isStringLike(aSubString) |
|
5118 |
&& (__isSmallInteger(startIndex)) |
|
5119 |
&& (__intVal(startIndex) > 0) |
|
5120 |
) { |
|
23862 | 5121 |
unsigned char *c_pSelf = __stringVal(self); |
5122 |
unsigned char *c_substring = __stringVal(aSubString); |
|
5123 |
unsigned char *c_pSelfI, *c_pSelfMax; |
|
5124 |
int c_lenSelf = __stringSize(self); |
|
5125 |
int c_lenSubstring = __stringSize(aSubString); |
|
5126 |
int c_idx0Max = c_lenSelf - c_lenSubstring; |
|
5127 |
unsigned char c_first; |
|
5128 |
unsigned char c_oppositeCaseFirst = 0; |
|
5129 |
int i; |
|
5130 |
||
5131 |
if (c_lenSubstring == 0) { |
|
19715 | 5132 |
#if 1 |
23862 | 5133 |
/* empty string does not match */ |
5134 |
notFound = true; |
|
5135 |
goto getOutOfHere; |
|
19715 | 5136 |
#else |
23862 | 5137 |
/* empty string matches */ |
5138 |
RETURN(startIndex); |
|
19715 | 5139 |
#endif |
23862 | 5140 |
} |
5141 |
||
5142 |
// searched string's length > string |
|
5143 |
if (c_idx0Max < 0) { |
|
5144 |
notFound = true; |
|
5145 |
goto getOutOfHere; |
|
5146 |
} |
|
5147 |
||
5148 |
c_first = c_substring[0]; |
|
5149 |
if (((c_first >= 'A') && (c_first <= 'Z')) |
|
5150 |
|| ((c_first >= 0xC0) && (c_first <= 0xDE) && (c_first != 0xD7))) { |
|
5151 |
c_oppositeCaseFirst = c_first - 'A' + 'a'; |
|
5152 |
} else { |
|
5153 |
if (((c_first >= 'a') && (c_first <= 'z')) |
|
5154 |
|| ((c_first >= 0xE0) && (c_first <= 0xFE) && (c_first != 0xF7))) { |
|
5155 |
c_oppositeCaseFirst = c_first - 'a' + 'A'; |
|
5156 |
} |
|
5157 |
} |
|
5158 |
||
5159 |
// idx: |
|
5160 |
// 0123456789 |
|
5161 |
||
5162 |
// 1234567890 - lenSelf = 10 |
|
5163 |
// abc - lenSubstring = 3 |
|
5164 |
// - idx0Max = 7 (last legal startIndex) |
|
5165 |
||
5166 |
i = __intVal(startIndex) - 1; |
|
5167 |
c_pSelfI = c_pSelf + i; |
|
5168 |
c_pSelfMax = c_pSelf + c_idx0Max; |
|
5169 |
||
5170 |
for (; c_pSelfI <= c_pSelfMax; c_pSelfI++) { |
|
5171 |
int j; |
|
5172 |
unsigned char c_selfChar; |
|
5173 |
||
5174 |
// find the first char |
|
5175 |
c_selfChar = c_pSelfI[0]; |
|
5176 |
if (c_selfChar != c_first && c_selfChar != c_oppositeCaseFirst) { |
|
19715 | 5177 |
searchNext: ; |
23862 | 5178 |
continue; |
5179 |
} |
|
5180 |
||
5181 |
// first char matches |
|
5182 |
// compare rest |
|
5183 |
for (j=1; j<c_lenSubstring; j++) { |
|
5184 |
unsigned char c_subChar = c_substring[j]; |
|
5185 |
unsigned char c_selfChar = c_pSelfI[j]; |
|
5186 |
||
5187 |
if (c_selfChar == c_subChar) continue; |
|
5188 |
||
5189 |
if (((c_subChar >= 'A') && (c_subChar <= 'Z')) |
|
5190 |
|| ((c_subChar >= 0xC0) && (c_subChar <= 0xDE) && (c_subChar != 0xD7))) { |
|
5191 |
unsigned char c_lcSubChar = c_subChar - 'A' + 'a'; |
|
5192 |
if (c_selfChar != c_lcSubChar) goto searchNext; |
|
5193 |
} else { |
|
5194 |
if (((c_subChar >= 'a') && (c_subChar <= 'z')) |
|
5195 |
|| ((c_subChar >= 0xE0) && (c_subChar <= 0xFE) && (c_subChar != 0xF7))) { |
|
5196 |
unsigned char c_ucSubChar = c_subChar - 'a' + 'A'; |
|
5197 |
if (c_selfChar != c_ucSubChar) goto searchNext; |
|
5198 |
} else { |
|
5199 |
goto searchNext; |
|
5200 |
} |
|
5201 |
} |
|
5202 |
} |
|
5203 |
// if we arrive here, we have a match at i |
|
5204 |
RETURN( __mkSmallInteger( c_pSelfI - c_pSelf + 1 ) ); |
|
5205 |
} |
|
5206 |
notFound = true; |
|
19715 | 5207 |
} |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
5208 |
|
19715 | 5209 |
getOutOfHere: ; |
5210 |
#endif /* ! __SCHTEAM__ */ |
|
5211 |
%}. |
|
21674 | 5212 |
|
19715 | 5213 |
notFound == true ifTrue:[ |
23862 | 5214 |
^ exceptionValue value. |
11346 | 5215 |
]. |
21674 | 5216 |
|
5217 |
"/ arrive here aSubstring is a UnicodeString or arguments are invalid |
|
23862 | 5218 |
^ super |
5219 |
indexOfSubCollection:aSubString |
|
5220 |
startingAt:startIndex |
|
5221 |
ifAbsent:exceptionValue |
|
5222 |
caseSensitive:false |
|
14301
d8e7b4196d5e
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14297
diff
changeset
|
5223 |
|
19715 | 5224 |
" |
21674 | 5225 |
'abcdefg' caseInsensitiveIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil |
23862 | 5226 |
'abcdefg' caseInsensitiveIndexOfSubCollection:'bcd' startingAt:1 ifAbsent:nil |
5227 |
'abcdefg' caseInsensitiveIndexOfSubCollection:'cde' startingAt:1 ifAbsent:nil |
|
5228 |
'abcabcg' caseInsensitiveIndexOfSubCollection:'abc' startingAt:2 ifAbsent:nil |
|
5229 |
||
5230 |
'ABCDEFG' caseInsensitiveIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil |
|
5231 |
'ABCDEFG' caseInsensitiveIndexOfSubCollection:'Abc' startingAt:1 ifAbsent:nil |
|
5232 |
'ABCDEFG' caseInsensitiveIndexOfSubCollection:'aBC' startingAt:1 ifAbsent:nil |
|
5233 |
'ABCDEFG' caseInsensitiveIndexOfSubCollection:'ABC' startingAt:1 ifAbsent:nil |
|
5234 |
||
5235 |
'ABCDEFG' caseInsensitiveIndexOfSubCollection:'a' startingAt:1 ifAbsent:nil |
|
5236 |
'ABCDEFG' caseInsensitiveIndexOfSubCollection:'A' startingAt:1 ifAbsent:nil |
|
5237 |
||
5238 |
'ABCDEFG' caseInsensitiveIndexOfSubCollection:'bcd' startingAt:1 ifAbsent:nil |
|
5239 |
'ABCDEFG' caseInsensitiveIndexOfSubCollection:'cde' startingAt:1 ifAbsent:nil |
|
5240 |
'ABCABCG' caseInsensitiveIndexOfSubCollection:'abc' startingAt:2 ifAbsent:nil |
|
5241 |
||
5242 |
'1234567890' caseInsensitiveIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil |
|
5243 |
'1234567890' caseInsensitiveIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
5244 |
" |
21674 | 5245 |
|
5246 |
"Created: / 28-03-2017 / 15:33:50 / stefan" |
|
5247 |
"Modified (comment): / 28-03-2017 / 16:35:16 / stefan" |
|
5248 |
! |
|
5249 |
||
5250 |
indexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive |
|
23874 | 5251 |
"redefined as primitive for maximum speed (BM). |
5252 |
Compared to the strstr libc function, on my machine, |
|
5253 |
BM is faster for caseSensitive compares above around 8.5 searched characters; |
|
5254 |
for caseInsensitive compares, strstr is slower than caseInsensitiveIndex. |
|
5255 |
(for much longer searched strings, BM is much faster; 5times as fast for 20chars)" |
|
21674 | 5256 |
|
5257 |
|notFound| |
|
5258 |
||
5259 |
caseSensitive ifFalse:[ |
|
23874 | 5260 |
^ self caseInsensitiveIndexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue. |
21674 | 5261 |
]. |
5262 |
||
5263 |
%{ /* STACK:4000 */ |
|
5264 |
#ifndef __SCHTEAM__ |
|
5265 |
if (__qIsStringLike(self) |
|
5266 |
&& __isStringLike(aSubString) |
|
5267 |
&& (__isSmallInteger(startIndex)) |
|
5268 |
&& (__intVal(startIndex) > 0) |
|
5269 |
) { |
|
23874 | 5270 |
unsigned char *y = __stringVal(self); |
5271 |
unsigned char *x = __stringVal(aSubString); |
|
5272 |
int m = __stringSize(aSubString); |
|
5273 |
int n = __stringSize(self); |
|
21674 | 5274 |
# define MAX_PATTERN_SIZE 128 |
5275 |
# define XSIZE 256 |
|
5276 |
# define ASIZE 256 |
|
5277 |
# define MAX(a,b) (a>b ? a : b) |
|
5278 |
||
23874 | 5279 |
if (m == 0) { |
21674 | 5280 |
#if 1 |
23874 | 5281 |
/* empty string does not match */ |
5282 |
RETURN(__mkSmallInteger(0)); |
|
21674 | 5283 |
#else |
23874 | 5284 |
/* empty string matches */ |
5285 |
RETURN(startIndex); |
|
21674 | 5286 |
#endif |
23874 | 5287 |
} |
5288 |
if (m <= XSIZE) { |
|
5289 |
int i, j; |
|
5290 |
static int lastPatternSize = 0; |
|
5291 |
static char lastPattern[MAX_PATTERN_SIZE+1] = { 0 }; |
|
5292 |
static int bmGs[XSIZE+1], bmBc[ASIZE]; |
|
21674 | 5293 |
|
5294 |
# define preBmBc(x, m, bmBc) { \ |
|
23874 | 5295 |
int i; \ |
5296 |
\ |
|
5297 |
for (i = 0; i < ASIZE; ++i) \ |
|
5298 |
bmBc[i] = m; \ |
|
5299 |
for (i = 0; i < m - 1; ++i) \ |
|
5300 |
bmBc[x[i]] = m - i - 1; \ |
|
5301 |
} |
|
21674 | 5302 |
|
5303 |
# define suffixes(x, m, suff) { \ |
|
23874 | 5304 |
int f, g, i; \ |
5305 |
\ |
|
5306 |
suff[m - 1] = m; \ |
|
5307 |
g = m - 1; \ |
|
5308 |
for (i = m - 2; i >= 0; --i) { \ |
|
5309 |
if (i > g && suff[i + m - 1 - f] < i - g) \ |
|
5310 |
suff[i] = suff[i + m - 1 - f]; \ |
|
5311 |
else { \ |
|
5312 |
if (i < g) \ |
|
5313 |
g = i; \ |
|
5314 |
f = i; \ |
|
5315 |
while (g >= 0 && x[g] == x[g + m - 1 - f]) \ |
|
5316 |
--g; \ |
|
5317 |
suff[i] = f - g; \ |
|
5318 |
} \ |
|
5319 |
} \ |
|
5320 |
} |
|
21674 | 5321 |
|
5322 |
# define preBmGs(x, m, bmGs) { \ |
|
23874 | 5323 |
int i, j, suff[XSIZE]; \ |
5324 |
\ |
|
5325 |
suffixes(x, m, suff); \ |
|
5326 |
\ |
|
5327 |
for (i = 0; i < m; ++i) \ |
|
5328 |
bmGs[i] = m; \ |
|
5329 |
j = 0; \ |
|
5330 |
for (i = m - 1; i >= 0; --i) \ |
|
5331 |
if (suff[i] == i + 1) \ |
|
5332 |
for (; j < m - 1 - i; ++j) \ |
|
5333 |
if (bmGs[j] == m) \ |
|
5334 |
bmGs[j] = m - 1 - i; \ |
|
5335 |
for (i = 0; i <= m - 2; ++i) \ |
|
5336 |
bmGs[m - 1 - suff[i]] = m - 1 - i; \ |
|
5337 |
} |
|
5338 |
||
5339 |
/* tables only depend on pattern; so we can cache them in case the same string is searched again */ |
|
5340 |
if ((m == lastPatternSize) && (strcmp(lastPattern, x) == 0)) { |
|
5341 |
/* tables are still valid */ |
|
5342 |
// printf("valid: \"%s\"\n", lastPattern); |
|
5343 |
} else { |
|
5344 |
/* Preprocessing */ |
|
5345 |
// printf("compute: \"%s\"\n", lastPattern); |
|
5346 |
preBmGs(x, m, bmGs); |
|
5347 |
preBmBc(x, m, bmBc); |
|
5348 |
if (m <= MAX_PATTERN_SIZE) { |
|
5349 |
// printf("cache for: \"%s\"\n", lastPattern); |
|
5350 |
strcpy(lastPattern, x); |
|
5351 |
lastPatternSize = m; |
|
5352 |
} |
|
5353 |
} |
|
5354 |
||
5355 |
/* Searching */ |
|
5356 |
j = __intVal(startIndex) - 1; |
|
5357 |
while (j <= n - m) { |
|
5358 |
for (i = m - 1; i >= 0 && x[i] == y[i + j]; --i); |
|
5359 |
if (i < 0) { |
|
5360 |
RETURN (__mkSmallInteger(j+1)); |
|
5361 |
j += bmGs[0]; |
|
5362 |
} else { |
|
5363 |
int s1 = bmGs[i]; |
|
5364 |
int s2 = bmBc[y[i + j]] - m + 1 + i; |
|
5365 |
j += MAX(s1, s2); |
|
5366 |
} |
|
5367 |
} |
|
5368 |
notFound = true; |
|
5369 |
} |
|
21674 | 5370 |
} |
5371 |
#endif /* ! __SCHTEAM__ */ |
|
5372 |
%}. |
|
5373 |
notFound == true ifTrue:[ |
|
23874 | 5374 |
^ exceptionValue value. |
21674 | 5375 |
]. |
5376 |
||
23874 | 5377 |
"/ arrive here if aSubstring is a UnicodeString or arguments are invalid |
21674 | 5378 |
^ super indexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:true |
5379 |
||
5380 |
"Modified: / 05-08-2012 / 12:27:31 / cg" |
|
5381 |
"Modified (comment): / 28-03-2017 / 16:31:54 / stefan" |
|
23874 | 5382 |
"Modified (comment): / 12-03-2019 / 20:15:33 / Claus Gittinger" |
11346 | 5383 |
! ! |
5384 |
||
608 | 5385 |
!String methodsFor:'testing'! |
5386 |
||
10958 | 5387 |
isLiteral |
5388 |
"return true, if the receiver can be used as a literal constant in ST syntax |
|
5389 |
(i.e. can be used in constant arrays)" |
|
5390 |
||
5391 |
^ true |
|
608 | 5392 |
! ! |
5393 |
||
4660 | 5394 |
!String methodsFor:'tracing'! |
5395 |
||
16771 | 5396 |
isSingleByteString |
16773 | 5397 |
"returns true only for strings and immutable strings. |
5398 |
Must replace foo isMemberOf:String and foo class == String" |
|
5399 |
||
16771 | 5400 |
^ true |
5401 |
! |
|
5402 |
||
4682 | 5403 |
traceInto:aRequestor level:level from:referrer |
4660 | 5404 |
"double dispatch into tracer, passing my type implicitely in the selector" |
5405 |
||
4682 | 5406 |
^ aRequestor traceString:self level:level from:referrer |
4660 | 5407 |
|
5408 |
||
5409 |
! ! |
|
5410 |
||
633 | 5411 |
!String class methodsFor:'documentation'! |
5412 |
||
2886 | 5413 |
version |
18551
7f43475b5613
eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents:
18405
diff
changeset
|
5414 |
^ '$Header$' |
12184
e91c375c7ea9
comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents:
11922
diff
changeset
|
5415 |
! |
e91c375c7ea9
comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents:
11922
diff
changeset
|
5416 |
|
e91c375c7ea9
comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents:
11922
diff
changeset
|
5417 |
version_CVS |
18551
7f43475b5613
eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents:
18405
diff
changeset
|
5418 |
^ '$Header$' |
633 | 5419 |
! ! |
23874 | 5420 |