author | penk |
Mon, 04 Nov 2002 18:41:59 +0100 | |
changeset 6828 | f1725ea64ff1 |
parent 6766 | a43b97582d4b |
child 6830 | 97b046007438 |
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 |
" |
|
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
237 |
(anInteger < 0) ifTrue:[ |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
238 |
" |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
239 |
the argument is negative, |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
240 |
" |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
241 |
self error:'bad (negative) argument to new:'. |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
242 |
^ nil |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
243 |
]. |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
244 |
|
5407 | 245 |
^ (super basicNew:anInteger+1) atAllPut:(Character space) |
1 | 246 |
! |
247 |
||
608 | 248 |
new:n |
4802 | 249 |
"return a new empty string with anInteger characters. |
250 |
In contrast to other smalltalks, this returns a string filled |
|
251 |
with spaces (instead of a string filled with 0-bytes). |
|
252 |
This makes much more sense, in that a freshly created string |
|
253 |
can be directly used as separator or for formatting." |
|
254 |
||
608 | 255 |
^ self basicNew:n |
347 | 256 |
! |
257 |
||
6599
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
258 |
readFrom:aStreamOrString onError:exceptionBlock |
347 | 259 |
"read & return the next String from the (character-)stream aStream; |
260 |
skipping all whitespace first; return the value of exceptionBlock, |
|
261 |
if no string can be read. The sequence of characters as read from the |
|
262 |
stream must be one as stored via storeOn: or storeString." |
|
263 |
||
6599
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
264 |
|str collected char| |
347 | 265 |
|
266 |
" |
|
267 |
this method is not to be inherited |
|
268 |
(i.e. not ok for subclasses; Symbol, for example) |
|
269 |
" |
|
270 |
self ~~ String ifTrue:[ |
|
6599
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
271 |
^ super readFrom:aStreamOrString onError:exceptionBlock |
347 | 272 |
]. |
273 |
||
6599
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
274 |
str := aStreamOrString readStream. |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
275 |
|
347 | 276 |
"skip whiteSpace" |
6599
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
277 |
str skipSeparators. |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
278 |
(str next == $') ifTrue:[ |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
279 |
collected := WriteStream on:(String new). |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
280 |
[true] whileTrue:[ |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
281 |
str atEnd ifTrue:[ |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
282 |
"/ mhmh - reached the end without a closing quote |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
283 |
"/ looks like an error to me ... |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
284 |
^ exceptionBlock value |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
285 |
]. |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
286 |
char := str next. |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
287 |
char == $' ifTrue:[ |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
288 |
"/ look for another quote |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
289 |
str peekOrNil == $' ifFalse:[ |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
290 |
^ collected contents |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
291 |
]. |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
292 |
str next. |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
293 |
]. |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
294 |
collected nextPut:char |
f4b35853b094
consiostency in #readFrom: - allow string argument
Claus Gittinger <cg@exept.de>
parents:
6588
diff
changeset
|
295 |
] |
347 | 296 |
]. |
297 |
^ exceptionBlock value |
|
298 |
||
299 |
" |
|
300 |
String readFrom:('''hello world''' readStream) |
|
301 |
String readFrom:('''hello '''' world''' readStream) |
|
302 |
String readFrom:('1 ''hello'' ' readStream) |
|
303 |
String readFrom:('1 ''hello'' ' readStream) onError:['foobar'] |
|
3376 | 304 |
" |
305 |
||
306 |
"Modified: / 14.4.1998 / 18:46:26 / cg" |
|
608 | 307 |
! |
308 |
||
309 |
unititializedNew:anInteger |
|
310 |
"redefine it back - strings must have a 0-byte at the end" |
|
311 |
||
312 |
^ self basicNew:anInteger |
|
313 |
! ! |
|
314 |
||
4981 | 315 |
!String class methodsFor:'Compatibility - Squeak'! |
316 |
||
317 |
cr |
|
4994 | 318 |
"return a string consisting of the cr-Character" |
4993 | 319 |
|
4981 | 320 |
^ Character cr asString |
4993 | 321 |
|
4994 | 322 |
"Modified: / 13.11.1999 / 13:53:36 / cg" |
4981 | 323 |
! ! |
324 |
||
608 | 325 |
!String class methodsFor:'binary storage'! |
326 |
||
327 |
binaryDefinitionFrom:stream manager:manager |
|
3085 | 328 |
"read a binary representation from stream. This is only invoked |
329 |
for long strings. Short strings are stored with 1byte length." |
|
330 |
||
331 |
|s len| |
|
608 | 332 |
|
3085 | 333 |
"take care of subclasses ..." |
334 |
((self == String) or:[self == Symbol]) ifTrue:[ |
|
3111 | 335 |
len := stream nextNumber:4. |
336 |
s := String basicNew:len. |
|
337 |
stream nextBytes:len into:s startingAt:1. |
|
338 |
^ s |
|
3085 | 339 |
]. |
340 |
^ super binaryDefinitionFrom:stream manager:manager |
|
341 |
||
342 |
"Modified: / 2.11.1997 / 16:18:37 / cg" |
|
608 | 343 |
! ! |
344 |
||
345 |
!String class methodsFor:'queries'! |
|
346 |
||
2680
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
347 |
defaultPlatformClass |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
348 |
"dummy for ST-80 compatibility" |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
349 |
|
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
350 |
^ self |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
351 |
|
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
352 |
"Created: 6.6.1997 / 18:25:56 / cg" |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
353 |
! |
18c85df5d930
#defaultPlatformClass for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2670
diff
changeset
|
354 |
|
608 | 355 |
isBuiltInClass |
1264 | 356 |
"return true if this class is known by the run-time-system. |
357 |
Here, true is returned for myself, false for subclasses." |
|
608 | 358 |
|
359 |
^ self == String |
|
1264 | 360 |
|
361 |
"Modified: 23.4.1996 / 16:00:38 / cg" |
|
1 | 362 |
! ! |
363 |
||
364 |
!String methodsFor:'accessing'! |
|
365 |
||
329 | 366 |
at:index |
367 |
"return the character at position index, an Integer. |
|
345 | 368 |
Reimplemented here to avoid the additional at:->basicAt: send |
369 |
(which we can do here, since at: is obviously not redefined in a subclass). |
|
329 | 370 |
This method is the same as at:." |
371 |
||
372 |
%{ /* NOCONTEXT */ |
|
373 |
||
374 |
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
|
375 |
REGISTER OBJ slf, cls; |
329 | 376 |
|
377 |
if (__isSmallInteger(index)) { |
|
5407 | 378 |
slf = self; |
379 |
cls = __qClass(slf); |
|
380 |
indx = __intVal(index) - 1; |
|
381 |
if (cls != String) { |
|
382 |
if (indx < 0) goto badIndex; |
|
383 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
384 |
} |
|
385 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
386 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
|
387 |
} |
|
329 | 388 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
389 |
badIndex: ; |
329 | 390 |
%}. |
5407 | 391 |
^ self basicAt:index |
1 | 392 |
! |
393 |
||
329 | 394 |
at:index put:aCharacter |
395 |
"store the argument, aCharacter at position index, an Integer. |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
396 |
Return aCharacter (sigh). |
345 | 397 |
Reimplemented here to avoid the additional at:put:->basicAt:put: send |
398 |
(but only for Strings, since subclasses may redefine basicAt:put:). |
|
329 | 399 |
This method is the same as basicAt:put:." |
400 |
||
401 |
%{ /* NOCONTEXT */ |
|
402 |
||
403 |
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
|
404 |
REGISTER OBJ slf; |
329 | 405 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
406 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
407 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
408 |
if (__isString(slf)) { |
5407 | 409 |
if (__isCharacter(aCharacter)) { |
410 |
value = __intVal(_characterVal(aCharacter)); |
|
411 |
if (((unsigned)value <= 0xFF) |
|
412 |
&& __isSmallInteger(index)) { |
|
413 |
indx = __intVal(index) - 1; |
|
414 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
415 |
__stringVal(slf)[indx] = value; |
|
416 |
RETURN ( aCharacter ); |
|
417 |
} |
|
418 |
} |
|
419 |
} |
|
329 | 420 |
} |
421 |
%}. |
|
5407 | 422 |
^ self basicAt:index put:aCharacter |
329 | 423 |
! |
424 |
||
608 | 425 |
basicAt:index |
426 |
"return the character at position index, an Integer |
|
427 |
- reimplemented here since we return characters" |
|
428 |
||
429 |
%{ /* NOCONTEXT */ |
|
430 |
||
431 |
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
|
432 |
REGISTER OBJ slf, cls; |
608 | 433 |
|
434 |
if (__isSmallInteger(index)) { |
|
5407 | 435 |
slf = self; |
436 |
cls = __qClass(slf); |
|
437 |
indx = __intVal(index) - 1; |
|
438 |
if (cls != String) { |
|
439 |
if (indx < 0) goto badIndex; |
|
440 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
441 |
} |
|
442 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
443 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
|
444 |
} |
|
608 | 445 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
446 |
badIndex: ; |
608 | 447 |
%}. |
3451 | 448 |
index isInteger ifFalse:[ |
5407 | 449 |
^ self indexNotInteger:index |
3451 | 450 |
]. |
5407 | 451 |
index == super basicSize ifTrue:[ |
452 |
^ self subscriptBoundsError:index |
|
453 |
]. |
|
454 |
^ Character value:(super basicAt:index) |
|
608 | 455 |
! |
456 |
||
1 | 457 |
basicAt:index put:aCharacter |
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
458 |
"store the argument, aCharacter at position index, an Integer. |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
459 |
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
|
460 |
- reimplemented here since we store characters" |
1 | 461 |
|
462 |
%{ /* NOCONTEXT */ |
|
463 |
||
464 |
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
|
465 |
REGISTER OBJ slf; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
466 |
REGISTER OBJ cls; |
1 | 467 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
468 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
469 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
470 |
if (__isCharacter(aCharacter)) { |
5407 | 471 |
value = __intVal(_characterVal(aCharacter)); |
472 |
if (((unsigned)value <= 0xFF) |
|
473 |
&& __isSmallInteger(index)) { |
|
474 |
cls = __qClass(slf); |
|
475 |
indx = __intVal(index) - 1; |
|
476 |
if (cls != String) { |
|
477 |
if (indx < 0) goto badIndex; |
|
478 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
479 |
} |
|
480 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
481 |
__stringVal(slf)[indx] = value; |
|
482 |
RETURN ( aCharacter ); |
|
483 |
} |
|
484 |
} |
|
1 | 485 |
} |
4388
b4ca5cf130c7
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4247
diff
changeset
|
486 |
badIndex: ; |
159 | 487 |
%}. |
1 | 488 |
(aCharacter isMemberOf:Character) ifFalse:[ |
5407 | 489 |
" |
490 |
tried to store something which is not a character |
|
491 |
" |
|
492 |
^ self elementNotCharacter |
|
299 | 493 |
]. |
494 |
(aCharacter asciiValue between:1 and:255) ifFalse:[ |
|
5407 | 495 |
" |
496 |
tried to store a multibyte character |
|
497 |
" |
|
498 |
^ self elementBoundsError |
|
299 | 499 |
]. |
500 |
" |
|
501 |
invalid index |
|
502 |
" |
|
3451 | 503 |
index isInteger ifFalse:[ |
5407 | 504 |
^ self indexNotInteger:index |
3451 | 505 |
]. |
5407 | 506 |
index == super basicSize ifTrue:[ |
507 |
^ self subscriptBoundsError:index |
|
508 |
]. |
|
509 |
super basicAt:index put:aCharacter asciiValue. |
|
510 |
^ aCharacter |
|
511 |
||
2 | 512 |
! ! |
513 |
||
3085 | 514 |
!String methodsFor:'binary storage'! |
515 |
||
516 |
storeBinaryDefinitionOn:stream manager:manager |
|
517 |
"append a binary representation of the receiver onto stream. |
|
518 |
Redefined since short Strings can be stored with a special type code |
|
519 |
in a more compact way. |
|
520 |
This is an internal interface for the binary storage mechanism." |
|
521 |
||
522 |
|myClass myBasicSize| |
|
523 |
||
524 |
"/ not for subclasses with named instVars. |
|
525 |
(myClass := self class) instSize ~~ 0 ifTrue:[ |
|
3111 | 526 |
^ super storeBinaryDefinitionOn:stream manager:manager |
3085 | 527 |
]. |
528 |
||
529 |
myBasicSize := self basicSize. |
|
530 |
||
531 |
"/ can use a more compact representation; |
|
532 |
"/ but not for subclasses ... |
|
533 |
||
534 |
((myClass == String) |
|
535 |
and:[myBasicSize <= 255]) ifTrue:[ |
|
3111 | 536 |
"/ special encoding: <codeForString> <len> <bytes> ... |
537 |
stream nextPut:(manager codeForString); nextPut:myBasicSize. |
|
3085 | 538 |
] ifFalse:[ |
3111 | 539 |
manager putIdOfClass:myClass on:stream. |
540 |
stream nextNumber:4 put:myBasicSize. |
|
3085 | 541 |
]. |
542 |
stream nextPutBytes:myBasicSize from:self startingAt:1. |
|
543 |
||
544 |
"Modified: / 2.11.1997 / 15:28:56 / cg" |
|
545 |
! ! |
|
546 |
||
53 | 547 |
!String methodsFor:'character searching'! |
1 | 548 |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
549 |
identityIndexOf:aCharacter |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
550 |
"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
|
551 |
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
|
552 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
553 |
%{ /* NOCONTEXT */ |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
554 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
555 |
REGISTER unsigned char *cp; |
6370 | 556 |
#ifndef FAST_MEMCHR |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
557 |
REGISTER unsigned byteValue; |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
558 |
REGISTER int index; |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
559 |
REGISTER int last; |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
560 |
#endif |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
561 |
OBJ cls; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
562 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
563 |
if (__isCharacter(aCharacter)) { |
5407 | 564 |
cp = __stringVal(self); |
565 |
if ((cls = __qClass(self)) != String) |
|
566 |
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
|
567 |
#ifdef FAST_MEMCHR |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
568 |
cp = (unsigned char *) memchr(cp, __intVal(__characterVal(aCharacter)), __stringSize(self)); |
5407 | 569 |
if (cp) { |
570 |
RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) ); |
|
571 |
} |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
572 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
573 |
byteValue = __intVal(__characterVal(aCharacter)); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
574 |
last = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
575 |
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
|
576 |
if (*cp++ == byteValue) { RETURN ( __MKSMALLINT(index) ); } |
5407 | 577 |
} |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
578 |
#endif |
5407 | 579 |
RETURN ( __MKSMALLINT(0)); |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
580 |
} |
5407 | 581 |
/* with identity compares, only characters can be in myself */ |
582 |
RETURN ( __MKSMALLINT(0)); |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
583 |
%}. |
5407 | 584 |
^ self primitiveFailed |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
585 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
586 |
" |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
587 |
'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
|
588 |
'hello world' identityIndexOf:$d |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
589 |
'hello world' identityIndexOf:1 |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
590 |
#[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
|
591 |
#[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
|
592 |
" |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
593 |
! |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
594 |
|
1 | 595 |
includes:aCharacter |
596 |
"return true if the argument, aCharacter is included in the receiver |
|
597 |
- reimplemented here for speed" |
|
598 |
||
599 |
%{ /* NOCONTEXT */ |
|
600 |
||
601 |
REGISTER unsigned char *cp; |
|
602 |
REGISTER int byteValue; |
|
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
603 |
#ifndef FAST_MEMCHR |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
604 |
REGISTER unsigned char *last; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
605 |
#endif |
53 | 606 |
OBJ cls; |
1 | 607 |
|
53 | 608 |
if (__isCharacter(aCharacter)) { |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
609 |
byteValue = __intVal(__characterVal(aCharacter)); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
610 |
cp = __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
611 |
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
|
612 |
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
|
613 |
#ifdef FAST_MEMCHR |
6368 | 614 |
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
|
615 |
RETURN ( true ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
616 |
} |
1 | 617 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
618 |
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
|
619 |
if (*cp == byteValue) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
620 |
RETURN ( true ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
621 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
622 |
} |
1 | 623 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
624 |
RETURN (false); |
1 | 625 |
} |
299 | 626 |
%}. |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
627 |
^ super includes:aCharacter |
53 | 628 |
|
95 | 629 |
" |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
630 |
'hello world' includes:$d |
95 | 631 |
'hello world' includes:$o |
632 |
'hello world' includes:$x |
|
633 |
'hello world' includes:1 |
|
299 | 634 |
'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
|
635 |
#[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
|
636 |
#[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
|
637 |
#[1 2 3 4 5] asString includes:(Character value:0) |
95 | 638 |
" |
1 | 639 |
! |
640 |
||
10 | 641 |
includesAny:aCollection |
642 |
"return true, if the receiver includes any of the characters in the |
|
53 | 643 |
argument, aCollection. |
644 |
- redefined for speed if the argument is a String." |
|
10 | 645 |
|
646 |
%{ /* NOCONTEXT */ |
|
647 |
||
648 |
REGISTER unsigned char *cp; |
|
649 |
REGISTER unsigned char *matchP; |
|
53 | 650 |
OBJ cls; |
10 | 651 |
|
53 | 652 |
if (__isString(aCollection)) { |
5407 | 653 |
matchP = __stringVal(aCollection); |
654 |
cp = __stringVal(self); |
|
655 |
if ((cls = __qClass(self)) != String) |
|
656 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
657 |
||
658 |
while (*cp) { |
|
659 |
if (strchr(matchP, *cp)) { |
|
660 |
RETURN ( true ); |
|
661 |
} |
|
662 |
cp++; |
|
663 |
} |
|
664 |
RETURN ( false ); |
|
10 | 665 |
} |
5407 | 666 |
%}. |
10 | 667 |
^ super includesAny:aCollection |
95 | 668 |
|
669 |
" |
|
670 |
'hello world' includesAny:'abcd' |
|
671 |
'hello world' includesAny:'xyz' |
|
672 |
'hello world' includesAny:(Array with:$a with:$b with:$d) |
|
673 |
'hello world' includesAny:(Array with:$x with:$y) |
|
674 |
'hello world' includesAny:(Array with:1 with:2) |
|
675 |
" |
|
10 | 676 |
! |
677 |
||
1 | 678 |
indexOf:aCharacter |
679 |
"return the index of the first occurrences of the argument, aCharacter |
|
680 |
in the receiver or 0 if not found - reimplemented here for speed." |
|
681 |
||
682 |
%{ /* NOCONTEXT */ |
|
683 |
||
684 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
685 |
REGISTER unsigned byteValue; |
2530 | 686 |
REGISTER int index; |
6370 | 687 |
#ifndef FAST_MEMCHR |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
688 |
REGISTER int last; |
1 | 689 |
#endif |
53 | 690 |
OBJ cls; |
1 | 691 |
|
53 | 692 |
if (__isCharacter(aCharacter)) { |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
693 |
cp = __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
694 |
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
|
695 |
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
|
696 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
697 |
byteValue = __intVal(__characterVal(aCharacter)); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
698 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
699 |
#ifdef FAST_MEMCHR |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
700 |
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
|
701 |
if (cp) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
702 |
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
|
703 |
} |
1 | 704 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
705 |
last = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
706 |
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
|
707 |
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
|
708 |
} |
1 | 709 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
710 |
RETURN ( __MKSMALLINT(0)); |
1 | 711 |
} |
370 | 712 |
%}. |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
713 |
^ super indexOf:aCharacter |
95 | 714 |
|
715 |
" |
|
716 |
'hello world' indexOf:(Character space) |
|
717 |
'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
|
718 |
'hello world' indexOf:$d |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
719 |
#[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
|
720 |
#[0 0 1 0 0] asString indexOf:(Character value:0) |
95 | 721 |
" |
1 | 722 |
! |
723 |
||
724 |
indexOf:aCharacter startingAt:start |
|
725 |
"return the index of the first occurrence of the argument, aCharacter |
|
726 |
in myself starting at start, anInteger or 0 if not found; |
|
727 |
- reimplemented here for speed" |
|
728 |
||
729 |
%{ /* NOCONTEXT */ |
|
730 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
731 |
REGISTER int index; |
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
732 |
REGISTER unsigned byteValue; |
1 | 733 |
int len; |
53 | 734 |
OBJ cls; |
1 | 735 |
|
252 | 736 |
if (__isSmallInteger(start)) { |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
737 |
if (__isCharacter(aCharacter)) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
738 |
byteValue = __intVal(_characterVal(aCharacter)); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
739 |
index = __intVal(start); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
740 |
if (index <= 0) |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
741 |
index = 1; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
742 |
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
|
743 |
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
|
744 |
len = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
745 |
if (index <= len) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
746 |
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
|
747 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
748 |
#ifdef FAST_MEMCHR |
6332
5b006cfad9ca
Fix bug in #indexOf:startingAt if defined(FAST_MEMCHR)
Stefan Vogel <sv@exept.de>
parents:
6331
diff
changeset
|
749 |
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
|
750 |
if (cp) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
751 |
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
|
752 |
} |
1 | 753 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
754 |
for (; index <= len; index++) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
755 |
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
|
756 |
} |
1 | 757 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
758 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
759 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
760 |
RETURN ( __MKSMALLINT(0) ); |
1 | 761 |
} |
370 | 762 |
%}. |
1 | 763 |
^ super indexOf:aCharacter startingAt:start |
53 | 764 |
|
95 | 765 |
" |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
766 |
'hello world' indexOf:$0 startingAt:1 |
95 | 767 |
'hello world' indexOf:$l startingAt:1 |
768 |
'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
|
769 |
'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
|
770 |
#[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
|
771 |
#[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3 |
95 | 772 |
" |
1 | 773 |
! |
774 |
||
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
775 |
indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
776 |
"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
|
777 |
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
|
778 |
- 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
|
779 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
780 |
%{ /* NOCONTEXT */ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
781 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
782 |
REGISTER unsigned char *ccp; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
783 |
REGISTER unsigned char *cp; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
784 |
REGISTER int index; |
2894 | 785 |
unsigned char *matchP; |
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
786 |
unsigned char c; |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
787 |
int len; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
788 |
OBJ cls; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
789 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
790 |
if (__isSmallInteger(start) |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
791 |
&& __isString(aCollectionOfCharacters)) { |
3111 | 792 |
matchP = __stringVal(aCollectionOfCharacters); |
793 |
index = __intVal(start); |
|
794 |
if (index <= 0) |
|
795 |
index = 1; |
|
796 |
if ((cls = __qClass(self)) != String) |
|
797 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
798 |
len = __stringSize(self); |
|
799 |
if (index <= len) { |
|
800 |
cp = __stringVal(self) + index - 1; |
|
801 |
while (c = *cp++) { |
|
802 |
for (ccp = matchP; *ccp ; ccp++) { |
|
803 |
if (*ccp == c) { |
|
804 |
RETURN ( __MKSMALLINT(index) ); |
|
805 |
} |
|
806 |
} |
|
807 |
index++; |
|
808 |
} |
|
809 |
} |
|
810 |
RETURN ( __MKSMALLINT(0) ); |
|
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
811 |
} |
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 |
"/ 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
|
815 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
816 |
^ super indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
817 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
818 |
" |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
819 |
'hello world' indexOfAny:'eoa' startingAt:1 |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
820 |
'hello world' indexOfAny:'eoa' startingAt:6 |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
821 |
'hello world' indexOfAny:'AOE' startingAt:1 |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
822 |
" |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
823 |
! |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
824 |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
825 |
indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
826 |
"return the index of the next control character; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
827 |
that is a character with asciiValue < 32. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
828 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
829 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
830 |
%{ /* NOCONTEXT */ |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
831 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
832 |
#ifndef NON_ASCII /* i.e. not EBCDIC ;-) */ |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
833 |
REGISTER unsigned char *cp; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
834 |
REGISTER unsigned char c; |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
835 |
REGISTER unsigned char *cpEnd; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
836 |
int len, index; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
837 |
OBJ cls; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
838 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
839 |
index = __intVal(start); |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
840 |
if (index <= 0) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
841 |
index = 1; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
842 |
} |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
843 |
if ((cls = __qClass(self)) != String) |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
844 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
845 |
len = __stringSize(self); |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
846 |
cpEnd = __stringVal(self) + len; |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
847 |
cp = __stringVal(self) + index - 1; |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
848 |
if (cp < cpEnd) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
849 |
while (cp < cpEnd) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
850 |
if (*cp++ < ' ') { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
851 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
852 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
853 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
854 |
RETURN ( __MKSMALLINT(0) ); |
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 |
#endif |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
857 |
%}. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
858 |
^ super indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
859 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
860 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
861 |
'hello world' indexOfControlCharacterStartingAt:1 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
862 |
'hello world\foo' withCRs indexOfControlCharacterStartingAt:1 |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
863 |
'1\' withCRs indexOfControlCharacterStartingAt:1 |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
864 |
'1\' withCRs indexOfControlCharacterStartingAt:2 |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
865 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
866 |
! |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
867 |
|
3403 | 868 |
indexOfNonSeparatorStartingAt:start |
869 |
"return the index of the next non-whiteSpace character" |
|
870 |
||
871 |
%{ /* NOCONTEXT */ |
|
872 |
||
873 |
REGISTER unsigned char *cp; |
|
874 |
REGISTER unsigned char c; |
|
875 |
int len, index; |
|
876 |
OBJ cls; |
|
877 |
||
878 |
index = __intVal(start); |
|
879 |
if (index <= 0) { |
|
5407 | 880 |
index = 1; |
3403 | 881 |
} |
882 |
if ((cls = __qClass(self)) != String) |
|
5407 | 883 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3403 | 884 |
len = __stringSize(self); |
885 |
if (index > len) { |
|
5407 | 886 |
RETURN ( __MKSMALLINT(0) ); |
3403 | 887 |
} |
888 |
cp = __stringVal(self) + index - 1; |
|
889 |
while (c = *cp++) { |
|
890 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
|
5407 | 891 |
if (c > ' ') |
3403 | 892 |
#endif |
5407 | 893 |
if ((c != ' ') && (c != '\t') && (c != '\n') |
894 |
&& (c != '\r') && (c != '\f')) { |
|
895 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
|
896 |
} |
|
3403 | 897 |
} |
5407 | 898 |
RETURN ( __MKSMALLINT(0) ); |
3403 | 899 |
%}. |
5407 | 900 |
^ super indexOfNonSeparatorStartingAt:start |
3403 | 901 |
|
902 |
" |
|
903 |
'hello world' indexOfNonWhiteSpaceStartingAt:3 |
|
904 |
'hello world' indexOfNonWhiteSpaceStartingAt:7 |
|
905 |
" |
|
906 |
! |
|
907 |
||
1 | 908 |
indexOfSeparatorStartingAt:start |
909 |
"return the index of the next separator character" |
|
910 |
||
911 |
%{ /* NOCONTEXT */ |
|
912 |
||
913 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
914 |
REGISTER unsigned char c; |
1 | 915 |
int len, index; |
53 | 916 |
OBJ cls; |
1 | 917 |
|
1134 | 918 |
index = __intVal(start); |
1 | 919 |
if (index <= 0) { |
5407 | 920 |
index = 1; |
1 | 921 |
} |
329 | 922 |
if ((cls = __qClass(self)) != String) |
5407 | 923 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1134 | 924 |
len = __stringSize(self); |
1 | 925 |
if (index > len) { |
5407 | 926 |
RETURN ( __MKSMALLINT(0) ); |
1 | 927 |
} |
1134 | 928 |
cp = __stringVal(self) + index - 1; |
1 | 929 |
while (c = *cp++) { |
329 | 930 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
5407 | 931 |
if (c <= ' ') |
1 | 932 |
#endif |
5407 | 933 |
if ((c == ' ') || (c == '\t') || (c == '\n') |
934 |
|| (c == '\r') || (c == '\f')) { |
|
935 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
|
936 |
} |
|
1 | 937 |
} |
5407 | 938 |
RETURN ( __MKSMALLINT(0) ); |
939 |
%}. |
|
940 |
^ super indexOfSeparatorStartingAt:start |
|
53 | 941 |
|
95 | 942 |
" |
943 |
'hello world' indexOfSeparatorStartingAt:3 |
|
944 |
'hello world' indexOfSeparatorStartingAt:7 |
|
945 |
" |
|
608 | 946 |
! |
947 |
||
948 |
occurrencesOf:aCharacter |
|
949 |
"count the occurrences of the argument, aCharacter in myself |
|
950 |
- reimplemented here for speed" |
|
951 |
||
952 |
%{ /* NOCONTEXT */ |
|
953 |
||
954 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
955 |
REGISTER unsigned byteValue; |
6828
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
956 |
REGISTER int count, limit; |
608 | 957 |
OBJ cls; |
958 |
||
959 |
if (__isCharacter(aCharacter)) { |
|
6828
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
960 |
limit = __stringSize(self); |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
961 |
count = 0; |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
962 |
byteValue = __intVal(_characterVal(aCharacter)); |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
963 |
cp = __stringVal(self); |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
964 |
if ((cls = __qClass(self)) != String) { |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
965 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
966 |
limit -= n; |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
967 |
cp += n; |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
968 |
} |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
969 |
while (limit > 0) { |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
970 |
limit--; |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
971 |
if (*cp++ == byteValue) count++; |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
972 |
} |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
973 |
RETURN ( __MKSMALLINT(count) ); |
608 | 974 |
} |
975 |
%}. |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
976 |
^ super occurrencesOf:aCharacter |
608 | 977 |
|
978 |
" |
|
979 |
'hello world' occurrencesOf:$a |
|
980 |
'hello world' occurrencesOf:$w |
|
981 |
'hello world' occurrencesOf:$l |
|
982 |
'hello world' occurrencesOf:$x |
|
983 |
'hello world' occurrencesOf:1 |
|
984 |
" |
|
53 | 985 |
! ! |
986 |
||
608 | 987 |
!String methodsFor:'comparing'! |
2 | 988 |
|
608 | 989 |
= aString |
990 |
"Compare the receiver with the argument and return true if the |
|
991 |
receiver is equal to the argument. Otherwise return false. |
|
992 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
|
993 |
Use sameAs: to compare with case ignored." |
|
1 | 994 |
|
375 | 995 |
%{ /* NOCONTEXT */ |
996 |
||
608 | 997 |
int l1, l2; |
998 |
REGISTER OBJ s = aString; |
|
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
999 |
unsigned char *cp1, *cp2; |
608 | 1000 |
OBJ cls; |
3111 | 1001 |
OBJ myCls; |
3335 | 1002 |
INT addrDelta; |
608 | 1003 |
|
1004 |
if (s == self) { |
|
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1005 |
RETURN ( true ); |
608 | 1006 |
} |
1007 |
if (! __isNonNilObject(s)) { |
|
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1008 |
RETURN ( false ); |
608 | 1009 |
} |
1 | 1010 |
|
3111 | 1011 |
cls = __qClass(s); |
1012 |
myCls = __qClass(self); |
|
608 | 1013 |
|
3111 | 1014 |
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
|
1015 |
cp2 = __stringVal(s); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1016 |
l2 = __stringSize(s); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1017 |
/* |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1018 |
* 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
|
1019 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1020 |
if (cls != String) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1021 |
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
|
1022 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1023 |
cp2 += n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1024 |
l2 -= n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1025 |
} |
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 |
cp1 = __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1028 |
l1 = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1029 |
/* |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1030 |
* 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
|
1031 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1032 |
if (myCls != String) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1033 |
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
|
1034 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1035 |
cp1 += n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1036 |
l1 -= n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1037 |
} |
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 (l1 != l2) { |
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 |
#ifdef FAST_MEMCMP |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1043 |
RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false ); |
3111 | 1044 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1045 |
addrDelta = cp2 - cp1; |
3989 | 1046 |
# ifdef UNROLL_LOOPS |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1047 |
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
|
1048 |
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
|
1049 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1050 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1051 |
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
|
1052 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1053 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1054 |
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
|
1055 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1056 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1057 |
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
|
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 INT) * 4); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1061 |
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
|
1062 |
} |
3989 | 1063 |
# endif /* UNROLL_LOOPS */ |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1064 |
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
|
1065 |
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
|
1066 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1067 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1068 |
l1 -= sizeof(unsigned INT); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1069 |
cp1 += sizeof(unsigned INT); |
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 |
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
|
1072 |
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
|
1073 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1074 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1075 |
l1 -= sizeof(unsigned short); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1076 |
cp1 += sizeof(unsigned short); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1077 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1078 |
while (l1) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1079 |
if (*cp1 != *(cp1+addrDelta)) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1080 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1081 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1082 |
l1--; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1083 |
cp1++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1084 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1085 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1086 |
RETURN (true); |
3111 | 1087 |
#endif |
1 | 1088 |
} |
3111 | 1089 |
%}. |
608 | 1090 |
^ super = aString |
1 | 1091 |
|
95 | 1092 |
" |
608 | 1093 |
'foo' = 'Foo' |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1094 |
'foo' sameAs: 'Foo' |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1095 |
#[0 0 1 0 0] asString = #[0 0 1 0 0] asString |
95 | 1096 |
" |
1 | 1097 |
! |
1098 |
||
608 | 1099 |
> aString |
1100 |
"Compare the receiver with the argument and return true if the |
|
1101 |
receiver is greater than the argument. Otherwise return false. |
|
1102 |
No national variants are honored; use after: for this. |
|
1103 |
In contrast to ST-80, case differences are NOT ignored, thus |
|
1104 |
'foo' > 'Foo' will return true. |
|
1105 |
This may change." |
|
1 | 1106 |
|
375 | 1107 |
%{ /* NOCONTEXT */ |
1108 |
||
608 | 1109 |
int len1, len2, cmp; |
1110 |
REGISTER OBJ s = aString; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1111 |
unsigned char *cp1, *cp2; |
608 | 1112 |
OBJ cls; |
3111 | 1113 |
OBJ myCls; |
1 | 1114 |
|
3111 | 1115 |
if (__isNonNilObject(s)) { |
1116 |
cls = __qClass(s); |
|
1117 |
myCls = __qClass(self); |
|
608 | 1118 |
|
3111 | 1119 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
1120 |
cp2 = __stringVal(s); |
|
1121 |
len2 = __stringSize(s); |
|
1122 |
/* |
|
1123 |
* care for instances of subclasses ... |
|
1124 |
*/ |
|
1125 |
if (cls != String) { |
|
1126 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
608 | 1127 |
|
3111 | 1128 |
cp2 += n; |
1129 |
len2 -= n; |
|
1130 |
} |
|
375 | 1131 |
|
3111 | 1132 |
cp1 = __stringVal(self); |
1133 |
len1 = __stringSize(self); |
|
1134 |
/* |
|
1135 |
* care for instances of subclasses ... |
|
1136 |
*/ |
|
1137 |
if (myCls != String) { |
|
1138 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
|
608 | 1139 |
|
3111 | 1140 |
cp1 += n; |
1141 |
len1 -= n; |
|
1142 |
} |
|
608 | 1143 |
|
3111 | 1144 |
if (len1 <= len2) |
1145 |
cmp = strncmp(cp1, cp2, len1); |
|
1146 |
else |
|
1147 |
cmp = strncmp(cp1, cp2, len2); |
|
608 | 1148 |
|
3111 | 1149 |
if (cmp > 0) { |
1150 |
RETURN ( true ); |
|
1151 |
} |
|
1152 |
if ((cmp == 0) && (len1 > len2)) { |
|
1153 |
RETURN ( true ); |
|
1154 |
} |
|
1155 |
RETURN ( false ); |
|
1156 |
} |
|
1 | 1157 |
} |
370 | 1158 |
%}. |
608 | 1159 |
^ super > aString |
1160 |
! |
|
1 | 1161 |
|
608 | 1162 |
after:aString |
1163 |
"Compare the receiver with the argument and return true if the |
|
1164 |
receiver should come after the argument in a sorted list. |
|
1165 |
Otherwise return false. |
|
1166 |
The comparison is language specific, depending on the value of |
|
1368 | 1167 |
LC_COLLATE, which is initialized from the environment. |
1168 |
||
1169 |
STUPID: |
|
1486 | 1170 |
#after has a completely different meaning in SeqColl ..." |
1 | 1171 |
|
1251 | 1172 |
^ (self compareCollatingWith:aString) > 0 |
1173 |
||
1368 | 1174 |
"Modified: 10.5.1996 / 14:02:45 / cg" |
1251 | 1175 |
! |
1176 |
||
1177 |
compareCollatingWith:aString |
|
1178 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
1179 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
1180 |
The comparison is language specific, depending on the value of |
|
1181 |
LC_COLLATE, which is in the shell environment." |
|
1182 |
||
1 | 1183 |
%{ /* NOCONTEXT */ |
1184 |
||
608 | 1185 |
int cmp; |
1186 |
REGISTER OBJ s = aString; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1187 |
unsigned char *cp1, *cp2; |
53 | 1188 |
OBJ cls; |
3111 | 1189 |
OBJ myCls; |
608 | 1190 |
|
3111 | 1191 |
if (__isNonNilObject(s)) { |
1192 |
cls = __qClass(s); |
|
1193 |
myCls = __qClass(self); |
|
1194 |
||
1195 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
|
1196 |
cp1 = __stringVal(self); |
|
608 | 1197 |
|
3111 | 1198 |
/* |
1199 |
* care for instances of subclasses ... |
|
1200 |
*/ |
|
1201 |
if (myCls != String) { |
|
1202 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
|
1203 |
||
1204 |
cp1 += n; |
|
1205 |
} |
|
1 | 1206 |
|
3111 | 1207 |
cp2 = __stringVal(s); |
1208 |
/* |
|
1209 |
* care for instances of subclasses ... |
|
1210 |
*/ |
|
1211 |
if (cls != String) { |
|
1212 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
608 | 1213 |
|
3111 | 1214 |
cp2 += n; |
1215 |
} |
|
608 | 1216 |
|
1217 |
#ifdef HAS_STRCOLL |
|
3111 | 1218 |
cmp = strcoll(cp1, cp2); |
608 | 1219 |
#else |
3111 | 1220 |
cmp = strcmp(cp1, cp2); |
608 | 1221 |
#endif |
1222 |
||
3111 | 1223 |
if (cmp > 0) { |
1224 |
RETURN ( __MKSMALLINT(1) ); |
|
1225 |
} |
|
1226 |
if (cmp < 0) { |
|
1227 |
RETURN ( __MKSMALLINT(-1) ); |
|
1228 |
} |
|
1229 |
RETURN ( __MKSMALLINT(0) ); |
|
1230 |
} |
|
370 | 1231 |
} |
329 | 1232 |
%}. |
608 | 1233 |
" |
1234 |
currently, this operation is only defined for strings, symbols |
|
1235 |
and subclasses. |
|
1236 |
" |
|
1251 | 1237 |
^ self primitiveFailed |
1 | 1238 |
! |
1239 |
||
608 | 1240 |
~= aString |
1241 |
"Compare the receiver with the argument and return true if the |
|
1242 |
receiver is not equal to the argument. Otherwise return false. |
|
3111 | 1243 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
1244 |
Actually, there is no need to redefine that method here, |
|
1245 |
the default (= not as inherited) works ok. |
|
1246 |
However, this may be heavily used and the redefinition saves an |
|
1247 |
extra message send." |
|
1 | 1248 |
|
608 | 1249 |
%{ /* NOCONTEXT */ |
1250 |
||
1 | 1251 |
int l1, l2; |
608 | 1252 |
REGISTER OBJ s = aString; |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1253 |
unsigned char *cp1, *cp2; |
3111 | 1254 |
OBJ cls, myCls; |
3335 | 1255 |
INT addrDelta; |
1 | 1256 |
|
608 | 1257 |
if (s == self) { |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1258 |
RETURN ( false ); |
608 | 1259 |
} |
1260 |
if (! __isNonNilObject(s)) { |
|
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1261 |
RETURN ( true ); |
608 | 1262 |
} |
3111 | 1263 |
|
1264 |
cls = __qClass(s); |
|
1265 |
myCls = __qClass(self); |
|
1266 |
||
1267 |
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
|
1268 |
cp1 = __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1269 |
l1 = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1270 |
/* |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1271 |
* 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
|
1272 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1273 |
if (myCls != String) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1274 |
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
|
1275 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1276 |
cp1 += n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1277 |
l1 -= n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1278 |
} |
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 |
cp2 = __stringVal(s); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1281 |
l2 = __stringSize(s); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1282 |
/* |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1283 |
* 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
|
1284 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1285 |
if (cls != String) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1286 |
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
|
1287 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1288 |
cp2 += n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1289 |
l2 -= n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1290 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1291 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1292 |
if (l1 != l2) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1293 |
RETURN ( true ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1294 |
} |
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 |
addrDelta = cp2 - cp1; |
3989 | 1297 |
# ifdef UNROLL_LOOPS |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1298 |
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
|
1299 |
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
|
1300 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1301 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1302 |
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
|
1303 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1304 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1305 |
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
|
1306 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1307 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1308 |
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
|
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 INT) * 4); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1312 |
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
|
1313 |
} |
3989 | 1314 |
# endif /* UNROLL_LOOPS */ |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1315 |
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
|
1316 |
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
|
1317 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1318 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1319 |
l1 -= sizeof(unsigned INT); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1320 |
cp1 += sizeof(unsigned INT); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1321 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1322 |
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
|
1323 |
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
|
1324 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1325 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1326 |
l1 -= sizeof(unsigned short); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1327 |
cp1 += sizeof(unsigned short); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1328 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1329 |
while (l1) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1330 |
if (*cp1 != *(cp1+addrDelta)) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1331 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1332 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1333 |
l1--; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1334 |
cp1++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1335 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1336 |
RETURN (false); |
608 | 1337 |
} |
3111 | 1338 |
%}. |
608 | 1339 |
^ super ~= aString |
1340 |
! ! |
|
1341 |
||
1342 |
!String methodsFor:'converting'! |
|
1343 |
||
3281
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1344 |
asBoldText |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1345 |
"return self as a bold text" |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1346 |
|
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1347 |
^Text string: self emphasis: #bold |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1348 |
! |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1349 |
|
5760 | 1350 |
asOneByteString |
1351 |
"I am a string" |
|
1352 |
||
1353 |
^ self |
|
1354 |
! |
|
1355 |
||
2856 | 1356 |
asString |
1357 |
"I am a string" |
|
1358 |
||
1359 |
^ self |
|
1360 |
||
1361 |
"Created: 14.8.1997 / 11:37:03 / stefan" |
|
1362 |
! |
|
1363 |
||
608 | 1364 |
asSymbol |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1365 |
"return a unique symbol with the name taken from my characters." |
608 | 1366 |
%{ |
1367 |
OBJ newSymbol; |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1368 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1369 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1370 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1371 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1372 |
if (cls != String) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1373 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1374 |
} else { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1375 |
indx = 0; |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1376 |
} |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1377 |
newSymbol = __MKSYMBOL(__stringVal(self) + indx, (OBJ *)0); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1378 |
if (newSymbol) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1379 |
RETURN ( newSymbol); |
608 | 1380 |
} |
1381 |
%}. |
|
1382 |
^ ObjectMemory allocationFailureSignal raise. |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1383 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1384 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1385 |
'hello' asSymbol |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1386 |
" |
608 | 1387 |
! |
1388 |
||
1389 |
asSymbolIfInterned |
|
1390 |
"if a symbol with the receivers characters is already known, return it. |
|
1391 |
Otherwise, return nil. This can be used to query for an existing |
|
1392 |
symbol and is the same as |
|
5407 | 1393 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
608 | 1394 |
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
|
1395 |
performed once." |
1 | 1396 |
|
608 | 1397 |
%{ /* NOCONTEXT */ |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1398 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1399 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1400 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1401 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1402 |
if (cls != String) { |
5407 | 1403 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1404 |
} else { |
5407 | 1405 |
indx = 0; |
608 | 1406 |
} |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1407 |
RETURN ( __SYMBOL_OR_NIL(__stringVal(self) + indx)); |
5407 | 1408 |
%}. |
1409 |
self primitiveFailed |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1410 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1411 |
'hello' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1412 |
'fooBarBaz' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1413 |
" |
608 | 1414 |
! |
1415 |
||
5762 | 1416 |
asUnicodeString |
1417 |
"thats not really true - characters above ascii 16r7F may need special treatment" |
|
1418 |
||
1419 |
^ ((UnicodeString new:self size) replaceFrom:1 to:self size with:self startingAt:1) |
|
1420 |
! |
|
1421 |
||
2416 | 1422 |
decodeAsLiteralArray |
1423 |
"given a literalEncoding in the receiver, |
|
1424 |
create & return the corresponding object. |
|
1425 |
The inverse operation to #literalArrayEncoding." |
|
1426 |
||
1427 |
^ self |
|
1428 |
||
1429 |
"Created: 25.2.1997 / 19:18:19 / cg" |
|
1430 |
! |
|
1431 |
||
608 | 1432 |
literalArrayEncoding |
1246 | 1433 |
"encode myself as an array literal, from which a copy of the receiver |
1434 |
can be reconstructed with #decodeAsLiteralArray." |
|
608 | 1435 |
|
1436 |
^ self |
|
1437 |
||
1438 |
"Modified: 1.9.1995 / 02:25:45 / claus" |
|
1246 | 1439 |
"Modified: 22.4.1996 / 13:00:50 / cg" |
608 | 1440 |
! |
1441 |
||
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1442 |
withTabsExpanded:numSpaces |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1443 |
"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
|
1444 |
are expanded into spaces (assuming numSpaces-col tabs). |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1445 |
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
|
1446 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1447 |
This does handle multiline strings. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1448 |
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
|
1449 |
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
|
1450 |
|
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
1451 |
%{ /* STACK:700 */ |
2894 | 1452 |
unsigned char buffer[80*8 + 10]; |
1453 |
unsigned char *srcP, *dstP, *cp0; |
|
608 | 1454 |
int idx, sz; |
1455 |
int any = 0; |
|
1456 |
OBJ newString; |
|
1457 |
char c; |
|
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1458 |
int n; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1459 |
|
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1460 |
if ((__qClass(self) == String) |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1461 |
&& __isSmallInteger(numSpaces)) { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1462 |
n = __intVal(numSpaces); |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1463 |
|
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1464 |
/* |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1465 |
* 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
|
1466 |
* 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
|
1467 |
* 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
|
1468 |
*/ |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1469 |
if (__stringSize(self) < 80) { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1470 |
idx = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1471 |
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
|
1472 |
if (c == '\t') { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1473 |
any = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1474 |
while (idx % n) { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1475 |
idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1476 |
*dstP++ = ' '; |
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 |
idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1479 |
*dstP++ = ' '; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1480 |
} else { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1481 |
*dstP++ = c; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1482 |
idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1483 |
if (c == '\n') { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1484 |
idx = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1485 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1486 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1487 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1488 |
if (! any) RETURN(self); |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1489 |
*dstP = '\0'; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1490 |
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
|
1491 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1492 |
/* |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1493 |
* 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
|
1494 |
* and expand it. |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1495 |
* |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1496 |
* first, scan for size ... |
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 |
idx = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1499 |
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
|
1500 |
if (c == '\t') { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1501 |
any = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1502 |
while (idx % n) { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1503 |
idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1504 |
sz++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1505 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1506 |
idx++; sz ++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1507 |
} else { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1508 |
sz++; idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1509 |
if (c == '\n') { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1510 |
idx = 1; |
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 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1513 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1514 |
if (! any) RETURN(self); |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1515 |
|
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1516 |
/* |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1517 |
* get the string |
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 |
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
|
1520 |
__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
|
1521 |
if (newString != nil) { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1522 |
__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
|
1523 |
|
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1524 |
/* |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1525 |
* expand |
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 |
idx = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1528 |
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
|
1529 |
if (c == '\t') { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1530 |
while (idx % n) { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1531 |
idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1532 |
*dstP++ = ' '; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1533 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1534 |
idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1535 |
*dstP++ = ' '; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1536 |
} else { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1537 |
*dstP++ = c; idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1538 |
if (c == '\n') { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1539 |
idx = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1540 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1541 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1542 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1543 |
*dstP++ = '\0'; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1544 |
RETURN (newString); |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1545 |
} |
608 | 1546 |
} |
1547 |
%}. |
|
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1548 |
^ super withTabsExpanded:numSpaces |
1 | 1549 |
! ! |
1550 |
||
1551 |
!String methodsFor:'copying'! |
|
1552 |
||
1553 |
, aString |
|
2 | 1554 |
"return the concatenation of myself and the argument, aString as |
1555 |
a String. |
|
1 | 1556 |
- reimplemented here for speed" |
1557 |
||
1558 |
%{ |
|
95 | 1559 |
int l1, l2, sz; |
1 | 1560 |
REGISTER OBJ s = aString; |
329 | 1561 |
REGISTER OBJ _string = String; |
13 | 1562 |
OBJ myClass, argClass, newString; |
1 | 1563 |
|
329 | 1564 |
if (__isNonNilObject(s)) { |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1565 |
myClass = __qClass(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1566 |
argClass = __qClass(s); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1567 |
/* |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1568 |
* 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
|
1569 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1570 |
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
|
1571 |
&& ((argClass == _string) || (argClass == Symbol))) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1572 |
l1 = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1573 |
l2 = __stringSize(s); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1574 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1575 |
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
|
1576 |
__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
|
1577 |
if (newString != nil) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1578 |
char *cp1, *cp2; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1579 |
REGISTER unsigned char *dstp; |
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 |
__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
|
1582 |
dstp = __stringVal(newString); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1583 |
cp1 = (char *) __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1584 |
cp2 = (char *) __stringVal(aString); |
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1585 |
|
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1586 |
#ifdef bcopy4 |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1587 |
/* 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
|
1588 |
* 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
|
1589 |
* 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
|
1590 |
* 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
|
1591 |
* 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
|
1592 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1593 |
{ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1594 |
int nw = l1 >> 2; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1595 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1596 |
if (l1 & 3) nw++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1597 |
bcopy4(cp1, dstp, nw); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1598 |
dstp += l1; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1599 |
} |
3673 | 1600 |
#else |
1601 |
# ifdef FAST_MEMCPY |
|
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1602 |
memcpy(dstp, cp1, l1); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1603 |
dstp += l1; |
3673 | 1604 |
# else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1605 |
while (l1 >= 4) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1606 |
*(int *)dstp = *(int *)cp1; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1607 |
dstp += 4; cp1 += 4; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1608 |
l1 -= 4; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1609 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1610 |
while (l1--) *dstp++ = *cp1++; |
3673 | 1611 |
# endif |
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1612 |
#endif |
2862 | 1613 |
|
3673 | 1614 |
#ifdef bcopy4 |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1615 |
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
|
1616 |
int nw = l2 >> 2; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1617 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1618 |
if (l2 & 3) nw++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1619 |
bcopy4(cp2, dstp, nw); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1620 |
*(dstp + l2) = '\0'; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1621 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1622 |
} |
3673 | 1623 |
#endif |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1624 |
|
1 | 1625 |
#ifdef FAST_MEMCPY |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1626 |
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
|
1627 |
dstp[l2] = '\0'; |
1 | 1628 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1629 |
while (l2--) *dstp++ = *cp2++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1630 |
*dstp = '\0'; |
1 | 1631 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1632 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1633 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1634 |
} |
1 | 1635 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1636 |
%}. |
1 | 1637 |
^ super , aString |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1638 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1639 |
" |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1640 |
#[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
|
1641 |
" |
1 | 1642 |
! |
1643 |
||
1644 |
concatenate:string1 and:string2 |
|
1645 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
1646 |
This is equivalent to self , string1 , string2 |
|
1647 |
- generated by compiler when such a construct is detected" |
|
1648 |
||
1649 |
|newString| |
|
2862 | 1650 |
|
1 | 1651 |
%{ |
95 | 1652 |
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
|
1653 |
#if !defined(FAST_MEMCPY) |
1 | 1654 |
REGISTER unsigned char *srcp; |
1655 |
#endif |
|
1656 |
REGISTER unsigned char *dstp; |
|
1657 |
||
53 | 1658 |
if ((__isString(self) || __isSymbol(self)) |
1659 |
&& (__isString(string1) || __isSymbol(string1)) |
|
1660 |
&& (__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
|
1661 |
len1 = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1662 |
len2 = __stringSize(string1); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1663 |
len3 = __stringSize(string2); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1664 |
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
|
1665 |
__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
|
1666 |
if (newString != nil) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1667 |
__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
|
1668 |
dstp = __stringVal(newString); |
1 | 1669 |
#ifdef FAST_MEMCPY |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1670 |
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
|
1671 |
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
|
1672 |
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
|
1673 |
*(dstp + len1 + len2 + len3) = '\0'; |
1 | 1674 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1675 |
srcp = __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1676 |
while (len1--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1677 |
srcp = __stringVal(string1); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1678 |
while (len2--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1679 |
srcp = __stringVal(string2); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1680 |
while (len3--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1681 |
*dstp = '\0'; |
1 | 1682 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1683 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1684 |
} |
1 | 1685 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1686 |
%}. |
1 | 1687 |
^ super , string1 , string2 |
1688 |
! |
|
1689 |
||
1690 |
concatenate:string1 and:string2 and:string3 |
|
1691 |
"return the concatenation of myself and the string arguments. |
|
1692 |
This is equivalent to self , string1 , string2 , string3 |
|
1693 |
- generated by compiler when such a construct is detected" |
|
1694 |
||
1695 |
|newString| |
|
2862 | 1696 |
|
1 | 1697 |
%{ |
95 | 1698 |
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
|
1699 |
#if !defined(FAST_MEMCPY) |
1 | 1700 |
REGISTER unsigned char *srcp; |
1701 |
#endif |
|
1702 |
REGISTER unsigned char *dstp; |
|
1703 |
||
53 | 1704 |
if ((__isString(self) || __isSymbol(self)) |
1705 |
&& (__isString(string1) || __isSymbol(string1)) |
|
1706 |
&& (__isString(string2) || __isSymbol(string2)) |
|
1707 |
&& (__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
|
1708 |
len1 = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1709 |
len2 = __stringSize(string1); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1710 |
len3 = __stringSize(string2); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1711 |
len4 = __stringSize(string3); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1712 |
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
|
1713 |
__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
|
1714 |
if (newString != nil) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1715 |
__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
|
1716 |
dstp = __stringVal(newString); |
1 | 1717 |
#ifdef FAST_MEMCPY |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1718 |
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
|
1719 |
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
|
1720 |
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
|
1721 |
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
|
1722 |
*(dstp + len1 + len2 + len3 + len4) = '\0'; |
1 | 1723 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1724 |
srcp = __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1725 |
while (len1--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1726 |
srcp = __stringVal(string1); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1727 |
while (len2--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1728 |
srcp = __stringVal(string2); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1729 |
while (len3--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1730 |
srcp = __stringVal(string3); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1731 |
while (len4--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1732 |
*dstp = '\0'; |
1 | 1733 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1734 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1735 |
} |
1 | 1736 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1737 |
%}. |
1 | 1738 |
^ super , string1 , string2 , string3 |
1739 |
! |
|
1740 |
||
4745 | 1741 |
copy |
1742 |
"return a copy of the receiver" |
|
1743 |
||
1744 |
(self isMemberOf:String) ifTrue:[ |
|
1745 |
^ self copyFrom:1 |
|
1746 |
]. |
|
1747 |
^ super copy |
|
1748 |
! |
|
1749 |
||
608 | 1750 |
copyFrom:start |
1751 |
"return the substring from start, anInteger to the end. |
|
1752 |
This method will always return a string, even if the receiver |
|
1753 |
is a subclass-instance. This might change if there is a need. |
|
1754 |
- reimplemented here for speed" |
|
1 | 1755 |
|
13 | 1756 |
%{ /* NOCONTEXT */ |
1 | 1757 |
|
608 | 1758 |
#if !defined(FAST_MEMCPY) |
1759 |
REGISTER unsigned char *srcp; |
|
1760 |
#endif |
|
1 | 1761 |
REGISTER unsigned char *dstp; |
608 | 1762 |
REGISTER int count; |
1763 |
int len, index1, sz; |
|
1764 |
OBJ newString; |
|
2862 | 1765 |
OBJ myClass; |
608 | 1766 |
|
2862 | 1767 |
myClass = __qClass(self); |
1768 |
||
2894 | 1769 |
#ifndef NO_PRIM_STRING |
2862 | 1770 |
if (__isSmallInteger(start) |
1771 |
&& ((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
|
1772 |
len = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1773 |
index1 = __intVal(start); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1774 |
if (index1 > 0) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1775 |
if (index1 <= len) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1776 |
count = len - index1 + 1; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1777 |
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
|
1778 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1779 |
__PROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1780 |
__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
|
1781 |
__UNPROTECT_CONTEXT__ |
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 |
if (newString != nil) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1784 |
__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
|
1785 |
dstp = __stringVal(newString); |
1 | 1786 |
#ifdef FAST_MEMCPY |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1787 |
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
|
1788 |
dstp[count] = '\0'; |
1 | 1789 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1790 |
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
|
1791 |
while (count--) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1792 |
*dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1793 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1794 |
*dstp = '\0'; |
1 | 1795 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1796 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1797 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1798 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1799 |
} |
13 | 1800 |
} |
2894 | 1801 |
#endif |
51 | 1802 |
%}. |
608 | 1803 |
"fall back in case of non-integer index or out-of-bound index; |
1804 |
will eventually lead to an out-of-bound signal raise" |
|
51 | 1805 |
|
608 | 1806 |
^ super copyFrom:start |
1 | 1807 |
! |
1808 |
||
1809 |
copyFrom:start to:stop |
|
1810 |
"return the substring starting at index start, anInteger and ending |
|
53 | 1811 |
at stop, anInteger. This method will always return a string, even |
1812 |
if the receiver is a subclass-instance. This might change if there is a need. |
|
1 | 1813 |
- reimplemented here for speed" |
1814 |
||
13 | 1815 |
%{ /* NOCONTEXT */ |
1816 |
||
1 | 1817 |
REGISTER unsigned char *srcp; |
1818 |
REGISTER unsigned char *dstp; |
|
1819 |
REGISTER int count; |
|
95 | 1820 |
int len, sz, index1, index2; |
13 | 1821 |
OBJ newString; |
2862 | 1822 |
OBJ myClass; |
1 | 1823 |
|
2862 | 1824 |
myClass = __qClass(self); |
1825 |
||
2894 | 1826 |
#ifndef NO_PRIM_STRING |
2862 | 1827 |
if (__bothSmallInteger(start, stop) |
1828 |
&& ((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
|
1829 |
len = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1830 |
index1 = __intVal(start); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1831 |
index2 = __intVal(stop); |
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 |
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
|
1834 |
if (index2 <= len) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1835 |
count = index2 - index1 + 1; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1836 |
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
|
1837 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1838 |
__PROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1839 |
__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
|
1840 |
__UNPROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1841 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1842 |
if (newString != nil) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1843 |
__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
|
1844 |
dstp = __stringVal(newString); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1845 |
srcp = __stringVal(self) + index1 - 1; |
2894 | 1846 |
#ifdef bcopy4 |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1847 |
{ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1848 |
int nw = count >> 2; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1849 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1850 |
if (count & 3) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1851 |
nw++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1852 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1853 |
bcopy4(srcp, dstp, nw); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1854 |
dstp[count] = '\0'; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1855 |
} |
1 | 1856 |
#else |
2894 | 1857 |
# ifdef FAST_MEMCPY |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1858 |
memcpy(dstp, srcp, count); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1859 |
dstp[count] = '\0'; |
209 | 1860 |
# else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1861 |
while (count--) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1862 |
*dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1863 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1864 |
*dstp = '\0'; |
209 | 1865 |
# endif |
13 | 1866 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1867 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1868 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1869 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1870 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1871 |
/* |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1872 |
* allow empty copy |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1873 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1874 |
if (index1 > index2) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1875 |
__PROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1876 |
__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
|
1877 |
__UNPROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1878 |
if (newString != nil) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1879 |
__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
|
1880 |
(__stringVal(newString))[0] = '\0'; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1881 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1882 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1883 |
} |
1 | 1884 |
} |
2894 | 1885 |
#endif |
51 | 1886 |
%}. |
1887 |
"fall back in case of non-integer index or out-of-bound index; |
|
1888 |
will eventually lead to an out-of-bound signal raise" |
|
1889 |
||
1 | 1890 |
^ super copyFrom:start to:stop |
1891 |
! |
|
1892 |
||
608 | 1893 |
copyWith:aCharacter |
1894 |
"return a new string containing the receivers characters |
|
1895 |
and the single new character, aCharacter. |
|
1896 |
This is different from concatentation, which expects another string |
|
1897 |
as argument, but equivalent to copy-and-addLast. |
|
1898 |
Reimplemented here for more speed" |
|
1899 |
||
1900 |
%{ /* NOCONTEXT */ |
|
1901 |
||
2887 | 1902 |
int count; |
608 | 1903 |
int sz; |
1904 |
REGISTER unsigned char *dstp; |
|
1905 |
OBJ cls, newString; |
|
2862 | 1906 |
OBJ myClass; |
608 | 1907 |
|
2862 | 1908 |
myClass = __qClass(self); |
1909 |
||
2894 | 1910 |
#ifndef NO_PRIM_STRING |
2862 | 1911 |
if (__isCharacter(aCharacter) |
1912 |
&& ((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
|
1913 |
count = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1914 |
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
|
1915 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1916 |
__PROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1917 |
__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
|
1918 |
__UNPROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1919 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1920 |
if (newString) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1921 |
__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
|
1922 |
dstp = __stringVal(newString); |
2862 | 1923 |
|
2887 | 1924 |
#ifdef bcopy4 |
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 |
int nw = count >> 2; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1927 |
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
|
1928 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1929 |
if (count & 3) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1930 |
nw++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1931 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1932 |
bcopy4(srcp, dstp, nw); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1933 |
dstp += count; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1934 |
} |
608 | 1935 |
#else |
2887 | 1936 |
# ifdef FAST_MEMCPY |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1937 |
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
|
1938 |
dstp += count; |
608 | 1939 |
# else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1940 |
{ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1941 |
REGISTER unsigned char *srcp; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1942 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1943 |
srcp = __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1944 |
while ((*dstp = *srcp++) != '\0') |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1945 |
dstp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1946 |
} |
608 | 1947 |
# endif |
2887 | 1948 |
# endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1949 |
*dstp++ = __intVal(_characterVal(aCharacter)); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1950 |
*dstp = '\0'; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1951 |
RETURN (newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1952 |
} |
608 | 1953 |
} |
2894 | 1954 |
#endif |
608 | 1955 |
%}. |
1956 |
"fall back in case of non-character arg; |
|
1957 |
will eventually lead to an bad element signal raise" |
|
1958 |
||
1959 |
^ super copyWith:aCharacter |
|
1960 |
! |
|
1961 |
||
2886 | 1962 |
deepCopy |
1963 |
"return a copy of the receiver" |
|
608 | 1964 |
|
1965 |
" |
|
1966 |
could be an instance of a subclass which needs deepCopy |
|
1967 |
of its named instvars ... |
|
1968 |
" |
|
1969 |
(self isMemberOf:String) ifTrue:[ |
|
1970 |
^ self copyFrom:1 |
|
1971 |
]. |
|
1972 |
^ super deepCopy |
|
1973 |
! |
|
1974 |
||
2886 | 1975 |
deepCopyUsing:aDictionary |
608 | 1976 |
"return a copy of the receiver - reimplemented to be a bit faster" |
1977 |
||
1978 |
" |
|
1979 |
could be an instance of a subclass which needs deepCopy |
|
1980 |
of its named instvars ... |
|
1981 |
" |
|
1982 |
(self isMemberOf:String) ifTrue:[ |
|
1983 |
^ self copyFrom:1 |
|
1984 |
]. |
|
1985 |
^ super deepCopy |
|
1986 |
! |
|
1987 |
||
2886 | 1988 |
shallowCopy |
1989 |
"return a copy of the receiver" |
|
608 | 1990 |
|
1991 |
(self isMemberOf:String) ifTrue:[ |
|
1992 |
^ self copyFrom:1 |
|
1993 |
]. |
|
1994 |
^ super shallowCopy |
|
1995 |
! |
|
1996 |
||
2886 | 1997 |
simpleDeepCopy |
1998 |
"return a copy of the receiver" |
|
608 | 1999 |
|
2000 |
" |
|
2001 |
could be an instance of a subclass which needs deepCopy |
|
2002 |
of its named instvars ... |
|
2003 |
" |
|
2004 |
(self isMemberOf:String) ifTrue:[ |
|
2005 |
^ self copyFrom:1 |
|
2006 |
]. |
|
2007 |
^ super deepCopy |
|
2008 |
! ! |
|
2009 |
||
4154 | 2010 |
!String methodsFor:'filling & replacing'! |
608 | 2011 |
|
2886 | 2012 |
atAllPut:aCharacter |
608 | 2013 |
"replace all elements with aCharacter |
1 | 2014 |
- reimplemented here for speed" |
2015 |
||
13 | 2016 |
%{ /* NOCONTEXT */ |
2017 |
||
608 | 2018 |
#ifndef FAST_MEMSET |
2019 |
REGISTER unsigned char *dst; |
|
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
2020 |
#endif |
608 | 2021 |
REGISTER int l; |
2022 |
REGISTER int byteValue; |
|
1 | 2023 |
|
608 | 2024 |
if (__isCharacter(aCharacter) && __isString(self)) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2025 |
byteValue = __intVal(_characterVal(aCharacter)); |
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
2026 |
l = __stringSize(self); |
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2027 |
|
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2028 |
#ifdef FAST_MEMSET |
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
2029 |
if (l > 0) { |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
2030 |
memset(__stringVal(self), byteValue, l); |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
2031 |
} |
608 | 2032 |
#else |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2033 |
{ |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2034 |
INT v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2035 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2036 |
v = (byteValue << 8) | byteValue; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2037 |
v = (v << 16) | v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2038 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2039 |
dst = __stringVal(self); |
3712 | 2040 |
|
2041 |
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */ |
|
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
2042 |
if (l > 0) { |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
2043 |
memset4(dst, v, l>>2); |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
2044 |
l = l & 3; |
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
2045 |
} |
3712 | 2046 |
# else |
2047 |
# ifdef UINT64 |
|
4247 | 2048 |
{ |
2049 |
UINT64 v64; |
|
2050 |
||
4660 | 2051 |
v64 = v; |
4247 | 2052 |
v64 = (v64 << 32) | v; |
4660 | 2053 |
while (l >= 8) { |
4247 | 2054 |
((UINT64 *)dst)[0] = v64; |
2055 |
dst += 8; |
|
2056 |
l -= 8; |
|
2057 |
} |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2058 |
} |
3712 | 2059 |
# else /* no UINT64 */ |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2060 |
while (l >= 16) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2061 |
((int *)dst)[0] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2062 |
((int *)dst)[1] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2063 |
((int *)dst)[2] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2064 |
((int *)dst)[3] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2065 |
dst += 16; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2066 |
l -= 16; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2067 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2068 |
if (l >= 8) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2069 |
((int *)dst)[0] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2070 |
((int *)dst)[1] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2071 |
dst += 8; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2072 |
l -= 8; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2073 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2074 |
if (l >= 4) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2075 |
((int *)dst)[0] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2076 |
dst += 4; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2077 |
l -= 4; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2078 |
} |
3712 | 2079 |
# if 0 |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2080 |
if (l >= 2) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2081 |
((short *)dst)[0] = v; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2082 |
dst += 2; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2083 |
l -= 2; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2084 |
} |
3712 | 2085 |
# endif |
2086 |
||
5648 | 2087 |
# endif /* UINT64 */ |
2088 |
# endif /* FAST_MEMSET4 */ |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2089 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2090 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2091 |
/* |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2092 |
* remaining bytes |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2093 |
*/ |
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
2094 |
while (l-- > 0) |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2095 |
*dst++ = byteValue; |
3712 | 2096 |
|
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2097 |
#endif /* no FAST_MEMSET */ |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2098 |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2099 |
RETURN ( self ); |
608 | 2100 |
} |
2862 | 2101 |
%}. |
608 | 2102 |
^ super atAllPut:aCharacter |
1 | 2103 |
|
608 | 2104 |
" |
3712 | 2105 |
(String new:10) atAllPut:$* |
608 | 2106 |
String new:10 withAll:$* |
2107 |
" |
|
2108 |
! |
|
2109 |
||
2929 | 2110 |
replaceAll:oldCharacter with:newCharacter |
4120 | 2111 |
"replace all oldCharacters by newCharacter in the receiver. |
2112 |
||
2113 |
Notice: This operation modifies the receiver, NOT a copy; |
|
2114 |
therefore the change may affect all others referencing the receiver." |
|
608 | 2115 |
|
2116 |
%{ /* NOCONTEXT */ |
|
2117 |
||
2118 |
REGISTER unsigned char *srcp; |
|
2119 |
REGISTER unsigned oldVal, newVal; |
|
4120 | 2120 |
unsigned char c, cNext; |
608 | 2121 |
|
2122 |
if (__isCharacter(oldCharacter) |
|
2123 |
&& __isCharacter(newCharacter) |
|
2124 |
&& __isString(self)) { |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2125 |
srcp = (unsigned char *)__stringVal(self); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2126 |
oldVal = __intVal(_characterVal(oldCharacter)); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2127 |
newVal = __intVal(_characterVal(newCharacter)); |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2128 |
|
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2129 |
cNext = *srcp; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2130 |
while ((c = cNext) != '\0') { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2131 |
cNext = srcp[1]; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2132 |
if (c == oldVal) |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2133 |
*srcp = newVal; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2134 |
srcp++; |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2135 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2136 |
RETURN ( self ); |
1 | 2137 |
} |
2862 | 2138 |
%}. |
2929 | 2139 |
^ super replaceAll:oldCharacter with:newCharacter |
51 | 2140 |
|
608 | 2141 |
" |
4120 | 2142 |
'helloWorld' copy replaceAll:$o with:$O |
2143 |
'helloWorld' copy replaceAll:$d with:$* |
|
2144 |
'helloWorld' copy replaceAll:$h with:$* |
|
608 | 2145 |
" |
2146 |
! |
|
1 | 2147 |
|
2886 | 2148 |
replaceFrom:start to:stop with:aString startingAt:repStart |
1 | 2149 |
"replace the characters starting at index start, anInteger and ending |
2150 |
at stop, anInteger with characters from aString starting at repStart. |
|
3234 | 2151 |
Return the receiver. |
1 | 2152 |
|
2153 |
- reimplemented here for speed" |
|
2154 |
||
2155 |
%{ /* NOCONTEXT */ |
|
2156 |
||
2157 |
REGISTER unsigned char *srcp, *dstp; |
|
2158 |
REGISTER int count; |
|
2159 |
int len, index1, index2; |
|
2160 |
int repLen, repIndex; |
|
2161 |
||
2894 | 2162 |
#ifndef NO_PRIM_STRING |
53 | 2163 |
if ((__isString(aString) || __isSymbol(aString)) |
2164 |
&& __isString(self) |
|
252 | 2165 |
&& __bothSmallInteger(start, stop)) { |
3451 | 2166 |
len = __stringSize(self); |
2167 |
index1 = __intVal(start); |
|
2168 |
index2 = __intVal(stop); |
|
2169 |
count = index2 - index1 + 1; |
|
2170 |
if (count <= 0) { |
|
2171 |
RETURN (self); |
|
2172 |
} |
|
2173 |
if ((index2 <= len) && (index1 > 0)) { |
|
2174 |
repLen = __stringSize(aString); |
|
2175 |
repIndex = __intVal(repStart); |
|
2176 |
if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) { |
|
2177 |
srcp = __stringVal(aString) + repIndex - 1; |
|
2178 |
dstp = __stringVal(self) + index1 - 1; |
|
2179 |
if (aString == self) { |
|
2180 |
/* take care of overlapping copy */ |
|
2181 |
if (srcp < dstp) { |
|
2182 |
/* must do a reverse copy */ |
|
2183 |
srcp += count; |
|
2184 |
dstp += count; |
|
2185 |
while (count-- > 0) { |
|
2186 |
*--dstp = *--srcp; |
|
2187 |
} |
|
2188 |
RETURN (self); |
|
2189 |
} |
|
2190 |
} |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2191 |
#ifdef bcopy4 |
3451 | 2192 |
/* copy quadbytes if pointers are aligned */ |
2193 |
/* |
|
2194 |
* no sizeof(int) here please - |
|
2195 |
* - bcopy4 (if defined) copies 4-bytes on ALL machines |
|
2196 |
*/ |
|
2197 |
if ((count > 12) |
|
2198 |
&& (((unsigned INT)srcp & 3) == 0) |
|
2199 |
&& (((unsigned INT)dstp & 3) == 0)) { |
|
2200 |
int n; |
|
2201 |
||
2202 |
n = count >> 2; /* make it quads */ |
|
2203 |
bcopy4(srcp, dstp, n); |
|
2204 |
n <<= 2; /* back to chars */ |
|
2205 |
dstp += n; |
|
2206 |
srcp += n; |
|
2207 |
count -= n; |
|
2208 |
} |
|
2209 |
while (count-- > 0) { |
|
2210 |
*dstp++ = *srcp++; |
|
2211 |
} |
|
1 | 2212 |
#else |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2213 |
# ifdef FAST_MEMCPY |
3451 | 2214 |
bcopy(srcp, dstp, count); |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2215 |
# else |
3451 | 2216 |
/* copy longs if pointers are aligned */ |
2217 |
if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0) |
|
2218 |
&& (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) { |
|
2219 |
while (count >= sizeof(INT)) { |
|
2220 |
*((unsigned INT *)dstp) = *((unsigned INT *)srcp); |
|
2221 |
dstp += sizeof(INT); |
|
2222 |
srcp += sizeof(INT); |
|
2223 |
count -= sizeof(INT); |
|
2224 |
} |
|
2225 |
} |
|
2226 |
while (count-- > 0) { |
|
2227 |
*dstp++ = *srcp++; |
|
2228 |
} |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2229 |
# endif |
1 | 2230 |
#endif |
3451 | 2231 |
RETURN (self); |
2232 |
} |
|
2233 |
} |
|
1 | 2234 |
} |
2894 | 2235 |
#endif |
2862 | 2236 |
%}. |
1 | 2237 |
^ 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
|
2238 |
|
1 | 2239 |
! |
2240 |
||
2886 | 2241 |
reverse |
2242 |
"in-place reverse the characters of the string." |
|
53 | 2243 |
|
2244 |
"Q: is there a need to redefine it here ?" |
|
1 | 2245 |
|
2246 |
%{ /* NOCONTEXT */ |
|
2247 |
||
2248 |
REGISTER char c; |
|
2249 |
REGISTER unsigned char *hip, *lowp; |
|
2250 |
||
53 | 2251 |
if (__isString(self)) { |
1134 | 2252 |
lowp = __stringVal(self); |
2253 |
hip = lowp + __stringSize(self) - 1; |
|
159 | 2254 |
while (lowp < hip) { |
2255 |
c = *lowp; |
|
2256 |
*lowp = *hip; |
|
2257 |
*hip = c; |
|
2258 |
lowp++; |
|
2259 |
hip--; |
|
2260 |
} |
|
2261 |
RETURN ( self ); |
|
1 | 2262 |
} |
2862 | 2263 |
%}. |
1 | 2264 |
^ super reverse |
2265 |
! |
|
2266 |
||
2267 |
withoutSeparators |
|
2862 | 2268 |
"return a string containing the chars of myself |
2269 |
without leading and trailing whitespace. |
|
2270 |
If there is no whitespace, the receiver is returned. |
|
95 | 2271 |
Notice, this is different from String>>withoutSpaces." |
1 | 2272 |
|
42 | 2273 |
|startIndex "{ Class: SmallInteger }" |
51 | 2274 |
endIndex "{ Class: SmallInteger }" |
2275 |
sz| |
|
2276 |
||
53 | 2277 |
startIndex := 0. |
2862 | 2278 |
|
51 | 2279 |
%{ |
2884 | 2280 |
REGISTER unsigned char *cp; |
2281 |
REGISTER unsigned char *ep; |
|
2282 |
REGISTER unsigned char c; |
|
51 | 2283 |
REGISTER unsigned char *cp0; |
2884 | 2284 |
REGISTER unsigned char *ep0; |
1 | 2285 |
|
51 | 2286 |
/* ignore instances of subclasses ... */ |
329 | 2287 |
if (__qClass(self) == String) { |
3111 | 2288 |
cp = cp0 = __stringVal(self); |
2862 | 2289 |
|
3111 | 2290 |
/* |
2291 |
* find first non-whiteSpace from beginning |
|
2292 |
*/ |
|
2862 | 2293 |
#ifndef NON_ASCII |
2954 | 2294 |
# ifdef UINT64 |
3111 | 2295 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
2296 |
cp += 8; |
|
2297 |
} |
|
2862 | 2298 |
# endif |
3111 | 2299 |
while (*((unsigned *)cp) == 0x20202020) { |
2300 |
cp += 4; |
|
2301 |
} |
|
2862 | 2302 |
#endif |
3111 | 2303 |
while ((c = *cp) |
329 | 2304 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
3111 | 2305 |
&& (c <= ' ') |
329 | 2306 |
#endif |
3111 | 2307 |
&& ((c == ' ') || (c == '\n') || (c == '\t') |
2308 |
|| (c == '\r') || (c == '\f')) |
|
2309 |
) { |
|
2310 |
cp++; |
|
2311 |
} |
|
2884 | 2312 |
|
3111 | 2313 |
/* |
2314 |
* find first non-whiteSpace from end |
|
2315 |
*/ |
|
2316 |
ep = ep0 = cp0 + __stringSize(self) - 1; |
|
2317 |
while ((ep >= cp) && (*ep == ' ')) ep--; |
|
2318 |
c = *ep; |
|
2319 |
while ((ep >= cp) && |
|
2862 | 2320 |
#ifndef NON_ASCII |
3111 | 2321 |
(c <= ' ') && |
329 | 2322 |
#endif |
3111 | 2323 |
((c == ' ') || (c == '\n') || (c == '\t') |
2324 |
|| (c == '\r') || (c == '\f'))) { |
|
2325 |
ep--; |
|
2326 |
c = *ep; |
|
2327 |
} |
|
2884 | 2328 |
|
3111 | 2329 |
/* |
2330 |
* no whiteSpace ? |
|
2331 |
*/ |
|
2332 |
if ((cp == cp0) && (ep == ep0)) { |
|
2333 |
RETURN(self); |
|
2334 |
} |
|
2884 | 2335 |
|
3111 | 2336 |
startIndex = __MKSMALLINT(cp - cp0 + 1); |
2337 |
endIndex = __MKSMALLINT(ep - cp0 + 1); |
|
51 | 2338 |
} |
202 | 2339 |
%}. |
2340 |
startIndex == 0 ifTrue:[^ super withoutSeparators]. |
|
2341 |
||
2342 |
startIndex > endIndex ifTrue:[^ '']. |
|
1 | 2343 |
^ self copyFrom:startIndex to:endIndex |
2884 | 2344 |
|
2345 |
" |
|
2346 |
'hello' withoutSeparators |
|
2347 |
' hello' withoutSeparators |
|
2348 |
' hello ' withoutSeparators |
|
2349 |
' hello ' withoutSeparators |
|
2350 |
' hello ' withoutSeparators |
|
2351 |
' hello ' withoutSeparators |
|
2352 |
' ' withoutSeparators |
|
2353 |
" |
|
2354 |
||
608 | 2355 |
! |
2356 |
||
2357 |
withoutSpaces |
|
2862 | 2358 |
"return a string containing the characters of myself |
2359 |
without leading and trailing spaces. |
|
2884 | 2360 |
If there are no spaces, the receiver is returned unchanged. |
608 | 2361 |
Notice, this is different from String>>withoutSeparators." |
2362 |
||
2363 |
|startIndex "{ Class: SmallInteger }" |
|
2364 |
endIndex "{ Class: SmallInteger }" |
|
2365 |
sz blank| |
|
2366 |
||
2367 |
startIndex := 0. |
|
2368 |
%{ |
|
2369 |
REGISTER unsigned char *cp; |
|
2884 | 2370 |
REGISTER unsigned char *ep; |
2371 |
unsigned char *cp0; |
|
2372 |
unsigned char *ep0; |
|
608 | 2373 |
|
2374 |
/* ignore instances of subclasses ... */ |
|
2375 |
if (__qClass(self) == String) { |
|
3111 | 2376 |
cp = cp0 = __stringVal(self); |
2862 | 2377 |
|
3111 | 2378 |
/* |
2379 |
* find first non-blank from beginning |
|
2380 |
*/ |
|
2862 | 2381 |
#ifndef NON_ASCII |
2954 | 2382 |
# ifdef UINT64 |
3111 | 2383 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
2384 |
cp += 8; |
|
2385 |
} |
|
2954 | 2386 |
# endif /* UINT64 */ |
3111 | 2387 |
while (*((unsigned *)cp) == 0x20202020) { |
2388 |
cp += 4; |
|
2389 |
} |
|
2862 | 2390 |
#endif |
3111 | 2391 |
while (*cp == ' ') cp++; |
2884 | 2392 |
|
3111 | 2393 |
/* |
2394 |
* find first non-blank from end |
|
2395 |
*/ |
|
2396 |
ep = ep0 = cp0 + __stringSize(self) - 1; |
|
2397 |
while ((ep >= cp) && (*ep == ' ')) ep--; |
|
2862 | 2398 |
|
3111 | 2399 |
/* |
2400 |
* no blanks ? |
|
2401 |
*/ |
|
2402 |
if ((cp == cp0) && (ep == ep0)) { |
|
2403 |
RETURN(self); |
|
2404 |
} |
|
2884 | 2405 |
|
3111 | 2406 |
startIndex = __MKSMALLINT(cp - cp0 + 1); |
2407 |
endIndex = __MKSMALLINT(ep - cp0 + 1); |
|
608 | 2408 |
} |
2409 |
%}. |
|
2410 |
startIndex == 0 ifTrue:[^ super withoutSpaces]. |
|
2411 |
||
2412 |
startIndex > endIndex ifTrue:[^ '']. |
|
2886 | 2413 |
((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self]. |
608 | 2414 |
^ self copyFrom:startIndex to:endIndex |
2884 | 2415 |
|
2416 |
" |
|
2417 |
' hello' withoutSpaces |
|
2418 |
' hello ' withoutSpaces |
|
2419 |
' hello ' withoutSpaces |
|
2420 |
' hello ' withoutSpaces |
|
2421 |
' hello ' withoutSpaces |
|
2422 |
' ' withoutSpaces |
|
2423 |
" |
|
608 | 2424 |
! ! |
2425 |
||
2426 |
!String methodsFor:'printing & storing'! |
|
2427 |
||
2886 | 2428 |
isLiteral |
4660 | 2429 |
"return true, if the receiver can be used as a literal constant in ST syntax |
608 | 2430 |
(i.e. can be used in constant arrays)" |
2431 |
||
2432 |
^ true |
|
2433 |
! |
|
2434 |
||
2886 | 2435 |
|
2436 |
"print the receiver on standard output. |
|
4631 | 2437 |
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
|
2438 |
will therefore work even in case of emergency (but only, if Stdout is nil)." |
608 | 2439 |
|
2440 |
%{ /* NOCONTEXT */ |
|
2441 |
||
2442 |
if (__qClass(self) == String) { |
|
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2443 |
if (@global(Stdout) == nil) { |
1486 | 2444 |
#ifdef WIN32 |
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2445 |
fprintf(stdout, "%s" , __stringVal(self)); |
1486 | 2446 |
#else |
4631 | 2447 |
/*cg: used to have fputs here, but that seems to be NOT prepared |
2448 |
* for eintr arriving and thus sometimes sends the string twice ... |
|
2449 |
* |
|
2450 |
* fputs(__stringVal(self), stdout); |
|
2451 |
*/ |
|
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2452 |
fwrite(__stringVal(self), 1, __stringSize(self), stdout); |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2453 |
fflush(stdout); |
1486 | 2454 |
#endif |
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2455 |
RETURN (self); |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2456 |
} |
608 | 2457 |
} |
3751 | 2458 |
%}. |
608 | 2459 |
^ super print |
2460 |
! |
|
2461 |
||
3751 | 2462 |
printCR |
2463 |
"print the receiver on standard output, followed by a cr. |
|
4631 | 2464 |
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
|
2465 |
will therefore work even in case of emergency (but only, if Stdout is nil)." |
3751 | 2466 |
|
2467 |
%{ /* NOCONTEXT */ |
|
2468 |
||
2469 |
if (__qClass(self) == String) { |
|
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2470 |
if (@global(Stdout) == nil) { |
3751 | 2471 |
#ifdef WIN32 |
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2472 |
fprintf(stdout, "%s\n" , __stringVal(self)); |
3751 | 2473 |
#else |
4631 | 2474 |
/*cg: used to have fputs here, but that seems to be NOT prepared |
2475 |
* for eintr arriving and thus sometimes sends the string twice ... |
|
2476 |
* |
|
2477 |
* fputs(__stringVal(self), stdout); fputs("\n", stdout); |
|
2478 |
*/ |
|
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2479 |
fwrite(__stringVal(self), 1, __stringSize(self), stdout); |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2480 |
fwrite("\n", 1, 1, stdout); |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2481 |
fflush(stdout); |
3751 | 2482 |
#endif |
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2483 |
RETURN (self); |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2484 |
} |
3751 | 2485 |
} |
2486 |
%}. |
|
2487 |
^ super printCR |
|
2488 |
! |
|
2489 |
||
2886 | 2490 |
printfPrintString:formatString |
608 | 2491 |
"non-portable but sometimes useful. |
2492 |
Return a printed representation of the receiver as specified by formatString, |
|
2493 |
which is defined by printf. |
|
2494 |
No checking on buffer overrun is done; the resulting string may not |
|
2495 |
be larger than 799 characters. |
|
2496 |
This method is NONSTANDARD and may be removed without notice." |
|
2497 |
||
2498 |
%{ /* STACK: 1000 */ |
|
2499 |
||
2500 |
char buffer[800]; |
|
2501 |
char *cp; |
|
2502 |
OBJ s; |
|
2503 |
||
2504 |
if (__isString(formatString)) { |
|
2505 |
/* |
|
2506 |
* actually only needed on sparc: since thisContext is |
|
2507 |
* in a global register, which gets destroyed by printf, |
|
2508 |
* manually save it here - very stupid ... |
|
2509 |
*/ |
|
2510 |
||
1134 | 2511 |
cp = (char *)__stringVal(self); |
608 | 2512 |
if (__qClass(self) != String) |
1134 | 2513 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
608 | 2514 |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
2515 |
__BEGIN_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
2516 |
|
1134 | 2517 |
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
|
2518 |
|
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
2519 |
__END_PROTECT_REGISTERS__ |
608 | 2520 |
|
833 | 2521 |
s = __MKSTRING(buffer COMMA_SND); |
608 | 2522 |
if (s != nil) { |
2523 |
RETURN (s); |
|
2524 |
} |
|
2525 |
} |
|
2526 |
%}. |
|
2527 |
self primitiveFailed |
|
2528 |
||
2529 |
" |
|
2530 |
'hello' printfPrintString:'%%s -> %s' |
|
2531 |
'hello' printfPrintString:'%%10s -> %10s' |
|
2532 |
'hello' printfPrintString:'%%-10s -> %-10s' |
|
2533 |
" |
|
2534 |
! |
|
2535 |
||
2886 | 2536 |
storeOn:aStream |
608 | 2537 |
"put the storeString of myself on aStream" |
2538 |
||
2539 |
aStream nextPut: $'. |
|
2540 |
(self includes:$') ifTrue:[ |
|
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2541 |
self printWithQuotesDoubledOn:aStream |
608 | 2542 |
] ifFalse:[ |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
2543 |
aStream nextPutAll:self |
608 | 2544 |
]. |
2545 |
aStream nextPut:$' |
|
3579 | 2546 |
|
2547 |
"Modified: / 15.6.1998 / 17:21:51 / cg" |
|
608 | 2548 |
! |
2549 |
||
2886 | 2550 |
storeString |
2551 |
"return a String for storing myself" |
|
608 | 2552 |
|
2553 |
|s n index| |
|
2554 |
||
2555 |
n := self occurrencesOf:$'. |
|
2556 |
n == 0 ifFalse:[ |
|
2557 |
s := String new:(n + 2 + self size). |
|
2558 |
s at:1 put:$'. |
|
2559 |
index := 2. |
|
2560 |
self do:[:thisChar | |
|
2561 |
(thisChar == $') ifTrue:[ |
|
2562 |
s at:index put:thisChar. |
|
2563 |
index := index + 1. |
|
2564 |
]. |
|
2565 |
s at:index put:thisChar. |
|
2566 |
index := index + 1. |
|
2567 |
]. |
|
2568 |
s at:index put:$'. |
|
2569 |
^ s |
|
2570 |
]. |
|
2571 |
^ '''' , self , '''' |
|
1 | 2572 |
! ! |
2573 |
||
6588 | 2574 |
!String methodsFor:'public'! |
2575 |
||
2576 |
isBinarySelector |
|
2577 |
"Answer a <boolean>, true if the receiver contains only chars in an ANSI binary method selector, else false." |
|
2578 |
#'SysPro'. "2001/02/02 Harmon, R. A. Added System Protocols support." |
|
2579 |
||
2580 |
^self allSatisfy: [:chr| '!!%&''*+,`/<=>?@\~|-' includes: chr] |
|
2581 |
! |
|
2582 |
||
2583 |
isUnarySelector |
|
2584 |
"Answer a <boolean>, true if the receiver contains only chars in an ANSI unary method selector, else false." |
|
2585 |
#'SysPro'. "2001/02/02 Harmon, R. A. Added System Protocols support." |
|
2586 |
||
2587 |
^self allSatisfy: [ :chr | chr isLetter | chr isDigit] |
|
2588 |
! ! |
|
2589 |
||
1 | 2590 |
!String methodsFor:'queries'! |
2591 |
||
5557 | 2592 |
basicSize |
2593 |
"return the number of characters in myself. |
|
2594 |
Redefined here to exclude the 0-byte at the end." |
|
2595 |
||
2596 |
%{ /* NOCONTEXT */ |
|
2597 |
REGISTER OBJ slf, cls; |
|
2598 |
||
2599 |
slf = self; |
|
2600 |
||
2601 |
cls = __qClass(slf); |
|
2602 |
if (cls == String) { |
|
2603 |
RETURN ( __MKSMALLINT(__stringSize(slf)) ); |
|
2604 |
} |
|
2605 |
RETURN ( __MKSMALLINT(__stringSize(slf) |
|
2606 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
|
2607 |
%}. |
|
2608 |
^ super basicSize - 1 |
|
2609 |
||
2610 |
! |
|
2611 |
||
2886 | 2612 |
bitsPerCharacter |
1239 | 2613 |
"return the number of bits each character has. |
2614 |
Here, 8 is returned (storing single byte characters)." |
|
2615 |
||
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2616 |
^ 8 |
1239 | 2617 |
|
2618 |
"Modified: 20.4.1996 / 23:08:42 / cg" |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2619 |
! |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2620 |
|
2886 | 2621 |
knownAsSymbol |
2622 |
"return true, if there is a symbol with same characters in the |
|
2862 | 2623 |
system. |
2624 |
Can be used to check for existance of a symbol without creating one" |
|
608 | 2625 |
|
2626 |
%{ /* NOCONTEXT */ |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2627 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2628 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2629 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2630 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2631 |
if (cls != String) { |
5407 | 2632 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2633 |
} else { |
5407 | 2634 |
indx = 0; |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2635 |
} |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2636 |
RETURN ( __KNOWNASSYMBOL(__stringVal(self) + indx) ); |
5407 | 2637 |
%}. |
6007 | 2638 |
"/ ^ self asSymbolIfInterned notNil. |
5407 | 2639 |
self primitiveFailed |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2640 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2641 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2642 |
'hello' knownAsSymbol |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2643 |
'fooBarBaz' knownAsSymbol |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2644 |
" |
5557 | 2645 |
! |
2646 |
||
2647 |
size |
|
2648 |
"return the number of characters in myself. |
|
2649 |
Reimplemented here to avoid the additional size->basicSize send |
|
2650 |
(which we can do here, since size is obviously not redefined in a subclass). |
|
2651 |
This method is the same as basicSize." |
|
2652 |
||
2653 |
%{ /* NOCONTEXT */ |
|
2654 |
REGISTER OBJ cls, slf; |
|
2655 |
||
2656 |
slf = self; |
|
2657 |
cls = __qClass(slf); |
|
2658 |
if (cls == String) { |
|
2659 |
RETURN ( __MKSMALLINT(__stringSize(slf)) ); |
|
2660 |
} |
|
2661 |
RETURN ( __MKSMALLINT(__stringSize(slf) |
|
2662 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
|
2663 |
%}. |
|
2664 |
^ self basicSize |
|
1 | 2665 |
! ! |
608 | 2666 |
|
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 |
6828
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
3010 |
^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.173 2002-11-04 17:41:59 penk Exp $' |
633 | 3011 |
! ! |