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