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