author | Claus Gittinger <cg@exept.de> |
Tue, 15 Apr 1997 13:05:18 +0200 | |
changeset 2549 | 9ca8a3fcdaa7 |
parent 2530 | d329f4251a53 |
child 2670 | c4eef0b3ea0d |
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 |
||
255 | 13 |
CharacterArray subclass:#String |
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
14 |
instanceVariableNames:'' |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
15 |
classVariableNames:'' |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
16 |
poolDictionaries:'' |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
17 |
category:'Collections-Text' |
88 | 18 |
! |
19 |
||
216 | 20 |
!String primitiveDefinitions! |
88 | 21 |
%{ |
1486 | 22 |
#ifndef WIN32 |
23 |
# include <stdio.h> |
|
24 |
# define _STDIO_H_INCLUDED_ |
|
25 |
#endif |
|
437 | 26 |
|
88 | 27 |
#include <ctype.h> |
359 | 28 |
|
273 | 29 |
#ifdef LINUX |
359 | 30 |
# define __STRINGDEFS__ |
31 |
# include <linuxIntern.h> |
|
302 | 32 |
#else |
33 |
extern char *strchr(); |
|
273 | 34 |
#endif |
95 | 35 |
|
36 |
/* |
|
37 |
* old st/x creates strings with spaces in it; |
|
38 |
* new st/x will fill it with zeros (for st-80 compatibility) |
|
39 |
* the define below sets old behavior. |
|
40 |
*/ |
|
41 |
#define INITIALIZE_WITH_SPACE |
|
88 | 42 |
%} |
216 | 43 |
! ! |
88 | 44 |
|
608 | 45 |
!String class methodsFor:'documentation'! |
46 |
||
47 |
copyright |
|
48 |
" |
|
49 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
50 |
All Rights Reserved |
|
51 |
||
52 |
This software is furnished under a license and may be used |
|
53 |
only in accordance with the terms of that license and with the |
|
54 |
inclusion of the above copyright notice. This software may not |
|
55 |
be provided or otherwise made available to, or used by, any |
|
56 |
other person. No title to or ownership of the software is |
|
57 |
hereby transferred. |
|
58 |
" |
|
59 |
! |
|
3 | 60 |
|
608 | 61 |
documentation |
62 |
" |
|
63 |
Strings are ByteArrays storing Characters. |
|
64 |
||
65 |
Strings are kind of kludgy: to allow for easy handling by c-functions, |
|
66 |
there is always one 0-byte added at the end, which is not counted |
|
67 |
in size. also, the at:put: method does not allow for storing 0-bytes. |
|
68 |
(to do this, the basicAt:put: and basicNew: methods are redefined) |
|
3 | 69 |
|
608 | 70 |
You cannot add any instvars to String, since the the run time system & compiler |
71 |
creates literal strings and knows that strings have no named instvars. |
|
72 |
||
73 |
If you really need strings with instVars, you have to create a subclass |
|
74 |
of String (the access functions defined here can handle this). |
|
75 |
A little warning though: not all smalltalk systems allow subclassing String, |
|
76 |
so your program may become unportable if you do so. |
|
1290 | 77 |
|
78 |
[author:] |
|
1486 | 79 |
Claus Gittinger |
1310 | 80 |
|
81 |
[see also:] |
|
1486 | 82 |
Text StringCollection TwoByteString JISEncodedString |
83 |
Symbol |
|
608 | 84 |
" |
3 | 85 |
! ! |
86 |
||
1 | 87 |
!String class methodsFor:'instance creation'! |
88 |
||
89 |
basicNew:anInteger |
|
90 |
"return a new empty string with anInteger characters" |
|
91 |
||
92 |
%{ /* NOCONTEXT */ |
|
93 |
||
94 |
OBJ newString; |
|
95 |
REGISTER int len; |
|
96 |
REGISTER unsigned char *cp; |
|
97 |
REGISTER OBJ *op; |
|
98 |
int nInstVars, instsize; |
|
99 |
||
252 | 100 |
if (__isSmallInteger(anInteger)) { |
1134 | 101 |
len = __intVal(anInteger); |
159 | 102 |
if (len >= 0) { |
95 | 103 |
if (self == String) { |
104 |
instsize = OHDR_SIZE + len + 1; |
|
835 | 105 |
if (__CanDoQuickNew(instsize)) { |
95 | 106 |
/* |
107 |
* the most common case |
|
108 |
*/ |
|
835 | 109 |
__qCheckedNew(newString, instsize); |
1134 | 110 |
__InstPtr(newString)->o_class = self; |
368 | 111 |
__qSTORE(newString, self); |
112 |
||
1134 | 113 |
cp = __stringVal(newString); |
357 | 114 |
#if defined(memset4) && !defined(NON_ASCII) |
115 |
instsize = len >> 2; |
|
116 |
if (len & 3) instsize++; |
|
117 |
memset4(cp, 0x20202020, instsize); |
|
159 | 118 |
*(cp + len) = '\0'; |
95 | 119 |
#else |
357 | 120 |
# ifdef FAST_MEMSET |
121 |
memset(cp, ' ', len); |
|
122 |
*(cp + len) = '\0'; |
|
123 |
# else |
|
159 | 124 |
while (len >= 8) { |
357 | 125 |
# ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
126 |
((int *)cp)[0] = 0x20202020; |
|
127 |
((int *)cp)[1] = 0x20202020; |
|
128 |
# else |
|
159 | 129 |
cp[0] = cp[1] = cp[2] = cp[3] = ' '; |
130 |
cp[4] = cp[5] = cp[6] = cp[7] = ' '; |
|
357 | 131 |
# endif |
159 | 132 |
cp += 8; |
95 | 133 |
len -= 8; |
159 | 134 |
} |
135 |
while (len--) |
|
136 |
*cp++ = ' '; |
|
137 |
*cp = '\0'; |
|
357 | 138 |
# endif |
95 | 139 |
#endif |
159 | 140 |
RETURN (newString); |
95 | 141 |
} |
142 |
nInstVars = 0; |
|
143 |
} else { |
|
1134 | 144 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
159 | 145 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + len + 1; |
95 | 146 |
} |
147 |
||
1399 | 148 |
__PROTECT_CONTEXT__; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
149 |
__qNew(newString, instsize); |
1399 | 150 |
__UNPROTECT_CONTEXT__; |
151 |
||
159 | 152 |
if (newString == nil) goto fail; |
1134 | 153 |
__InstPtr(newString)->o_class = self; |
368 | 154 |
__qSTORE(newString, self); |
1 | 155 |
|
95 | 156 |
if (nInstVars) { |
1 | 157 |
#if defined(memset4) |
1134 | 158 |
memset4(__InstPtr(newString)->i_instvars, nil, nInstVars); |
1 | 159 |
#else |
160 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
|
159 | 161 |
/* |
162 |
* knowing that nil is 0 |
|
163 |
*/ |
|
1134 | 164 |
memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars)); |
1 | 165 |
# else |
1134 | 166 |
op = __InstPtr(newString)->i_instvars; |
159 | 167 |
do { |
168 |
*op++ = nil; |
|
169 |
} while (--nInstVars); |
|
1 | 170 |
# endif |
171 |
#endif |
|
1134 | 172 |
cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars); |
159 | 173 |
} else { |
1134 | 174 |
cp = __stringVal(newString); |
95 | 175 |
} |
1 | 176 |
|
177 |
#ifdef FAST_MEMSET |
|
159 | 178 |
memset(cp, ' ', len); |
179 |
*(cp + len) = '\0'; |
|
1 | 180 |
#else |
159 | 181 |
while (len >= 8) { |
357 | 182 |
# ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
183 |
((int *)cp)[0] = 0x20202020; |
|
184 |
((int *)cp)[1] = 0x20202020; |
|
185 |
# else |
|
159 | 186 |
cp[0] = cp[1] = cp[2] = cp[3] = ' '; |
187 |
cp[4] = cp[5] = cp[6] = cp[7] = ' '; |
|
357 | 188 |
# endif |
159 | 189 |
cp += 8; |
190 |
len -= 8; |
|
191 |
} |
|
192 |
while (len--) |
|
193 |
*cp++ = ' '; |
|
194 |
*cp = '\0'; |
|
1 | 195 |
#endif |
159 | 196 |
RETURN (newString); |
197 |
} |
|
1 | 198 |
} |
95 | 199 |
fail: ;; |
1019 | 200 |
%}. |
95 | 201 |
" |
202 |
invalid argument, or out-of-memory: |
|
203 |
use error handling in superclass |
|
204 |
" |
|
1 | 205 |
^ (super basicNew:anInteger) atAllPut:(Character space) |
206 |
! |
|
207 |
||
608 | 208 |
new:n |
209 |
^ self basicNew:n |
|
347 | 210 |
! |
211 |
||
212 |
readFrom:aStream onError:exceptionBlock |
|
213 |
"read & return the next String from the (character-)stream aStream; |
|
214 |
skipping all whitespace first; return the value of exceptionBlock, |
|
215 |
if no string can be read. The sequence of characters as read from the |
|
216 |
stream must be one as stored via storeOn: or storeString." |
|
217 |
||
218 |
|collected char| |
|
219 |
||
220 |
" |
|
221 |
this method is not to be inherited |
|
222 |
(i.e. not ok for subclasses; Symbol, for example) |
|
223 |
" |
|
224 |
self ~~ String ifTrue:[ |
|
225 |
^ super readFrom:aStream onError:exceptionBlock |
|
226 |
]. |
|
227 |
||
228 |
"skip whiteSpace" |
|
229 |
aStream skipSeparators. |
|
230 |
(aStream next == $') ifTrue:[ |
|
231 |
collected := WriteStream on:(String new). |
|
232 |
[true] whileTrue:[ |
|
233 |
aStream atEnd ifTrue:[ |
|
234 |
"/ mhmh - reached the end without a closing quote |
|
235 |
"/ looks like an error to me ... |
|
236 |
^ exceptionBlock value |
|
237 |
]. |
|
238 |
char := aStream next. |
|
239 |
char == $' ifTrue:[ |
|
240 |
"/ look for another quote |
|
241 |
aStream peek == $' ifFalse:[ |
|
242 |
^ collected contents |
|
243 |
]. |
|
244 |
aStream next. |
|
245 |
]. |
|
246 |
collected nextPut:char |
|
247 |
] |
|
248 |
]. |
|
249 |
^ exceptionBlock value |
|
250 |
||
251 |
" |
|
252 |
String readFrom:('''hello world''' readStream) |
|
253 |
String readFrom:('''hello '''' world''' readStream) |
|
254 |
String readFrom:('1 ''hello'' ' readStream) |
|
255 |
String readFrom:('1 ''hello'' ' readStream) onError:['foobar'] |
|
256 |
" |
|
608 | 257 |
! |
258 |
||
259 |
unititializedNew:anInteger |
|
260 |
"redefine it back - strings must have a 0-byte at the end" |
|
261 |
||
262 |
^ self basicNew:anInteger |
|
263 |
! ! |
|
264 |
||
265 |
!String class methodsFor:'binary storage'! |
|
266 |
||
267 |
binaryDefinitionFrom:stream manager:manager |
|
268 |
"read a binary representation from stream." |
|
269 |
||
270 |
^ (stream next:(stream nextNumber: 4)) asString |
|
271 |
! ! |
|
272 |
||
273 |
!String class methodsFor:'queries'! |
|
274 |
||
275 |
isBuiltInClass |
|
1264 | 276 |
"return true if this class is known by the run-time-system. |
277 |
Here, true is returned for myself, false for subclasses." |
|
608 | 278 |
|
279 |
^ self == String |
|
1264 | 280 |
|
281 |
"Modified: 23.4.1996 / 16:00:38 / cg" |
|
1 | 282 |
! ! |
283 |
||
284 |
!String methodsFor:'accessing'! |
|
285 |
||
329 | 286 |
at:index |
287 |
"return the character at position index, an Integer. |
|
345 | 288 |
Reimplemented here to avoid the additional at:->basicAt: send |
289 |
(which we can do here, since at: is obviously not redefined in a subclass). |
|
329 | 290 |
This method is the same as at:." |
291 |
||
292 |
%{ /* NOCONTEXT */ |
|
293 |
||
294 |
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
|
295 |
REGISTER OBJ slf, cls; |
329 | 296 |
|
297 |
if (__isSmallInteger(index)) { |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
298 |
indx = __intVal(index) - 1; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
299 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
300 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
301 |
cls = __qClass(slf); |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
302 |
if (cls != String) |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
303 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
304 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
305 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
329 | 306 |
} |
307 |
} |
|
308 |
%}. |
|
309 |
^ self subscriptBoundsError:index |
|
1 | 310 |
! |
311 |
||
329 | 312 |
at:index put:aCharacter |
313 |
"store the argument, aCharacter at position index, an Integer. |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
314 |
Return aCharacter (sigh). |
345 | 315 |
Reimplemented here to avoid the additional at:put:->basicAt:put: send |
316 |
(but only for Strings, since subclasses may redefine basicAt:put:). |
|
329 | 317 |
This method is the same as basicAt:put:." |
318 |
||
319 |
%{ /* NOCONTEXT */ |
|
320 |
||
321 |
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
|
322 |
REGISTER OBJ slf; |
329 | 323 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
324 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
325 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
326 |
if (__isString(slf)) { |
1486 | 327 |
if (__isCharacter(aCharacter)) { |
328 |
value = __intVal(_characterVal(aCharacter)); |
|
329 |
if (((unsigned)value <= 0xFF) |
|
330 |
&& __isSmallInteger(index)) { |
|
331 |
indx = __intVal(index) - 1; |
|
332 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
333 |
__stringVal(slf)[indx] = value; |
|
334 |
RETURN ( aCharacter ); |
|
335 |
} |
|
336 |
} |
|
337 |
} |
|
329 | 338 |
} |
339 |
%}. |
|
345 | 340 |
(self isMemberOf:String) ifFalse:[ |
1486 | 341 |
^ super at:index put:aCharacter |
345 | 342 |
]. |
343 |
||
329 | 344 |
(aCharacter isMemberOf:Character) ifFalse:[ |
1486 | 345 |
" |
346 |
tried to store something which is not a character |
|
347 |
" |
|
348 |
^ self elementNotCharacter |
|
329 | 349 |
]. |
350 |
(aCharacter asciiValue between:1 and:255) ifFalse:[ |
|
1486 | 351 |
" |
352 |
tried to store a multibyte character |
|
353 |
" |
|
354 |
^ self elementBoundsError |
|
329 | 355 |
]. |
356 |
" |
|
357 |
invalid index |
|
358 |
" |
|
359 |
^ self subscriptBoundsError:index |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
360 |
|
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
361 |
"Modified: 19.4.1996 / 11:40:27 / cg" |
329 | 362 |
! |
363 |
||
608 | 364 |
basicAt:index |
365 |
"return the character at position index, an Integer |
|
366 |
- reimplemented here since we return characters" |
|
367 |
||
368 |
%{ /* NOCONTEXT */ |
|
369 |
||
370 |
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
|
371 |
REGISTER OBJ slf, cls; |
608 | 372 |
|
373 |
if (__isSmallInteger(index)) { |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
374 |
indx = __intVal(index) - 1; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
375 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
376 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
377 |
cls = __qClass(slf); |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
378 |
if (cls != String) |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
379 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
380 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
381 |
RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) ); |
608 | 382 |
} |
383 |
} |
|
384 |
%}. |
|
385 |
^ self subscriptBoundsError:index |
|
386 |
! |
|
387 |
||
1 | 388 |
basicAt:index put:aCharacter |
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
389 |
"store the argument, aCharacter at position index, an Integer. |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
390 |
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
|
391 |
- reimplemented here since we store characters" |
1 | 392 |
|
393 |
%{ /* NOCONTEXT */ |
|
394 |
||
395 |
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
|
396 |
REGISTER OBJ slf; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
397 |
REGISTER OBJ cls; |
1 | 398 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
399 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
400 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
401 |
if (__isCharacter(aCharacter)) { |
1486 | 402 |
value = __intVal(_characterVal(aCharacter)); |
403 |
if (((unsigned)value <= 0xFF) |
|
404 |
&& __isSmallInteger(index)) { |
|
405 |
indx = __intVal(index) - 1; |
|
406 |
cls = __qClass(slf); |
|
407 |
if (cls != String) |
|
408 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
409 |
if ((unsigned)indx < (unsigned)(__stringSize(slf))) { |
|
410 |
__stringVal(slf)[indx] = value; |
|
411 |
RETURN ( aCharacter ); |
|
412 |
} |
|
413 |
} |
|
1 | 414 |
} |
159 | 415 |
%}. |
1 | 416 |
(aCharacter isMemberOf:Character) ifFalse:[ |
1486 | 417 |
" |
418 |
tried to store something which is not a character |
|
419 |
" |
|
420 |
^ self elementNotCharacter |
|
299 | 421 |
]. |
422 |
(aCharacter asciiValue between:1 and:255) ifFalse:[ |
|
1486 | 423 |
" |
424 |
tried to store a multibyte character |
|
425 |
" |
|
426 |
^ self elementBoundsError |
|
299 | 427 |
]. |
428 |
" |
|
429 |
invalid index |
|
430 |
" |
|
431 |
^ self subscriptBoundsError:index |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
432 |
|
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
433 |
"Modified: 19.4.1996 / 11:15:48 / cg" |
429 | 434 |
! |
435 |
||
608 | 436 |
basicSize |
437 |
"return the number of characters in myself. |
|
438 |
Redefined here to exclude the 0-byte at the end." |
|
439 |
||
440 |
%{ /* NOCONTEXT */ |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
441 |
REGISTER OBJ slf, cls; |
608 | 442 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
443 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
444 |
|
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
445 |
cls = __qClass(slf); |
608 | 446 |
if (cls == String) { |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
447 |
RETURN ( __MKSMALLINT(__stringSize(slf)) ); |
608 | 448 |
} |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
449 |
RETURN ( __MKSMALLINT(__stringSize(slf) |
1486 | 450 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
608 | 451 |
%} |
452 |
! |
|
429 | 453 |
|
608 | 454 |
size |
455 |
"return the number of characters in myself. |
|
456 |
Reimplemented here to avoid the additional size->basicSize send |
|
457 |
(which we can do here, since size is obviously not redefined in a subclass). |
|
458 |
This method is the same as basicSize." |
|
429 | 459 |
|
608 | 460 |
%{ /* NOCONTEXT */ |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
461 |
REGISTER OBJ cls, slf; |
608 | 462 |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
463 |
slf = self; |
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
464 |
cls = __qClass(slf); |
608 | 465 |
if (cls == String) { |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
466 |
RETURN ( __MKSMALLINT(__stringSize(slf)) ); |
429 | 467 |
} |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
468 |
RETURN ( __MKSMALLINT(__stringSize(slf) |
1134 | 469 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)))); |
608 | 470 |
%} |
2 | 471 |
! ! |
472 |
||
53 | 473 |
!String methodsFor:'character searching'! |
1 | 474 |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
475 |
identityIndexOf:aCharacter |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
476 |
"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
|
477 |
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
|
478 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
479 |
%{ /* NOCONTEXT */ |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
480 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
481 |
REGISTER unsigned char *cp; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
482 |
#ifdef FAST_STRCHR |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
483 |
char *strchr(); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
484 |
#else |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
485 |
REGISTER int byteValue; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
486 |
REGISTER int index; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
487 |
char c; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
488 |
#endif |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
489 |
OBJ cls; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
490 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
491 |
if (__isCharacter(aCharacter)) { |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
492 |
cp = __stringVal(self); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
493 |
if ((cls = __qClass(self)) != String) |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
494 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
495 |
#ifdef FAST_STRCHR |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
496 |
cp = (unsigned char *) strchr(cp, __intVal(_characterVal(aCharacter))); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
497 |
if (cp) { |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
498 |
RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) ); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
499 |
} |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
500 |
#else |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
501 |
byteValue = __intVal(_characterVal(aCharacter)); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
502 |
index = 1; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
503 |
while (c = *cp++) { |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
504 |
if (c == byteValue) { RETURN ( __MKSMALLINT(index) ); } |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
505 |
index++; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
506 |
} |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
507 |
#endif |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
508 |
RETURN ( __MKSMALLINT(0)); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
509 |
} |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
510 |
%}. |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
511 |
"/ with identity compares, only characters can be in myself |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
512 |
^ 0 |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
513 |
|
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
514 |
" |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
515 |
'hello world' indexOf:(Character space) |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
516 |
'hello world' indexOf:$A |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
517 |
" |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
518 |
! |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
519 |
|
1 | 520 |
includes:aCharacter |
521 |
"return true if the argument, aCharacter is included in the receiver |
|
522 |
- reimplemented here for speed" |
|
523 |
||
524 |
%{ /* NOCONTEXT */ |
|
525 |
||
526 |
REGISTER unsigned char *cp; |
|
527 |
REGISTER int byteValue; |
|
53 | 528 |
OBJ cls; |
1 | 529 |
|
53 | 530 |
if (__isCharacter(aCharacter)) { |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
531 |
byteValue = __intVal(_characterVal(aCharacter)); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
532 |
cp = __stringVal(self); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
533 |
if ((cls = __qClass(self)) != String) |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
534 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1 | 535 |
#ifdef FAST_STRCHR |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
536 |
cp = (unsigned char *) strchr(cp, __intVal(_characterVal(aCharacter))); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
537 |
if (cp) { |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
538 |
RETURN ( true ); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
539 |
} |
1 | 540 |
#else |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
541 |
while (*cp) { |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
542 |
if (*cp == byteValue) { |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
543 |
RETURN ( true ); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
544 |
} |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
545 |
cp++; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
546 |
} |
1 | 547 |
#endif |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
548 |
RETURN (false); |
1 | 549 |
} |
299 | 550 |
%}. |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
551 |
^ super includes:aCharacter |
53 | 552 |
|
95 | 553 |
" |
554 |
'hello world' includes:$a |
|
555 |
'hello world' includes:$o |
|
556 |
'hello world' includes:$x |
|
557 |
'hello world' includes:1 |
|
299 | 558 |
'hello world' asTwoByteString includes:$o |
95 | 559 |
" |
1 | 560 |
! |
561 |
||
10 | 562 |
includesAny:aCollection |
563 |
"return true, if the receiver includes any of the characters in the |
|
53 | 564 |
argument, aCollection. |
565 |
- redefined for speed if the argument is a String." |
|
10 | 566 |
|
567 |
%{ /* NOCONTEXT */ |
|
568 |
||
569 |
REGISTER unsigned char *cp; |
|
570 |
REGISTER unsigned char *matchP; |
|
53 | 571 |
OBJ cls; |
10 | 572 |
|
53 | 573 |
if (__isString(aCollection)) { |
1134 | 574 |
matchP = __stringVal(aCollection); |
575 |
cp = __stringVal(self); |
|
329 | 576 |
if ((cls = __qClass(self)) != String) |
1134 | 577 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
53 | 578 |
|
159 | 579 |
while (*cp) { |
329 | 580 |
if (strchr(matchP, *cp)) { |
159 | 581 |
RETURN ( true ); |
582 |
} |
|
583 |
cp++; |
|
584 |
} |
|
585 |
RETURN ( false ); |
|
10 | 586 |
} |
587 |
%} |
|
588 |
. |
|
589 |
^ super includesAny:aCollection |
|
95 | 590 |
|
591 |
" |
|
592 |
'hello world' includesAny:'abcd' |
|
593 |
'hello world' includesAny:'xyz' |
|
594 |
'hello world' includesAny:(Array with:$a with:$b with:$d) |
|
595 |
'hello world' includesAny:(Array with:$x with:$y) |
|
596 |
'hello world' includesAny:(Array with:1 with:2) |
|
597 |
" |
|
10 | 598 |
! |
599 |
||
1 | 600 |
indexOf:aCharacter |
601 |
"return the index of the first occurrences of the argument, aCharacter |
|
602 |
in the receiver or 0 if not found - reimplemented here for speed." |
|
603 |
||
604 |
%{ /* NOCONTEXT */ |
|
605 |
||
606 |
REGISTER unsigned char *cp; |
|
2530 | 607 |
REGISTER int byteValue; |
608 |
REGISTER int index; |
|
1 | 609 |
#ifdef FAST_STRCHR |
610 |
char *strchr(); |
|
2529
f33167bc7b23
Define vars for #ifdef FAST_STRCHR.
Stefan Vogel <sv@exept.de>
parents:
2528
diff
changeset
|
611 |
#else |
370 | 612 |
char c; |
1 | 613 |
#endif |
53 | 614 |
OBJ cls; |
1 | 615 |
|
53 | 616 |
if (__isCharacter(aCharacter)) { |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
617 |
cp = __stringVal(self); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
618 |
if ((cls = __qClass(self)) != String) |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
619 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
620 |
|
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
621 |
byteValue = __intVal(_characterVal(aCharacter)); |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
622 |
if (byteValue == 0) { |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
623 |
index = strlen(cp); |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
624 |
if (index >= __stringSize(self)) { |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
625 |
index = 0; |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
626 |
} else { |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
627 |
index++; |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
628 |
} |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
629 |
RETURN ( __MKSMALLINT(index) ); |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
630 |
} |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
631 |
|
1 | 632 |
#ifdef FAST_STRCHR |
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
633 |
cp = (unsigned char *) strchr(cp, byteValue); |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
634 |
if (cp) { |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
635 |
RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) ); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
636 |
} |
1 | 637 |
#else |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
638 |
index = 1; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
639 |
while (c = *cp++) { |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
640 |
if (c == byteValue) { RETURN ( __MKSMALLINT(index) ); } |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
641 |
index++; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
642 |
} |
1 | 643 |
#endif |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
644 |
RETURN ( __MKSMALLINT(0)); |
1 | 645 |
} |
370 | 646 |
%}. |
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
647 |
^ super indexOf:aCharacter |
95 | 648 |
|
649 |
" |
|
650 |
'hello world' indexOf:(Character space) |
|
651 |
'hello world' indexOf:$A |
|
652 |
" |
|
1 | 653 |
! |
654 |
||
655 |
indexOf:aCharacter startingAt:start |
|
656 |
"return the index of the first occurrence of the argument, aCharacter |
|
657 |
in myself starting at start, anInteger or 0 if not found; |
|
658 |
- reimplemented here for speed" |
|
659 |
||
660 |
%{ /* NOCONTEXT */ |
|
661 |
||
662 |
REGISTER unsigned char *cp; |
|
663 |
REGISTER int index, byteValue; |
|
664 |
#ifdef FAST_STRCHR |
|
665 |
char *strchr(); |
|
370 | 666 |
#else |
667 |
char c; |
|
1 | 668 |
#endif |
669 |
int len; |
|
53 | 670 |
OBJ cls; |
1 | 671 |
|
252 | 672 |
if (__isSmallInteger(start)) { |
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
673 |
if (__isCharacter(aCharacter)) { |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
674 |
byteValue = __intVal(_characterVal(aCharacter)); |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
675 |
index = __intVal(start); |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
676 |
if (index <= 0) |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
677 |
index = 1; |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
678 |
if ((cls = __qClass(self)) != String) |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
679 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
680 |
len = __stringSize(self); |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
681 |
if (index <= len) { |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
682 |
cp = __stringVal(self) + index - 1; |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
683 |
|
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
684 |
if (byteValue == 0) { |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
685 |
index += strlen(cp); |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
686 |
if (index > len) { |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
687 |
index = 0; |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
688 |
} |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
689 |
RETURN ( __MKSMALLINT(index) ); |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
690 |
} |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
691 |
|
1 | 692 |
#ifdef FAST_STRCHR |
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
693 |
cp = (unsigned char *) strchr(cp, byteValue); |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
694 |
if (cp) { |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
695 |
RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) ); |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
696 |
} |
1 | 697 |
#else |
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
698 |
while (c = *cp++) { |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
699 |
if (c == byteValue) { |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
700 |
RETURN ( __MKSMALLINT(index) ); |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
701 |
} |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
702 |
index++; |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
703 |
} |
1 | 704 |
#endif |
2528
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
705 |
} |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
706 |
} |
a2a7639ab47c
allow searching for 0-byte with indexOf and indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
707 |
RETURN ( __MKSMALLINT(0) ); |
1 | 708 |
} |
370 | 709 |
%}. |
1 | 710 |
^ super indexOf:aCharacter startingAt:start |
53 | 711 |
|
95 | 712 |
" |
713 |
'hello world' indexOf:$l startingAt:1 |
|
714 |
'hello world' indexOf:$l startingAt:5 |
|
715 |
" |
|
1 | 716 |
! |
717 |
||
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
718 |
indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
719 |
"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
|
720 |
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
|
721 |
- 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
|
722 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
723 |
%{ /* NOCONTEXT */ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
724 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
725 |
REGISTER unsigned char *ccp; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
726 |
REGISTER unsigned char *cp; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
727 |
REGISTER int index; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
728 |
char *matchP; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
729 |
char c; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
730 |
int len; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
731 |
OBJ cls; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
732 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
733 |
if (__isSmallInteger(start) |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
734 |
&& __isString(aCollectionOfCharacters)) { |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
735 |
matchP = __stringVal(aCollectionOfCharacters); |
1134 | 736 |
index = __intVal(start); |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
737 |
if (index <= 0) |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
738 |
index = 1; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
739 |
if ((cls = __qClass(self)) != String) |
1134 | 740 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
741 |
len = __stringSize(self); |
|
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
742 |
if (index <= len) { |
1134 | 743 |
cp = __stringVal(self) + index - 1; |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
744 |
while (c = *cp++) { |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
745 |
for (ccp = matchP; *ccp ; ccp++) { |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
746 |
if (*ccp == c) { |
1134 | 747 |
RETURN ( __MKSMALLINT(index) ); |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
748 |
} |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
749 |
} |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
750 |
index++; |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
751 |
} |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
752 |
} |
1134 | 753 |
RETURN ( __MKSMALLINT(0) ); |
516
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
754 |
} |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
755 |
%}. |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
756 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
757 |
"/ 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
|
758 |
"/ |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
759 |
^ super indexOfAny:aCollectionOfCharacters startingAt:start |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
760 |
|
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
761 |
" |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
762 |
'hello world' indexOfAny:'eoa' startingAt:1 |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
763 |
'hello world' indexOfAny:'eoa' startingAt:6 |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
764 |
'hello world' indexOfAny:'AOE' startingAt:1 |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
765 |
" |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
766 |
! |
17a170eb1112
speedup indexOfAny:startingAt: if arg is a string
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
767 |
|
1 | 768 |
indexOfSeparatorStartingAt:start |
769 |
"return the index of the next separator character" |
|
770 |
||
771 |
%{ /* NOCONTEXT */ |
|
772 |
||
773 |
REGISTER unsigned char *cp; |
|
774 |
REGISTER char c; |
|
775 |
int len, index; |
|
53 | 776 |
OBJ cls; |
1 | 777 |
|
1134 | 778 |
index = __intVal(start); |
1 | 779 |
if (index <= 0) { |
159 | 780 |
index = 1; |
1 | 781 |
} |
329 | 782 |
if ((cls = __qClass(self)) != String) |
1134 | 783 |
index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
784 |
len = __stringSize(self); |
|
1 | 785 |
if (index > len) { |
1134 | 786 |
RETURN ( __MKSMALLINT(0) ); |
1 | 787 |
} |
1134 | 788 |
cp = __stringVal(self) + index - 1; |
1 | 789 |
while (c = *cp++) { |
329 | 790 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
159 | 791 |
if (c <= ' ') |
1 | 792 |
#endif |
159 | 793 |
if ((c == ' ') || (c == '\t') || (c == '\n') |
794 |
|| (c == '\r') || (c == '\f')) { |
|
1134 | 795 |
RETURN ( __MKSMALLINT(cp - __stringVal(self)) ); |
159 | 796 |
} |
1 | 797 |
} |
798 |
%} |
|
799 |
. |
|
800 |
^ 0 |
|
53 | 801 |
|
95 | 802 |
" |
803 |
'hello world' indexOfSeparatorStartingAt:3 |
|
804 |
'hello world' indexOfSeparatorStartingAt:7 |
|
805 |
" |
|
608 | 806 |
! |
807 |
||
808 |
occurrencesOf:aCharacter |
|
809 |
"count the occurrences of the argument, aCharacter in myself |
|
810 |
- reimplemented here for speed" |
|
811 |
||
812 |
%{ /* NOCONTEXT */ |
|
813 |
||
814 |
REGISTER unsigned char *cp; |
|
815 |
REGISTER int byteValue; |
|
816 |
REGISTER int count; |
|
817 |
OBJ cls; |
|
818 |
||
819 |
if (__isCharacter(aCharacter)) { |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
820 |
count = 0; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
821 |
byteValue = __intVal(_characterVal(aCharacter)); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
822 |
cp = __stringVal(self); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
823 |
if ((cls = __qClass(self)) != String) |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
824 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
825 |
while (*cp) { |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
826 |
if (*cp++ == byteValue) count++; |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
827 |
} |
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
828 |
RETURN ( __MKSMALLINT(count) ); |
608 | 829 |
} |
830 |
%}. |
|
1950
2378ed1ae467
must fall back to super searchers, when searching
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
831 |
^ super occurrencesOf:aCharacter |
608 | 832 |
|
833 |
" |
|
834 |
'hello world' occurrencesOf:$a |
|
835 |
'hello world' occurrencesOf:$w |
|
836 |
'hello world' occurrencesOf:$l |
|
837 |
'hello world' occurrencesOf:$x |
|
838 |
'hello world' occurrencesOf:1 |
|
839 |
" |
|
53 | 840 |
! ! |
841 |
||
608 | 842 |
!String methodsFor:'comparing'! |
2 | 843 |
|
608 | 844 |
= aString |
845 |
"Compare the receiver with the argument and return true if the |
|
846 |
receiver is equal to the argument. Otherwise return false. |
|
847 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo'). |
|
848 |
Use sameAs: to compare with case ignored." |
|
1 | 849 |
|
375 | 850 |
%{ /* NOCONTEXT */ |
851 |
||
608 | 852 |
int l1, l2; |
853 |
REGISTER OBJ s = aString; |
|
854 |
char *cp1, *cp2; |
|
855 |
OBJ cls; |
|
856 |
||
857 |
if (s == self) { |
|
858 |
RETURN ( true ); |
|
859 |
} |
|
860 |
if (! __isNonNilObject(s)) { |
|
861 |
RETURN ( false ); |
|
862 |
} |
|
1 | 863 |
|
608 | 864 |
if (((cls = __qClass(s)) == String) || (cls == Symbol) || (cls == __qClass(self))) { |
1134 | 865 |
cp1 = (char *) __stringVal(self); |
866 |
l1 = __stringSize(self); |
|
608 | 867 |
/* |
868 |
* care for instances of subclasses ... |
|
869 |
*/ |
|
870 |
if (__qClass(self) != String) { |
|
1134 | 871 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
608 | 872 |
|
873 |
cp1 += n; |
|
874 |
l1 -= n; |
|
379 | 875 |
} |
375 | 876 |
|
1134 | 877 |
cp2 = (char *) __stringVal(s); |
878 |
l2 = __stringSize(s); |
|
608 | 879 |
/* |
880 |
* care for instances of subclasses ... |
|
881 |
*/ |
|
882 |
if (cls != String) { |
|
1134 | 883 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
608 | 884 |
|
885 |
cp2 += n; |
|
886 |
l2 -= n; |
|
375 | 887 |
} |
608 | 888 |
|
889 |
if (l1 != l2) { |
|
890 |
RETURN ( false ); |
|
891 |
} |
|
892 |
RETURN ( (strncmp(cp1, cp2, l1) == 0) ? true : false ); |
|
1 | 893 |
} |
608 | 894 |
%} |
895 |
. |
|
896 |
^ super = aString |
|
1 | 897 |
|
95 | 898 |
" |
608 | 899 |
'foo' = 'Foo' |
900 |
'foo' sameAs: 'Foo' |
|
95 | 901 |
" |
1 | 902 |
! |
903 |
||
608 | 904 |
> aString |
905 |
"Compare the receiver with the argument and return true if the |
|
906 |
receiver is greater than the argument. Otherwise return false. |
|
907 |
No national variants are honored; use after: for this. |
|
908 |
In contrast to ST-80, case differences are NOT ignored, thus |
|
909 |
'foo' > 'Foo' will return true. |
|
910 |
This may change." |
|
1 | 911 |
|
375 | 912 |
%{ /* NOCONTEXT */ |
913 |
||
608 | 914 |
int len1, len2, cmp; |
915 |
REGISTER OBJ s = aString; |
|
916 |
char *cp1, *cp2; |
|
917 |
OBJ cls; |
|
1 | 918 |
|
608 | 919 |
if (__isNonNilObject(s) |
920 |
&& (((cls = __qClass(s)) == String) || (cls == Symbol) || (cls == __qClass(self)))) { |
|
1134 | 921 |
cp1 = (char *) __stringVal(self); |
922 |
len1 = __stringSize(self); |
|
608 | 923 |
|
924 |
/* |
|
925 |
* care for instances of subclasses ... |
|
926 |
*/ |
|
927 |
if (__qClass(self) != String) { |
|
1134 | 928 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
608 | 929 |
|
930 |
cp1 += n; |
|
931 |
len1 -= n; |
|
379 | 932 |
} |
375 | 933 |
|
1134 | 934 |
cp2 = (char *) __stringVal(s); |
935 |
len2 = __stringSize(s); |
|
608 | 936 |
/* |
937 |
* care for instances of subclasses ... |
|
938 |
*/ |
|
939 |
if (cls != String) { |
|
1134 | 940 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
608 | 941 |
|
942 |
cp2 += n; |
|
943 |
len2 -= n; |
|
375 | 944 |
} |
608 | 945 |
|
946 |
if (len1 <= len2) |
|
947 |
cmp = strncmp(cp1, cp2, len1); |
|
948 |
else |
|
949 |
cmp = strncmp(cp1, cp2, len2); |
|
950 |
||
951 |
if (cmp > 0) { |
|
952 |
RETURN ( true ); |
|
953 |
} |
|
954 |
if ((cmp == 0) && (len1 > len2)) { |
|
955 |
RETURN ( true ); |
|
956 |
} |
|
957 |
RETURN ( false ); |
|
1 | 958 |
} |
370 | 959 |
%}. |
608 | 960 |
^ super > aString |
961 |
! |
|
1 | 962 |
|
608 | 963 |
after:aString |
964 |
"Compare the receiver with the argument and return true if the |
|
965 |
receiver should come after the argument in a sorted list. |
|
966 |
Otherwise return false. |
|
967 |
The comparison is language specific, depending on the value of |
|
1368 | 968 |
LC_COLLATE, which is initialized from the environment. |
969 |
||
970 |
STUPID: |
|
1486 | 971 |
#after has a completely different meaning in SeqColl ..." |
1 | 972 |
|
1251 | 973 |
^ (self compareCollatingWith:aString) > 0 |
974 |
||
975 |
" |
|
976 |
'max' > 'mäx' |
|
977 |
'man' > 'mäx' |
|
978 |
'max' after:'mäx' |
|
979 |
'man' after:'mäx' |
|
980 |
" |
|
981 |
||
1368 | 982 |
"Modified: 10.5.1996 / 14:02:45 / cg" |
1251 | 983 |
! |
984 |
||
985 |
compareCollatingWith:aString |
|
986 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
987 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
988 |
The comparison is language specific, depending on the value of |
|
989 |
LC_COLLATE, which is in the shell environment." |
|
990 |
||
1 | 991 |
%{ /* NOCONTEXT */ |
992 |
||
608 | 993 |
int cmp; |
994 |
REGISTER OBJ s = aString; |
|
995 |
char *cp1, *cp2; |
|
53 | 996 |
OBJ cls; |
1 | 997 |
|
608 | 998 |
if (__isNonNilObject(s) |
999 |
&& (((cls = __qClass(s)) == String) || (cls == Symbol) || (cls == __qClass(self)))) { |
|
1486 | 1000 |
cp1 = (char *) __stringVal(self); |
608 | 1001 |
|
1486 | 1002 |
/* |
1003 |
* care for instances of subclasses ... |
|
1004 |
*/ |
|
1005 |
if (__qClass(self) != String) { |
|
1006 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
|
608 | 1007 |
|
1486 | 1008 |
cp1 += n; |
1009 |
} |
|
1 | 1010 |
|
1486 | 1011 |
cp2 = (char *) __stringVal(s); |
1012 |
/* |
|
1013 |
* care for instances of subclasses ... |
|
1014 |
*/ |
|
1015 |
if (cls != String) { |
|
1016 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
608 | 1017 |
|
1486 | 1018 |
cp2 += n; |
1019 |
} |
|
608 | 1020 |
|
1021 |
#ifdef HAS_STRCOLL |
|
1486 | 1022 |
cmp = strcoll(cp1, cp2); |
608 | 1023 |
#else |
1486 | 1024 |
cmp = strcmp(cp1, cp2); |
608 | 1025 |
#endif |
1026 |
||
1486 | 1027 |
if (cmp > 0) { |
1028 |
RETURN ( __MKSMALLINT(1) ); |
|
1029 |
} |
|
1030 |
if (cmp < 0) { |
|
1031 |
RETURN ( __MKSMALLINT(-1) ); |
|
1032 |
} |
|
1033 |
RETURN ( __MKSMALLINT(0) ); |
|
370 | 1034 |
} |
329 | 1035 |
%}. |
608 | 1036 |
" |
1037 |
currently, this operation is only defined for strings, symbols |
|
1038 |
and subclasses. |
|
1039 |
" |
|
1251 | 1040 |
^ self primitiveFailed |
1 | 1041 |
! |
1042 |
||
608 | 1043 |
~= aString |
1044 |
"Compare the receiver with the argument and return true if the |
|
1045 |
receiver is not equal to the argument. Otherwise return false. |
|
1046 |
This compare is case-sensitive (i.e. 'Foo' is NOT = 'foo')" |
|
1 | 1047 |
|
608 | 1048 |
%{ /* NOCONTEXT */ |
1049 |
||
1 | 1050 |
int l1, l2; |
608 | 1051 |
REGISTER OBJ s = aString; |
1052 |
char *cp1, *cp2; |
|
1053 |
OBJ cls; |
|
1 | 1054 |
|
608 | 1055 |
if (s == self) { |
1056 |
RETURN ( false ); |
|
1057 |
} |
|
1058 |
if (! __isNonNilObject(s)) { |
|
1059 |
RETURN ( true ); |
|
1060 |
} |
|
1061 |
if (((cls = __qClass(s)) == String) || (cls == Symbol) || (cls == __qClass(self))) { |
|
1134 | 1062 |
cp1 = (char *) __stringVal(self); |
1063 |
l1 = __stringSize(self); |
|
608 | 1064 |
/* |
1065 |
* care for instances of subclasses ... |
|
1066 |
*/ |
|
1067 |
if (__qClass(self) != String) { |
|
1134 | 1068 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
1 | 1069 |
|
608 | 1070 |
cp1 += n; |
1071 |
l1 -= n; |
|
1072 |
} |
|
1073 |
||
1134 | 1074 |
cp2 = (char *) __stringVal(s); |
1075 |
l2 = __stringSize(s); |
|
608 | 1076 |
/* |
1077 |
* care for instances of subclasses ... |
|
1078 |
*/ |
|
1079 |
if (cls != String) { |
|
1134 | 1080 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
608 | 1081 |
|
1082 |
cp2 += n; |
|
1083 |
l2 -= n; |
|
159 | 1084 |
} |
62 | 1085 |
|
608 | 1086 |
if (l1 != l2) { |
1087 |
RETURN ( true ); |
|
1088 |
} |
|
1089 |
RETURN ( (strncmp(cp1, cp2, l1) == 0) ? false : true ); |
|
1090 |
} |
|
1091 |
%} |
|
1092 |
. |
|
1093 |
^ super ~= aString |
|
1094 |
! ! |
|
1095 |
||
1096 |
!String methodsFor:'converting'! |
|
1097 |
||
1098 |
asSymbol |
|
1099 |
"return a unique symbol with the name taken from myself. |
|
1100 |
The receiver must be a String, subclass instances are (currently) |
|
1101 |
not allowed." |
|
1102 |
%{ |
|
1103 |
OBJ newSymbol; |
|
62 | 1104 |
|
608 | 1105 |
if (__qClass(self) == String) { |
2200 | 1106 |
newSymbol = __MKSYMBOL(__stringVal(self), (OBJ *)0); |
608 | 1107 |
if (newSymbol) { |
1108 |
RETURN ( newSymbol); |
|
1109 |
} |
|
1110 |
} |
|
1111 |
%}. |
|
1112 |
self class ~~ String ifTrue:[ |
|
1113 |
"/ |
|
1114 |
"/ it is only allowed to as for string symbols - no subclass instances |
|
1115 |
"/ |
|
1116 |
^ self primitiveFailed |
|
1117 |
]. |
|
1118 |
^ ObjectMemory allocationFailureSignal raise. |
|
1119 |
! |
|
1120 |
||
1121 |
asSymbolIfInterned |
|
1122 |
"if a symbol with the receivers characters is already known, return it. |
|
1123 |
Otherwise, return nil. This can be used to query for an existing |
|
1124 |
symbol and is the same as |
|
1125 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
|
1126 |
but slightly faster, since the symbol lookup operation is only |
|
1127 |
performed once. |
|
1128 |
The receiver must be a String, subclass instances are (currently) |
|
1129 |
not allowed." |
|
1 | 1130 |
|
608 | 1131 |
%{ /* NOCONTEXT */ |
1132 |
if (__qClass(self) == String) { |
|
1134 | 1133 |
RETURN ( __SYMBOL_OR_NIL(__stringVal(self))); |
608 | 1134 |
} |
1135 |
%}. |
|
1136 |
self primitiveFailed |
|
1137 |
! |
|
1138 |
||
2416 | 1139 |
decodeAsLiteralArray |
1140 |
"given a literalEncoding in the receiver, |
|
1141 |
create & return the corresponding object. |
|
1142 |
The inverse operation to #literalArrayEncoding." |
|
1143 |
||
1144 |
^ self |
|
1145 |
||
1146 |
"Created: 25.2.1997 / 19:18:19 / cg" |
|
1147 |
! |
|
1148 |
||
608 | 1149 |
literalArrayEncoding |
1246 | 1150 |
"encode myself as an array literal, from which a copy of the receiver |
1151 |
can be reconstructed with #decodeAsLiteralArray." |
|
608 | 1152 |
|
1153 |
^ self |
|
1154 |
||
1155 |
"Modified: 1.9.1995 / 02:25:45 / claus" |
|
1246 | 1156 |
"Modified: 22.4.1996 / 13:00:50 / cg" |
608 | 1157 |
! |
1158 |
||
1159 |
withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1160 |
"return a string with the characters of the receiver where all tabulator characters |
608 | 1161 |
are expanded into spaces (assuming 8-col tabs). |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1162 |
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
|
1163 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1164 |
This does handle multiline strings. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1165 |
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
|
1166 |
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
|
1167 |
|
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
1168 |
%{ /* STACK:700 */ |
608 | 1169 |
char buffer[80*8 + 10]; |
1170 |
char *srcP, *dstP, *cp0; |
|
1171 |
int idx, sz; |
|
1172 |
int any = 0; |
|
1173 |
OBJ newString; |
|
1174 |
char c; |
|
1175 |
||
1176 |
if (__qClass(self) == String) { |
|
1177 |
/* |
|
1178 |
* for small strings (< 80), do it without a prescan ... |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1179 |
* the buffer is large enough to even convert a |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1180 |
* receiver consisting fully of tabs. |
608 | 1181 |
*/ |
1182 |
if (__stringSize(self) < 80) { |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1183 |
idx = 1; |
608 | 1184 |
for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) { |
1185 |
if (c == '\t') { |
|
1186 |
any = 1; |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1187 |
while (idx % 8) { |
608 | 1188 |
idx++; |
1189 |
*dstP++ = ' '; |
|
159 | 1190 |
} |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1191 |
idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1192 |
*dstP++ = ' '; |
608 | 1193 |
} else { |
1194 |
*dstP++ = c; |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1195 |
idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1196 |
if (c == '\n') { |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1197 |
idx = 1; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1198 |
} |
608 | 1199 |
} |
1200 |
} |
|
1201 |
if (! any) RETURN(self); |
|
1202 |
*dstP = '\0'; |
|
1203 |
RETURN (__MKSTRING_L(buffer, (dstP-buffer))); |
|
1204 |
} |
|
1205 |
/* |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1206 |
* for large strings, we compute the new size, allocate a new string |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1207 |
* and expand it. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1208 |
* |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1209 |
* first, scan for size ... |
608 | 1210 |
*/ |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1211 |
idx = 1; |
608 | 1212 |
for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) { |
1213 |
if (c == '\t') { |
|
1214 |
any = 1; |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1215 |
while (idx % 8) { |
608 | 1216 |
idx++; |
1217 |
sz++; |
|
1218 |
} |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1219 |
idx++; sz ++; |
608 | 1220 |
} else { |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1221 |
sz++; idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1222 |
if (c == '\n') { |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1223 |
idx = 1; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1224 |
} |
159 | 1225 |
} |
1226 |
} |
|
608 | 1227 |
if (! any) RETURN(self); |
1 | 1228 |
|
608 | 1229 |
/* |
1230 |
* get the string |
|
1231 |
*/ |
|
1232 |
sz = OHDR_SIZE + sz + 1; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1233 |
__qNew(newString, sz); |
608 | 1234 |
if (newString != nil) { |
1134 | 1235 |
__InstPtr(newString)->o_class = String; |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1236 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1237 |
/* |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1238 |
* expand |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1239 |
*/ |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1240 |
idx = 1; |
608 | 1241 |
for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) { |
1242 |
if (c == '\t') { |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1243 |
while (idx % 8) { |
608 | 1244 |
idx++; |
1245 |
*dstP++ = ' '; |
|
1246 |
} |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1247 |
idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1248 |
*dstP++ = ' '; |
608 | 1249 |
} else { |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1250 |
*dstP++ = c; idx++; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1251 |
if (c == '\n') { |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1252 |
idx = 1; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
633
diff
changeset
|
1253 |
} |
608 | 1254 |
} |
1255 |
} |
|
1256 |
*dstP++ = '\0'; |
|
1257 |
RETURN (newString); |
|
1258 |
} |
|
1259 |
} |
|
1260 |
%}. |
|
1261 |
^ super withTabsExpanded |
|
1 | 1262 |
! ! |
1263 |
||
1264 |
!String methodsFor:'copying'! |
|
1265 |
||
1266 |
, aString |
|
2 | 1267 |
"return the concatenation of myself and the argument, aString as |
1268 |
a String. |
|
1 | 1269 |
- reimplemented here for speed" |
1270 |
||
1271 |
%{ |
|
95 | 1272 |
int l1, l2, sz; |
1 | 1273 |
char *cp1, *cp2; |
1274 |
REGISTER unsigned char *dstp; |
|
1275 |
REGISTER OBJ s = aString; |
|
329 | 1276 |
REGISTER OBJ _string = String; |
13 | 1277 |
OBJ myClass, argClass, newString; |
1 | 1278 |
|
329 | 1279 |
if (__isNonNilObject(s)) { |
1804
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1280 |
myClass = __qClass(self); |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1281 |
argClass = __qClass(s); |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1282 |
/* |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1283 |
* can do it here if both are Strings/Symbols: |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1284 |
*/ |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1285 |
if (((myClass == _string) || (myClass == Symbol)) |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1286 |
&& ((argClass == _string) || (argClass == Symbol))) { |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1287 |
cp1 = (char *) __stringVal(self); |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1288 |
l1 = __stringSize(self); |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1289 |
if (myClass != _string) { |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1290 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
1 | 1291 |
|
1804
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1292 |
cp1 += n; |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1293 |
l1 -= n; |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1294 |
} |
1 | 1295 |
|
1804
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1296 |
cp2 = (char *) __stringVal(s); |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1297 |
l2 = __stringSize(s); |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1298 |
if (argClass != _string) { |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1299 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(s))->c_ninstvars)); |
1 | 1300 |
|
1804
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1301 |
cp2 += n; |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1302 |
l2 -= n; |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1303 |
} |
1 | 1304 |
|
1804
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1305 |
sz = OHDR_SIZE + l1 + l2 + 1; |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1306 |
__qNew(newString, sz); |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1307 |
if (newString != nil) { |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1308 |
__InstPtr(newString)->o_class = String; |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1309 |
dstp = __stringVal(newString); |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1310 |
/* |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1311 |
* refetch in case of a GC |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1312 |
*/ |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1313 |
cp1 = (char *) __stringVal(self); |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1314 |
cp2 = (char *) __stringVal(aString); |
1 | 1315 |
#ifdef FAST_MEMCPY |
1804
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1316 |
bcopy(cp1, dstp, l1); |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1317 |
bcopy(cp2, dstp + l1, l2+1); |
1 | 1318 |
#else |
1319 |
# ifdef FAST_STRCPY |
|
1804
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1320 |
strcpy(dstp, cp1); |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1321 |
strcpy(dstp + l1, cp2); |
1 | 1322 |
# else |
1804
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1323 |
while ((*dstp++ = *cp1++) != '\0') ; |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1324 |
dstp--; |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1325 |
while ((*dstp++ = *cp2++) != '\0') ; |
1 | 1326 |
# endif |
1327 |
#endif |
|
1804
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1328 |
RETURN ( newString ); |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1329 |
} |
6bfcf20ed1da
oops - , should care for non-string arg.
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1330 |
} |
1 | 1331 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1332 |
%}. |
1 | 1333 |
^ super , aString |
1334 |
! |
|
1335 |
||
1336 |
concatenate:string1 and:string2 |
|
1337 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
1338 |
This is equivalent to self , string1 , string2 |
|
1339 |
- generated by compiler when such a construct is detected" |
|
1340 |
||
1341 |
|newString| |
|
1342 |
%{ |
|
95 | 1343 |
int len1, len2, len3, sz; |
1 | 1344 |
#if !defined(FAST_MEMCPY) && !defined(FAST_STRCPY) |
1345 |
REGISTER unsigned char *srcp; |
|
1346 |
#endif |
|
1347 |
REGISTER unsigned char *dstp; |
|
1348 |
||
53 | 1349 |
if ((__isString(self) || __isSymbol(self)) |
1350 |
&& (__isString(string1) || __isSymbol(string1)) |
|
1351 |
&& (__isString(string2) || __isSymbol(string2))) { |
|
1134 | 1352 |
len1 = __stringSize(self); |
1353 |
len2 = __stringSize(string1); |
|
1354 |
len3 = __stringSize(string2); |
|
95 | 1355 |
sz = OHDR_SIZE + len1 + len2 + len3 + 1; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1356 |
__qNew(newString, sz); |
159 | 1357 |
if (newString != nil) { |
1134 | 1358 |
__InstPtr(newString)->o_class = String; |
1359 |
dstp = __stringVal(newString); |
|
1 | 1360 |
#ifdef FAST_MEMCPY |
1134 | 1361 |
bcopy(__stringVal(self), dstp, len1); |
1362 |
bcopy(__stringVal(string1), dstp + len1, len2); |
|
1363 |
bcopy(__stringVal(string2), dstp + len1 + len2, len3+1); |
|
1 | 1364 |
#else |
1365 |
# ifdef FAST_STRCPY |
|
1134 | 1366 |
strcpy(dstp, __stringVal(self)); |
1367 |
strcpy(dstp + len1, __stringVal(string1)); |
|
1368 |
strcpy(dstp + len1 + len2, __stringVal(string2)); |
|
1 | 1369 |
# else |
1134 | 1370 |
srcp = __stringVal(self); |
159 | 1371 |
while ((*dstp++ = *srcp++) != '\0') ; |
1372 |
dstp--; |
|
1134 | 1373 |
srcp = __stringVal(string1); |
159 | 1374 |
while ((*dstp++ = *srcp++) != '\0') ; |
1375 |
dstp--; |
|
1134 | 1376 |
srcp = __stringVal(string2); |
159 | 1377 |
while ((*dstp++ = *srcp++) != '\0') ; |
1 | 1378 |
# endif |
1379 |
#endif |
|
159 | 1380 |
RETURN ( newString ); |
1381 |
} |
|
1 | 1382 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1383 |
%}. |
1 | 1384 |
^ super , string1 , string2 |
1385 |
! |
|
1386 |
||
1387 |
concatenate:string1 and:string2 and:string3 |
|
1388 |
"return the concatenation of myself and the string arguments. |
|
1389 |
This is equivalent to self , string1 , string2 , string3 |
|
1390 |
- generated by compiler when such a construct is detected" |
|
1391 |
||
1392 |
|newString| |
|
1393 |
%{ |
|
95 | 1394 |
int len1, len2, len3, len4, sz; |
1 | 1395 |
#if !defined(FAST_MEMCPY) && !defined(FAST_STRCPY) |
1396 |
REGISTER unsigned char *srcp; |
|
1397 |
#endif |
|
1398 |
REGISTER unsigned char *dstp; |
|
1399 |
||
53 | 1400 |
if ((__isString(self) || __isSymbol(self)) |
1401 |
&& (__isString(string1) || __isSymbol(string1)) |
|
1402 |
&& (__isString(string2) || __isSymbol(string2)) |
|
1403 |
&& (__isString(string3) || __isSymbol(string3))) { |
|
1134 | 1404 |
len1 = __stringSize(self); |
1405 |
len2 = __stringSize(string1); |
|
1406 |
len3 = __stringSize(string2); |
|
1407 |
len4 = __stringSize(string3); |
|
95 | 1408 |
sz = OHDR_SIZE + len1 + len2 + len3 + len4 + 1; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1409 |
__qNew(newString, sz); |
159 | 1410 |
if (newString != nil) { |
1134 | 1411 |
__InstPtr(newString)->o_class = String; |
1412 |
dstp = __stringVal(newString); |
|
1 | 1413 |
#ifdef FAST_MEMCPY |
1134 | 1414 |
bcopy(__stringVal(self), dstp, len1); |
1415 |
bcopy(__stringVal(string1), dstp + len1, len2); |
|
1416 |
bcopy(__stringVal(string2), dstp + len1 + len2, len3); |
|
1417 |
bcopy(__stringVal(string3), dstp + len1 + len2 + len3, len4+1); |
|
1 | 1418 |
#else |
1419 |
# ifdef FAST_STRCPY |
|
1134 | 1420 |
strcpy(dstp, __stringVal(self)); |
1421 |
strcpy(dstp + len1, __stringVal(string1)); |
|
1422 |
strcpy(dstp + len1 + len2, __stringVal(string2)); |
|
1423 |
strcpy(dstp + len1 + len2 + len3, __stringVal(string3)); |
|
1 | 1424 |
# else |
1134 | 1425 |
srcp = __stringVal(self); |
159 | 1426 |
while ((*dstp++ = *srcp++) != '\0') ; |
1427 |
dstp--; |
|
1134 | 1428 |
srcp = __stringVal(string1); |
159 | 1429 |
while ((*dstp++ = *srcp++) != '\0') ; |
1430 |
dstp--; |
|
1134 | 1431 |
srcp = __stringVal(string2); |
159 | 1432 |
while ((*dstp++ = *srcp++) != '\0') ; |
1433 |
dstp--; |
|
1134 | 1434 |
srcp = __stringVal(string3); |
159 | 1435 |
while ((*dstp++ = *srcp++) != '\0') ; |
1 | 1436 |
# endif |
1437 |
#endif |
|
159 | 1438 |
RETURN ( newString ); |
1439 |
} |
|
1 | 1440 |
} |
519
0ab6612e060b
expand tabs slightly rewritten (no real change)
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
1441 |
%}. |
1 | 1442 |
^ super , string1 , string2 , string3 |
1443 |
! |
|
1444 |
||
608 | 1445 |
copyFrom:start |
1446 |
"return the substring from start, anInteger to the end. |
|
1447 |
This method will always return a string, even if the receiver |
|
1448 |
is a subclass-instance. This might change if there is a need. |
|
1449 |
- reimplemented here for speed" |
|
1 | 1450 |
|
13 | 1451 |
%{ /* NOCONTEXT */ |
1 | 1452 |
|
608 | 1453 |
#if !defined(FAST_MEMCPY) |
1454 |
REGISTER unsigned char *srcp; |
|
1455 |
#endif |
|
1 | 1456 |
REGISTER unsigned char *dstp; |
608 | 1457 |
REGISTER int count; |
1458 |
int len, index1, sz; |
|
1459 |
OBJ newString; |
|
1460 |
||
1461 |
if (__isSmallInteger(start)) { |
|
1134 | 1462 |
len = __stringSize(self); |
1463 |
index1 = __intVal(start); |
|
608 | 1464 |
if (index1 > 0) { |
1465 |
if (__qClass(self) != String) { |
|
1134 | 1466 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
1 | 1467 |
|
608 | 1468 |
index1 += n; |
1469 |
} |
|
1470 |
if (index1 <= len) { |
|
1471 |
count = len - index1 + 1; |
|
834 | 1472 |
__PROTECT_CONTEXT__ |
608 | 1473 |
sz = OHDR_SIZE + count + 1; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1474 |
__qNew(newString, sz); |
834 | 1475 |
__UNPROTECT_CONTEXT__ |
608 | 1476 |
if (newString != nil) { |
1134 | 1477 |
__InstPtr(newString)->o_class = String; |
1478 |
dstp = __stringVal(newString); |
|
1 | 1479 |
#ifdef FAST_MEMCPY |
1134 | 1480 |
bcopy(__stringVal(self) + index1 - 1, dstp, count); |
608 | 1481 |
dstp[count] = '\0'; |
1 | 1482 |
#else |
1483 |
# ifdef FAST_STRCPY |
|
1134 | 1484 |
strncpy(dstp, __stringVal(self) + index1 - 1, count); |
608 | 1485 |
dstp[count] = '\0'; |
1 | 1486 |
# else |
1134 | 1487 |
srcp = __stringVal(self) + index1 - 1; |
608 | 1488 |
while (count--) { |
1489 |
*dstp++ = *srcp++; |
|
1490 |
} |
|
1491 |
*dstp = '\0'; |
|
1 | 1492 |
# endif |
1493 |
#endif |
|
608 | 1494 |
RETURN ( newString ); |
1495 |
} |
|
1496 |
} |
|
159 | 1497 |
} |
13 | 1498 |
} |
51 | 1499 |
%}. |
608 | 1500 |
"fall back in case of non-integer index or out-of-bound index; |
1501 |
will eventually lead to an out-of-bound signal raise" |
|
51 | 1502 |
|
608 | 1503 |
^ super copyFrom:start |
1 | 1504 |
! |
1505 |
||
1506 |
copyFrom:start to:stop |
|
1507 |
"return the substring starting at index start, anInteger and ending |
|
53 | 1508 |
at stop, anInteger. This method will always return a string, even |
1509 |
if the receiver is a subclass-instance. This might change if there is a need. |
|
1 | 1510 |
- reimplemented here for speed" |
1511 |
||
13 | 1512 |
%{ /* NOCONTEXT */ |
1513 |
||
1 | 1514 |
#if !defined(FAST_MEMCPY) |
1515 |
REGISTER unsigned char *srcp; |
|
1516 |
#endif |
|
1517 |
REGISTER unsigned char *dstp; |
|
1518 |
REGISTER int count; |
|
95 | 1519 |
int len, sz, index1, index2; |
13 | 1520 |
OBJ newString; |
1 | 1521 |
|
252 | 1522 |
if (__bothSmallInteger(start, stop)) { |
1134 | 1523 |
len = __stringSize(self); |
1524 |
index1 = __intVal(start); |
|
1525 |
index2 = __intVal(stop); |
|
1 | 1526 |
|
159 | 1527 |
if ((index1 <= index2) && (index1 > 0)) { |
329 | 1528 |
if (__qClass(self) != String) { |
1134 | 1529 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
1 | 1530 |
|
159 | 1531 |
index1 += n; |
1532 |
index2 += n; |
|
1533 |
} |
|
1534 |
if (index2 <= len) { |
|
1535 |
count = index2 - index1 + 1; |
|
1399 | 1536 |
sz = OHDR_SIZE + count + 1; |
834 | 1537 |
__PROTECT_CONTEXT__ |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1538 |
__qNew(newString, sz); |
834 | 1539 |
__UNPROTECT_CONTEXT__ |
1399 | 1540 |
|
159 | 1541 |
if (newString != nil) { |
1134 | 1542 |
__InstPtr(newString)->o_class = String; |
1543 |
dstp = __stringVal(newString); |
|
1 | 1544 |
#ifdef FAST_MEMCPY |
1134 | 1545 |
bcopy(__stringVal(self) + index1 - 1, dstp, count); |
159 | 1546 |
dstp[count] = '\0'; |
1 | 1547 |
#else |
209 | 1548 |
# ifdef FAST_STRCPY |
1134 | 1549 |
strncpy(dstp, __stringVal(self) + index1 - 1, count); |
209 | 1550 |
dstp[count] = '\0'; |
1551 |
# else |
|
1134 | 1552 |
srcp = __stringVal(self) + index1 - 1; |
159 | 1553 |
while (count--) { |
1554 |
*dstp++ = *srcp++; |
|
1555 |
} |
|
1556 |
*dstp = '\0'; |
|
209 | 1557 |
# endif |
13 | 1558 |
#endif |
159 | 1559 |
RETURN ( newString ); |
1560 |
} |
|
1561 |
} |
|
1562 |
} |
|
375 | 1563 |
/* |
1564 |
* allow empty copy |
|
1565 |
*/ |
|
1566 |
if (index1 > index2) { |
|
834 | 1567 |
__PROTECT_CONTEXT__ |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1568 |
__qNew(newString, OHDR_SIZE+1); |
834 | 1569 |
__UNPROTECT_CONTEXT__ |
375 | 1570 |
if (newString != nil) { |
1134 | 1571 |
__InstPtr(newString)->o_class = String; |
375 | 1572 |
__stringVal(newString)[0] = '\0'; |
1573 |
RETURN ( newString ); |
|
1574 |
} |
|
1575 |
} |
|
1 | 1576 |
} |
51 | 1577 |
%}. |
1578 |
"fall back in case of non-integer index or out-of-bound index; |
|
1579 |
will eventually lead to an out-of-bound signal raise" |
|
1580 |
||
1 | 1581 |
^ super copyFrom:start to:stop |
1582 |
! |
|
1583 |
||
608 | 1584 |
copyWith:aCharacter |
1585 |
"return a new string containing the receivers characters |
|
1586 |
and the single new character, aCharacter. |
|
1587 |
This is different from concatentation, which expects another string |
|
1588 |
as argument, but equivalent to copy-and-addLast. |
|
1589 |
Reimplemented here for more speed" |
|
1590 |
||
1591 |
%{ /* NOCONTEXT */ |
|
1592 |
||
1593 |
int sz; |
|
1594 |
REGISTER unsigned char *dstp; |
|
1595 |
int offs; |
|
1596 |
OBJ cls, newString; |
|
1597 |
||
1598 |
if (__isCharacter(aCharacter)) { |
|
1599 |
sz = __qSize(self) + 1; |
|
1600 |
if ((cls = __qClass(self)) != String) { |
|
1134 | 1601 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
608 | 1602 |
sz -= offs; |
1603 |
} else |
|
1604 |
offs = 0; |
|
1605 |
||
834 | 1606 |
__PROTECT_CONTEXT__ |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1607 |
__qNew(newString, sz); |
834 | 1608 |
__UNPROTECT_CONTEXT__ |
608 | 1609 |
if (newString) { |
1134 | 1610 |
__InstPtr(newString)->o_class = String; |
1611 |
dstp = __stringVal(newString); |
|
608 | 1612 |
#ifdef FAST_MEMCPY |
1613 |
sz = sz - OHDR_SIZE - 1 - 1; |
|
1134 | 1614 |
bcopy(__stringVal(self) + offs, dstp, sz); |
608 | 1615 |
dstp += sz; |
1616 |
#else |
|
1617 |
# ifdef FAST_STRCPY |
|
1134 | 1618 |
strcpy(dstp, __stringVal(self) + offs); |
608 | 1619 |
dstp += sz - OHDR_SIZE - 1 - 1; |
1620 |
# else |
|
1621 |
{ |
|
1622 |
REGISTER unsigned char *srcp; |
|
1623 |
||
1134 | 1624 |
srcp = __stringVal(self) + offs; |
608 | 1625 |
while ((*dstp = *srcp++) != '\0') |
1626 |
dstp++; |
|
1627 |
} |
|
1628 |
# endif |
|
1629 |
#endif |
|
1134 | 1630 |
*dstp++ = __intVal(_characterVal(aCharacter)); |
608 | 1631 |
*dstp = '\0'; |
1632 |
RETURN (newString ); |
|
1633 |
} |
|
1634 |
} |
|
1635 |
%}. |
|
1636 |
"fall back in case of non-character arg; |
|
1637 |
will eventually lead to an bad element signal raise" |
|
1638 |
||
1639 |
^ super copyWith:aCharacter |
|
1640 |
! |
|
1641 |
||
1642 |
deepCopy |
|
1643 |
"return a copy of the receiver" |
|
1644 |
||
1645 |
" |
|
1646 |
could be an instance of a subclass which needs deepCopy |
|
1647 |
of its named instvars ... |
|
1648 |
" |
|
1649 |
(self isMemberOf:String) ifTrue:[ |
|
1650 |
^ self copyFrom:1 |
|
1651 |
]. |
|
1652 |
^ super deepCopy |
|
1653 |
! |
|
1654 |
||
1655 |
deepCopyUsing:aDictionary |
|
1656 |
"return a copy of the receiver - reimplemented to be a bit faster" |
|
1657 |
||
1658 |
" |
|
1659 |
could be an instance of a subclass which needs deepCopy |
|
1660 |
of its named instvars ... |
|
1661 |
" |
|
1662 |
(self isMemberOf:String) ifTrue:[ |
|
1663 |
^ self copyFrom:1 |
|
1664 |
]. |
|
1665 |
^ super deepCopy |
|
1666 |
! |
|
1667 |
||
1668 |
shallowCopy |
|
1669 |
"return a copy of the receiver" |
|
1670 |
||
1671 |
(self isMemberOf:String) ifTrue:[ |
|
1672 |
^ self copyFrom:1 |
|
1673 |
]. |
|
1674 |
^ super shallowCopy |
|
1675 |
! |
|
1676 |
||
1677 |
simpleDeepCopy |
|
1678 |
"return a copy of the receiver" |
|
1679 |
||
1680 |
" |
|
1681 |
could be an instance of a subclass which needs deepCopy |
|
1682 |
of its named instvars ... |
|
1683 |
" |
|
1684 |
(self isMemberOf:String) ifTrue:[ |
|
1685 |
^ self copyFrom:1 |
|
1686 |
]. |
|
1687 |
^ super deepCopy |
|
1688 |
! ! |
|
1689 |
||
1690 |
!String methodsFor:'filling and replacing'! |
|
1691 |
||
1692 |
atAllPut:aCharacter |
|
1693 |
"replace all elements with aCharacter |
|
1 | 1694 |
- reimplemented here for speed" |
1695 |
||
13 | 1696 |
%{ /* NOCONTEXT */ |
1697 |
||
608 | 1698 |
#ifndef FAST_MEMSET |
1699 |
REGISTER unsigned char *dst; |
|
1700 |
REGISTER int l; |
|
1 | 1701 |
#endif |
608 | 1702 |
REGISTER int byteValue; |
1 | 1703 |
|
608 | 1704 |
if (__isCharacter(aCharacter) && __isString(self)) { |
1134 | 1705 |
byteValue = __intVal(_characterVal(aCharacter)); |
608 | 1706 |
#ifdef FAST_MEMSET |
1134 | 1707 |
memset(__stringVal(self), byteValue, __qSize(self) - OHDR_SIZE - 1); |
608 | 1708 |
#else |
1134 | 1709 |
dst = __stringVal(self); |
608 | 1710 |
l = __qSize(self) - OHDR_SIZE - 1; |
1711 |
while (l >= 8) { |
|
1712 |
dst[0] = dst[1] = dst[2] = dst[3] = byteValue; |
|
1713 |
dst[4] = dst[5] = dst[6] = dst[7] = byteValue; |
|
1714 |
dst += 8; |
|
1715 |
l -= 8; |
|
1716 |
} |
|
1717 |
while (l--) |
|
1718 |
*dst++ = byteValue; |
|
1719 |
#endif |
|
1720 |
RETURN ( self ); |
|
1721 |
} |
|
1722 |
%} |
|
1723 |
. |
|
1724 |
^ super atAllPut:aCharacter |
|
1 | 1725 |
|
608 | 1726 |
" |
1727 |
(String new:10) atAllPut:$* |
|
1728 |
String new:10 withAll:$* |
|
1729 |
" |
|
1730 |
! |
|
1731 |
||
1732 |
replaceAll:oldCharacter by:newCharacter |
|
1733 |
"replace all oldCharacters by newCharacter in the receiver" |
|
1734 |
||
1735 |
%{ /* NOCONTEXT */ |
|
1736 |
||
1737 |
REGISTER unsigned char *srcp; |
|
1738 |
REGISTER unsigned oldVal, newVal; |
|
1739 |
||
1740 |
if (__isCharacter(oldCharacter) |
|
1741 |
&& __isCharacter(newCharacter) |
|
1742 |
&& __isString(self)) { |
|
1134 | 1743 |
srcp = (unsigned char *)__stringVal(self); |
1744 |
oldVal = __intVal(_characterVal(oldCharacter)); |
|
1745 |
newVal = __intVal(_characterVal(newCharacter)); |
|
608 | 1746 |
while (*srcp) { |
1747 |
if (*srcp == oldVal) |
|
1748 |
*srcp = newVal; |
|
1749 |
srcp++; |
|
159 | 1750 |
} |
608 | 1751 |
RETURN ( self ); |
1 | 1752 |
} |
608 | 1753 |
%} |
1754 |
. |
|
1755 |
^ super replaceAll:oldCharacter by:newCharacter |
|
51 | 1756 |
|
608 | 1757 |
" |
1758 |
'helloWorld' copy replaceAll:$o by:$O |
|
1759 |
" |
|
1760 |
! |
|
1 | 1761 |
|
1762 |
replaceFrom:start to:stop with:aString startingAt:repStart |
|
1763 |
"replace the characters starting at index start, anInteger and ending |
|
1764 |
at stop, anInteger with characters from aString starting at repStart. |
|
1765 |
||
1766 |
- reimplemented here for speed" |
|
1767 |
||
1768 |
%{ /* NOCONTEXT */ |
|
1769 |
||
1770 |
REGISTER unsigned char *srcp, *dstp; |
|
1771 |
REGISTER int count; |
|
1772 |
int len, index1, index2; |
|
1773 |
int repLen, repIndex; |
|
1774 |
||
53 | 1775 |
if ((__isString(aString) || __isSymbol(aString)) |
1776 |
&& __isString(self) |
|
252 | 1777 |
&& __bothSmallInteger(start, stop)) { |
1134 | 1778 |
len = __stringSize(self); |
1779 |
index1 = __intVal(start); |
|
1780 |
index2 = __intVal(stop); |
|
159 | 1781 |
count = index2 - index1 + 1; |
1782 |
if (count <= 0) { |
|
1783 |
RETURN (self); |
|
1784 |
} |
|
1785 |
if ((index2 <= len) && (index1 > 0)) { |
|
1134 | 1786 |
repLen = __stringSize(aString); |
1787 |
repIndex = __intVal(repStart); |
|
159 | 1788 |
if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) { |
1134 | 1789 |
srcp = __stringVal(aString) + repIndex - 1; |
1790 |
dstp = __stringVal(self) + index1 - 1; |
|
159 | 1791 |
if (aString == self) { |
1792 |
/* take care of overlapping copy */ |
|
1793 |
if (srcp < dstp) { |
|
1794 |
/* must do a reverse copy */ |
|
1795 |
srcp += count; |
|
1796 |
dstp += count; |
|
1797 |
while (count-- > 0) { |
|
1798 |
*--dstp = *--srcp; |
|
1799 |
} |
|
1800 |
RETURN (self); |
|
1801 |
} |
|
1802 |
} |
|
1 | 1803 |
#ifdef FAST_MEMCPY |
159 | 1804 |
bcopy(srcp, dstp, count); |
1 | 1805 |
#else |
159 | 1806 |
while (count-- > 0) { |
1807 |
*dstp++ = *srcp++; |
|
1808 |
} |
|
1 | 1809 |
#endif |
159 | 1810 |
RETURN (self); |
1811 |
} |
|
1812 |
} |
|
1 | 1813 |
} |
1814 |
%} |
|
1815 |
. |
|
1816 |
^ super replaceFrom:start to:stop with:aString startingAt:repStart |
|
1817 |
! |
|
1818 |
||
1819 |
reverse |
|
53 | 1820 |
"in-place reverse the characters of the string." |
1821 |
||
1822 |
"Q: is there a need to redefine it here ?" |
|
1 | 1823 |
|
1824 |
%{ /* NOCONTEXT */ |
|
1825 |
||
1826 |
REGISTER char c; |
|
1827 |
REGISTER unsigned char *hip, *lowp; |
|
1828 |
||
53 | 1829 |
if (__isString(self)) { |
1134 | 1830 |
lowp = __stringVal(self); |
1831 |
hip = lowp + __stringSize(self) - 1; |
|
159 | 1832 |
while (lowp < hip) { |
1833 |
c = *lowp; |
|
1834 |
*lowp = *hip; |
|
1835 |
*hip = c; |
|
1836 |
lowp++; |
|
1837 |
hip--; |
|
1838 |
} |
|
1839 |
RETURN ( self ); |
|
1 | 1840 |
} |
1841 |
%} |
|
1842 |
. |
|
1843 |
^ super reverse |
|
1844 |
! |
|
1845 |
||
1846 |
withoutSeparators |
|
95 | 1847 |
"return a copy of myself without leading and trailing whitespace. |
1848 |
Notice, this is different from String>>withoutSpaces." |
|
1 | 1849 |
|
42 | 1850 |
|startIndex "{ Class: SmallInteger }" |
51 | 1851 |
endIndex "{ Class: SmallInteger }" |
1852 |
sz| |
|
1853 |
||
53 | 1854 |
startIndex := 0. |
51 | 1855 |
%{ |
1856 |
REGISTER unsigned char *cp0; |
|
1857 |
REGISTER unsigned char *cp; |
|
1858 |
REGISTER unsigned char c; |
|
1 | 1859 |
|
51 | 1860 |
/* ignore instances of subclasses ... */ |
329 | 1861 |
if (__qClass(self) == String) { |
1134 | 1862 |
cp = cp0 = __stringVal(self); |
379 | 1863 |
while ((c = *cp) |
329 | 1864 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
379 | 1865 |
&& (c <= ' ') |
329 | 1866 |
#endif |
379 | 1867 |
&& ((c == ' ') || (c == '\n') || (c == '\t') |
329 | 1868 |
|| (c == '\r') || (c == '\f')) |
1869 |
) { |
|
159 | 1870 |
cp++; |
1871 |
} |
|
1134 | 1872 |
startIndex = __MKSMALLINT(cp - cp0 + 1); |
159 | 1873 |
cp = cp + strlen(cp) - 1; |
1874 |
while ((cp >= cp0) && (*cp == ' ')) cp--; |
|
1875 |
c = *cp; |
|
1876 |
while ((cp >= cp0) && |
|
329 | 1877 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
1878 |
(c <= ' ') && |
|
1879 |
#endif |
|
159 | 1880 |
((c == ' ') || (c == '\n') || (c == '\t') |
1881 |
|| (c == '\r') || (c == '\f'))) { |
|
1882 |
cp--; |
|
1883 |
c = *cp; |
|
1884 |
} |
|
1134 | 1885 |
endIndex = __MKSMALLINT(cp - cp0 + 1); |
51 | 1886 |
} |
202 | 1887 |
%}. |
1888 |
startIndex == 0 ifTrue:[^ super withoutSeparators]. |
|
1889 |
||
1890 |
startIndex > endIndex ifTrue:[^ '']. |
|
1891 |
((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self]. |
|
1 | 1892 |
^ self copyFrom:startIndex to:endIndex |
608 | 1893 |
! |
1894 |
||
1895 |
withoutSpaces |
|
1896 |
"return a copy of myself without leading and trailing spaces. |
|
1897 |
Notice, this is different from String>>withoutSeparators." |
|
1898 |
||
1899 |
|startIndex "{ Class: SmallInteger }" |
|
1900 |
endIndex "{ Class: SmallInteger }" |
|
1901 |
sz blank| |
|
1902 |
||
1903 |
startIndex := 0. |
|
1904 |
%{ |
|
1905 |
REGISTER unsigned char *cp0; |
|
1906 |
REGISTER unsigned char *cp; |
|
1907 |
||
1908 |
/* ignore instances of subclasses ... */ |
|
1909 |
if (__qClass(self) == String) { |
|
1134 | 1910 |
cp = cp0 = __stringVal(self); |
608 | 1911 |
while (*cp == ' ') cp++; |
1134 | 1912 |
startIndex = __MKSMALLINT(cp - cp0 + 1); |
608 | 1913 |
cp = cp + strlen(cp) - 1; |
1914 |
while ((cp >= cp0) && (*cp == ' ')) cp--; |
|
1134 | 1915 |
endIndex = __MKSMALLINT(cp - cp0 + 1); |
608 | 1916 |
} |
1917 |
%}. |
|
1918 |
startIndex == 0 ifTrue:[^ super withoutSpaces]. |
|
1919 |
||
1920 |
startIndex > endIndex ifTrue:[^ '']. |
|
1921 |
((startIndex == 1) and:[endIndex == self size]) ifTrue:[^ self]. |
|
1922 |
^ self copyFrom:startIndex to:endIndex |
|
1923 |
! ! |
|
1924 |
||
1925 |
!String methodsFor:'printing & storing'! |
|
1926 |
||
1927 |
isLiteral |
|
1928 |
"return true, if the receiver can be used as a literal |
|
1929 |
(i.e. can be used in constant arrays)" |
|
1930 |
||
1931 |
^ true |
|
1932 |
! |
|
1933 |
||
1934 |
||
1935 |
"print the receiver on standard output. |
|
1936 |
This method does NOT use the stream classes and will therefore work |
|
1937 |
even in case of emergency." |
|
1938 |
||
1939 |
%{ /* NOCONTEXT */ |
|
1940 |
||
1941 |
if (__qClass(self) == String) { |
|
1486 | 1942 |
#ifdef WIN32 |
1943 |
printf("%s" , __stringVal(self)); |
|
1944 |
#else |
|
1134 | 1945 |
fputs(__stringVal(self), stdout); fflush(stdout); |
1486 | 1946 |
#endif |
608 | 1947 |
RETURN (self); |
1948 |
} |
|
1949 |
%} |
|
1950 |
. |
|
1951 |
^ super print |
|
1952 |
! |
|
1953 |
||
1954 |
printfPrintString:formatString |
|
1955 |
"non-portable but sometimes useful. |
|
1956 |
Return a printed representation of the receiver as specified by formatString, |
|
1957 |
which is defined by printf. |
|
1958 |
No checking on buffer overrun is done; the resulting string may not |
|
1959 |
be larger than 799 characters. |
|
1960 |
This method is NONSTANDARD and may be removed without notice." |
|
1961 |
||
1962 |
%{ /* STACK: 1000 */ |
|
1963 |
||
1964 |
char buffer[800]; |
|
1965 |
char *cp; |
|
1966 |
OBJ s; |
|
1967 |
||
1968 |
if (__isString(formatString)) { |
|
1969 |
/* |
|
1970 |
* actually only needed on sparc: since thisContext is |
|
1971 |
* in a global register, which gets destroyed by printf, |
|
1972 |
* manually save it here - very stupid ... |
|
1973 |
*/ |
|
1974 |
||
1134 | 1975 |
cp = (char *)__stringVal(self); |
608 | 1976 |
if (__qClass(self) != String) |
1134 | 1977 |
cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
608 | 1978 |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
1979 |
__BEGIN_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
1980 |
|
1134 | 1981 |
sprintf(buffer, (char *)__stringVal(formatString), cp); |
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
1982 |
|
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
1983 |
__END_PROTECT_REGISTERS__ |
608 | 1984 |
|
833 | 1985 |
s = __MKSTRING(buffer COMMA_SND); |
608 | 1986 |
if (s != nil) { |
1987 |
RETURN (s); |
|
1988 |
} |
|
1989 |
} |
|
1990 |
%}. |
|
1991 |
self primitiveFailed |
|
1992 |
||
1993 |
" |
|
1994 |
'hello' printfPrintString:'%%s -> %s' |
|
1995 |
'hello' printfPrintString:'%%10s -> %10s' |
|
1996 |
'hello' printfPrintString:'%%-10s -> %-10s' |
|
1997 |
" |
|
1998 |
! |
|
1999 |
||
2000 |
storeOn:aStream |
|
2001 |
"put the storeString of myself on aStream" |
|
2002 |
||
2003 |
aStream nextPut: $'. |
|
2004 |
(self includes:$') ifTrue:[ |
|
2005 |
self do:[:thisChar | |
|
2006 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
2007 |
aStream nextPut:thisChar |
|
2008 |
] |
|
2009 |
] ifFalse:[ |
|
2010 |
aStream nextPutAll:self |
|
2011 |
]. |
|
2012 |
aStream nextPut:$' |
|
2013 |
! |
|
2014 |
||
2015 |
storeString |
|
2016 |
"return a String for storing myself" |
|
2017 |
||
2018 |
|s n index| |
|
2019 |
||
2020 |
n := self occurrencesOf:$'. |
|
2021 |
n == 0 ifFalse:[ |
|
2022 |
s := String new:(n + 2 + self size). |
|
2023 |
s at:1 put:$'. |
|
2024 |
index := 2. |
|
2025 |
self do:[:thisChar | |
|
2026 |
(thisChar == $') ifTrue:[ |
|
2027 |
s at:index put:thisChar. |
|
2028 |
index := index + 1. |
|
2029 |
]. |
|
2030 |
s at:index put:thisChar. |
|
2031 |
index := index + 1. |
|
2032 |
]. |
|
2033 |
s at:index put:$'. |
|
2034 |
^ s |
|
2035 |
]. |
|
2036 |
^ '''' , self , '''' |
|
1 | 2037 |
! ! |
2038 |
||
2039 |
!String methodsFor:'queries'! |
|
2040 |
||
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2041 |
bitsPerCharacter |
1239 | 2042 |
"return the number of bits each character has. |
2043 |
Here, 8 is returned (storing single byte characters)." |
|
2044 |
||
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2045 |
^ 8 |
1239 | 2046 |
|
2047 |
"Modified: 20.4.1996 / 23:08:42 / cg" |
|
1218
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2048 |
! |
5ed62714c8d1
commentary; ignoredMethods removed
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2049 |
|
68 | 2050 |
isEmpty |
2051 |
"return true if the receiver is empty (i.e. if size == 0) |
|
2052 |
Redefined here for performance" |
|
2053 |
||
2054 |
%{ /* NOCONTEXT */ |
|
2055 |
OBJ cls; |
|
2056 |
||
329 | 2057 |
cls = __qClass(self); |
68 | 2058 |
if ((cls == String) || (cls == Symbol)) { |
1134 | 2059 |
RETURN ( (__stringSize(self) == 0) ? true : false); |
68 | 2060 |
} |
2061 |
%} |
|
2062 |
. |
|
2063 |
^ super isEmpty |
|
608 | 2064 |
! |
2065 |
||
2066 |
knownAsSymbol |
|
2067 |
"return true, if there is a symbol with same characters in the |
|
2068 |
system - use to check for existance of a symbol without creating one" |
|
2069 |
||
2070 |
%{ /* NOCONTEXT */ |
|
1134 | 2071 |
RETURN ( __KNOWNASSYMBOL(__stringVal(self)) ); |
608 | 2072 |
%} |
1 | 2073 |
! ! |
608 | 2074 |
|
2075 |
!String methodsFor:'testing'! |
|
2076 |
||
1380 | 2077 |
endsWith:aString |
2078 |
"return true, if the receiver end with something, aString." |
|
2079 |
||
2080 |
%{ /* NOCONTEXT */ |
|
2081 |
||
2082 |
int len1, len2; |
|
2083 |
REGISTER unsigned char *src1, *src2; |
|
2084 |
char c; |
|
2085 |
||
2086 |
if ((__isString(self) || __isSymbol(self)) |
|
2087 |
&& (__isString(aString) || __isSymbol(aString))) { |
|
2088 |
len1 = __qSize(self); |
|
2089 |
len2 = __qSize(aString); |
|
2090 |
if (len1 < len2) { |
|
2091 |
RETURN ( false ); |
|
2092 |
} |
|
2093 |
||
2094 |
src1 = __stringVal(self) + len1 - len2; |
|
2095 |
src2 = __stringVal(aString); |
|
2096 |
while (c = *src2++) { |
|
2097 |
if (c != *src1++) { |
|
2098 |
RETURN ( false ); |
|
2099 |
} |
|
2100 |
} |
|
2101 |
RETURN (true); |
|
2102 |
} |
|
2103 |
%}. |
|
2104 |
(aString isMemberOf:Character) ifTrue:[ |
|
2105 |
self size == 0 ifTrue:[^ false]. |
|
2106 |
^ (self at:(self size)) == aString |
|
2107 |
]. |
|
2108 |
^ super endsWith:aString |
|
2109 |
||
2110 |
" |
|
2111 |
'hello world' endsWith:'world' |
|
2112 |
'hello world' endsWith:'earth' |
|
2113 |
'hello world' endsWith:$d |
|
2114 |
'hello world' endsWith:#($r $l $d) |
|
2115 |
" |
|
2116 |
! |
|
2117 |
||
608 | 2118 |
isBlank |
2119 |
"return true, if the receivers size is 0 or if it contains only spaces. |
|
2120 |
Q: should we care for whiteSpace in general here ?" |
|
2121 |
||
2122 |
%{ /* NOCONTEXT */ |
|
2123 |
||
2124 |
REGISTER unsigned char *src; |
|
2125 |
REGISTER unsigned char c; |
|
2126 |
OBJ cls; |
|
2127 |
||
1134 | 2128 |
src = __stringVal(self); |
608 | 2129 |
if ((cls = __qClass(self)) != String) |
1134 | 2130 |
src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
608 | 2131 |
|
2132 |
#ifndef NON_ASCII |
|
2133 |
while (*((unsigned *)src) == 0x20202020) { |
|
2134 |
src += 4; |
|
2135 |
} |
|
2136 |
#endif |
|
2137 |
while (c = *src++) |
|
2138 |
if (c != ' ') { |
|
2139 |
RETURN ( false ); |
|
2140 |
} |
|
2141 |
%}. |
|
2142 |
^ true |
|
2143 |
! |
|
2144 |
||
2145 |
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight |
|
2146 |
"parametrized levenshtein. arguments are the costs for |
|
2147 |
substitution, case-change, insertion and deletion of a character." |
|
2148 |
||
1138
993e6ffdbf51
removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents:
1134
diff
changeset
|
2149 |
%{ /* STACK: 2000 */ |
608 | 2150 |
|
2151 |
/* |
|
2152 |
* this is very heavy used when correcting errors |
|
2153 |
* (all symbols are searched for best match) - therefore it must be fast |
|
2154 |
*/ |
|
2155 |
{ |
|
2156 |
unsigned short *data; |
|
2157 |
int l1, l2; |
|
2158 |
REGISTER int sz; |
|
2159 |
unsigned char *s1, *s2; |
|
2160 |
int v1, v2, v3, m; |
|
2161 |
REGISTER unsigned short *dp; |
|
2162 |
REGISTER int delta; |
|
2163 |
REGISTER int j; |
|
2164 |
int i; |
|
2165 |
int iW, cW, sW, dW; |
|
1486 | 2166 |
# define FASTSIZE 30 /* increase STACK if you increase this ... */ |
608 | 2167 |
unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)]; |
2168 |
||
2169 |
if ((__isString(self) || __isSymbol(self)) |
|
2170 |
&& (__isString(aString) || __isSymbol(aString)) |
|
2171 |
&& __bothSmallInteger(insrtWeight, caseWeight) |
|
2172 |
&& __bothSmallInteger(substWeight, deleteWeight)) { |
|
1134 | 2173 |
iW = __intVal(insrtWeight); |
2174 |
cW = __intVal(caseWeight); |
|
2175 |
sW = __intVal(substWeight); |
|
2176 |
dW = __intVal(deleteWeight); |
|
2177 |
s1 = __stringVal(self); |
|
2178 |
s2 = __stringVal(aString); |
|
608 | 2179 |
l1 = strlen(s1); |
2180 |
l2 = strlen(s2); |
|
2181 |
||
2182 |
sz = (l1 < l2) ? l2 : l1; |
|
2183 |
delta = sz + 1; |
|
2184 |
if (sz <= FASTSIZE) { |
|
2185 |
data = fastData; |
|
2186 |
} else { |
|
2187 |
/* add ifdef ALLOCA here ... */ |
|
2188 |
data = (unsigned short *)malloc(delta * delta * sizeof(short)); |
|
2189 |
if (! data) goto mallocFailed; |
|
2190 |
} |
|
2191 |
||
2192 |
data[0] = 0; |
|
2193 |
dp = data+1; |
|
2194 |
for (j=1, dp=data+1; j<=sz; j++, dp++) |
|
2195 |
*dp = *(dp-1) + iW; |
|
2196 |
||
2197 |
for (i=1, dp=data+delta; i<=sz; i++, dp+=delta) |
|
2198 |
*dp = *(dp-delta) + dW; |
|
2199 |
||
2200 |
for (i=1; i<=l1; i++) { |
|
2201 |
for (j=1; j<=l2; j++) { |
|
2202 |
dp = data + (i*delta) + j; |
|
2203 |
if (s1[i] != s2[j]) { |
|
2204 |
if (tolower(s1[i]) == tolower(s2[j])) { |
|
2205 |
m = cW; |
|
2206 |
} else { |
|
2207 |
m = sW; |
|
2208 |
} |
|
2209 |
} else |
|
2210 |
m = 0; |
|
2211 |
||
2212 |
v2 = *(dp - 1) + iW; |
|
2213 |
v3 = *(dp - delta) + dW; |
|
2214 |
v1 = *(dp - delta - 1) + m; |
|
2215 |
if (v1 < v2) |
|
2216 |
if (v1 < v3) |
|
2217 |
m = v1; |
|
2218 |
else |
|
2219 |
m = v3; |
|
2220 |
else |
|
2221 |
if (v2 < v3) |
|
2222 |
m = v2; |
|
2223 |
else |
|
2224 |
m = v3; |
|
2225 |
*dp = m; |
|
2226 |
} |
|
2227 |
} |
|
2228 |
m = data[l1 * delta + l2]; |
|
2229 |
if (sz > FASTSIZE) |
|
2230 |
free(data); |
|
1134 | 2231 |
RETURN ( __MKSMALLINT(m) ); |
608 | 2232 |
} |
2233 |
mallocFailed: ; |
|
2234 |
} |
|
2235 |
%}. |
|
2236 |
||
2237 |
^ super levenshteinTo:aString |
|
2238 |
s:substWeight c:caseWeight |
|
2239 |
i:insrtWeight d:deleteWeight |
|
2240 |
||
2241 |
"'ocmprt' levenshteinTo:'computer' |
|
2242 |
'computer' levenshteinTo:'computer' |
|
2243 |
'ocmputer' levenshteinTo:'computer' |
|
2244 |
'cmputer' levenshteinTo:'computer' |
|
2245 |
'Computer' levenshteinTo:'computer'" |
|
1380 | 2246 |
! |
2247 |
||
2248 |
startsWith:aString |
|
2249 |
"return true, if the receiver starts with something, aString." |
|
2250 |
||
2251 |
%{ /* NOCONTEXT */ |
|
2252 |
||
2253 |
int len1, len2; |
|
2254 |
REGISTER unsigned char *src1, *src2; |
|
2255 |
char c; |
|
2256 |
||
2257 |
if ((__isString(self) || __isSymbol(self)) |
|
2258 |
&& (__isString(aString) || __isSymbol(aString))) { |
|
2369
df5fa692a261
slightly faster startsWith:, if 1st char is different
Claus Gittinger <cg@exept.de>
parents:
2200
diff
changeset
|
2259 |
src1 = __stringVal(self); |
df5fa692a261
slightly faster startsWith:, if 1st char is different
Claus Gittinger <cg@exept.de>
parents:
2200
diff
changeset
|
2260 |
src2 = __stringVal(aString); |
df5fa692a261
slightly faster startsWith:, if 1st char is different
Claus Gittinger <cg@exept.de>
parents:
2200
diff
changeset
|
2261 |
if (src1[0] != src2[0]) { |
df5fa692a261
slightly faster startsWith:, if 1st char is different
Claus Gittinger <cg@exept.de>
parents:
2200
diff
changeset
|
2262 |
RETURN ( false ); |
df5fa692a261
slightly faster startsWith:, if 1st char is different
Claus Gittinger <cg@exept.de>
parents:
2200
diff
changeset
|
2263 |
} |
df5fa692a261
slightly faster startsWith:, if 1st char is different
Claus Gittinger <cg@exept.de>
parents:
2200
diff
changeset
|
2264 |
|
1380 | 2265 |
len1 = __qSize(self); |
2266 |
len2 = __qSize(aString); |
|
2267 |
if (len1 < len2) { |
|
2268 |
RETURN ( false ); |
|
2269 |
} |
|
2270 |
||
2271 |
while (c = *src2++) { |
|
2369
df5fa692a261
slightly faster startsWith:, if 1st char is different
Claus Gittinger <cg@exept.de>
parents:
2200
diff
changeset
|
2272 |
if (c != *src1) { |
1380 | 2273 |
RETURN ( false ); |
2274 |
} |
|
2369
df5fa692a261
slightly faster startsWith:, if 1st char is different
Claus Gittinger <cg@exept.de>
parents:
2200
diff
changeset
|
2275 |
src1++; |
1380 | 2276 |
} |
2277 |
RETURN (true); |
|
2278 |
} |
|
2279 |
%}. |
|
2280 |
(aString isMemberOf:Character) ifTrue:[ |
|
2281 |
self size == 0 ifTrue:[^ false]. |
|
2282 |
^ (self at:1) == aString |
|
2283 |
]. |
|
2284 |
^ super startsWith:aString |
|
2285 |
||
2286 |
" |
|
2287 |
'hello world' startsWith:'hello' |
|
2288 |
'hello world' startsWith:'hi' |
|
2289 |
'hello world' startsWith:$h |
|
2290 |
'hello world' startsWith:#($h $e $l) |
|
2291 |
" |
|
608 | 2292 |
! ! |
2293 |
||
633 | 2294 |
!String class methodsFor:'documentation'! |
2295 |
||
2296 |
version |
|
2530 | 2297 |
^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.91 1997-04-07 11:57:04 stefan Exp $' |
633 | 2298 |
! ! |