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