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