author | mawalch |
Mon, 15 Aug 2016 16:13:16 +0200 | |
changeset 20272 | 9d04254b1c19 |
parent 20193 | c24ef271e741 |
child 20342 | 219a5a47e8b1 |
child 20384 | 78b74ac7c891 |
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 |
|
3809
dd1df62365ee
use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
28 |
#include <stdio.h> |
dd1df62365ee
use threadsafe fprintf (win32)
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
29 |
#define _STDIO_H_INCLUDED_ |
14752
201d3e649814
include stdlib.h to define malloc() prototypes
Stefan Vogel <sv@exept.de>
parents:
14664
diff
changeset
|
30 |
#include <stdlib.h> |
88 | 31 |
#include <ctype.h> |
359 | 32 |
|
273 | 33 |
#ifdef LINUX |
359 | 34 |
# define __STRINGDEFS__ |
35 |
# include <linuxIntern.h> |
|
273 | 36 |
#endif |
95 | 37 |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
38 |
#ifdef __osx__ |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
39 |
# include <string.h> |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
40 |
# include <stdlib.h> |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
41 |
#endif |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
42 |
|
19877 | 43 |
#ifdef __MINGW__ |
44 |
# include <string.h> |
|
45 |
# include <stdlib.h> |
|
46 |
#endif |
|
47 |
||
95 | 48 |
/* |
49 |
* old st/x creates strings with spaces in it; |
|
50 |
* new st/x will fill it with zeros (for st-80 compatibility) |
|
51 |
* the define below sets old behavior. |
|
52 |
*/ |
|
53 |
#define INITIALIZE_WITH_SPACE |
|
6370 | 54 |
|
19107 | 55 |
#ifdef FAST_MEMCHR |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
56 |
// # 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
|
57 |
// extern void *memchr(); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
58 |
// # endif |
6370 | 59 |
#endif |
88 | 60 |
%} |
216 | 61 |
! ! |
88 | 62 |
|
8647 | 63 |
!String primitiveFunctions! |
64 |
%{ |
|
65 |
||
8898 | 66 |
static int |
19878 | 67 |
nextOnKeyboard(int char1, int char2) |
10371 | 68 |
{ |
8647 | 69 |
/* compare two characters if they are next to each other on a (US-) keyboard */ |
10370 | 70 |
|
71 |
static char *us_keys[] = { "1234567890-", |
|
9473 | 72 |
"*qwertyuiop", |
73 |
"**asdfghjkl:", |
|
74 |
"***zxcvbnm", |
|
75 |
0 }; |
|
10370 | 76 |
static char *de_keys[] = { "1234567890-", |
77 |
"*qwertzuiop", |
|
78 |
"**asdfghjkl:", |
|
79 |
"***yxcvbnm", |
|
80 |
0 }; |
|
10371 | 81 |
char **keys = us_keys; |
8647 | 82 |
char **line1, **line2; |
83 |
char *col1, *col2; |
|
84 |
int diff; |
|
85 |
||
86 |
for (line1 = keys; *line1 != 0; line1++) { |
|
9473 | 87 |
for (col1 = *line1; *col1 != 0 && *col1 != char1; col1++) |
88 |
continue; |
|
8647 | 89 |
} |
90 |
if (*col1 == 0) |
|
9473 | 91 |
return(0); |
8647 | 92 |
|
93 |
for (line2 = keys; *line2 != 0; line2++) { |
|
9473 | 94 |
for (col2 = *line2; *col2 != 0 && *col2 != char2; col2++) |
95 |
continue; |
|
8647 | 96 |
} |
97 |
if (*col2 == 0) |
|
9473 | 98 |
return(0); |
8647 | 99 |
|
100 |
diff = col1 - col2; |
|
101 |
if (diff > 1 || diff < -1) |
|
9473 | 102 |
return(0); |
8647 | 103 |
|
104 |
diff = line1 - line2; |
|
105 |
if (diff > 1 || diff < -1) |
|
9473 | 106 |
return(0); |
8647 | 107 |
return(1); |
108 |
} |
|
109 |
||
110 |
%} |
|
111 |
! ! |
|
112 |
||
608 | 113 |
!String class methodsFor:'documentation'! |
114 |
||
115 |
copyright |
|
116 |
" |
|
117 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
9473 | 118 |
All Rights Reserved |
608 | 119 |
|
120 |
This software is furnished under a license and may be used |
|
121 |
only in accordance with the terms of that license and with the |
|
122 |
inclusion of the above copyright notice. This software may not |
|
123 |
be provided or otherwise made available to, or used by, any |
|
124 |
other person. No title to or ownership of the software is |
|
125 |
hereby transferred. |
|
126 |
" |
|
127 |
! |
|
3 | 128 |
|
608 | 129 |
documentation |
130 |
" |
|
131 |
Strings are ByteArrays storing Characters. |
|
132 |
||
19910 | 133 |
Strings are kind of kludgy: to allow for easy handling by C functions, |
608 | 134 |
there is always one 0-byte added at the end, which is not counted |
19305 | 135 |
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
|
136 |
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
|
137 |
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
|
138 |
prevent a nonsense contents ...) |
3 | 139 |
|
19305 | 140 |
You cannot add any instvars to String, since the run time system & compiler |
608 | 141 |
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
|
142 |
If you really need strings with instVars, you have to create a subclass |
608 | 143 |
of String (the access functions defined here can handle this). |
144 |
A little warning though: not all smalltalk systems allow subclassing String, |
|
145 |
so your program may become unportable if you do so. |
|
1290 | 146 |
|
20003 | 147 |
Strings have an implicit (assumed) encoding of ISO-8859-1. |
7895 | 148 |
For strings with other encodings, either keep the encoding separately, |
149 |
or use instances of encodedString. |
|
150 |
||
19910 | 151 |
Be careful when using the 0-byte in a String. This is not prohibited, but |
152 |
the implementations of some String methods use C functions and may |
|
153 |
therefore yield unexpected results (e.g. compareWith:collating:) when |
|
154 |
processing a String containing the 0-byte. |
|
155 |
||
1290 | 156 |
[author:] |
19910 | 157 |
Claus Gittinger |
1310 | 158 |
|
159 |
[see also:] |
|
19910 | 160 |
Text StringCollection TwoByteString JISEncodedString |
161 |
Symbol |
|
608 | 162 |
" |
3 | 163 |
! ! |
164 |
||
1 | 165 |
!String class methodsFor:'instance creation'! |
166 |
||
167 |
basicNew:anInteger |
|
4802 | 168 |
"return a new empty string with anInteger characters. |
169 |
In contrast to other smalltalks, this returns a string filled |
|
170 |
with spaces (instead of a string filled with 0-bytes). |
|
171 |
This makes much more sense, in that a freshly created string |
|
172 |
can be directly used as separator or for formatting." |
|
1 | 173 |
|
174 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
175 |
#ifdef __SCHTEAM__ |
18236 | 176 |
return context._RETURN( self.basicNew( anInteger.intValue() )); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
177 |
#else |
1 | 178 |
OBJ newString; |
18581 | 179 |
REGISTER INT len, instsize; |
1 | 180 |
REGISTER unsigned char *cp; |
18581 | 181 |
int nInstVars; |
1 | 182 |
|
252 | 183 |
if (__isSmallInteger(anInteger)) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
184 |
len = __intVal(anInteger); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
185 |
if (len >= 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
186 |
instsize = OHDR_SIZE + len + 1; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
187 |
if (self == String || self == ImmutableString) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
188 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
189 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
190 |
* the most common case |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
191 |
*/ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
192 |
__qCheckedNew(newString, instsize); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
193 |
__InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
194 |
__qSTORE(newString, self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
195 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
196 |
cp = __stringVal(newString); |
19748 | 197 |
|
198 |
# if defined(memset4) |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
199 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
200 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
201 |
* no sizeof(int) here please - |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
202 |
* - memset4 (if defined) fills 4-bytes on ALL machines |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
203 |
*/ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
204 |
int l4 = len >> 2; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
205 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
206 |
if (len & 3) l4++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
207 |
memset4(cp, 0x20202020, l4); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
208 |
cp[len] = '\0'; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
209 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
210 |
# else |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
211 |
# ifdef FAST_MEMSET |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
212 |
memset(cp, ' ', len); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
213 |
cp[len] = '\0'; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
214 |
# else |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
215 |
for ( ; len >= 8; cp += 8, len -= 8) { |
19748 | 216 |
# ifdef INT64 |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
217 |
((INT64 *)cp)[0] = 0x2020202020202020L; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
218 |
# else |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
219 |
((int *)cp)[0] = 0x20202020; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
220 |
((int *)cp)[1] = 0x20202020; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
221 |
# endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
222 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
223 |
while (len--) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
224 |
*cp++ = ' '; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
225 |
*cp = '\0'; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
226 |
# endif /* not FAST_MEMSET */ |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
227 |
# endif /* not memset4 */ |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
228 |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
229 |
RETURN (newString); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
230 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
231 |
nInstVars = 0; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
232 |
} else { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
233 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
234 |
instsize += __OBJS2BYTES__(nInstVars); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
235 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
236 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
237 |
__PROTECT_CONTEXT__; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
238 |
__qNew(newString, instsize); /* OBJECT ALLOCATION */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
239 |
__UNPROTECT_CONTEXT__; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
240 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
241 |
if (newString == nil) goto fail; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
242 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
243 |
__InstPtr(newString)->o_class = self; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
244 |
__qSTORE(newString, self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
245 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
246 |
cp = __stringVal(newString); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
247 |
if (nInstVars) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
248 |
OBJ *op; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
249 |
cp += __OBJS2BYTES__(nInstVars); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
250 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
251 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
252 |
* nil-out instvars |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
253 |
*/ |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
254 |
# if defined(memset4) |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
255 |
memset4(__InstPtr(newString)->i_instvars, nil, nInstVars); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
256 |
# else |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
257 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
258 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
259 |
* knowing that nil is 0 |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
260 |
*/ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
261 |
memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars)); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
262 |
# else |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
263 |
op = __InstPtr(newString)->i_instvars; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
264 |
do { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
265 |
*op++ = nil; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
266 |
} while (--nInstVars); |
19748 | 267 |
# endif /* !FAST_MEMSET */ |
357 | 268 |
# endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
269 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
270 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
271 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
272 |
* fill with spaces |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
273 |
*/ |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
274 |
# ifdef FAST_MEMSET |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
275 |
memset(cp, ' ', len); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
276 |
*(cp + len) = '\0'; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
277 |
# else |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
278 |
while (len >= 8) { |
19748 | 279 |
# ifdef INT64 |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
280 |
((INT64 *)cp)[0] = 0x2020202020202020L; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
281 |
# else |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
282 |
((int *)cp)[0] = 0x20202020; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
283 |
((int *)cp)[1] = 0x20202020; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
284 |
# endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
285 |
cp += 8; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
286 |
len -= 8; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
287 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
288 |
while (len--) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
289 |
*cp++ = ' '; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
290 |
*cp = '\0'; |
19748 | 291 |
# endif /* !FAST_MEMSET */ |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
292 |
RETURN (newString); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
293 |
} |
1 | 294 |
} |
95 | 295 |
fail: ;; |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
296 |
#endif /* not __SCHTEAM__ */ |
1019 | 297 |
%}. |
95 | 298 |
" |
299 |
invalid argument, or out-of-memory: |
|
300 |
use error handling in superclass |
|
301 |
" |
|
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
302 |
(anInteger < 0) ifTrue:[ |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
303 |
" |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
304 |
the argument is negative, |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
305 |
" |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
306 |
self error:'bad (negative) argument to new:'. |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
307 |
^ nil |
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
308 |
]. |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
309 |
|
5407 | 310 |
^ (super basicNew:anInteger+1) atAllPut:(Character space) |
1 | 311 |
! |
312 |
||
608 | 313 |
new:n |
20193 | 314 |
"return a new empty string with n characters. |
4802 | 315 |
In contrast to other smalltalks, this returns a string filled |
316 |
with spaces (instead of a string filled with 0-bytes). |
|
317 |
This makes much more sense, in that a freshly created string |
|
20272 | 318 |
can be directly used as separator or for formatting. |
319 |
||
320 |
Redefined here with exactly the same code as in Behavior for |
|
321 |
better performance. " |
|
4802 | 322 |
|
608 | 323 |
^ self basicNew:n |
347 | 324 |
! |
325 |
||
6599
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
326 |
readFrom:aStreamOrString onError:exceptionBlock |
347 | 327 |
"read & return the next String from the (character-)stream aStream; |
328 |
skipping all whitespace first; return the value of exceptionBlock, |
|
8898 | 329 |
if no string can be read. The sequence of characters as read from the |
347 | 330 |
stream must be one as stored via storeOn: or storeString." |
331 |
||
332 |
" |
|
333 |
this method is not to be inherited |
|
334 |
(i.e. not ok for subclasses; Symbol, for example) |
|
335 |
" |
|
336 |
self ~~ String ifTrue:[ |
|
10352 | 337 |
^ super readFrom:aStreamOrString onError:exceptionBlock |
347 | 338 |
]. |
9426 | 339 |
^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
347 | 340 |
|
341 |
" |
|
8898 | 342 |
String readFrom:('''hello world''' readStream) |
343 |
String readFrom:('''hello '''' world''' readStream) |
|
347 | 344 |
String readFrom:('1 ''hello'' ' readStream) |
8898 | 345 |
String readFrom:('1 ''hello'' ' readStream) onError:['foobar'] |
3376 | 346 |
" |
347 |
||
9426 | 348 |
"Modified: / 05-07-2006 / 16:41:29 / cg" |
9473 | 349 |
"Modified: / 07-08-2006 / 15:03:09 / fm" |
608 | 350 |
! |
351 |
||
7684 | 352 |
uninitializedNew:anInteger |
353 |
"return a new string with anInteger characters but undefined contents. |
|
354 |
Use this, if the string is filled anyway with new data, for example, if |
|
355 |
used as a stream buffer." |
|
356 |
||
357 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
358 |
#ifdef __SCHTEAM__ |
18236 | 359 |
return context._RETURN( self.basicNew( anInteger.intValue() )); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
360 |
#else |
7684 | 361 |
OBJ newString; |
362 |
REGISTER int len; |
|
363 |
REGISTER unsigned char *cp; |
|
364 |
REGISTER OBJ *op; |
|
365 |
int nInstVars, instsize; |
|
366 |
||
367 |
if (__isSmallInteger(anInteger)) { |
|
9473 | 368 |
len = __intVal(anInteger); |
369 |
if (len >= 0) { |
|
370 |
instsize = OHDR_SIZE + len + 1; |
|
371 |
if (self == String) { |
|
372 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
|
373 |
/* |
|
374 |
* the most common case |
|
375 |
*/ |
|
376 |
__qCheckedNew(newString, instsize); |
|
377 |
__InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */ |
|
378 |
__qSTORE(newString, self); |
|
379 |
||
380 |
cp = __stringVal(newString); |
|
381 |
cp[len] = '\0'; |
|
382 |
RETURN (newString); |
|
383 |
} |
|
384 |
nInstVars = 0; |
|
385 |
} else { |
|
386 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
|
387 |
instsize += __OBJS2BYTES__(nInstVars); |
|
388 |
} |
|
389 |
||
390 |
__PROTECT_CONTEXT__; |
|
391 |
__qNew(newString, instsize); /* OBJECT ALLOCATION */ |
|
392 |
__UNPROTECT_CONTEXT__; |
|
393 |
||
394 |
if (newString == nil) goto fail; |
|
395 |
||
396 |
__InstPtr(newString)->o_class = self; |
|
397 |
__qSTORE(newString, self); |
|
398 |
||
399 |
if (nInstVars) { |
|
400 |
/* |
|
401 |
* nil-out instvars |
|
402 |
*/ |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
403 |
# if defined(memset4) |
9473 | 404 |
memset4(__InstPtr(newString)->i_instvars, nil, nInstVars); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
405 |
# else |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
406 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
9473 | 407 |
/* |
408 |
* knowing that nil is 0 |
|
409 |
*/ |
|
410 |
memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars)); |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
411 |
# else |
9473 | 412 |
op = __InstPtr(newString)->i_instvars; |
413 |
do { |
|
414 |
*op++ = nil; |
|
415 |
} while (--nInstVars); |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
416 |
# endif |
7684 | 417 |
# endif |
9473 | 418 |
cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars); |
419 |
} else { |
|
420 |
cp = __stringVal(newString); |
|
421 |
} |
|
422 |
||
423 |
*(cp + len) = '\0'; |
|
424 |
RETURN (newString); |
|
425 |
} |
|
7684 | 426 |
} |
427 |
fail: ;; |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
428 |
#endif /* not __SCHTEAM__ */ |
7684 | 429 |
%}. |
430 |
" |
|
431 |
invalid argument, or out-of-memory: |
|
432 |
use error handling in superclass |
|
433 |
" |
|
434 |
(anInteger < 0) ifTrue:[ |
|
9473 | 435 |
" |
436 |
the argument is negative, |
|
437 |
" |
|
438 |
self error:'bad (negative) argument to new:'. |
|
439 |
^ nil |
|
7684 | 440 |
]. |
608 | 441 |
|
442 |
^ self basicNew:anInteger |
|
7684 | 443 |
|
444 |
" |
|
445 |
String uninitializedNew:100 |
|
446 |
" |
|
608 | 447 |
! ! |
448 |
||
8438
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
449 |
!String class methodsFor:'Compatibility-Dolphin'! |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
450 |
|
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
451 |
lineDelimiter |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
452 |
"Dolphin compatibility: answer CR LF" |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
453 |
|
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
454 |
^ self crlf |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
455 |
! ! |
317f70e84d61
Dolphin compatibility method #lineDelimiter
Stefan Vogel <sv@exept.de>
parents:
8415
diff
changeset
|
456 |
|
7302 | 457 |
!String class methodsFor:'Compatibility-Squeak'! |
4981 | 458 |
|
459 |
cr |
|
4994 | 460 |
"return a string consisting of the cr-Character" |
4993 | 461 |
|
19503 | 462 |
"/ ATTENTION: you get a NL (for compatibility) here!! |
463 |
"/ please use String return / String lf |
|
464 |
self halt:'please make it explicit, if a return or a linefeed is wanted.'. |
|
465 |
"/ for now. |
|
466 |
"/ will be changed, when the historic UNIX baggage is removed |
|
467 |
"/ 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
|
468 |
|
19503 | 469 |
^ self lf |
7282 | 470 |
! |
471 |
||
472 |
crlf |
|
473 |
"return a string consisting of the cr-lf Characters" |
|
474 |
||
475 |
CRLF isNil ifTrue:[ |
|
9473 | 476 |
CRLF := String |
477 |
with:Character return |
|
478 |
with:Character linefeed |
|
7282 | 479 |
]. |
480 |
^ CRLF |
|
481 |
! |
|
482 |
||
483 |
lf |
|
484 |
"return a string consisting of the lf Character" |
|
485 |
||
486 |
LF isNil ifTrue:[ |
|
9473 | 487 |
LF := String with:Character linefeed |
7282 | 488 |
]. |
489 |
^ LF |
|
11856 | 490 |
! |
491 |
||
19503 | 492 |
return |
493 |
"return a string consisting of the cr-Character" |
|
494 |
||
495 |
CR isNil ifTrue:[ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
496 |
CR := String with:Character return |
19503 | 497 |
]. |
498 |
^ CR |
|
499 |
! |
|
500 |
||
12344
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
501 |
stringHash:aString initialHash:speciesHash |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
502 |
"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
|
503 |
|
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
504 |
| stringSize hash low | |
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 := aString size. |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
507 |
hash := speciesHash bitAnd: 16rFFFFFFF. |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
508 |
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
|
509 |
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
|
510 |
"Begin hashMultiply" |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
511 |
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
|
512 |
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
|
513 |
]. |
a4cf954bb1e1
added: #stringHash:initialHash:
Claus Gittinger <cg@exept.de>
parents:
12184
diff
changeset
|
514 |
^ hash. |
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 |
|
11856 | 517 |
tab |
518 |
"return a string consisting of the tab-Character" |
|
519 |
||
14330 | 520 |
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
|
521 |
TAB := String with:Character tab |
14330 | 522 |
]. |
523 |
^ TAB |
|
4981 | 524 |
! ! |
525 |
||
13182 | 526 |
|
19790 | 527 |
|
20126 | 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 |
|
19790 | 549 |
|
550 |
||
551 |
||
9182 | 552 |
|
1 | 553 |
!String methodsFor:'accessing'! |
554 |
||
329 | 555 |
at:index |
556 |
"return the character at position index, an Integer. |
|
345 | 557 |
Reimplemented here to avoid the additional at:->basicAt: send |
558 |
(which we can do here, since at: is obviously not redefined in a subclass). |
|
329 | 559 |
This method is the same as at:." |
560 |
||
561 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
562 |
#ifdef __SCHTEAM__ |
18236 | 563 |
if (index.isSmallInteger()) { |
18215 | 564 |
int idx1Based = context.stArg(0).intValue(); // st index is 1 based |
18404 | 565 |
return context._RETURN( self.basicAt( idx1Based )); |
18215 | 566 |
} |
567 |
#else |
|
329 | 568 |
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
|
569 |
REGISTER OBJ slf, cls; |
329 | 570 |
|
571 |
if (__isSmallInteger(index)) { |
|
9473 | 572 |
slf = self; |
573 |
cls = __qClass(slf); |
|
574 |
indx = __intVal(index) - 1; |
|
575 |
if (cls != String) { |
|
576 |
if (indx < 0) goto badIndex; |
|
577 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
578 |
} |
|
579 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
580 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
|
581 |
} |
|
329 | 582 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
583 |
badIndex: ; |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
584 |
#endif /* ! __SCHTEAM__ */ |
329 | 585 |
%}. |
5407 | 586 |
^ self basicAt:index |
1 | 587 |
! |
588 |
||
329 | 589 |
at:index put:aCharacter |
590 |
"store the argument, aCharacter at position index, an Integer. |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
591 |
Return aCharacter (sigh). |
345 | 592 |
Reimplemented here to avoid the additional at:put:->basicAt:put: send |
593 |
(but only for Strings, since subclasses may redefine basicAt:put:). |
|
329 | 594 |
This method is the same as basicAt:put:." |
595 |
||
596 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
597 |
#ifdef __SCHTEAM__ |
18236 | 598 |
if (index.isSmallInteger()) { |
599 |
int idx1Based = index.intValue(); // st index is 1 based |
|
600 |
||
18286 | 601 |
self.basicAt_put(idx1Based, aCharacter ); |
18404 | 602 |
return context._RETURN( aCharacter ); |
18215 | 603 |
} |
604 |
#else |
|
329 | 605 |
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
|
606 |
REGISTER OBJ slf; |
329 | 607 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
608 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
609 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
610 |
if (__isString(slf)) { |
9473 | 611 |
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
|
612 |
value = __intVal(__characterVal(aCharacter)); |
9473 | 613 |
if (((unsigned)value <= 0xFF) |
614 |
&& __isSmallInteger(index)) { |
|
615 |
indx = __intVal(index) - 1; |
|
616 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
617 |
__stringVal(slf)[indx] = value; |
|
618 |
RETURN ( aCharacter ); |
|
619 |
} |
|
620 |
} |
|
621 |
} |
|
329 | 622 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
623 |
#endif /* ! __SCHTEAM__ */ |
329 | 624 |
%}. |
5407 | 625 |
^ self basicAt:index put:aCharacter |
329 | 626 |
! |
627 |
||
608 | 628 |
basicAt:index |
629 |
"return the character at position index, an Integer |
|
630 |
- reimplemented here since we return characters" |
|
631 |
||
632 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
633 |
#ifdef __SCHTEAM__ |
18236 | 634 |
if (index.isSmallInteger()) { |
635 |
int idx1Based = index.intValue(); // st index is 1 based |
|
18404 | 636 |
return context._RETURN( self.basicAt( idx1Based )); |
18215 | 637 |
} |
638 |
#else |
|
608 | 639 |
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
|
640 |
REGISTER OBJ slf, cls; |
608 | 641 |
|
642 |
if (__isSmallInteger(index)) { |
|
9473 | 643 |
slf = self; |
644 |
cls = __qClass(slf); |
|
645 |
indx = __intVal(index) - 1; |
|
646 |
if (cls != String) { |
|
647 |
if (indx < 0) goto badIndex; |
|
648 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
649 |
} |
|
650 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
651 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
|
652 |
} |
|
608 | 653 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
654 |
badIndex: ; |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
655 |
#endif /* not __SCHTEAM__ */ |
608 | 656 |
%}. |
3451 | 657 |
index isInteger ifFalse:[ |
9473 | 658 |
^ self indexNotInteger:index |
3451 | 659 |
]. |
5407 | 660 |
index == super basicSize ifTrue:[ |
9473 | 661 |
^ self subscriptBoundsError:index |
5407 | 662 |
]. |
663 |
^ Character value:(super basicAt:index) |
|
608 | 664 |
! |
665 |
||
1 | 666 |
basicAt:index put:aCharacter |
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
667 |
"store the argument, aCharacter at position index, an Integer. |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
668 |
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
|
669 |
- reimplemented here since we store characters" |
1 | 670 |
|
671 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
672 |
#ifdef __SCHTEAM__ |
18236 | 673 |
if (index.isSmallInteger()) { |
674 |
int idx1Based = index.intValue(); // st index is 1 based |
|
675 |
||
18286 | 676 |
self.basicAt_put(idx1Based, aCharacter ); |
18404 | 677 |
return context._RETURN( aCharacter ); |
18215 | 678 |
} |
679 |
#else |
|
1 | 680 |
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
|
681 |
REGISTER OBJ slf; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
682 |
REGISTER OBJ cls; |
1 | 683 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
684 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
685 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
686 |
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
|
687 |
value = __intVal(__characterVal(aCharacter)); |
9473 | 688 |
if (((unsigned)value <= 0xFF) |
689 |
&& __isSmallInteger(index)) { |
|
690 |
cls = __qClass(slf); |
|
691 |
indx = __intVal(index) - 1; |
|
692 |
if (cls != String) { |
|
693 |
if (indx < 0) goto badIndex; |
|
694 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
695 |
} |
|
696 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
697 |
__stringVal(slf)[indx] = value; |
|
698 |
RETURN ( aCharacter ); |
|
699 |
} |
|
700 |
} |
|
1 | 701 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
702 |
badIndex: ; |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
703 |
#endif /* not __SCHTEAM__ */ |
159 | 704 |
%}. |
1 | 705 |
(aCharacter isMemberOf:Character) ifFalse:[ |
9473 | 706 |
" |
707 |
tried to store something which is not a character |
|
708 |
" |
|
709 |
^ self elementNotCharacter |
|
299 | 710 |
]. |
8093
8ca1e24688d8
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
711 |
(aCharacter codePoint between:1 and:255) ifFalse:[ |
9473 | 712 |
" |
713 |
tried to store a multibyte character |
|
714 |
" |
|
715 |
^ self elementBoundsError:aCharacter |
|
299 | 716 |
]. |
717 |
" |
|
718 |
invalid index |
|
719 |
" |
|
3451 | 720 |
index isInteger ifFalse:[ |
9473 | 721 |
^ self indexNotInteger:index |
3451 | 722 |
]. |
5407 | 723 |
index == super basicSize ifTrue:[ |
9473 | 724 |
^ self subscriptBoundsError:index |
5407 | 725 |
]. |
8093
8ca1e24688d8
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
726 |
super basicAt:index put:aCharacter codePoint. |
8898 | 727 |
^ aCharacter |
12716 | 728 |
! |
729 |
||
730 |
first |
|
731 |
"return the first character. |
|
732 |
Reimplemented here for speed" |
|
733 |
||
734 |
%{ /* NOCONTEXT */ |
|
735 |
||
736 |
REGISTER int indx; |
|
737 |
REGISTER OBJ slf, cls; |
|
738 |
||
739 |
slf = self; |
|
740 |
cls = __qClass(slf); |
|
741 |
indx = 0; |
|
742 |
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
|
743 |
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
|
744 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
12716 | 745 |
} |
746 |
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
|
747 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
12716 | 748 |
} |
749 |
badIndex: ; |
|
750 |
%}. |
|
751 |
^ super first |
|
752 |
||
753 |
" |
|
754 |
'abc' first |
|
755 |
'' first |
|
756 |
" |
|
2 | 757 |
! ! |
758 |
||
13182 | 759 |
|
53 | 760 |
!String methodsFor:'character searching'! |
1 | 761 |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
762 |
identityIndexOf:aCharacter |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
763 |
"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
|
764 |
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
|
765 |
|
19744 | 766 |
^ self indexOf:aCharacter startingAt:1. |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
767 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
768 |
" |
8898 | 769 |
'hello world' identityIndexOf:(Character space) |
770 |
'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
|
771 |
'hello world' identityIndexOf:1 |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
772 |
#[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
|
773 |
#[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
|
774 |
" |
13920 | 775 |
|
776 |
"Modified: / 10-01-2012 / 17:07:12 / cg" |
|
1 | 777 |
! |
778 |
||
13923
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
779 |
identityIndexOf:aCharacter startingAt:index |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
780 |
"return the index of the first occurrences of the argument, aCharacter |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
781 |
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
|
782 |
|
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
783 |
^ self indexOf:aCharacter startingAt:index |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
784 |
|
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 |
'hello world' identityIndexOf:(Character space) |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
787 |
'hello world' identityIndexOf:$d |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
788 |
'hello world' identityIndexOf:1 |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
789 |
#[0 0 1 0 0] asString identityIndexOf:(Character value:1) |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
790 |
#[0 0 1 0 0] asString identityIndexOf:(Character value:0) |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
791 |
" |
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 |
"Created: / 10-01-2012 / 17:10:54 / cg" |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
794 |
! |
d5c7ee3d3d6a
added: #identityIndexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13922
diff
changeset
|
795 |
|
10 | 796 |
includesAny:aCollection |
797 |
"return true, if the receiver includes any of the characters in the |
|
53 | 798 |
argument, aCollection. |
17573 | 799 |
- redefined for speed if the argument is a String; especially optimized, |
800 |
if the searched collection has less than 6 characters." |
|
10 | 801 |
|
802 |
%{ /* NOCONTEXT */ |
|
803 |
||
804 |
REGISTER unsigned char *cp; |
|
805 |
REGISTER unsigned char *matchP; |
|
53 | 806 |
OBJ cls; |
19748 | 807 |
int index, last; |
10 | 808 |
|
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
809 |
if (__isStringLike(aCollection)) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
810 |
matchP = __stringVal(aCollection); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
811 |
last = __stringSize(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
812 |
cp = __stringVal(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
813 |
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
|
814 |
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
|
815 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
816 |
cp += numInstBytes; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
817 |
last -= numInstBytes; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
818 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
819 |
index = 0; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
820 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
821 |
switch (__stringSize(aCollection)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
822 |
case 5: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
823 |
/* five character search */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
824 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
825 |
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
|
826 |
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
|
827 |
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
|
828 |
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
|
829 |
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
|
830 |
unsigned char ch; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
831 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
832 |
while (index < last) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
833 |
ch = cp[index]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
834 |
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
|
835 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
836 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
837 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
838 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
839 |
RETURN (false); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
840 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
841 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
842 |
case 4: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
843 |
/* four character search */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
844 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
845 |
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
|
846 |
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
|
847 |
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
|
848 |
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
|
849 |
unsigned char ch; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
850 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
851 |
while (index < last) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
852 |
ch = cp[index]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
853 |
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
|
854 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
855 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
856 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
857 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
858 |
RETURN (false); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
859 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
860 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
861 |
case 3: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
862 |
/* three character search */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
863 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
864 |
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
|
865 |
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
|
866 |
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
|
867 |
unsigned char ch; |
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 |
while (index < last) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
870 |
ch = cp[index]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
871 |
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
|
872 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
873 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
874 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
875 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
876 |
RETURN (false); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
877 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
878 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
879 |
case 2: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
880 |
/* two character search */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
881 |
{ |
19748 | 882 |
#if 0 |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
883 |
// 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
|
884 |
if (last < 2000) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
885 |
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
|
886 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
887 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
888 |
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
|
889 |
RETURN ( true ); |
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 |
} |
19748 | 892 |
#endif |
893 |
||
894 |
#if 1 |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
895 |
// this is 30 %faster ! |
19748 | 896 |
# define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL) |
897 |
# define hasByteM(v,m) hasZeroByte( (v) ^ m) |
|
898 |
||
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
899 |
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
|
900 |
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
|
901 |
int last4 = last-4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
902 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
903 |
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
|
904 |
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
|
905 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
906 |
while (index < last4) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
907 |
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
|
908 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
909 |
if (hasByteM(v,m1)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
910 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
911 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
912 |
if (hasByteM(v,m2)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
913 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
914 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
915 |
index += 4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
916 |
} |
19748 | 917 |
|
918 |
# undef hasZeroByte |
|
919 |
# undef hasByteM |
|
920 |
#else |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
921 |
while (index < last4) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
922 |
unsigned char ch; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
923 |
int any; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
924 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
925 |
ch = cp[index]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
926 |
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
|
927 |
ch = cp[index+1]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
928 |
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
|
929 |
ch = cp[index+2]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
930 |
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
|
931 |
ch = cp[index+3]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
932 |
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
|
933 |
if (any) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
934 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
935 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
936 |
index += 4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
937 |
} |
19748 | 938 |
#endif |
939 |
||
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
940 |
while (index < last) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
941 |
unsigned char ch; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
942 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
943 |
ch = cp[index]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
944 |
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
|
945 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
946 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
947 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
948 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
949 |
RETURN (false); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
950 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
951 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
952 |
case 1: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
953 |
/* single character search */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
954 |
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
|
955 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
956 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
957 |
RETURN ( false ); |
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 |
case 0: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
960 |
RETURN ( false ); |
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 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
963 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
964 |
unsigned char ch; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
965 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
966 |
while (index < last) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
967 |
ch = cp[index]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
968 |
if (strchr(matchP, ch)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
969 |
RETURN ( true ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
970 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
971 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
972 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
973 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
974 |
RETURN ( false ); |
10 | 975 |
} |
5407 | 976 |
%}. |
10 | 977 |
^ super includesAny:aCollection |
95 | 978 |
|
979 |
" |
|
8898 | 980 |
'hello world' includesAny:'abcd' |
981 |
'hello world' includesAny:'xyz' |
|
982 |
'hello world' includesAny:'xz' |
|
983 |
'hello world' includesAny:'od' |
|
984 |
'hello world' includesAny:'xd' |
|
985 |
'hello world' includesAny:'dx' |
|
986 |
'hello world' includesAny:(Array with:$a with:$b with:$d) |
|
987 |
'hello world' includesAny:(Array with:$x with:$y) |
|
988 |
'hello world' includesAny:(Array with:1 with:2) |
|
19748 | 989 |
|
990 |
|s| |
|
991 |
s := String new:1000 withAll:$a. |
|
992 |
Time millisecondsToRun:[ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
993 |
1000000 timesRepeat:[ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
994 |
s includesAny:'12' |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
995 |
] |
19748 | 996 |
].540 680 550 850 890 850 |
997 |
||
998 |
|s| |
|
999 |
s := String new:2000 withAll:$a. |
|
1000 |
Time millisecondsToRun:[ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1001 |
1000000 timesRepeat:[ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1002 |
s includesAny:'12' |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1003 |
] |
19748 | 1004 |
]. 1030 1060 1650 1690 |
1005 |
||
1006 |
|s| |
|
1007 |
s := 'hello world'. |
|
1008 |
Time millisecondsToRun:[ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1009 |
1000000 timesRepeat:[ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1010 |
s includesAny:'12' |
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 |
].70 60 |
95 | 1013 |
" |
10 | 1014 |
! |
1015 |
||
1 | 1016 |
indexOf:aCharacter startingAt:start |
1017 |
"return the index of the first occurrence of the argument, aCharacter |
|
1018 |
in myself starting at start, anInteger or 0 if not found; |
|
1019 |
- reimplemented here for speed" |
|
1020 |
||
1021 |
%{ /* NOCONTEXT */ |
|
18306 | 1022 |
#ifdef __SCHTEAM__ |
1023 |
if (start.isSmallInteger() |
|
1024 |
&& aCharacter.isSTCharacter()) { |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1025 |
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
|
1026 |
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
|
1027 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1028 |
return context._RETURN( jIdx+1 ); // st index is 1 based |
18306 | 1029 |
} |
1030 |
||
1031 |
#else |
|
19772
9dad3602ce7d
ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents:
19759
diff
changeset
|
1032 |
|
19745 | 1033 |
# if defined(__BORLANDC__) || defined(__VISUALC__) |
1034 |
# undef __UNROLL_LOOPS__ |
|
1035 |
# undef FAST_MEMCHR |
|
1036 |
# define V2 |
|
1037 |
# endif |
|
13920 | 1038 |
|
1 | 1039 |
REGISTER unsigned char *cp; |
8913 | 1040 |
REGISTER INT index; |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1041 |
REGISTER unsigned byteValue; |
8924 | 1042 |
int last; |
53 | 1043 |
OBJ cls; |
1 | 1044 |
|
252 | 1045 |
if (__isSmallInteger(start)) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1046 |
index = __intVal(start); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1047 |
if (index > 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1048 |
if (__isCharacter(aCharacter)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1049 |
byteValue = __intVal(__characterVal(aCharacter)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1050 |
if (byteValue <= 0xFF) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1051 |
last = __stringSize(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1052 |
cp = __stringVal(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1053 |
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
|
1054 |
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
|
1055 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1056 |
cp += numInstBytes; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1057 |
last -= numInstBytes; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1058 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1059 |
if (index <= last) { |
18306 | 1060 |
# ifdef FAST_MEMCHR |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1061 |
REGISTER unsigned char *ncp; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1062 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1063 |
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
|
1064 |
if (ncp) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1065 |
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
|
1066 |
} |
18306 | 1067 |
# else |
19772
9dad3602ce7d
ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents:
19759
diff
changeset
|
1068 |
|
18306 | 1069 |
# ifdef V2 |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1070 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1071 |
// see bit twiddling hacks |
13920 | 1072 |
# define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL) |
1073 |
# define hasByteM(v,m) hasZeroByte( (v) ^ m) |
|
18909 | 1074 |
# if __POINTER_SIZE__ == 8 |
1075 |
# define hasZeroByte8(v) (((v) - 0x0101010101010101ULL) & ~(v) & 0x8080808080808080ULL) |
|
1076 |
# 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
|
1077 |
// 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
|
1078 |
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
|
1079 |
int last8 = last-8; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1080 |
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
|
1081 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1082 |
while (index <= last8) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1083 |
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
|
1084 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1085 |
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
|
1086 |
index += 8; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1087 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1088 |
} |
18909 | 1089 |
# endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1090 |
// 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
|
1091 |
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
|
1092 |
int last4 = last-4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1093 |
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
|
1094 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1095 |
while (index <= last4) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1096 |
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
|
1097 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1098 |
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
|
1099 |
index += 4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1100 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1101 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1102 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1103 |
# else |
19772
9dad3602ce7d
ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents:
19759
diff
changeset
|
1104 |
|
9dad3602ce7d
ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents:
19759
diff
changeset
|
1105 |
# ifdef __UNROLL_LOOPS__ |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1106 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1107 |
int last4 = last-4; |
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 |
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
|
1110 |
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
|
1111 |
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
|
1112 |
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
|
1113 |
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
|
1114 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1115 |
} |
19772
9dad3602ce7d
ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents:
19759
diff
changeset
|
1116 |
# endif |
9dad3602ce7d
ouch - indexOf:startingAt: code broken for non-optimized bit-hack search (UNROLL)
mawalch
parents:
19759
diff
changeset
|
1117 |
# endif /* V2 */ |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1118 |
while (index <= last) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1119 |
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
|
1120 |
RETURN ( __mkSmallInteger(index) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1121 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1122 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1123 |
} |
13920 | 1124 |
# endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1125 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1126 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1127 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1128 |
RETURN ( __mkSmallInteger(0) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1129 |
} |
1 | 1130 |
} |
18306 | 1131 |
# undef V2 |
1132 |
#endif /* not SCHTEAM */ |
|
370 | 1133 |
%}. |
1 | 1134 |
^ super indexOf:aCharacter startingAt:start |
53 | 1135 |
|
95 | 1136 |
" |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1137 |
'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
|
1138 |
'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
|
1139 |
'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
|
1140 |
'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
|
1141 |
#[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
|
1142 |
#[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3 |
13920 | 1143 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1144 |
'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
|
1145 |
'1234567890123456a' indexOf:$b |
13920 | 1146 |
|
1147 |
|s| |
|
1148 |
s := '12345678901234b'. |
|
1149 |
self assert:(s indexOf:$x) == 0. |
|
1150 |
self assert:(s indexOf:$1) == 1. |
|
1151 |
self assert:(s indexOf:$2) == 2. |
|
1152 |
self assert:(s indexOf:$3) == 3. |
|
1153 |
self assert:(s indexOf:$4) == 4. |
|
1154 |
self assert:(s indexOf:$5) == 5. |
|
1155 |
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
|
1156 |
self assert:(s indexOf:$b) == 15. |
13920 | 1157 |
|
1158 |
|s| |
|
1159 |
s := ''. |
|
1160 |
self assert:(s indexOf:$1) == 0. |
|
1161 |
s := '1'. |
|
1162 |
self assert:(s indexOf:$1) == 1. |
|
1163 |
self assert:(s indexOf:$2) == 0. |
|
1164 |
s := '12'. |
|
1165 |
self assert:(s indexOf:$1) == 1. |
|
1166 |
self assert:(s indexOf:$2) == 2. |
|
1167 |
self assert:(s indexOf:$3) == 0. |
|
1168 |
s := '123'. |
|
1169 |
self assert:(s indexOf:$1) == 1. |
|
1170 |
self assert:(s indexOf:$2) == 2. |
|
1171 |
self assert:(s indexOf:$3) == 3. |
|
1172 |
self assert:(s indexOf:$4) == 0. |
|
1173 |
s := '1234'. |
|
1174 |
self assert:(s indexOf:$1) == 1. |
|
1175 |
self assert:(s indexOf:$2) == 2. |
|
1176 |
self assert:(s indexOf:$3) == 3. |
|
1177 |
self assert:(s indexOf:$4) == 4. |
|
1178 |
self assert:(s indexOf:$5) == 0. |
|
1179 |
s := '12345'. |
|
1180 |
self assert:(s indexOf:$1) == 1. |
|
1181 |
self assert:(s indexOf:$2) == 2. |
|
1182 |
self assert:(s indexOf:$3) == 3. |
|
1183 |
self assert:(s indexOf:$4) == 4. |
|
1184 |
self assert:(s indexOf:$5) == 5. |
|
1185 |
self assert:(s indexOf:$6) == 0. |
|
1186 |
s := '123456'. |
|
1187 |
self assert:(s indexOf:$1) == 1. |
|
1188 |
self assert:(s indexOf:$2) == 2. |
|
1189 |
self assert:(s indexOf:$3) == 3. |
|
1190 |
self assert:(s indexOf:$4) == 4. |
|
1191 |
self assert:(s indexOf:$5) == 5. |
|
1192 |
self assert:(s indexOf:$6) == 6. |
|
1193 |
self assert:(s indexOf:$7) == 0. |
|
1194 |
s := '1234567'. |
|
1195 |
self assert:(s indexOf:$1) == 1. |
|
1196 |
self assert:(s indexOf:$2) == 2. |
|
1197 |
self assert:(s indexOf:$3) == 3. |
|
1198 |
self assert:(s indexOf:$4) == 4. |
|
1199 |
self assert:(s indexOf:$5) == 5. |
|
1200 |
self assert:(s indexOf:$6) == 6. |
|
1201 |
self assert:(s indexOf:$7) == 7. |
|
1202 |
self assert:(s indexOf:$8) == 0. |
|
1203 |
s := '12345678'. |
|
1204 |
self assert:(s indexOf:$1) == 1. |
|
1205 |
self assert:(s indexOf:$2) == 2. |
|
1206 |
self assert:(s indexOf:$3) == 3. |
|
1207 |
self assert:(s indexOf:$4) == 4. |
|
1208 |
self assert:(s indexOf:$5) == 5. |
|
1209 |
self assert:(s indexOf:$6) == 6. |
|
1210 |
self assert:(s indexOf:$7) == 7. |
|
1211 |
self assert:(s indexOf:$8) == 8. |
|
1212 |
self assert:(s indexOf:$9) == 0. |
|
1213 |
s := '123456789'. |
|
1214 |
self assert:(s indexOf:$1) == 1. |
|
1215 |
self assert:(s indexOf:$2) == 2. |
|
1216 |
self assert:(s indexOf:$3) == 3. |
|
1217 |
self assert:(s indexOf:$4) == 4. |
|
1218 |
self assert:(s indexOf:$5) == 5. |
|
1219 |
self assert:(s indexOf:$6) == 6. |
|
1220 |
self assert:(s indexOf:$7) == 7. |
|
1221 |
self assert:(s indexOf:$8) == 8. |
|
1222 |
self assert:(s indexOf:$9) == 9. |
|
1223 |
||
1224 |
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
|
1225 |
self assert:(s indexOf:$b) == 0. |
13920 | 1226 |
|
1227 |
|s| |
|
1228 |
s := String new:1024. |
|
1229 |
s atAllPut:$a. |
|
1230 |
s at:512 put:(Character space). |
|
1231 |
Time millisecondsToRun:[ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1232 |
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
|
1233 |
] |
13920 | 1234 |
|
1235 |
timing (ms): |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1236 |
bcc OSX(2007 powerbook) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1237 |
v1: 1763 normal |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1238 |
2340 +unroll |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1239 |
3308 memsrch !! 90 |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1240 |
v2: 1045 150 |
95 | 1241 |
" |
13920 | 1242 |
|
13922
b693795611ea
changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
13921
diff
changeset
|
1243 |
"Modified: / 10-01-2012 / 17:09:34 / cg" |
1 | 1244 |
! |
1245 |
||
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1246 |
indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1247 |
"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
|
1248 |
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
|
1249 |
- 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
|
1250 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1251 |
%{ /* NOCONTEXT */ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1252 |
|
13116
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1253 |
unsigned char *ccp; |
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1254 |
unsigned char *cp; |
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1255 |
INT index; |
2894 | 1256 |
unsigned char *matchP; |
8006 | 1257 |
unsigned char c, min, max; |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1258 |
int len; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1259 |
OBJ cls; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1260 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1261 |
if (__isSmallInteger(start) |
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
1262 |
&& __isStringLike(aCollectionOfCharacters)) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1263 |
matchP = __stringVal(aCollectionOfCharacters); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1264 |
index = __intVal(start); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1265 |
if (index > 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1266 |
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
|
1267 |
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
|
1268 |
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
|
1269 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1270 |
len = __stringSize(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1271 |
if (index <= len) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1272 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1273 |
if (matchP[0] == 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1274 |
/* matchSet is empty */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1275 |
RETURN ( __mkSmallInteger(0) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1276 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1277 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1278 |
if (matchP[1] == 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1279 |
/* 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
|
1280 |
unsigned char m = matchP[0]; |
13116
467e182438ff
changed: #indexOfAny:startingAt:
Stefan Vogel <sv@exept.de>
parents:
12763
diff
changeset
|
1281 |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1282 |
# ifdef FAST_MEMCHR |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1283 |
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
|
1284 |
if (ccp) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1285 |
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
|
1286 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1287 |
# else |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1288 |
while ((c = *cp++) != '\0') { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1289 |
if (c == m) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1290 |
RETURN ( __mkSmallInteger(index) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1291 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1292 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1293 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1294 |
# endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1295 |
RETURN ( __mkSmallInteger(0) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1296 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1297 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1298 |
if (matchP[2] == 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1299 |
/* two character matches */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1300 |
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
|
1301 |
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
|
1302 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1303 |
while ((c = *cp++) != '\0') { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1304 |
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
|
1305 |
RETURN ( __mkSmallInteger(index) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1306 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1307 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1308 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1309 |
RETURN ( __mkSmallInteger(0) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1310 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1311 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1312 |
min = max = matchP[0]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1313 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1314 |
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
|
1315 |
unsigned char c = *ccp; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1316 |
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
|
1317 |
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
|
1318 |
} |
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 |
while ((c = *cp++) != '\0') { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1321 |
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
|
1322 |
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
|
1323 |
if (*ccp == c) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1324 |
RETURN ( __mkSmallInteger(index) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1325 |
} |
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 |
index++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1329 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1330 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1331 |
RETURN ( __mkSmallInteger(0) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1332 |
} |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1333 |
} |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1334 |
%}. |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1335 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1336 |
"/ 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
|
1337 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1338 |
^ super indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1339 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1340 |
" |
8898 | 1341 |
'hello world' indexOfAny:'eoa' startingAt:1 |
1342 |
'hello world' indexOfAny:'eoa' startingAt:6 |
|
1343 |
'hello world' indexOfAny:'AOE' startingAt:1 |
|
1344 |
'hello world' indexOfAny:'o' startingAt:6 |
|
1345 |
'hello world' indexOfAny:'o' startingAt:6 |
|
19839 | 1346 |
'hello world§' indexOfAny:'#§$' startingAt:6 |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1347 |
" |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1348 |
! |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1349 |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1350 |
indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1351 |
"return the index of the next control character; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1352 |
that is a character with asciiValue < 32. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1353 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1354 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1355 |
%{ /* NOCONTEXT */ |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1356 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1357 |
REGISTER unsigned char *cp; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1358 |
REGISTER unsigned char c; |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
1359 |
REGISTER unsigned char *cpEnd; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1360 |
int len, index; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1361 |
OBJ cls; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1362 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1363 |
index = __intVal(start); |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1364 |
if (index <= 0) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1365 |
index = 1; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1366 |
} |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1367 |
len = __stringSize(self); |
15044 | 1368 |
cp = __stringVal(self); |
1369 |
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
|
1370 |
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
|
1371 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1372 |
cp += numInstBytes; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1373 |
len -= numInstBytes; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1374 |
} |
15044 | 1375 |
while (index <= len) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1376 |
REGISTER unsigned char c; |
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 |
c = cp[index - 1]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1379 |
if (c < ' ') { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1380 |
RETURN ( __mkSmallInteger(index) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1381 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1382 |
index++; |
15044 | 1383 |
} |
1384 |
RETURN ( __mkSmallInteger(0) ); |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1385 |
%}. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1386 |
^ super indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1387 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1388 |
" |
8898 | 1389 |
'hello world' indexOfControlCharacterStartingAt:1 |
1390 |
'hello world\foo' withCRs indexOfControlCharacterStartingAt:1 |
|
1391 |
'1\' withCRs indexOfControlCharacterStartingAt:1 |
|
1392 |
'1\' withCRs indexOfControlCharacterStartingAt:2 |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1393 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1394 |
! |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1395 |
|
3403 | 1396 |
indexOfNonSeparatorStartingAt:start |
1397 |
"return the index of the next non-whiteSpace character" |
|
1398 |
||
1399 |
%{ /* NOCONTEXT */ |
|
1400 |
||
1401 |
REGISTER unsigned char *cp; |
|
1402 |
REGISTER unsigned char c; |
|
1403 |
int len, index; |
|
1404 |
OBJ cls; |
|
1405 |
||
1406 |
index = __intVal(start); |
|
1407 |
if (index <= 0) { |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1408 |
index = 1; |
3403 | 1409 |
} |
1410 |
len = __stringSize(self); |
|
15044 | 1411 |
cp = __stringVal(self); |
1412 |
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
|
1413 |
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
|
1414 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1415 |
cp += numInstBytes; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1416 |
len -= numInstBytes; |
3403 | 1417 |
} |
15044 | 1418 |
while (index <= len) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1419 |
REGISTER unsigned char c; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1420 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1421 |
c = cp[index - 1]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1422 |
if (c > ' ') { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1423 |
if ((c != ' ') && (c != '\t') && (c != '\n') |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1424 |
&& (c != '\r') && (c != '\f')) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1425 |
RETURN ( __mkSmallInteger(index) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1426 |
} |
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 |
index++; |
3403 | 1429 |
} |
8913 | 1430 |
RETURN ( __mkSmallInteger(0) ); |
3403 | 1431 |
%}. |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1432 |
^ super indexOfNonSeparatorStartingAt:start |
3403 | 1433 |
|
1434 |
" |
|
8898 | 1435 |
'hello world' indexOfNonWhiteSpaceStartingAt:3 |
1436 |
'hello world' indexOfNonWhiteSpaceStartingAt:7 |
|
3403 | 1437 |
" |
1438 |
! |
|
1439 |
||
1 | 1440 |
indexOfSeparatorStartingAt:start |
1441 |
"return the index of the next separator character" |
|
1442 |
||
1443 |
%{ /* NOCONTEXT */ |
|
1444 |
||
19748 | 1445 |
if (__isSmallInteger(start)) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1446 |
REGISTER unsigned char *cp; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1447 |
int len, index; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1448 |
OBJ cls; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1449 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1450 |
index = __intVal(start)-1; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1451 |
// is this a good idea? |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1452 |
if (index < 0) { |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1453 |
index = 0; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1454 |
} |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1455 |
len = __stringSize(self); |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1456 |
cp = __stringVal(self); |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1457 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1458 |
// care for subclasses of string |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1459 |
if ((cls = __qClass(self)) != String) { |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1460 |
int numInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1461 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1462 |
cp += numInstBytes; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1463 |
len -= numInstBytes; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1464 |
} |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1465 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1466 |
// these pre-loops do fast skip over non-separators |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1467 |
// (anything above 0x32) |
19748 | 1468 |
#if __POINTER_SIZE__ == 8 |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1469 |
if ((index & 7) == 0) { |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1470 |
int len8 = len-8; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1471 |
while (index < len8) { |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1472 |
REGISTER unsigned INT eightChars; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1473 |
REGISTER unsigned INT eightCharsMasked; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1474 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1475 |
eightChars = ((unsigned INT *)(cp+index))[0]; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1476 |
eightCharsMasked = eightChars & 0xE0E0E0E0E0E0E0E0ULL; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1477 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1478 |
// any control char? |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1479 |
// (these are 0..31 and also the space); |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1480 |
// so we need two compares. |
19748 | 1481 |
# define hasZeroByte(v) (((v) - 0x0101010101010101ULL) & ~(v) & 0x8080808080808080ULL) |
1482 |
# define hasByteM(v,m) hasZeroByte( (v) ^ m) |
|
19790 | 1483 |
# define maskSpace (~0ULL/255 * (32)) |
1484 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1485 |
if (hasByteM(eightChars, maskSpace)) break; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1486 |
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
|
1487 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1488 |
# undef hasZeroByte |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1489 |
# undef hasByteM |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1490 |
# undef maskSpace |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1491 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1492 |
index += 8; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1493 |
} |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1494 |
} |
19748 | 1495 |
#endif /* POINTER_SIZE == 8*/ |
1496 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1497 |
if ((index & 3) == 0) { |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1498 |
int len4 = len-4; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1499 |
while (index < len4) { |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1500 |
REGISTER unsigned int fourChars; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1501 |
REGISTER unsigned int fourCharsMasked; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1502 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1503 |
fourChars = ((unsigned int *)(cp+index))[0]; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1504 |
fourCharsMasked = fourChars & 0xE0E0E0E0UL; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1505 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1506 |
// any control char? |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1507 |
// (these are 0..31 and also the space); |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1508 |
// so we need two compares. |
19748 | 1509 |
# define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL) |
1510 |
# define hasByteM(v,m) hasZeroByte( (v) ^ m) |
|
1511 |
# define maskSpace (~0UL/255 * (32)) |
|
1512 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1513 |
if (hasByteM(fourChars, maskSpace)) break; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1514 |
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
|
1515 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1516 |
# undef hasZeroByte |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1517 |
# undef hasByteM |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1518 |
# undef maskSpace |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1519 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1520 |
index += 4; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1521 |
} |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1522 |
} |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1523 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1524 |
while (index < len) { |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1525 |
REGISTER unsigned char c; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1526 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1527 |
c = cp[index]; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1528 |
if (c <= ' ') { |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1529 |
if ((c == ' ') || (c == '\t') || (c == '\n') |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1530 |
|| (c == '\r') || (c == '\f')) { |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1531 |
RETURN ( __mkSmallInteger(index+1) ); |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1532 |
} |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1533 |
} |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1534 |
index++; |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1535 |
} |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1536 |
RETURN ( __mkSmallInteger(0) ); |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1537 |
} |
5407 | 1538 |
%}. |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1539 |
^ super indexOfSeparatorStartingAt:start |
53 | 1540 |
|
19748 | 1541 |
" 123456789012 |
1542 |
'hello world ' indexOfSeparatorStartingAt:1 -> 6 |
|
1543 |
'hello world ' indexOfSeparatorStartingAt:3 -> 6 |
|
1544 |
'hello world ' indexOfSeparatorStartingAt:7 -> 12 |
|
1545 |
'hello world' indexOfSeparatorStartingAt:7 -> 0 |
|
1546 |
'helloworld' indexOfSeparatorStartingAt:1 -> 0 |
|
95 | 1547 |
" |
19748 | 1548 |
|
1549 |
" |
|
1550 |
|s| |
|
1551 |
s := String new:1000 withAll:$a. |
|
1552 |
self assert:(s indexOfSeparatorStartingAt:1) == 0. |
|
1553 |
Time millisecondsToRun:[ |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1554 |
1000000 timesRepeat:[ s indexOfSeparatorStartingAt:1 ] |
19748 | 1555 |
] |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1556 |
original (char-wise):760 760 750 |
19748 | 1557 |
with 4-byte at a time: 640 650 620 |
1558 |
with 8-byte at a time: 300 290 320 |
|
1559 |
" |
|
1560 |
" |
|
1561 |
|s| |
|
1562 |
s := String new:1000 withAll:$a. |
|
1563 |
s at:400 put:(Character return). |
|
1564 |
self assert:(s indexOfSeparatorStartingAt:1) == 400. |
|
1565 |
Time millisecondsToRun:[ |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1566 |
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
|
1567 |
] |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1568 |
original (char-wise):340 350 |
19748 | 1569 |
with 4-byte at a time: 310 290 280 |
1570 |
with 8-byte at a time: 150 140 140 |
|
1571 |
" |
|
1572 |
" |
|
1573 |
|s| |
|
1574 |
s := String new:1000 withAll:$a. |
|
1575 |
s at:999 put:(Character space). |
|
1576 |
self assert:(s indexOfSeparatorStartingAt:1) == 999. |
|
1577 |
Time millisecondsToRun:[ |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19839
diff
changeset
|
1578 |
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
|
1579 |
] |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1580 |
original (char-wise): 750 750 790 |
19748 | 1581 |
with 4-byte at a time: 640 640 620 |
1582 |
with 8-byte at a time: 280 290 300 |
|
95 | 1583 |
" |
608 | 1584 |
! |
1585 |
||
1586 |
occurrencesOf:aCharacter |
|
1587 |
"count the occurrences of the argument, aCharacter in myself |
|
1588 |
- reimplemented here for speed" |
|
1589 |
||
1590 |
%{ /* NOCONTEXT */ |
|
1591 |
||
1592 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1593 |
REGISTER unsigned byteValue; |
8913 | 1594 |
REGISTER INT count, limit; |
608 | 1595 |
OBJ cls; |
1596 |
||
1597 |
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
|
1598 |
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
|
1599 |
count = 0; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1600 |
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
|
1601 |
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
|
1602 |
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
|
1603 |
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
|
1604 |
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
|
1605 |
limit -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1606 |
cp += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1607 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1608 |
/* 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
|
1609 |
* (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
|
1610 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1611 |
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
|
1612 |
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
|
1613 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1614 |
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
|
1615 |
limit -= 4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1616 |
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
|
1617 |
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
|
1618 |
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
|
1619 |
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
|
1620 |
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
|
1621 |
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
|
1622 |
cp += 4; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1623 |
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
|
1624 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1625 |
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
|
1626 |
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
|
1627 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1628 |
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
|
1629 |
limit--; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1630 |
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
|
1631 |
cp ++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1632 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1633 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1634 |
RETURN ( __mkSmallInteger(count) ); |
608 | 1635 |
} |
1636 |
%}. |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
1637 |
^ super occurrencesOf:aCharacter |
608 | 1638 |
|
1639 |
" |
|
1640 |
'hello world' occurrencesOf:$a |
|
1641 |
'hello world' occurrencesOf:$w |
|
8898 | 1642 |
'hello world' occurrencesOf:$l |
1643 |
'hello world' occurrencesOf:$x |
|
1644 |
'hello world' occurrencesOf:1 |
|
11418 | 1645 |
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
|
1646 |
1000000 timesRepeat:[ 'abcdefghijklmn' occurrencesOf:$x ] |
11418 | 1647 |
]. 219 203 156 203 204 204 219 172 187 187 141 |
608 | 1648 |
" |
53 | 1649 |
! ! |
1650 |
||
608 | 1651 |
!String methodsFor:'comparing'! |
2 | 1652 |
|
8312 | 1653 |
< aString |
1654 |
"Compare the receiver with the argument and return true if the |
|
1655 |
receiver is greater than the argument. Otherwise return false. |
|
1656 |
No national variants are honored; use after: for this. |
|
1657 |
In contrast to ST-80, case differences are NOT ignored, thus |
|
8898 | 1658 |
'foo' < 'Foo' will return false. |
8312 | 1659 |
This may change." |
1660 |
||
1661 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
1662 |
#ifdef __SCHTEAM__ |
18236 | 1663 |
return context._RETURN( self.stringLtP(aString) ); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1664 |
/* NOTREACHED */ |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1665 |
#else |
8312 | 1666 |
int len1, len2, cmp; |
1667 |
unsigned char *cp1, *cp2; |
|
14664 | 1668 |
int argIsString; |
1669 |
||
1670 |
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
|
1671 |
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
|
1672 |
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
|
1673 |
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
|
1674 |
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
|
1675 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1676 |
* 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
|
1677 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1678 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1679 |
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
|
1680 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1681 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1682 |
len2 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1683 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1684 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1685 |
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
|
1686 |
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
|
1687 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1688 |
* 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
|
1689 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1690 |
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
|
1691 |
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
|
1692 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1693 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1694 |
len1 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1695 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1696 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1697 |
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
|
1698 |
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
|
1699 |
else |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1700 |
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
|
1701 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1702 |
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
|
1703 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1704 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1705 |
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
|
1706 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1707 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1708 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1709 |
} |
8312 | 1710 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1711 |
#endif |
8312 | 1712 |
%}. |
1713 |
^ super < aString |
|
1714 |
! |
|
1715 |
||
608 | 1716 |
= aString |
1717 |
"Compare the receiver with the argument and return true if the |
|
1718 |
receiver is equal to the argument. Otherwise return false. |
|
1719 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
|
1720 |
Use sameAs: to compare with case ignored." |
|
1 | 1721 |
|
375 | 1722 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
1723 |
#ifdef __SCHTEAM__ |
18347 | 1724 |
if (aString == self) { |
1725 |
return __c__._RETURN_true(); |
|
1726 |
} |
|
1727 |
if (aString.isStringLike()) { |
|
18700 | 1728 |
return __c__._RETURN( self.isStringEqual(aString) ? STObject.True : STObject.False ); |
18347 | 1729 |
} |
18700 | 1730 |
if (aString == STObject.Nil) { |
1731 |
return __c__._RETURN_false(); |
|
1732 |
} |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1733 |
#else |
608 | 1734 |
int l1, l2; |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1735 |
unsigned char *cp1, *cp2; |
3335 | 1736 |
INT addrDelta; |
14664 | 1737 |
int argIsString; |
1738 |
||
1739 |
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
|
1740 |
RETURN ( true ); |
608 | 1741 |
} |
14664 | 1742 |
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
|
1743 |
RETURN ( false ); |
608 | 1744 |
} |
1 | 1745 |
|
14664 | 1746 |
argIsString = __qIsStringLike(aString); |
1747 |
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
|
1748 |
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
|
1749 |
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
|
1750 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1751 |
* 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
|
1752 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1753 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1754 |
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
|
1755 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1756 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1757 |
l2 -= n; |
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 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1760 |
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
|
1761 |
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
|
1762 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1763 |
* 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
|
1764 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1765 |
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
|
1766 |
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
|
1767 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1768 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1769 |
l1 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1770 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1771 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1772 |
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
|
1773 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1774 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1775 |
# 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
|
1776 |
RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false ); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1777 |
# else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1778 |
addrDelta = cp2 - cp1; |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1779 |
# 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
|
1780 |
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
|
1781 |
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
|
1782 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1783 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1784 |
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
|
1785 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1786 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1787 |
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
|
1788 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1789 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1790 |
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
|
1791 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1792 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1793 |
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
|
1794 |
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
|
1795 |
} |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1796 |
# 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
|
1797 |
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
|
1798 |
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
|
1799 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1800 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1801 |
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
|
1802 |
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
|
1803 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1804 |
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
|
1805 |
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
|
1806 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1807 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1808 |
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
|
1809 |
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
|
1810 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1811 |
while (l1) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1812 |
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
|
1813 |
RETURN (false); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1814 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1815 |
l1--; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1816 |
cp1++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1817 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1818 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1819 |
RETURN (true); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1820 |
# endif |
1 | 1821 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
1822 |
#endif /* not __SCHTEAM__ */ |
3111 | 1823 |
%}. |
608 | 1824 |
^ super = aString |
1 | 1825 |
|
95 | 1826 |
" |
8898 | 1827 |
'foo' = 'Foo' |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1828 |
'foo' sameAs: 'Foo' |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1829 |
#[0 0 1 0 0] asString = #[0 0 1 0 0] asString |
95 | 1830 |
" |
7868 | 1831 |
" |
1832 |
|tEmpty tCmp| |
|
1833 |
||
1834 |
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
|
1835 |
1000000 timesRepeat:[] |
7868 | 1836 |
]. |
1837 |
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
|
1838 |
1000000 timesRepeat:[ '1234567890' = '1234567890' ] |
7868 | 1839 |
]. |
8898 | 1840 |
tCmp - tEmpty |
7868 | 1841 |
" |
1 | 1842 |
! |
1843 |
||
608 | 1844 |
> aString |
1845 |
"Compare the receiver with the argument and return true if the |
|
1846 |
receiver is greater than the argument. Otherwise return false. |
|
1847 |
No national variants are honored; use after: for this. |
|
1848 |
In contrast to ST-80, case differences are NOT ignored, thus |
|
8898 | 1849 |
'foo' > 'Foo' will return true. |
608 | 1850 |
This may change." |
1 | 1851 |
|
375 | 1852 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
1853 |
#ifdef __SCHTEAM__ |
18236 | 1854 |
return context._RETURN( aString.stringLtP( self ) ); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1855 |
/* NOTREACHED */ |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
1856 |
#else |
608 | 1857 |
int len1, len2, cmp; |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1858 |
unsigned char *cp1, *cp2; |
14664 | 1859 |
int argIsString; |
1860 |
||
1861 |
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
|
1862 |
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
|
1863 |
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
|
1864 |
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
|
1865 |
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
|
1866 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1867 |
* 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
|
1868 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1869 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1870 |
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
|
1871 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1872 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1873 |
len2 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1874 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1875 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1876 |
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
|
1877 |
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
|
1878 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1879 |
* 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
|
1880 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1881 |
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
|
1882 |
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
|
1883 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1884 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1885 |
len1 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1886 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1887 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1888 |
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
|
1889 |
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
|
1890 |
else |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1891 |
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
|
1892 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1893 |
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
|
1894 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1895 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1896 |
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
|
1897 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1898 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1899 |
RETURN ( false ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
1900 |
} |
1 | 1901 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
1902 |
#endif /* not __SCHTEAM__ */ |
370 | 1903 |
%}. |
608 | 1904 |
^ super > aString |
1905 |
! |
|
1 | 1906 |
|
1251 | 1907 |
compareCollatingWith:aString |
1908 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
8898 | 1909 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
1251 | 1910 |
The comparison is language specific, depending on the value of |
1911 |
LC_COLLATE, which is in the shell environment." |
|
1912 |
||
19741 | 1913 |
^ self compareWith:aString collating:true |
1914 |
||
608 | 1915 |
" |
19839 | 1916 |
'hallo' compareWith:'hällo' |
1917 |
'hbllo' compareWith:'hällo' |
|
1918 |
||
1919 |
'hallo' compareCollatingWith:'hällo' |
|
1920 |
'hbllo' compareCollatingWith:'hällo' |
|
608 | 1921 |
" |
1 | 1922 |
! |
1923 |
||
14664 | 1924 |
compareWith:aString |
1925 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
1926 |
greater, 0 if equal and -1 if less than the argument. |
|
1927 |
This comparison is based on the elements' codepoints - |
|
1928 |
i.e. upper/lowercase & national characters are NOT treated specially. |
|
1929 |
'foo' compareWith: 'Foo' will return 1. |
|
1930 |
while 'foo' sameAs:'Foo' will return true" |
|
1931 |
||
19741 | 1932 |
^ self compareWith:aString collating:false |
1933 |
! |
|
1934 |
||
1935 |
compareWith:aString collating:collatingBoolean |
|
1936 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
1937 |
greater, 0 if equal and -1 if less than the argument. |
|
1938 |
If the collatingBoolean is true, the comparison will be based on the |
|
1939 |
current setting of LC_COLLATE in the locale (which is set in the shell environment); |
|
1940 |
otherwise, it will be a simple string-compare. |
|
1941 |
This comparison is based on the elements' codepoints - |
|
1942 |
i.e. upper/lowercase & national characters are NOT treated specially. |
|
1943 |
'foo' compareWith: 'Foo' will return 1. |
|
1944 |
while 'foo' sameAs:'Foo' will return true" |
|
1945 |
||
14664 | 1946 |
%{ /* NOCONTEXT */ |
1947 |
||
1948 |
int cmp; |
|
1949 |
unsigned char *cp1, *cp2; |
|
1950 |
int argIsString; |
|
1951 |
||
1952 |
if (__isNonNilObject(aString)) { |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1953 |
argIsString = __qIsStringLike(aString); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1954 |
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
|
1955 |
// |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1956 |
// 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
|
1957 |
// |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1958 |
cp1 = __stringVal(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1959 |
if (!__qIsStringLike(self)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1960 |
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
|
1961 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1962 |
cp1 += n; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1963 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1964 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1965 |
// |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1966 |
// 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
|
1967 |
// |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1968 |
cp2 = __stringVal(aString); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1969 |
if (!argIsString) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1970 |
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
|
1971 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1972 |
cp2 += n; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1973 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1974 |
if (collatingBoolean == true) { |
19741 | 1975 |
#ifdef HAS_STRCOLL |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1976 |
cmp = strcoll(cp1, cp2); |
19741 | 1977 |
#else |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1978 |
// 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
|
1979 |
goto getOutOfHere; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1980 |
#endif |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1981 |
} else { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1982 |
cmp = strcmp(cp1, cp2); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1983 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1984 |
{ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1985 |
// 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
|
1986 |
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
|
1987 |
RETURN( __mkSmallInteger( signum ) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1988 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
1989 |
} |
14664 | 1990 |
} |
19741 | 1991 |
getOutOfHere: ; |
14664 | 1992 |
%}. |
1993 |
" |
|
19741 | 1994 |
currently, this operation is only defined for strings, symbols and subclasses. |
1995 |
allow for an implementation in Smalltalk |
|
14664 | 1996 |
" |
19741 | 1997 |
^ super compareWith:aString collating:collatingBoolean |
14664 | 1998 |
! |
1999 |
||
14653 | 2000 |
hash |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2001 |
"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
|
2002 |
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
|
2003 |
used in the ST/X VM (which is actually fnv-1a)" |
14653 | 2004 |
|
2005 |
%{ /* NOCONTEXT */ |
|
18343 | 2006 |
#ifdef __SCHTEAM__ |
2007 |
STString me = self.asSTString(); |
|
2008 |
long h = me.hash_fnv1a(); |
|
2009 |
return __c__._RETURN(STInteger._new(h)); |
|
2010 |
#else |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2011 |
extern unsigned int __symbolHash(char *); |
18581 | 2012 |
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
|
2013 |
unsigned int h; |
14653 | 2014 |
|
2015 |
if (!__qIsStringLike(self)) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2016 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
14653 | 2017 |
} |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2018 |
h = __symbolHash(cp); |
16891
93560afff48f
oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents:
16889
diff
changeset
|
2019 |
// make sure, it fits into a smallInt |
93560afff48f
oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents:
16889
diff
changeset
|
2020 |
h = (h ^ (h >> 30)) & 0x3FFFFFFF; |
93560afff48f
oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents:
16889
diff
changeset
|
2021 |
RETURN(__mkSmallInteger(h)); |
18343 | 2022 |
#endif /* not SCHTEAM */ |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2023 |
%}. |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2024 |
^ self primitiveFailed |
14653 | 2025 |
|
2026 |
" |
|
2027 |
'a' hash |
|
2028 |
'ab' hash = 'ab' asUnicode16String hash |
|
2029 |
" |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2030 |
|
14653 | 2031 |
"Created: / 26-12-2011 / 13:53:09 / cg" |
2032 |
! |
|
2033 |
||
13880 | 2034 |
hash_dragonBook |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2035 |
"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
|
2036 |
This method implements the dragon-book algorithm (aho, ullman)." |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2037 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2038 |
%{ /* NOCONTEXT */ |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2039 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2040 |
REGISTER unsigned g, val; |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2041 |
REGISTER unsigned char *cp, *cp0; |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2042 |
int l; |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2043 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2044 |
cp = __stringVal(self); |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2045 |
l = __stringSize(self); |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2046 |
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
|
2047 |
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
|
2048 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2049 |
cp += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2050 |
l -= n; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2051 |
} |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2052 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2053 |
/* |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2054 |
* this is the dragon-book algorithm |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2055 |
*/ |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2056 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2057 |
val = 0; |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2058 |
switch (l) { |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2059 |
default: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2060 |
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
|
2061 |
val = (val << 4) + *cp; |
18551
7f43475b5613
eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents:
18405
diff
changeset
|
2062 |
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
|
2063 |
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
|
2064 |
val ^= g; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2065 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2066 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2067 |
break; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2068 |
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
|
2069 |
val = cp[5] << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2070 |
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
|
2071 |
val = (val + cp[4]) << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2072 |
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
|
2073 |
val = (val + cp[3]) << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2074 |
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
|
2075 |
val = (val + cp[2]) << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2076 |
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
|
2077 |
val = (val + cp[1]) << 4; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2078 |
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
|
2079 |
val = val + cp[0]; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2080 |
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
|
2081 |
break; |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2082 |
} |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2083 |
|
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2084 |
/* |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2085 |
* multiply by large prime to spread values |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2086 |
* This speeds up Set and Dictionary by a factor of 10! |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2087 |
*/ |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2088 |
val *= 31415821; |
12763 | 2089 |
RETURN ( __mkSmallInteger(val & _MAX_INT)); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2090 |
%}. |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2091 |
^ self primitiveFailed |
10697
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2092 |
! |
77ab35cd09a5
oops: Unicode16String-hash returned different value from
sr
parents:
10677
diff
changeset
|
2093 |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2094 |
hash_fnv1a |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2095 |
"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
|
2096 |
This method uses the fnv-1a algorithm |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2097 |
(which is actually a pretty good one)." |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2098 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2099 |
%{ /* NOCONTEXT */ |
18343 | 2100 |
#ifdef __SCHTEAM__ |
2101 |
STString me = self.asSTString(); |
|
2102 |
long h = me.hash_fnv1a(); |
|
2103 |
return __c__._RETURN(STInteger._new(h)); |
|
2104 |
#else |
|
18581 | 2105 |
REGISTER unsigned int h = 2166136261u; |
2106 |
REGISTER unsigned char *cp = __stringVal(self); |
|
2107 |
INT l = __stringSize(self); |
|
2108 |
||
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2109 |
if (!__qIsStringLike(self)) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2110 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2111 |
|
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2112 |
cp += n; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2113 |
l -= n; |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2114 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2115 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2116 |
while (l >= 4) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2117 |
l -= 4; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2118 |
h = (h ^ cp[0]) * 16777619; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2119 |
h = (h ^ cp[1]) * 16777619; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2120 |
h = (h ^ cp[2]) * 16777619; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2121 |
h = (h ^ cp[3]) * 16777619; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2122 |
cp += 4; |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2123 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2124 |
while (l--) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2125 |
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
|
2126 |
} |
16900
04c111f73292
make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents:
16891
diff
changeset
|
2127 |
// make it a smallInteger |
04c111f73292
make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents:
16891
diff
changeset
|
2128 |
h = (h ^ (h >> 30)) & 0x3FFFFFFF; |
04c111f73292
make sure that hash returns a smallInt
Claus Gittinger <cg@exept.de>
parents:
16891
diff
changeset
|
2129 |
RETURN ( __mkSmallInteger(h)); |
18343 | 2130 |
#endif /* not SCHTEAM */ |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2131 |
%}. |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2132 |
^ self primitiveFailed |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2133 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2134 |
" |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2135 |
'a' hash_fnv1a |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2136 |
" |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2137 |
! |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2138 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2139 |
hash_java |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2140 |
"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
|
2141 |
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
|
2142 |
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
|
2143 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2144 |
%{ /* NOCONTEXT */ |
18343 | 2145 |
#ifdef __SCHTEAM__ |
2146 |
STString me = self.asSTString(); |
|
2147 |
long h = me.hash_java(); |
|
2148 |
return __c__._RETURN(STInteger._new(h)); |
|
2149 |
#else |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2150 |
REGISTER unsigned INT val; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2151 |
REGISTER unsigned char *cp; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2152 |
int l; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2153 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2154 |
cp = __stringVal(self); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2155 |
l = __stringSize(self); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2156 |
if (!__qIsStringLike(self)) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2157 |
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
|
2158 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2159 |
cp += n; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2160 |
l -= n; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2161 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2162 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2163 |
/* |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2164 |
* 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
|
2165 |
*/ |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2166 |
val = 0; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2167 |
while (l >= 4) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2168 |
l -= 4; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2169 |
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
|
2170 |
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
|
2171 |
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
|
2172 |
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
|
2173 |
cp += 4; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2174 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2175 |
while (l--) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2176 |
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
|
2177 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2178 |
RETURN ( __MKUINT(val)); |
18343 | 2179 |
#endif /* not SCHTEAM */ |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2180 |
%}. |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2181 |
^ self primitiveFailed |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2182 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2183 |
" |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2184 |
'a' hash_java |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2185 |
" |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2186 |
! |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2187 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2188 |
hash_sdbm |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2189 |
"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
|
2190 |
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
|
2191 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2192 |
%{ /* NOCONTEXT */ |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2193 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2194 |
REGISTER unsigned INT val; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2195 |
REGISTER unsigned char *cp; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2196 |
int l; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2197 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2198 |
cp = __stringVal(self); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2199 |
l = __stringSize(self); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2200 |
if (!__qIsStringLike(self)) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2201 |
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
|
2202 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2203 |
cp += n; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2204 |
l -= n; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2205 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2206 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2207 |
/* |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2208 |
* 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
|
2209 |
*/ |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2210 |
val = 0; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2211 |
while (l >= 4) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2212 |
l -= 4; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2213 |
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
|
2214 |
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
|
2215 |
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
|
2216 |
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
|
2217 |
cp += 4; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2218 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2219 |
while (l--) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2220 |
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
|
2221 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2222 |
RETURN ( __mkSmallInteger(val & _MAX_INT)); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2223 |
%}. |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2224 |
^ self primitiveFailed |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2225 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2226 |
" |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2227 |
'a' hash |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2228 |
'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
|
2229 |
" |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2230 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2231 |
"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
|
2232 |
! |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2233 |
|
608 | 2234 |
~= aString |
2235 |
"Compare the receiver with the argument and return true if the |
|
2236 |
receiver is not equal to the argument. Otherwise return false. |
|
3111 | 2237 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
2238 |
Actually, there is no need to redefine that method here, |
|
2239 |
the default (= not as inherited) works ok. |
|
2240 |
However, this may be heavily used and the redefinition saves an |
|
2241 |
extra message send." |
|
1 | 2242 |
|
608 | 2243 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
2244 |
#ifdef __SCHTEAM__ |
18700 | 2245 |
if (aString == self) { |
2246 |
return __c__._RETURN_false(); |
|
2247 |
} |
|
2248 |
if (aString.isStringLike()) { |
|
2249 |
return __c__._RETURN( self.isStringEqual(aString) ? STObject.False : STObject.True ); |
|
2250 |
} |
|
2251 |
if (aString == STObject.Nil) { |
|
2252 |
return __c__._RETURN_true(); |
|
2253 |
} |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2254 |
#else |
1 | 2255 |
int l1, l2; |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
2256 |
unsigned char *cp1, *cp2; |
3111 | 2257 |
OBJ cls, myCls; |
3335 | 2258 |
INT addrDelta; |
14664 | 2259 |
int argIsString; |
2260 |
||
2261 |
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
|
2262 |
RETURN ( false ); |
608 | 2263 |
} |
14664 | 2264 |
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
|
2265 |
RETURN ( true ); |
608 | 2266 |
} |
3111 | 2267 |
|
14664 | 2268 |
argIsString = __qIsStringLike(aString); |
2269 |
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
|
2270 |
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
|
2271 |
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
|
2272 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2273 |
* 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
|
2274 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2275 |
if (!__qIsStringLike(self)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2276 |
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
|
2277 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2278 |
cp1 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2279 |
l1 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2280 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2281 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2282 |
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
|
2283 |
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
|
2284 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2285 |
* 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
|
2286 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2287 |
if (!argIsString) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2288 |
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
|
2289 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2290 |
cp2 += n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2291 |
l2 -= n; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2292 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2293 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2294 |
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
|
2295 |
RETURN ( true ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2296 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2297 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2298 |
addrDelta = cp2 - cp1; |
8919 | 2299 |
# 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
|
2300 |
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
|
2301 |
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
|
2302 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2303 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2304 |
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
|
2305 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2306 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2307 |
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
|
2308 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2309 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2310 |
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
|
2311 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2312 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2313 |
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
|
2314 |
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
|
2315 |
} |
8919 | 2316 |
# 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
|
2317 |
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
|
2318 |
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
|
2319 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2320 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2321 |
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
|
2322 |
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
|
2323 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2324 |
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
|
2325 |
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
|
2326 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2327 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2328 |
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
|
2329 |
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
|
2330 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2331 |
while (l1) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2332 |
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
|
2333 |
RETURN (true); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2334 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2335 |
l1--; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2336 |
cp1++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2337 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2338 |
RETURN (false); |
608 | 2339 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
2340 |
#endif /* not __SCHTEAM__ */ |
3111 | 2341 |
%}. |
608 | 2342 |
^ super ~= aString |
2343 |
! ! |
|
2344 |
||
2345 |
!String methodsFor:'converting'! |
|
2346 |
||
6830 | 2347 |
asArrayOfSubstrings |
11906 | 2348 |
"Answer an array with all the substrings of the receiver separated by |
2349 |
separator characters (space, cr, tab, linefeed, formfeed, etc). |
|
2350 |
CG: This is ported Squeak code, and I am not sure if it is more efficient than |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2351 |
the inherited one... after all: who added it anyway ?" |
16457 | 2352 |
|
2353 |
| substrings start end stop | |
|
11906 | 2354 |
|
2355 |
substrings := OrderedCollection new. |
|
2356 |
start := 1. |
|
16457 | 2357 |
stop := self size. |
2358 |
[start <= stop] whileTrue: [ |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2359 |
(self at: start) isSeparator ifFalse: [ |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2360 |
end := start + 1. |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2361 |
[end <= stop and: [(self at: end) isSeparator not]] |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2362 |
whileTrue: [end := end + 1]. |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2363 |
substrings add: (self copyFrom: start to: end - 1). |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2364 |
start := end - 1 |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2365 |
]. |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
2366 |
start := start + 1 |
11906 | 2367 |
]. |
2368 |
^ substrings asArray |
|
6830 | 2369 |
! |
2370 |
||
11882 | 2371 |
asAsciiZ |
2372 |
"if the receiver does not end with a 0-valued character, return a copy of it, |
|
2373 |
with an additional 0-character. Otherwise return the receiver. This is sometimes |
|
2374 |
needed when a string has to be passed to C, which needs 0-terminated strings. |
|
2375 |
Notice, that all singleByte strings are already 0-terminated in ST/X, whereas wide |
|
2376 |
strings are not." |
|
2377 |
||
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2378 |
^ self |
11882 | 2379 |
|
2380 |
" |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2381 |
'abc' asAsciiZ |
11882 | 2382 |
'abc' asWideString asAsciiZ |
2383 |
" |
|
2384 |
! |
|
2385 |
||
10594 | 2386 |
asByteArray |
15938 | 2387 |
"return a new ByteArray with the receiver's elements. |
2388 |
This redefined method is faster than Collection>>#asByteArray" |
|
10594 | 2389 |
|
2390 |
|bytes sz| |
|
2391 |
||
2392 |
sz := self size. |
|
2393 |
bytes := ByteArray new:sz . |
|
2394 |
bytes replaceFrom:1 to:sz with:self startingAt:1. |
|
2395 |
^ bytes |
|
2396 |
||
2397 |
" |
|
16019
b204c9d6ce6d
no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents:
15938
diff
changeset
|
2398 |
'fooBar' asByteArray. |
10594 | 2399 |
" |
14260
c8e2fa654d6d
comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents:
14217
diff
changeset
|
2400 |
|
c8e2fa654d6d
comment/format in: #asByteArray
Claus Gittinger <cg@exept.de>
parents:
14217
diff
changeset
|
2401 |
"Modified (comment): / 26-07-2012 / 22:55:26 / cg" |
10594 | 2402 |
! |
2403 |
||
9472 | 2404 |
asExternalBytes |
19170 | 2405 |
"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
|
2406 |
my characters. |
19170 | 2407 |
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
|
2408 |
i.t. it can be handed to a C-function, and must |
19170 | 2409 |
(either there or here) be freed explicitly or unprotectedFromGC" |
2410 |
||
2411 |
^ (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
|
2412 |
replaceNullTerminatedFromString:self |
9472 | 2413 |
|
2414 |
" |
|
2415 |
|x| |
|
2416 |
x := 'fooBar' asExternalBytes. |
|
2417 |
x unprotectFromGC. |
|
2418 |
ObjectMemory garbageCollect |
|
2419 |
" |
|
2420 |
||
2421 |
"Modified: / 03-08-2006 / 14:45:32 / fm" |
|
2422 |
! |
|
2423 |
||
14156 | 2424 |
asExternalBytesUnprotected |
2425 |
"Like asExternalBytes, but does not register the bytes so |
|
15837 | 2426 |
bytes are GARBAGE-COLLECTED!!" |
14156 | 2427 |
|
19170 | 2428 |
^ (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
|
2429 |
replaceNullTerminatedFromString:self |
14156 | 2430 |
|
2431 |
" |
|
2432 |
|x| |
|
2433 |
x := 'fooBar' asExternalBytesUnprotected. |
|
2434 |
ObjectMemory garbageCollect |
|
2435 |
" |
|
2436 |
||
2437 |
"Created: / 05-06-2012 / 14:12:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
15837 | 2438 |
"Modified: / 30-11-2013 / 11:41:40 / cg" |
14156 | 2439 |
! |
2440 |
||
12454 | 2441 |
asImmutableString |
2442 |
"return a write-protected copy of myself" |
|
2443 |
||
2444 |
^ self copy changeClassTo:ImmutableString |
|
2445 |
! |
|
2446 |
||
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2447 |
asLowercase |
20109 | 2448 |
"a tuned version for Strings with size < 255. Some apps call this very heavily. |
2449 |
We can do this for 8-bit strings, since the mapping is well known and lowercase chars |
|
2450 |
fit in one byte also." |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2451 |
|
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2452 |
%{ /* NOCONTEXT */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2453 |
#ifndef __SCHTEAM__ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2454 |
REGISTER OBJ slf = self; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2455 |
|
20109 | 2456 |
if (__isStringLike(slf)) { |
2457 |
char quickBuffer[256]; |
|
2458 |
int sz = __stringSize(slf); |
|
2459 |
||
2460 |
if (sz < (sizeof(quickBuffer)-1)) { |
|
2461 |
REGISTER int i = 0; |
|
2462 |
int anyChange = 0; |
|
2463 |
REGISTER unsigned char *cp = __stringVal(slf); |
|
2464 |
||
2465 |
// fast advance |
|
2466 |
// all uppercase chars are in the ranges 0x41 .. 0x5A (A..Z) |
|
2467 |
// or 0xC0 .. 0xDF. |
|
2468 |
// I.e. they have the 0x20 bit clear. |
|
2469 |
// Thus, we can fast skip over lowercase, spaces and some punctuation, |
|
2470 |
// if all bytes of a word have the x20 bit set. |
|
20126 | 2471 |
|
18661 | 2472 |
#if __POINTER_SIZE__ == 8 |
20126 | 2473 |
for (; i < (sz-8); i += 8) { |
2474 |
unsigned INT eightChars = *(unsigned INT *)(cp+i); |
|
2475 |
if ((eightChars & 0x2020202020202020ULL) != 0x2020202020202020ULL) goto convert; |
|
2476 |
*(unsigned INT *)(quickBuffer+i) = eightChars; |
|
20109 | 2477 |
} |
18661 | 2478 |
#endif |
20126 | 2479 |
for (; i < (sz-4); i += 4) { |
2480 |
unsigned int fourChars = *(unsigned int *)(cp+i); |
|
20109 | 2481 |
if ((fourChars & 0x20202020U) != 0x20202020U) break; |
20126 | 2482 |
*(unsigned int *)(quickBuffer+i) = fourChars; |
20109 | 2483 |
} |
20126 | 2484 |
convert: |
20109 | 2485 |
for (; i<sz; i++) { |
2486 |
unsigned char ch = cp[i]; |
|
2487 |
||
2488 |
quickBuffer[i] = ch; |
|
2489 |
if ((ch & 0x60) == 0x40) { |
|
20126 | 2490 |
if (ch >= 'A' && ch <= 'Z') { |
2491 |
quickBuffer[i] = ch - 'A' + 'a'; |
|
2492 |
anyChange = 1; |
|
2493 |
} else { |
|
2494 |
// deal with national latin1 characters |
|
2495 |
if (ch >= 0xC0 && ch <= 0xDE && ch != 0xD7) { |
|
2496 |
quickBuffer[i] = ch + 0x20; |
|
20109 | 2497 |
anyChange = 1; |
2498 |
} |
|
2499 |
} |
|
2500 |
} |
|
2501 |
} |
|
2502 |
if (! anyChange) { |
|
2503 |
RETURN(slf); |
|
2504 |
} |
|
2505 |
quickBuffer[i] = '\0'; |
|
2506 |
RETURN (__MKSTRING_L(quickBuffer, i)); |
|
2507 |
} |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2508 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2509 |
#endif /* ! __SCHTEAM__ */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2510 |
%}. |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2511 |
^ super asLowercase |
20109 | 2512 |
|
2513 |
" |
|
2514 |
'Hello WORLD' asLowercase |
|
20126 | 2515 |
(String new:300) asLowercase |
20109 | 2516 |
" |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2517 |
! |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
2518 |
|
9574 | 2519 |
asPackageId |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2520 |
"given a package-string as receiver, return a packageId object. |
14566 | 2521 |
packageIds hide the details of module/directory handling inside the path. |
2522 |
See PackageId for the required format of those strings." |
|
12184
e91c375c7ea9
comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents:
11922
diff
changeset
|
2523 |
|
14571 | 2524 |
^ PackageId from: self |
9574 | 2525 |
|
2526 |
" |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2527 |
'stx:libbasic' asPackageId |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2528 |
'stx:goodies/net/ssl' asPackageId |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2529 |
'stx:hello' asPackageId |
9574 | 2530 |
" |
2531 |
||
2532 |
"Created: / 18-08-2006 / 12:19:54 / cg" |
|
2533 |
! |
|
2534 |
||
7877
bef56f06d2f8
asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents:
7869
diff
changeset
|
2535 |
asSingleByteString |
5760 | 2536 |
"I am a string" |
2537 |
||
2538 |
^ self |
|
2539 |
! |
|
2540 |
||
11287 | 2541 |
asSingleByteStringIfPossible |
2542 |
"I am a single-byte string" |
|
2543 |
||
2544 |
^ self |
|
2545 |
! |
|
2546 |
||
9473 | 2547 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
11883 | 2548 |
"return the receiver converted to a 'normal' string, |
2549 |
with invalid characters replaced by replacementCharacter. |
|
2550 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
2551 |
and replace characters above code-255 with some replacement. |
|
2552 |
Dummy here, because I am already a single byte string." |
|
2553 |
||
9473 | 2554 |
^ self |
2555 |
||
2556 |
"Modified: / 07-08-2006 / 15:04:45 / fm" |
|
2557 |
! |
|
2558 |
||
608 | 2559 |
asSymbol |
19748 | 2560 |
"Return a unique symbol with the name taken from the receiver's characters." |
7869 | 2561 |
|
2562 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
2563 |
#ifdef __SCHTEAM__ |
18286 | 2564 |
return context._RETURN( STSymbol._new(self.asString()) ); |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2565 |
#else |
608 | 2566 |
OBJ newSymbol; |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2567 |
OBJ cls; |
7869 | 2568 |
char *cp = __stringVal(self); |
2569 |
||
2570 |
/* care for instances of a subclass with instVars */ |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2571 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2572 |
if (cls != String) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2573 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2574 |
} |
7869 | 2575 |
newSymbol = __MKSYMBOL(cp, (OBJ *)0); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2576 |
if (newSymbol) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
2577 |
RETURN ( newSymbol); |
608 | 2578 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
2579 |
#endif /* not __SCHTEAM__ */ |
608 | 2580 |
%}. |
2581 |
^ ObjectMemory allocationFailureSignal raise. |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2582 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2583 |
" |
8898 | 2584 |
'hello' asSymbol |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2585 |
" |
608 | 2586 |
! |
2587 |
||
2588 |
asSymbolIfInterned |
|
19748 | 2589 |
"If a symbol with the receiver's characters is already known, return it. Otherwise, return nil. |
9233 | 2590 |
This can be used to query for an existing symbol and is the same as: |
20162 | 2591 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
608 | 2592 |
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
|
2593 |
performed once." |
1 | 2594 |
|
608 | 2595 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
2596 |
#ifdef __SCHTEAM__ |
18622 | 2597 |
STObject symbolOrNull = STSymbol.asSymbolIfInterned( self.asString() ); |
2598 |
||
2599 |
return context._RETURN( symbolOrNull == null ? STObject.Nil : symbolOrNull ); |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2600 |
#else |
20162 | 2601 |
OBJ cls = __qClass(self); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2602 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2603 |
|
20162 | 2604 |
if (cls != String && cls != ImmutableString) { |
2605 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2606 |
} else { |
20162 | 2607 |
indx = 0; |
608 | 2608 |
} |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2609 |
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
|
2610 |
#endif /* not __SCHTEAM__ */ |
5407 | 2611 |
%}. |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2612 |
^ self primitiveFailed |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2613 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2614 |
'hello' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2615 |
'fooBarBaz' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2616 |
" |
608 | 2617 |
! |
2618 |
||
17378 | 2619 |
beImmutable |
2620 |
"make myself write-protected" |
|
2621 |
||
2622 |
self changeClassTo:ImmutableString |
|
2623 |
! |
|
2624 |
||
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2625 |
withTabsExpanded:numSpaces |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
2626 |
"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
|
2627 |
are expanded into spaces (assuming numSpaces-col tabs). |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
2628 |
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
|
2629 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
2630 |
This does handle multiline strings. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
2631 |
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
|
2632 |
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
|
2633 |
|
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
2634 |
%{ /* STACK:700 */ |
2894 | 2635 |
unsigned char buffer[80*8 + 10]; |
2636 |
unsigned char *srcP, *dstP, *cp0; |
|
608 | 2637 |
int idx, sz; |
2638 |
int any = 0; |
|
2639 |
OBJ newString; |
|
2640 |
char c; |
|
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2641 |
int n; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2642 |
|
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2643 |
if ((__qClass(self) == String) |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2644 |
&& __isSmallInteger(numSpaces)) { |
9473 | 2645 |
n = __intVal(numSpaces); |
2646 |
||
2647 |
/* |
|
2648 |
* for small strings (< 80), do it without a prescan ... |
|
2649 |
* the buffer is large enough to even convert a |
|
2650 |
* receiver consisting fully of tabs. |
|
2651 |
*/ |
|
2652 |
if (__stringSize(self) < 80) { |
|
2653 |
idx = 1; |
|
2654 |
for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) { |
|
2655 |
if (c == '\t') { |
|
2656 |
any = 1; |
|
2657 |
while (idx % n) { |
|
2658 |
idx++; |
|
2659 |
*dstP++ = ' '; |
|
2660 |
} |
|
2661 |
idx++; |
|
2662 |
*dstP++ = ' '; |
|
2663 |
} else { |
|
2664 |
*dstP++ = c; |
|
2665 |
idx++; |
|
2666 |
if (c == '\n') { |
|
2667 |
idx = 1; |
|
2668 |
} |
|
2669 |
} |
|
2670 |
} |
|
2671 |
if (! any) RETURN(self); |
|
2672 |
*dstP = '\0'; |
|
2673 |
RETURN (__MKSTRING_L(buffer, (dstP-buffer))); |
|
2674 |
} |
|
2675 |
/* |
|
2676 |
* for large strings, we compute the new size, allocate a new string |
|
2677 |
* and expand it. |
|
2678 |
* |
|
2679 |
* first, scan for size ... |
|
2680 |
*/ |
|
2681 |
idx = 1; |
|
2682 |
for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) { |
|
2683 |
if (c == '\t') { |
|
2684 |
any = 1; |
|
2685 |
while (idx % n) { |
|
2686 |
idx++; |
|
2687 |
sz++; |
|
2688 |
} |
|
2689 |
idx++; sz ++; |
|
2690 |
} else { |
|
2691 |
sz++; idx++; |
|
2692 |
if (c == '\n') { |
|
2693 |
idx = 1; |
|
2694 |
} |
|
2695 |
} |
|
2696 |
} |
|
2697 |
if (! any) RETURN(self); |
|
2698 |
||
2699 |
/* |
|
2700 |
* get the string |
|
2701 |
*/ |
|
2702 |
sz = OHDR_SIZE + sz + 1; |
|
2703 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
|
2704 |
if (newString != nil) { |
|
2705 |
__InstPtr(newString)->o_class = String; |
|
2706 |
__qSTORE(newString, String); |
|
2707 |
||
2708 |
/* |
|
2709 |
* expand |
|
2710 |
*/ |
|
2711 |
idx = 1; |
|
2712 |
for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) { |
|
2713 |
if (c == '\t') { |
|
2714 |
while (idx % n) { |
|
2715 |
idx++; |
|
2716 |
*dstP++ = ' '; |
|
2717 |
} |
|
2718 |
idx++; |
|
2719 |
*dstP++ = ' '; |
|
2720 |
} else { |
|
2721 |
*dstP++ = c; idx++; |
|
2722 |
if (c == '\n') { |
|
2723 |
idx = 1; |
|
2724 |
} |
|
2725 |
} |
|
2726 |
} |
|
2727 |
*dstP++ = '\0'; |
|
2728 |
RETURN (newString); |
|
2729 |
} |
|
608 | 2730 |
} |
2731 |
%}. |
|
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
2732 |
^ super withTabsExpanded:numSpaces |
1 | 2733 |
! ! |
2734 |
||
2735 |
!String methodsFor:'copying'! |
|
2736 |
||
20070 | 2737 |
, aStringOrCharacter |
2738 |
"return the concatenation of myself and the argument, aStringOrCharacter as a String. |
|
1 | 2739 |
- reimplemented here for speed" |
2740 |
||
2741 |
%{ |
|
18286 | 2742 |
#ifdef __SCHTEAM__ |
20070 | 2743 |
if ( aStringOrCharacter.isStringLike() && self.isStringLike() ) { |
20033 | 2744 |
STString me = self.asSTString(); |
20070 | 2745 |
STString other = aStringOrCharacter.asSTString(); |
20033 | 2746 |
int myLength = me.characters.length; |
2747 |
int otherLength = other.characters.length; |
|
2748 |
||
2749 |
char[] newChars = new char[myLength + otherLength]; |
|
2750 |
System.arraycopy(me.characters, 0, newChars, 0, myLength); |
|
2751 |
System.arraycopy(other.characters, 0, newChars, myLength, otherLength); |
|
2752 |
return context._RETURN( new STString( newChars )); |
|
18286 | 2753 |
} |
2754 |
#else |
|
20033 | 2755 |
/* |
2756 |
* can do it here if both are Strings/Symbols: |
|
2757 |
*/ |
|
20070 | 2758 |
if (__qIsStringLike(self)) { |
2759 |
char *cp1 = (char *) __stringVal(self); |
|
20033 | 2760 |
int l1 = __stringSize(self); |
20070 | 2761 |
int l2; |
20107 | 2762 |
char *cp2 = 0; |
20070 | 2763 |
int sz; |
2764 |
OBJ newString; |
|
2765 |
char character; |
|
2766 |
||
2767 |
if (__isCharacter(aStringOrCharacter)) { |
|
2768 |
if (__intVal(__characterVal(aStringOrCharacter)) <= 0 || __intVal(__characterVal(aStringOrCharacter)) > 255) |
|
2769 |
goto out; |
|
2770 |
||
2771 |
character = __intVal(__characterVal(aStringOrCharacter)); |
|
2772 |
l2 = 1; |
|
2773 |
cp2 = &character; |
|
2774 |
} else if (__isStringLike(aStringOrCharacter)) { |
|
2775 |
l2 = __stringSize(aStringOrCharacter); |
|
2776 |
} else |
|
2777 |
goto out; |
|
2778 |
||
2779 |
sz = OHDR_SIZE + l1 + l2 + 1; |
|
20033 | 2780 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
20107 | 2781 |
|
2782 |
cp1 = (char *) __stringVal(self); |
|
2783 |
if (cp2 == 0) |
|
2784 |
cp2 = (char *) __stringVal(aStringOrCharacter); |
|
2785 |
||
20033 | 2786 |
if (newString != nil) { |
2787 |
REGISTER unsigned char *dstp; |
|
2788 |
||
2789 |
__InstPtr(newString)->o_class = String; |
|
2790 |
__qSTORE(newString, String); |
|
2791 |
dstp = __stringVal(newString); |
|
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
2792 |
|
20107 | 2793 |
# if defined(bcopy4) |
20033 | 2794 |
/* knowing that allocation is 4-byte aligned and |
2795 |
* size rounded up to next 4-byte, the first copy |
|
2796 |
* can be done word-wise. |
|
2797 |
* that speeds up size-10-string , size-10-string |
|
2798 |
* by 10% on a P5/200. |
|
2799 |
*/ |
|
2800 |
{ |
|
2801 |
int nw = l1 >> 2; |
|
2802 |
||
2803 |
if (l1 & 3) nw++; |
|
2804 |
bcopy4(cp1, dstp, nw); |
|
2805 |
dstp += l1; |
|
2806 |
} |
|
20107 | 2807 |
# elif defined(FAST_MEMCPY) |
20033 | 2808 |
memcpy(dstp, cp1, l1); |
2809 |
dstp += l1; |
|
20107 | 2810 |
# else |
20033 | 2811 |
while (l1 >= 4) { |
2812 |
*(int *)dstp = *(int *)cp1; |
|
2813 |
dstp += 4; cp1 += 4; |
|
2814 |
l1 -= 4; |
|
2815 |
} |
|
2816 |
while (l1--) *dstp++ = *cp1++; |
|
3673 | 2817 |
# endif |
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2818 |
|
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2819 |
# ifdef bcopy4 |
20033 | 2820 |
if (((INT)dstp & 3) == 0) { |
2821 |
int nw = l2 >> 2; |
|
2822 |
||
2823 |
if (l2 & 3) nw++; |
|
2824 |
bcopy4(cp2, dstp, nw); |
|
2825 |
*(dstp + l2) = '\0'; |
|
2826 |
RETURN ( newString ); |
|
2827 |
} |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2828 |
# endif |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2829 |
|
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2830 |
# ifdef FAST_MEMCPY |
20033 | 2831 |
memcpy(dstp, cp2, l2+1); |
2832 |
dstp[l2] = '\0'; |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2833 |
# else |
20033 | 2834 |
while (l2--) *dstp++ = *cp2++; |
2835 |
*dstp = '\0'; |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
2836 |
# endif |
20033 | 2837 |
RETURN ( newString ); |
2838 |
} |
|
1 | 2839 |
} |
20070 | 2840 |
out:; |
18286 | 2841 |
#endif /* not SCHTEAM */ |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
2842 |
%}. |
20070 | 2843 |
^ super , aStringOrCharacter |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2844 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2845 |
" |
20070 | 2846 |
'hello' , ' world' asImmutableString |
2847 |
'hello ' , #world |
|
2848 |
'hello ' , $w |
|
8898 | 2849 |
#[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
|
2850 |
" |
14074 | 2851 |
|
2852 |
"Modified: / 01-04-2012 / 13:19:44 / cg" |
|
1 | 2853 |
! |
2854 |
||
2855 |
concatenate:string1 and:string2 |
|
2856 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
2857 |
This is equivalent to self , string1 , string2 |
|
2858 |
- generated by compiler when such a construct is detected" |
|
2859 |
||
2860 |
|newString| |
|
2862 | 2861 |
|
1 | 2862 |
%{ |
95 | 2863 |
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
|
2864 |
#if !defined(FAST_MEMCPY) |
1 | 2865 |
REGISTER unsigned char *srcp; |
2866 |
#endif |
|
2867 |
REGISTER unsigned char *dstp; |
|
2868 |
||
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2869 |
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
|
2870 |
&& __isStringLike(string1) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2871 |
&& __isStringLike(string2)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2872 |
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
|
2873 |
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
|
2874 |
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
|
2875 |
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
|
2876 |
__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
|
2877 |
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
|
2878 |
__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
|
2879 |
__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
|
2880 |
dstp = __stringVal(newString); |
1 | 2881 |
#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
|
2882 |
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
|
2883 |
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
|
2884 |
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
|
2885 |
*(dstp + len1 + len2 + len3) = '\0'; |
1 | 2886 |
#else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2887 |
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
|
2888 |
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
|
2889 |
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
|
2890 |
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
|
2891 |
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
|
2892 |
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
|
2893 |
*dstp = '\0'; |
1 | 2894 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2895 |
RETURN ( newString ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2896 |
} |
1 | 2897 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
2898 |
%}. |
1 | 2899 |
^ super , string1 , string2 |
2900 |
! |
|
2901 |
||
2902 |
concatenate:string1 and:string2 and:string3 |
|
2903 |
"return the concatenation of myself and the string arguments. |
|
2904 |
This is equivalent to self , string1 , string2 , string3 |
|
2905 |
- generated by compiler when such a construct is detected" |
|
2906 |
||
2907 |
|newString| |
|
2862 | 2908 |
|
1 | 2909 |
%{ |
95 | 2910 |
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
|
2911 |
#if !defined(FAST_MEMCPY) |
1 | 2912 |
REGISTER unsigned char *srcp; |
2913 |
#endif |
|
2914 |
REGISTER unsigned char *dstp; |
|
2915 |
||
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2916 |
if (__qIsStringLike(self) |
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
2917 |
&& __isStringLike(string1) |
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
2918 |
&& __isStringLike(string2) |
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
2919 |
&& __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
|
2920 |
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
|
2921 |
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
|
2922 |
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
|
2923 |
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
|
2924 |
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
|
2925 |
__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
|
2926 |
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
|
2927 |
__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
|
2928 |
__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
|
2929 |
dstp = __stringVal(newString); |
1 | 2930 |
#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
|
2931 |
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
|
2932 |
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
|
2933 |
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
|
2934 |
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
|
2935 |
*(dstp + len1 + len2 + len3 + len4) = '\0'; |
1 | 2936 |
#else |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2937 |
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
|
2938 |
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
|
2939 |
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
|
2940 |
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
|
2941 |
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
|
2942 |
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
|
2943 |
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
|
2944 |
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
|
2945 |
*dstp = '\0'; |
1 | 2946 |
#endif |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2947 |
RETURN ( newString ); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
2948 |
} |
1 | 2949 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
2950 |
%}. |
1 | 2951 |
^ super , string1 , string2 , string3 |
2952 |
! |
|
2953 |
||
4745 | 2954 |
copy |
2955 |
"return a copy of the receiver" |
|
2956 |
||
16543 | 2957 |
(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
|
2958 |
^ self copyFrom:1 |
4745 | 2959 |
]. |
2960 |
^ super copy |
|
2961 |
! |
|
2962 |
||
608 | 2963 |
copyFrom:start |
19748 | 2964 |
"return a new collection consisting of receiver's elements from startIndex to the end of the collection. |
8898 | 2965 |
This method will always return a string, even if the receiver |
608 | 2966 |
is a subclass-instance. This might change if there is a need. |
2967 |
- reimplemented here for speed" |
|
1 | 2968 |
|
13 | 2969 |
%{ /* NOCONTEXT */ |
1 | 2970 |
|
608 | 2971 |
#if !defined(FAST_MEMCPY) |
2972 |
REGISTER unsigned char *srcp; |
|
2973 |
#endif |
|
1 | 2974 |
REGISTER unsigned char *dstp; |
608 | 2975 |
REGISTER int count; |
2976 |
int len, index1, sz; |
|
2977 |
OBJ newString; |
|
2862 | 2978 |
|
2894 | 2979 |
#ifndef NO_PRIM_STRING |
20033 | 2980 |
if (__isSmallInteger(start) && __qIsStringLike(self)) { |
2981 |
len = __stringSize(self); |
|
2982 |
index1 = __intVal(start); |
|
2983 |
if (index1 > 0) { |
|
2984 |
if (index1 <= len) { |
|
2985 |
count = len - index1 + 1; |
|
2986 |
sz = OHDR_SIZE + count + 1; |
|
2987 |
||
2988 |
__PROTECT_CONTEXT__ |
|
2989 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
|
2990 |
__UNPROTECT_CONTEXT__ |
|
2991 |
||
2992 |
if (newString != nil) { |
|
2993 |
__InstPtr(newString)->o_class = String; |
|
2994 |
__qSTORE(newString, String); |
|
2995 |
dstp = __stringVal(newString); |
|
1 | 2996 |
#ifdef FAST_MEMCPY |
20033 | 2997 |
memcpy(dstp, __stringVal(self) + index1 - 1, count); |
2998 |
dstp[count] = '\0'; |
|
1 | 2999 |
#else |
20033 | 3000 |
srcp = __stringVal(self) + index1 - 1; |
3001 |
while (count--) { |
|
3002 |
*dstp++ = *srcp++; |
|
3003 |
} |
|
3004 |
*dstp = '\0'; |
|
1 | 3005 |
#endif |
20033 | 3006 |
RETURN ( newString ); |
3007 |
} |
|
3008 |
} |
|
3009 |
} |
|
13 | 3010 |
} |
2894 | 3011 |
#endif |
51 | 3012 |
%}. |
608 | 3013 |
"fall back in case of non-integer index or out-of-bound index; |
3014 |
will eventually lead to an out-of-bound signal raise" |
|
51 | 3015 |
|
608 | 3016 |
^ super copyFrom:start |
20033 | 3017 |
|
3018 |
" |
|
3019 |
'12345' copyFrom:3 |
|
3020 |
" |
|
1 | 3021 |
! |
3022 |
||
3023 |
copyFrom:start to:stop |
|
3024 |
"return the substring starting at index start, anInteger and ending |
|
53 | 3025 |
at stop, anInteger. This method will always return a string, even |
3026 |
if the receiver is a subclass-instance. This might change if there is a need. |
|
1 | 3027 |
- reimplemented here for speed" |
3028 |
||
13 | 3029 |
%{ /* NOCONTEXT */ |
3030 |
||
1 | 3031 |
REGISTER unsigned char *srcp; |
3032 |
REGISTER unsigned char *dstp; |
|
3033 |
REGISTER int count; |
|
95 | 3034 |
int len, sz, index1, index2; |
13 | 3035 |
OBJ newString; |
2862 | 3036 |
|
2894 | 3037 |
#ifndef NO_PRIM_STRING |
20033 | 3038 |
if (__bothSmallInteger(start, stop) && __qIsStringLike(self)) { |
3039 |
len = __stringSize(self); |
|
3040 |
index1 = __intVal(start); |
|
3041 |
index2 = __intVal(stop); |
|
3042 |
||
3043 |
if ((index1 <= index2) && (index1 > 0)) { |
|
3044 |
if (index2 <= len) { |
|
3045 |
count = index2 - index1 + 1; |
|
3046 |
sz = OHDR_SIZE + count + 1; |
|
3047 |
||
3048 |
__PROTECT_CONTEXT__ |
|
3049 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
|
3050 |
__UNPROTECT_CONTEXT__ |
|
3051 |
||
3052 |
if (newString != nil) { |
|
3053 |
__InstPtr(newString)->o_class = String; |
|
3054 |
__qSTORE(newString, String); |
|
3055 |
dstp = __stringVal(newString); |
|
3056 |
srcp = __stringVal(self) + index1 - 1; |
|
2894 | 3057 |
#ifdef bcopy4 |
20033 | 3058 |
{ |
3059 |
int nw = count >> 2; |
|
3060 |
||
3061 |
if (count & 3) { |
|
3062 |
nw++; |
|
3063 |
} |
|
3064 |
bcopy4(srcp, dstp, nw); |
|
3065 |
dstp[count] = '\0'; |
|
3066 |
} |
|
1 | 3067 |
#else |
2894 | 3068 |
# ifdef FAST_MEMCPY |
20033 | 3069 |
memcpy(dstp, srcp, count); |
3070 |
dstp[count] = '\0'; |
|
209 | 3071 |
# else |
20033 | 3072 |
while (count--) { |
3073 |
*dstp++ = *srcp++; |
|
3074 |
} |
|
3075 |
*dstp = '\0'; |
|
209 | 3076 |
# endif |
13 | 3077 |
#endif |
20033 | 3078 |
RETURN ( newString ); |
3079 |
} |
|
3080 |
} |
|
3081 |
} |
|
3082 |
/* |
|
3083 |
* allow empty copy |
|
3084 |
*/ |
|
3085 |
if (index1 > index2) { |
|
3086 |
__PROTECT_CONTEXT__ |
|
3087 |
__qNew(newString, OHDR_SIZE+1); /* OBJECT ALLOCATION */ |
|
3088 |
__UNPROTECT_CONTEXT__ |
|
3089 |
if (newString != nil) { |
|
3090 |
__InstPtr(newString)->o_class = String; |
|
3091 |
(__stringVal(newString))[0] = '\0'; |
|
3092 |
RETURN ( newString ); |
|
3093 |
} |
|
3094 |
} |
|
1 | 3095 |
} |
2894 | 3096 |
#endif |
51 | 3097 |
%}. |
3098 |
"fall back in case of non-integer index or out-of-bound index; |
|
3099 |
will eventually lead to an out-of-bound signal raise" |
|
3100 |
||
1 | 3101 |
^ super copyFrom:start to:stop |
20033 | 3102 |
|
3103 |
" |
|
3104 |
'12345678' copyFrom:3 to:7 |
|
3105 |
" |
|
1 | 3106 |
! |
3107 |
||
608 | 3108 |
copyWith:aCharacter |
19748 | 3109 |
"return a new string containing the receiver's characters |
8898 | 3110 |
and the single new character, aCharacter. |
608 | 3111 |
This is different from concatentation, which expects another string |
3112 |
as argument, but equivalent to copy-and-addLast. |
|
3113 |
Reimplemented here for more speed" |
|
3114 |
||
3115 |
%{ /* NOCONTEXT */ |
|
3116 |
||
2887 | 3117 |
int count; |
608 | 3118 |
int sz; |
3119 |
REGISTER unsigned char *dstp; |
|
3120 |
OBJ cls, newString; |
|
2862 | 3121 |
|
2894 | 3122 |
#ifndef NO_PRIM_STRING |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3123 |
if (__isCharacter(aCharacter)) { |
20033 | 3124 |
unsigned int cVal = __intVal(__characterVal(aCharacter)); |
3125 |
||
3126 |
if ((cVal <= 0xFF) && __qIsStringLike(self)) { |
|
3127 |
count = __stringSize(self); |
|
3128 |
sz = OHDR_SIZE + count + 1 + 1; |
|
3129 |
||
3130 |
__PROTECT_CONTEXT__ |
|
3131 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
|
3132 |
__UNPROTECT_CONTEXT__ |
|
3133 |
||
3134 |
if (newString) { |
|
3135 |
__InstPtr(newString)->o_class = String; |
|
3136 |
__qSTORE(newString, String); |
|
3137 |
dstp = __stringVal(newString); |
|
2862 | 3138 |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3139 |
# ifdef bcopy4 |
20033 | 3140 |
{ |
3141 |
int nw = count >> 2; |
|
3142 |
char *srcp = (char *)__stringVal(self); |
|
3143 |
||
3144 |
if (count & 3) { |
|
3145 |
nw++; |
|
3146 |
} |
|
3147 |
bcopy4(srcp, dstp, nw); |
|
3148 |
dstp += count; |
|
3149 |
} |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3150 |
# else |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3151 |
# ifdef FAST_MEMCPY |
20033 | 3152 |
memcpy(dstp, __stringVal(self), count); |
3153 |
dstp += count; |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3154 |
# else |
20033 | 3155 |
{ |
3156 |
REGISTER unsigned char *srcp; |
|
3157 |
||
3158 |
srcp = __stringVal(self); |
|
3159 |
while ((*dstp = *srcp++) != '\0') |
|
3160 |
dstp++; |
|
3161 |
} |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
3162 |
# endif |
2887 | 3163 |
# endif |
20033 | 3164 |
*dstp++ = cVal; |
3165 |
*dstp = '\0'; |
|
3166 |
RETURN (newString ); |
|
3167 |
} |
|
3168 |
} |
|
608 | 3169 |
} |
2894 | 3170 |
#endif |
608 | 3171 |
%}. |
3172 |
"fall back in case of non-character arg; |
|
3173 |
will eventually lead to an bad element signal raise" |
|
3174 |
||
3175 |
^ super copyWith:aCharacter |
|
3176 |
! |
|
3177 |
||
2886 | 3178 |
deepCopy |
3179 |
"return a copy of the receiver" |
|
608 | 3180 |
|
3181 |
" |
|
3182 |
could be an instance of a subclass which needs deepCopy |
|
3183 |
of its named instvars ... |
|
3184 |
" |
|
16543 | 3185 |
(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
|
3186 |
^ self copyFrom:1 |
608 | 3187 |
]. |
3188 |
^ super deepCopy |
|
3189 |
! |
|
3190 |
||
10951 | 3191 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
8383 | 3192 |
"return a deep copy of the receiver - reimplemented to be a bit faster" |
608 | 3193 |
|
3194 |
" |
|
3195 |
could be an instance of a subclass which needs deepCopy |
|
3196 |
of its named instvars ... |
|
3197 |
" |
|
16543 | 3198 |
(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
|
3199 |
^ self copyFrom:1 |
608 | 3200 |
]. |
10951 | 3201 |
^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector |
608 | 3202 |
! |
3203 |
||
2886 | 3204 |
shallowCopy |
3205 |
"return a copy of the receiver" |
|
608 | 3206 |
|
16543 | 3207 |
(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
|
3208 |
^ self copyFrom:1 |
608 | 3209 |
]. |
3210 |
^ super shallowCopy |
|
3211 |
! |
|
3212 |
||
2886 | 3213 |
simpleDeepCopy |
3214 |
"return a copy of the receiver" |
|
608 | 3215 |
|
3216 |
" |
|
3217 |
could be an instance of a subclass which needs deepCopy |
|
3218 |
of its named instvars ... |
|
3219 |
" |
|
16543 | 3220 |
(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
|
3221 |
^ self copyFrom:1 |
608 | 3222 |
]. |
7881 | 3223 |
^ super simpleDeepCopy |
608 | 3224 |
! ! |
3225 |
||
14384
1082868a753c
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14353
diff
changeset
|
3226 |
|
4154 | 3227 |
!String methodsFor:'filling & replacing'! |
608 | 3228 |
|
2886 | 3229 |
atAllPut:aCharacter |
608 | 3230 |
"replace all elements with aCharacter |
1 | 3231 |
- reimplemented here for speed" |
3232 |
||
13 | 3233 |
%{ /* NOCONTEXT */ |
3234 |
||
608 | 3235 |
#ifndef FAST_MEMSET |
3236 |
REGISTER unsigned char *dst; |
|
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
3237 |
#endif |
608 | 3238 |
REGISTER int l; |
3239 |
REGISTER int byteValue; |
|
1 | 3240 |
|
608 | 3241 |
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
|
3242 |
byteValue = __intVal(__characterVal(aCharacter)); |
9473 | 3243 |
if ((unsigned)byteValue <= 0xFF) { |
3244 |
l = __stringSize(self); |
|
8898 | 3245 |
|
3246 |
#ifdef FAST_MEMSET |
|
9473 | 3247 |
if (l > 0) { |
3248 |
memset(__stringVal(self), byteValue, l); |
|
3249 |
} |
|
608 | 3250 |
#else |
9473 | 3251 |
{ |
3252 |
INT v; |
|
3253 |
||
3254 |
v = (byteValue << 8) | byteValue; |
|
3255 |
v = (v << 16) | v; |
|
3256 |
||
3257 |
dst = __stringVal(self); |
|
3712 | 3258 |
|
3259 |
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */ |
|
9473 | 3260 |
if (l > 0) { |
3261 |
memset4(dst, v, l>>2); |
|
3262 |
l = l & 3; |
|
3263 |
} |
|
3712 | 3264 |
# else |
3265 |
# ifdef UINT64 |
|
9473 | 3266 |
{ |
3267 |
UINT64 v64; |
|
3268 |
||
3269 |
v64 = v; |
|
3270 |
v64 = (v64 << 32) | v; |
|
3271 |
while (l >= 8) { |
|
3272 |
((UINT64 *)dst)[0] = v64; |
|
3273 |
dst += 8; |
|
3274 |
l -= 8; |
|
3275 |
} |
|
3276 |
} |
|
3712 | 3277 |
# else /* no UINT64 */ |
9473 | 3278 |
while (l >= 16) { |
3279 |
((int *)dst)[0] = v; |
|
3280 |
((int *)dst)[1] = v; |
|
3281 |
((int *)dst)[2] = v; |
|
3282 |
((int *)dst)[3] = v; |
|
3283 |
dst += 16; |
|
3284 |
l -= 16; |
|
3285 |
} |
|
3286 |
if (l >= 8) { |
|
3287 |
((int *)dst)[0] = v; |
|
3288 |
((int *)dst)[1] = v; |
|
3289 |
dst += 8; |
|
3290 |
l -= 8; |
|
3291 |
} |
|
3292 |
if (l >= 4) { |
|
3293 |
((int *)dst)[0] = v; |
|
3294 |
dst += 4; |
|
3295 |
l -= 4; |
|
3296 |
} |
|
3712 | 3297 |
# if 0 |
9473 | 3298 |
if (l >= 2) { |
3299 |
((short *)dst)[0] = v; |
|
3300 |
dst += 2; |
|
3301 |
l -= 2; |
|
3302 |
} |
|
3712 | 3303 |
# endif |
3304 |
||
5648 | 3305 |
# endif /* UINT64 */ |
3306 |
# endif /* FAST_MEMSET4 */ |
|
9473 | 3307 |
} |
3308 |
||
3309 |
/* |
|
3310 |
* remaining bytes |
|
3311 |
*/ |
|
3312 |
while (l-- > 0) |
|
3313 |
*dst++ = byteValue; |
|
3712 | 3314 |
|
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
3315 |
#endif /* no FAST_MEMSET */ |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
3316 |
|
9473 | 3317 |
RETURN ( self ); |
3318 |
} |
|
608 | 3319 |
} |
2862 | 3320 |
%}. |
608 | 3321 |
^ super atAllPut:aCharacter |
1 | 3322 |
|
608 | 3323 |
" |
8898 | 3324 |
(String new:10) atAllPut:$* |
3325 |
String new:10 withAll:$* |
|
608 | 3326 |
" |
3327 |
! |
|
3328 |
||
2929 | 3329 |
replaceAll:oldCharacter with:newCharacter |
4120 | 3330 |
"replace all oldCharacters by newCharacter in the receiver. |
3331 |
||
3332 |
Notice: This operation modifies the receiver, NOT a copy; |
|
3333 |
therefore the change may affect all others referencing the receiver." |
|
608 | 3334 |
|
3335 |
%{ /* NOCONTEXT */ |
|
3336 |
||
3337 |
REGISTER unsigned char *srcp; |
|
3338 |
REGISTER unsigned oldVal, newVal; |
|
4120 | 3339 |
unsigned char c, cNext; |
608 | 3340 |
|
3341 |
if (__isCharacter(oldCharacter) |
|
3342 |
&& __isCharacter(newCharacter) |
|
3343 |
&& __isString(self)) { |
|
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3344 |
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
|
3345 |
oldVal = __intVal(__characterVal(oldCharacter)); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3346 |
newVal = __intVal(__characterVal(newCharacter)); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3347 |
if ((oldVal <= 0xFF) |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3348 |
&& (newVal <= 0xFF)) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3349 |
cNext = *srcp; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3350 |
while ((c = cNext) != '\0') { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3351 |
cNext = srcp[1]; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3352 |
if (c == oldVal) |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3353 |
*srcp = newVal; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3354 |
srcp++; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3355 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3356 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3357 |
RETURN ( self ); |
1 | 3358 |
} |
2862 | 3359 |
%}. |
16203 | 3360 |
newCharacter isCharacter ifFalse:[self halt:'please change the sender']. |
2929 | 3361 |
^ super replaceAll:oldCharacter with:newCharacter |
51 | 3362 |
|
608 | 3363 |
" |
8898 | 3364 |
'helloWorld' copy replaceAll:$o with:$O |
3365 |
'helloWorld' copy replaceAll:$d with:$* |
|
3366 |
'helloWorld' copy replaceAll:$h with:$* |
|
608 | 3367 |
" |
3368 |
! |
|
1 | 3369 |
|
2886 | 3370 |
replaceFrom:start to:stop with:aString startingAt:repStart |
1 | 3371 |
"replace the characters starting at index start, anInteger and ending |
3372 |
at stop, anInteger with characters from aString starting at repStart. |
|
3234 | 3373 |
Return the receiver. |
1 | 3374 |
|
3375 |
- reimplemented here for speed" |
|
3376 |
||
3377 |
%{ /* NOCONTEXT */ |
|
18286 | 3378 |
#ifdef __SCHTEAM__ |
3379 |
if ( aString.isStringLike() |
|
3380 |
&& self.isStringLike() |
|
3381 |
&& start.isSmallInteger() |
|
3382 |
&& stop.isSmallInteger() |
|
3383 |
&& repStart.isSmallInteger()) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3384 |
STString me = self.asSTString(); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3385 |
STString other = aString.asSTString(); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3386 |
int _start = start.intValue() - 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3387 |
int _stop = stop.intValue() - 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3388 |
int _repStart = repStart.intValue() - 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3389 |
int mySize = me.characters.length; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3390 |
int otherSize = other.characters.length; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3391 |
int count = _stop - _start + 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3392 |
|
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3393 |
if (_start >= 0 |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3394 |
&& _repStart >= 0 |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3395 |
&& _stop < mySize |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3396 |
&& (_repStart + count) <= otherSize) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3397 |
if (count > 0) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3398 |
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
|
3399 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3400 |
return context._RETURN(self); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3401 |
} |
18286 | 3402 |
} |
3403 |
#else |
|
1 | 3404 |
|
3405 |
REGISTER unsigned char *srcp, *dstp; |
|
3406 |
REGISTER int count; |
|
3407 |
int len, index1, index2; |
|
3408 |
int repLen, repIndex; |
|
3409 |
||
18286 | 3410 |
# ifndef NO_PRIM_STRING |
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
3411 |
if (__isStringLike(aString) |
53 | 3412 |
&& __isString(self) |
252 | 3413 |
&& __bothSmallInteger(start, stop)) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3414 |
len = __stringSize(self); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3415 |
index1 = __intVal(start); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3416 |
index2 = __intVal(stop); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3417 |
count = index2 - index1 + 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3418 |
if (count <= 0) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3419 |
RETURN (self); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3420 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3421 |
if ((index2 <= len) && (index1 > 0)) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3422 |
repLen = __stringSize(aString); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3423 |
repIndex = __intVal(repStart); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3424 |
if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3425 |
srcp = __stringVal(aString) + repIndex - 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3426 |
dstp = __stringVal(self) + index1 - 1; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3427 |
if (aString == self) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3428 |
/* take care of overlapping copy */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3429 |
memmove(dstp, srcp, count); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3430 |
RETURN (self); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3431 |
} |
18286 | 3432 |
# ifdef bcopy4 |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3433 |
/* copy quadbytes if pointers are aligned */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3434 |
/* |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3435 |
* no sizeof(int) here please - |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3436 |
* - 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
|
3437 |
*/ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3438 |
if ((count > 12) |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3439 |
&& (((unsigned INT)srcp & 3) == 0) |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3440 |
&& (((unsigned INT)dstp & 3) == 0)) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3441 |
int n; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3442 |
|
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3443 |
n = count >> 2; /* make it quads */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3444 |
bcopy4(srcp, dstp, n); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3445 |
n <<= 2; /* back to chars */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3446 |
dstp += n; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3447 |
srcp += n; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3448 |
count -= n; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3449 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3450 |
while (count-- > 0) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3451 |
*dstp++ = *srcp++; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3452 |
} |
18286 | 3453 |
# else |
3454 |
# ifdef FAST_MEMCPY |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3455 |
memcpy(dstp, srcp, count); |
18286 | 3456 |
# else |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3457 |
/* copy longs if pointers are aligned */ |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3458 |
if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0) |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3459 |
&& (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3460 |
while (count >= sizeof(INT)) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3461 |
*((unsigned INT *)dstp) = *((unsigned INT *)srcp); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3462 |
dstp += sizeof(INT); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3463 |
srcp += sizeof(INT); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3464 |
count -= sizeof(INT); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3465 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3466 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3467 |
while (count-- > 0) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3468 |
*dstp++ = *srcp++; |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3469 |
} |
18286 | 3470 |
# endif |
3471 |
# endif |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3472 |
RETURN (self); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3473 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3474 |
} |
1 | 3475 |
} |
18286 | 3476 |
# endif |
3477 |
#endif /* not SCHTEAM */ |
|
2862 | 3478 |
%}. |
1 | 3479 |
^ super replaceFrom:start to:stop with:aString startingAt:repStart |
3480 |
! |
|
3481 |
||
3482 |
withoutSeparators |
|
8898 | 3483 |
"return a string containing the chars of myself |
2862 | 3484 |
without leading and trailing whitespace. |
3485 |
If there is no whitespace, the receiver is returned. |
|
95 | 3486 |
Notice, this is different from String>>withoutSpaces." |
1 | 3487 |
|
42 | 3488 |
|startIndex "{ Class: SmallInteger }" |
8898 | 3489 |
endIndex "{ Class: SmallInteger }" |
51 | 3490 |
sz| |
3491 |
||
53 | 3492 |
startIndex := 0. |
2862 | 3493 |
|
51 | 3494 |
%{ |
2884 | 3495 |
REGISTER unsigned char *cp; |
3496 |
REGISTER unsigned char *ep; |
|
3497 |
REGISTER unsigned char c; |
|
51 | 3498 |
REGISTER unsigned char *cp0; |
2884 | 3499 |
REGISTER unsigned char *ep0; |
1 | 3500 |
|
51 | 3501 |
/* ignore instances of subclasses ... */ |
329 | 3502 |
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
|
3503 |
cp = cp0 = __stringVal(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3504 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3505 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3506 |
* 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
|
3507 |
*/ |
19748 | 3508 |
#ifdef UINT64 |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3509 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3510 |
cp += 8; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3511 |
} |
329 | 3512 |
#endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3513 |
while (*((unsigned *)cp) == 0x20202020) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3514 |
cp += 4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3515 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3516 |
while ((c = *cp) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3517 |
&& (c <= ' ') |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3518 |
&& ((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
|
3519 |
|| (c == '\r') || (c == '\f')) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3520 |
) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3521 |
cp++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3522 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3523 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3524 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3525 |
* 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
|
3526 |
*/ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3527 |
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
|
3528 |
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
|
3529 |
c = *ep; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3530 |
while ((ep >= cp) && |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3531 |
(c <= ' ') && |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3532 |
((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
|
3533 |
|| (c == '\r') || (c == '\f'))) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3534 |
ep--; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3535 |
c = *ep; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3536 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3537 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3538 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3539 |
* no whiteSpace ? |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3540 |
*/ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3541 |
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
|
3542 |
RETURN(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3543 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3544 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3545 |
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
|
3546 |
endIndex = __mkSmallInteger(ep - cp0 + 1); |
51 | 3547 |
} |
202 | 3548 |
%}. |
3549 |
startIndex == 0 ifTrue:[^ super withoutSeparators]. |
|
3550 |
||
3551 |
startIndex > endIndex ifTrue:[^ '']. |
|
1 | 3552 |
^ self copyFrom:startIndex to:endIndex |
2884 | 3553 |
|
3554 |
" |
|
8898 | 3555 |
'hello' withoutSeparators |
3556 |
' hello' withoutSeparators |
|
3557 |
' hello ' withoutSeparators |
|
3558 |
' hello ' withoutSeparators |
|
3559 |
' hello ' withoutSeparators |
|
2884 | 3560 |
' hello ' withoutSeparators |
8898 | 3561 |
' ' withoutSeparators |
2884 | 3562 |
" |
608 | 3563 |
! |
3564 |
||
3565 |
withoutSpaces |
|
8898 | 3566 |
"return a string containing the characters of myself |
2862 | 3567 |
without leading and trailing spaces. |
2884 | 3568 |
If there are no spaces, the receiver is returned unchanged. |
608 | 3569 |
Notice, this is different from String>>withoutSeparators." |
3570 |
||
3571 |
|startIndex "{ Class: SmallInteger }" |
|
8898 | 3572 |
endIndex "{ Class: SmallInteger }" |
608 | 3573 |
sz blank| |
3574 |
||
3575 |
startIndex := 0. |
|
3576 |
%{ |
|
3577 |
REGISTER unsigned char *cp; |
|
2884 | 3578 |
REGISTER unsigned char *ep; |
3579 |
unsigned char *cp0; |
|
3580 |
unsigned char *ep0; |
|
608 | 3581 |
|
3582 |
/* ignore instances of subclasses ... */ |
|
3583 |
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
|
3584 |
cp = cp0 = __stringVal(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3585 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3586 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3587 |
* 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
|
3588 |
*/ |
19748 | 3589 |
#ifdef UINT64 |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3590 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3591 |
cp += 8; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3592 |
} |
19748 | 3593 |
#endif /* UINT64 */ |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3594 |
while (*((unsigned *)cp) == 0x20202020) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3595 |
cp += 4; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3596 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3597 |
while (*cp == ' ') cp++; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3598 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3599 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3600 |
* 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
|
3601 |
*/ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3602 |
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
|
3603 |
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
|
3604 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3605 |
/* |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3606 |
* no blanks ? |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3607 |
*/ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3608 |
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
|
3609 |
RETURN(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3610 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3611 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3612 |
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
|
3613 |
endIndex = __mkSmallInteger(ep - cp0 + 1); |
608 | 3614 |
} |
3615 |
%}. |
|
3616 |
startIndex == 0 ifTrue:[^ super withoutSpaces]. |
|
3617 |
||
3618 |
startIndex > endIndex ifTrue:[^ '']. |
|
2886 | 3619 |
((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self]. |
608 | 3620 |
^ self copyFrom:startIndex to:endIndex |
2884 | 3621 |
|
3622 |
" |
|
8898 | 3623 |
' hello' withoutSpaces |
3624 |
' hello ' withoutSpaces |
|
3625 |
' hello ' withoutSpaces |
|
3626 |
' hello ' withoutSpaces |
|
2884 | 3627 |
' hello ' withoutSpaces |
8898 | 3628 |
' ' withoutSpaces |
2884 | 3629 |
" |
608 | 3630 |
! ! |
3631 |
||
3632 |
!String methodsFor:'printing & storing'! |
|
3633 |
||
16393 | 3634 |
displayString |
3635 |
"return a string used when displaying the receiver in a view." |
|
3636 |
||
18215 | 3637 |
^ super displayString. |
17539 | 3638 |
"/ ^ self storeString. |
3639 |
||
3640 |
" |
|
3641 |
'hello' -> 'hello' |
|
3642 |
" |
|
16393 | 3643 |
! |
3644 |
||
14163 | 3645 |
errorPrint |
15536 | 3646 |
"print the receiver on standard error, if the global Stderr is nil; |
3647 |
otherwise, fall back to the inherited errorPrint, which sends the string to |
|
3648 |
the Stderr stream. |
|
14163 | 3649 |
This method does NOT (by purpose) use the stream classes and |
15536 | 3650 |
will therefore work even in case of emergency during early startup |
3651 |
(but only, as long as Stderr is nil, which is set later after startup)." |
|
14163 | 3652 |
|
3653 |
%{ /* NOCONTEXT */ |
|
18286 | 3654 |
#ifdef __SCHTEAM__ |
3655 |
if (@global(Stderr) == STObject.Nil) { |
|
3656 |
if (self.isStringLike()) { |
|
18999 | 3657 |
org.exept.stj.STSystem.err.print(self.asString()); |
18286 | 3658 |
return context._RETURN(self); |
3659 |
} |
|
3660 |
} |
|
3661 |
#else |
|
15440 | 3662 |
if (@global(Stderr) == nil) { |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3663 |
if (__qIsStringLike(self)) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3664 |
console_fprintf(stderr, "%s" , __stringVal(self)); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3665 |
console_fflush(stderr); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3666 |
RETURN (self); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3667 |
} |
14163 | 3668 |
} |
18286 | 3669 |
#endif /* not SCHTEAM */ |
14163 | 3670 |
%}. |
16253 | 3671 |
super errorPrint |
14664 | 3672 |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3673 |
" |
14664 | 3674 |
'hello world' asUnicode16String errorPrint |
3675 |
(Character value:356) asString errorPrint |
|
19839 | 3676 |
'Bönnigheim' errorPrint |
3677 |
'Bönnigheim' asUnicodeString errorPrint |
|
14664 | 3678 |
" |
14163 | 3679 |
! |
3680 |
||
3681 |
errorPrintCR |
|
15536 | 3682 |
"print the receiver on standard error, followed by a cr, |
3683 |
if the global Stderr is nil; otherwise, fall back to the inherited errorPrintCR, |
|
3684 |
which sends the string to the Stderr stream. |
|
14163 | 3685 |
This method does NOT (by purpose) use the stream classes and |
15536 | 3686 |
will therefore work even in case of emergency during early startup |
3687 |
(but only, as long as Stderr is nil, which is set later after startup)." |
|
14163 | 3688 |
|
3689 |
%{ /* NOCONTEXT */ |
|
18286 | 3690 |
#ifdef __SCHTEAM__ |
3691 |
if (@global(Stderr) == STObject.Nil) { |
|
3692 |
if (self.isStringLike()) { |
|
18999 | 3693 |
org.exept.stj.STSystem.err.println(self.asString()); |
18286 | 3694 |
return context._RETURN(self); |
3695 |
} |
|
3696 |
} |
|
3697 |
#else |
|
15440 | 3698 |
if (@global(Stderr) == nil) { |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3699 |
if (__qIsStringLike(self)) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3700 |
console_fprintf(stderr, "%s\n" , __stringVal(self)); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3701 |
console_fflush(stderr); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3702 |
RETURN (self); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
3703 |
} |
14163 | 3704 |
} |
18286 | 3705 |
#endif |
14163 | 3706 |
%}. |
16253 | 3707 |
super errorPrintCR |
14163 | 3708 |
! |
3709 |
||
2886 | 3710 |
|
15536 | 3711 |
"print the receiver on standard output, if the global Stdout is nil; |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3712 |
otherwise, fall back to the inherited print, |
19383 | 3713 |
which sends the string to the Stdout stream. |
8898 | 3714 |
This method does NOT (by purpose) use the stream classes and |
15536 | 3715 |
will therefore work even in case of emergency during early startup |
3716 |
(but only, as long as Stdout is nil, which is set later after startup)." |
|
608 | 3717 |
|
3718 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
3719 |
#ifdef __SCHTEAM__ |
18668 | 3720 |
if (STSmalltalkEnvironment.GetBindingOrNull(STSymbol._new("Stdout")) == null) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3721 |
org.exept.stj.STSystem.out.print(self.toString()); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3722 |
return context._RETURN(self); |
18215 | 3723 |
} |
3724 |
#else |
|
15440 | 3725 |
if (@global(Stdout) == nil) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3726 |
if (__qIsStringLike(self)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3727 |
console_fprintf(stdout, "%s" , __stringVal(self)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3728 |
console_fflush(stdout); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3729 |
RETURN (self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
3730 |
} |
608 | 3731 |
} |
18215 | 3732 |
#endif |
3751 | 3733 |
%}. |
16253 | 3734 |
super print |
608 | 3735 |
! |
3736 |
||
3751 | 3737 |
printCR |
15536 | 3738 |
"print the receiver on standard output, followed by a cr, |
3739 |
if the global Stdout is nil; otherwise, fall back to the inherited errorPrintCR, |
|
3740 |
which sends the string to the Stdout stream. |
|
8898 | 3741 |
This method does NOT (by purpose) use the stream classes and |
15536 | 3742 |
will therefore work even in case of emergency during early startup |
3743 |
(but only, as long as Stdout is nil, which is set later after startup)." |
|
3751 | 3744 |
|
3745 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
3746 |
#ifdef __SCHTEAM__ |
18668 | 3747 |
if (STSmalltalkEnvironment.GetBindingOrNull(STSymbol._new("Stdout")) == null) { |
18999 | 3748 |
org.exept.stj.STSystem.out.println(self.toString()); |
3749 |
return context._RETURN(self); |
|
18215 | 3750 |
} |
3751 |
#else |
|
15440 | 3752 |
if (@global(Stdout) == nil) { |
18999 | 3753 |
if (__qIsStringLike(self)) { |
3754 |
console_fprintf(stdout, "%s\n" , __stringVal(self)); |
|
3755 |
console_fflush(stdout); |
|
3756 |
RETURN (self); |
|
3757 |
} |
|
3751 | 3758 |
} |
18215 | 3759 |
#endif |
3751 | 3760 |
%}. |
16253 | 3761 |
super printCR |
3751 | 3762 |
! |
3763 |
||
2886 | 3764 |
printfPrintString:formatString |
7746 | 3765 |
"non-standard but sometimes useful. |
8898 | 3766 |
Return a printed representation of the receiver as specified by formatString, |
608 | 3767 |
which is defined by printf. |
11921 | 3768 |
This method is NONSTANDARD and may be removed without notice. |
15536 | 3769 |
WARNNG: this goes directly to the C-printf function and may therefore be inherently unsafe. |
11921 | 3770 |
Please use the printf: method, which is safe as it is completely implemented in Smalltalk." |
608 | 3771 |
|
3772 |
%{ /* STACK: 1000 */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
3773 |
#ifndef __SCHTEAM__ |
608 | 3774 |
char buffer[800]; |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3775 |
char *buf = buffer; |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3776 |
int bufsize = sizeof(buffer); |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3777 |
char *mallocbuf = NULL; |
608 | 3778 |
char *cp; |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3779 |
int len; |
608 | 3780 |
OBJ s; |
8898 | 3781 |
extern void *malloc(); |
608 | 3782 |
|
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
3783 |
if (__isStringLike(formatString)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3784 |
cp = (char *)__stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3785 |
if (__qClass(self) != String) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3786 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3787 |
} |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3788 |
again: |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3789 |
/* |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3790 |
* actually only needed on sparc: since thisContext is |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3791 |
* in a global register, which gets destroyed by printf, |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3792 |
* manually save it here - very stupid ... |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3793 |
*/ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3794 |
__BEGIN_PROTECT_REGISTERS__ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3795 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3796 |
len = snprintf(buf, bufsize, (char *)__stringVal(formatString), cp); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3797 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3798 |
__END_PROTECT_REGISTERS__ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3799 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3800 |
if ((len < 0) || (len > bufsize)) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3801 |
if (len < 0) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3802 |
bufsize = bufsize * 2; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3803 |
} else { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3804 |
bufsize = len + 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3805 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3806 |
if (mallocbuf) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3807 |
free(mallocbuf); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3808 |
buf = mallocbuf = malloc(bufsize); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3809 |
if (buf == NULL) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3810 |
goto fail; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3811 |
goto again; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3812 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3813 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3814 |
s = __MKSTRING_L(buf, len); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3815 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3816 |
if (mallocbuf) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3817 |
free(mallocbuf); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3818 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3819 |
if (s != nil) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3820 |
RETURN (s); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
3821 |
} |
608 | 3822 |
} |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3823 |
fail:; |
18215 | 3824 |
#endif |
608 | 3825 |
%}. |
3826 |
self primitiveFailed |
|
3827 |
||
3828 |
" |
|
8898 | 3829 |
'hello' printfPrintString:'%%s -> %s' |
3830 |
(String new:900) printfPrintString:'%%s -> %s' |
|
3831 |
'hello' printfPrintString:'%%10s -> %10s' |
|
3832 |
'hello' printfPrintString:'%%-10s -> %-10s' |
|
3833 |
'hello' printfPrintString:'%%900s -> %900s' |
|
3834 |
'hello' printfPrintString:'%%-900s -> %-900s' |
|
608 | 3835 |
" |
3836 |
! |
|
3837 |
||
2886 | 3838 |
storeOn:aStream |
608 | 3839 |
"put the storeString of myself on aStream" |
3840 |
||
7599
188489aaaacd
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7338
diff
changeset
|
3841 |
aStream nextPut:$'. |
608 | 3842 |
(self includes:$') ifTrue:[ |
9473 | 3843 |
self printWithQuotesDoubledOn:aStream |
608 | 3844 |
] ifFalse:[ |
9473 | 3845 |
aStream nextPutAll:self |
608 | 3846 |
]. |
3847 |
aStream nextPut:$' |
|
3579 | 3848 |
|
3849 |
"Modified: / 15.6.1998 / 17:21:51 / cg" |
|
608 | 3850 |
! |
3851 |
||
2886 | 3852 |
storeString |
3853 |
"return a String for storing myself" |
|
608 | 3854 |
|
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8038
diff
changeset
|
3855 |
^ self basicStoreString. |
1 | 3856 |
! ! |
3857 |
||
3858 |
!String methodsFor:'queries'! |
|
3859 |
||
5557 | 3860 |
basicSize |
3861 |
"return the number of characters in myself. |
|
3862 |
Redefined here to exclude the 0-byte at the end." |
|
3863 |
||
3864 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
3865 |
#ifdef __SCHTEAM__ |
18404 | 3866 |
return context._RETURN( STInteger._new( self.basicSize() ) ); |
18215 | 3867 |
#else |
5557 | 3868 |
REGISTER OBJ slf, cls; |
3869 |
||
3870 |
slf = self; |
|
3871 |
cls = __qClass(slf); |
|
3872 |
if (cls == String) { |
|
20068 | 3873 |
RETURN ( __mkSmallInteger(__stringSize(slf)) ); |
5557 | 3874 |
} |
8913 | 3875 |
RETURN ( __mkSmallInteger(__stringSize(slf) |
20068 | 3876 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
18215 | 3877 |
#endif |
5557 | 3878 |
%}. |
3879 |
^ super basicSize - 1 |
|
3880 |
! |
|
3881 |
||
2886 | 3882 |
bitsPerCharacter |
1239 | 3883 |
"return the number of bits each character has. |
3884 |
Here, 8 is returned (storing single byte characters)." |
|
3885 |
||
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
3886 |
^ 8 |
1239 | 3887 |
|
3888 |
"Modified: 20.4.1996 / 23:08:42 / cg" |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
3889 |
! |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
3890 |
|
19759 | 3891 |
bytesPerCharacter |
3892 |
"return the number of bytes each character has. |
|
3893 |
Here, 1 is returned (storing single byte characters)." |
|
3894 |
||
3895 |
^ 1 |
|
3896 |
! |
|
3897 |
||
18594 | 3898 |
characterSize |
3899 |
"answer the size in bits of my largest character (actually only 7 or 8)" |
|
3900 |
||
3901 |
%{ /* NOCONTEXT */ |
|
3902 |
||
3903 |
REGISTER unsigned char *cp = __stringVal(self); |
|
3904 |
REGISTER unsigned char *last = cp + __stringSize(self); |
|
3905 |
||
3906 |
if (!__isStringLike(self)) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3907 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
18594 | 3908 |
} |
3909 |
#if __POINTER_SIZE__ == 8 |
|
3910 |
if (sizeof(unsigned INT) == 8) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3911 |
for ( ; (cp+8) <= last; cp += 8) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3912 |
if (*(unsigned INT *)cp & 0x8080808080808080) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3913 |
RETURN ( __mkSmallInteger(8) ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3914 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3915 |
} |
18594 | 3916 |
} |
3917 |
#endif |
|
3918 |
if (sizeof(int) == 4) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3919 |
for ( ; (cp+4) <= last; cp += 4) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3920 |
if (*(unsigned int *)cp & 0x80808080) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3921 |
RETURN ( __mkSmallInteger(8) ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3922 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3923 |
} |
18594 | 3924 |
} |
3925 |
for ( ; (cp+2) <= last; cp += 2) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3926 |
if (*(unsigned short *)cp & 0x8080) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3927 |
RETURN ( __mkSmallInteger(8) ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3928 |
} |
18594 | 3929 |
} |
3930 |
for ( ; cp < last; cp++) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3931 |
if (*cp & 0x80) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3932 |
RETURN ( __mkSmallInteger(8) ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3933 |
} |
18594 | 3934 |
} |
3935 |
RETURN ( __mkSmallInteger(7) ); |
|
3936 |
%}. |
|
3937 |
^ super characterSize |
|
3938 |
||
3939 |
" |
|
3940 |
'hello world' characterSize |
|
3941 |
'hello world' asUnicode16String characterSize |
|
3942 |
('hello world' , (Character value:16r88) asString) characterSize |
|
3943 |
" |
|
18587 | 3944 |
! |
3945 |
||
18594 | 3946 |
containsNon7BitAscii |
8898 | 3947 |
"return true, if the underlying string contains 8BitCharacters (or widers) |
8458 | 3948 |
(i.e. if it is non-ascii)" |
3949 |
||
3950 |
%{ /* NOCONTEXT */ |
|
3951 |
||
18594 | 3952 |
REGISTER unsigned char *cp = __stringVal(self); |
3953 |
REGISTER unsigned char *last = cp + __stringSize(self); |
|
3954 |
||
3955 |
if (!__isStringLike(self)) { |
|
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3956 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
9268
0d06a0818b52
contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents:
9233
diff
changeset
|
3957 |
} |
10371 | 3958 |
#if __POINTER_SIZE__ == 8 |
18594 | 3959 |
if (sizeof(unsigned INT) == 8) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3960 |
for ( ; (cp+8) <= last; cp += 8) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3961 |
if (*(unsigned INT *)cp & 0x8080808080808080) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3962 |
RETURN ( true ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3963 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3964 |
} |
8458 | 3965 |
} |
10371 | 3966 |
#endif |
9268
0d06a0818b52
contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents:
9233
diff
changeset
|
3967 |
if (sizeof(int) == 4) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3968 |
for ( ; (cp+4) <= last; cp += 4) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3969 |
if (*(unsigned int *)cp & 0x80808080) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3970 |
RETURN ( true ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3971 |
} |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3972 |
} |
9268
0d06a0818b52
contains8BitChars int-size indep.
Claus Gittinger <cg@exept.de>
parents:
9233
diff
changeset
|
3973 |
} |
18594 | 3974 |
for ( ; (cp+2) <= last; cp += 2) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3975 |
if (*(unsigned short *)cp & 0x8080) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3976 |
RETURN ( true ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3977 |
} |
8915
eb2652ce257d
fixed includes/indexOf for subclasses of string with instVars;
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
3978 |
} |
18594 | 3979 |
for ( ; cp < last; cp++) { |
18660
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3980 |
if (*cp & 0x80) { |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3981 |
RETURN ( true ); |
c77c8916b3e5
added a tuned version of asLowercase
Claus Gittinger <cg@exept.de>
parents:
18622
diff
changeset
|
3982 |
} |
8458 | 3983 |
} |
3984 |
RETURN (false); |
|
3985 |
%}. |
|
18594 | 3986 |
^ super containsNon7BitAscii |
8458 | 3987 |
|
3988 |
" |
|
18594 | 3989 |
'hello world' containsNon7BitAscii |
3990 |
'hello world' asTwoByteString containsNon7BitAscii |
|
3991 |
('hello world' , (Character value:16r88) asString) containsNon7BitAscii |
|
8458 | 3992 |
" |
3993 |
! |
|
3994 |
||
18968 | 3995 |
containsNon8BitElements |
3996 |
"return true, if the underlying string contains elements larger than a single byte" |
|
3997 |
||
3998 |
^ false. |
|
3999 |
! |
|
4000 |
||
14556 | 4001 |
isWideString |
19579 | 4002 |
"true if I require more than one byte per character" |
4003 |
||
14556 | 4004 |
^ false |
4005 |
! |
|
4006 |
||
2886 | 4007 |
knownAsSymbol |
4008 |
"return true, if there is a symbol with same characters in the |
|
2862 | 4009 |
system. |
4010 |
Can be used to check for existance of a symbol without creating one" |
|
608 | 4011 |
|
4012 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4013 |
#ifdef __SCHTEAM__ |
18405 | 4014 |
return context._RETURN( (STSymbol.asSymbolIfInterned(self.asSTString().asString()) != null) ? STObject.True : STObject.False ); |
18215 | 4015 |
#else |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4016 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4017 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4018 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4019 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4020 |
if (cls != String) { |
9473 | 4021 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4022 |
} else { |
9473 | 4023 |
indx = 0; |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4024 |
} |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4025 |
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
|
4026 |
#endif /* ! __SCHTEAM__ */ |
5407 | 4027 |
%}. |
6007 | 4028 |
"/ ^ self asSymbolIfInterned notNil. |
5407 | 4029 |
self primitiveFailed |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4030 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4031 |
" |
8898 | 4032 |
'hello' knownAsSymbol |
4033 |
'fooBarBaz' knownAsSymbol |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4034 |
" |
5557 | 4035 |
! |
4036 |
||
4037 |
size |
|
4038 |
"return the number of characters in myself. |
|
4039 |
Reimplemented here to avoid the additional size->basicSize send |
|
4040 |
(which we can do here, since size is obviously not redefined in a subclass). |
|
4041 |
This method is the same as basicSize." |
|
4042 |
||
4043 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4044 |
#ifdef __SCHTEAM__ |
18404 | 4045 |
return context._RETURN( STInteger._new( self.basicSize() ) ); |
18215 | 4046 |
#else |
5557 | 4047 |
REGISTER OBJ cls, slf; |
4048 |
||
4049 |
slf = self; |
|
4050 |
cls = __qClass(slf); |
|
4051 |
if (cls == String) { |
|
9473 | 4052 |
RETURN ( __mkSmallInteger(__stringSize(slf)) ); |
5557 | 4053 |
} |
8913 | 4054 |
RETURN ( __mkSmallInteger(__stringSize(slf) |
9473 | 4055 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
18215 | 4056 |
#endif |
5557 | 4057 |
%}. |
4058 |
^ self basicSize |
|
8038 | 4059 |
! |
4060 |
||
4061 |
stringSpecies |
|
15525 | 4062 |
^ self species |
19839 | 4063 |
! |
4064 |
||
4065 |
utf8DecodedMaxBytes |
|
4066 |
"return the number of charcters needed when this string is |
|
4067 |
decoded from UTF-8." |
|
4068 |
||
4069 |
%{ /* NOCONTEXT */ |
|
4070 |
||
4071 |
unsigned char *cp = __stringVal(self); |
|
4072 |
unsigned char *last = cp + __stringSize(self); |
|
4073 |
int max = 1; |
|
19877 | 4074 |
|
19839 | 4075 |
if (!__isStringLike(self)) { |
19877 | 4076 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
19839 | 4077 |
} |
4078 |
||
4079 |
for ( ; cp < last; cp++) { |
|
19877 | 4080 |
unsigned char mask = *cp & 0xF0; |
4081 |
if (mask != 0) { |
|
4082 |
if ((mask & 0xE0 )== 0xC0) { if (max < 2) max = 2; } |
|
4083 |
else if (mask == 0xE0) { if (max < 3) max = 3; } |
|
4084 |
else if (mask == 0xF0) { max = 4; break;} |
|
4085 |
} |
|
19839 | 4086 |
} |
4087 |
RETURN (__mkSmallInteger(max)); |
|
4088 |
%}. |
|
4089 |
||
4090 |
" |
|
4091 |
'hello world' utf8DecodedMaxBytes |
|
4092 |
'ä' utf8Encoded utf8DecodedMaxBytes |
|
4093 |
'äΣΔΨӕἤῴ' utf8Encoded utf8DecodedMaxBytes |
|
4094 |
" |
|
4095 |
! |
|
4096 |
||
4097 |
utf8DecodedSize |
|
4098 |
"return the number of charcters needed when this string is |
|
4099 |
decoded from UTF-8." |
|
4100 |
||
4101 |
%{ /* NOCONTEXT */ |
|
4102 |
||
4103 |
unsigned char *cp = __stringVal(self); |
|
4104 |
unsigned char *last = cp + __stringSize(self); |
|
4105 |
unsigned INT len = 0; |
|
4106 |
||
4107 |
if (!__isStringLike(self)) { |
|
19877 | 4108 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
19839 | 4109 |
} |
4110 |
// count the number of start-bytes |
|
4111 |
for ( ; cp < last; cp++) { |
|
19877 | 4112 |
if ((*cp & 0xC0) != 0x80) len++; |
19839 | 4113 |
} |
4114 |
RETURN (__mkSmallInteger(len)); |
|
4115 |
%}. |
|
4116 |
||
4117 |
" |
|
4118 |
'hello world' utf8DecodedSize |
|
4119 |
'ä' utf8Encoded utf8DecodedSize |
|
4120 |
'äΣΔΨӕἤῴ' utf8Encoded utf8DecodedSize |
|
4121 |
" |
|
1 | 4122 |
! ! |
608 | 4123 |
|
11267 | 4124 |
!String methodsFor:'sorting & reordering'! |
4125 |
||
4126 |
reverse |
|
4127 |
"in-place reverse the characters of the string. |
|
4128 |
WARNING: this is a destructive operation, which modifies the receiver. |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4129 |
Please use reversed (with a d) for a functional version." |
11267 | 4130 |
|
4131 |
"Q: is there a need to redefine it here ?" |
|
4132 |
||
4133 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4134 |
#ifndef __SCHTEAM__ |
11267 | 4135 |
REGISTER char c; |
4136 |
REGISTER unsigned char *hip, *lowp; |
|
4137 |
||
4138 |
if (__isString(self)) { |
|
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4139 |
lowp = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4140 |
hip = lowp + __stringSize(self) - 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4141 |
while (lowp < hip) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4142 |
c = *lowp; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4143 |
*lowp = *hip; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4144 |
*hip = c; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4145 |
lowp++; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4146 |
hip--; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4147 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4148 |
RETURN ( self ); |
11267 | 4149 |
} |
18215 | 4150 |
#endif |
11267 | 4151 |
%}. |
4152 |
^ super reverse |
|
4153 |
! ! |
|
10820 | 4154 |
|
19790 | 4155 |
|
11346 | 4156 |
!String methodsFor:'substring searching'! |
4157 |
||
4158 |
indexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive |
|
11347
7819f5148ca1
Boyer Moore algorithm for fast string search.
Claus Gittinger <cg@exept.de>
parents:
11346
diff
changeset
|
4159 |
"redefined as primitive for maximum speed (BM)" |
11346 | 4160 |
|
4161 |
|notFound| |
|
4162 |
||
14384
1082868a753c
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14353
diff
changeset
|
4163 |
%{ /* STACK:4000 */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4164 |
#ifndef __SCHTEAM__ |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4165 |
if (__qIsStringLike(self) |
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
4166 |
&& __isStringLike(aSubString) |
11346 | 4167 |
&& (caseSensitive == true) |
4168 |
&& (__isSmallInteger(startIndex)) |
|
4169 |
&& (__intVal(startIndex) > 0) |
|
4170 |
) { |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4171 |
unsigned char *y = __stringVal(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4172 |
unsigned char *x = __stringVal(aSubString); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4173 |
int m = __stringSize(aSubString); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4174 |
int n = __stringSize(self); |
14301
d8e7b4196d5e
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14297
diff
changeset
|
4175 |
# define MAX_PATTERN_SIZE 128 |
11346 | 4176 |
# define XSIZE 256 |
4177 |
# define ASIZE 256 |
|
4178 |
# define MAX(a,b) (a>b ? a : b) |
|
4179 |
||
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4180 |
if (m == 0) { |
11824
20754d2d3b37
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11418
diff
changeset
|
4181 |
#if 1 |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4182 |
/* empty string does not match */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4183 |
RETURN(__mkSmallInteger(0)); |
11824
20754d2d3b37
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11418
diff
changeset
|
4184 |
#else |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4185 |
/* empty string matches */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4186 |
RETURN(startIndex); |
11824
20754d2d3b37
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11418
diff
changeset
|
4187 |
#endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4188 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4189 |
if (m <= XSIZE) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4190 |
int i, j; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4191 |
static int lastPatternSize = 0; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4192 |
static char lastPattern[MAX_PATTERN_SIZE+1] = { 0 }; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4193 |
static int bmGs[XSIZE+1], bmBc[ASIZE]; |
11346 | 4194 |
|
4195 |
# define preBmBc(x, m, bmBc) { \ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4196 |
int i; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4197 |
\ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4198 |
for (i = 0; i < ASIZE; ++i) \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4199 |
bmBc[i] = m; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4200 |
for (i = 0; i < m - 1; ++i) \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4201 |
bmBc[x[i]] = m - i - 1; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4202 |
} |
11346 | 4203 |
|
4204 |
# define suffixes(x, m, suff) { \ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4205 |
int f, g, i; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4206 |
\ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4207 |
suff[m - 1] = m; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4208 |
g = m - 1; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4209 |
for (i = m - 2; i >= 0; --i) { \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4210 |
if (i > g && suff[i + m - 1 - f] < i - g) \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4211 |
suff[i] = suff[i + m - 1 - f]; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4212 |
else { \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4213 |
if (i < g) \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4214 |
g = i; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4215 |
f = i; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4216 |
while (g >= 0 && x[g] == x[g + m - 1 - f]) \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4217 |
--g; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4218 |
suff[i] = f - g; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4219 |
} \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4220 |
} \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4221 |
} |
11346 | 4222 |
|
4223 |
# define preBmGs(x, m, bmGs) { \ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4224 |
int i, j, suff[XSIZE]; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4225 |
\ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4226 |
suffixes(x, m, suff); \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4227 |
\ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4228 |
for (i = 0; i < m; ++i) \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4229 |
bmGs[i] = m; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4230 |
j = 0; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4231 |
for (i = m - 1; i >= 0; --i) \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4232 |
if (suff[i] == i + 1) \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4233 |
for (; j < m - 1 - i; ++j) \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4234 |
if (bmGs[j] == m) \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4235 |
bmGs[j] = m - 1 - i; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4236 |
for (i = 0; i <= m - 2; ++i) \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4237 |
bmGs[m - 1 - suff[i]] = m - 1 - i; \ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4238 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4239 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4240 |
/* tables only depend on pattern; so we can cache them in case the same string is searched again */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4241 |
if ((m == lastPatternSize) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4242 |
&& (strcmp(lastPattern, x) == 0)) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4243 |
/* tables are still valid */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4244 |
// printf("valid: \"%s\"\n", lastPattern); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4245 |
} else { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4246 |
/* Preprocessing */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4247 |
// printf("compute: \"%s\"\n", lastPattern); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4248 |
preBmGs(x, m, bmGs); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4249 |
preBmBc(x, m, bmBc); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4250 |
if (m <= MAX_PATTERN_SIZE) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4251 |
// printf("cache for: \"%s\"\n", lastPattern); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4252 |
strcpy(lastPattern, x); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4253 |
lastPatternSize = m; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4254 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4255 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4256 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4257 |
/* Searching */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4258 |
j = __intVal(startIndex) - 1; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4259 |
while (j <= n - m) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4260 |
for (i = m - 1; i >= 0 && x[i] == y[i + j]; --i); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4261 |
if (i < 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4262 |
RETURN (__mkSmallInteger(j+1)); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4263 |
j += bmGs[0]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4264 |
} else { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4265 |
int s1 = bmGs[i]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4266 |
int s2 = bmBc[y[i + j]] - m + 1 + i; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4267 |
j += MAX(s1, s2); |
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 |
notFound = true; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4271 |
} |
11346 | 4272 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4273 |
#endif /* ! __SCHTEAM__ */ |
11346 | 4274 |
%}. |
4275 |
notFound == true ifTrue:[ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4276 |
^ exceptionValue value. |
19715 | 4277 |
]. |
4278 |
^ self slowIndexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive |
|
4279 |
||
4280 |
"Modified: / 05-08-2012 / 12:27:31 / cg" |
|
4281 |
! |
|
4282 |
||
4283 |
slowIndexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive |
|
4284 |
"naive search fallback (non-BM). |
|
4285 |
Use this for short searchStrings (<= 2) |
|
4286 |
or for caseSensitive searches" |
|
4287 |
||
4288 |
|notFound| |
|
4289 |
||
4290 |
%{ |
|
4291 |
#ifndef __SCHTEAM__ |
|
4292 |
if (__qIsStringLike(self) |
|
4293 |
&& __isStringLike(aSubString) |
|
4294 |
&& (__isSmallInteger(startIndex)) |
|
4295 |
&& (__intVal(startIndex) > 0) |
|
4296 |
) { |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4297 |
unsigned char *c_pSelf = __stringVal(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4298 |
unsigned char *c_substring = __stringVal(aSubString); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4299 |
unsigned char *c_pSelfI, *c_pSelfMax; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4300 |
int c_lenSelf = __stringSize(self); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4301 |
int c_lenSubstring = __stringSize(aSubString); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4302 |
int c_idx0Max = c_lenSelf - c_lenSubstring; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4303 |
unsigned char c_first; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4304 |
unsigned char c_ucFirst; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4305 |
unsigned char c_lcFirst; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4306 |
unsigned char c_oppositeCaseFirst; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4307 |
int i; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4308 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4309 |
if (c_lenSubstring == 0) { |
19715 | 4310 |
#if 1 |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4311 |
/* empty string does not match */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4312 |
notFound = true; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4313 |
goto getOutOfHere; |
19715 | 4314 |
#else |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4315 |
/* empty string matches */ |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4316 |
RETURN(startIndex); |
19715 | 4317 |
#endif |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4318 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4319 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4320 |
// searched string's length > string |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4321 |
if (c_idx0Max < 0) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4322 |
notFound = true; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4323 |
goto getOutOfHere; |
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 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4326 |
c_first = c_lcFirst = c_substring[0]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4327 |
if (((c_first >= 'A') && (c_first <= 'Z')) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4328 |
|| ((c_first >= 0xC0) && (c_first <= 0xDE))) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4329 |
c_ucFirst = c_first; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4330 |
c_lcFirst = c_oppositeCaseFirst = c_first - 'A' + 'a'; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4331 |
} else { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4332 |
if (((c_first >= 'a') && (c_first <= 'z')) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4333 |
|| ((c_first >= 0xE0) && (c_first <= 0xFE))) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4334 |
c_lcFirst = c_first; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4335 |
c_ucFirst = c_oppositeCaseFirst = c_first - 'a' + 'A'; |
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 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4338 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4339 |
// idx: |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4340 |
// 0123456789 |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4341 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4342 |
// 1234567890 - lenSelf = 10 |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4343 |
// abc - lenSubstring = 3 |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4344 |
// - idx0Max = 7 (last legal startIndex) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4345 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4346 |
i = __intVal(startIndex) - 1; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4347 |
c_pSelfI = c_pSelf + i; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4348 |
c_pSelfMax = c_pSelf + c_idx0Max; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4349 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4350 |
for (; c_pSelfI <= c_pSelfMax; c_pSelfI++) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4351 |
int j; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4352 |
unsigned char c_selfChar; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4353 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4354 |
// find the first char |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4355 |
c_selfChar = c_pSelfI[0]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4356 |
if (c_selfChar != c_first) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4357 |
if (caseSensitive == true) continue; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4358 |
if (c_selfChar != c_oppositeCaseFirst) { |
19715 | 4359 |
searchNext: ; |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4360 |
continue; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4361 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4362 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4363 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4364 |
// first char matches |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4365 |
// compare rest |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4366 |
for (j=1; j<c_lenSubstring; j++) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4367 |
unsigned char c_selfChar, c_subChar, c_lcSubChar, c_ucSubChar; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4368 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4369 |
c_subChar = c_substring[j]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4370 |
c_selfChar = c_pSelfI[j]; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4371 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4372 |
if (c_selfChar == c_subChar) continue; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4373 |
if (caseSensitive == true) goto searchNext; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4374 |
|
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4375 |
c_lcSubChar = c_subChar; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4376 |
if (((c_lcSubChar >= 'A') && (c_lcSubChar <= 'Z')) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4377 |
|| ((c_lcSubChar >= 0xC0) && (c_lcSubChar <= 0xDE))) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4378 |
c_lcSubChar = c_subChar - 'A' + 'a'; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4379 |
if (c_selfChar != c_lcSubChar) goto searchNext; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4380 |
} else { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4381 |
if (((c_lcSubChar >= 'a') && (c_lcSubChar <= 'z')) |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4382 |
|| ((c_lcSubChar >= 0xE0) && (c_lcSubChar <= 0xFE))) { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4383 |
c_ucSubChar = c_subChar - 'a' + 'A'; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4384 |
if (c_selfChar != c_ucSubChar) goto searchNext; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4385 |
} else { |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4386 |
goto searchNext; |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4387 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4388 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4389 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4390 |
// if we arrive here, we have a match at i |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4391 |
RETURN( __mkSmallInteger( c_pSelfI - c_pSelf + 1 ) ); |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4392 |
} |
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4393 |
notFound = true; |
19715 | 4394 |
} |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4395 |
|
19715 | 4396 |
getOutOfHere: ; |
4397 |
#endif /* ! __SCHTEAM__ */ |
|
4398 |
%}. |
|
4399 |
"/ arrive here if either not found, or invalid arguments |
|
4400 |
notFound == true ifTrue:[ |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4401 |
^ exceptionValue value. |
11346 | 4402 |
]. |
4403 |
^ super indexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive |
|
14301
d8e7b4196d5e
changed: #indexOfSubCollection:startingAt:ifAbsent:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
14297
diff
changeset
|
4404 |
|
19715 | 4405 |
" |
4406 |
'abcdefg' slowIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil caseSensitive:false |
|
4407 |
'abcdefg' slowIndexOfSubCollection:'bcd' startingAt:1 ifAbsent:nil caseSensitive:false |
|
4408 |
'abcdefg' slowIndexOfSubCollection:'cde' startingAt:1 ifAbsent:nil caseSensitive:false |
|
4409 |
'abcabcg' slowIndexOfSubCollection:'abc' startingAt:2 ifAbsent:nil caseSensitive:false |
|
4410 |
||
4411 |
'ABCDEFG' slowIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil caseSensitive:false |
|
4412 |
'ABCDEFG' slowIndexOfSubCollection:'Abc' startingAt:1 ifAbsent:nil caseSensitive:false |
|
4413 |
'ABCDEFG' slowIndexOfSubCollection:'aBC' startingAt:1 ifAbsent:nil caseSensitive:false |
|
4414 |
'ABCDEFG' slowIndexOfSubCollection:'ABC' startingAt:1 ifAbsent:nil caseSensitive:false |
|
4415 |
||
4416 |
'ABCDEFG' slowIndexOfSubCollection:'a' startingAt:1 ifAbsent:nil caseSensitive:false |
|
4417 |
'ABCDEFG' slowIndexOfSubCollection:'A' startingAt:1 ifAbsent:nil caseSensitive:false |
|
4418 |
||
4419 |
'ABCDEFG' slowIndexOfSubCollection:'bcd' startingAt:1 ifAbsent:nil caseSensitive:false |
|
4420 |
'ABCDEFG' slowIndexOfSubCollection:'cde' startingAt:1 ifAbsent:nil caseSensitive:false |
|
4421 |
'ABCABCG' slowIndexOfSubCollection:'abc' startingAt:2 ifAbsent:nil caseSensitive:false |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4422 |
|
19715 | 4423 |
'1234567890' slowIndexOfSubCollection:'abc' startingAt:1 ifAbsent:nil caseSensitive:false |
4424 |
'1234567890' slowIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil caseSensitive:false |
|
4425 |
'1234567890' slowIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil caseSensitive:true |
|
4426 |
'1234567890' slowIndexOfSubCollection:'234' startingAt:1 ifAbsent:nil caseSensitive:true |
|
4427 |
'1234567890' slowIndexOfSubCollection:'345' startingAt:1 ifAbsent:nil caseSensitive:true |
|
4428 |
'1231231231' slowIndexOfSubCollection:'123' startingAt:1 ifAbsent:nil caseSensitive:true |
|
4429 |
'1231231231' slowIndexOfSubCollection:'123' startingAt:2 ifAbsent:nil caseSensitive:true |
|
4430 |
'1231231231' slowIndexOfSubCollection:'123' startingAt:3 ifAbsent:nil caseSensitive:true |
|
4431 |
'1231231231' slowIndexOfSubCollection:'123' startingAt:4 ifAbsent:nil caseSensitive:true |
|
4432 |
'1231231231' slowIndexOfSubCollection:'123' startingAt:5 ifAbsent:nil caseSensitive:true |
|
4433 |
'1231231231' slowIndexOfSubCollection:'123' startingAt:6 ifAbsent:nil caseSensitive:true |
|
4434 |
'1231231231' slowIndexOfSubCollection:'123' startingAt:7 ifAbsent:nil caseSensitive:true |
|
4435 |
'1231231231' slowIndexOfSubCollection:'123' startingAt:8 ifAbsent:nil caseSensitive:true |
|
4436 |
'1231231231' slowIndexOfSubCollection:'123' startingAt:9 ifAbsent:nil caseSensitive:true |
|
4437 |
'1231231231' slowIndexOfSubCollection:'123' startingAt:10 ifAbsent:nil caseSensitive:true |
|
4438 |
'1231231231' slowIndexOfSubCollection:'123' startingAt:11 ifAbsent:nil caseSensitive:true |
|
4439 |
'1231231231' slowIndexOfSubCollection:'231' startingAt:1 ifAbsent:nil caseSensitive:true |
|
4440 |
'1231231231' slowIndexOfSubCollection:'231' startingAt:3 ifAbsent:nil caseSensitive:true |
|
4441 |
'1231231231' slowIndexOfSubCollection:'231' startingAt:5 ifAbsent:nil caseSensitive:true |
|
4442 |
'1231231231' slowIndexOfSubCollection:'231' startingAt:6 ifAbsent:nil caseSensitive:true |
|
4443 |
'1231231231' slowIndexOfSubCollection:'231' startingAt:8 ifAbsent:nil caseSensitive:true |
|
4444 |
'1231231231' slowIndexOfSubCollection:'231' startingAt:9 ifAbsent:nil caseSensitive:true |
|
4445 |
'1231231231' slowIndexOfSubCollection:'2310' startingAt:6 ifAbsent:nil caseSensitive:true |
|
4446 |
'1231231231' slowIndexOfSubCollection:'2310' startingAt:8 ifAbsent:nil caseSensitive:true |
|
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4447 |
" |
11346 | 4448 |
! ! |
4449 |
||
608 | 4450 |
!String methodsFor:'testing'! |
4451 |
||
2886 | 4452 |
endsWith:aStringOrChar |
16174 | 4453 |
"return true, if the receiver ends with something, aStringOrChar. |
4454 |
If aStringOrChar is an empty string, true is returned" |
|
1380 | 4455 |
|
4456 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4457 |
#ifndef __SCHTEAM__ |
1380 | 4458 |
int len1, len2; |
4459 |
REGISTER unsigned char *src1, *src2; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
4460 |
unsigned char c; |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
4461 |
REGISTER OBJ slf = self; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
4462 |
|
12485
121288c11396
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12454
diff
changeset
|
4463 |
if (__isStringLike(slf) && __isStringLike(aStringOrChar)) { |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4464 |
len1 = __qSize(slf); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4465 |
len2 = __qSize(aStringOrChar); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4466 |
if (len1 < len2) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4467 |
RETURN ( false ); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4468 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4469 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4470 |
src1 = __stringVal(slf) + (len1 - len2); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4471 |
src2 = __stringVal(aStringOrChar); |
18551
7f43475b5613
eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents:
18405
diff
changeset
|
4472 |
while ((c = *src2++) != '\0') { |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4473 |
if (c != *src1++) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4474 |
RETURN ( false ); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4475 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4476 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4477 |
RETURN (true); |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
4478 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
4479 |
if (__isCharacter(aStringOrChar)) { |
16889
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4480 |
int val; |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4481 |
|
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4482 |
val = __intVal(__characterVal(aStringOrChar)); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4483 |
if ((unsigned)val <= 0xFF) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4484 |
len1 = __stringSize(slf); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4485 |
if (len1 > 0) { |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4486 |
RETURN ( (__stringVal(slf)[len1-1] == val) ? true : false); |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4487 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4488 |
} |
18ebf0d880ba
refer to the VM's hash algorithm in String >> hash;
Claus Gittinger <cg@exept.de>
parents:
16773
diff
changeset
|
4489 |
RETURN ( false ); |
1380 | 4490 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4491 |
#endif /* ! __SCHTEAM__ */ |
1380 | 4492 |
%}. |
2862 | 4493 |
^ super endsWith:aStringOrChar |
1380 | 4494 |
|
4495 |
" |
|
4496 |
'hello world' endsWith:'world' |
|
4497 |
'hello world' endsWith:'earth' |
|
8898 | 4498 |
'hello world' endsWith:$d |
4499 |
'hello world' endsWith:$e |
|
4500 |
'' endsWith:$d |
|
1380 | 4501 |
'hello world' endsWith:#($r $l $d) |
8898 | 4502 |
'hello world' endsWith:'' |
1380 | 4503 |
" |
4504 |
! |
|
4505 |
||
2886 | 4506 |
isBlank |
19748 | 4507 |
"return true, if the receiver's size is 0 or if it contains only spaces. |
608 | 4508 |
Q: should we care for whiteSpace in general here ?" |
4509 |
||
4510 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4511 |
#ifndef __SCHTEAM__ |
608 | 4512 |
REGISTER unsigned char *src; |
4513 |
REGISTER unsigned char c; |
|
4514 |
OBJ cls; |
|
4515 |
||
1134 | 4516 |
src = __stringVal(self); |
608 | 4517 |
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
|
4518 |
src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
19748 | 4519 |
|
4520 |
# ifdef UINT64 |
|
2954 | 4521 |
while (*((UINT64 *)src) == 0x2020202020202020L) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4522 |
src += 8; |
2862 | 4523 |
} |
19748 | 4524 |
# endif /* UINT64 */ |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
4525 |
|
608 | 4526 |
while (*((unsigned *)src) == 0x20202020) { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4527 |
src += 4; |
608 | 4528 |
} |
2862 | 4529 |
|
18551
7f43475b5613
eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents:
18405
diff
changeset
|
4530 |
while ((c = *src++) == ' ') |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4531 |
;; /* just walking along */ |
18551
7f43475b5613
eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents:
18405
diff
changeset
|
4532 |
if (c != '\0') { |
19773
323213f1d992
memchr is now found in stdlib.h or string.h
Claus Gittinger <cg@exept.de>
parents:
19772
diff
changeset
|
4533 |
RETURN ( false ); |
2862 | 4534 |
} |
5407 | 4535 |
RETURN ( true ); |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4536 |
# endif /* ! __SCHTEAM__ */ |
608 | 4537 |
%}. |
5407 | 4538 |
^ super isBlank |
608 | 4539 |
! |
4540 |
||
5556 | 4541 |
isEmpty |
4542 |
"return true if the receiver is empty (i.e. if size == 0) |
|
4543 |
Redefined here for performance" |
|
4544 |
||
4545 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4546 |
#ifndef __SCHTEAM__ |
5556 | 4547 |
OBJ cls; |
4548 |
||
4549 |
cls = __qClass(self); |
|
4550 |
if ((cls == String) || (cls == Symbol)) { |
|
9473 | 4551 |
RETURN ( (__stringSize(self) == 0) ? true : false); |
5556 | 4552 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4553 |
#endif /* ! __SCHTEAM__ */ |
5556 | 4554 |
%}. |
4555 |
^ self size == 0 |
|
4556 |
! |
|
4557 |
||
10958 | 4558 |
isLiteral |
4559 |
"return true, if the receiver can be used as a literal constant in ST syntax |
|
4560 |
(i.e. can be used in constant arrays)" |
|
4561 |
||
4562 |
^ true |
|
4563 |
! |
|
4564 |
||
8647 | 4565 |
levenshteinTo:aString s:substWeight k:kbdTypoWeight c:caseWeight i:insrtWeight d:deleteWeight |
608 | 4566 |
"parametrized levenshtein. arguments are the costs for |
4567 |
substitution, case-change, insertion and deletion of a character." |
|
4568 |
||
1138
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
4569 |
%{ /* STACK: 2000 */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4570 |
#ifndef __SCHTEAM__ |
8898 | 4571 |
/* |
4572 |
* this is very heavy used when correcting errors |
|
608 | 4573 |
* (all symbols are searched for best match) - therefore it must be fast |
4574 |
*/ |
|
8647 | 4575 |
|
608 | 4576 |
unsigned short *data; |
4577 |
int l1, l2; |
|
4578 |
REGISTER int sz; |
|
4579 |
unsigned char *s1, *s2; |
|
8913 | 4580 |
int v1, v2, v3; |
4581 |
INT m; |
|
608 | 4582 |
REGISTER unsigned short *dp; |
8647 | 4583 |
REGISTER int rowDelta; |
608 | 4584 |
REGISTER int j; |
4585 |
int i; |
|
8647 | 4586 |
int iW, cW, sW, kW, dW; |
1486 | 4587 |
# define FASTSIZE 30 /* increase STACK if you increase this ... */ |
608 | 4588 |
unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)]; |
8898 | 4589 |
extern void *malloc(); |
608 | 4590 |
|
14664 | 4591 |
if (__qIsStringLike(self) && __isStringLike(aString) |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4592 |
&& __bothSmallInteger(insrtWeight, caseWeight) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4593 |
&& __bothSmallInteger(substWeight, deleteWeight) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4594 |
&& __isSmallInteger(kbdTypoWeight) |
8647 | 4595 |
) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4596 |
iW = __intVal(insrtWeight); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4597 |
cW = __intVal(caseWeight); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4598 |
sW = __intVal(substWeight); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4599 |
kW = __intVal(kbdTypoWeight); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4600 |
dW = __intVal(deleteWeight); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4601 |
s1 = __stringVal(self); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4602 |
s2 = __stringVal(aString); |
16019
b204c9d6ce6d
no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents:
15938
diff
changeset
|
4603 |
l1 = __stringSize(self); |
b204c9d6ce6d
no need to strlen to get the length of a String instance
Claus Gittinger <cg@exept.de>
parents:
15938
diff
changeset
|
4604 |
l2 = __stringSize(aString); |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4605 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4606 |
sz = (l1 < l2) ? l2 : l1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4607 |
rowDelta = sz + 1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4608 |
if (sz <= FASTSIZE) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4609 |
data = fastData; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4610 |
} else { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4611 |
/* add ifdef ALLOCA here ... */ |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4612 |
data = (unsigned short *)malloc(rowDelta * rowDelta * sizeof(short)); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4613 |
if (! data) goto mallocFailed; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4614 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4615 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4616 |
data[0] = 0; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4617 |
for (j=1, dp=data+1; j<=sz; j++, dp++) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4618 |
*dp = dp[-1] + iW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4619 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4620 |
for (i=1, dp=data+rowDelta; i<=sz; i++, dp+=rowDelta) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4621 |
*dp = dp[-rowDelta] + dW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4622 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4623 |
for (i=0; i<l1; i++) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4624 |
for (j=0; j<l2; j++) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4625 |
if (s1[i] == s2[j]) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4626 |
m = 0; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4627 |
else if (tolower(s1[i]) == tolower(s2[j])) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4628 |
m = cW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4629 |
else if (sW != kW && nextOnKeyboard(tolower(s1[i]), tolower(s2[j]))) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4630 |
m = kW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4631 |
else |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4632 |
m = sW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4633 |
|
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4634 |
dp = data + ((i+1)*rowDelta) + j; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4635 |
v2 = dp[0] + iW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4636 |
v1 = dp[-rowDelta] + m; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4637 |
v3 = dp[-rowDelta+1] + dW; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4638 |
if (v1 < v2) { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4639 |
if (v1 < v3) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4640 |
m = v1; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4641 |
else |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4642 |
m = v3; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4643 |
} else { |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4644 |
if (v2 < v3) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4645 |
m = v2; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4646 |
else |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4647 |
m = v3; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4648 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4649 |
dp[1] = m; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4650 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4651 |
} |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4652 |
m = data[l1*rowDelta + l2]; |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4653 |
if (sz > FASTSIZE) |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4654 |
free(data); |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4655 |
RETURN ( __mkSmallInteger(m) ); |
608 | 4656 |
} |
4657 |
mallocFailed: ; |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4658 |
#endif /* ! __SCHTEAM__ */ |
608 | 4659 |
%}. |
4660 |
||
8898 | 4661 |
^ super levenshteinTo:aString |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4662 |
s:substWeight k:kbdTypoWeight c:caseWeight |
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15044
diff
changeset
|
4663 |
i:insrtWeight d:deleteWeight |
8647 | 4664 |
|
4665 |
" |
|
4666 |
'ocmprt' levenshteinTo:'computer' |
|
608 | 4667 |
'computer' levenshteinTo:'computer' |
4668 |
'ocmputer' levenshteinTo:'computer' |
|
4669 |
'cmputer' levenshteinTo:'computer' |
|
8647 | 4670 |
'computer' levenshteinTo:'cmputer' |
4671 |
'computer' levenshteinTo:'vomputer' |
|
4672 |
'computer' levenshteinTo:'bomputer' |
|
4673 |
'Computer' levenshteinTo:'computer' |
|
4674 |
" |
|
1380 | 4675 |
! |
4676 |
||
5556 | 4677 |
notEmpty |
4678 |
"return true if the receiver is not empty (i.e. if size ~~ 0) |
|
4679 |
Redefined here for performance" |
|
4680 |
||
4681 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4682 |
#ifndef __SCHTEAM__ |
5556 | 4683 |
OBJ cls; |
4684 |
||
4685 |
cls = __qClass(self); |
|
4686 |
if ((cls == String) || (cls == Symbol)) { |
|
9473 | 4687 |
RETURN ( (__stringSize(self) != 0) ? true : false); |
5556 | 4688 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18236
diff
changeset
|
4689 |
#endif /* ! __SCHTEAM__ */ |
5556 | 4690 |
%}. |
4691 |
^ self size ~~ 0 |
|
4692 |
! |
|
4693 |
||
2886 | 4694 |
startsWith:aStringOrChar |
4389
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4388
diff
changeset
|
4695 |
"return true, if the receiver starts with something, aStringOrChar. |
17370 | 4696 |
If the argument is empty, true is returned. |
4697 |
Notice, that this is similar to, but slightly different from VW's and Squeak's beginsWith:, |
|
4698 |
which are both inconsistent w.r.t. an empty argument." |
|
1380 | 4699 |
|
4700 |
%{ /* NOCONTEXT */ |
|
18343 | 4701 |
#ifdef __SCHTEAM__ |
4702 |
if (self.isSTString()) { |
|
4703 |
if (aStringOrChar.isSTString()) { |
|
4704 |
java.lang.String me = self.asString(); |
|
4705 |
java.lang.String other = aStringOrChar.asString(); |
|
18405 | 4706 |
return __c__._RETURN( me.startsWith(other) ? STObject.True : STObject.False); |
18343 | 4707 |
} |
4708 |
if (aStringOrChar.isSTCharacter()) { |
|
4709 |
char[] me = self.asSTString().characters; |
|
4710 |
char ch = aStringOrChar.charValue(); |
|
4711 |
return __c__._RETURN( ((me.length > 0) |
|
18405 | 4712 |
&& (me[0] == ch)) ? STObject.True : STObject.False); |
18343 | 4713 |
} |
4714 |
} |
|
4715 |
#else |
|
1380 | 4716 |
int len1, len2; |
4717 |
REGISTER unsigned char *src1, *src2; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
4718 |
unsigned char c; |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
4719 |
REGISTER OBJ slf = self; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
4720 |
|
14217 | 4721 |
if (__qIsStringLike(slf) &&__isStringLike(aStringOrChar)) { |
18215 | 4722 |
src1 = __stringVal(slf); |
4723 |
src2 = __stringVal(aStringOrChar); |
|
4724 |
||
4725 |
if (src1[0] != src2[0]) { |
|
4726 |
if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) { |
|
4727 |
RETURN (true); |
|
4728 |
} |
|
4729 |
RETURN ( false ); |
|
4730 |
} |
|
4731 |
||
4732 |
len1 = __qSize(slf); |
|
4733 |
len2 = __qSize(aStringOrChar); |
|
4734 |
if (len1 < len2) { |
|
4735 |
RETURN ( false ); |
|
4736 |
} |
|
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
4737 |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
4738 |
# ifdef UINT64 |
18215 | 4739 |
while (len2 > (OHDR_SIZE+sizeof(UINT64))) { |
4740 |
if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) { |
|
4741 |
RETURN (false); |
|
4742 |
} |
|
4743 |
len2 -= sizeof(UINT64); |
|
4744 |
src1 += sizeof(UINT64); |
|
4745 |
src2 += sizeof(UINT64); |
|
4746 |
} |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
4747 |
# else |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
4748 |
# ifdef __UNROLL_LOOPS__ |
18215 | 4749 |
while (len2 > (OHDR_SIZE+sizeof(INT)*4)) { |
4750 |
if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) { |
|
4751 |
RETURN (false); |
|
4752 |
} |
|
4753 |
if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) { |
|
4754 |
RETURN (false); |
|
4755 |
} |
|
4756 |
if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) { |
|
4757 |
RETURN (false); |
|
4758 |
} |
|
4759 |
if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) { |
|
4760 |
RETURN (false); |
|
4761 |
} |
|
4762 |
len2 -= sizeof(INT)*4; |
|
4763 |
src1 += sizeof(INT)*4; |
|
4764 |
src2 += sizeof(INT)*4; |
|
4765 |
} |
|
18233
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
4766 |
# endif /* __UNROLL_LOOPS__ */ |
b0bba7f5bfeb
java support (experimental)
Claus Gittinger <cg@exept.de>
parents:
18215
diff
changeset
|
4767 |
# endif /* UINT64 */ |
3546
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
4768 |
|
18215 | 4769 |
while (len2 > (OHDR_SIZE+sizeof(INT))) { |
4770 |
if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) { |
|
4771 |
RETURN (false); |
|
4772 |
} |
|
4773 |
len2 -= sizeof(INT); |
|
4774 |
src1 += sizeof(INT); |
|
4775 |
src2 += sizeof(INT); |
|
4776 |
} |
|
4777 |
||
18551
7f43475b5613
eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents:
18405
diff
changeset
|
4778 |
while ((c = *src2++) != '\0') { |
18215 | 4779 |
if (c != *src1) { |
4780 |
RETURN ( false ); |
|
4781 |
} |
|
4782 |
src1++; |
|
4783 |
} |
|
4784 |
RETURN (true); |
|
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
4785 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
4786 |
if (__isCharacter(aStringOrChar)) { |
18215 | 4787 |
int val; |
4788 |
||
4789 |
val = __intVal(__characterVal(aStringOrChar)); |
|
4790 |
if ((unsigned)val <= 0xFF) { |
|
4791 |
len1 = __stringSize(slf); |
|
4792 |
if (len1 > 0) { |
|
4793 |
RETURN ( (__stringVal(slf)[0] == val) ? true : false); |
|
4794 |
} |
|
4795 |
} |
|
4796 |
RETURN ( false ); |
|
1380 | 4797 |
} |
18343 | 4798 |
#endif /* not __SCHTEAM__ */ |
1380 | 4799 |
%}. |
2862 | 4800 |
^ super startsWith:aStringOrChar |
1380 | 4801 |
|
4802 |
" |
|
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
4803 |
'hello world' startsWith:'hello' |
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
4804 |
'hello world' startsWith:'hella' |
8898 | 4805 |
'hello world' startsWith:'hi' |
4806 |
'hello world' startsWith:$h |
|
4807 |
'hello world' startsWith:$H |
|
4808 |
'hello world' startsWith:(Character value:16rFF00) |
|
4809 |
'hello world' startsWith:60 |
|
1380 | 4810 |
'hello world' startsWith:#($h $e $l) |
8898 | 4811 |
'hello world' startsWith:'' |
1380 | 4812 |
" |
608 | 4813 |
! ! |
4814 |
||
4660 | 4815 |
!String methodsFor:'tracing'! |
4816 |
||
16771 | 4817 |
isSingleByteString |
16773 | 4818 |
"returns true only for strings and immutable strings. |
4819 |
Must replace foo isMemberOf:String and foo class == String" |
|
4820 |
||
16771 | 4821 |
^ true |
4822 |
! |
|
4823 |
||
4682 | 4824 |
traceInto:aRequestor level:level from:referrer |
4660 | 4825 |
"double dispatch into tracer, passing my type implicitely in the selector" |
4826 |
||
4682 | 4827 |
^ aRequestor traceString:self level:level from:referrer |
4660 | 4828 |
|
4829 |
||
4830 |
! ! |
|
4831 |
||
19790 | 4832 |
|
633 | 4833 |
!String class methodsFor:'documentation'! |
4834 |
||
2886 | 4835 |
version |
18551
7f43475b5613
eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents:
18405
diff
changeset
|
4836 |
^ '$Header$' |
12184
e91c375c7ea9
comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents:
11922
diff
changeset
|
4837 |
! |
e91c375c7ea9
comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents:
11922
diff
changeset
|
4838 |
|
e91c375c7ea9
comment/format in: #asPackageId
Claus Gittinger <cg@exept.de>
parents:
11922
diff
changeset
|
4839 |
version_CVS |
18551
7f43475b5613
eliminated some compiler warnings
Claus Gittinger <cg@exept.de>
parents:
18405
diff
changeset
|
4840 |
^ '$Header$' |
633 | 4841 |
! ! |
19910 | 4842 |