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