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