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