author | Stefan Vogel <sv@exept.de> |
Sat, 26 Jun 2004 14:13:51 +0200 | |
changeset 8415 | 7e0f1105bc9f |
parent 8383 | dea5311899c5 |
child 8438 | 317f70e84d61 |
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 |
||
8205
045e07212c93
indexOfAny:StartingAt: bug fix (unsigned char needed)
Claus Gittinger <cg@exept.de>
parents:
8093
diff
changeset
|
992 |
for (ccp = matchP+1; *ccp ; ccp++) { |
045e07212c93
indexOfAny:StartingAt: bug fix (unsigned char needed)
Claus Gittinger <cg@exept.de>
parents:
8093
diff
changeset
|
993 |
unsigned char c = *ccp; |
8006 | 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 |
|
8205
045e07212c93
indexOfAny:StartingAt: bug fix (unsigned char needed)
Claus Gittinger <cg@exept.de>
parents:
8093
diff
changeset
|
1023 |
'hello world§' indexOfAny:'#§$' startingAt:6 |
516
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 |
! |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
1026 |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1027 |
indexOfControlCharacterStartingAt:start |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1028 |
"return the index of the next control character; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1029 |
that is a character with asciiValue < 32. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1030 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1031 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1032 |
%{ /* NOCONTEXT */ |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1033 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1034 |
#ifndef NON_ASCII /* i.e. not EBCDIC ;-) */ |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1035 |
REGISTER unsigned char *cp; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1036 |
REGISTER unsigned char c; |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
1037 |
REGISTER unsigned char *cpEnd; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1038 |
int len, index; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1039 |
OBJ cls; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1040 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1041 |
index = __intVal(start); |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1042 |
if (index <= 0) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1043 |
index = 1; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1044 |
} |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1045 |
if ((cls = __qClass(self)) != String) |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1046 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1047 |
len = __stringSize(self); |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
1048 |
cpEnd = __stringVal(self) + len; |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
1049 |
cp = __stringVal(self) + index - 1; |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
1050 |
if (cp < cpEnd) { |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1051 |
while (cp < cpEnd) { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1052 |
if (*cp++ < ' ') { |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1053 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
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 |
} |
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1056 |
RETURN ( __MKSMALLINT(0) ); |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1057 |
} |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1058 |
#endif |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1059 |
%}. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1060 |
^ super indexOfControlCharacterStartingAt:start |
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 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1063 |
'hello world' indexOfControlCharacterStartingAt:1 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1064 |
'hello world\foo' withCRs indexOfControlCharacterStartingAt:1 |
3734
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
1065 |
'1\' withCRs indexOfControlCharacterStartingAt:1 |
5d4e741062bd
may not finish search with 0-byte
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
1066 |
'1\' withCRs indexOfControlCharacterStartingAt:2 |
3668
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 |
! |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3651
diff
changeset
|
1069 |
|
3403 | 1070 |
indexOfNonSeparatorStartingAt:start |
1071 |
"return the index of the next non-whiteSpace character" |
|
1072 |
||
1073 |
%{ /* NOCONTEXT */ |
|
1074 |
||
1075 |
REGISTER unsigned char *cp; |
|
1076 |
REGISTER unsigned char c; |
|
1077 |
int len, index; |
|
1078 |
OBJ cls; |
|
1079 |
||
1080 |
index = __intVal(start); |
|
1081 |
if (index <= 0) { |
|
5407 | 1082 |
index = 1; |
3403 | 1083 |
} |
1084 |
if ((cls = __qClass(self)) != String) |
|
5407 | 1085 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3403 | 1086 |
len = __stringSize(self); |
1087 |
if (index > len) { |
|
5407 | 1088 |
RETURN ( __MKSMALLINT(0) ); |
3403 | 1089 |
} |
1090 |
cp = __stringVal(self) + index - 1; |
|
1091 |
while (c = *cp++) { |
|
1092 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
|
5407 | 1093 |
if (c > ' ') |
3403 | 1094 |
#endif |
5407 | 1095 |
if ((c != ' ') && (c != '\t') && (c != '\n') |
1096 |
&& (c != '\r') && (c != '\f')) { |
|
1097 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
|
1098 |
} |
|
3403 | 1099 |
} |
5407 | 1100 |
RETURN ( __MKSMALLINT(0) ); |
3403 | 1101 |
%}. |
5407 | 1102 |
^ super indexOfNonSeparatorStartingAt:start |
3403 | 1103 |
|
1104 |
" |
|
1105 |
'hello world' indexOfNonWhiteSpaceStartingAt:3 |
|
1106 |
'hello world' indexOfNonWhiteSpaceStartingAt:7 |
|
1107 |
" |
|
1108 |
! |
|
1109 |
||
1 | 1110 |
indexOfSeparatorStartingAt:start |
1111 |
"return the index of the next separator character" |
|
1112 |
||
1113 |
%{ /* NOCONTEXT */ |
|
1114 |
||
1115 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1116 |
REGISTER unsigned char c; |
1 | 1117 |
int len, index; |
53 | 1118 |
OBJ cls; |
1 | 1119 |
|
1134 | 1120 |
index = __intVal(start); |
1 | 1121 |
if (index <= 0) { |
5407 | 1122 |
index = 1; |
1 | 1123 |
} |
329 | 1124 |
if ((cls = __qClass(self)) != String) |
5407 | 1125 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1134 | 1126 |
len = __stringSize(self); |
1 | 1127 |
if (index > len) { |
5407 | 1128 |
RETURN ( __MKSMALLINT(0) ); |
1 | 1129 |
} |
1134 | 1130 |
cp = __stringVal(self) + index - 1; |
1 | 1131 |
while (c = *cp++) { |
329 | 1132 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
5407 | 1133 |
if (c <= ' ') |
1 | 1134 |
#endif |
5407 | 1135 |
if ((c == ' ') || (c == '\t') || (c == '\n') |
1136 |
|| (c == '\r') || (c == '\f')) { |
|
1137 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
|
1138 |
} |
|
1 | 1139 |
} |
5407 | 1140 |
RETURN ( __MKSMALLINT(0) ); |
1141 |
%}. |
|
1142 |
^ super indexOfSeparatorStartingAt:start |
|
53 | 1143 |
|
95 | 1144 |
" |
1145 |
'hello world' indexOfSeparatorStartingAt:3 |
|
1146 |
'hello world' indexOfSeparatorStartingAt:7 |
|
1147 |
" |
|
608 | 1148 |
! |
1149 |
||
1150 |
occurrencesOf:aCharacter |
|
1151 |
"count the occurrences of the argument, aCharacter in myself |
|
1152 |
- reimplemented here for speed" |
|
1153 |
||
1154 |
%{ /* NOCONTEXT */ |
|
1155 |
||
1156 |
REGISTER unsigned char *cp; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1157 |
REGISTER unsigned byteValue; |
6828
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
1158 |
REGISTER int count, limit; |
608 | 1159 |
OBJ cls; |
1160 |
||
1161 |
if (__isCharacter(aCharacter)) { |
|
6828
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
1162 |
limit = __stringSize(self); |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
1163 |
count = 0; |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
1164 |
byteValue = __intVal(_characterVal(aCharacter)); |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
1165 |
if (byteValue <= 0xFF) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
1166 |
cp = __stringVal(self); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
1167 |
if ((cls = __qClass(self)) != String) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
1168 |
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
|
1169 |
limit -= n; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
1170 |
cp += n; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
1171 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
1172 |
while (limit > 0) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
1173 |
limit--; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
1174 |
if (*cp++ == byteValue) count++; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
1175 |
} |
6828
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
1176 |
} |
f1725ea64ff1
fixed occurrencesOf: - no longer stop counting with 0-byte
penk
parents:
6766
diff
changeset
|
1177 |
RETURN ( __MKSMALLINT(count) ); |
608 | 1178 |
} |
1179 |
%}. |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
1180 |
^ super occurrencesOf:aCharacter |
608 | 1181 |
|
1182 |
" |
|
1183 |
'hello world' occurrencesOf:$a |
|
1184 |
'hello world' occurrencesOf:$w |
|
1185 |
'hello world' occurrencesOf:$l |
|
1186 |
'hello world' occurrencesOf:$x |
|
1187 |
'hello world' occurrencesOf:1 |
|
1188 |
" |
|
53 | 1189 |
! ! |
1190 |
||
608 | 1191 |
!String methodsFor:'comparing'! |
2 | 1192 |
|
8312 | 1193 |
< aString |
1194 |
"Compare the receiver with the argument and return true if the |
|
1195 |
receiver is greater than the argument. Otherwise return false. |
|
1196 |
No national variants are honored; use after: for this. |
|
1197 |
In contrast to ST-80, case differences are NOT ignored, thus |
|
1198 |
'foo' < 'Foo' will return false. |
|
1199 |
This may change." |
|
1200 |
||
1201 |
%{ /* NOCONTEXT */ |
|
1202 |
||
1203 |
int len1, len2, cmp; |
|
1204 |
REGISTER OBJ s = aString; |
|
1205 |
unsigned char *cp1, *cp2; |
|
1206 |
OBJ cls; |
|
1207 |
OBJ myCls; |
|
1208 |
||
1209 |
if (__isNonNilObject(s)) { |
|
1210 |
cls = __qClass(s); |
|
1211 |
myCls = __qClass(self); |
|
1212 |
||
1213 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
|
1214 |
cp2 = __stringVal(s); |
|
1215 |
len2 = __stringSize(s); |
|
1216 |
/* |
|
1217 |
* care for instances of subclasses ... |
|
1218 |
*/ |
|
1219 |
if (cls != String) { |
|
1220 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1221 |
||
1222 |
cp2 += n; |
|
1223 |
len2 -= n; |
|
1224 |
} |
|
1225 |
||
1226 |
cp1 = __stringVal(self); |
|
1227 |
len1 = __stringSize(self); |
|
1228 |
/* |
|
1229 |
* care for instances of subclasses ... |
|
1230 |
*/ |
|
1231 |
if (myCls != String) { |
|
1232 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
|
1233 |
||
1234 |
cp1 += n; |
|
1235 |
len1 -= n; |
|
1236 |
} |
|
1237 |
||
1238 |
if (len1 <= len2) |
|
1239 |
cmp = strncmp(cp1, cp2, len1); |
|
1240 |
else |
|
1241 |
cmp = strncmp(cp1, cp2, len2); |
|
1242 |
||
1243 |
if (cmp < 0) { |
|
1244 |
RETURN ( true ); |
|
1245 |
} |
|
1246 |
if ((cmp == 0) && (len1 < len2)) { |
|
1247 |
RETURN ( true ); |
|
1248 |
} |
|
1249 |
RETURN ( false ); |
|
1250 |
} |
|
1251 |
} |
|
1252 |
%}. |
|
1253 |
^ super < aString |
|
1254 |
! |
|
1255 |
||
608 | 1256 |
= aString |
1257 |
"Compare the receiver with the argument and return true if the |
|
1258 |
receiver is equal to the argument. Otherwise return false. |
|
1259 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
|
1260 |
Use sameAs: to compare with case ignored." |
|
1 | 1261 |
|
375 | 1262 |
%{ /* NOCONTEXT */ |
1263 |
||
608 | 1264 |
int l1, l2; |
1265 |
REGISTER OBJ s = aString; |
|
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1266 |
unsigned char *cp1, *cp2; |
608 | 1267 |
OBJ cls; |
3111 | 1268 |
OBJ myCls; |
3335 | 1269 |
INT addrDelta; |
608 | 1270 |
|
1271 |
if (s == self) { |
|
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1272 |
RETURN ( true ); |
608 | 1273 |
} |
1274 |
if (! __isNonNilObject(s)) { |
|
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1275 |
RETURN ( false ); |
608 | 1276 |
} |
1 | 1277 |
|
3111 | 1278 |
cls = __qClass(s); |
1279 |
myCls = __qClass(self); |
|
608 | 1280 |
|
7868 | 1281 |
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
|
1282 |
cp2 = __stringVal(s); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1283 |
l2 = __stringSize(s); |
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 |
* 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
|
1286 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1287 |
if (cls != String) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1288 |
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
|
1289 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1290 |
cp2 += n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1291 |
l2 -= n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1292 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1293 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1294 |
cp1 = __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1295 |
l1 = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1296 |
/* |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1297 |
* 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
|
1298 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1299 |
if (myCls != String) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1300 |
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
|
1301 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1302 |
cp1 += n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1303 |
l1 -= n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1304 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1305 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1306 |
if (l1 != l2) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1307 |
RETURN ( false ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1308 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1309 |
#ifdef FAST_MEMCMP |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1310 |
RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false ); |
3111 | 1311 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1312 |
addrDelta = cp2 - cp1; |
3989 | 1313 |
# ifdef UNROLL_LOOPS |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1314 |
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
|
1315 |
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
|
1316 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1317 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1318 |
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
|
1319 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1320 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1321 |
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
|
1322 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1323 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1324 |
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
|
1325 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1326 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1327 |
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
|
1328 |
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
|
1329 |
} |
3989 | 1330 |
# endif /* UNROLL_LOOPS */ |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1331 |
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
|
1332 |
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
|
1333 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1334 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1335 |
l1 -= sizeof(unsigned INT); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1336 |
cp1 += sizeof(unsigned INT); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1337 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1338 |
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
|
1339 |
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
|
1340 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1341 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1342 |
l1 -= sizeof(unsigned short); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1343 |
cp1 += sizeof(unsigned short); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1344 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1345 |
while (l1) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1346 |
if (*cp1 != *(cp1+addrDelta)) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1347 |
RETURN (false); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1348 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1349 |
l1--; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1350 |
cp1++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1351 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1352 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1353 |
RETURN (true); |
3111 | 1354 |
#endif |
1 | 1355 |
} |
3111 | 1356 |
%}. |
608 | 1357 |
^ super = aString |
1 | 1358 |
|
95 | 1359 |
" |
608 | 1360 |
'foo' = 'Foo' |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1361 |
'foo' sameAs: 'Foo' |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1362 |
#[0 0 1 0 0] asString = #[0 0 1 0 0] asString |
95 | 1363 |
" |
7868 | 1364 |
" |
1365 |
|tEmpty tCmp| |
|
1366 |
||
1367 |
tEmpty := Time millisecondsToRun:[ |
|
1368 |
1000000 timesRepeat:[] |
|
1369 |
]. |
|
1370 |
tCmp := Time millisecondsToRun:[ |
|
1371 |
1000000 timesRepeat:[ '1234567890' = '1234567890' ] |
|
1372 |
]. |
|
1373 |
tCmp - tEmpty |
|
1374 |
" |
|
1 | 1375 |
! |
1376 |
||
608 | 1377 |
> aString |
1378 |
"Compare the receiver with the argument and return true if the |
|
1379 |
receiver is greater than the argument. Otherwise return false. |
|
1380 |
No national variants are honored; use after: for this. |
|
1381 |
In contrast to ST-80, case differences are NOT ignored, thus |
|
1382 |
'foo' > 'Foo' will return true. |
|
1383 |
This may change." |
|
1 | 1384 |
|
375 | 1385 |
%{ /* NOCONTEXT */ |
1386 |
||
608 | 1387 |
int len1, len2, cmp; |
1388 |
REGISTER OBJ s = aString; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1389 |
unsigned char *cp1, *cp2; |
608 | 1390 |
OBJ cls; |
3111 | 1391 |
OBJ myCls; |
1 | 1392 |
|
3111 | 1393 |
if (__isNonNilObject(s)) { |
1394 |
cls = __qClass(s); |
|
1395 |
myCls = __qClass(self); |
|
608 | 1396 |
|
3111 | 1397 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
1398 |
cp2 = __stringVal(s); |
|
1399 |
len2 = __stringSize(s); |
|
1400 |
/* |
|
1401 |
* care for instances of subclasses ... |
|
1402 |
*/ |
|
1403 |
if (cls != String) { |
|
1404 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
608 | 1405 |
|
3111 | 1406 |
cp2 += n; |
1407 |
len2 -= n; |
|
1408 |
} |
|
375 | 1409 |
|
3111 | 1410 |
cp1 = __stringVal(self); |
1411 |
len1 = __stringSize(self); |
|
1412 |
/* |
|
1413 |
* care for instances of subclasses ... |
|
1414 |
*/ |
|
1415 |
if (myCls != String) { |
|
1416 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
|
608 | 1417 |
|
3111 | 1418 |
cp1 += n; |
1419 |
len1 -= n; |
|
1420 |
} |
|
608 | 1421 |
|
3111 | 1422 |
if (len1 <= len2) |
1423 |
cmp = strncmp(cp1, cp2, len1); |
|
1424 |
else |
|
1425 |
cmp = strncmp(cp1, cp2, len2); |
|
608 | 1426 |
|
3111 | 1427 |
if (cmp > 0) { |
1428 |
RETURN ( true ); |
|
1429 |
} |
|
1430 |
if ((cmp == 0) && (len1 > len2)) { |
|
1431 |
RETURN ( true ); |
|
1432 |
} |
|
1433 |
RETURN ( false ); |
|
1434 |
} |
|
1 | 1435 |
} |
370 | 1436 |
%}. |
608 | 1437 |
^ super > aString |
1438 |
! |
|
1 | 1439 |
|
608 | 1440 |
after:aString |
1441 |
"Compare the receiver with the argument and return true if the |
|
1442 |
receiver should come after the argument in a sorted list. |
|
1443 |
Otherwise return false. |
|
1444 |
The comparison is language specific, depending on the value of |
|
1368 | 1445 |
LC_COLLATE, which is initialized from the environment. |
1446 |
||
1447 |
STUPID: |
|
1486 | 1448 |
#after has a completely different meaning in SeqColl ..." |
1 | 1449 |
|
1251 | 1450 |
^ (self compareCollatingWith:aString) > 0 |
1451 |
||
1368 | 1452 |
"Modified: 10.5.1996 / 14:02:45 / cg" |
1251 | 1453 |
! |
1454 |
||
1455 |
compareCollatingWith:aString |
|
1456 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
1457 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
1458 |
The comparison is language specific, depending on the value of |
|
1459 |
LC_COLLATE, which is in the shell environment." |
|
1460 |
||
1 | 1461 |
%{ /* NOCONTEXT */ |
1462 |
||
608 | 1463 |
int cmp; |
1464 |
REGISTER OBJ s = aString; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
1465 |
unsigned char *cp1, *cp2; |
53 | 1466 |
OBJ cls; |
3111 | 1467 |
OBJ myCls; |
608 | 1468 |
|
3111 | 1469 |
if (__isNonNilObject(s)) { |
1470 |
cls = __qClass(s); |
|
1471 |
myCls = __qClass(self); |
|
1472 |
||
1473 |
if ((cls == String) || (cls == Symbol) || (cls == myCls)) { |
|
1474 |
cp1 = __stringVal(self); |
|
608 | 1475 |
|
3111 | 1476 |
/* |
1477 |
* care for instances of subclasses ... |
|
1478 |
*/ |
|
1479 |
if (myCls != String) { |
|
1480 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)); |
|
1481 |
||
1482 |
cp1 += n; |
|
1483 |
} |
|
1 | 1484 |
|
3111 | 1485 |
cp2 = __stringVal(s); |
1486 |
/* |
|
1487 |
* care for instances of subclasses ... |
|
1488 |
*/ |
|
1489 |
if (cls != String) { |
|
1490 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
608 | 1491 |
|
3111 | 1492 |
cp2 += n; |
1493 |
} |
|
608 | 1494 |
|
1495 |
#ifdef HAS_STRCOLL |
|
3111 | 1496 |
cmp = strcoll(cp1, cp2); |
608 | 1497 |
#else |
3111 | 1498 |
cmp = strcmp(cp1, cp2); |
608 | 1499 |
#endif |
1500 |
||
3111 | 1501 |
if (cmp > 0) { |
1502 |
RETURN ( __MKSMALLINT(1) ); |
|
1503 |
} |
|
1504 |
if (cmp < 0) { |
|
1505 |
RETURN ( __MKSMALLINT(-1) ); |
|
1506 |
} |
|
1507 |
RETURN ( __MKSMALLINT(0) ); |
|
1508 |
} |
|
370 | 1509 |
} |
329 | 1510 |
%}. |
608 | 1511 |
" |
1512 |
currently, this operation is only defined for strings, symbols |
|
1513 |
and subclasses. |
|
1514 |
" |
|
1251 | 1515 |
^ self primitiveFailed |
1 | 1516 |
! |
1517 |
||
608 | 1518 |
~= aString |
1519 |
"Compare the receiver with the argument and return true if the |
|
1520 |
receiver is not equal to the argument. Otherwise return false. |
|
3111 | 1521 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
1522 |
Actually, there is no need to redefine that method here, |
|
1523 |
the default (= not as inherited) works ok. |
|
1524 |
However, this may be heavily used and the redefinition saves an |
|
1525 |
extra message send." |
|
1 | 1526 |
|
608 | 1527 |
%{ /* NOCONTEXT */ |
1528 |
||
1 | 1529 |
int l1, l2; |
608 | 1530 |
REGISTER OBJ s = aString; |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
1531 |
unsigned char *cp1, *cp2; |
3111 | 1532 |
OBJ cls, myCls; |
3335 | 1533 |
INT addrDelta; |
1 | 1534 |
|
608 | 1535 |
if (s == self) { |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1536 |
RETURN ( false ); |
608 | 1537 |
} |
1538 |
if (! __isNonNilObject(s)) { |
|
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1539 |
RETURN ( true ); |
608 | 1540 |
} |
3111 | 1541 |
|
1542 |
cls = __qClass(s); |
|
1543 |
myCls = __qClass(self); |
|
1544 |
||
1545 |
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
|
1546 |
cp1 = __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1547 |
l1 = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1548 |
/* |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1549 |
* 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
|
1550 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1551 |
if (myCls != String) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1552 |
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
|
1553 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1554 |
cp1 += n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1555 |
l1 -= n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1556 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1557 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1558 |
cp2 = __stringVal(s); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1559 |
l2 = __stringSize(s); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1560 |
/* |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1561 |
* 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
|
1562 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1563 |
if (cls != String) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1564 |
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
|
1565 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1566 |
cp2 += n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1567 |
l2 -= n; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1568 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1569 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1570 |
if (l1 != l2) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1571 |
RETURN ( true ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1572 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1573 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1574 |
addrDelta = cp2 - cp1; |
3989 | 1575 |
# ifdef UNROLL_LOOPS |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1576 |
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
|
1577 |
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
|
1578 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1579 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1580 |
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
|
1581 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1582 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1583 |
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
|
1584 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1585 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1586 |
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
|
1587 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1588 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1589 |
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
|
1590 |
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
|
1591 |
} |
3989 | 1592 |
# endif /* UNROLL_LOOPS */ |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1593 |
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
|
1594 |
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
|
1595 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1596 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1597 |
l1 -= sizeof(unsigned INT); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1598 |
cp1 += sizeof(unsigned INT); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1599 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1600 |
if (l1 >= sizeof(unsigned short)) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1601 |
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
|
1602 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1603 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1604 |
l1 -= sizeof(unsigned short); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1605 |
cp1 += sizeof(unsigned short); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1606 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1607 |
while (l1) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1608 |
if (*cp1 != *(cp1+addrDelta)) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1609 |
RETURN (true); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1610 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1611 |
l1--; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1612 |
cp1++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1613 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1614 |
RETURN (false); |
608 | 1615 |
} |
3111 | 1616 |
%}. |
608 | 1617 |
^ super ~= aString |
1618 |
! ! |
|
1619 |
||
1620 |
!String methodsFor:'converting'! |
|
1621 |
||
6830 | 1622 |
asArrayOfSubstrings |
1623 |
"Answer an array with all the substrings of the receiver separated by |
|
1624 |
separator characters (space, cr, tab, linefeed, formfeed, etc)." |
|
1625 |
||
1626 |
| substrings start end | |
|
1627 |
substrings _ OrderedCollection new. |
|
1628 |
start _ 1. |
|
1629 |
[start <= self size] whileTrue: [ |
|
1630 |
(self at: start) isSeparator ifFalse: [ |
|
1631 |
end _ start + 1. |
|
1632 |
[end <= self size and: [(self at: end) isSeparator not]] |
|
1633 |
whileTrue: [end _ end + 1]. |
|
1634 |
substrings add: (self copyFrom: start to: end - 1). |
|
1635 |
start _ end - 1]. |
|
1636 |
start _ start + 1]. |
|
1637 |
^ substrings asArray |
|
1638 |
! |
|
1639 |
||
3281
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1640 |
asBoldText |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1641 |
"return self as a bold text" |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1642 |
|
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1643 |
^Text string: self emphasis: #bold |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1644 |
! |
d108dee000f7
#asBoldText added for often used bold texts in dialogs, etc.
tz
parents:
3234
diff
changeset
|
1645 |
|
7877
bef56f06d2f8
asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents:
7869
diff
changeset
|
1646 |
asSingleByteString |
5760 | 1647 |
"I am a string" |
1648 |
||
1649 |
^ self |
|
1650 |
! |
|
1651 |
||
7878 | 1652 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
1653 |
"I am a string" |
|
1654 |
||
1655 |
^ self |
|
1656 |
! |
|
1657 |
||
2856 | 1658 |
asString |
1659 |
"I am a string" |
|
1660 |
||
1661 |
^ self |
|
1662 |
||
1663 |
"Created: 14.8.1997 / 11:37:03 / stefan" |
|
1664 |
! |
|
1665 |
||
608 | 1666 |
asSymbol |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1667 |
"return a unique symbol with the name taken from my characters." |
7869 | 1668 |
|
1669 |
%{ /* NOCONTEXT */ |
|
608 | 1670 |
OBJ newSymbol; |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1671 |
OBJ cls; |
7869 | 1672 |
char *cp = __stringVal(self); |
1673 |
||
1674 |
/* care for instances of a subclass with instVars */ |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1675 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1676 |
if (cls != String) { |
7869 | 1677 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1678 |
} |
7869 | 1679 |
newSymbol = __MKSYMBOL(cp, (OBJ *)0); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1680 |
if (newSymbol) { |
7869 | 1681 |
RETURN ( newSymbol); |
608 | 1682 |
} |
1683 |
%}. |
|
1684 |
^ ObjectMemory allocationFailureSignal raise. |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1685 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1686 |
" |
7869 | 1687 |
'hello' asSymbol |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1688 |
" |
608 | 1689 |
! |
1690 |
||
1691 |
asSymbolIfInterned |
|
1692 |
"if a symbol with the receivers characters is already known, return it. |
|
1693 |
Otherwise, return nil. This can be used to query for an existing |
|
1694 |
symbol and is the same as |
|
5407 | 1695 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
608 | 1696 |
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
|
1697 |
performed once." |
1 | 1698 |
|
608 | 1699 |
%{ /* NOCONTEXT */ |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1700 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1701 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1702 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1703 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1704 |
if (cls != String) { |
5407 | 1705 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1706 |
} else { |
5407 | 1707 |
indx = 0; |
608 | 1708 |
} |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1709 |
RETURN ( __SYMBOL_OR_NIL(__stringVal(self) + indx)); |
5407 | 1710 |
%}. |
1711 |
self primitiveFailed |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1712 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1713 |
'hello' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1714 |
'fooBarBaz' asSymbolIfInterned |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
1715 |
" |
608 | 1716 |
! |
1717 |
||
2416 | 1718 |
decodeAsLiteralArray |
1719 |
"given a literalEncoding in the receiver, |
|
1720 |
create & return the corresponding object. |
|
1721 |
The inverse operation to #literalArrayEncoding." |
|
1722 |
||
1723 |
^ self |
|
1724 |
||
1725 |
"Created: 25.2.1997 / 19:18:19 / cg" |
|
1726 |
! |
|
1727 |
||
608 | 1728 |
literalArrayEncoding |
1246 | 1729 |
"encode myself as an array literal, from which a copy of the receiver |
1730 |
can be reconstructed with #decodeAsLiteralArray." |
|
608 | 1731 |
|
1732 |
^ self |
|
1733 |
||
1734 |
"Modified: 1.9.1995 / 02:25:45 / claus" |
|
1246 | 1735 |
"Modified: 22.4.1996 / 13:00:50 / cg" |
608 | 1736 |
! |
1737 |
||
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1738 |
withTabsExpanded:numSpaces |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1739 |
"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
|
1740 |
are expanded into spaces (assuming numSpaces-col tabs). |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1741 |
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
|
1742 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1743 |
This does handle multiline strings. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1744 |
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
|
1745 |
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
|
1746 |
|
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
1747 |
%{ /* STACK:700 */ |
2894 | 1748 |
unsigned char buffer[80*8 + 10]; |
1749 |
unsigned char *srcP, *dstP, *cp0; |
|
608 | 1750 |
int idx, sz; |
1751 |
int any = 0; |
|
1752 |
OBJ newString; |
|
1753 |
char c; |
|
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1754 |
int n; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1755 |
|
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1756 |
if ((__qClass(self) == String) |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1757 |
&& __isSmallInteger(numSpaces)) { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1758 |
n = __intVal(numSpaces); |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1759 |
|
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1760 |
/* |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1761 |
* 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
|
1762 |
* 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
|
1763 |
* 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
|
1764 |
*/ |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1765 |
if (__stringSize(self) < 80) { |
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 = buffer; (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 |
any = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1770 |
while (idx % n) { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1771 |
idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1772 |
*dstP++ = ' '; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1773 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1774 |
idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1775 |
*dstP++ = ' '; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1776 |
} else { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1777 |
*dstP++ = c; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1778 |
idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1779 |
if (c == '\n') { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1780 |
idx = 1; |
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 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1783 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1784 |
if (! any) RETURN(self); |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1785 |
*dstP = '\0'; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1786 |
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
|
1787 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1788 |
/* |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1789 |
* 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
|
1790 |
* and expand it. |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1791 |
* |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1792 |
* first, scan for size ... |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1793 |
*/ |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1794 |
idx = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1795 |
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
|
1796 |
if (c == '\t') { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1797 |
any = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1798 |
while (idx % n) { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1799 |
idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1800 |
sz++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1801 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1802 |
idx++; sz ++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1803 |
} else { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1804 |
sz++; idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1805 |
if (c == '\n') { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1806 |
idx = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1807 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1808 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1809 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1810 |
if (! any) RETURN(self); |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1811 |
|
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1812 |
/* |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1813 |
* get the string |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1814 |
*/ |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1815 |
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
|
1816 |
__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
|
1817 |
if (newString != nil) { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1818 |
__InstPtr(newString)->o_class = String; |
7856
a5758a9e6248
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7774
diff
changeset
|
1819 |
__qSTORE(newString, String); |
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1820 |
|
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1821 |
/* |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1822 |
* expand |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1823 |
*/ |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1824 |
idx = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1825 |
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
|
1826 |
if (c == '\t') { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1827 |
while (idx % n) { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1828 |
idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1829 |
*dstP++ = ' '; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1830 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1831 |
idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1832 |
*dstP++ = ' '; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1833 |
} else { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1834 |
*dstP++ = c; idx++; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1835 |
if (c == '\n') { |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1836 |
idx = 1; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1837 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1838 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1839 |
} |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1840 |
*dstP++ = '\0'; |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1841 |
RETURN (newString); |
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1842 |
} |
608 | 1843 |
} |
1844 |
%}. |
|
5742
7c02fc4de0ae
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5710
diff
changeset
|
1845 |
^ super withTabsExpanded:numSpaces |
1 | 1846 |
! ! |
1847 |
||
1848 |
!String methodsFor:'copying'! |
|
1849 |
||
1850 |
, aString |
|
2 | 1851 |
"return the concatenation of myself and the argument, aString as |
1852 |
a String. |
|
1 | 1853 |
- reimplemented here for speed" |
1854 |
||
1855 |
%{ |
|
95 | 1856 |
int l1, l2, sz; |
1 | 1857 |
REGISTER OBJ s = aString; |
329 | 1858 |
REGISTER OBJ _string = String; |
13 | 1859 |
OBJ myClass, argClass, newString; |
1 | 1860 |
|
329 | 1861 |
if (__isNonNilObject(s)) { |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1862 |
myClass = __qClass(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1863 |
argClass = __qClass(s); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1864 |
/* |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1865 |
* 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
|
1866 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1867 |
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
|
1868 |
&& ((argClass == _string) || (argClass == Symbol))) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1869 |
l1 = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1870 |
l2 = __stringSize(s); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1871 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1872 |
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
|
1873 |
__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
|
1874 |
if (newString != nil) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1875 |
char *cp1, *cp2; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1876 |
REGISTER unsigned char *dstp; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1877 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1878 |
__InstPtr(newString)->o_class = String; |
7856
a5758a9e6248
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7774
diff
changeset
|
1879 |
__qSTORE(newString, String); |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1880 |
dstp = __stringVal(newString); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1881 |
cp1 = (char *) __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1882 |
cp2 = (char *) __stringVal(aString); |
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1883 |
|
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1884 |
#ifdef bcopy4 |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1885 |
/* 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
|
1886 |
* 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
|
1887 |
* 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
|
1888 |
* 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
|
1889 |
* 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
|
1890 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1891 |
{ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1892 |
int nw = l1 >> 2; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1893 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1894 |
if (l1 & 3) nw++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1895 |
bcopy4(cp1, dstp, nw); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1896 |
dstp += l1; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1897 |
} |
3673 | 1898 |
#else |
1899 |
# ifdef FAST_MEMCPY |
|
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1900 |
memcpy(dstp, cp1, l1); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1901 |
dstp += l1; |
3673 | 1902 |
# else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1903 |
while (l1 >= 4) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1904 |
*(int *)dstp = *(int *)cp1; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1905 |
dstp += 4; cp1 += 4; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1906 |
l1 -= 4; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1907 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1908 |
while (l1--) *dstp++ = *cp1++; |
3673 | 1909 |
# endif |
3651
265d1c30eff5
tuned comma (concatenation) for i386.
Claus Gittinger <cg@exept.de>
parents:
3579
diff
changeset
|
1910 |
#endif |
2862 | 1911 |
|
3673 | 1912 |
#ifdef bcopy4 |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1913 |
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
|
1914 |
int nw = l2 >> 2; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1915 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1916 |
if (l2 & 3) nw++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1917 |
bcopy4(cp2, dstp, nw); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1918 |
*(dstp + l2) = '\0'; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1919 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1920 |
} |
3673 | 1921 |
#endif |
4205
56d69caa8f92
threadsafe printf-defines now in ntIntern.h
Claus Gittinger <cg@exept.de>
parents:
4154
diff
changeset
|
1922 |
|
1 | 1923 |
#ifdef FAST_MEMCPY |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1924 |
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
|
1925 |
dstp[l2] = '\0'; |
1 | 1926 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1927 |
while (l2--) *dstp++ = *cp2++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1928 |
*dstp = '\0'; |
1 | 1929 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1930 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1931 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1932 |
} |
1 | 1933 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1934 |
%}. |
1 | 1935 |
^ super , aString |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1936 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1937 |
" |
7867 | 1938 |
'hello' , 'world' |
1939 |
#[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
|
1940 |
" |
1 | 1941 |
! |
1942 |
||
1943 |
concatenate:string1 and:string2 |
|
1944 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
1945 |
This is equivalent to self , string1 , string2 |
|
1946 |
- generated by compiler when such a construct is detected" |
|
1947 |
||
1948 |
|newString| |
|
2862 | 1949 |
|
1 | 1950 |
%{ |
95 | 1951 |
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
|
1952 |
#if !defined(FAST_MEMCPY) |
1 | 1953 |
REGISTER unsigned char *srcp; |
1954 |
#endif |
|
1955 |
REGISTER unsigned char *dstp; |
|
1956 |
||
53 | 1957 |
if ((__isString(self) || __isSymbol(self)) |
1958 |
&& (__isString(string1) || __isSymbol(string1)) |
|
1959 |
&& (__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
|
1960 |
len1 = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1961 |
len2 = __stringSize(string1); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1962 |
len3 = __stringSize(string2); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1963 |
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
|
1964 |
__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
|
1965 |
if (newString != nil) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1966 |
__InstPtr(newString)->o_class = String; |
7856
a5758a9e6248
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7774
diff
changeset
|
1967 |
__qSTORE(newString, String); |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1968 |
dstp = __stringVal(newString); |
1 | 1969 |
#ifdef FAST_MEMCPY |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1970 |
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
|
1971 |
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
|
1972 |
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
|
1973 |
*(dstp + len1 + len2 + len3) = '\0'; |
1 | 1974 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1975 |
srcp = __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1976 |
while (len1--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1977 |
srcp = __stringVal(string1); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1978 |
while (len2--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1979 |
srcp = __stringVal(string2); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1980 |
while (len3--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1981 |
*dstp = '\0'; |
1 | 1982 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1983 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
1984 |
} |
1 | 1985 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1986 |
%}. |
1 | 1987 |
^ super , string1 , string2 |
1988 |
! |
|
1989 |
||
1990 |
concatenate:string1 and:string2 and:string3 |
|
1991 |
"return the concatenation of myself and the string arguments. |
|
1992 |
This is equivalent to self , string1 , string2 , string3 |
|
1993 |
- generated by compiler when such a construct is detected" |
|
1994 |
||
1995 |
|newString| |
|
2862 | 1996 |
|
1 | 1997 |
%{ |
95 | 1998 |
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
|
1999 |
#if !defined(FAST_MEMCPY) |
1 | 2000 |
REGISTER unsigned char *srcp; |
2001 |
#endif |
|
2002 |
REGISTER unsigned char *dstp; |
|
2003 |
||
53 | 2004 |
if ((__isString(self) || __isSymbol(self)) |
2005 |
&& (__isString(string1) || __isSymbol(string1)) |
|
2006 |
&& (__isString(string2) || __isSymbol(string2)) |
|
2007 |
&& (__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
|
2008 |
len1 = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2009 |
len2 = __stringSize(string1); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2010 |
len3 = __stringSize(string2); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2011 |
len4 = __stringSize(string3); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2012 |
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
|
2013 |
__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
|
2014 |
if (newString != nil) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2015 |
__InstPtr(newString)->o_class = String; |
7856
a5758a9e6248
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7774
diff
changeset
|
2016 |
__qSTORE(newString, String); |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2017 |
dstp = __stringVal(newString); |
1 | 2018 |
#ifdef FAST_MEMCPY |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2019 |
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
|
2020 |
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
|
2021 |
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
|
2022 |
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
|
2023 |
*(dstp + len1 + len2 + len3 + len4) = '\0'; |
1 | 2024 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2025 |
srcp = __stringVal(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2026 |
while (len1--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2027 |
srcp = __stringVal(string1); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2028 |
while (len2--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2029 |
srcp = __stringVal(string2); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2030 |
while (len3--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2031 |
srcp = __stringVal(string3); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2032 |
while (len4--) *dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2033 |
*dstp = '\0'; |
1 | 2034 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2035 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2036 |
} |
1 | 2037 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
2038 |
%}. |
1 | 2039 |
^ super , string1 , string2 , string3 |
2040 |
! |
|
2041 |
||
4745 | 2042 |
copy |
2043 |
"return a copy of the receiver" |
|
2044 |
||
2045 |
(self isMemberOf:String) ifTrue:[ |
|
2046 |
^ self copyFrom:1 |
|
2047 |
]. |
|
2048 |
^ super copy |
|
2049 |
! |
|
2050 |
||
608 | 2051 |
copyFrom:start |
2052 |
"return the substring from start, anInteger to the end. |
|
2053 |
This method will always return a string, even if the receiver |
|
2054 |
is a subclass-instance. This might change if there is a need. |
|
2055 |
- reimplemented here for speed" |
|
1 | 2056 |
|
13 | 2057 |
%{ /* NOCONTEXT */ |
1 | 2058 |
|
608 | 2059 |
#if !defined(FAST_MEMCPY) |
2060 |
REGISTER unsigned char *srcp; |
|
2061 |
#endif |
|
1 | 2062 |
REGISTER unsigned char *dstp; |
608 | 2063 |
REGISTER int count; |
2064 |
int len, index1, sz; |
|
2065 |
OBJ newString; |
|
2862 | 2066 |
OBJ myClass; |
608 | 2067 |
|
2862 | 2068 |
myClass = __qClass(self); |
2069 |
||
2894 | 2070 |
#ifndef NO_PRIM_STRING |
2862 | 2071 |
if (__isSmallInteger(start) |
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 |
if (index1 > 0) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2076 |
if (index1 <= len) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2077 |
count = len - index1 + 1; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2078 |
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
|
2079 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2080 |
__PROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2081 |
__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
|
2082 |
__UNPROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2083 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2084 |
if (newString != nil) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2085 |
__InstPtr(newString)->o_class = String; |
7856
a5758a9e6248
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7774
diff
changeset
|
2086 |
__qSTORE(newString, String); |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2087 |
dstp = __stringVal(newString); |
1 | 2088 |
#ifdef FAST_MEMCPY |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2089 |
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
|
2090 |
dstp[count] = '\0'; |
1 | 2091 |
#else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2092 |
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
|
2093 |
while (count--) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2094 |
*dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2095 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2096 |
*dstp = '\0'; |
1 | 2097 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2098 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2099 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2100 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2101 |
} |
13 | 2102 |
} |
2894 | 2103 |
#endif |
51 | 2104 |
%}. |
608 | 2105 |
"fall back in case of non-integer index or out-of-bound index; |
2106 |
will eventually lead to an out-of-bound signal raise" |
|
51 | 2107 |
|
608 | 2108 |
^ super copyFrom:start |
1 | 2109 |
! |
2110 |
||
2111 |
copyFrom:start to:stop |
|
2112 |
"return the substring starting at index start, anInteger and ending |
|
53 | 2113 |
at stop, anInteger. This method will always return a string, even |
2114 |
if the receiver is a subclass-instance. This might change if there is a need. |
|
1 | 2115 |
- reimplemented here for speed" |
2116 |
||
13 | 2117 |
%{ /* NOCONTEXT */ |
2118 |
||
1 | 2119 |
REGISTER unsigned char *srcp; |
2120 |
REGISTER unsigned char *dstp; |
|
2121 |
REGISTER int count; |
|
95 | 2122 |
int len, sz, index1, index2; |
13 | 2123 |
OBJ newString; |
2862 | 2124 |
OBJ myClass; |
1 | 2125 |
|
2862 | 2126 |
myClass = __qClass(self); |
2127 |
||
2894 | 2128 |
#ifndef NO_PRIM_STRING |
2862 | 2129 |
if (__bothSmallInteger(start, stop) |
2130 |
&& ((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
|
2131 |
len = __stringSize(self); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2132 |
index1 = __intVal(start); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2133 |
index2 = __intVal(stop); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2134 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2135 |
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
|
2136 |
if (index2 <= len) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2137 |
count = index2 - index1 + 1; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2138 |
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
|
2139 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2140 |
__PROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2141 |
__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
|
2142 |
__UNPROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2143 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2144 |
if (newString != nil) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2145 |
__InstPtr(newString)->o_class = String; |
7856
a5758a9e6248
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7774
diff
changeset
|
2146 |
__qSTORE(newString, String); |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2147 |
dstp = __stringVal(newString); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2148 |
srcp = __stringVal(self) + index1 - 1; |
2894 | 2149 |
#ifdef bcopy4 |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2150 |
{ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2151 |
int nw = count >> 2; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2152 |
|
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2153 |
if (count & 3) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2154 |
nw++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2155 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2156 |
bcopy4(srcp, dstp, nw); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2157 |
dstp[count] = '\0'; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2158 |
} |
1 | 2159 |
#else |
2894 | 2160 |
# ifdef FAST_MEMCPY |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2161 |
memcpy(dstp, srcp, count); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2162 |
dstp[count] = '\0'; |
209 | 2163 |
# else |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2164 |
while (count--) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2165 |
*dstp++ = *srcp++; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2166 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2167 |
*dstp = '\0'; |
209 | 2168 |
# endif |
13 | 2169 |
#endif |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2170 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2171 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2172 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2173 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2174 |
/* |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2175 |
* allow empty copy |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2176 |
*/ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2177 |
if (index1 > index2) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2178 |
__PROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2179 |
__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
|
2180 |
__UNPROTECT_CONTEXT__ |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2181 |
if (newString != nil) { |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2182 |
__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
|
2183 |
(__stringVal(newString))[0] = '\0'; |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2184 |
RETURN ( newString ); |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2185 |
} |
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2186 |
} |
1 | 2187 |
} |
2894 | 2188 |
#endif |
51 | 2189 |
%}. |
2190 |
"fall back in case of non-integer index or out-of-bound index; |
|
2191 |
will eventually lead to an out-of-bound signal raise" |
|
2192 |
||
1 | 2193 |
^ super copyFrom:start to:stop |
2194 |
! |
|
2195 |
||
608 | 2196 |
copyWith:aCharacter |
2197 |
"return a new string containing the receivers characters |
|
2198 |
and the single new character, aCharacter. |
|
2199 |
This is different from concatentation, which expects another string |
|
2200 |
as argument, but equivalent to copy-and-addLast. |
|
2201 |
Reimplemented here for more speed" |
|
2202 |
||
2203 |
%{ /* NOCONTEXT */ |
|
2204 |
||
2887 | 2205 |
int count; |
608 | 2206 |
int sz; |
2207 |
REGISTER unsigned char *dstp; |
|
2208 |
OBJ cls, newString; |
|
2862 | 2209 |
OBJ myClass; |
608 | 2210 |
|
2862 | 2211 |
myClass = __qClass(self); |
2212 |
||
2894 | 2213 |
#ifndef NO_PRIM_STRING |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2214 |
if (__isCharacter(aCharacter)) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2215 |
unsigned int cVal = __intVal(__characterVal(aCharacter)); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2216 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2217 |
if ((cVal <= 0xFF) |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2218 |
&& ((myClass==String) || (myClass==Symbol))) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2219 |
count = __stringSize(self); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2220 |
sz = OHDR_SIZE + count + 1 + 1; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2221 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2222 |
__PROTECT_CONTEXT__ |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2223 |
__qNew(newString, sz); /* OBJECT ALLOCATION */ |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2224 |
__UNPROTECT_CONTEXT__ |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2225 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2226 |
if (newString) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2227 |
__InstPtr(newString)->o_class = String; |
7856
a5758a9e6248
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7774
diff
changeset
|
2228 |
__qSTORE(newString, String); |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2229 |
dstp = __stringVal(newString); |
2862 | 2230 |
|
2887 | 2231 |
#ifdef bcopy4 |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2232 |
{ |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2233 |
int nw = count >> 2; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2234 |
char *srcp = (char *)__stringVal(self); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2235 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2236 |
if (count & 3) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2237 |
nw++; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2238 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2239 |
bcopy4(srcp, dstp, nw); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2240 |
dstp += count; |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2241 |
} |
608 | 2242 |
#else |
2887 | 2243 |
# ifdef FAST_MEMCPY |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2244 |
memcpy(dstp, __stringVal(self), count); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2245 |
dstp += count; |
608 | 2246 |
# else |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2247 |
{ |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2248 |
REGISTER unsigned char *srcp; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2249 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2250 |
srcp = __stringVal(self); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2251 |
while ((*dstp = *srcp++) != '\0') |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2252 |
dstp++; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2253 |
} |
608 | 2254 |
# endif |
2887 | 2255 |
# endif |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2256 |
*dstp++ = cVal; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2257 |
*dstp = '\0'; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2258 |
RETURN (newString ); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2259 |
} |
6331
3cb5595cf170
Strings do not treat 0-bytes as end of string.
Stefan Vogel <sv@exept.de>
parents:
6007
diff
changeset
|
2260 |
} |
608 | 2261 |
} |
2894 | 2262 |
#endif |
608 | 2263 |
%}. |
2264 |
"fall back in case of non-character arg; |
|
2265 |
will eventually lead to an bad element signal raise" |
|
2266 |
||
2267 |
^ super copyWith:aCharacter |
|
2268 |
! |
|
2269 |
||
2886 | 2270 |
deepCopy |
2271 |
"return a copy of the receiver" |
|
608 | 2272 |
|
2273 |
" |
|
2274 |
could be an instance of a subclass which needs deepCopy |
|
2275 |
of its named instvars ... |
|
2276 |
" |
|
2277 |
(self isMemberOf:String) ifTrue:[ |
|
2278 |
^ self copyFrom:1 |
|
2279 |
]. |
|
2280 |
^ super deepCopy |
|
2281 |
! |
|
2282 |
||
2886 | 2283 |
deepCopyUsing:aDictionary |
8383 | 2284 |
"return a deep copy of the receiver - reimplemented to be a bit faster" |
608 | 2285 |
|
2286 |
" |
|
2287 |
could be an instance of a subclass which needs deepCopy |
|
2288 |
of its named instvars ... |
|
2289 |
" |
|
2290 |
(self isMemberOf:String) ifTrue:[ |
|
7881 | 2291 |
^ self copyFrom:1 |
608 | 2292 |
]. |
7881 | 2293 |
^ super deepCopyUsing:aDictionary |
608 | 2294 |
! |
2295 |
||
2886 | 2296 |
shallowCopy |
2297 |
"return a copy of the receiver" |
|
608 | 2298 |
|
2299 |
(self isMemberOf:String) ifTrue:[ |
|
2300 |
^ self copyFrom:1 |
|
2301 |
]. |
|
2302 |
^ super shallowCopy |
|
2303 |
! |
|
2304 |
||
2886 | 2305 |
simpleDeepCopy |
2306 |
"return a copy of the receiver" |
|
608 | 2307 |
|
2308 |
" |
|
2309 |
could be an instance of a subclass which needs deepCopy |
|
2310 |
of its named instvars ... |
|
2311 |
" |
|
2312 |
(self isMemberOf:String) ifTrue:[ |
|
7881 | 2313 |
^ self copyFrom:1 |
608 | 2314 |
]. |
7881 | 2315 |
^ super simpleDeepCopy |
608 | 2316 |
! ! |
2317 |
||
4154 | 2318 |
!String methodsFor:'filling & replacing'! |
608 | 2319 |
|
2886 | 2320 |
atAllPut:aCharacter |
608 | 2321 |
"replace all elements with aCharacter |
1 | 2322 |
- reimplemented here for speed" |
2323 |
||
13 | 2324 |
%{ /* NOCONTEXT */ |
2325 |
||
608 | 2326 |
#ifndef FAST_MEMSET |
2327 |
REGISTER unsigned char *dst; |
|
6766
a43b97582d4b
oops - (String new:-1) did crash the system (atAllPut:)
Michael Beyl <mb@exept.de>
parents:
6599
diff
changeset
|
2328 |
#endif |
608 | 2329 |
REGISTER int l; |
2330 |
REGISTER int byteValue; |
|
1 | 2331 |
|
608 | 2332 |
if (__isCharacter(aCharacter) && __isString(self)) { |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2333 |
byteValue = __intVal(_characterVal(aCharacter)); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2334 |
if ((unsigned)byteValue <= 0xFF) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2335 |
l = __stringSize(self); |
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2336 |
|
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2337 |
#ifdef FAST_MEMSET |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2338 |
if (l > 0) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2339 |
memset(__stringVal(self), byteValue, l); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2340 |
} |
608 | 2341 |
#else |
6833
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 |
INT v; |
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 |
v = (byteValue << 8) | byteValue; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2346 |
v = (v << 16) | v; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2347 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2348 |
dst = __stringVal(self); |
3712 | 2349 |
|
2350 |
# 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
|
2351 |
if (l > 0) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2352 |
memset4(dst, v, l>>2); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2353 |
l = l & 3; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2354 |
} |
3712 | 2355 |
# else |
2356 |
# ifdef UINT64 |
|
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2357 |
{ |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2358 |
UINT64 v64; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2359 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2360 |
v64 = v; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2361 |
v64 = (v64 << 32) | v; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2362 |
while (l >= 8) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2363 |
((UINT64 *)dst)[0] = v64; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2364 |
dst += 8; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2365 |
l -= 8; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2366 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2367 |
} |
3712 | 2368 |
# else /* no UINT64 */ |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2369 |
while (l >= 16) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2370 |
((int *)dst)[0] = v; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2371 |
((int *)dst)[1] = v; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2372 |
((int *)dst)[2] = v; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2373 |
((int *)dst)[3] = v; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2374 |
dst += 16; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2375 |
l -= 16; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2376 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2377 |
if (l >= 8) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2378 |
((int *)dst)[0] = v; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2379 |
((int *)dst)[1] = v; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2380 |
dst += 8; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2381 |
l -= 8; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2382 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2383 |
if (l >= 4) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2384 |
((int *)dst)[0] = v; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2385 |
dst += 4; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2386 |
l -= 4; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2387 |
} |
3712 | 2388 |
# if 0 |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2389 |
if (l >= 2) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2390 |
((short *)dst)[0] = v; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2391 |
dst += 2; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2392 |
l -= 2; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2393 |
} |
3712 | 2394 |
# endif |
2395 |
||
5648 | 2396 |
# endif /* UINT64 */ |
2397 |
# endif /* FAST_MEMSET4 */ |
|
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2398 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2399 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2400 |
/* |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2401 |
* remaining bytes |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2402 |
*/ |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2403 |
while (l-- > 0) |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2404 |
*dst++ = byteValue; |
3712 | 2405 |
|
3711
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2406 |
#endif /* no FAST_MEMSET */ |
bdb2e9d06d33
20% speedup (p6/266) in #atAllPut:
Claus Gittinger <cg@exept.de>
parents:
3710
diff
changeset
|
2407 |
|
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2408 |
RETURN ( self ); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2409 |
} |
608 | 2410 |
} |
2862 | 2411 |
%}. |
608 | 2412 |
^ super atAllPut:aCharacter |
1 | 2413 |
|
608 | 2414 |
" |
3712 | 2415 |
(String new:10) atAllPut:$* |
608 | 2416 |
String new:10 withAll:$* |
2417 |
" |
|
2418 |
! |
|
2419 |
||
2929 | 2420 |
replaceAll:oldCharacter with:newCharacter |
4120 | 2421 |
"replace all oldCharacters by newCharacter in the receiver. |
2422 |
||
2423 |
Notice: This operation modifies the receiver, NOT a copy; |
|
2424 |
therefore the change may affect all others referencing the receiver." |
|
608 | 2425 |
|
2426 |
%{ /* NOCONTEXT */ |
|
2427 |
||
2428 |
REGISTER unsigned char *srcp; |
|
2429 |
REGISTER unsigned oldVal, newVal; |
|
4120 | 2430 |
unsigned char c, cNext; |
608 | 2431 |
|
2432 |
if (__isCharacter(oldCharacter) |
|
2433 |
&& __isCharacter(newCharacter) |
|
2434 |
&& __isString(self)) { |
|
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2435 |
srcp = (unsigned char *)__stringVal(self); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2436 |
oldVal = __intVal(_characterVal(oldCharacter)); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2437 |
newVal = __intVal(_characterVal(newCharacter)); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2438 |
if ((oldVal <= 0xFF) |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2439 |
&& (newVal <= 0xFF)) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2440 |
cNext = *srcp; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2441 |
while ((c = cNext) != '\0') { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2442 |
cNext = srcp[1]; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2443 |
if (c == oldVal) |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2444 |
*srcp = newVal; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2445 |
srcp++; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2446 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2447 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
2448 |
RETURN ( self ); |
1 | 2449 |
} |
2862 | 2450 |
%}. |
2929 | 2451 |
^ super replaceAll:oldCharacter with:newCharacter |
51 | 2452 |
|
608 | 2453 |
" |
4120 | 2454 |
'helloWorld' copy replaceAll:$o with:$O |
2455 |
'helloWorld' copy replaceAll:$d with:$* |
|
2456 |
'helloWorld' copy replaceAll:$h with:$* |
|
608 | 2457 |
" |
2458 |
! |
|
1 | 2459 |
|
2886 | 2460 |
replaceFrom:start to:stop with:aString startingAt:repStart |
1 | 2461 |
"replace the characters starting at index start, anInteger and ending |
2462 |
at stop, anInteger with characters from aString starting at repStart. |
|
3234 | 2463 |
Return the receiver. |
1 | 2464 |
|
2465 |
- reimplemented here for speed" |
|
2466 |
||
2467 |
%{ /* NOCONTEXT */ |
|
2468 |
||
2469 |
REGISTER unsigned char *srcp, *dstp; |
|
2470 |
REGISTER int count; |
|
2471 |
int len, index1, index2; |
|
2472 |
int repLen, repIndex; |
|
2473 |
||
2894 | 2474 |
#ifndef NO_PRIM_STRING |
53 | 2475 |
if ((__isString(aString) || __isSymbol(aString)) |
2476 |
&& __isString(self) |
|
252 | 2477 |
&& __bothSmallInteger(start, stop)) { |
3451 | 2478 |
len = __stringSize(self); |
2479 |
index1 = __intVal(start); |
|
2480 |
index2 = __intVal(stop); |
|
2481 |
count = index2 - index1 + 1; |
|
2482 |
if (count <= 0) { |
|
2483 |
RETURN (self); |
|
2484 |
} |
|
2485 |
if ((index2 <= len) && (index1 > 0)) { |
|
2486 |
repLen = __stringSize(aString); |
|
2487 |
repIndex = __intVal(repStart); |
|
2488 |
if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) { |
|
2489 |
srcp = __stringVal(aString) + repIndex - 1; |
|
2490 |
dstp = __stringVal(self) + index1 - 1; |
|
2491 |
if (aString == self) { |
|
2492 |
/* take care of overlapping copy */ |
|
2493 |
if (srcp < dstp) { |
|
2494 |
/* must do a reverse copy */ |
|
2495 |
srcp += count; |
|
2496 |
dstp += count; |
|
2497 |
while (count-- > 0) { |
|
2498 |
*--dstp = *--srcp; |
|
2499 |
} |
|
2500 |
RETURN (self); |
|
2501 |
} |
|
2502 |
} |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2503 |
#ifdef bcopy4 |
3451 | 2504 |
/* copy quadbytes if pointers are aligned */ |
2505 |
/* |
|
2506 |
* no sizeof(int) here please - |
|
2507 |
* - bcopy4 (if defined) copies 4-bytes on ALL machines |
|
2508 |
*/ |
|
2509 |
if ((count > 12) |
|
2510 |
&& (((unsigned INT)srcp & 3) == 0) |
|
2511 |
&& (((unsigned INT)dstp & 3) == 0)) { |
|
2512 |
int n; |
|
2513 |
||
2514 |
n = count >> 2; /* make it quads */ |
|
2515 |
bcopy4(srcp, dstp, n); |
|
2516 |
n <<= 2; /* back to chars */ |
|
2517 |
dstp += n; |
|
2518 |
srcp += n; |
|
2519 |
count -= n; |
|
2520 |
} |
|
2521 |
while (count-- > 0) { |
|
2522 |
*dstp++ = *srcp++; |
|
2523 |
} |
|
1 | 2524 |
#else |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2525 |
# ifdef FAST_MEMCPY |
3451 | 2526 |
bcopy(srcp, dstp, count); |
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2527 |
# else |
3451 | 2528 |
/* copy longs if pointers are aligned */ |
2529 |
if ((((unsigned INT)srcp & (sizeof(INT)-1)) == 0) |
|
2530 |
&& (((unsigned INT)dstp & (sizeof(INT)-1)) == 0)) { |
|
2531 |
while (count >= sizeof(INT)) { |
|
2532 |
*((unsigned INT *)dstp) = *((unsigned INT *)srcp); |
|
2533 |
dstp += sizeof(INT); |
|
2534 |
srcp += sizeof(INT); |
|
2535 |
count -= sizeof(INT); |
|
2536 |
} |
|
2537 |
} |
|
2538 |
while (count-- > 0) { |
|
2539 |
*dstp++ = *srcp++; |
|
2540 |
} |
|
2867
015574e235fd
tuned replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2862
diff
changeset
|
2541 |
# endif |
1 | 2542 |
#endif |
3451 | 2543 |
RETURN (self); |
2544 |
} |
|
2545 |
} |
|
1 | 2546 |
} |
2894 | 2547 |
#endif |
2862 | 2548 |
%}. |
1 | 2549 |
^ 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
|
2550 |
|
1 | 2551 |
! |
2552 |
||
2886 | 2553 |
reverse |
7338 | 2554 |
"in-place reverse the characters of the string. |
2555 |
WARNING: this is a destructive operation, which modifies the receiver." |
|
53 | 2556 |
|
2557 |
"Q: is there a need to redefine it here ?" |
|
1 | 2558 |
|
2559 |
%{ /* NOCONTEXT */ |
|
2560 |
||
2561 |
REGISTER char c; |
|
2562 |
REGISTER unsigned char *hip, *lowp; |
|
2563 |
||
53 | 2564 |
if (__isString(self)) { |
7338 | 2565 |
lowp = __stringVal(self); |
2566 |
hip = lowp + __stringSize(self) - 1; |
|
2567 |
while (lowp < hip) { |
|
2568 |
c = *lowp; |
|
2569 |
*lowp = *hip; |
|
2570 |
*hip = c; |
|
2571 |
lowp++; |
|
2572 |
hip--; |
|
2573 |
} |
|
2574 |
RETURN ( self ); |
|
1 | 2575 |
} |
2862 | 2576 |
%}. |
1 | 2577 |
^ super reverse |
2578 |
! |
|
2579 |
||
2580 |
withoutSeparators |
|
2862 | 2581 |
"return a string containing the chars of myself |
2582 |
without leading and trailing whitespace. |
|
2583 |
If there is no whitespace, the receiver is returned. |
|
95 | 2584 |
Notice, this is different from String>>withoutSpaces." |
1 | 2585 |
|
42 | 2586 |
|startIndex "{ Class: SmallInteger }" |
51 | 2587 |
endIndex "{ Class: SmallInteger }" |
2588 |
sz| |
|
2589 |
||
53 | 2590 |
startIndex := 0. |
2862 | 2591 |
|
51 | 2592 |
%{ |
2884 | 2593 |
REGISTER unsigned char *cp; |
2594 |
REGISTER unsigned char *ep; |
|
2595 |
REGISTER unsigned char c; |
|
51 | 2596 |
REGISTER unsigned char *cp0; |
2884 | 2597 |
REGISTER unsigned char *ep0; |
1 | 2598 |
|
51 | 2599 |
/* ignore instances of subclasses ... */ |
329 | 2600 |
if (__qClass(self) == String) { |
3111 | 2601 |
cp = cp0 = __stringVal(self); |
2862 | 2602 |
|
3111 | 2603 |
/* |
2604 |
* find first non-whiteSpace from beginning |
|
2605 |
*/ |
|
2862 | 2606 |
#ifndef NON_ASCII |
2954 | 2607 |
# ifdef UINT64 |
3111 | 2608 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
2609 |
cp += 8; |
|
2610 |
} |
|
2862 | 2611 |
# endif |
3111 | 2612 |
while (*((unsigned *)cp) == 0x20202020) { |
2613 |
cp += 4; |
|
2614 |
} |
|
2862 | 2615 |
#endif |
3111 | 2616 |
while ((c = *cp) |
329 | 2617 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
3111 | 2618 |
&& (c <= ' ') |
329 | 2619 |
#endif |
3111 | 2620 |
&& ((c == ' ') || (c == '\n') || (c == '\t') |
2621 |
|| (c == '\r') || (c == '\f')) |
|
2622 |
) { |
|
2623 |
cp++; |
|
2624 |
} |
|
2884 | 2625 |
|
3111 | 2626 |
/* |
2627 |
* find first non-whiteSpace from end |
|
2628 |
*/ |
|
2629 |
ep = ep0 = cp0 + __stringSize(self) - 1; |
|
2630 |
while ((ep >= cp) && (*ep == ' ')) ep--; |
|
2631 |
c = *ep; |
|
2632 |
while ((ep >= cp) && |
|
2862 | 2633 |
#ifndef NON_ASCII |
3111 | 2634 |
(c <= ' ') && |
329 | 2635 |
#endif |
3111 | 2636 |
((c == ' ') || (c == '\n') || (c == '\t') |
2637 |
|| (c == '\r') || (c == '\f'))) { |
|
2638 |
ep--; |
|
2639 |
c = *ep; |
|
2640 |
} |
|
2884 | 2641 |
|
3111 | 2642 |
/* |
2643 |
* no whiteSpace ? |
|
2644 |
*/ |
|
2645 |
if ((cp == cp0) && (ep == ep0)) { |
|
2646 |
RETURN(self); |
|
2647 |
} |
|
2884 | 2648 |
|
3111 | 2649 |
startIndex = __MKSMALLINT(cp - cp0 + 1); |
2650 |
endIndex = __MKSMALLINT(ep - cp0 + 1); |
|
51 | 2651 |
} |
202 | 2652 |
%}. |
2653 |
startIndex == 0 ifTrue:[^ super withoutSeparators]. |
|
2654 |
||
2655 |
startIndex > endIndex ifTrue:[^ '']. |
|
1 | 2656 |
^ self copyFrom:startIndex to:endIndex |
2884 | 2657 |
|
2658 |
" |
|
2659 |
'hello' withoutSeparators |
|
2660 |
' hello' withoutSeparators |
|
2661 |
' hello ' withoutSeparators |
|
2662 |
' hello ' withoutSeparators |
|
2663 |
' hello ' withoutSeparators |
|
2664 |
' hello ' withoutSeparators |
|
2665 |
' ' withoutSeparators |
|
2666 |
" |
|
2667 |
||
608 | 2668 |
! |
2669 |
||
2670 |
withoutSpaces |
|
2862 | 2671 |
"return a string containing the characters of myself |
2672 |
without leading and trailing spaces. |
|
2884 | 2673 |
If there are no spaces, the receiver is returned unchanged. |
608 | 2674 |
Notice, this is different from String>>withoutSeparators." |
2675 |
||
2676 |
|startIndex "{ Class: SmallInteger }" |
|
2677 |
endIndex "{ Class: SmallInteger }" |
|
2678 |
sz blank| |
|
2679 |
||
2680 |
startIndex := 0. |
|
2681 |
%{ |
|
2682 |
REGISTER unsigned char *cp; |
|
2884 | 2683 |
REGISTER unsigned char *ep; |
2684 |
unsigned char *cp0; |
|
2685 |
unsigned char *ep0; |
|
608 | 2686 |
|
2687 |
/* ignore instances of subclasses ... */ |
|
2688 |
if (__qClass(self) == String) { |
|
3111 | 2689 |
cp = cp0 = __stringVal(self); |
2862 | 2690 |
|
3111 | 2691 |
/* |
2692 |
* find first non-blank from beginning |
|
2693 |
*/ |
|
2862 | 2694 |
#ifndef NON_ASCII |
2954 | 2695 |
# ifdef UINT64 |
3111 | 2696 |
while (*((UINT64 *)cp) == 0x2020202020202020L) { |
2697 |
cp += 8; |
|
2698 |
} |
|
2954 | 2699 |
# endif /* UINT64 */ |
3111 | 2700 |
while (*((unsigned *)cp) == 0x20202020) { |
2701 |
cp += 4; |
|
2702 |
} |
|
2862 | 2703 |
#endif |
3111 | 2704 |
while (*cp == ' ') cp++; |
2884 | 2705 |
|
3111 | 2706 |
/* |
2707 |
* find first non-blank from end |
|
2708 |
*/ |
|
2709 |
ep = ep0 = cp0 + __stringSize(self) - 1; |
|
2710 |
while ((ep >= cp) && (*ep == ' ')) ep--; |
|
2862 | 2711 |
|
3111 | 2712 |
/* |
2713 |
* no blanks ? |
|
2714 |
*/ |
|
2715 |
if ((cp == cp0) && (ep == ep0)) { |
|
2716 |
RETURN(self); |
|
2717 |
} |
|
2884 | 2718 |
|
3111 | 2719 |
startIndex = __MKSMALLINT(cp - cp0 + 1); |
2720 |
endIndex = __MKSMALLINT(ep - cp0 + 1); |
|
608 | 2721 |
} |
2722 |
%}. |
|
2723 |
startIndex == 0 ifTrue:[^ super withoutSpaces]. |
|
2724 |
||
2725 |
startIndex > endIndex ifTrue:[^ '']. |
|
2886 | 2726 |
((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self]. |
608 | 2727 |
^ self copyFrom:startIndex to:endIndex |
2884 | 2728 |
|
2729 |
" |
|
2730 |
' hello' withoutSpaces |
|
2731 |
' hello ' withoutSpaces |
|
2732 |
' hello ' withoutSpaces |
|
2733 |
' hello ' withoutSpaces |
|
2734 |
' hello ' withoutSpaces |
|
2735 |
' ' withoutSpaces |
|
2736 |
" |
|
608 | 2737 |
! ! |
2738 |
||
2739 |
!String methodsFor:'printing & storing'! |
|
2740 |
||
2886 | 2741 |
isLiteral |
4660 | 2742 |
"return true, if the receiver can be used as a literal constant in ST syntax |
608 | 2743 |
(i.e. can be used in constant arrays)" |
2744 |
||
2745 |
^ true |
|
2746 |
! |
|
2747 |
||
2886 | 2748 |
|
2749 |
"print the receiver on standard output. |
|
4631 | 2750 |
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
|
2751 |
will therefore work even in case of emergency (but only, if Stdout is nil)." |
608 | 2752 |
|
2753 |
%{ /* NOCONTEXT */ |
|
2754 |
||
2755 |
if (__qClass(self) == String) { |
|
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2756 |
if (@global(Stdout) == nil) { |
1486 | 2757 |
#ifdef WIN32 |
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2758 |
fprintf(stdout, "%s" , __stringVal(self)); |
1486 | 2759 |
#else |
4631 | 2760 |
/*cg: used to have fputs here, but that seems to be NOT prepared |
2761 |
* for eintr arriving and thus sometimes sends the string twice ... |
|
2762 |
* |
|
2763 |
* fputs(__stringVal(self), stdout); |
|
2764 |
*/ |
|
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2765 |
fwrite(__stringVal(self), 1, __stringSize(self), stdout); |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2766 |
fflush(stdout); |
1486 | 2767 |
#endif |
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2768 |
RETURN (self); |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2769 |
} |
608 | 2770 |
} |
3751 | 2771 |
%}. |
608 | 2772 |
^ super print |
2773 |
! |
|
2774 |
||
3751 | 2775 |
printCR |
2776 |
"print the receiver on standard output, followed by a cr. |
|
4631 | 2777 |
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
|
2778 |
will therefore work even in case of emergency (but only, if Stdout is nil)." |
3751 | 2779 |
|
2780 |
%{ /* NOCONTEXT */ |
|
2781 |
||
2782 |
if (__qClass(self) == String) { |
|
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2783 |
if (@global(Stdout) == nil) { |
3751 | 2784 |
#ifdef WIN32 |
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2785 |
fprintf(stdout, "%s\n" , __stringVal(self)); |
3751 | 2786 |
#else |
4631 | 2787 |
/*cg: used to have fputs here, but that seems to be NOT prepared |
2788 |
* for eintr arriving and thus sometimes sends the string twice ... |
|
2789 |
* |
|
2790 |
* fputs(__stringVal(self), stdout); fputs("\n", stdout); |
|
2791 |
*/ |
|
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2792 |
fwrite(__stringVal(self), 1, __stringSize(self), stdout); |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2793 |
fwrite("\n", 1, 1, stdout); |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2794 |
fflush(stdout); |
3751 | 2795 |
#endif |
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2796 |
RETURN (self); |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
2797 |
} |
3751 | 2798 |
} |
2799 |
%}. |
|
2800 |
^ super printCR |
|
2801 |
! |
|
2802 |
||
2886 | 2803 |
printfPrintString:formatString |
7746 | 2804 |
"non-standard but sometimes useful. |
608 | 2805 |
Return a printed representation of the receiver as specified by formatString, |
2806 |
which is defined by printf. |
|
2807 |
This method is NONSTANDARD and may be removed without notice." |
|
2808 |
||
2809 |
%{ /* STACK: 1000 */ |
|
2810 |
||
2811 |
char buffer[800]; |
|
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2812 |
char *buf = buffer; |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2813 |
int bufsize = sizeof(buffer); |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2814 |
char *mallocbuf = NULL; |
608 | 2815 |
char *cp; |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2816 |
int len; |
608 | 2817 |
OBJ s; |
2818 |
||
2819 |
if (__isString(formatString)) { |
|
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2820 |
cp = (char *)__stringVal(self); |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2821 |
if (__qClass(self) != String) |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2822 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2823 |
|
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2824 |
again: |
7746 | 2825 |
/* |
2826 |
* actually only needed on sparc: since thisContext is |
|
2827 |
* in a global register, which gets destroyed by printf, |
|
2828 |
* manually save it here - very stupid ... |
|
2829 |
*/ |
|
2830 |
__BEGIN_PROTECT_REGISTERS__ |
|
2831 |
||
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2832 |
len = snprintf(buf, bufsize, (char *)__stringVal(formatString), cp); |
7746 | 2833 |
|
2834 |
__END_PROTECT_REGISTERS__ |
|
2835 |
||
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2836 |
|
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2837 |
if (len > bufsize) { |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2838 |
bufsize = len + 1; |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2839 |
if (mallocbuf) |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2840 |
free(mallocbuf); |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2841 |
buf = mallocbuf = malloc(bufsize); |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2842 |
if (buf == NULL) |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2843 |
goto fail; |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2844 |
goto again; |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2845 |
} else if (len < 0) { |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2846 |
bufsize *= 2; |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2847 |
if (mallocbuf) |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2848 |
free(mallocbuf); |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2849 |
buf = mallocbuf = malloc(bufsize); |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2850 |
if (buf == NULL) |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2851 |
goto fail; |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2852 |
goto again; |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2853 |
} |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2854 |
|
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2855 |
s = __MKSTRING_L(buf, len); |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2856 |
|
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2857 |
if (mallocbuf) |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2858 |
free(mallocbuf); |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2859 |
|
7746 | 2860 |
if (s != nil) { |
2861 |
RETURN (s); |
|
2862 |
} |
|
608 | 2863 |
} |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2864 |
fail:; |
608 | 2865 |
%}. |
2866 |
self primitiveFailed |
|
2867 |
||
2868 |
" |
|
2869 |
'hello' printfPrintString:'%%s -> %s' |
|
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2870 |
(String new:900) printfPrintString:'%%s -> %s' |
608 | 2871 |
'hello' printfPrintString:'%%10s -> %10s' |
2872 |
'hello' printfPrintString:'%%-10s -> %-10s' |
|
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2873 |
'hello' printfPrintString:'%%900s -> %900s' |
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
2874 |
'hello' printfPrintString:'%%-900s -> %-900s' |
608 | 2875 |
" |
2876 |
! |
|
2877 |
||
2886 | 2878 |
storeOn:aStream |
608 | 2879 |
"put the storeString of myself on aStream" |
2880 |
||
7599
188489aaaacd
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7338
diff
changeset
|
2881 |
aStream nextPut:$'. |
608 | 2882 |
(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
|
2883 |
self printWithQuotesDoubledOn:aStream |
608 | 2884 |
] ifFalse:[ |
7599
188489aaaacd
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7338
diff
changeset
|
2885 |
aStream nextPutAll:self |
608 | 2886 |
]. |
2887 |
aStream nextPut:$' |
|
3579 | 2888 |
|
2889 |
"Modified: / 15.6.1998 / 17:21:51 / cg" |
|
608 | 2890 |
! |
2891 |
||
2886 | 2892 |
storeString |
2893 |
"return a String for storing myself" |
|
608 | 2894 |
|
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8038
diff
changeset
|
2895 |
^ self basicStoreString. |
1 | 2896 |
! ! |
2897 |
||
6588 | 2898 |
!String methodsFor:'public'! |
2899 |
||
2900 |
isBinarySelector |
|
2901 |
"Answer a <boolean>, true if the receiver contains only chars in an ANSI binary method selector, else false." |
|
2902 |
#'SysPro'. "2001/02/02 Harmon, R. A. Added System Protocols support." |
|
2903 |
||
2904 |
^self allSatisfy: [:chr| '!!%&''*+,`/<=>?@\~|-' includes: chr] |
|
2905 |
! |
|
2906 |
||
2907 |
isUnarySelector |
|
2908 |
"Answer a <boolean>, true if the receiver contains only chars in an ANSI unary method selector, else false." |
|
2909 |
#'SysPro'. "2001/02/02 Harmon, R. A. Added System Protocols support." |
|
2910 |
||
6830 | 2911 |
^self allSatisfy: [ :chr | chr isLetter or:[ chr isDigit] ] |
6588 | 2912 |
! ! |
2913 |
||
1 | 2914 |
!String methodsFor:'queries'! |
2915 |
||
5557 | 2916 |
basicSize |
2917 |
"return the number of characters in myself. |
|
2918 |
Redefined here to exclude the 0-byte at the end." |
|
2919 |
||
2920 |
%{ /* NOCONTEXT */ |
|
2921 |
REGISTER OBJ slf, cls; |
|
2922 |
||
2923 |
slf = self; |
|
2924 |
||
2925 |
cls = __qClass(slf); |
|
2926 |
if (cls == String) { |
|
2927 |
RETURN ( __MKSMALLINT(__stringSize(slf)) ); |
|
2928 |
} |
|
2929 |
RETURN ( __MKSMALLINT(__stringSize(slf) |
|
2930 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
|
2931 |
%}. |
|
2932 |
^ super basicSize - 1 |
|
2933 |
||
2934 |
! |
|
2935 |
||
2886 | 2936 |
bitsPerCharacter |
1239 | 2937 |
"return the number of bits each character has. |
2938 |
Here, 8 is returned (storing single byte characters)." |
|
2939 |
||
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2940 |
^ 8 |
1239 | 2941 |
|
2942 |
"Modified: 20.4.1996 / 23:08:42 / cg" |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2943 |
! |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2944 |
|
2886 | 2945 |
knownAsSymbol |
2946 |
"return true, if there is a symbol with same characters in the |
|
2862 | 2947 |
system. |
2948 |
Can be used to check for existance of a symbol without creating one" |
|
608 | 2949 |
|
2950 |
%{ /* NOCONTEXT */ |
|
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2951 |
OBJ cls; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2952 |
int indx; |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2953 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2954 |
cls = __qClass(self); |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2955 |
if (cls != String) { |
5407 | 2956 |
indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2957 |
} else { |
5407 | 2958 |
indx = 0; |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2959 |
} |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2960 |
RETURN ( __KNOWNASSYMBOL(__stringVal(self) + indx) ); |
5407 | 2961 |
%}. |
6007 | 2962 |
"/ ^ self asSymbolIfInterned notNil. |
5407 | 2963 |
self primitiveFailed |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2964 |
|
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2965 |
" |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2966 |
'hello' knownAsSymbol |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2967 |
'fooBarBaz' knownAsSymbol |
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
2968 |
" |
5557 | 2969 |
! |
2970 |
||
2971 |
size |
|
2972 |
"return the number of characters in myself. |
|
2973 |
Reimplemented here to avoid the additional size->basicSize send |
|
2974 |
(which we can do here, since size is obviously not redefined in a subclass). |
|
2975 |
This method is the same as basicSize." |
|
2976 |
||
2977 |
%{ /* NOCONTEXT */ |
|
2978 |
REGISTER OBJ cls, slf; |
|
2979 |
||
2980 |
slf = self; |
|
2981 |
cls = __qClass(slf); |
|
2982 |
if (cls == String) { |
|
2983 |
RETURN ( __MKSMALLINT(__stringSize(slf)) ); |
|
2984 |
} |
|
2985 |
RETURN ( __MKSMALLINT(__stringSize(slf) |
|
2986 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
|
2987 |
%}. |
|
2988 |
^ self basicSize |
|
8038 | 2989 |
! |
2990 |
||
2991 |
stringSpecies |
|
2992 |
^ String |
|
1 | 2993 |
! ! |
608 | 2994 |
|
2995 |
!String methodsFor:'testing'! |
|
2996 |
||
2886 | 2997 |
endsWith:aStringOrChar |
2862 | 2998 |
"return true, if the receiver ends with something, aStringOrChar." |
1380 | 2999 |
|
3000 |
%{ /* NOCONTEXT */ |
|
3001 |
||
3002 |
int len1, len2; |
|
3003 |
REGISTER unsigned char *src1, *src2; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
3004 |
unsigned char c; |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3005 |
REGISTER OBJ slf = self; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3006 |
|
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3007 |
if ((__isString(slf) || __isSymbol(slf)) |
2862 | 3008 |
&& (__isString(aStringOrChar) || __isSymbol(aStringOrChar))) { |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3009 |
len1 = __qSize(slf); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3010 |
len2 = __qSize(aStringOrChar); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3011 |
if (len1 < len2) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3012 |
RETURN ( false ); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3013 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3014 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3015 |
src1 = __stringVal(slf) + (len1 - len2); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3016 |
src2 = __stringVal(aStringOrChar); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3017 |
while (c = *src2++) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3018 |
if (c != *src1++) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3019 |
RETURN ( false ); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3020 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3021 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3022 |
RETURN (true); |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3023 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3024 |
if (__isCharacter(aStringOrChar)) { |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3025 |
int val; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3026 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3027 |
val = __intVal(_characterVal(aStringOrChar)); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3028 |
if ((unsigned)val <= 0xFF) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3029 |
len1 = __stringSize(slf); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3030 |
if (len1 > 0) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3031 |
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
|
3032 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3033 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3034 |
RETURN ( false ); |
1380 | 3035 |
} |
3036 |
%}. |
|
2862 | 3037 |
^ super endsWith:aStringOrChar |
1380 | 3038 |
|
3039 |
" |
|
3040 |
'hello world' endsWith:'world' |
|
3041 |
'hello world' endsWith:'earth' |
|
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3042 |
'hello world' endsWith:$d |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3043 |
'hello world' endsWith:$e |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3044 |
'' endsWith:$d |
1380 | 3045 |
'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
|
3046 |
'hello world' endsWith:'' |
1380 | 3047 |
" |
3048 |
! |
|
3049 |
||
2886 | 3050 |
isBlank |
3051 |
"return true, if the receivers size is 0 or if it contains only spaces. |
|
608 | 3052 |
Q: should we care for whiteSpace in general here ?" |
3053 |
||
3054 |
%{ /* NOCONTEXT */ |
|
3055 |
||
3056 |
REGISTER unsigned char *src; |
|
3057 |
REGISTER unsigned char c; |
|
3058 |
OBJ cls; |
|
3059 |
||
1134 | 3060 |
src = __stringVal(self); |
608 | 3061 |
if ((cls = __qClass(self)) != String) |
5407 | 3062 |
src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
608 | 3063 |
|
3064 |
#ifndef NON_ASCII |
|
2954 | 3065 |
# ifdef UINT64 |
3066 |
while (*((UINT64 *)src) == 0x2020202020202020L) { |
|
5407 | 3067 |
src += 8; |
2862 | 3068 |
} |
2954 | 3069 |
# endif /* UINT64 */ |
3710
6ee8b3c37d09
allow subclass-insts of String
Claus Gittinger <cg@exept.de>
parents:
3673
diff
changeset
|
3070 |
|
608 | 3071 |
while (*((unsigned *)src) == 0x20202020) { |
5407 | 3072 |
src += 4; |
608 | 3073 |
} |
2862 | 3074 |
#endif /* ascii */ |
3075 |
||
3076 |
while (c = *src++) { |
|
5407 | 3077 |
if (c != ' ') { |
3078 |
RETURN ( false ); |
|
3079 |
} |
|
2862 | 3080 |
} |
5407 | 3081 |
RETURN ( true ); |
608 | 3082 |
%}. |
5407 | 3083 |
^ super isBlank |
608 | 3084 |
! |
3085 |
||
5556 | 3086 |
isEmpty |
3087 |
"return true if the receiver is empty (i.e. if size == 0) |
|
3088 |
Redefined here for performance" |
|
3089 |
||
3090 |
%{ /* NOCONTEXT */ |
|
3091 |
OBJ cls; |
|
3092 |
||
3093 |
cls = __qClass(self); |
|
3094 |
if ((cls == String) || (cls == Symbol)) { |
|
3095 |
RETURN ( (__stringSize(self) == 0) ? true : false); |
|
3096 |
} |
|
3097 |
%}. |
|
3098 |
^ self size == 0 |
|
3099 |
! |
|
3100 |
||
2886 | 3101 |
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight |
608 | 3102 |
"parametrized levenshtein. arguments are the costs for |
3103 |
substitution, case-change, insertion and deletion of a character." |
|
3104 |
||
1138
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
3105 |
%{ /* STACK: 2000 */ |
608 | 3106 |
|
3107 |
/* |
|
3108 |
* this is very heavy used when correcting errors |
|
3109 |
* (all symbols are searched for best match) - therefore it must be fast |
|
3110 |
*/ |
|
3111 |
{ |
|
3112 |
unsigned short *data; |
|
3113 |
int l1, l2; |
|
3114 |
REGISTER int sz; |
|
3115 |
unsigned char *s1, *s2; |
|
3116 |
int v1, v2, v3, m; |
|
3117 |
REGISTER unsigned short *dp; |
|
3118 |
REGISTER int delta; |
|
3119 |
REGISTER int j; |
|
3120 |
int i; |
|
3121 |
int iW, cW, sW, dW; |
|
1486 | 3122 |
# define FASTSIZE 30 /* increase STACK if you increase this ... */ |
608 | 3123 |
unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)]; |
3124 |
||
3125 |
if ((__isString(self) || __isSymbol(self)) |
|
3126 |
&& (__isString(aString) || __isSymbol(aString)) |
|
3127 |
&& __bothSmallInteger(insrtWeight, caseWeight) |
|
3128 |
&& __bothSmallInteger(substWeight, deleteWeight)) { |
|
1134 | 3129 |
iW = __intVal(insrtWeight); |
3130 |
cW = __intVal(caseWeight); |
|
3131 |
sW = __intVal(substWeight); |
|
3132 |
dW = __intVal(deleteWeight); |
|
3133 |
s1 = __stringVal(self); |
|
3134 |
s2 = __stringVal(aString); |
|
608 | 3135 |
l1 = strlen(s1); |
3136 |
l2 = strlen(s2); |
|
3137 |
||
3138 |
sz = (l1 < l2) ? l2 : l1; |
|
3139 |
delta = sz + 1; |
|
3140 |
if (sz <= FASTSIZE) { |
|
3141 |
data = fastData; |
|
3142 |
} else { |
|
3143 |
/* add ifdef ALLOCA here ... */ |
|
3144 |
data = (unsigned short *)malloc(delta * delta * sizeof(short)); |
|
3145 |
if (! data) goto mallocFailed; |
|
3146 |
} |
|
3147 |
||
3148 |
data[0] = 0; |
|
3149 |
dp = data+1; |
|
3150 |
for (j=1, dp=data+1; j<=sz; j++, dp++) |
|
3151 |
*dp = *(dp-1) + iW; |
|
3152 |
||
3153 |
for (i=1, dp=data+delta; i<=sz; i++, dp+=delta) |
|
3154 |
*dp = *(dp-delta) + dW; |
|
3155 |
||
3156 |
for (i=1; i<=l1; i++) { |
|
3157 |
for (j=1; j<=l2; j++) { |
|
3158 |
dp = data + (i*delta) + j; |
|
3159 |
if (s1[i] != s2[j]) { |
|
3160 |
if (tolower(s1[i]) == tolower(s2[j])) { |
|
3161 |
m = cW; |
|
3162 |
} else { |
|
3163 |
m = sW; |
|
3164 |
} |
|
3165 |
} else |
|
3166 |
m = 0; |
|
3167 |
||
3168 |
v2 = *(dp - 1) + iW; |
|
3169 |
v3 = *(dp - delta) + dW; |
|
3170 |
v1 = *(dp - delta - 1) + m; |
|
3171 |
if (v1 < v2) |
|
3172 |
if (v1 < v3) |
|
3173 |
m = v1; |
|
3174 |
else |
|
3175 |
m = v3; |
|
3176 |
else |
|
3177 |
if (v2 < v3) |
|
3178 |
m = v2; |
|
3179 |
else |
|
3180 |
m = v3; |
|
3181 |
*dp = m; |
|
3182 |
} |
|
3183 |
} |
|
3184 |
m = data[l1 * delta + l2]; |
|
3185 |
if (sz > FASTSIZE) |
|
3186 |
free(data); |
|
1134 | 3187 |
RETURN ( __MKSMALLINT(m) ); |
608 | 3188 |
} |
3189 |
mallocFailed: ; |
|
3190 |
} |
|
3191 |
%}. |
|
3192 |
||
3193 |
^ super levenshteinTo:aString |
|
3194 |
s:substWeight c:caseWeight |
|
3195 |
i:insrtWeight d:deleteWeight |
|
3196 |
||
3197 |
"'ocmprt' levenshteinTo:'computer' |
|
3198 |
'computer' levenshteinTo:'computer' |
|
3199 |
'ocmputer' levenshteinTo:'computer' |
|
3200 |
'cmputer' levenshteinTo:'computer' |
|
3201 |
'Computer' levenshteinTo:'computer'" |
|
1380 | 3202 |
! |
3203 |
||
5556 | 3204 |
notEmpty |
3205 |
"return true if the receiver is not empty (i.e. if size ~~ 0) |
|
3206 |
Redefined here for performance" |
|
3207 |
||
3208 |
%{ /* NOCONTEXT */ |
|
3209 |
OBJ cls; |
|
3210 |
||
3211 |
cls = __qClass(self); |
|
3212 |
if ((cls == String) || (cls == Symbol)) { |
|
3213 |
RETURN ( (__stringSize(self) != 0) ? true : false); |
|
3214 |
} |
|
3215 |
%}. |
|
3216 |
^ self size ~~ 0 |
|
3217 |
! |
|
3218 |
||
2886 | 3219 |
startsWith:aStringOrChar |
4389
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4388
diff
changeset
|
3220 |
"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
|
3221 |
If the argument is empty, true is returned." |
1380 | 3222 |
|
3223 |
%{ /* NOCONTEXT */ |
|
3224 |
||
3225 |
int len1, len2; |
|
3226 |
REGISTER unsigned char *src1, *src2; |
|
2858
866ffc52ac8a
oops - need unsigned character compares
Claus Gittinger <cg@exept.de>
parents:
2856
diff
changeset
|
3227 |
unsigned char c; |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3228 |
REGISTER OBJ slf = self; |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3229 |
|
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3230 |
if (((__qClass(slf)==String) || (__qClass(slf)==Symbol)) |
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
3231 |
&& __isNonNilObject(aStringOrChar) |
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
3232 |
&& ((__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
|
3233 |
src1 = __stringVal(slf); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3234 |
src2 = __stringVal(aStringOrChar); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3235 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3236 |
if (src1[0] != src2[0]) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3237 |
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
|
3238 |
RETURN (true); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3239 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3240 |
RETURN ( false ); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3241 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3242 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3243 |
len1 = __qSize(slf); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3244 |
len2 = __qSize(aStringOrChar); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3245 |
if (len1 < len2) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3246 |
RETURN ( false ); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3247 |
} |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3248 |
|
4247 | 3249 |
#ifdef UINT64 |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3250 |
while (len2 > (OHDR_SIZE+sizeof(UINT64))) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3251 |
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
|
3252 |
RETURN (false); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3253 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3254 |
len2 -= sizeof(UINT64); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3255 |
src1 += sizeof(UINT64); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3256 |
src2 += sizeof(UINT64); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3257 |
} |
4247 | 3258 |
#else |
3259 |
# ifdef UNROLL_LOOPS |
|
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3260 |
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
|
3261 |
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
|
3262 |
RETURN (false); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3263 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3264 |
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
|
3265 |
RETURN (false); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3266 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3267 |
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
|
3268 |
RETURN (false); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3269 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3270 |
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
|
3271 |
RETURN (false); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3272 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3273 |
len2 -= sizeof(INT)*4; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3274 |
src1 += sizeof(INT)*4; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3275 |
src2 += sizeof(INT)*4; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3276 |
} |
4247 | 3277 |
# endif /* UNROLL_LOOPS */ |
3278 |
#endif /* UINT64 */ |
|
3546
00984e13534a
8-byte compares (if possible) in startsWith:
Claus Gittinger <cg@exept.de>
parents:
3545
diff
changeset
|
3279 |
|
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3280 |
while (len2 > (OHDR_SIZE+sizeof(INT))) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3281 |
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
|
3282 |
RETURN (false); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3283 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3284 |
len2 -= sizeof(INT); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3285 |
src1 += sizeof(INT); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3286 |
src2 += sizeof(INT); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3287 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3288 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3289 |
while (c = *src2++) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3290 |
if (c != *src1) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3291 |
RETURN ( false ); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3292 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3293 |
src1++; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3294 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3295 |
RETURN (true); |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3296 |
} |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3297 |
if (__isCharacter(aStringOrChar)) { |
6833
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3298 |
int val; |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3299 |
|
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3300 |
val = __intVal(_characterVal(aStringOrChar)); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3301 |
if ((unsigned)val <= 0xFF) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3302 |
len1 = __stringSize(slf); |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3303 |
if (len1 > 0) { |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3304 |
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
|
3305 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3306 |
} |
bc361f384f7f
care for twoByteChars in all inline-C code
Claus Gittinger <cg@exept.de>
parents:
6830
diff
changeset
|
3307 |
RETURN ( false ); |
1380 | 3308 |
} |
3309 |
%}. |
|
2862 | 3310 |
^ super startsWith:aStringOrChar |
1380 | 3311 |
|
3312 |
" |
|
3314
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
3313 |
'hello world' startsWith:'hello' |
94046261fba0
tuned #~= , #= and #startsWith:
Claus Gittinger <cg@exept.de>
parents:
3281
diff
changeset
|
3314 |
'hello world' startsWith:'hella' |
1380 | 3315 |
'hello world' startsWith:'hi' |
3545
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3316 |
'hello world' startsWith:$h |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3317 |
'hello world' startsWith:$H |
5238e4d15d64
better code for endsWith: / startsWith: for single-character arg.
Claus Gittinger <cg@exept.de>
parents:
3451
diff
changeset
|
3318 |
'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
|
3319 |
'hello world' startsWith:60 |
1380 | 3320 |
'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
|
3321 |
'hello world' startsWith:'' |
1380 | 3322 |
" |
608 | 3323 |
! ! |
3324 |
||
4660 | 3325 |
!String methodsFor:'tracing'! |
3326 |
||
4682 | 3327 |
traceInto:aRequestor level:level from:referrer |
4660 | 3328 |
"double dispatch into tracer, passing my type implicitely in the selector" |
3329 |
||
4682 | 3330 |
^ aRequestor traceString:self level:level from:referrer |
4660 | 3331 |
|
3332 |
||
3333 |
! ! |
|
3334 |
||
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3335 |
|
633 | 3336 |
!String class methodsFor:'documentation'! |
3337 |
||
2886 | 3338 |
version |
8415
7e0f1105bc9f
Security: use snprintf() instead of sprintf()
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3339 |
^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.207 2004-06-26 12:13:51 stefan Exp $' |
633 | 3340 |
! ! |