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