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