author | Claus Gittinger <cg@exept.de> |
Wed, 05 Aug 1998 16:53:13 +0200 | |
changeset 3734 | 5d4e741062bd |
parent 3712 | f93cb659b10d |
child 3751 | e2913a6c124b |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
255 | 13 |
CharacterArray subclass:#String |
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
14 |
instanceVariableNames:'' |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
15 |
classVariableNames:'' |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
16 |
poolDictionaries:'' |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
17 |
category:'Collections-Text' |
88 | 18 |
! |
19 |
||
216 | 20 |
!String primitiveDefinitions! |
88 | 21 |
%{ |
2894 | 22 |
#ifdef __openVMS__ |
23 |
/* |
|
24 |
* mhmh - used in stdio ... |
|
25 |
*/ |
|
26 |
# undef __new |
|
27 |
#endif |
|
28 |
||
1486 | 29 |
#ifndef WIN32 |
30 |
# include <stdio.h> |
|
31 |
# define _STDIO_H_INCLUDED_ |
|
32 |
#endif |
|
437 | 33 |
|
88 | 34 |
#include <ctype.h> |
359 | 35 |
|
273 | 36 |
#ifdef LINUX |
359 | 37 |
# define __STRINGDEFS__ |
38 |
# include <linuxIntern.h> |
|
302 | 39 |
#else |
40 |
extern char *strchr(); |
|
273 | 41 |
#endif |
95 | 42 |
|
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 |
|
88 | 49 |
%} |
216 | 50 |
! ! |
88 | 51 |
|
608 | 52 |
!String class methodsFor:'documentation'! |
53 |
||
54 |
copyright |
|
55 |
" |
|
56 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
57 |
All Rights Reserved |
|
58 |
||
59 |
This software is furnished under a license and may be used |
|
60 |
only in accordance with the terms of that license and with the |
|
61 |
inclusion of the above copyright notice. This software may not |
|
62 |
be provided or otherwise made available to, or used by, any |
|
63 |
other person. No title to or ownership of the software is |
|
64 |
hereby transferred. |
|
65 |
" |
|
66 |
! |
|
3 | 67 |
|
608 | 68 |
documentation |
69 |
" |
|
70 |
Strings are ByteArrays storing Characters. |
|
71 |
||
72 |
Strings are kind of kludgy: to allow for easy handling by c-functions, |
|
73 |
there is always one 0-byte added at the end, which is not counted |
|
74 |
in size. also, the at:put: method does not allow for storing 0-bytes. |
|
75 |
(to do this, the basicAt:put: and basicNew: methods are redefined) |
|
3 | 76 |
|
608 | 77 |
You cannot add any instvars to String, since the the run time system & compiler |
78 |
creates literal strings and knows that strings have no named instvars. |
|
79 |
||
80 |
If you really need strings with instVars, you have to create a subclass |
|
81 |
of String (the access functions defined here can handle this). |
|
82 |
A little warning though: not all smalltalk systems allow subclassing String, |
|
83 |
so your program may become unportable if you do so. |
|
1290 | 84 |
|
85 |
[author:] |
|
1486 | 86 |
Claus Gittinger |
1310 | 87 |
|
88 |
[see also:] |
|
1486 | 89 |
Text StringCollection TwoByteString JISEncodedString |
90 |
Symbol |
|
608 | 91 |
" |
3 | 92 |
! ! |
93 |
||
1 | 94 |
!String class methodsFor:'instance creation'! |
95 |
||
96 |
basicNew:anInteger |
|
97 |
"return a new empty string with anInteger characters" |
|
98 |
||
99 |
%{ /* NOCONTEXT */ |
|
100 |
||
101 |
OBJ newString; |
|
102 |
REGISTER int len; |
|
103 |
REGISTER unsigned char *cp; |
|
104 |
REGISTER OBJ *op; |
|
105 |
int nInstVars, instsize; |
|
106 |
||
252 | 107 |
if (__isSmallInteger(anInteger)) { |
3451 | 108 |
len = __intVal(anInteger); |
109 |
if (len >= 0) { |
|
110 |
instsize = OHDR_SIZE + len + 1; |
|
111 |
if (self == String) { |
|
112 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
|
113 |
/* |
|
114 |
* the most common case |
|
115 |
*/ |
|
116 |
__qCheckedNew(newString, instsize); |
|
117 |
__InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */ |
|
118 |
__qSTORE(newString, self); |
|
119 |
||
120 |
cp = __stringVal(newString); |
|
2862 | 121 |
|
357 | 122 |
#if defined(memset4) && !defined(NON_ASCII) |
3451 | 123 |
{ |
124 |
/* |
|
125 |
* no sizeof(int) here please - |
|
126 |
* - memset4 (if defined) fills 4-bytes on ALL machines |
|
127 |
*/ |
|
128 |
int l4 = len >> 2; |
|
129 |
||
130 |
if (len & 3) l4++; |
|
131 |
memset4(cp, 0x20202020, l4); |
|
132 |
cp[len] = '\0'; |
|
133 |
} |
|
95 | 134 |
#else |
357 | 135 |
# ifdef FAST_MEMSET |
3451 | 136 |
memset(cp, ' ', len); |
137 |
cp[len] = '\0'; |
|
357 | 138 |
# else |
3451 | 139 |
while (len >= 8) { |
3449
84160615c630
oops - basicNew was bad for subclasses of String.
Claus Gittinger <cg@exept.de>
parents:
3403
diff
changeset
|
140 |
# ifndef NON_ASCII /* i.e. EBCDIC */ |
2954 | 141 |
# ifdef INT64 |
3451 | 142 |
((INT64 *)cp)[0] = 0x2020202020202020L; |
2862 | 143 |
# else |
3451 | 144 |
((int *)cp)[0] = 0x20202020; |
145 |
((int *)cp)[1] = 0x20202020; |
|
2862 | 146 |
# endif |
357 | 147 |
# else |
3451 | 148 |
cp[0] = cp[1] = cp[2] = cp[3] = ' '; |
149 |
cp[4] = cp[5] = cp[6] = cp[7] = ' '; |
|
357 | 150 |
# endif |
3451 | 151 |
cp += 8; |
152 |
len -= 8; |
|
153 |
} |
|
154 |
while (len--) |
|
155 |
*cp++ = ' '; |
|
156 |
*cp = '\0'; |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
157 |
# endif /* not FAST_MEMSET */ |
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
158 |
#endif /* not memset4 */ |
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
159 |
|
3451 | 160 |
RETURN (newString); |
161 |
} |
|
162 |
nInstVars = 0; |
|
163 |
} else { |
|
164 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
|
165 |
instsize += __OBJS2BYTES__(nInstVars); |
|
166 |
} |
|
167 |
||
168 |
__PROTECT_CONTEXT__; |
|
169 |
__qNew(newString, instsize); /* OBJECT ALLOCATION */ |
|
170 |
__UNPROTECT_CONTEXT__; |
|
171 |
||
172 |
if (newString == nil) goto fail; |
|
173 |
||
174 |
__InstPtr(newString)->o_class = self; |
|
175 |
__qSTORE(newString, self); |
|
176 |
||
177 |
if (nInstVars) { |
|
178 |
/* |
|
179 |
* nil-out instvars |
|
180 |
*/ |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
181 |
#if defined(memset4) |
3451 | 182 |
memset4(__InstPtr(newString)->i_instvars, nil, nInstVars); |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
183 |
#else |
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
184 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
3451 | 185 |
/* |
186 |
* knowing that nil is 0 |
|
187 |
*/ |
|
188 |
memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars)); |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
189 |
# else |
3451 | 190 |
op = __InstPtr(newString)->i_instvars; |
191 |
do { |
|
192 |
*op++ = nil; |
|
193 |
} while (--nInstVars); |
|
357 | 194 |
# endif |
95 | 195 |
#endif |
3451 | 196 |
cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars); |
197 |
} else { |
|
198 |
cp = __stringVal(newString); |
|
199 |
} |
|
200 |
||
201 |
/* |
|
202 |
* fill with spaces |
|
203 |
*/ |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
204 |
#ifdef FAST_MEMSET |
3451 | 205 |
memset(cp, ' ', len); |
206 |
*(cp + len) = '\0'; |
|
1 | 207 |
#else |
3451 | 208 |
while (len >= 8) { |
357 | 209 |
# ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
2954 | 210 |
# ifdef INT64 |
3451 | 211 |
((INT64 *)cp)[0] = 0x2020202020202020L; |
2862 | 212 |
# else |
3451 | 213 |
((int *)cp)[0] = 0x20202020; |
214 |
((int *)cp)[1] = 0x20202020; |
|
2862 | 215 |
# endif |
357 | 216 |
# else |
3451 | 217 |
cp[0] = cp[1] = cp[2] = cp[3] = ' '; |
218 |
cp[4] = cp[5] = cp[6] = cp[7] = ' '; |
|
357 | 219 |
# endif |
3451 | 220 |
cp += 8; |
221 |
len -= 8; |
|
222 |
} |
|
223 |
while (len--) |
|
224 |
*cp++ = ' '; |
|
225 |
*cp = '\0'; |
|
1 | 226 |
#endif |
3451 | 227 |
RETURN (newString); |
228 |
} |
|
1 | 229 |
} |
95 | 230 |
fail: ;; |
1019 | 231 |
%}. |
95 | 232 |
" |
233 |
invalid argument, or out-of-memory: |
|
234 |
use error handling in superclass |
|
235 |
" |
|
1 | 236 |
^ (super basicNew:anInteger) atAllPut:(Character space) |
237 |
! |
|
238 |
||
608 | 239 |
new:n |
240 |
^ self basicNew:n |
|
347 | 241 |
! |
242 |
||
243 |
readFrom:aStream onError:exceptionBlock |
|
244 |
"read & return the next String from the (character-)stream aStream; |
|
245 |
skipping all whitespace first; return the value of exceptionBlock, |
|
246 |
if no string can be read. The sequence of characters as read from the |
|
247 |
stream must be one as stored via storeOn: or storeString." |
|
248 |
||
249 |
|collected char| |
|
250 |
||
251 |
" |
|
252 |
this method is not to be inherited |
|
253 |
(i.e. not ok for subclasses; Symbol, for example) |
|
254 |
" |
|
255 |
self ~~ String ifTrue:[ |
|
3451 | 256 |
^ super readFrom:aStream onError:exceptionBlock |
347 | 257 |
]. |
258 |
||
259 |
"skip whiteSpace" |
|
260 |
aStream skipSeparators. |
|
261 |
(aStream next == $') ifTrue:[ |
|
3451 | 262 |
collected := WriteStream on:(String new). |
263 |
[true] whileTrue:[ |
|
264 |
aStream atEnd ifTrue:[ |
|
265 |
"/ mhmh - reached the end without a closing quote |
|
266 |
"/ looks like an error to me ... |
|
267 |
^ exceptionBlock value |
|
268 |
]. |
|
269 |
char := aStream next. |
|
270 |
char == $' ifTrue:[ |
|
271 |
"/ look for another quote |
|
272 |
aStream peekOrNil == $' ifFalse:[ |
|
273 |
^ collected contents |
|
274 |
]. |
|
275 |
aStream next. |
|
276 |
]. |
|
277 |
collected nextPut:char |
|
278 |
] |
|
347 | 279 |
]. |
280 |
^ exceptionBlock value |
|
281 |
||
282 |
" |
|
283 |
String readFrom:('''hello world''' readStream) |
|
284 |
String readFrom:('''hello '''' world''' readStream) |
|
285 |
String readFrom:('1 ''hello'' ' readStream) |
|
286 |
String readFrom:('1 ''hello'' ' readStream) onError:['foobar'] |
|
3376 | 287 |
" |
288 |
||
289 |
"Modified: / 14.4.1998 / 18:46:26 / cg" |
|
608 | 290 |
! |
291 |
||
292 |
unititializedNew:anInteger |
|
293 |
"redefine it back - strings must have a 0-byte at the end" |
|
294 |
||
295 |
^ self basicNew:anInteger |
|
296 |
! ! |
|
297 |
||
298 |
!String class methodsFor:'binary storage'! |
|
299 |
||
300 |
binaryDefinitionFrom:stream manager:manager |
|
3085 | 301 |
"read a binary representation from stream. This is only invoked |
302 |
for long strings. Short strings are stored with 1byte length." |
|
303 |
||
304 |
|s len| |
|
608 | 305 |
|
3085 | 306 |
"take care of subclasses ..." |
307 |
((self == String) or:[self == Symbol]) ifTrue:[ |
|
3111 | 308 |
len := stream nextNumber:4. |
309 |
s := String basicNew:len. |
|
310 |
stream nextBytes:len into:s startingAt:1. |
|
311 |
^ s |
|
3085 | 312 |
]. |
313 |
^ super binaryDefinitionFrom:stream manager:manager |
|
314 |
||
315 |
"Modified: / 2.11.1997 / 16:18:37 / cg" |
|
608 | 316 |
! ! |
317 |
||
318 |
!String class methodsFor:'queries'! |
|
319 |
||
2680
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
320 |
defaultPlatformClass |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
321 |
"dummy for ST-80 compatibility" |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
322 |
|
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
323 |
^ self |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
324 |
|
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
325 |
"Created: 6.6.1997 / 18:25:56 / cg" |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
326 |
! |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
327 |
|
608 | 328 |
isBuiltInClass |
1264 | 329 |
"return true if this class is known by the run-time-system. |
330 |
Here, true is returned for myself, false for subclasses." |
|
608 | 331 |
|
332 |
^ self == String |
|
1264 | 333 |
|
334 |
"Modified: 23.4.1996 / 16:00:38 / cg" |
|
1 | 335 |
! ! |
336 |
||
337 |
!String methodsFor:'accessing'! |
|
338 |
||
329 | 339 |
at:index |
340 |
"return the character at position index, an Integer. |
|
345 | 341 |
Reimplemented here to avoid the additional at:->basicAt: send |
342 |
(which we can do here, since at: is obviously not redefined in a subclass). |
|
329 | 343 |
This method is the same as at:." |
344 |
||
345 |
%{ /* NOCONTEXT */ |
|
346 |
||
347 |
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
|
348 |
REGISTER OBJ slf, cls; |
329 | 349 |
|
350 |
if (__isSmallInteger(index)) { |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
351 |
indx = __intVal(index) - 1; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
352 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
353 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
354 |
cls = __qClass(slf); |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
355 |
if (cls != String) |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
356 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
357 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
358 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
329 | 359 |
} |
360 |
} |
|
361 |
%}. |
|
3451 | 362 |
index isInteger ifFalse:[ |
363 |
^ self indexNotInteger:index |
|
364 |
]. |
|
329 | 365 |
^ self subscriptBoundsError:index |
1 | 366 |
! |
367 |
||
329 | 368 |
at:index put:aCharacter |
369 |
"store the argument, aCharacter at position index, an Integer. |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
370 |
Return aCharacter (sigh). |
345 | 371 |
Reimplemented here to avoid the additional at:put:->basicAt:put: send |
372 |
(but only for Strings, since subclasses may redefine basicAt:put:). |
|
329 | 373 |
This method is the same as basicAt:put:." |
374 |
||
375 |
%{ /* NOCONTEXT */ |
|
376 |
||
377 |
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
|
378 |
REGISTER OBJ slf; |
329 | 379 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
380 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
381 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
382 |
if (__isString(slf)) { |
1486 | 383 |
if (__isCharacter(aCharacter)) { |
384 |
value = __intVal(_characterVal(aCharacter)); |
|
385 |
if (((unsigned)value <= 0xFF) |
|
386 |
&& __isSmallInteger(index)) { |
|
387 |
indx = __intVal(index) - 1; |
|
388 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
389 |
__stringVal(slf)[indx] = value; |
|
390 |
RETURN ( aCharacter ); |
|
391 |
} |
|
392 |
} |
|
393 |
} |
|
329 | 394 |
} |
395 |
%}. |
|
345 | 396 |
(self isMemberOf:String) ifFalse:[ |
1486 | 397 |
^ super at:index put:aCharacter |
345 | 398 |
]. |
399 |
||
329 | 400 |
(aCharacter isMemberOf:Character) ifFalse:[ |
1486 | 401 |
" |
402 |
tried to store something which is not a character |
|
403 |
" |
|
404 |
^ self elementNotCharacter |
|
329 | 405 |
]. |
406 |
(aCharacter asciiValue between:1 and:255) ifFalse:[ |
|
1486 | 407 |
" |
408 |
tried to store a multibyte character |
|
409 |
" |
|
410 |
^ self elementBoundsError |
|
329 | 411 |
]. |
412 |
" |
|
413 |
invalid index |
|
414 |
" |
|
3451 | 415 |
index isInteger ifFalse:[ |
416 |
^ self indexNotInteger:index |
|
417 |
]. |
|
329 | 418 |
^ self subscriptBoundsError:index |
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
419 |
|
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
420 |
"Modified: 19.4.1996 / 11:40:27 / cg" |
329 | 421 |
! |
422 |
||
608 | 423 |
basicAt:index |
424 |
"return the character at position index, an Integer |
|
425 |
- reimplemented here since we return characters" |
|
426 |
||
427 |
%{ /* NOCONTEXT */ |
|
428 |
||
429 |
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
|
430 |
REGISTER OBJ slf, cls; |
608 | 431 |
|
432 |
if (__isSmallInteger(index)) { |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
433 |
indx = __intVal(index) - 1; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
434 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
435 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
436 |
cls = __qClass(slf); |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
437 |
if (cls != String) |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
438 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
439 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
440 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
608 | 441 |
} |
442 |
} |
|
443 |
%}. |
|
3451 | 444 |
index isInteger ifFalse:[ |
445 |
^ self indexNotInteger:index |
|
446 |
]. |
|
608 | 447 |
^ self subscriptBoundsError:index |
448 |
! |
|
449 |
||
1 | 450 |
basicAt:index put:aCharacter |
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
451 |
"store the argument, aCharacter at position index, an Integer. |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
452 |
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
|
453 |
- reimplemented here since we store characters" |
1 | 454 |
|
455 |
%{ /* NOCONTEXT */ |
|
456 |
||
457 |
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
|
458 |
REGISTER OBJ slf; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
459 |
REGISTER OBJ cls; |
1 | 460 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
461 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
462 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
463 |
if (__isCharacter(aCharacter)) { |
1486 | 464 |
value = __intVal(_characterVal(aCharacter)); |
465 |
if (((unsigned)value <= 0xFF) |
|
466 |
&& __isSmallInteger(index)) { |
|
467 |
indx = __intVal(index) - 1; |
|
468 |
cls = __qClass(slf); |
|
469 |
if (cls != String) |
|
470 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
471 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
472 |
__stringVal(slf)[indx] = value; |
|
473 |
RETURN ( aCharacter ); |
|
474 |
} |
|
475 |
} |
|
1 | 476 |
} |
159 | 477 |
%}. |
1 | 478 |
(aCharacter isMemberOf:Character) ifFalse:[ |
1486 | 479 |
" |
480 |
tried to store something which is not a character |
|
481 |
" |
|
482 |
^ self elementNotCharacter |
|
299 | 483 |
]. |
484 |
(aCharacter asciiValue between:1 and:255) ifFalse:[ |
|
1486 | 485 |
" |
486 |
tried to store a multibyte character |
|
487 |
" |
|
488 |
^ self elementBoundsError |
|
299 | 489 |
]. |
490 |
" |
|
491 |
invalid index |
|
492 |
" |
|
3451 | 493 |
index isInteger ifFalse:[ |
494 |
^ self indexNotInteger:index |
|
495 |
]. |
|
299 | 496 |
^ self subscriptBoundsError:index |
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
497 |
|
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
498 |
"Modified: 19.4.1996 / 11:15:48 / cg" |
429 | 499 |
! |
500 |
||
608 | 501 |
basicSize |
502 |
"return the number of characters in myself. |
|
503 |
Redefined here to exclude the 0-byte at the end." |
|
504 |
||
505 |
%{ /* NOCONTEXT */ |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
506 |
REGISTER OBJ slf, cls; |
608 | 507 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
508 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
509 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
510 |
cls = __qClass(slf); |
608 | 511 |
if (cls == String) { |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
512 |
RETURN ( __MKSMALLINT(__stringSize(slf)) ); |
608 | 513 |
} |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
514 |
RETURN ( __MKSMALLINT(__stringSize(slf) |
1486 | 515 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
608 | 516 |
%} |
517 |
! |
|
429 | 518 |
|
608 | 519 |
size |
520 |
"return the number of characters in myself. |
|
521 |
Reimplemented here to avoid the additional size->basicSize send |
|
522 |
(which we can do here, since size is obviously not redefined in a subclass). |
|
523 |
This method is the same as basicSize." |
|
429 | 524 |
|
608 | 525 |
%{ /* NOCONTEXT */ |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
526 |
REGISTER OBJ cls, slf; |
608 | 527 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
528 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
529 |
cls = __qClass(slf); |
608 | 530 |
if (cls == String) { |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
531 |
RETURN ( __MKSMALLINT(__stringSize(slf)) ); |
429 | 532 |
} |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
533 |
RETURN ( __MKSMALLINT(__stringSize(slf) |
1134 | 534 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
608 | 535 |
%} |
2 | 536 |
! ! |
537 |
||
3085 | 538 |
!String methodsFor:'binary storage'! |
539 |
||
540 |
storeBinaryDefinitionOn:stream manager:manager |
|
541 |
"append a binary representation of the receiver onto stream. |
|
542 |
Redefined since short Strings can be stored with a special type code |
|
543 |
in a more compact way. |
|
544 |
This is an internal interface for the binary storage mechanism." |
|
545 |
||
546 |
|myClass myBasicSize| |
|
547 |
||
548 |
"/ not for subclasses with named instVars. |
|
549 |
(myClass := self class) instSize ~~ 0 ifTrue:[ |
|
3111 | 550 |
^ super storeBinaryDefinitionOn:stream manager:manager |
3085 | 551 |
]. |
552 |
||
553 |
myBasicSize := self basicSize. |
|
554 |
||
555 |
"/ can use a more compact representation; |
|
556 |
"/ but not for subclasses ... |
|
557 |
||
558 |
((myClass == String) |
|
559 |
and:[myBasicSize <= 255]) ifTrue:[ |
|
3111 | 560 |
"/ special encoding: <codeForString> <len> <bytes> ... |
561 |
stream nextPut:(manager codeForString); nextPut:myBasicSize. |
|
3085 | 562 |
] ifFalse:[ |
3111 | 563 |
manager putIdOfClass:myClass on:stream. |
564 |
stream nextNumber:4 put:myBasicSize. |
|
3085 | 565 |
]. |
566 |
stream nextPutBytes:myBasicSize from:self startingAt:1. |
|
567 |
||
568 |
"Modified: / 2.11.1997 / 15:28:56 / cg" |
|
569 |
! ! |
|
570 |
||
53 | 571 |
!String methodsFor:'character searching'! |
1 | 572 |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
573 |
identityIndexOf:aCharacter |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
574 |
"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
|
575 |
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
|
576 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
577 |
%{ /* NOCONTEXT */ |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
578 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
579 |
REGISTER unsigned char *cp; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
580 |
#ifdef FAST_STRCHR |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
581 |
char *strchr(); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
582 |
#else |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
583 |
REGISTER unsigned byteValue; |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
584 |
REGISTER int index; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
585 |
char c; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
586 |
#endif |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
587 |
OBJ cls; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
588 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
589 |
if (__isCharacter(aCharacter)) { |
3111 | 590 |
cp = __stringVal(self); |
591 |
if ((cls = __qClass(self)) != String) |
|
592 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
593 |
#ifdef FAST_STRCHR |
3111 | 594 |
cp = (unsigned char *) strchr(cp, __intVal(_characterVal(aCharacter))); |
595 |
if (cp) { |
|
596 |
RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) ); |
|
597 |
} |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
598 |
#else |
3111 | 599 |
byteValue = __intVal(_characterVal(aCharacter)); |
600 |
index = 1; |
|
601 |
while (c = *cp++) { |
|
602 |
if (c == byteValue) { RETURN ( __MKSMALLINT(index) ); } |
|
603 |
index++; |
|
604 |
} |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
605 |
#endif |
3111 | 606 |
RETURN ( __MKSMALLINT(0)); |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
607 |
} |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
608 |
%}. |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
609 |
"/ with identity compares, only characters can be in myself |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
610 |
^ 0 |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
611 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
612 |
" |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
613 |
'hello world' indexOf:(Character space) |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
614 |
'hello world' indexOf:$A |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
615 |
" |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
616 |
! |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
617 |
|
1 | 618 |
includes:aCharacter |
619 |
"return true if the argument, aCharacter is included in the receiver |
|
620 |
- reimplemented here for speed" |
|
621 |
||
622 |
%{ /* NOCONTEXT */ |
|
623 |
||
624 |
REGISTER unsigned char *cp; |
|
625 |
REGISTER int byteValue; |
|
53 | 626 |
OBJ cls; |
1 | 627 |
|
53 | 628 |
if (__isCharacter(aCharacter)) { |
3111 | 629 |
byteValue = __intVal(_characterVal(aCharacter)); |
630 |
cp = __stringVal(self); |
|
631 |
if ((cls = __qClass(self)) != String) |
|
632 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1 | 633 |
#ifdef FAST_STRCHR |
3111 | 634 |
cp = (unsigned char *) strchr(cp, __intVal(_characterVal(aCharacter))); |
635 |
if (cp) { |
|
636 |
RETURN ( true ); |
|
637 |
} |
|
1 | 638 |
#else |
3111 | 639 |
while (*cp) { |
640 |
if (*cp == byteValue) { |
|
641 |
RETURN ( true ); |
|
642 |
} |
|
643 |
cp++; |
|
644 |
} |
|
1 | 645 |
#endif |
3111 | 646 |
RETURN (false); |
1 | 647 |
} |
299 | 648 |
%}. |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
649 |
^ super includes:aCharacter |
53 | 650 |
|
95 | 651 |
" |
652 |
'hello world' includes:$a |
|
653 |
'hello world' includes:$o |
|
654 |
'hello world' includes:$x |
|
655 |
'hello world' includes:1 |
|
299 | 656 |
'hello world' asTwoByteString includes:$o |
95 | 657 |
" |
1 | 658 |
! |
659 |
||
10 | 660 |
includesAny:aCollection |
661 |
"return true, if the receiver includes any of the characters in the |
|
53 | 662 |
argument, aCollection. |
663 |
- redefined for speed if the argument is a String." |
|
10 | 664 |
|
665 |
%{ /* NOCONTEXT */ |
|
666 |
||
667 |
REGISTER unsigned char *cp; |
|
668 |
REGISTER unsigned char *matchP; |
|
53 | 669 |
OBJ cls; |
10 | 670 |
|
53 | 671 |
if (__isString(aCollection)) { |
1134 | 672 |
matchP = __stringVal(aCollection); |
673 |
cp = __stringVal(self); |
|
329 | 674 |
if ((cls = __qClass(self)) != String) |
1134 | 675 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
53 | 676 |
|
159 | 677 |
while (*cp) { |
329 | 678 |
if (strchr(matchP, *cp)) { |
159 | 679 |
RETURN ( true ); |
680 |
} |
|
681 |
cp++; |
|
682 |
} |
|
683 |
RETURN ( false ); |
|
10 | 684 |
} |
685 |
%} |
|
686 |
. |
|
687 |
^ super includesAny:aCollection |
|
95 | 688 |
|
689 |
" |
|
690 |
'hello world' includesAny:'abcd' |
|
691 |
'hello world' includesAny:'xyz' |
|
692 |
'hello world' includesAny:(Array with:$a with:$b with:$d) |
|
693 |
'hello world' includesAny:(Array with:$x with:$y) |
|
694 |
'hello world' includesAny:(Array with:1 with:2) |
|
695 |
" |
|
10 | 696 |
! |
697 |
||
1 | 698 |
indexOf:aCharacter |
699 |
"return the index of the first occurrences of the argument, aCharacter |
|
700 |
in the receiver or 0 if not found - reimplemented here for speed." |
|
701 |
||
702 |
%{ /* NOCONTEXT */ |
|
703 |
||
704 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
705 |
REGISTER unsigned byteValue; |
2530 | 706 |
REGISTER int index; |
1 | 707 |
#ifdef FAST_STRCHR |
708 |
char *strchr(); |
|
2529
f33167bc7b23
Define vars for #ifdef FAST_STRCHR.
Stefan Vogel <sv@exept.de>
parents:
2528
diff
changeset
|
709 |
#else |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
710 |
unsigned char c; |
1 | 711 |
#endif |
53 | 712 |
OBJ cls; |
1 | 713 |
|
53 | 714 |
if (__isCharacter(aCharacter)) { |
3111 | 715 |
cp = __stringVal(self); |
716 |
if ((cls = __qClass(self)) != String) |
|
717 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
718 |
|
3111 | 719 |
byteValue = __intVal(_characterVal(aCharacter)); |
720 |
if (byteValue == 0) { |
|
721 |
index = strlen(cp); |
|
722 |
if (index >= __stringSize(self)) { |
|
723 |
index = 0; |
|
724 |
} else { |
|
725 |
index++; |
|
726 |
} |
|
727 |
RETURN ( __MKSMALLINT(index) ); |
|
728 |
} |
|
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
729 |
|
1 | 730 |
#ifdef FAST_STRCHR |
3111 | 731 |
cp = (unsigned char *) strchr(cp, byteValue); |
732 |
if (cp) { |
|
733 |
RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) ); |
|
734 |
} |
|
1 | 735 |
#else |
3111 | 736 |
index = 1; |
737 |
while (c = *cp++) { |
|
738 |
if (c == byteValue) { RETURN ( __MKSMALLINT(index) ); } |
|
739 |
index++; |
|
740 |
} |
|
1 | 741 |
#endif |
3111 | 742 |
RETURN ( __MKSMALLINT(0)); |
1 | 743 |
} |
370 | 744 |
%}. |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
745 |
^ super indexOf:aCharacter |
95 | 746 |
|
747 |
" |
|
748 |
'hello world' indexOf:(Character space) |
|
749 |
'hello world' indexOf:$A |
|
750 |
" |
|
1 | 751 |
! |
752 |
||
753 |
indexOf:aCharacter startingAt:start |
|
754 |
"return the index of the first occurrence of the argument, aCharacter |
|
755 |
in myself starting at start, anInteger or 0 if not found; |
|
756 |
- reimplemented here for speed" |
|
757 |
||
758 |
%{ /* NOCONTEXT */ |
|
759 |
||
760 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
761 |
REGISTER int index; |
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
762 |
REGISTER unsigned byteValue; |
1 | 763 |
#ifdef FAST_STRCHR |
764 |
char *strchr(); |
|
370 | 765 |
#else |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
766 |
unsigned char c; |
1 | 767 |
#endif |
768 |
int len; |
|
53 | 769 |
OBJ cls; |
1 | 770 |
|
252 | 771 |
if (__isSmallInteger(start)) { |
3111 | 772 |
if (__isCharacter(aCharacter)) { |
773 |
byteValue = __intVal(_characterVal(aCharacter)); |
|
774 |
index = __intVal(start); |
|
775 |
if (index <= 0) |
|
776 |
index = 1; |
|
777 |
if ((cls = __qClass(self)) != String) |
|
778 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
779 |
len = __stringSize(self); |
|
780 |
if (index <= len) { |
|
781 |
cp = __stringVal(self) + index - 1; |
|
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
782 |
|
3111 | 783 |
if (byteValue == 0) { |
784 |
index += strlen(cp); |
|
785 |
if (index > len) { |
|
786 |
index = 0; |
|
787 |
} |
|
788 |
RETURN ( __MKSMALLINT(index) ); |
|
789 |
} |
|
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
790 |
|
1 | 791 |
#ifdef FAST_STRCHR |
3111 | 792 |
cp = (unsigned char *) strchr(cp, byteValue); |
793 |
if (cp) { |
|
794 |
RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) ); |
|
795 |
} |
|
1 | 796 |
#else |
3111 | 797 |
while (c = *cp++) { |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
798 |
|
3111 | 799 |
if (c == byteValue) { |
800 |
RETURN ( __MKSMALLINT(index) ); |
|
801 |
} |
|
802 |
index++; |
|
803 |
} |
|
1 | 804 |
#endif |
3111 | 805 |
} |
806 |
} |
|
807 |
RETURN ( __MKSMALLINT(0) ); |
|
1 | 808 |
} |
370 | 809 |
%}. |
1 | 810 |
^ super indexOf:aCharacter startingAt:start |
53 | 811 |
|
95 | 812 |
" |
813 |
'hello world' indexOf:$l startingAt:1 |
|
814 |
'hello world' indexOf:$l startingAt:5 |
|
815 |
" |
|
1 | 816 |
! |
817 |
||
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
818 |
indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
819 |
"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
|
820 |
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
|
821 |
- 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
|
822 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
823 |
%{ /* NOCONTEXT */ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
824 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
825 |
REGISTER unsigned char *ccp; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
826 |
REGISTER unsigned char *cp; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
827 |
REGISTER int index; |
2894 | 828 |
unsigned char *matchP; |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
829 |
unsigned char c; |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
830 |
int len; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
831 |
OBJ cls; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
832 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
833 |
if (__isSmallInteger(start) |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
834 |
&& __isString(aCollectionOfCharacters)) { |
3111 | 835 |
matchP = __stringVal(aCollectionOfCharacters); |
836 |
index = __intVal(start); |
|
837 |
if (index <= 0) |
|
838 |
index = 1; |
|
839 |
if ((cls = __qClass(self)) != String) |
|
840 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
841 |
len = __stringSize(self); |
|
842 |
if (index <= len) { |
|
843 |
cp = __stringVal(self) + index - 1; |
|
844 |
while (c = *cp++) { |
|
845 |
for (ccp = matchP; *ccp ; ccp++) { |
|
846 |
if (*ccp == c) { |
|
847 |
RETURN ( __MKSMALLINT(index) ); |
|
848 |
} |
|
849 |
} |
|
850 |
index++; |
|
851 |
} |
|
852 |
} |
|
853 |
RETURN ( __MKSMALLINT(0) ); |
|
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
854 |
} |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
855 |
%}. |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
856 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
857 |
"/ 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
|
858 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
859 |
^ super indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
860 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
861 |
" |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
862 |
'hello world' indexOfAny:'eoa' startingAt:1 |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
863 |
'hello world' indexOfAny:'eoa' startingAt:6 |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
864 |
'hello world' indexOfAny:'AOE' startingAt:1 |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
865 |
" |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
866 |
! |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
867 |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
868 |
indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
869 |
"return the index of the next control character; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
870 |
that is a character with asciiValue < 32. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
871 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
872 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
873 |
%{ /* NOCONTEXT */ |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
874 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
875 |
#ifndef NON_ASCII /* i.e. not EBCDIC ;-) */ |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
876 |
REGISTER unsigned char *cp; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
877 |
REGISTER unsigned char c; |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
878 |
REGISTER unsigned char *cpEnd; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
879 |
int len, index; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
880 |
OBJ cls; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
881 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
882 |
index = __intVal(start); |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
883 |
if (index <= 0) { |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
884 |
index = 1; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
885 |
} |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
886 |
if ((cls = __qClass(self)) != String) |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
887 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
888 |
len = __stringSize(self); |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
889 |
cpEnd = __stringVal(self) + len; |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
890 |
cp = __stringVal(self) + index - 1; |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
891 |
if (cp < cpEnd) { |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
892 |
while (cp < cpEnd) { |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
893 |
if (*cp++ < ' ') { |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
894 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
895 |
} |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
896 |
} |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
897 |
RETURN ( __MKSMALLINT(0) ); |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
898 |
} |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
899 |
#endif |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
900 |
%}. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
901 |
^ super indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
902 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
903 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
904 |
'hello world' indexOfControlCharacterStartingAt:1 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
905 |
'hello world\foo' withCRs indexOfControlCharacterStartingAt:1 |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
906 |
'1\' withCRs indexOfControlCharacterStartingAt:1 |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
907 |
'1\' withCRs indexOfControlCharacterStartingAt:2 |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
908 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
909 |
! |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
910 |
|
3403 | 911 |
indexOfNonSeparatorStartingAt:start |
912 |
"return the index of the next non-whiteSpace character" |
|
913 |
||
914 |
%{ /* NOCONTEXT */ |
|
915 |
||
916 |
REGISTER unsigned char *cp; |
|
917 |
REGISTER unsigned char c; |
|
918 |
int len, index; |
|
919 |
OBJ cls; |
|
920 |
||
921 |
index = __intVal(start); |
|
922 |
if (index <= 0) { |
|
3451 | 923 |
index = 1; |
3403 | 924 |
} |
925 |
if ((cls = __qClass(self)) != String) |
|
3451 | 926 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3403 | 927 |
len = __stringSize(self); |
928 |
if (index > len) { |
|
3451 | 929 |
RETURN ( __MKSMALLINT(0) ); |
3403 | 930 |
} |
931 |
cp = __stringVal(self) + index - 1; |
|
932 |
while (c = *cp++) { |
|
933 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
|
3451 | 934 |
if (c > ' ') |
3403 | 935 |
#endif |
3451 | 936 |
if ((c != ' ') && (c != '\t') && (c != '\n') |
937 |
&& (c != '\r') && (c != '\f')) { |
|
938 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
|
939 |
} |
|
3403 | 940 |
} |
941 |
%}. |
|
942 |
^ 0 |
|
943 |
||
944 |
" |
|
945 |
'hello world' indexOfNonWhiteSpaceStartingAt:3 |
|
946 |
'hello world' indexOfNonWhiteSpaceStartingAt:7 |
|
947 |
" |
|
948 |
! |
|
949 |
||
1 | 950 |
indexOfSeparatorStartingAt:start |
951 |
"return the index of the next separator character" |
|
952 |
||
953 |
%{ /* NOCONTEXT */ |
|
954 |
||
955 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
956 |
REGISTER unsigned char c; |
1 | 957 |
int len, index; |
53 | 958 |
OBJ cls; |
1 | 959 |
|
1134 | 960 |
index = __intVal(start); |
1 | 961 |
if (index <= 0) { |
3111 | 962 |
index = 1; |
1 | 963 |
} |
329 | 964 |
if ((cls = __qClass(self)) != String) |
3111 | 965 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1134 | 966 |
len = __stringSize(self); |
1 | 967 |
if (index > len) { |
3111 | 968 |
RETURN ( __MKSMALLINT(0) ); |
1 | 969 |
} |
1134 | 970 |
cp = __stringVal(self) + index - 1; |
1 | 971 |
while (c = *cp++) { |
329 | 972 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
3111 | 973 |
if (c <= ' ') |
1 | 974 |
#endif |
3111 | 975 |
if ((c == ' ') || (c == '\t') || (c == '\n') |
976 |
|| (c == '\r') || (c == '\f')) { |
|
977 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
|
978 |
} |
|
1 | 979 |
} |
980 |
%} |
|
981 |
. |
|
982 |
^ 0 |
|
53 | 983 |
|
95 | 984 |
" |
985 |
'hello world' indexOfSeparatorStartingAt:3 |
|
986 |
'hello world' indexOfSeparatorStartingAt:7 |
|
987 |
" |
|
608 | 988 |
! |
989 |
||
990 |
occurrencesOf:aCharacter |
|
991 |
"count the occurrences of the argument, aCharacter in myself |
|
992 |
- reimplemented here for speed" |
|
993 |
||
994 |
%{ /* NOCONTEXT */ |
|
995 |
||
996 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
997 |
REGISTER unsigned byteValue; |
608 | 998 |
REGISTER int count; |
999 |
OBJ cls; |
|
1000 |
||
1001 |
if (__isCharacter(aCharacter)) { |
|
3111 | 1002 |
count = 0; |
1003 |
byteValue = __intVal(_characterVal(aCharacter)); |
|
1004 |
cp = __stringVal(self); |
|
1005 |
if ((cls = __qClass(self)) != String) |
|
1006 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1007 |
while (*cp) { |
|
1008 |
if (*cp++ == byteValue) count++; |
|
1009 |
} |
|
1010 |
RETURN ( __MKSMALLINT(count) ); |
|
608 | 1011 |
} |
1012 |
%}. |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
1013 |
^ super occurrencesOf:aCharacter |
608 | 1014 |
|
1015 |
" |
|
1016 |
'hello world' occurrencesOf:$a |
|
1017 |
'hello world' occurrencesOf:$w |
|
1018 |
'hello world' occurrencesOf:$l |
|
1019 |
'hello world' occurrencesOf:$x |
|
1020 |
'hello world' occurrencesOf:1 |
|
1021 |
" |
|
53 | 1022 |
! ! |
1023 |
||
608 | 1024 |
!String methodsFor:'comparing'! |
2 | 1025 |
|
608 | 1026 |
= aString |
1027 |
"Compare the receiver with the argument and return true if the |
|
1028 |
receiver is equal to the argument. Otherwise return false. |
|
1029 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
|
1030 |
Use sameAs: to compare with case ignored." |
|
1 | 1031 |
|
375 | 1032 |
%{ /* NOCONTEXT */ |
1033 |
||
608 | 1034 |
int l1, l2; |
1035 |
REGISTER OBJ s = aString; |
|
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1036 |
unsigned char *cp1, *cp2; |
608 | 1037 |
OBJ cls; |
3111 | 1038 |
OBJ myCls; |
3335 | 1039 |
INT addrDelta; |
608 | 1040 |
|
1041 |
if (s == self) { |
|
3451 | 1042 |
RETURN ( true ); |
608 | 1043 |
} |
1044 |
if (! __isNonNilObject(s)) { |
|
3451 | 1045 |
RETURN ( false ); |
608 | 1046 |
} |
1 | 1047 |
|
3111 | 1048 |
cls = __qClass(s); |
1049 |
myCls = __qClass(self); |
|
608 | 1050 |
|
3111 | 1051 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
3451 | 1052 |
cp2 = __stringVal(s); |
1053 |
l2 = __stringSize(s); |
|
1054 |
/* |
|
1055 |
* care for instances of subclasses ... |
|
1056 |
*/ |
|
1057 |
if (cls != String) { |
|
1058 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1059 |
||
1060 |
cp2 += n; |
|
1061 |
l2 -= n; |
|
1062 |
} |
|
1063 |
||
1064 |
cp1 = __stringVal(self); |
|
1065 |
l1 = __stringSize(self); |
|
1066 |
/* |
|
1067 |
* care for instances of subclasses ... |
|
1068 |
*/ |
|
1069 |
if (myCls != String) { |
|
1070 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
|
1071 |
||
1072 |
cp1 += n; |
|
1073 |
l1 -= n; |
|
1074 |
} |
|
1075 |
||
1076 |
if (l1 != l2) { |
|
1077 |
RETURN ( false ); |
|
1078 |
} |
|
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1079 |
#undef FAST_STRNCMP |
3111 | 1080 |
#ifdef FAST_STRNCMP |
3451 | 1081 |
RETURN ( (strncmp(cp1, cp2, l1) == 0) ? true : false ); |
3111 | 1082 |
#else |
3451 | 1083 |
addrDelta = cp2 - cp1; |
1084 |
while (l1 >= sizeof(unsigned INT)) { |
|
1085 |
if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) { |
|
1086 |
RETURN (false); |
|
1087 |
} |
|
1088 |
l1 -= sizeof(unsigned INT); |
|
1089 |
cp1 += sizeof(unsigned INT); |
|
1090 |
} |
|
1091 |
if (l1 >= sizeof(unsigned short)) { |
|
1092 |
if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) { |
|
1093 |
RETURN (false); |
|
1094 |
} |
|
1095 |
l1 -= sizeof(unsigned short); |
|
1096 |
cp1 += sizeof(unsigned short); |
|
1097 |
} |
|
1098 |
while (l1) { |
|
1099 |
if (*cp1 != *(cp1+addrDelta)) { |
|
1100 |
RETURN (false); |
|
1101 |
} |
|
1102 |
l1--; |
|
1103 |
cp1++; |
|
1104 |
} |
|
1105 |
||
1106 |
RETURN (true); |
|
3111 | 1107 |
#endif |
1 | 1108 |
} |
3111 | 1109 |
%}. |
608 | 1110 |
^ super = aString |
1 | 1111 |
|
95 | 1112 |
" |
608 | 1113 |
'foo' = 'Foo' |
1114 |
'foo' sameAs: 'Foo' |
|
95 | 1115 |
" |
1 | 1116 |
! |
1117 |
||
608 | 1118 |
> aString |
1119 |
"Compare the receiver with the argument and return true if the |
|
1120 |
receiver is greater than the argument. Otherwise return false. |
|
1121 |
No national variants are honored; use after: for this. |
|
1122 |
In contrast to ST-80, case differences are NOT ignored, thus |
|
1123 |
'foo' > 'Foo' will return true. |
|
1124 |
This may change." |
|
1 | 1125 |
|
375 | 1126 |
%{ /* NOCONTEXT */ |
1127 |
||
608 | 1128 |
int len1, len2, cmp; |
1129 |
REGISTER OBJ s = aString; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1130 |
unsigned char *cp1, *cp2; |
608 | 1131 |
OBJ cls; |
3111 | 1132 |
OBJ myCls; |
1 | 1133 |
|
3111 | 1134 |
if (__isNonNilObject(s)) { |
1135 |
cls = __qClass(s); |
|
1136 |
myCls = __qClass(self); |
|
608 | 1137 |
|
3111 | 1138 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
1139 |
cp2 = __stringVal(s); |
|
1140 |
len2 = __stringSize(s); |
|
1141 |
/* |
|
1142 |
* care for instances of subclasses ... |
|
1143 |
*/ |
|
1144 |
if (cls != String) { |
|
1145 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
608 | 1146 |
|
3111 | 1147 |
cp2 += n; |
1148 |
len2 -= n; |
|
1149 |
} |
|
375 | 1150 |
|
3111 | 1151 |
cp1 = __stringVal(self); |
1152 |
len1 = __stringSize(self); |
|
1153 |
/* |
|
1154 |
* care for instances of subclasses ... |
|
1155 |
*/ |
|
1156 |
if (myCls != String) { |
|
1157 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
|
608 | 1158 |
|
3111 | 1159 |
cp1 += n; |
1160 |
len1 -= n; |
|
1161 |
} |
|
608 | 1162 |
|
3111 | 1163 |
if (len1 <= len2) |
1164 |
cmp = strncmp(cp1, cp2, len1); |
|
1165 |
else |
|
1166 |
cmp = strncmp(cp1, cp2, len2); |
|
608 | 1167 |
|
3111 | 1168 |
if (cmp > 0) { |
1169 |
RETURN ( true ); |
|
1170 |
} |
|
1171 |
if ((cmp == 0) && (len1 > len2)) { |
|
1172 |
RETURN ( true ); |
|
1173 |
} |
|
1174 |
RETURN ( false ); |
|
1175 |
} |
|
1 | 1176 |
} |
370 | 1177 |
%}. |
608 | 1178 |
^ super > aString |
1179 |
! |
|
1 | 1180 |
|
608 | 1181 |
after:aString |
1182 |
"Compare the receiver with the argument and return true if the |
|
1183 |
receiver should come after the argument in a sorted list. |
|
1184 |
Otherwise return false. |
|
1185 |
The comparison is language specific, depending on the value of |
|
1368 | 1186 |
LC_COLLATE, which is initialized from the environment. |
1187 |
||
1188 |
STUPID: |
|
1486 | 1189 |
#after has a completely different meaning in SeqColl ..." |
1 | 1190 |
|
1251 | 1191 |
^ (self compareCollatingWith:aString) > 0 |
1192 |
||
1193 |
" |
|
1194 |
'max' > 'mäx' |
|
1195 |
'man' > 'mäx' |
|
1196 |
'max' after:'mäx' |
|
1197 |
'man' after:'mäx' |
|
1198 |
" |
|
1199 |
||
1368 | 1200 |
"Modified: 10.5.1996 / 14:02:45 / cg" |
1251 | 1201 |
! |
1202 |
||
1203 |
compareCollatingWith:aString |
|
1204 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
1205 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
1206 |
The comparison is language specific, depending on the value of |
|
1207 |
LC_COLLATE, which is in the shell environment." |
|
1208 |
||
1 | 1209 |
%{ /* NOCONTEXT */ |
1210 |
||
608 | 1211 |
int cmp; |
1212 |
REGISTER OBJ s = aString; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1213 |
unsigned char *cp1, *cp2; |
53 | 1214 |
OBJ cls; |
3111 | 1215 |
OBJ myCls; |
608 | 1216 |
|
3111 | 1217 |
if (__isNonNilObject(s)) { |
1218 |
cls = __qClass(s); |
|
1219 |
myCls = __qClass(self); |
|
1220 |
||
1221 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
|
1222 |
cp1 = __stringVal(self); |
|
608 | 1223 |
|
3111 | 1224 |
/* |
1225 |
* care for instances of subclasses ... |
|
1226 |
*/ |
|
1227 |
if (myCls != String) { |
|
1228 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
|
1229 |
||
1230 |
cp1 += n; |
|
1231 |
} |
|
1 | 1232 |
|
3111 | 1233 |
cp2 = __stringVal(s); |
1234 |
/* |
|
1235 |
* care for instances of subclasses ... |
|
1236 |
*/ |
|
1237 |
if (cls != String) { |
|
1238 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
608 | 1239 |
|
3111 | 1240 |
cp2 += n; |
1241 |
} |
|
608 | 1242 |
|
1243 |
#ifdef HAS_STRCOLL |
|
3111 | 1244 |
cmp = strcoll(cp1, cp2); |
608 | 1245 |
#else |
3111 | 1246 |
cmp = strcmp(cp1, cp2); |
608 | 1247 |
#endif |
1248 |
||
3111 | 1249 |
if (cmp > 0) { |
1250 |
RETURN ( __MKSMALLINT(1) ); |
|
1251 |
} |
|
1252 |
if (cmp < 0) { |
|
1253 |
RETURN ( __MKSMALLINT(-1) ); |
|
1254 |
} |
|
1255 |
RETURN ( __MKSMALLINT(0) ); |
|
1256 |
} |
|
370 | 1257 |
} |
329 | 1258 |
%}. |
608 | 1259 |
" |
1260 |
currently, this operation is only defined for strings, symbols |
|
1261 |
and subclasses. |
|
1262 |
" |
|
1251 | 1263 |
^ self primitiveFailed |
1 | 1264 |
! |
1265 |
||
608 | 1266 |
~= aString |
1267 |
"Compare the receiver with the argument and return true if the |
|
1268 |
receiver is not equal to the argument. Otherwise return false. |
|
3111 | 1269 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
1270 |
Actually, there is no need to redefine that method here, |
|
1271 |
the default (= not as inherited) works ok. |
|
1272 |
However, this may be heavily used and the redefinition saves an |
|
1273 |
extra message send." |
|
1 | 1274 |
|
608 | 1275 |
%{ /* NOCONTEXT */ |
1276 |
||
1 | 1277 |
int l1, l2; |
608 | 1278 |
REGISTER OBJ s = aString; |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1279 |
unsigned char *cp1, *cp2; |
3111 | 1280 |
OBJ cls, myCls; |
3335 | 1281 |
INT addrDelta; |
1 | 1282 |
|
608 | 1283 |
if (s == self) { |
3451 | 1284 |
RETURN ( false ); |
608 | 1285 |
} |
1286 |
if (! __isNonNilObject(s)) { |
|
3451 | 1287 |
RETURN ( true ); |
608 | 1288 |
} |
3111 | 1289 |
|
1290 |
cls = __qClass(s); |
|
1291 |
myCls = __qClass(self); |
|
1292 |
||
1293 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
|
3451 | 1294 |
cp1 = __stringVal(self); |
1295 |
l1 = __stringSize(self); |
|
1296 |
/* |
|
1297 |
* care for instances of subclasses ... |
|
1298 |
*/ |
|
1299 |
if (myCls != String) { |
|
1300 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
|
1301 |
||
1302 |
cp1 += n; |
|
1303 |
l1 -= n; |
|
1304 |
} |
|
1305 |
||
1306 |
cp2 = __stringVal(s); |
|
1307 |
l2 = __stringSize(s); |
|
1308 |
/* |
|
1309 |
* care for instances of subclasses ... |
|
1310 |
*/ |
|
1311 |
if (cls != String) { |
|
1312 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1313 |
||
1314 |
cp2 += n; |
|
1315 |
l2 -= n; |
|
1316 |
} |
|
1317 |
||
1318 |
if (l1 != l2) { |
|
1319 |
RETURN ( true ); |
|
1320 |
} |
|
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1321 |
|
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1322 |
#undef FAST_STRNCMP |
3111 | 1323 |
#ifdef FAST_STRNCMP |
3451 | 1324 |
RETURN ( (strncmp(cp1, cp2, l1) == 0) ? false : true ); |
3111 | 1325 |
#else |
3451 | 1326 |
addrDelta = cp2 - cp1; |
1327 |
while (l1 >= sizeof(unsigned INT)) { |
|
1328 |
if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) { |
|
1329 |
RETURN (true); |
|
1330 |
} |
|
1331 |
l1 -= sizeof(unsigned INT); |
|
1332 |
cp1 += sizeof(unsigned INT); |
|
1333 |
} |
|
1334 |
if (l1 >= sizeof(unsigned short)) { |
|
1335 |
if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) { |
|
1336 |
RETURN (true); |
|
1337 |
} |
|
1338 |
l1 -= sizeof(unsigned short); |
|
1339 |
cp1 += sizeof(unsigned short); |
|
1340 |
} |
|
1341 |
while (l1) { |
|
1342 |
if (*cp1 != *(cp1+addrDelta)) { |
|
1343 |
RETURN (true); |
|
1344 |
} |
|
1345 |
l1--; |
|
1346 |
cp1++; |
|
1347 |
} |
|
1348 |
RETURN (false); |
|
3111 | 1349 |
#endif |
608 | 1350 |
} |
3111 | 1351 |
%}. |
608 | 1352 |
^ super ~= aString |
1353 |
! ! |
|
1354 |
||
1355 |
!String methodsFor:'converting'! |
|
1356 |
||
3281
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1357 |
asBoldText |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1358 |
"return self as a bold text" |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1359 |
|
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1360 |
^Text string: self emphasis: #bold |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1361 |
! |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1362 |
|
2856 | 1363 |
asString |
1364 |
"I am a string" |
|
1365 |
||
1366 |
^ self |
|
1367 |
||
1368 |
"Created: 14.8.1997 / 11:37:03 / stefan" |
|
1369 |
! |
|
1370 |
||
608 | 1371 |
asSymbol |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1372 |
"return a unique symbol with the name taken from my characters." |
608 | 1373 |
%{ |
1374 |
OBJ newSymbol; |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1375 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1376 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1377 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1378 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1379 |
if (cls != String) { |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1380 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1381 |
} else { |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1382 |
indx = 0; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1383 |
} |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1384 |
newSymbol = __MKSYMBOL(__stringVal(self) + indx, (OBJ *)0); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1385 |
if (newSymbol) { |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1386 |
RETURN ( newSymbol); |
608 | 1387 |
} |
1388 |
%}. |
|
1389 |
^ ObjectMemory allocationFailureSignal raise. |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1390 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1391 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1392 |
'hello' asSymbol |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1393 |
" |
608 | 1394 |
! |
1395 |
||
1396 |
asSymbolIfInterned |
|
1397 |
"if a symbol with the receivers characters is already known, return it. |
|
1398 |
Otherwise, return nil. This can be used to query for an existing |
|
1399 |
symbol and is the same as |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1400 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
608 | 1401 |
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
|
1402 |
performed once." |
1 | 1403 |
|
608 | 1404 |
%{ /* NOCONTEXT */ |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1405 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1406 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1407 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1408 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1409 |
if (cls != String) { |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1410 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1411 |
} else { |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1412 |
indx = 0; |
608 | 1413 |
} |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1414 |
RETURN ( __SYMBOL_OR_NIL(__stringVal(self) + indx)); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1415 |
%} |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1416 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1417 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1418 |
'hello' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1419 |
'fooBarBaz' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1420 |
" |
608 | 1421 |
! |
1422 |
||
2416 | 1423 |
decodeAsLiteralArray |
1424 |
"given a literalEncoding in the receiver, |
|
1425 |
create & return the corresponding object. |
|
1426 |
The inverse operation to #literalArrayEncoding." |
|
1427 |
||
1428 |
^ self |
|
1429 |
||
1430 |
"Created: 25.2.1997 / 19:18:19 / cg" |
|
1431 |
! |
|
1432 |
||
608 | 1433 |
literalArrayEncoding |
1246 | 1434 |
"encode myself as an array literal, from which a copy of the receiver |
1435 |
can be reconstructed with #decodeAsLiteralArray." |
|
608 | 1436 |
|
1437 |
^ self |
|
1438 |
||
1439 |
"Modified: 1.9.1995 / 02:25:45 / claus" |
|
1246 | 1440 |
"Modified: 22.4.1996 / 13:00:50 / cg" |
608 | 1441 |
! |
1442 |
||
1443 |
withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1444 |
"return a string with the characters of the receiver where all tabulator characters |
608 | 1445 |
are expanded into spaces (assuming 8-col tabs). |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1446 |
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
|
1447 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1448 |
This does handle multiline strings. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1449 |
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
|
1450 |
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
|
1451 |
|
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
1452 |
%{ /* STACK:700 */ |
2894 | 1453 |
unsigned char buffer[80*8 + 10]; |
1454 |
unsigned char *srcP, *dstP, *cp0; |
|
608 | 1455 |
int idx, sz; |
1456 |
int any = 0; |
|
1457 |
OBJ newString; |
|
1458 |
char c; |
|
1459 |
||
1460 |
if (__qClass(self) == String) { |
|
1461 |
/* |
|
1462 |
* for small strings (< 80), do it without a prescan ... |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1463 |
* the buffer is large enough to even convert a |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1464 |
* receiver consisting fully of tabs. |
608 | 1465 |
*/ |
1466 |
if (__stringSize(self) < 80) { |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1467 |
idx = 1; |
608 | 1468 |
for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) { |
1469 |
if (c == '\t') { |
|
1470 |
any = 1; |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1471 |
while (idx % 8) { |
608 | 1472 |
idx++; |
1473 |
*dstP++ = ' '; |
|
159 | 1474 |
} |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1475 |
idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1476 |
*dstP++ = ' '; |
608 | 1477 |
} else { |
1478 |
*dstP++ = c; |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1479 |
idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1480 |
if (c == '\n') { |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1481 |
idx = 1; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1482 |
} |
608 | 1483 |
} |
1484 |
} |
|
1485 |
if (! any) RETURN(self); |
|
1486 |
*dstP = '\0'; |
|
1487 |
RETURN (__MKSTRING_L(buffer, (dstP-buffer))); |
|
1488 |
} |
|
1489 |
/* |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1490 |
* for large strings, we compute the new size, allocate a new string |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1491 |
* and expand it. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1492 |
* |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1493 |
* first, scan for size ... |
608 | 1494 |
*/ |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1495 |
idx = 1; |
608 | 1496 |
for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) { |
1497 |
if (c == '\t') { |
|
1498 |
any = 1; |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1499 |
while (idx % 8) { |
608 | 1500 |
idx++; |
1501 |
sz++; |
|
1502 |
} |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1503 |
idx++; sz ++; |
608 | 1504 |
} else { |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1505 |
sz++; idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1506 |
if (c == '\n') { |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1507 |
idx = 1; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1508 |
} |
159 | 1509 |
} |
1510 |
} |
|
608 | 1511 |
if (! any) RETURN(self); |
1 | 1512 |
|
608 | 1513 |
/* |
1514 |
* get the string |
|
1515 |
*/ |
|
1516 |
sz = OHDR_SIZE + sz + 1; |
|
3111 | 1517 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
608 | 1518 |
if (newString != nil) { |
1134 | 1519 |
__InstPtr(newString)->o_class = String; |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1520 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1521 |
/* |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1522 |
* expand |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1523 |
*/ |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1524 |
idx = 1; |
608 | 1525 |
for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) { |
1526 |
if (c == '\t') { |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1527 |
while (idx % 8) { |
608 | 1528 |
idx++; |
1529 |
*dstP++ = ' '; |
|
1530 |
} |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1531 |
idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1532 |
*dstP++ = ' '; |
608 | 1533 |
} else { |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1534 |
*dstP++ = c; idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1535 |
if (c == '\n') { |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1536 |
idx = 1; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1537 |
} |
608 | 1538 |
} |
1539 |
} |
|
1540 |
*dstP++ = '\0'; |
|
1541 |
RETURN (newString); |
|
1542 |
} |
|
1543 |
} |
|
1544 |
%}. |
|
1545 |
^ super withTabsExpanded |
|
1 | 1546 |
! ! |
1547 |
||
1548 |
!String methodsFor:'copying'! |
|
1549 |
||
1550 |
, aString |
|
2 | 1551 |
"return the concatenation of myself and the argument, aString as |
1552 |
a String. |
|
1 | 1553 |
- reimplemented here for speed" |
1554 |
||
1555 |
%{ |
|
95 | 1556 |
int l1, l2, sz; |
1 | 1557 |
REGISTER OBJ s = aString; |
329 | 1558 |
REGISTER OBJ _string = String; |
13 | 1559 |
OBJ myClass, argClass, newString; |
1 | 1560 |
|
329 | 1561 |
if (__isNonNilObject(s)) { |
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1562 |
myClass = __qClass(self); |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1563 |
argClass = __qClass(s); |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1564 |
/* |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1565 |
* can do it here if both are Strings/Symbols: |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1566 |
*/ |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1567 |
if (((myClass == _string) || (myClass == Symbol)) |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1568 |
&& ((argClass == _string) || (argClass == Symbol))) { |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1569 |
l1 = __stringSize(self); |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1570 |
l2 = __stringSize(s); |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1571 |
|
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1572 |
sz = OHDR_SIZE + l1 + l2 + 1; |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1573 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1574 |
if (newString != nil) { |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1575 |
char *cp1, *cp2; |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1576 |
REGISTER unsigned char *dstp; |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1577 |
|
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1578 |
__InstPtr(newString)->o_class = String; |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1579 |
dstp = __stringVal(newString); |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1580 |
cp1 = (char *) __stringVal(self); |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1581 |
cp2 = (char *) __stringVal(aString); |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1582 |
|
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1583 |
#ifdef bcopy4 |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1584 |
/* knowing that allocation is 4-byte aligned and |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1585 |
* size rounded up to next 4-byte, the first copy |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1586 |
* can be done word-wise. |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1587 |
* that speeds up size-10-string , size-10-string |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1588 |
* by 10% on a P5/200. |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1589 |
*/ |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1590 |
{ |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1591 |
int nw = l1 >> 2; |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1592 |
|
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1593 |
if (l1 & 3) nw++; |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1594 |
bcopy4(cp1, dstp, nw); |
3673 | 1595 |
dstp += l1; |
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1596 |
} |
3673 | 1597 |
#else |
1598 |
# ifdef FAST_MEMCPY |
|
1599 |
bcopy(cp1, dstp, l1); |
|
1600 |
dstp += l1; |
|
1601 |
# else |
|
1602 |
# ifdef FAST_STRCPY |
|
1603 |
strncpy(dstp, cp1, l1); |
|
1604 |
dstp += l1; |
|
1605 |
# else |
|
1606 |
while (l1--) *dstp++ = *cp1++; |
|
1607 |
# endif |
|
1608 |
# endif |
|
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1609 |
#endif |
2862 | 1610 |
|
3673 | 1611 |
#ifdef bcopy4 |
1612 |
if (((INT)dstp & 3) == 0) { |
|
1613 |
int nw = l2 >> 2; |
|
1614 |
||
1615 |
if (l2 & 3) nw++; |
|
1616 |
bcopy4(cp2, dstp, nw); |
|
1617 |
*(dstp + l2) = '\0'; |
|
1618 |
RETURN ( newString ); |
|
1619 |
} |
|
1620 |
#endif |
|
1621 |
||
1 | 1622 |
#ifdef FAST_MEMCPY |
3673 | 1623 |
bcopy(cp2, dstp, l2+1); |
1624 |
*(dstp + l2) = '\0'; |
|
1 | 1625 |
#else |
1626 |
# ifdef FAST_STRCPY |
|
3673 | 1627 |
strncpy(dstp, cp2, l2); |
1628 |
*(dstp + l2) = '\0'; |
|
1 | 1629 |
# else |
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1630 |
while (l2--) *dstp++ = *cp2++; |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1631 |
*dstp = '\0'; |
1 | 1632 |
# endif |
1633 |
#endif |
|
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1634 |
RETURN ( newString ); |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1635 |
} |
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1636 |
} |
1 | 1637 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1638 |
%}. |
1 | 1639 |
^ super , aString |
1640 |
! |
|
1641 |
||
1642 |
concatenate:string1 and:string2 |
|
1643 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
1644 |
This is equivalent to self , string1 , string2 |
|
1645 |
- generated by compiler when such a construct is detected" |
|
1646 |
||
1647 |
|newString| |
|
2862 | 1648 |
|
1 | 1649 |
%{ |
95 | 1650 |
int len1, len2, len3, sz; |
1 | 1651 |
#if !defined(FAST_MEMCPY) && !defined(FAST_STRCPY) |
1652 |
REGISTER unsigned char *srcp; |
|
1653 |
#endif |
|
1654 |
REGISTER unsigned char *dstp; |
|
1655 |
||
53 | 1656 |
if ((__isString(self) || __isSymbol(self)) |
1657 |
&& (__isString(string1) || __isSymbol(string1)) |
|
1658 |
&& (__isString(string2) || __isSymbol(string2))) { |
|
1134 | 1659 |
len1 = __stringSize(self); |
1660 |
len2 = __stringSize(string1); |
|
1661 |
len3 = __stringSize(string2); |
|
95 | 1662 |
sz = OHDR_SIZE + len1 + len2 + len3 + 1; |
3111 | 1663 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
159 | 1664 |
if (newString != nil) { |
1134 | 1665 |
__InstPtr(newString)->o_class = String; |
1666 |
dstp = __stringVal(newString); |
|
1 | 1667 |
#ifdef FAST_MEMCPY |
1134 | 1668 |
bcopy(__stringVal(self), dstp, len1); |
1669 |
bcopy(__stringVal(string1), dstp + len1, len2); |
|
1670 |
bcopy(__stringVal(string2), dstp + len1 + len2, len3+1); |
|
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1671 |
*(dstp + len1 + len2 + len3) = '\0'; |
1 | 1672 |
#else |
1673 |
# ifdef FAST_STRCPY |
|
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1674 |
strncpy(dstp, __stringVal(self), len1); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1675 |
strncpy(dstp + len1, __stringVal(string1), len2); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1676 |
strncpy(dstp + len1 + len2, __stringVal(string2), len3); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1677 |
*(dstp + len1 + len2 + len3) = '\0'; |
1 | 1678 |
# else |
1134 | 1679 |
srcp = __stringVal(self); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1680 |
while (len1--) *dstp++ = *srcp++; |
1134 | 1681 |
srcp = __stringVal(string1); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1682 |
while (len2--) *dstp++ = *srcp++; |
1134 | 1683 |
srcp = __stringVal(string2); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1684 |
while (len3--) *dstp++ = *srcp++; |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1685 |
*dstp = '\0'; |
1 | 1686 |
# endif |
1687 |
#endif |
|
159 | 1688 |
RETURN ( newString ); |
1689 |
} |
|
1 | 1690 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1691 |
%}. |
1 | 1692 |
^ super , string1 , string2 |
1693 |
! |
|
1694 |
||
1695 |
concatenate:string1 and:string2 and:string3 |
|
1696 |
"return the concatenation of myself and the string arguments. |
|
1697 |
This is equivalent to self , string1 , string2 , string3 |
|
1698 |
- generated by compiler when such a construct is detected" |
|
1699 |
||
1700 |
|newString| |
|
2862 | 1701 |
|
1 | 1702 |
%{ |
95 | 1703 |
int len1, len2, len3, len4, sz; |
1 | 1704 |
#if !defined(FAST_MEMCPY) && !defined(FAST_STRCPY) |
1705 |
REGISTER unsigned char *srcp; |
|
1706 |
#endif |
|
1707 |
REGISTER unsigned char *dstp; |
|
1708 |
||
53 | 1709 |
if ((__isString(self) || __isSymbol(self)) |
1710 |
&& (__isString(string1) || __isSymbol(string1)) |
|
1711 |
&& (__isString(string2) || __isSymbol(string2)) |
|
1712 |
&& (__isString(string3) || __isSymbol(string3))) { |
|
1134 | 1713 |
len1 = __stringSize(self); |
1714 |
len2 = __stringSize(string1); |
|
1715 |
len3 = __stringSize(string2); |
|
1716 |
len4 = __stringSize(string3); |
|
95 | 1717 |
sz = OHDR_SIZE + len1 + len2 + len3 + len4 + 1; |
3111 | 1718 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
159 | 1719 |
if (newString != nil) { |
1134 | 1720 |
__InstPtr(newString)->o_class = String; |
1721 |
dstp = __stringVal(newString); |
|
1 | 1722 |
#ifdef FAST_MEMCPY |
1134 | 1723 |
bcopy(__stringVal(self), dstp, len1); |
1724 |
bcopy(__stringVal(string1), dstp + len1, len2); |
|
1725 |
bcopy(__stringVal(string2), dstp + len1 + len2, len3); |
|
1726 |
bcopy(__stringVal(string3), dstp + len1 + len2 + len3, len4+1); |
|
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1727 |
*(dstp + len1 + len2 + len3 + len4) = '\0'; |
1 | 1728 |
#else |
1729 |
# ifdef FAST_STRCPY |
|
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1730 |
strncpy(dstp, __stringVal(self), len1); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1731 |
strncpy(dstp + len1, __stringVal(string1), len2); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1732 |
strncpy(dstp + len1 + len2, __stringVal(string2), len3); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1733 |
strncpy(dstp + len1 + len2 + len3, __stringVal(string3), len4); |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1734 |
*(dstp + len1 + len2 + len3 + len4) = '\0'; |
1 | 1735 |
# else |
1134 | 1736 |
srcp = __stringVal(self); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1737 |
while (len1--) *dstp++ = *srcp++; |
1134 | 1738 |
srcp = __stringVal(string1); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1739 |
while (len2--) *dstp++ = *srcp++; |
1134 | 1740 |
srcp = __stringVal(string2); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1741 |
while (len3--) *dstp++ = *srcp++; |
1134 | 1742 |
srcp = __stringVal(string3); |
3153
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1743 |
while (len4--) *dstp++ = *srcp++; |
d8eed4e5c60f
use strncpy when concatenating strings.
Claus Gittinger <cg@exept.de>
parents:
3111
diff
changeset
|
1744 |
*dstp = '\0'; |
1 | 1745 |
# endif |
1746 |
#endif |
|
159 | 1747 |
RETURN ( newString ); |
1748 |
} |
|
1 | 1749 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1750 |
%}. |
1 | 1751 |
^ super , string1 , string2 , string3 |
1752 |
! |
|
1753 |
||
608 | 1754 |
copyFrom:start |
1755 |
"return the substring from start, anInteger to the end. |
|
1756 |
This method will always return a string, even if the receiver |
|
1757 |
is a subclass-instance. This might change if there is a need. |
|
1758 |
- reimplemented here for speed" |
|
1 | 1759 |
|
13 | 1760 |
%{ /* NOCONTEXT */ |
1 | 1761 |
|
608 | 1762 |
#if !defined(FAST_MEMCPY) |
1763 |
REGISTER unsigned char *srcp; |
|
1764 |
#endif |
|
1 | 1765 |
REGISTER unsigned char *dstp; |
608 | 1766 |
REGISTER int count; |
1767 |
int len, index1, sz; |
|
1768 |
OBJ newString; |
|
2862 | 1769 |
OBJ myClass; |
608 | 1770 |
|
2862 | 1771 |
myClass = __qClass(self); |
1772 |
||
2894 | 1773 |
#ifndef NO_PRIM_STRING |
2862 | 1774 |
if (__isSmallInteger(start) |
1775 |
&& ((myClass==String) || (myClass==Symbol))) { |
|
1134 | 1776 |
len = __stringSize(self); |
1777 |
index1 = __intVal(start); |
|
608 | 1778 |
if (index1 > 0) { |
1779 |
if (index1 <= len) { |
|
1780 |
count = len - index1 + 1; |
|
2862 | 1781 |
sz = OHDR_SIZE + count + 1; |
1782 |
||
834 | 1783 |
__PROTECT_CONTEXT__ |
3111 | 1784 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
834 | 1785 |
__UNPROTECT_CONTEXT__ |
2862 | 1786 |
|
608 | 1787 |
if (newString != nil) { |
1134 | 1788 |
__InstPtr(newString)->o_class = String; |
1789 |
dstp = __stringVal(newString); |
|
1 | 1790 |
#ifdef FAST_MEMCPY |
1134 | 1791 |
bcopy(__stringVal(self) + index1 - 1, dstp, count); |
608 | 1792 |
dstp[count] = '\0'; |
1 | 1793 |
#else |
1794 |
# ifdef FAST_STRCPY |
|
1134 | 1795 |
strncpy(dstp, __stringVal(self) + index1 - 1, count); |
608 | 1796 |
dstp[count] = '\0'; |
1 | 1797 |
# else |
1134 | 1798 |
srcp = __stringVal(self) + index1 - 1; |
608 | 1799 |
while (count--) { |
1800 |
*dstp++ = *srcp++; |
|
1801 |
} |
|
1802 |
*dstp = '\0'; |
|
1 | 1803 |
# endif |
1804 |
#endif |
|
608 | 1805 |
RETURN ( newString ); |
1806 |
} |
|
1807 |
} |
|
159 | 1808 |
} |
13 | 1809 |
} |
2894 | 1810 |
#endif |
51 | 1811 |
%}. |
608 | 1812 |
"fall back in case of non-integer index or out-of-bound index; |
1813 |
will eventually lead to an out-of-bound signal raise" |
|
51 | 1814 |
|
608 | 1815 |
^ super copyFrom:start |
1 | 1816 |
! |
1817 |
||
1818 |
copyFrom:start to:stop |
|
1819 |
"return the substring starting at index start, anInteger and ending |
|
53 | 1820 |
at stop, anInteger. This method will always return a string, even |
1821 |
if the receiver is a subclass-instance. This might change if there is a need. |
|
1 | 1822 |
- reimplemented here for speed" |
1823 |
||
13 | 1824 |
%{ /* NOCONTEXT */ |
1825 |
||
1 | 1826 |
REGISTER unsigned char *srcp; |
1827 |
REGISTER unsigned char *dstp; |
|
1828 |
REGISTER int count; |
|
95 | 1829 |
int len, sz, index1, index2; |
13 | 1830 |
OBJ newString; |
2862 | 1831 |
OBJ myClass; |
1 | 1832 |
|
2862 | 1833 |
myClass = __qClass(self); |
1834 |
||
2894 | 1835 |
#ifndef NO_PRIM_STRING |
2862 | 1836 |
if (__bothSmallInteger(start, stop) |
1837 |
&& ((myClass==String) || (myClass==Symbol))) { |
|
1134 | 1838 |
len = __stringSize(self); |
1839 |
index1 = __intVal(start); |
|
1840 |
index2 = __intVal(stop); |
|
1 | 1841 |
|
159 | 1842 |
if ((index1 <= index2) && (index1 > 0)) { |
1843 |
if (index2 <= len) { |
|
1844 |
count = index2 - index1 + 1; |
|
1399 | 1845 |
sz = OHDR_SIZE + count + 1; |
2862 | 1846 |
|
834 | 1847 |
__PROTECT_CONTEXT__ |
3111 | 1848 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
834 | 1849 |
__UNPROTECT_CONTEXT__ |
1399 | 1850 |
|
159 | 1851 |
if (newString != nil) { |
1134 | 1852 |
__InstPtr(newString)->o_class = String; |
1853 |
dstp = __stringVal(newString); |
|
2894 | 1854 |
srcp = __stringVal(self) + index1 - 1; |
1855 |
#ifdef bcopy4 |
|
3111 | 1856 |
{ |
1857 |
int nw = count >> 2; |
|
2894 | 1858 |
|
3111 | 1859 |
if (count & 3) { |
1860 |
nw++; |
|
1861 |
} |
|
1862 |
bcopy4(srcp, dstp, nw); |
|
1863 |
dstp[count] = '\0'; |
|
1864 |
} |
|
1 | 1865 |
#else |
2894 | 1866 |
# ifdef FAST_MEMCPY |
1867 |
bcopy(srcp, dstp, count); |
|
209 | 1868 |
dstp[count] = '\0'; |
1869 |
# else |
|
2894 | 1870 |
# ifdef FAST_STRCPY |
1871 |
strncpy(dstp, srcp, count); |
|
1872 |
dstp[count] = '\0'; |
|
1873 |
# else |
|
159 | 1874 |
while (count--) { |
1875 |
*dstp++ = *srcp++; |
|
1876 |
} |
|
1877 |
*dstp = '\0'; |
|
2894 | 1878 |
# endif |
209 | 1879 |
# endif |
13 | 1880 |
#endif |
159 | 1881 |
RETURN ( newString ); |
1882 |
} |
|
1883 |
} |
|
1884 |
} |
|
375 | 1885 |
/* |
1886 |
* allow empty copy |
|
1887 |
*/ |
|
1888 |
if (index1 > index2) { |
|
834 | 1889 |
__PROTECT_CONTEXT__ |
3111 | 1890 |
__qNew(newString, OHDR_SIZE+1); /* OBJECT ALLOCATION */ |
834 | 1891 |
__UNPROTECT_CONTEXT__ |
375 | 1892 |
if (newString != nil) { |
1134 | 1893 |
__InstPtr(newString)->o_class = String; |
2894 | 1894 |
(__stringVal(newString))[0] = '\0'; |
375 | 1895 |
RETURN ( newString ); |
1896 |
} |
|
1897 |
} |
|
1 | 1898 |
} |
2894 | 1899 |
#endif |
51 | 1900 |
%}. |
1901 |
"fall back in case of non-integer index or out-of-bound index; |
|
1902 |
will eventually lead to an out-of-bound signal raise" |
|
1903 |
||
1 | 1904 |
^ super copyFrom:start to:stop |
1905 |
! |
|
1906 |
||
608 | 1907 |
copyWith:aCharacter |
1908 |
"return a new string containing the receivers characters |
|
1909 |
and the single new character, aCharacter. |
|
1910 |
This is different from concatentation, which expects another string |
|
1911 |
as argument, but equivalent to copy-and-addLast. |
|
1912 |
Reimplemented here for more speed" |
|
1913 |
||
1914 |
%{ /* NOCONTEXT */ |
|
1915 |
||
2887 | 1916 |
int count; |
608 | 1917 |
int sz; |
1918 |
REGISTER unsigned char *dstp; |
|
1919 |
OBJ cls, newString; |
|
2862 | 1920 |
OBJ myClass; |
608 | 1921 |
|
2862 | 1922 |
myClass = __qClass(self); |
1923 |
||
2894 | 1924 |
#ifndef NO_PRIM_STRING |
2862 | 1925 |
if (__isCharacter(aCharacter) |
1926 |
&& ((myClass==String) || (myClass==Symbol))) { |
|
2887 | 1927 |
count = __stringSize(self); |
1928 |
sz = OHDR_SIZE + count + 1 + 1; |
|
608 | 1929 |
|
834 | 1930 |
__PROTECT_CONTEXT__ |
3111 | 1931 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
834 | 1932 |
__UNPROTECT_CONTEXT__ |
2862 | 1933 |
|
608 | 1934 |
if (newString) { |
1134 | 1935 |
__InstPtr(newString)->o_class = String; |
1936 |
dstp = __stringVal(newString); |
|
2862 | 1937 |
|
2887 | 1938 |
#ifdef bcopy4 |
1939 |
{ |
|
1940 |
int nw = count >> 2; |
|
1941 |
char *srcp = (char *)__stringVal(self); |
|
1942 |
||
1943 |
if (count & 3) { |
|
1944 |
nw++; |
|
1945 |
} |
|
1946 |
bcopy4(srcp, dstp, nw); |
|
1947 |
dstp += count; |
|
1948 |
} |
|
608 | 1949 |
#else |
2887 | 1950 |
# ifdef FAST_MEMCPY |
1951 |
bcopy(__stringVal(self), dstp, count); |
|
1952 |
dstp += count; |
|
608 | 1953 |
# else |
2887 | 1954 |
# ifdef FAST_STRCPY |
1955 |
strncpy(dstp, __stringVal(self), count); |
|
1956 |
dstp += count; |
|
1957 |
# else |
|
608 | 1958 |
{ |
1959 |
REGISTER unsigned char *srcp; |
|
1960 |
||
2862 | 1961 |
srcp = __stringVal(self); |
608 | 1962 |
while ((*dstp = *srcp++) != '\0') |
1963 |
dstp++; |
|
1964 |
} |
|
2887 | 1965 |
# endif |
608 | 1966 |
# endif |
2887 | 1967 |
# endif |
1134 | 1968 |
*dstp++ = __intVal(_characterVal(aCharacter)); |
608 | 1969 |
*dstp = '\0'; |
1970 |
RETURN (newString ); |
|
1971 |
} |
|
1972 |
} |
|
2894 | 1973 |
#endif |
608 | 1974 |
%}. |
1975 |
"fall back in case of non-character arg; |
|
1976 |
will eventually lead to an bad element signal raise" |
|
1977 |
||
1978 |
^ super copyWith:aCharacter |
|
1979 |
! |
|
1980 |
||
2886 | 1981 |
deepCopy |
1982 |
"return a copy of the receiver" |
|
608 | 1983 |
|
1984 |
" |
|
1985 |
could be an instance of a subclass which needs deepCopy |
|
1986 |
of its named instvars ... |
|
1987 |
" |
|
1988 |
(self isMemberOf:String) ifTrue:[ |
|
1989 |
^ self copyFrom:1 |
|
1990 |
]. |
|
1991 |
^ super deepCopy |
|
1992 |
! |
|
1993 |
||
2886 | 1994 |
deepCopyUsing:aDictionary |
608 | 1995 |
"return a copy of the receiver - reimplemented to be a bit faster" |
1996 |
||
1997 |
" |
|
1998 |
could be an instance of a subclass which needs deepCopy |
|
1999 |
of its named instvars ... |
|
2000 |
" |
|
2001 |
(self isMemberOf:String) ifTrue:[ |
|
2002 |
^ self copyFrom:1 |
|
2003 |
]. |
|
2004 |
^ super deepCopy |
|
2005 |
! |
|
2006 |
||
2886 | 2007 |
shallowCopy |
2008 |
"return a copy of the receiver" |
|
608 | 2009 |
|
2010 |
(self isMemberOf:String) ifTrue:[ |
|
2011 |
^ self copyFrom:1 |
|
2012 |
]. |
|
2013 |
^ super shallowCopy |
|
2014 |
! |
|
2015 |
||
2886 | 2016 |
simpleDeepCopy |
2017 |
"return a copy of the receiver" |
|
608 | 2018 |
|
2019 |
" |
|
2020 |
could be an instance of a subclass which needs deepCopy |
|
2021 |
of its named instvars ... |
|
2022 |
" |
|
2023 |
(self isMemberOf:String) ifTrue:[ |
|
2024 |
^ self copyFrom:1 |
|
2025 |
]. |
|
2026 |
^ super deepCopy |
|
2027 |
! ! |
|
2028 |
||
2029 |
!String methodsFor:'filling and replacing'! |
|
2030 |
||
2886 | 2031 |
atAllPut:aCharacter |
608 | 2032 |
"replace all elements with aCharacter |
1 | 2033 |
- reimplemented here for speed" |
2034 |
||
13 | 2035 |
%{ /* NOCONTEXT */ |
2036 |
||
608 | 2037 |
#ifndef FAST_MEMSET |
2038 |
REGISTER unsigned char *dst; |
|
2039 |
REGISTER int l; |
|
1 | 2040 |
#endif |
608 | 2041 |
REGISTER int byteValue; |
1 | 2042 |
|
608 | 2043 |
if (__isCharacter(aCharacter) && __isString(self)) { |
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2044 |
byteValue = __intVal(_characterVal(aCharacter)); |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2045 |
|
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2046 |
#ifdef FAST_MEMSET |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2047 |
memset(__stringVal(self), byteValue, __stringSize(self)); |
608 | 2048 |
#else |
3712 | 2049 |
{ |
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2050 |
INT v; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2051 |
|
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2052 |
v = (byteValue << 8) | byteValue; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2053 |
v = (v << 16) | v; |
3712 | 2054 |
|
2055 |
dst = __stringVal(self); |
|
2056 |
l = __stringSize(self); |
|
2057 |
||
2058 |
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */ |
|
2059 |
memset4(dst, v, l>>2); |
|
2060 |
l = l & 3; |
|
2061 |
# else |
|
2062 |
# ifdef UINT64 |
|
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2063 |
v = (v << 32) | v; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2064 |
while (l >= 8) { |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2065 |
((UINT64 *)dst)[0] = v; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2066 |
dst += 8; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2067 |
l -= 8; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2068 |
} |
3712 | 2069 |
# else /* no UINT64 */ |
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2070 |
while (l >= 16) { |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2071 |
((int *)dst)[0] = v; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2072 |
((int *)dst)[1] = v; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2073 |
((int *)dst)[2] = v; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2074 |
((int *)dst)[3] = v; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2075 |
dst += 16; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2076 |
l -= 16; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2077 |
} |
3712 | 2078 |
if (l >= 8) { |
2079 |
((int *)dst)[0] = v; |
|
2080 |
((int *)dst)[1] = v; |
|
2081 |
dst += 8; |
|
2082 |
l -= 8; |
|
2083 |
} |
|
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2084 |
if (l >= 4) { |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2085 |
((int *)dst)[0] = v; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2086 |
dst += 4; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2087 |
l -= 4; |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2088 |
} |
3712 | 2089 |
# if 0 |
2090 |
if (l >= 2) { |
|
2091 |
((short *)dst)[0] = v; |
|
2092 |
dst += 2; |
|
2093 |
l -= 2; |
|
2094 |
} |
|
2095 |
# endif |
|
2096 |
||
2097 |
# endif |
|
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2098 |
# endif |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2099 |
} |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2100 |
|
3712 | 2101 |
/* |
2102 |
* remaining bytes |
|
2103 |
*/ |
|
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2104 |
while (l--) |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2105 |
*dst++ = byteValue; |
3712 | 2106 |
|
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2107 |
#endif /* no FAST_MEMSET */ |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2108 |
|
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2109 |
RETURN ( self ); |
608 | 2110 |
} |
2862 | 2111 |
%}. |
608 | 2112 |
^ super atAllPut:aCharacter |
1 | 2113 |
|
608 | 2114 |
" |
3712 | 2115 |
(String new:10) atAllPut:$* |
608 | 2116 |
String new:10 withAll:$* |
2117 |
" |
|
2118 |
! |
|
2119 |
||
2929 | 2120 |
replaceAll:oldCharacter with:newCharacter |
608 | 2121 |
"replace all oldCharacters by newCharacter in the receiver" |
2122 |
||
2123 |
%{ /* NOCONTEXT */ |
|
2124 |
||
2125 |
REGISTER unsigned char *srcp; |
|
2126 |
REGISTER unsigned oldVal, newVal; |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2127 |
unsigned char c; |
608 | 2128 |
|
2129 |
if (__isCharacter(oldCharacter) |
|
2130 |
&& __isCharacter(newCharacter) |
|
2131 |
&& __isString(self)) { |
|
3111 | 2132 |
srcp = (unsigned char *)__stringVal(self); |
2133 |
oldVal = __intVal(_characterVal(oldCharacter)); |
|
2134 |
newVal = __intVal(_characterVal(newCharacter)); |
|
2135 |
while ((c = *srcp) != '\0') { |
|
2136 |
if (c == oldVal) |
|
2137 |
*srcp = newVal; |
|
2138 |
srcp++; |
|
2139 |
} |
|
2140 |
RETURN ( self ); |
|
1 | 2141 |
} |
2862 | 2142 |
%}. |
2929 | 2143 |
^ super replaceAll:oldCharacter with:newCharacter |
51 | 2144 |
|
608 | 2145 |
" |
2929 | 2146 |
'helloWorld' copy replaceAll:$o with:$O |
608 | 2147 |
" |
2148 |
! |
|
1 | 2149 |
|
2886 | 2150 |
replaceFrom:start to:stop with:aString startingAt:repStart |
1 | 2151 |
"replace the characters starting at index start, anInteger and ending |
2152 |
at stop, anInteger with characters from aString starting at repStart. |
|
3234 | 2153 |
Return the receiver. |
1 | 2154 |
|
2155 |
- reimplemented here for speed" |
|
2156 |
||
2157 |
%{ /* NOCONTEXT */ |
|
2158 |
||
2159 |
REGISTER unsigned char *srcp, *dstp; |
|
2160 |
REGISTER int count; |
|
2161 |
int len, index1, index2; |
|
2162 |
int repLen, repIndex; |
|
2163 |
||
2894 | 2164 |
#ifndef NO_PRIM_STRING |
53 | 2165 |
if ((__isString(aString) || __isSymbol(aString)) |
2166 |
&& __isString(self) |
|
252 | 2167 |
&& __bothSmallInteger(start, stop)) { |
3451 | 2168 |
len = __stringSize(self); |
2169 |
index1 = __intVal(start); |
|
2170 |
index2 = __intVal(stop); |
|
2171 |
count = index2 - index1 + 1; |
|
2172 |
if (count <= 0) { |
|
2173 |
RETURN (self); |
|
2174 |
} |
|
2175 |
if ((index2 <= len) && (index1 > 0)) { |
|
2176 |
repLen = __stringSize(aString); |
|
2177 |
repIndex = __intVal(repStart); |
|
2178 |
if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) { |
|
2179 |
srcp = __stringVal(aString) + repIndex - 1; |
|
2180 |
dstp = __stringVal(self) + index1 - 1; |
|
2181 |
if (aString == self) { |
|
2182 |
/* take care of overlapping copy */ |
|
2183 |
if (srcp < dstp) { |
|
2184 |
/* must do a reverse copy */ |
|
2185 |
srcp += count; |
|
2186 |
dstp += count; |
|
2187 |
while (count-- > 0) { |
|
2188 |
*--dstp = *--srcp; |
|
2189 |
} |
|
2190 |
RETURN (self); |
|
2191 |
} |
|
2192 |
} |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2193 |
#ifdef bcopy4 |
3451 | 2194 |
/* copy quadbytes if pointers are aligned */ |
2195 |
/* |
|
2196 |
* no sizeof(int) here please - |
|
2197 |
* - bcopy4 (if defined) copies 4-bytes on ALL machines |
|
2198 |
*/ |
|
2199 |
if ((count > 12) |
|
2200 |
&& (((unsigned INT)srcp & 3) == 0) |
|
2201 |
&& (((unsigned INT)dstp & 3) == 0)) { |
|
2202 |
int n; |
|
2203 |
||
2204 |
n = count >> 2; /* make it quads */ |
|
2205 |
bcopy4(srcp, dstp, n); |
|
2206 |
n <<= 2; /* back to chars */ |
|
2207 |
dstp += n; |
|
2208 |
srcp += n; |
|
2209 |
count -= n; |
|
2210 |
} |
|
2211 |
while (count-- > 0) { |
|
2212 |
*dstp++ = *srcp++; |
|
2213 |
} |
|
1 | 2214 |
#else |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2215 |
# ifdef FAST_MEMCPY |
3451 | 2216 |
bcopy(srcp, dstp, count); |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2217 |
# else |
3451 | 2218 |
/* copy longs if pointers are aligned */ |
2219 |
if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0) |
|
2220 |
&& (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) { |
|
2221 |
while (count >= sizeof(INT)) { |
|
2222 |
*((unsigned INT *)dstp) = *((unsigned INT *)srcp); |
|
2223 |
dstp += sizeof(INT); |
|
2224 |
srcp += sizeof(INT); |
|
2225 |
count -= sizeof(INT); |
|
2226 |
} |
|
2227 |
} |
|
2228 |
while (count-- > 0) { |
|
2229 |
*dstp++ = *srcp++; |
|
2230 |
} |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2231 |
# endif |
1 | 2232 |
#endif |
3451 | 2233 |
RETURN (self); |
2234 |
} |
|
2235 |
} |
|
1 | 2236 |
} |
2894 | 2237 |
#endif |
2862 | 2238 |
%}. |
1 | 2239 |
^ super replaceFrom:start to:stop with:aString startingAt:repStart |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2240 |
|
1 | 2241 |
! |
2242 |
||
2886 | 2243 |
reverse |
2244 |
"in-place reverse the characters of the string." |
|
53 | 2245 |
|
2246 |
"Q: is there a need to redefine it here ?" |
|
1 | 2247 |
|
2248 |
%{ /* NOCONTEXT */ |
|
2249 |
||
2250 |
REGISTER char c; |
|
2251 |
REGISTER unsigned char *hip, *lowp; |
|
2252 |
||
53 | 2253 |
if (__isString(self)) { |
1134 | 2254 |
lowp = __stringVal(self); |
2255 |
hip = lowp + __stringSize(self) - 1; |
|
159 | 2256 |
while (lowp < hip) { |
2257 |
c = *lowp; |
|
2258 |
*lowp = *hip; |
|
2259 |
*hip = c; |
|
2260 |
lowp++; |
|
2261 |
hip--; |
|
2262 |
} |
|
2263 |
RETURN ( self ); |
|
1 | 2264 |
} |
2862 | 2265 |
%}. |
1 | 2266 |
^ super reverse |
2267 |
! |
|
2268 |
||
2269 |
withoutSeparators |
|
2862 | 2270 |
"return a string containing the chars of myself |
2271 |
without leading and trailing whitespace. |
|
2272 |
If there is no whitespace, the receiver is returned. |
|
95 | 2273 |
Notice, this is different from String>>withoutSpaces." |
1 | 2274 |
|
42 | 2275 |
|startIndex "{ Class: SmallInteger }" |
51 | 2276 |
endIndex "{ Class: SmallInteger }" |
2277 |
sz| |
|
2278 |
||
53 | 2279 |
startIndex := 0. |
2862 | 2280 |
|
51 | 2281 |
%{ |
2884 | 2282 |
REGISTER unsigned char *cp; |
2283 |
REGISTER unsigned char *ep; |
|
2284 |
REGISTER unsigned char c; |
|
51 | 2285 |
REGISTER unsigned char *cp0; |
2884 | 2286 |
REGISTER unsigned char *ep0; |
1 | 2287 |
|
51 | 2288 |
/* ignore instances of subclasses ... */ |
329 | 2289 |
if (__qClass(self) == String) { |
3111 | 2290 |
cp = cp0 = __stringVal(self); |
2862 | 2291 |
|
3111 | 2292 |
/* |
2293 |
* find first non-whiteSpace from beginning |
|
2294 |
*/ |
|
2862 | 2295 |
#ifndef NON_ASCII |
2954 | 2296 |
# ifdef UINT64 |
3111 | 2297 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
2298 |
cp += 8; |
|
2299 |
} |
|
2862 | 2300 |
# endif |
3111 | 2301 |
while (*((unsigned *)cp) == 0x20202020) { |
2302 |
cp += 4; |
|
2303 |
} |
|
2862 | 2304 |
#endif |
3111 | 2305 |
while ((c = *cp) |
329 | 2306 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
3111 | 2307 |
&& (c <= ' ') |
329 | 2308 |
#endif |
3111 | 2309 |
&& ((c == ' ') || (c == '\n') || (c == '\t') |
2310 |
|| (c == '\r') || (c == '\f')) |
|
2311 |
) { |
|
2312 |
cp++; |
|
2313 |
} |
|
2884 | 2314 |
|
3111 | 2315 |
/* |
2316 |
* find first non-whiteSpace from end |
|
2317 |
*/ |
|
2318 |
ep = ep0 = cp0 + __stringSize(self) - 1; |
|
2319 |
while ((ep >= cp) && (*ep == ' ')) ep--; |
|
2320 |
c = *ep; |
|
2321 |
while ((ep >= cp) && |
|
2862 | 2322 |
#ifndef NON_ASCII |
3111 | 2323 |
(c <= ' ') && |
329 | 2324 |
#endif |
3111 | 2325 |
((c == ' ') || (c == '\n') || (c == '\t') |
2326 |
|| (c == '\r') || (c == '\f'))) { |
|
2327 |
ep--; |
|
2328 |
c = *ep; |
|
2329 |
} |
|
2884 | 2330 |
|
3111 | 2331 |
/* |
2332 |
* no whiteSpace ? |
|
2333 |
*/ |
|
2334 |
if ((cp == cp0) && (ep == ep0)) { |
|
2335 |
RETURN(self); |
|
2336 |
} |
|
2884 | 2337 |
|
3111 | 2338 |
startIndex = __MKSMALLINT(cp - cp0 + 1); |
2339 |
endIndex = __MKSMALLINT(ep - cp0 + 1); |
|
51 | 2340 |
} |
202 | 2341 |
%}. |
2342 |
startIndex == 0 ifTrue:[^ super withoutSeparators]. |
|
2343 |
||
2344 |
startIndex > endIndex ifTrue:[^ '']. |
|
1 | 2345 |
^ self copyFrom:startIndex to:endIndex |
2884 | 2346 |
|
2347 |
" |
|
2348 |
'hello' withoutSeparators |
|
2349 |
' hello' withoutSeparators |
|
2350 |
' hello ' withoutSeparators |
|
2351 |
' hello ' withoutSeparators |
|
2352 |
' hello ' withoutSeparators |
|
2353 |
' hello ' withoutSeparators |
|
2354 |
' ' withoutSeparators |
|
2355 |
" |
|
2356 |
||
608 | 2357 |
! |
2358 |
||
2359 |
withoutSpaces |
|
2862 | 2360 |
"return a string containing the characters of myself |
2361 |
without leading and trailing spaces. |
|
2884 | 2362 |
If there are no spaces, the receiver is returned unchanged. |
608 | 2363 |
Notice, this is different from String>>withoutSeparators." |
2364 |
||
2365 |
|startIndex "{ Class: SmallInteger }" |
|
2366 |
endIndex "{ Class: SmallInteger }" |
|
2367 |
sz blank| |
|
2368 |
||
2369 |
startIndex := 0. |
|
2370 |
%{ |
|
2371 |
REGISTER unsigned char *cp; |
|
2884 | 2372 |
REGISTER unsigned char *ep; |
2373 |
unsigned char *cp0; |
|
2374 |
unsigned char *ep0; |
|
608 | 2375 |
|
2376 |
/* ignore instances of subclasses ... */ |
|
2377 |
if (__qClass(self) == String) { |
|
3111 | 2378 |
cp = cp0 = __stringVal(self); |
2862 | 2379 |
|
3111 | 2380 |
/* |
2381 |
* find first non-blank from beginning |
|
2382 |
*/ |
|
2862 | 2383 |
#ifndef NON_ASCII |
2954 | 2384 |
# ifdef UINT64 |
3111 | 2385 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
2386 |
cp += 8; |
|
2387 |
} |
|
2954 | 2388 |
# endif /* UINT64 */ |
3111 | 2389 |
while (*((unsigned *)cp) == 0x20202020) { |
2390 |
cp += 4; |
|
2391 |
} |
|
2862 | 2392 |
#endif |
3111 | 2393 |
while (*cp == ' ') cp++; |
2884 | 2394 |
|
3111 | 2395 |
/* |
2396 |
* find first non-blank from end |
|
2397 |
*/ |
|
2398 |
ep = ep0 = cp0 + __stringSize(self) - 1; |
|
2399 |
while ((ep >= cp) && (*ep == ' ')) ep--; |
|
2862 | 2400 |
|
3111 | 2401 |
/* |
2402 |
* no blanks ? |
|
2403 |
*/ |
|
2404 |
if ((cp == cp0) && (ep == ep0)) { |
|
2405 |
RETURN(self); |
|
2406 |
} |
|
2884 | 2407 |
|
3111 | 2408 |
startIndex = __MKSMALLINT(cp - cp0 + 1); |
2409 |
endIndex = __MKSMALLINT(ep - cp0 + 1); |
|
608 | 2410 |
} |
2411 |
%}. |
|
2412 |
startIndex == 0 ifTrue:[^ super withoutSpaces]. |
|
2413 |
||
2414 |
startIndex > endIndex ifTrue:[^ '']. |
|
2886 | 2415 |
((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self]. |
608 | 2416 |
^ self copyFrom:startIndex to:endIndex |
2884 | 2417 |
|
2418 |
" |
|
2419 |
' hello' withoutSpaces |
|
2420 |
' hello ' withoutSpaces |
|
2421 |
' hello ' withoutSpaces |
|
2422 |
' hello ' withoutSpaces |
|
2423 |
' hello ' withoutSpaces |
|
2424 |
' ' withoutSpaces |
|
2425 |
" |
|
608 | 2426 |
! ! |
2427 |
||
2428 |
!String methodsFor:'printing & storing'! |
|
2429 |
||
2886 | 2430 |
isLiteral |
2431 |
"return true, if the receiver can be used as a literal |
|
608 | 2432 |
(i.e. can be used in constant arrays)" |
2433 |
||
2434 |
^ true |
|
2435 |
! |
|
2436 |
||
2886 | 2437 |
|
2438 |
"print the receiver on standard output. |
|
608 | 2439 |
This method does NOT use the stream classes and will therefore work |
2440 |
even in case of emergency." |
|
2441 |
||
2442 |
%{ /* NOCONTEXT */ |
|
2443 |
||
2444 |
if (__qClass(self) == String) { |
|
1486 | 2445 |
#ifdef WIN32 |
2446 |
printf("%s" , __stringVal(self)); |
|
2447 |
#else |
|
1134 | 2448 |
fputs(__stringVal(self), stdout); fflush(stdout); |
1486 | 2449 |
#endif |
608 | 2450 |
RETURN (self); |
2451 |
} |
|
2452 |
%} |
|
2453 |
. |
|
2454 |
^ super print |
|
2455 |
! |
|
2456 |
||
2886 | 2457 |
printfPrintString:formatString |
608 | 2458 |
"non-portable but sometimes useful. |
2459 |
Return a printed representation of the receiver as specified by formatString, |
|
2460 |
which is defined by printf. |
|
2461 |
No checking on buffer overrun is done; the resulting string may not |
|
2462 |
be larger than 799 characters. |
|
2463 |
This method is NONSTANDARD and may be removed without notice." |
|
2464 |
||
2465 |
%{ /* STACK: 1000 */ |
|
2466 |
||
2467 |
char buffer[800]; |
|
2468 |
char *cp; |
|
2469 |
OBJ s; |
|
2470 |
||
2471 |
if (__isString(formatString)) { |
|
2472 |
/* |
|
2473 |
* actually only needed on sparc: since thisContext is |
|
2474 |
* in a global register, which gets destroyed by printf, |
|
2475 |
* manually save it here - very stupid ... |
|
2476 |
*/ |
|
2477 |
||
1134 | 2478 |
cp = (char *)__stringVal(self); |
608 | 2479 |
if (__qClass(self) != String) |
1134 | 2480 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
608 | 2481 |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
2482 |
__BEGIN_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
2483 |
|
1134 | 2484 |
sprintf(buffer, (char *)__stringVal(formatString), cp); |
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
2485 |
|
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
2486 |
__END_PROTECT_REGISTERS__ |
608 | 2487 |
|
833 | 2488 |
s = __MKSTRING(buffer COMMA_SND); |
608 | 2489 |
if (s != nil) { |
2490 |
RETURN (s); |
|
2491 |
} |
|
2492 |
} |
|
2493 |
%}. |
|
2494 |
self primitiveFailed |
|
2495 |
||
2496 |
" |
|
2497 |
'hello' printfPrintString:'%%s -> %s' |
|
2498 |
'hello' printfPrintString:'%%10s -> %10s' |
|
2499 |
'hello' printfPrintString:'%%-10s -> %-10s' |
|
2500 |
" |
|
2501 |
! |
|
2502 |
||
2886 | 2503 |
storeOn:aStream |
608 | 2504 |
"put the storeString of myself on aStream" |
2505 |
||
2506 |
aStream nextPut: $'. |
|
2507 |
(self includes:$') ifTrue:[ |
|
3579 | 2508 |
self printWithQuotesDoubledOn:aStream |
608 | 2509 |
] ifFalse:[ |
3579 | 2510 |
aStream nextPutAll:self |
608 | 2511 |
]. |
2512 |
aStream nextPut:$' |
|
3579 | 2513 |
|
2514 |
"Modified: / 15.6.1998 / 17:21:51 / cg" |
|
608 | 2515 |
! |
2516 |
||
2886 | 2517 |
storeString |
2518 |
"return a String for storing myself" |
|
608 | 2519 |
|
2520 |
|s n index| |
|
2521 |
||
2522 |
n := self occurrencesOf:$'. |
|
2523 |
n == 0 ifFalse:[ |
|
2524 |
s := String new:(n + 2 + self size). |
|
2525 |
s at:1 put:$'. |
|
2526 |
index := 2. |
|
2527 |
self do:[:thisChar | |
|
2528 |
(thisChar == $') ifTrue:[ |
|
2529 |
s at:index put:thisChar. |
|
2530 |
index := index + 1. |
|
2531 |
]. |
|
2532 |
s at:index put:thisChar. |
|
2533 |
index := index + 1. |
|
2534 |
]. |
|
2535 |
s at:index put:$'. |
|
2536 |
^ s |
|
2537 |
]. |
|
2538 |
^ '''' , self , '''' |
|
1 | 2539 |
! ! |
2540 |
||
2541 |
!String methodsFor:'queries'! |
|
2542 |
||
2886 | 2543 |
bitsPerCharacter |
1239 | 2544 |
"return the number of bits each character has. |
2545 |
Here, 8 is returned (storing single byte characters)." |
|
2546 |
||
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2547 |
^ 8 |
1239 | 2548 |
|
2549 |
"Modified: 20.4.1996 / 23:08:42 / cg" |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2550 |
! |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2551 |
|
2886 | 2552 |
isEmpty |
2553 |
"return true if the receiver is empty (i.e. if size == 0) |
|
68 | 2554 |
Redefined here for performance" |
2555 |
||
2556 |
%{ /* NOCONTEXT */ |
|
2557 |
OBJ cls; |
|
2558 |
||
329 | 2559 |
cls = __qClass(self); |
68 | 2560 |
if ((cls == String) || (cls == Symbol)) { |
3451 | 2561 |
RETURN ( (__stringSize(self) == 0) ? true : false); |
68 | 2562 |
} |
2862 | 2563 |
%}. |
3227
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2564 |
^ self size == 0 |
608 | 2565 |
! |
2566 |
||
2886 | 2567 |
knownAsSymbol |
2568 |
"return true, if there is a symbol with same characters in the |
|
2862 | 2569 |
system. |
2570 |
Can be used to check for existance of a symbol without creating one" |
|
608 | 2571 |
|
2572 |
%{ /* NOCONTEXT */ |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2573 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2574 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2575 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2576 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2577 |
if (cls != String) { |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2578 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2579 |
} else { |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2580 |
indx = 0; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2581 |
} |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2582 |
RETURN ( __KNOWNASSYMBOL(__stringVal(self) + indx) ); |
608 | 2583 |
%} |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2584 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2585 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2586 |
'hello' knownAsSymbol |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2587 |
'fooBarBaz' knownAsSymbol |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2588 |
" |
3227
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2589 |
! |
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2590 |
|
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2591 |
notEmpty |
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2592 |
"return true if the receiver is not empty (i.e. if size ~~ 0) |
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2593 |
Redefined here for performance" |
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2594 |
|
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2595 |
%{ /* NOCONTEXT */ |
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2596 |
OBJ cls; |
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2597 |
|
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2598 |
cls = __qClass(self); |
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2599 |
if ((cls == String) || (cls == Symbol)) { |
3451 | 2600 |
RETURN ( (__stringSize(self) != 0) ? true : false); |
3227
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2601 |
} |
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2602 |
%}. |
b75df9db0435
added tuned version notEmpty
Claus Gittinger <cg@exept.de>
parents:
3153
diff
changeset
|
2603 |
^ self size ~~ 0 |
1 | 2604 |
! ! |
608 | 2605 |
|
2670 | 2606 |
!String methodsFor:'regular expression matching'! |
2607 |
||
2886 | 2608 |
asRegex |
2609 |
"Compile the receiver as a regex matcher. May raise RxParser>>syntaxErrorSignal |
|
2670 | 2610 |
or RxParser>>compilationErrorSignal. |
2611 |
||| This is a part of the Regular Expression Matcher package, (c) Vassili Bykov, 1996. |
|
2612 |
||| Refer to `documentation' protocol of RxParser class for details." |
|
2613 |
||
2614 |
^ Regex::RxParser preferredMatcherClass for: (Regex::RxParser new parse: self) |
|
2615 |
||
2616 |
"Modified: 3.6.1997 / 11:25:25 / cg" |
|
2617 |
! |
|
2618 |
||
2886 | 2619 |
matchesRegex: regexString |
2670 | 2620 |
"Test if the receiver matches a regex. May raise RxParser>>regexErrorSignal or |
2621 |
child signals. |
|
2622 |
||| This is a part of the Regular Expression Matcher package, (c) Vassili Bykov, 1996. |
|
2623 |
||| Refer to `documentation' protocol of RxParser class for details." |
|
2624 |
||
2625 |
^regexString asRegex matches: self |
|
2626 |
||
2627 |
"Modified: 3.6.1997 / 11:25:30 / cg" |
|
2628 |
! |
|
2629 |
||
2886 | 2630 |
prefixMatchesRegex: regexString |
2670 | 2631 |
"Test if the receiver's prefix matches a regex. |
2632 |
May raise RxParser class>>regexErrorSignal or child signals. |
|
2633 |
||| This is a part of the Regular Expression Matcher package, (c) Vassili Bykov, 1996. |
|
2634 |
||| Refer to `documentation' protocol of RxParser class for details." |
|
2635 |
||
2636 |
^regexString asRegex matchesPrefix: self |
|
2637 |
||
2638 |
"Modified: 3.6.1997 / 11:25:34 / cg" |
|
2639 |
! ! |
|
2640 |
||
608 | 2641 |
!String methodsFor:'testing'! |
2642 |
||
2886 | 2643 |
endsWith:aStringOrChar |
2862 | 2644 |
"return true, if the receiver ends with something, aStringOrChar." |
1380 | 2645 |
|
2646 |
%{ /* NOCONTEXT */ |
|
2647 |
||
2648 |
int len1, len2; |
|
2649 |
REGISTER unsigned char *src1, *src2; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
2650 |
unsigned char c; |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2651 |
REGISTER OBJ slf = self; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2652 |
|
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2653 |
if ((__isString(slf) || __isSymbol(slf)) |
2862 | 2654 |
&& (__isString(aStringOrChar) || __isSymbol(aStringOrChar))) { |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2655 |
len1 = __qSize(slf); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2656 |
len2 = __qSize(aStringOrChar); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2657 |
if (len1 < len2) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2658 |
RETURN ( false ); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2659 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2660 |
|
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2661 |
src1 = __stringVal(slf) + (len1 - len2); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2662 |
src2 = __stringVal(aStringOrChar); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2663 |
while (c = *src2++) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2664 |
if (c != *src1++) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2665 |
RETURN ( false ); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2666 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2667 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2668 |
RETURN (true); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2669 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2670 |
if (__isCharacter(aStringOrChar)) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2671 |
int val; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2672 |
|
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2673 |
val = __intVal(_characterVal(aStringOrChar)); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2674 |
if ((unsigned)val <= 255) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2675 |
len1 = __stringSize(slf); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2676 |
if (len1 > 0) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2677 |
RETURN ( (__stringVal(slf)[len1-1] == val) ? true : false); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2678 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2679 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2680 |
RETURN ( false ); |
1380 | 2681 |
} |
2682 |
%}. |
|
2862 | 2683 |
^ super endsWith:aStringOrChar |
1380 | 2684 |
|
2685 |
" |
|
2686 |
'hello world' endsWith:'world' |
|
2687 |
'hello world' endsWith:'earth' |
|
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2688 |
'hello world' endsWith:$d |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2689 |
'hello world' endsWith:$e |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2690 |
'' endsWith:$d |
1380 | 2691 |
'hello world' endsWith:#($r $l $d) |
2692 |
" |
|
2693 |
! |
|
2694 |
||
2886 | 2695 |
isBlank |
2696 |
"return true, if the receivers size is 0 or if it contains only spaces. |
|
608 | 2697 |
Q: should we care for whiteSpace in general here ?" |
2698 |
||
2699 |
%{ /* NOCONTEXT */ |
|
2700 |
||
2701 |
REGISTER unsigned char *src; |
|
2702 |
REGISTER unsigned char c; |
|
2703 |
OBJ cls; |
|
2704 |
||
1134 | 2705 |
src = __stringVal(self); |
608 | 2706 |
if ((cls = __qClass(self)) != String) |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2707 |
src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
608 | 2708 |
|
2709 |
#ifndef NON_ASCII |
|
2954 | 2710 |
# ifdef UINT64 |
2711 |
while (*((UINT64 *)src) == 0x2020202020202020L) { |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2712 |
src += 8; |
2862 | 2713 |
} |
2954 | 2714 |
# endif /* UINT64 */ |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2715 |
|
608 | 2716 |
while (*((unsigned *)src) == 0x20202020) { |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2717 |
src += 4; |
608 | 2718 |
} |
2862 | 2719 |
#endif /* ascii */ |
2720 |
||
2721 |
while (c = *src++) { |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2722 |
if (c != ' ') { |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2723 |
RETURN ( false ); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2724 |
} |
2862 | 2725 |
} |
608 | 2726 |
%}. |
2727 |
^ true |
|
2728 |
! |
|
2729 |
||
2886 | 2730 |
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight |
608 | 2731 |
"parametrized levenshtein. arguments are the costs for |
2732 |
substitution, case-change, insertion and deletion of a character." |
|
2733 |
||
1138
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
2734 |
%{ /* STACK: 2000 */ |
608 | 2735 |
|
2736 |
/* |
|
2737 |
* this is very heavy used when correcting errors |
|
2738 |
* (all symbols are searched for best match) - therefore it must be fast |
|
2739 |
*/ |
|
2740 |
{ |
|
2741 |
unsigned short *data; |
|
2742 |
int l1, l2; |
|
2743 |
REGISTER int sz; |
|
2744 |
unsigned char *s1, *s2; |
|
2745 |
int v1, v2, v3, m; |
|
2746 |
REGISTER unsigned short *dp; |
|
2747 |
REGISTER int delta; |
|
2748 |
REGISTER int j; |
|
2749 |
int i; |
|
2750 |
int iW, cW, sW, dW; |
|
1486 | 2751 |
# define FASTSIZE 30 /* increase STACK if you increase this ... */ |
608 | 2752 |
unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)]; |
2753 |
||
2754 |
if ((__isString(self) || __isSymbol(self)) |
|
2755 |
&& (__isString(aString) || __isSymbol(aString)) |
|
2756 |
&& __bothSmallInteger(insrtWeight, caseWeight) |
|
2757 |
&& __bothSmallInteger(substWeight, deleteWeight)) { |
|
1134 | 2758 |
iW = __intVal(insrtWeight); |
2759 |
cW = __intVal(caseWeight); |
|
2760 |
sW = __intVal(substWeight); |
|
2761 |
dW = __intVal(deleteWeight); |
|
2762 |
s1 = __stringVal(self); |
|
2763 |
s2 = __stringVal(aString); |
|
608 | 2764 |
l1 = strlen(s1); |
2765 |
l2 = strlen(s2); |
|
2766 |
||
2767 |
sz = (l1 < l2) ? l2 : l1; |
|
2768 |
delta = sz + 1; |
|
2769 |
if (sz <= FASTSIZE) { |
|
2770 |
data = fastData; |
|
2771 |
} else { |
|
2772 |
/* add ifdef ALLOCA here ... */ |
|
2773 |
data = (unsigned short *)malloc(delta * delta * sizeof(short)); |
|
2774 |
if (! data) goto mallocFailed; |
|
2775 |
} |
|
2776 |
||
2777 |
data[0] = 0; |
|
2778 |
dp = data+1; |
|
2779 |
for (j=1, dp=data+1; j<=sz; j++, dp++) |
|
2780 |
*dp = *(dp-1) + iW; |
|
2781 |
||
2782 |
for (i=1, dp=data+delta; i<=sz; i++, dp+=delta) |
|
2783 |
*dp = *(dp-delta) + dW; |
|
2784 |
||
2785 |
for (i=1; i<=l1; i++) { |
|
2786 |
for (j=1; j<=l2; j++) { |
|
2787 |
dp = data + (i*delta) + j; |
|
2788 |
if (s1[i] != s2[j]) { |
|
2789 |
if (tolower(s1[i]) == tolower(s2[j])) { |
|
2790 |
m = cW; |
|
2791 |
} else { |
|
2792 |
m = sW; |
|
2793 |
} |
|
2794 |
} else |
|
2795 |
m = 0; |
|
2796 |
||
2797 |
v2 = *(dp - 1) + iW; |
|
2798 |
v3 = *(dp - delta) + dW; |
|
2799 |
v1 = *(dp - delta - 1) + m; |
|
2800 |
if (v1 < v2) |
|
2801 |
if (v1 < v3) |
|
2802 |
m = v1; |
|
2803 |
else |
|
2804 |
m = v3; |
|
2805 |
else |
|
2806 |
if (v2 < v3) |
|
2807 |
m = v2; |
|
2808 |
else |
|
2809 |
m = v3; |
|
2810 |
*dp = m; |
|
2811 |
} |
|
2812 |
} |
|
2813 |
m = data[l1 * delta + l2]; |
|
2814 |
if (sz > FASTSIZE) |
|
2815 |
free(data); |
|
1134 | 2816 |
RETURN ( __MKSMALLINT(m) ); |
608 | 2817 |
} |
2818 |
mallocFailed: ; |
|
2819 |
} |
|
2820 |
%}. |
|
2821 |
||
2822 |
^ super levenshteinTo:aString |
|
2823 |
s:substWeight c:caseWeight |
|
2824 |
i:insrtWeight d:deleteWeight |
|
2825 |
||
2826 |
"'ocmprt' levenshteinTo:'computer' |
|
2827 |
'computer' levenshteinTo:'computer' |
|
2828 |
'ocmputer' levenshteinTo:'computer' |
|
2829 |
'cmputer' levenshteinTo:'computer' |
|
2830 |
'Computer' levenshteinTo:'computer'" |
|
1380 | 2831 |
! |
2832 |
||
2886 | 2833 |
startsWith:aStringOrChar |
2862 | 2834 |
"return true, if the receiver starts with something, aStringOrChar." |
1380 | 2835 |
|
2836 |
%{ /* NOCONTEXT */ |
|
2837 |
||
2838 |
int len1, len2; |
|
2839 |
REGISTER unsigned char *src1, *src2; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
2840 |
unsigned char c; |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2841 |
REGISTER OBJ slf = self; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2842 |
|
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2843 |
if (((__qClass(slf)==String) || (__qClass(slf)==Symbol)) |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
2844 |
&& __isNonNilObject(aStringOrChar) |
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
2845 |
&& ((__qClass(aStringOrChar)==String) || (__qClass(aStringOrChar)==Symbol))) { |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2846 |
src1 = __stringVal(slf); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2847 |
src2 = __stringVal(aStringOrChar); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2848 |
if (src1[0] != src2[0]) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2849 |
RETURN ( false ); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2850 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2851 |
|
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2852 |
len1 = __qSize(slf); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2853 |
len2 = __qSize(aStringOrChar); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2854 |
if (len1 < len2) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2855 |
RETURN ( false ); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2856 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2857 |
|
3546
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
2858 |
# ifdef UINT64 |
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
2859 |
while (len2 > (OHDR_SIZE+sizeof(UINT64))) { |
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
2860 |
if ( *((unsigned UINT64 *)src1) != *((unsigned UINT64 *)src2) ) { |
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
2861 |
RETURN (false); |
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
2862 |
} |
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
2863 |
len2 -= sizeof(UINT64); |
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
2864 |
src1 += sizeof(UINT64); |
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
2865 |
src2 += sizeof(UINT64); |
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
2866 |
} |
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
2867 |
# endif /* UINT64 */ |
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
2868 |
|
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2869 |
while (len2 > (OHDR_SIZE+sizeof(INT))) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2870 |
if ( *((unsigned INT *)src1) != *((unsigned INT *)src2) ) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2871 |
RETURN (false); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2872 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2873 |
len2 -= sizeof(INT); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2874 |
src1 += sizeof(INT); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2875 |
src2 += sizeof(INT); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2876 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2877 |
|
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2878 |
while (c = *src2++) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2879 |
if (c != *src1) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2880 |
RETURN ( false ); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2881 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2882 |
src1++; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2883 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2884 |
RETURN (true); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2885 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2886 |
if (__isCharacter(aStringOrChar)) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2887 |
int val; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2888 |
|
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2889 |
val = __intVal(_characterVal(aStringOrChar)); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2890 |
if ((unsigned)val <= 255) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2891 |
len1 = __stringSize(slf); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2892 |
if (len1 > 0) { |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2893 |
RETURN ( (__stringVal(slf)[0] == val) ? true : false); |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2894 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2895 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2896 |
RETURN ( false ); |
1380 | 2897 |
} |
2898 |
%}. |
|
2862 | 2899 |
^ super startsWith:aStringOrChar |
1380 | 2900 |
|
2901 |
" |
|
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
2902 |
'hello world' startsWith:'hello' |
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
2903 |
'hello world' startsWith:'hella' |
1380 | 2904 |
'hello world' startsWith:'hi' |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2905 |
'hello world' startsWith:$h |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2906 |
'hello world' startsWith:$H |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2907 |
'hello world' startsWith:(Character value:16rFF00) |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
2908 |
'hello world' startsWith:60 |
1380 | 2909 |
'hello world' startsWith:#($h $e $l) |
2910 |
" |
|
608 | 2911 |
! ! |
2912 |
||
633 | 2913 |
!String class methodsFor:'documentation'! |
2914 |
||
2886 | 2915 |
version |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
2916 |
^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.127 1998-08-05 14:53:13 cg Exp $' |
633 | 2917 |
! ! |