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