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