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