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