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