author | Claus Gittinger <cg@exept.de> |
Wed, 07 Oct 2009 19:36:31 +0200 | |
changeset 12170 | 0a05269657de |
parent 12111 | 4b1ac266f7aa |
child 12171 | 7cda74bef54a |
permissions | -rw-r--r-- |
64 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
9192 | 3 |
All Rights Reserved |
64 | 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 |
" |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
13 |
|
3926 | 14 |
ByteArray variableByteSubclass:#CharacterArray |
9192 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'PreviousMatch DecoderTables EncoderTables DecodingFailedSignal |
|
11348
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
17 |
EncodingFailedSignal LastString LastShiftTable' |
9192 | 18 |
poolDictionaries:'' |
19 |
category:'Collections-Text' |
|
64 | 20 |
! |
21 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
22 |
!CharacterArray class methodsFor:'documentation'! |
64 | 23 |
|
82 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
9192 | 27 |
All Rights Reserved |
82 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
64 | 38 |
documentation |
39 |
" |
|
255 | 40 |
CharacterArray is a superclass for all kinds of Strings (i.e. |
68 | 41 |
(singleByte-)Strings, TwoByteStrings and whatever comes in the future. |
154 | 42 |
|
8874 | 43 |
This class is abstract, meaning that there are no instances of it. |
2537 | 44 |
All this class does is provide common protocol for concrete subclasses. |
1290 | 45 |
|
46 |
[author:] |
|
9192 | 47 |
Claus Gittinger |
1290 | 48 |
|
49 |
[see also:] |
|
9192 | 50 |
String TwoByteString |
51 |
StringCollection |
|
64 | 52 |
" |
53 |
! ! |
|
54 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
55 |
!CharacterArray class methodsFor:'initialization'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
56 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
57 |
initialize |
8874 | 58 |
DecodingFailedSignal isNil ifTrue:[ |
9192 | 59 |
DecodingFailedSignal := DecodingError. |
60 |
DecodingFailedSignal notifierString:'error during decode'. |
|
61 |
||
62 |
EncodingFailedSignal :=EncodingError. |
|
63 |
EncodingFailedSignal notifierString:'error during encode'. |
|
5440 | 64 |
] |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
65 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
66 |
" |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
67 |
CharacterArray initialize |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
68 |
" |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
69 |
|
2833 | 70 |
"Modified: 3.8.1997 / 18:15:59 / cg" |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
71 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
72 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
73 |
!CharacterArray class methodsFor:'instance creation'! |
64 | 74 |
|
75 |
basicNew |
|
76 |
"return a new empty string" |
|
77 |
||
78 |
^ self basicNew:0 |
|
79 |
! |
|
80 |
||
2734 | 81 |
fromBytes:aByteCollection |
82 |
"return an instance of the receiver class, |
|
83 |
taking untranslated bytes from the argument, aByteCollection. |
|
84 |
Only useful, when reading twoByteStrings from external sources." |
|
85 |
||
86 |
|mySize nBytes newString dstIdx| |
|
87 |
||
88 |
nBytes := aByteCollection size. |
|
89 |
mySize := self basicNew bitsPerCharacter. |
|
90 |
mySize == 16 ifTrue:[ |
|
9192 | 91 |
newString := self basicNew:(nBytes // 2). |
92 |
dstIdx := 1. |
|
93 |
aByteCollection pairWiseDo:[:hi :lo | |
|
94 |
newString at:dstIdx put:(Character value:(hi bitShift:8)+lo). |
|
95 |
dstIdx := dstIdx + 1 |
|
96 |
]. |
|
97 |
^ newString. |
|
2734 | 98 |
]. |
99 |
||
100 |
^ (self basicNew:nBytes) replaceFrom:1 with:aByteCollection |
|
101 |
||
102 |
" |
|
103 |
TwoByteString fromBytes:#[16r21 16r21] |
|
104 |
" |
|
105 |
||
106 |
"Modified: 30.6.1997 / 20:08:37 / cg" |
|
107 |
! |
|
108 |
||
64 | 109 |
fromString:aString |
110 |
"return a copy of the argument, aString" |
|
111 |
||
68 | 112 |
^ (self basicNew:(aString size)) replaceFrom:1 with:aString |
113 |
||
114 |
"TwoByteString fromString:'hello'" |
|
581 | 115 |
! |
116 |
||
117 |
fromStringCollection:aCollectionOfStrings |
|
118 |
"return new string formed by concatenating a copy of the argument, aString" |
|
119 |
||
120 |
^ self fromStringCollection:aCollectionOfStrings separatedBy:'' |
|
121 |
||
122 |
" |
|
123 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') |
|
124 |
" |
|
125 |
||
126 |
"Created: 20.11.1995 / 15:26:59 / cg" |
|
127 |
! |
|
128 |
||
129 |
fromStringCollection:aCollectionOfStrings separatedBy:aSeparatorString |
|
130 |
"return new string formed by concatenating a copy of the argument, aString" |
|
131 |
||
132 |
|newString first| |
|
133 |
||
134 |
newString := ''. |
|
135 |
first := true. |
|
8874 | 136 |
aCollectionOfStrings do:[:s | |
9192 | 137 |
first ifFalse:[ |
138 |
newString := newString , aSeparatorString |
|
139 |
] ifTrue:[ |
|
140 |
first := false |
|
141 |
]. |
|
142 |
newString := newString , s |
|
581 | 143 |
]. |
144 |
^ newString |
|
145 |
||
146 |
" |
|
147 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:' ' |
|
148 |
" |
|
149 |
||
150 |
"Created: 20.11.1995 / 15:32:17 / cg" |
|
608 | 151 |
! |
152 |
||
5757 | 153 |
fromUTF8Bytes:aByteCollection |
5758 | 154 |
"return a new string which represents the characters as decoded |
155 |
from the utf8 encoded bytes, aByteCollection. |
|
156 |
Returns either a normal String, or a TwoByteString instance. |
|
6810 | 157 |
Only useful, when reading twoByteStrings from external sources. |
158 |
This only handles up-to 16bit characters" |
|
5757 | 159 |
|
7876 | 160 |
^ self decodeFromUTF8:aByteCollection. |
5757 | 161 |
|
162 |
" |
|
8874 | 163 |
CharacterArray fromUTF8Bytes:#[ 16r41 16r42 ] |
164 |
CharacterArray fromUTF8Bytes:#[ 16rC1 16r02 ] |
|
165 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r81 16r02 ] |
|
6810 | 166 |
CharacterArray fromUTF8Bytes:#[ 16rEF 16rBF 16rBF ] |
167 |
||
168 |
rfc2279 examples: |
|
8874 | 169 |
CharacterArray fromUTF8Bytes:#[ 16r41 16rE2 16r89 16rA2 16rCE 16r91 16r2E ] |
170 |
CharacterArray fromUTF8Bytes:#[ 16rED 16r95 16r9C 16rEA 16rB5 16rAD 16rEC 16r96 16rB4 ] |
|
171 |
CharacterArray fromUTF8Bytes:#[ 16rE6 16r97 16rA5 16rE6 16r9C 16rAC 16rE8 16rAA 16r9E ] |
|
6810 | 172 |
|
173 |
invalid: |
|
8874 | 174 |
CharacterArray fromUTF8Bytes:#[ 16rC0 16r80 ] |
175 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r80 16r80 ] |
|
5757 | 176 |
" |
177 |
! |
|
178 |
||
608 | 179 |
new |
180 |
"return a new empty string" |
|
181 |
||
182 |
^ self basicNew:0 |
|
9425 | 183 |
! |
184 |
||
185 |
readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
|
186 |
"read & return the next String from the (character-)stream aStream; |
|
187 |
skipping all whitespace first; return the value of exceptionBlock, |
|
188 |
if no string can be read. The sequence of characters as read from the |
|
189 |
stream must be one as stored via storeOn: or storeString." |
|
190 |
||
191 |
|str collected char| |
|
192 |
||
193 |
str := aStreamOrString readStream. |
|
194 |
||
195 |
"skip whiteSpace" |
|
196 |
str skipSeparators. |
|
11320 | 197 |
|
198 |
(str nextOrNil == $') ifTrue:[ |
|
199 |
collected := self writeStream. |
|
200 |
[str atEnd] whileFalse:[ |
|
201 |
char := str next. |
|
202 |
char == $' ifTrue:[ |
|
203 |
"/ look for another quote |
|
204 |
str peekOrNil ~~ $' ifTrue:[ |
|
205 |
"end of string reached" |
|
206 |
^ collected contents. |
|
207 |
]. |
|
208 |
"eat doubled quote" |
|
209 |
str next. |
|
210 |
]. |
|
211 |
((char ~~ Character return) or:[str peekOrNil ~~ Character lf]) ifTrue:[ |
|
212 |
"compress CRLF to LF, but keep a single CR" |
|
213 |
collected nextPut:char. |
|
214 |
]. |
|
215 |
]. |
|
216 |
"if we come here, we reached the end without finding a closing $'" |
|
9425 | 217 |
]. |
218 |
^ exceptionBlock value |
|
219 |
||
220 |
" |
|
221 |
String readFrom:('''hello world''' readStream) |
|
222 |
String readFrom:('''hello '''' world''' readStream) |
|
223 |
String readFrom:('1 ''hello'' ' readStream) |
|
224 |
String readFrom:('1 ''hello'' ' readStream) onError:['foobar'] |
|
225 |
" |
|
226 |
||
227 |
"Created: / 05-07-2006 / 16:41:04 / cg" |
|
10045
bbd328940fb4
care for cr-lf when reading a smalltalk string
Claus Gittinger <cg@exept.de>
parents:
9845
diff
changeset
|
228 |
"Modified: / 06-10-2006 / 14:05:32 / cg" |
11243
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
229 |
! |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
230 |
|
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
231 |
writeStream |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
232 |
"create a write-stream on an instance of the receiver-class" |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
233 |
|
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
234 |
^ CharacterWriteStream on:(self new:50). |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
235 |
|
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
236 |
" |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
237 |
String writeStream |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
238 |
" |
64 | 239 |
! ! |
240 |
||
9265 | 241 |
!CharacterArray class methodsFor:'Compatibility-VW'! |
242 |
||
243 |
fromIntegerArray: anArray |
|
244 |
"Answer a new instance of the receiver that is created from the argument, anArray." |
|
245 |
||
246 |
| new | |
|
247 |
||
248 |
new := self new: anArray size. |
|
249 |
1 to: anArray size do:[:index | |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
250 |
new at: index put: (anArray at: index) asCharacter |
9265 | 251 |
]. |
252 |
^new |
|
253 |
||
254 |
" |
|
255 |
String fromIntegerArray: #[8 127] |
|
256 |
" |
|
257 |
! ! |
|
258 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
259 |
!CharacterArray class methodsFor:'Signal constants'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
260 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
261 |
decodingFailedSignal |
2833 | 262 |
"return the signal, raised when decoding of a string is not possible |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
263 |
due to invalid characters contained in the source. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
264 |
This may happen for example, if a non EUC coded 8-bit string |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
265 |
is attempted to be decoded into a JIS string." |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
266 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
267 |
^ DecodingFailedSignal |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
268 |
|
2833 | 269 |
"Created: 28.6.1997 / 20:09:55 / cg" |
270 |
"Modified: 3.8.1997 / 18:16:47 / cg" |
|
271 |
! |
|
272 |
||
273 |
encodingFailedSignal |
|
274 |
"return the (query-) signal, raised when encoding of a string is not possible |
|
275 |
due to invalid characters contained in the source." |
|
276 |
||
277 |
^ EncodingFailedSignal |
|
278 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
279 |
"Modified: 28.6.1997 / 20:09:35 / cg" |
2833 | 280 |
"Created: 3.8.1997 / 18:16:40 / cg" |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
281 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
282 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
283 |
!CharacterArray class methodsFor:'cleanup'! |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
284 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
285 |
lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
286 |
"cleanup in low-memory situations" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
287 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
288 |
DecoderTables := EncoderTables := nil |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
289 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
290 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
291 |
CharacterArray lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
292 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
293 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
294 |
"Created: 22.2.1996 / 16:30:30 / cg" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
295 |
"Modified: 22.2.1996 / 17:58:05 / cg" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
296 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
297 |
|
7421 | 298 |
!CharacterArray class methodsFor:'encoding & decoding'! |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
299 |
|
7876 | 300 |
decodeFromUTF8:aStringOrByteCollection |
301 |
"return a string which represents the characters as decoded |
|
302 |
from the utf8 encoded bytes, aByteCollection. |
|
303 |
Returns either a normal String, or a TwoByteString instance. |
|
304 |
Only useful, when reading twoByteStrings from external sources. |
|
305 |
This only handles up-to 16bit characters." |
|
306 |
||
8124
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
307 |
^ CharacterEncoderImplementations::ISO10646_to_UTF8 decodeString:aStringOrByteCollection |
7876 | 308 |
|
309 |
" |
|
8874 | 310 |
CharacterArray fromUTF8Bytes:#[ 16r41 16r42 ] |
311 |
CharacterArray fromUTF8Bytes:#[ 16rC1 16r02 ] |
|
312 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r81 16r02 ] |
|
7876 | 313 |
CharacterArray fromUTF8Bytes:#[ 16rEF 16rBF 16rBF ] |
314 |
||
315 |
rfc2279 examples: |
|
8874 | 316 |
CharacterArray fromUTF8Bytes:#[ 16r41 16rE2 16r89 16rA2 16rCE 16r91 16r2E ] |
317 |
CharacterArray fromUTF8Bytes:#[ 16rED 16r95 16r9C 16rEA 16rB5 16rAD 16rEC 16r96 16rB4 ] |
|
318 |
CharacterArray fromUTF8Bytes:#[ 16rE6 16r97 16rA5 16rE6 16r9C 16rAC 16rE8 16rAA 16r9E ] |
|
7876 | 319 |
|
320 |
invalid: |
|
8874 | 321 |
CharacterArray fromUTF8Bytes:#[ 16rC0 16r80 ] |
322 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r80 16r80 ] |
|
7876 | 323 |
" |
443 | 324 |
! ! |
325 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
326 |
!CharacterArray class methodsFor:'pattern matching'! |
64 | 327 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
328 |
matchEscapeCharacter |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
329 |
"return the character used to escape a matchCharacter |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
330 |
(i.e. make it a regular character in a matchPattern)" |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
331 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
332 |
^ $\ |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
333 |
! |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
334 |
|
327 | 335 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop ignoreCase:ignoreCase |
336 |
"helper for match; return true if the characters from start to stop in |
|
337 |
aString are matching the scan in matchScan from matchStart to matchStop. |
|
328 | 338 |
The matchScan is as created by asMatchScanArray. |
327 | 339 |
|
8874 | 340 |
This algorithm is not at all the most efficient; |
341 |
for heavy duty pattern matching, an interface (primitive) to the regex |
|
328 | 342 |
pattern matching package should be added." |
327 | 343 |
|
8874 | 344 |
|matchEntry |
327 | 345 |
mStart "{ Class: SmallInteger }" |
346 |
mStop "{ Class: SmallInteger }" |
|
347 |
sStart "{ Class: SmallInteger }" |
|
348 |
sStop "{ Class: SmallInteger }" |
|
349 |
mSize "{ Class: SmallInteger }" |
|
350 |
sSize "{ Class: SmallInteger }" |
|
351 |
index "{ Class: SmallInteger }" |
|
2561 | 352 |
quickCheck matchLast nextMatchEntry |
986 | 353 |
checkChar included| |
327 | 354 |
|
355 |
mStart := matchStart. |
|
356 |
mStop := matchStop. |
|
357 |
sStart := start. |
|
358 |
sStop := stop. |
|
359 |
||
360 |
[true] whileTrue:[ |
|
8874 | 361 |
"/ Transcript showCR:('match: ''' , (aString copyFrom:sStart to:sStop) , |
3537 | 362 |
"/ ''' against:' , (matchScanArray copyFrom:mStart to:mStop) printString). |
363 |
||
11018 | 364 |
mSize := mStop - mStart + 1. |
365 |
sSize := sStop - sStart + 1. |
|
366 |
||
367 |
"empty strings match" |
|
368 |
(mSize == 0) ifTrue:[^ (sSize == 0)]. |
|
369 |
||
370 |
matchEntry := matchScanArray at:mStart. |
|
371 |
||
372 |
"/ the most common case first: |
|
373 |
(sSize ~~ 0 |
|
374 |
and:[(checkChar := (aString at:sStart)) = matchEntry]) ifTrue:[ |
|
375 |
"advance by one and continue" |
|
376 |
mStart := mStart + 1. |
|
377 |
sStart := sStart + 1 |
|
378 |
] ifFalse:[ |
|
379 |
(matchEntry == #any) ifTrue:[ |
|
380 |
"restString empty -> no match" |
|
381 |
(sSize == 0) ifTrue:[^ false]. |
|
382 |
"# matches single character" |
|
383 |
((sSize == 1) and:[mSize == 1]) ifTrue:[^ true]. |
|
384 |
"advance by one and continue" |
|
385 |
mStart := mStart + 1. |
|
386 |
sStart := sStart + 1 |
|
387 |
] ifFalse:[ |
|
388 |
(matchEntry == #anyString) ifTrue:[ |
|
389 |
"* alone matches anything" |
|
390 |
(mSize == 1) ifTrue:[^ true]. |
|
391 |
"restString empty & matchString not empty -> no match" |
|
392 |
(sSize == 0) ifTrue:[^ false]. |
|
393 |
||
394 |
" |
|
395 |
try to avoid some of the recursion by checking last |
|
396 |
character and continue with shortened strings if possible |
|
397 |
" |
|
398 |
quickCheck := false. |
|
399 |
(mStop >= mStart) ifTrue:[ |
|
400 |
matchLast := matchScanArray at:mStop. |
|
401 |
(matchLast ~~ #anyString) ifTrue:[ |
|
402 |
(matchLast == #any) ifTrue:[ |
|
403 |
quickCheck := true |
|
404 |
] ifFalse:[ |
|
405 |
matchLast == (aString at:sStop) ifTrue:[ |
|
406 |
quickCheck := true |
|
407 |
] ifFalse:[ |
|
408 |
matchLast isString ifTrue:[ |
|
409 |
quickCheck := matchLast includes:(aString at:sStop) |
|
410 |
] |
|
411 |
] |
|
412 |
] |
|
413 |
] |
|
414 |
]. |
|
415 |
quickCheck ifTrue:[ |
|
416 |
" |
|
417 |
quickCheck ok, advance from the right |
|
418 |
" |
|
419 |
mStop := mStop - 1. |
|
420 |
sStop := sStop - 1 |
|
421 |
] ifFalse:[ |
|
422 |
"/ no quick check; |
|
423 |
"/ look for the next character(s) |
|
424 |
"/ and try matching there |
|
425 |
"/ (to avoid recursion) |
|
426 |
||
427 |
mStart < mStop ifTrue:[ |
|
428 |
nextMatchEntry := matchScanArray at:mStart+1. |
|
429 |
nextMatchEntry isCharacter ifTrue:[ |
|
430 |
sStart <= sStop ifTrue:[ |
|
431 |
[true] whileTrue:[ |
|
432 |
ignoreCase ifFalse:[ |
|
433 |
index := aString indexOf:nextMatchEntry startingAt:sStart |
|
434 |
] ifTrue:[ |
|
435 |
index := aString findFirst:[:c | c asLowercase = nextMatchEntry asLowercase] |
|
436 |
startingAt:sStart. |
|
437 |
]. |
|
438 |
(index == 0 or:[index > sStop]) ifTrue:[ |
|
439 |
^ false |
|
440 |
]. |
|
441 |
(self matchScan:matchScanArray |
|
442 |
from:(mStart + 1) |
|
443 |
to:mStop |
|
444 |
with:aString |
|
445 |
from:index |
|
446 |
to:sStop |
|
447 |
ignoreCase:ignoreCase |
|
448 |
) ifTrue:[ |
|
449 |
^ true |
|
450 |
]. |
|
451 |
sStart := index + 1. |
|
452 |
] |
|
453 |
] |
|
454 |
] |
|
455 |
]. |
|
456 |
||
457 |
" |
|
458 |
no quick check possible; |
|
459 |
loop over all possible substrings |
|
460 |
" |
|
461 |
index := sStart. |
|
462 |
[index <= sStop] whileTrue:[ |
|
463 |
(self matchScan:matchScanArray |
|
464 |
from:(mStart + 1) |
|
465 |
to:mStop |
|
466 |
with:aString |
|
467 |
from:index |
|
468 |
to:sStop |
|
469 |
ignoreCase:ignoreCase |
|
470 |
) ifTrue:[ |
|
471 |
^ true |
|
472 |
]. |
|
473 |
index := index + 1 |
|
474 |
]. |
|
475 |
^ false |
|
476 |
]. |
|
477 |
] ifFalse:[ |
|
478 |
(matchEntry isString) ifTrue:[ |
|
479 |
"testString empty -> no match" |
|
480 |
(sSize == 0) ifTrue:[^ false]. |
|
481 |
||
482 |
included := false. |
|
483 |
"/ checkChar := aString at:sStart. |
|
484 |
included := matchEntry includes:checkChar. |
|
485 |
included ifFalse:[ |
|
486 |
ignoreCase ifTrue:[ |
|
487 |
checkChar isUppercase ifTrue:[ |
|
488 |
included := matchEntry includes:checkChar asLowercase. |
|
489 |
] ifFalse:[ |
|
490 |
included := matchEntry includes:checkChar asUppercase. |
|
491 |
] |
|
492 |
]. |
|
493 |
]. |
|
494 |
mStart := mStart + 1. |
|
495 |
mSize := mSize - 1. |
|
496 |
included ifFalse:[^ false]. |
|
497 |
||
498 |
((sSize == 1) and:[mSize == 0]) ifTrue:[^ true]. |
|
499 |
"cut off 1st char and continue" |
|
500 |
sStart := sStart + 1 |
|
501 |
] ifFalse:[ |
|
502 |
"/ must be single character |
|
503 |
||
504 |
"testString empty ?" |
|
505 |
(sSize == 0) ifTrue:[^ false]. |
|
506 |
||
507 |
"first characters equal ?" |
|
508 |
"/ checkChar := aString at:sStart. |
|
509 |
ignoreCase ifFalse:[^ false]. |
|
510 |
(checkChar asUppercase ~= matchEntry asUppercase) ifTrue:[^ false]. |
|
511 |
||
512 |
"advance and continue" |
|
513 |
mStart := mStart + 1. |
|
514 |
sStart := sStart + 1 |
|
515 |
] |
|
516 |
] |
|
517 |
] |
|
518 |
] |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
519 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
520 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
521 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
522 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
523 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
524 |
scanArray := self matchScanArrayFrom:'*hello'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
525 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
526 |
CharacterArray |
11018 | 527 |
matchScan:scanArray |
528 |
from:1 |
|
529 |
to:scanArray size |
|
530 |
with:s |
|
531 |
from:1 |
|
532 |
to:s size |
|
533 |
ignoreCase:false |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
534 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
535 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
536 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
537 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
538 |
scanArray := self matchScanArrayFrom:'*hello*'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
539 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
540 |
CharacterArray |
11018 | 541 |
matchScan:scanArray |
542 |
from:1 |
|
543 |
to:scanArray size |
|
544 |
with:s |
|
545 |
from:1 |
|
546 |
to:s size |
|
547 |
ignoreCase:false |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
548 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
549 |
|
3879 | 550 |
"Modified: / 15.10.1998 / 13:39:25 / cg" |
608 | 551 |
! |
552 |
||
553 |
matchScanArrayFrom:aString |
|
554 |
"scan a pattern string and decompose it into a scanArray. |
|
555 |
This is processed faster (especially with character ranges), and |
|
556 |
can also be reused later. (if the same pattern is to be searched again)" |
|
557 |
||
9282
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
558 |
^ self matchScanArrayFrom:aString escapeCharacter:(self matchEscapeCharacter) |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
559 |
|
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
560 |
" |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
561 |
String matchScanArrayFrom:'*ute*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
562 |
String matchScanArrayFrom:'**ute**' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
563 |
String matchScanArrayFrom:'*uter' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
564 |
String matchScanArrayFrom:'\*uter' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
565 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
566 |
String matchScanArrayFrom:'[abcd]*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
567 |
String matchScanArrayFrom:'[a-k]*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
568 |
String matchScanArrayFrom:'*some*compl*ern*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
569 |
String matchScanArrayFrom:'[a-' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
570 |
String matchScanArrayFrom:'[a-zA-Z]' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
571 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
572 |
" |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
573 |
|
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
574 |
"Modified: 2.4.1997 / 16:20:29 / cg" |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
575 |
! |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
576 |
|
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
577 |
matchScanArrayFrom:aString escapeCharacter:escape |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
578 |
"scan a pattern string and decompose it into a scanArray. |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
579 |
This is processed faster (especially with character ranges), and |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
580 |
can also be reused later. (if the same pattern is to be searched again)" |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
581 |
|
8874 | 582 |
|coll |
608 | 583 |
idx "{ Class: SmallInteger }" |
9282
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
584 |
end c1 c2 matchSet previous| |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
585 |
|
5487 | 586 |
previous := nil. |
608 | 587 |
|
588 |
coll := OrderedCollection new. |
|
589 |
idx := 1. end := aString size. |
|
590 |
[idx <= end] whileTrue:[ |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
591 |
|char this| |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
592 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
593 |
char := aString at:idx. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
594 |
char == $* ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
595 |
previous ~~ #anyString ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
596 |
this := #anyString |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
597 |
] |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
598 |
] ifFalse:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
599 |
char == $# ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
600 |
previous ~~ #anyString ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
601 |
this := #any |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
602 |
] |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
603 |
] ifFalse:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
604 |
char == $[ ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
605 |
matchSet := IdentitySet new. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
606 |
idx := idx + 1. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
607 |
idx > end ifTrue:[^ nil]. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
608 |
char := aString at:idx. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
609 |
c1 := nil. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
610 |
[char ~~ $]] whileTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
611 |
((char == $-) and:[c1 notNil]) ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
612 |
idx := idx + 1. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
613 |
idx > end ifTrue:[^ nil]. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
614 |
c2 := aString at:idx. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
615 |
c1 to:c2 do:[:c | matchSet add:c]. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
616 |
c1 := nil. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
617 |
idx := idx + 1. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
618 |
] ifFalse:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
619 |
(char ~~ $]) ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
620 |
matchSet add:char. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
621 |
c1 := char. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
622 |
idx := idx + 1 |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
623 |
] |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
624 |
]. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
625 |
idx > end ifTrue:[^ nil]. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
626 |
char := aString at:idx |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
627 |
]. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
628 |
this := matchSet asString |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
629 |
] ifFalse:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
630 |
char == escape ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
631 |
idx := idx + 1. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
632 |
idx > end ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
633 |
"/ mhmh - what should we do here ? |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
634 |
this := char |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
635 |
] ifFalse:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
636 |
this := aString at:idx. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
637 |
] |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
638 |
] ifFalse:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
639 |
this := char |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
640 |
] |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
641 |
] |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
642 |
] |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
643 |
]. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
644 |
this notNil ifTrue:[coll add:this. previous := this]. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
645 |
idx := idx + 1 |
608 | 646 |
]. |
647 |
||
648 |
^ coll asArray |
|
649 |
||
650 |
" |
|
8874 | 651 |
String matchScanArrayFrom:'*ute*' |
652 |
String matchScanArrayFrom:'**ute**' |
|
653 |
String matchScanArrayFrom:'*uter' |
|
654 |
String matchScanArrayFrom:'\*uter' |
|
655 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
|
656 |
String matchScanArrayFrom:'[abcd]*' |
|
657 |
String matchScanArrayFrom:'[a-k]*' |
|
658 |
String matchScanArrayFrom:'*some*compl*ern*' |
|
659 |
String matchScanArrayFrom:'[a-' |
|
660 |
String matchScanArrayFrom:'[a-zA-Z]' |
|
661 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
|
608 | 662 |
" |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
663 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
664 |
"Modified: 2.4.1997 / 16:20:29 / cg" |
9192 | 665 |
! ! |
666 |
||
667 |
!CharacterArray class methodsFor:'queries'! |
|
668 |
||
669 |
isAbstract |
|
11229 | 670 |
"Return if this class is an abstract class. |
671 |
True is returned for CharacterArray here; false for subclasses. |
|
672 |
Abstract subclasses must redefine again." |
|
673 |
||
9192 | 674 |
^ self == CharacterArray |
675 |
! ! |
|
676 |
||
677 |
!CharacterArray methodsFor:'Compatibility-ANSI'! |
|
678 |
||
679 |
addLineDelimiters |
|
680 |
"Ansi compatibility - same as withCRs" |
|
681 |
||
682 |
^ self withCRs |
|
683 |
||
684 |
"Modified: / 13.11.2001 / 19:16:25 / cg" |
|
685 |
! ! |
|
686 |
||
687 |
!CharacterArray methodsFor:'Compatibility-Dolphin'! |
|
688 |
||
689 |
argumentCount |
|
690 |
"same as #numArgs - return the number of arguments a message with myself |
|
691 |
as selector would take." |
|
692 |
||
693 |
^ self numArgs |
|
694 |
! |
|
695 |
||
696 |
copyExpanding:expandTable |
|
697 |
"return a copy of myself, with translations from the expandTable sliced in. |
|
698 |
The argument is supposed to map from characters to either characters or strings." |
|
699 |
||
700 |
|ds| |
|
701 |
||
702 |
ds := WriteStream on:(self species new). |
|
703 |
self do:[:eachChar | |
|
704 |
|repl| |
|
705 |
||
706 |
repl := expandTable at:eachChar ifAbsent:nil. |
|
707 |
repl isNil ifTrue:[ |
|
708 |
ds nextPut:eachChar |
|
709 |
] ifFalse:[ |
|
710 |
repl size == 0 ifTrue:[ |
|
711 |
ds nextPut:repl |
|
712 |
] ifFalse:[ |
|
713 |
ds nextPutAll:repl |
|
714 |
] |
|
715 |
]. |
|
716 |
]. |
|
6870 | 717 |
^ ds contents. |
718 |
! |
|
719 |
||
720 |
formatWith:aString |
|
11955 | 721 |
"Compatibility method - do not use in new code. |
722 |
same as #bindWith: for dolphin compatibility" |
|
6870 | 723 |
|
724 |
^ self bindWith:aString |
|
725 |
||
726 |
" |
|
727 |
'hello%1world' formatWith:'123' |
|
728 |
" |
|
729 |
! |
|
730 |
||
731 |
formatWith:arg1 with:arg2 |
|
11955 | 732 |
"Compatibility method - do not use in new code. |
733 |
same as #bindWith: for dolphin compatibility" |
|
6870 | 734 |
|
735 |
^ self bindWith:arg1 with:arg2 |
|
736 |
||
737 |
" |
|
738 |
'hello%1 %2world' formatWith:'123' with:234 |
|
739 |
" |
|
740 |
! |
|
741 |
||
742 |
formatWith:arg1 with:arg2 with:arg3 |
|
11955 | 743 |
"Compatibility method - do not use in new code. |
744 |
same as #bindWith: for dolphin compatibility" |
|
6870 | 745 |
|
746 |
^ self bindWith:arg1 with:arg2 with:arg3 |
|
747 |
||
748 |
" |
|
749 |
'hello%1 %2 %3world' formatWith:'123' with:234 with:345 |
|
750 |
" |
|
6391 | 751 |
! ! |
752 |
||
7261 | 753 |
!CharacterArray methodsFor:'Compatibility-ST/V'! |
608 | 754 |
|
755 |
byteAt:index put:aByte |
|
756 |
"store a byte at given index. |
|
757 |
This is an ST/V compatibility method." |
|
758 |
||
1333
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
759 |
"/ (aByte == 0) ifTrue:[ |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
760 |
"/ "store a space instead" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
761 |
"/ ^ super basicAt:index put:(Character space) |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
762 |
"/ ]. |
11754
5132248cfd6e
common definition of #byteAt:put between CharacterArray and Symbol
Stefan Vogel <sv@exept.de>
parents:
11632
diff
changeset
|
763 |
^ self basicAt:index put:(Character value:aByte) |
9192 | 764 |
|
765 |
" |
|
766 |
'hello' copy at:1 put:$H asciiValue; yourself |
|
767 |
'hello' copy byteAt:1 put:72; yourself |
|
768 |
'hello' copy byteAt:1 put:0; yourself |
|
769 |
" |
|
770 |
||
771 |
"Modified: 6.5.1996 / 10:35:26 / cg" |
|
772 |
! |
|
608 | 773 |
|
774 |
replChar:oldChar with:newChar |
|
775 |
"return a copy of the receiver, with all oldChars replaced |
|
776 |
by newChar. |
|
777 |
This is an ST/V compatibility method." |
|
778 |
||
3656 | 779 |
^ self copyReplaceAll:oldChar with:newChar |
608 | 780 |
|
781 |
" |
|
8874 | 782 |
'12345678901234567890' replChar:$0 with:$* |
608 | 783 |
" |
3656 | 784 |
|
785 |
"Modified: / 18.7.1998 / 22:52:57 / cg" |
|
608 | 786 |
! |
787 |
||
788 |
replChar:oldChar withString:newString |
|
789 |
"return a copy of the receiver, with all oldChars replaced |
|
790 |
by newString (i.e. slice in the newString in place of the oldChar). |
|
791 |
This is an ST/V compatibility method." |
|
792 |
||
793 |
|tmpStream| |
|
794 |
||
795 |
tmpStream := WriteStream on:(self class new). |
|
796 |
self do:[:element | |
|
9192 | 797 |
element = oldChar ifTrue:[ |
798 |
tmpStream nextPutAll:newString |
|
799 |
] ifFalse:[ |
|
800 |
tmpStream nextPut:element |
|
801 |
]. |
|
608 | 802 |
]. |
803 |
^ tmpStream contents |
|
804 |
||
805 |
" |
|
8874 | 806 |
'12345678901234567890' replChar:$0 withString:'foo' |
807 |
'a string with spaces' replChar:$ withString:' foo ' |
|
608 | 808 |
" |
9192 | 809 |
! |
810 |
||
811 |
replString:subString withString:newString |
|
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
812 |
"return a copy of the receiver, with all sequences of subString replaced |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
813 |
by newString (i.e. slice in the newString in place of the oldString)." |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
814 |
|
8347 | 815 |
^ self copyReplaceString:subString withString:newString |
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
816 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
817 |
" |
8874 | 818 |
'12345678901234567890' replString:'123' withString:'OneTwoThree' |
819 |
'12345678901234567890' replString:'123' withString:'*' |
|
820 |
'12345678901234567890' replString:'234' withString:'foo' |
|
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
821 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
822 |
('a string with spaces' replChar:$ withString:' foo ') |
9192 | 823 |
replString:'foo' withString:'bar' |
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
824 |
" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
825 |
|
8347 | 826 |
"Modified: / 12-05-2004 / 12:00:27 / cg" |
9192 | 827 |
! |
828 |
||
9275 | 829 |
subString:start to:end |
830 |
^ self copyFrom:start to:end |
|
831 |
||
832 |
" |
|
833 |
'12345678901234567890' subString:3 to:8 |
|
834 |
" |
|
835 |
! |
|
836 |
||
9192 | 837 |
trimBlanks |
838 |
"return a copy of the receiver without leading |
|
839 |
and trailing spaces. |
|
840 |
This is an ST/V compatibility method." |
|
841 |
||
842 |
^ self withoutSpaces |
|
843 |
||
844 |
" |
|
845 |
' spaces at beginning' trimBlanks |
|
846 |
'spaces at end ' trimBlanks |
|
847 |
' spaces at beginning and end ' trimBlanks |
|
848 |
'no spaces' trimBlanks |
|
849 |
" |
|
850 |
! ! |
|
851 |
||
852 |
!CharacterArray methodsFor:'Compatibility-Squeak'! |
|
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
853 |
|
6148 | 854 |
asDate |
855 |
"Many allowed forms, see Date.readFrom:" |
|
856 |
||
857 |
^ Date readFrom: (ReadStream on: self) |
|
858 |
||
859 |
" |
|
8874 | 860 |
'30 Apr 1999' asDate dayName capitalized |
6148 | 861 |
" |
862 |
! |
|
863 |
||
8971 | 864 |
asUrl |
865 |
^ self asURL |
|
866 |
! |
|
867 |
||
10840 | 868 |
asWideString |
869 |
^ self asTwoByteString |
|
870 |
||
871 |
" |
|
872 |
'abc' asWideString |
|
873 |
" |
|
874 |
! |
|
875 |
||
4989 | 876 |
capitalized |
877 |
^ self asUppercaseFirst |
|
878 |
||
879 |
" |
|
880 |
'hello' capitalized |
|
881 |
" |
|
882 |
! |
|
883 |
||
10841 | 884 |
caseInsensitiveLessOrEqual:aString |
885 |
^ (self compareCaselessWith:aString) <= 0 |
|
886 |
! |
|
887 |
||
888 |
caseSensitiveLessOrEqual:aString |
|
889 |
^ self <= aString |
|
890 |
! |
|
891 |
||
892 |
charactersExactlyMatching:aString |
|
893 |
|idx nMax| |
|
894 |
||
895 |
nMax :=(self size) min:(aString size). |
|
896 |
idx := 1. |
|
897 |
[idx <= nMax] whileTrue:[ |
|
898 |
(self at:idx) = (aString at:idx) ifFalse:[ |
|
899 |
^ idx - 1 |
|
900 |
]. |
|
901 |
idx := idx + 1. |
|
902 |
]. |
|
903 |
^ nMax |
|
904 |
||
905 |
" |
|
906 |
'abc' charactersExactlyMatching:'abc' |
|
907 |
'abc' charactersExactlyMatching:'abcd' |
|
908 |
'abcd' charactersExactlyMatching:'abc' |
|
909 |
'abc' charactersExactlyMatching:'abd' |
|
910 |
'abc' charactersExactlyMatching:'xxx' |
|
911 |
" |
|
912 |
! |
|
913 |
||
9192 | 914 |
endsWithDigit |
915 |
"Answer whether the receiver's final character represents a digit. 3/11/96 sw" |
|
916 |
||
917 |
^ self size > 0 and: [self last isDigit] |
|
918 |
! |
|
919 |
||
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
920 |
findDelimiters:delimiters startingAt:start |
9192 | 921 |
"Answer the index of the character within the receiver, starting at start, that matches one of the delimiters. If the receiver does not contain any of the delimiters, answer size + 1." |
922 |
||
923 |
|idx| |
|
924 |
||
925 |
idx := self indexOfAny:delimiters startingAt:start. |
|
926 |
idx == 0 ifTrue:[^ self size + 1]. |
|
927 |
^ idx. |
|
928 |
"/start to: self size do: [:i | |
|
929 |
"/ |char| |
|
930 |
"/ |
|
931 |
"/ char := self at: i. |
|
932 |
"/ delimiters do: [:delim | delim = char ifTrue: [^ i]] |
|
8971 | 933 |
"/ ]. |
934 |
"/ ^ self size + 1 |
|
935 |
! |
|
936 |
||
4981 | 937 |
findTokens:delimiters |
7270 | 938 |
"cg: I am not sure, if this is really the squeak semantics (w.r.t. empty fields)" |
939 |
||
4981 | 940 |
^ self asCollectionOfSubstringsSeparatedByAny:delimiters |
7270 | 941 |
|
942 |
" |
|
8874 | 943 |
'a|b#c||e' findTokens:#($# $|) |
7270 | 944 |
" |
4981 | 945 |
! |
946 |
||
4974 | 947 |
includesSubString:aString |
948 |
"return true, if a substring is contained in the receiver. |
|
949 |
The compare is case sensitive." |
|
950 |
||
951 |
^ self includesString:aString |
|
952 |
||
953 |
" |
|
8874 | 954 |
'hello world' includesSubString:'Hel' |
9192 | 955 |
'hello world' includesSubString:'hel' |
956 |
'hello world' includesSubString:'llo' |
|
957 |
" |
|
958 |
||
959 |
||
960 |
||
961 |
! |
|
962 |
||
11178 | 963 |
includesSubString:aString caseSensitive:caseSensitive |
11179 | 964 |
^ self includesSubstring:aString caseSensitive:caseSensitive |
11178 | 965 |
! |
966 |
||
9192 | 967 |
includesSubstring:aString caseSensitive:caseSensitive |
9190 | 968 |
"return true, if a substring is contained in the receiver. |
9192 | 969 |
The argument, caseSensitive controls if case is ignored in the compare." |
970 |
||
971 |
"/ for now, a q&d hack ... |
|
972 |
||
973 |
caseSensitive ifFalse:[ |
|
974 |
^ self asLowercase includesString:aString asLowercase |
|
975 |
]. |
|
9190 | 976 |
^ self includesString:aString |
977 |
||
978 |
" |
|
9192 | 979 |
'hello world' includesSubstring:'Hel' caseSensitive:true |
980 |
'hello world' includesSubstring:'Hel' caseSensitive:false |
|
981 |
" |
|
982 |
||
983 |
||
984 |
||
985 |
! |
|
9190 | 986 |
|
6979 | 987 |
isAllDigits |
988 |
"Answer whether the receiver's characters are all digits" |
|
989 |
||
990 |
^ self conform:[:eachChar | eachChar isDigit] |
|
991 |
||
992 |
" |
|
993 |
'hello world' isAllDigits |
|
994 |
'12344' isAllDigits |
|
995 |
" |
|
996 |
! |
|
997 |
||
4890 | 998 |
lastSpacePosition |
999 |
^ self lastIndexOfSeparator |
|
1000 |
! |
|
1001 |
||
7022 | 1002 |
padded:leftOrRight to:paddedSize with:padCharacter |
1003 |
leftOrRight == #left ifTrue:[ |
|
9192 | 1004 |
^ self leftPaddedTo:paddedSize with:padCharacter |
9190 | 1005 |
]. |
1006 |
^ self paddedTo:paddedSize with:padCharacter |
|
1007 |
||
1008 |
" |
|
8874 | 1009 |
'hello' padded:#right to:10 with:$. |
9192 | 1010 |
'hello' padded:#left to:10 with:$. |
1011 |
" |
|
1012 |
! |
|
1013 |
||
1014 |
skipDelimiters:delimiters startingAt:start |
|
1015 |
"Answer the index of the character within the receiver, starting at start, |
|
1016 |
that does NOT match one of the delimiters. |
|
1017 |
If the receiver does not contain any of the delimiters, answer size + 1. |
|
1018 |
Assumes the delimiters to be a non-empty string." |
|
1019 |
||
1020 |
start to:self size do:[:i | |
|
1021 |
delimiters detect:[:delim | delim = (self at:i) ] ifNone:[ ^ i ] |
|
1022 |
]. |
|
1023 |
^ self size + 1 |
|
1024 |
||
1025 |
" |
|
1026 |
'123***7890' skipDelimiters:'*' startingAt:4 |
|
1027 |
'123***7890' skipDelimiters:'*' startingAt:3 |
|
9190 | 1028 |
'123***7890' skipDelimiters:'*' startingAt:10 |
1029 |
'123*******' skipDelimiters:'*' startingAt:10 |
|
8874 | 1030 |
" |
1031 |
! |
|
1032 |
||
9190 | 1033 |
substrings |
1034 |
^ self asCollectionOfWords |
|
1035 |
||
1036 |
" |
|
1037 |
'foo bar baz' substrings |
|
1038 |
" |
|
1039 |
! |
|
1040 |
||
1041 |
truncateTo:smallSize |
|
9192 | 1042 |
"return myself or a copy shortened to smallSize. 1/18/96 sw" |
1043 |
||
1044 |
self size <= smallSize ifTrue:[^ self]. |
|
1045 |
^ self copyFrom: 1 to: smallSize |
|
1046 |
||
1047 |
" |
|
1048 |
'hello world' truncateTo:5 |
|
1049 |
'hello' truncateTo:10 |
|
1050 |
||
1051 |
'hello world' copyTo:5 |
|
1052 |
'hello' copyTo:10 |
|
1053 |
" |
|
1054 |
! |
|
5795 | 1055 |
|
4890 | 1056 |
withBlanksTrimmed |
1057 |
"Return a copy of the receiver from which leading and trailing blanks have been trimmed." |
|
1058 |
||
1059 |
^ self withoutSpaces |
|
1060 |
||
1061 |
" |
|
8874 | 1062 |
' hello world ' withBlanksTrimmed |
4890 | 1063 |
" |
1064 |
||
1065 |
||
1066 |
||
1067 |
! |
|
1068 |
||
1069 |
withNoLineLongerThan: aNumber |
|
1070 |
"Answer a string with the same content as receiver, but rewrapped so that no line has more characters than the given number" |
|
1071 |
||
9192 | 1072 |
| listOfLines currentLast currentStart resultString putativeLast putativeLine crPosition | |
1073 |
||
1074 |
aNumber isNumber not | (aNumber < 1) ifTrue: [self error: 'too narrow']. |
|
1075 |
listOfLines _ OrderedCollection new. |
|
1076 |
currentLast _ 0. |
|
1077 |
[currentLast < self size] whileTrue: |
|
1078 |
[currentStart _ currentLast + 1. |
|
1079 |
putativeLast _ (currentStart + aNumber - 1) min: self size. |
|
1080 |
putativeLine _ self copyFrom: currentStart to: putativeLast. |
|
1081 |
(crPosition _ putativeLine indexOf: Character cr) > 0 ifTrue: |
|
1082 |
[putativeLast _ currentStart + crPosition - 1. |
|
1083 |
putativeLine _ self copyFrom: currentStart to: putativeLast]. |
|
1084 |
currentLast _ putativeLast == self size |
|
1085 |
ifTrue: |
|
1086 |
[putativeLast] |
|
1087 |
ifFalse: |
|
1088 |
[currentStart + putativeLine lastSpacePosition - 1]. |
|
1089 |
currentLast <= currentStart ifTrue: |
|
1090 |
["line has NO spaces; baleout!!" |
|
1091 |
currentLast _ putativeLast]. |
|
1092 |
listOfLines add: (self copyFrom: currentStart to: currentLast) withBlanksTrimmed]. |
|
1093 |
||
1094 |
listOfLines size > 0 ifFalse: [^ '']. |
|
1095 |
resultString _ listOfLines first. |
|
1096 |
2 to: listOfLines size do: |
|
1097 |
[:i | resultString _ resultString, Character cr asString, (listOfLines at: i)]. |
|
1098 |
^ resultString |
|
1099 |
||
1100 |
" |
|
1101 |
#(5 7 20) collect: |
|
1102 |
[:i | 'Fred the bear went down to the brook to read his book in silence' withNoLineLongerThan: i] |
|
1103 |
" |
|
9190 | 1104 |
|
1105 |
||
1106 |
||
10883 | 1107 |
! |
1108 |
||
11565 | 1109 |
withoutTrailing:char |
1110 |
"return a copy of myself without trailing char. |
|
1111 |
Returns an empty string, if the receiver consist only of char." |
|
1112 |
||
1113 |
|index sz| |
|
1114 |
||
1115 |
index := sz := self size. |
|
10883 | 1116 |
[index ~~ 0] whileTrue:[ |
11565 | 1117 |
(self at:index) == char ifFalse:[ |
1118 |
index == sz ifTrue:[^ self]. |
|
10883 | 1119 |
^ self copyTo:index |
1120 |
]. |
|
1121 |
index := index - 1 |
|
1122 |
]. |
|
1123 |
^ '' |
|
1124 |
||
1125 |
" |
|
11565 | 1126 |
' foo....' withoutTrailing:$. |
1127 |
'foo....' withoutTrailing:$. |
|
1128 |
' foo' withoutTrailing:$. |
|
1129 |
'.......' withoutTrailing:$. |
|
1130 |
'foo' withoutTrailing:$. |
|
1131 |
" |
|
1132 |
! |
|
1133 |
||
1134 |
withoutTrailingBlanks |
|
1135 |
"return a copy of myself without trailing spaces. |
|
1136 |
Notice: this does NOT remove tabs, newline or any other whitespace. |
|
1137 |
Returns an empty string, if the receiver consist only of spaces." |
|
1138 |
||
1139 |
^ self withoutTrailing:Character space |
|
1140 |
||
1141 |
" |
|
10883 | 1142 |
' foo ' withoutTrailingBlanks |
1143 |
'foo ' withoutTrailingBlanks |
|
1144 |
' foo' withoutTrailingBlanks |
|
1145 |
' ' withoutTrailingBlanks |
|
1146 |
'foo' withoutTrailingBlanks |
|
1147 |
(' ' , Character tab asString , ' foo ') withoutTrailingBlanks inspect |
|
1148 |
(' foo' , Character tab asString) withoutTrailingBlanks inspect |
|
1149 |
" |
|
9190 | 1150 |
! ! |
1151 |
||
1152 |
!CharacterArray methodsFor:'Compatibility-V''Age'! |
|
1153 |
||
1154 |
addLineDelimiter |
|
1155 |
"replace all '\'-characters by line delimiter (cr) - characters. |
|
9192 | 1156 |
This has been added for VisualAge compatibility." |
1157 |
||
1158 |
^ self withCRs |
|
1159 |
! |
|
1160 |
||
1161 |
bindWith:aString |
|
1162 |
"return a copy of the receiver, where a '%1' escape is |
|
1163 |
replaced by aString. |
|
1164 |
This has been added for VisualAge compatibility." |
|
1165 |
||
1166 |
^ self expandPlaceholdersWith:(Array with:aString) |
|
1167 |
||
1168 |
" |
|
1169 |
'do you like %1 ?' bindWith:'smalltalk' |
|
1170 |
" |
|
1171 |
! |
|
608 | 1172 |
|
1173 |
bindWith:string1 with:string2 |
|
1174 |
"return a copy of the receiver, where a '%1' escape is |
|
1175 |
replaced by string1 and '%2' is replaced by string2. |
|
1176 |
This has been added for VisualAge compatibility." |
|
1177 |
||
1178 |
^ self expandPlaceholdersWith:(Array with:string1 with:string2) |
|
1179 |
||
1180 |
" |
|
1181 |
'do you prefer %1 or rather %2 ?' |
|
9192 | 1182 |
bindWith:'smalltalk' with:'c++' |
1183 |
" |
|
1184 |
! |
|
9190 | 1185 |
|
1186 |
bindWith:str1 with:str2 with:str3 |
|
608 | 1187 |
"return a copy of the receiver, where a '%1', '%2' and '%3' escapes |
1188 |
are replaced by str1, str2 and str3 respectively. |
|
1189 |
This has been added for VisualAge compatibility." |
|
1190 |
||
1191 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3) |
|
1192 |
||
1193 |
" |
|
9192 | 1194 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
1195 |
bindWith:'smalltalk' with:'c++' with:'c' |
|
1196 |
" |
|
1197 |
! |
|
608 | 1198 |
|
1199 |
bindWith:str1 with:str2 with:str3 with:str4 |
|
1200 |
"return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes |
|
1201 |
are replaced by str1, str2, str3 and str4 respectively. |
|
1202 |
This has been added for VisualAge compatibility." |
|
1203 |
||
1204 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4) |
|
1205 |
||
1206 |
" |
|
9192 | 1207 |
'do you prefer %1 or rather %2 (not talking about %3 or even %4) ?' |
1208 |
bindWith:'smalltalk' with:'c++' with:'c' with:'assembler' |
|
1209 |
" |
|
1210 |
! |
|
608 | 1211 |
|
2344 | 1212 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 |
1213 |
"return a copy of the receiver, where a '%1' .. '%5' escapes |
|
1214 |
are replaced by str1 .. str5 respectively. |
|
1215 |
This has been added for VisualAge compatibility." |
|
1216 |
||
1217 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5) |
|
1218 |
||
1219 |
"Created: 31.1.1997 / 16:25:42 / cg" |
|
1220 |
! |
|
1221 |
||
5343 | 1222 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 |
1223 |
"return a copy of the receiver, where a '%1' .. '%6' escapes |
|
11524 | 1224 |
are replaced by str1 .. str6 respectively. |
5343 | 1225 |
This has been added for VisualAge compatibility." |
1226 |
||
8874 | 1227 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
11524 | 1228 |
with:str3 with:str4 |
1229 |
with:str5 with:str6) |
|
1230 |
! |
|
1231 |
||
1232 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 with:str7 |
|
1233 |
"return a copy of the receiver, where a '%1' .. '%7' escapes |
|
1234 |
are replaced by str1 .. str7 respectively. |
|
1235 |
This has been added for VisualAge compatibility." |
|
1236 |
||
1237 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
|
1238 |
with:str3 with:str4 |
|
1239 |
with:str5 with:str6 |
|
1240 |
with:str7) |
|
5343 | 1241 |
! |
1242 |
||
608 | 1243 |
bindWithArguments:anArrayOfStrings |
1244 |
"return a copy of the receiver, where a '%i' escape |
|
1245 |
is replaced by the coresponding string from the argument array. |
|
1246 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
1247 |
This has been added for VisualAge compatibility." |
|
1248 |
||
9192 | 1249 |
^ self expandPlaceholdersWith:anArrayOfStrings |
1250 |
||
1251 |
" |
|
1252 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
1253 |
bindWithArguments:#('smalltalk' 'c++' 'c') |
|
1254 |
" |
|
1255 |
! |
|
608 | 1256 |
|
1257 |
subStrings |
|
1258 |
"return an array consisting of all words contained in the receiver. |
|
1259 |
Words are separated by whitespace. |
|
1260 |
This has been added for VisualAge compatibility." |
|
1261 |
||
1262 |
^ self asCollectionOfWords |
|
1263 |
||
1264 |
" |
|
1265 |
'hello world, this is smalltalk' subStrings |
|
1266 |
" |
|
1267 |
! |
|
1268 |
||
1269 |
subStrings:separatorCharacter |
|
1270 |
"return an array consisting of all words contained in the receiver. |
|
1271 |
Words are separated by separatorCharacter. |
|
1272 |
This has been added for VisualAge compatibility." |
|
1273 |
||
9192 | 1274 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter |
1275 |
||
1276 |
" |
|
1277 |
'foo:bar:baz:smalltalk' subStrings:$: |
|
1278 |
" |
|
1279 |
! |
|
1280 |
||
1281 |
trimSeparators |
|
1282 |
"return a copy of the receiver without leading and trailing whiteSpace" |
|
1283 |
||
1284 |
^ self withoutSeparators |
|
1285 |
! ! |
|
1286 |
||
1287 |
!CharacterArray methodsFor:'Compatibility-VW'! |
|
5964 | 1288 |
|
6139 | 1289 |
asLogicalFileSpecification |
1290 |
^ self asFilename |
|
1291 |
||
1292 |
"Created: / 30.10.2001 / 17:29:53 / cg" |
|
1293 |
! |
|
1294 |
||
6119 | 1295 |
asQualifiedReference |
1296 |
^ BindingReference pathString:(self string) |
|
1297 |
||
1298 |
! |
|
1299 |
||
5964 | 1300 |
expandMacros |
1301 |
"ST80 compatibility - expand '<..>' macros with |
|
1302 |
argument strings. Similar to #bindWith:. |
|
1303 |
Read the comment in #expandMacrosWithArguments: about |
|
1304 |
limited compatibility issues." |
|
1305 |
||
1306 |
^ self expandMacrosWithArguments:#() |
|
1307 |
||
1308 |
" |
|
1309 |
'hello<n>foo' expandMacros |
|
1310 |
" |
|
1311 |
||
9192 | 1312 |
"Modified: / 18.6.1998 / 16:03:02 / cg" |
1313 |
! |
|
1314 |
||
1315 |
expandMacrosWith:arg |
|
5964 | 1316 |
"ST80 compatibility - expand '<..>' macros with |
1317 |
argument strings. Similar to #bindWith:. |
|
1318 |
Read the comment in #expandMacrosWithArguments: about |
|
1319 |
limited compatibility issues." |
|
1320 |
||
9192 | 1321 |
^ self expandMacrosWithArguments:(Array with:arg) |
1322 |
||
1323 |
"Created: / 1.11.1997 / 13:01:28 / cg" |
|
1324 |
"Modified: / 1.11.1997 / 13:30:50 / cg" |
|
1325 |
! |
|
5964 | 1326 |
|
1327 |
expandMacrosWith:arg1 with:arg2 |
|
1328 |
"ST80 compatibility - expand '<..>' macros with |
|
1329 |
argument strings. Similar to #bindWith:. |
|
1330 |
Read the comment in #expandMacrosWithArguments: about |
|
1331 |
limited compatibility issues." |
|
1332 |
||
1333 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2) |
|
1334 |
||
1335 |
"Modified: / 6.7.1998 / 21:58:14 / cg" |
|
1336 |
! |
|
1337 |
||
1338 |
expandMacrosWith:arg1 with:arg2 with:arg3 |
|
1339 |
"ST80 compatibility - expand '<..>' macros with |
|
1340 |
argument strings. Similar to #bindWith:. |
|
1341 |
Read the comment in #expandMacrosWithArguments: about |
|
1342 |
limited compatibility issues." |
|
1343 |
||
1344 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2 with:arg3) |
|
1345 |
! |
|
1346 |
||
10353
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1347 |
expandMacrosWith:arg1 with:arg2 with:arg3 with:arg4 |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1348 |
"ST80 compatibility - expand '<..>' macros with |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1349 |
argument strings. Similar to #bindWith:. |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1350 |
Read the comment in #expandMacrosWithArguments: about |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1351 |
limited compatibility issues." |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1352 |
|
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1353 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1354 |
! |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1355 |
|
9192 | 1356 |
expandMacrosWithArguments:argArray |
5964 | 1357 |
"ST80 compatibility - expand '<..>' macros with |
1358 |
argument strings. Similar to #bindWith:. |
|
1359 |
WARNING: possibly not all ST80 expansions are supported here." |
|
1360 |
||
1361 |
"/ supported expansions: |
|
1362 |
"/ |
|
1363 |
"/ <#p> # is arg Number; slice in the args printString |
|
8222
f2c454a9a038
replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents:
8124
diff
changeset
|
1364 |
"/ <#s> # is arg Number; slice in the arg itself (must know asString) |
5964 | 1365 |
"/ <#?s1:s2> # is arg Number; slice in s1 if the arg is true, s2 otherwise |
7643 | 1366 |
"/ use first arg if # is not given (i.e. no number before s,p ...) |
5964 | 1367 |
"/ <n> replace by a newLine character |
1368 |
"/ <t> replace by a tab character |
|
6834
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
1369 |
"/ %X the X character itself |
5964 | 1370 |
|
8999
f3fda66ea51e
#expandMacrosWithArguments: - be mor friendly to xml strings.
Stefan Vogel <sv@exept.de>
parents:
8971
diff
changeset
|
1371 |
|in out c fmt nr arg s1 s2 peekc| |
5964 | 1372 |
|
1373 |
in := self readStream. |
|
10721
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1374 |
out := CharacterWriteStream on:(self species uninitializedNew:self size). |
5964 | 1375 |
|
1376 |
[in atEnd] whileFalse:[ |
|
10721
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1377 |
c := in next. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1378 |
c == $% ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1379 |
c := in next. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1380 |
out nextPut:c |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1381 |
] ifFalse:[c ~~ $< ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1382 |
out nextPut:c. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1383 |
] ifFalse:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1384 |
peekc := in peek. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1385 |
[peekc == $<] whileTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1386 |
out nextPut:$<. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1387 |
peekc := in nextPeek. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1388 |
]. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1389 |
peekc == $n ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1390 |
peekc := in nextPeek. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1391 |
peekc == $> ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1392 |
in next. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1393 |
out cr. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1394 |
] ifFalse:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1395 |
out nextPutAll:'<n'. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1396 |
] |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1397 |
] ifFalse:[peekc == $t ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1398 |
peekc := in nextPeek. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1399 |
peekc == $> ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1400 |
in next. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1401 |
out tab. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1402 |
] ifFalse:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1403 |
out nextPutAll:'<t'. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1404 |
] |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1405 |
] ifFalse:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1406 |
peekc isDigit ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1407 |
"start an argument expansion ..." |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1408 |
nr := Integer readFrom:in onError:nil. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1409 |
nr isNil ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1410 |
"this cannot happen (there is at least one digit)" |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1411 |
self error:'invalid format' mayProceed:true. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1412 |
^ self |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1413 |
]. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1414 |
fmt := in next. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1415 |
(fmt ~~ $? and:[in peek ~~ $>]) ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1416 |
out nextPut:$<. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1417 |
nr printOn:out. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1418 |
out nextPut:fmt. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1419 |
] ifFalse:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1420 |
(nr between:1 and:argArray size) ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1421 |
arg := argArray at:nr. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1422 |
] ifFalse:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1423 |
arg := '' |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1424 |
]. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1425 |
|
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1426 |
fmt == $p ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1427 |
"expand with args printString" |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1428 |
arg printOn:out. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1429 |
] ifFalse:[fmt == $s ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1430 |
"expand with arg itself" |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1431 |
arg isText ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1432 |
out contentsSpecies isText ifFalse:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1433 |
out := (WriteStream on:Text new) nextPutAll:out contents; yourself. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1434 |
]. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1435 |
out nextPutAll:arg. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1436 |
] ifFalse:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1437 |
out nextPutAll:arg "asString" string. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1438 |
] |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1439 |
] ifFalse:[fmt == $? ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1440 |
s1 := in upTo:$:. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1441 |
s2 := in nextUpTo:$>. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1442 |
arg == true ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1443 |
out nextPutAll:s1 |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1444 |
] ifFalse:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1445 |
out nextPutAll:s2 |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1446 |
]. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1447 |
] ifFalse:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1448 |
"what does VW do here ?" |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1449 |
self error:'invalid format' mayProceed:true. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1450 |
^ self |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1451 |
]]]. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1452 |
c := in next. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1453 |
c ~~ $> ifTrue:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1454 |
"what does VW do here ?" |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1455 |
self error:'invalid format' mayProceed:true. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1456 |
^ self |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1457 |
] |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1458 |
|
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1459 |
]. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1460 |
] ifFalse:[ |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1461 |
out nextPut:$<. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1462 |
]. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1463 |
]]. |
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1464 |
]]. |
5964 | 1465 |
]. |
1466 |
^ out contents |
|
1467 |
||
1468 |
" |
|
8874 | 1469 |
'hello <1s> how are you' expandMacrosWith:(OperatingSystem getLoginName) |
1470 |
'one plus one is <1p>' expandMacrosWith:2 |
|
5964 | 1471 |
" |
1472 |
||
10721
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1473 |
"Modified: / 18-09-2007 / 22:50:43 / cg" |
9192 | 1474 |
! |
1475 |
||
1476 |
isCharacters |
|
1477 |
"added for visual works compatibility" |
|
1478 |
^ true |
|
1479 |
! ! |
|
1480 |
||
1481 |
!CharacterArray methodsFor:'character searching'! |
|
1482 |
||
1483 |
includesMatchCharacters |
|
8874 | 1484 |
"return true if the receiver includes any meta characters (i.e. $* or $#) |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1485 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1486 |
Here, do not care for $\ escapes" |
608 | 1487 |
|
1488 |
^ self includesAny:'*#[' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1489 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1490 |
" |
8874 | 1491 |
'*foo' includesMatchCharacters |
1492 |
'\*foo' includesMatchCharacters |
|
1493 |
'\*foo' includesUnescapedMatchCharacters |
|
1494 |
'*foo' includesMatchCharacters |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1495 |
'\\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1496 |
'foo*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1497 |
'foo\*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1498 |
'foo\' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1499 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1500 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1501 |
"Modified: 2.4.1997 / 18:12:34 / cg" |
9192 | 1502 |
! |
1503 |
||
1504 |
includesSeparator |
|
1505 |
"return true, if the receiver contains any whitespace characters" |
|
1506 |
||
1507 |
^ (self indexOfSeparator ~~ 0) |
|
1508 |
||
1509 |
" |
|
1510 |
'hello world' includesSeparator |
|
1511 |
'helloworld' includesSeparator |
|
1512 |
" |
|
1513 |
! |
|
1514 |
||
1515 |
includesUnescapedMatchCharacters |
|
8874 | 1516 |
"return true if the receiver really includes any meta characters (i.e. $* or $#) |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1517 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1518 |
Here, care for $\ escapes" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1519 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1520 |
|idx sz specialChars escape| |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1521 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1522 |
idx := 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1523 |
sz := self size. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1524 |
specialChars := '*#[\'. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1525 |
(escape := self class matchEscapeCharacter) ~~ $\ ifTrue:[ |
9192 | 1526 |
specialChars := specialChars copy. |
1527 |
specialChars at:specialChars size put:escape |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1528 |
]. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1529 |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1530 |
[true] whileTrue:[ |
9192 | 1531 |
idx := self indexOfAny:specialChars startingAt:idx. |
1532 |
idx == 0 ifTrue:[^ false]. |
|
1533 |
(self at:idx) == escape ifFalse:[^ true]. |
|
1534 |
idx := idx + 2. |
|
1535 |
idx > sz ifTrue:[^ false]. |
|
8874 | 1536 |
]. |
1537 |
||
1538 |
" |
|
1539 |
'*foo' includesUnescapedMatchCharacters |
|
1540 |
'\*foo' includesUnescapedMatchCharacters |
|
1541 |
'\\foo' includesUnescapedMatchCharacters |
|
1542 |
'\\\$foo' includesUnescapedMatchCharacters |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1543 |
'*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1544 |
'\\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1545 |
'foo*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1546 |
'foo\*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1547 |
'foo\' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1548 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1549 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1550 |
"Modified: 2.4.1997 / 17:08:52 / cg" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1551 |
"Created: 2.4.1997 / 17:23:26 / cg" |
9192 | 1552 |
! |
1553 |
||
1554 |
indexOfControlCharacterStartingAt:startIndex |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1555 |
"return the index of the next control character; |
4117 | 1556 |
starting the search at startIndex, searching forward; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1557 |
that is a character with asciiValue < 32. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1558 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1559 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1560 |
|start "{ Class: SmallInteger }" |
9192 | 1561 |
mySize "{ Class: SmallInteger }"| |
1562 |
||
1563 |
start := startIndex. |
|
1564 |
mySize := self size. |
|
1565 |
||
1566 |
start to:mySize do:[:index | |
|
1567 |
(self at:index) isControlCharacter ifTrue:[^ index] |
|
1568 |
]. |
|
1569 |
^ 0 |
|
1570 |
||
1571 |
" |
|
1572 |
'hello world' asTwoByteString indexOfControlCharacterStartingAt:1 |
|
1573 |
'hello world\foo' withCRsasTwoByteString indexOfControlCharacterStartingAt:1 |
|
1574 |
" |
|
1575 |
||
1576 |
"Modified: / 21.7.1998 / 17:25:07 / cg" |
|
1577 |
! |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1578 |
|
8541 | 1579 |
indexOfNonSeparator |
1580 |
"return the index of the first non-whitespace character. |
|
1581 |
return 0 if no non-separator was found" |
|
1582 |
||
1583 |
^ self indexOfNonSeparatorStartingAt:1. |
|
1584 |
||
1585 |
" |
|
8874 | 1586 |
' hello world' indexOfNonSeparator |
1587 |
' ' indexOfNonSeparator |
|
1588 |
'a ' indexOfNonSeparator |
|
1589 |
'abc' indexOfNonSeparator |
|
1590 |
' ' indexOfNonSeparator |
|
9192 | 1591 |
'' indexOfNonSeparator |
1592 |
" |
|
1593 |
! |
|
1594 |
||
1595 |
indexOfNonSeparatorStartingAt:startIndex |
|
4117 | 1596 |
"return the index of the next non-whitespace character, |
1597 |
starting the search at startIndex, searching forward; |
|
1598 |
return 0 if no non-separator was found" |
|
608 | 1599 |
|
1600 |
|start "{ Class: SmallInteger }" |
|
1601 |
mySize "{ Class: SmallInteger }"| |
|
1602 |
||
1603 |
start := startIndex. |
|
1604 |
mySize := self size. |
|
1605 |
||
1606 |
start to:mySize do:[:index | |
|
9192 | 1607 |
(self at:index) isSeparator ifFalse:[^ index] |
608 | 1608 |
]. |
1609 |
^ 0 |
|
1610 |
||
1611 |
" |
|
8874 | 1612 |
' hello world' indexOfNonSeparatorStartingAt:1 |
1613 |
' ' indexOfNonSeparatorStartingAt:1 |
|
1614 |
'a ' indexOfNonSeparatorStartingAt:2 |
|
4117 | 1615 |
" |
1616 |
||
608 | 1617 |
" |
1618 |
|s index1 index2| |
|
1619 |
s := ' foo bar baz'. |
|
1620 |
index1 := s indexOfNonSeparatorStartingAt:1. |
|
1621 |
index2 := s indexOfSeparatorStartingAt:index1. |
|
1622 |
s copyFrom:index1 to:index2 - 1 |
|
1623 |
" |
|
9192 | 1624 |
! |
1625 |
||
1626 |
indexOfSeparator |
|
1627 |
"return the index of the first whitespace character; |
|
1628 |
starting the search at the beginning, searching forward; |
|
1629 |
return 0 if no separator was found" |
|
1630 |
||
1631 |
^ self indexOfSeparatorStartingAt:1 |
|
1632 |
||
1633 |
" |
|
1634 |
'hello world' indexOfSeparator |
|
1635 |
'helloworld' indexOfSeparator |
|
1636 |
'hello ' indexOfSeparator |
|
1637 |
' hello' indexOfSeparator |
|
1638 |
" |
|
1639 |
! |
|
1640 |
||
1641 |
indexOfSeparatorStartingAt:startIndex |
|
1642 |
"return the index of the next whitespace character, |
|
1643 |
starting the search at startIndex, searching forward; |
|
1644 |
return 0 if no separator was found" |
|
1645 |
||
1646 |
|start "{ Class: SmallInteger }" |
|
1647 |
mySize "{ Class: SmallInteger }"| |
|
1648 |
||
1649 |
start := startIndex. |
|
1650 |
mySize := self size. |
|
1651 |
||
1652 |
start to:mySize do:[:index | |
|
1653 |
(self at:index) isSeparator ifTrue:[^ index] |
|
1654 |
]. |
|
1655 |
^ 0 |
|
1656 |
||
1657 |
" |
|
1658 |
'hello world' indexOfSeparatorStartingAt:3 |
|
1659 |
' hello world' indexOfSeparatorStartingAt:3 |
|
8874 | 1660 |
'hello world ' indexOfSeparatorStartingAt:3 |
1661 |
'hello world ' indexOfSeparatorStartingAt:6 |
|
1662 |
'hello world ' indexOfSeparatorStartingAt:7 |
|
1663 |
'helloworld ' indexOfSeparatorStartingAt:7 |
|
1664 |
'helloworld' indexOfSeparatorStartingAt:7 |
|
4117 | 1665 |
" |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1666 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1667 |
|
4117 | 1668 |
lastIndexOfSeparator |
1669 |
"return the last index of the whitespace character. |
|
1670 |
(i.e. start the search at the end and search backwards); |
|
1671 |
Returns 0 if no separator is found." |
|
1672 |
||
1673 |
^ self lastIndexOfSeparatorStartingAt:(self size) |
|
1674 |
||
1675 |
" |
|
8874 | 1676 |
'hello world' lastIndexOfSeparator |
1677 |
'helloworld' lastIndexOfSeparator |
|
1678 |
'hel lo wor ld' lastIndexOfSeparator |
|
1679 |
'hel ' lastIndexOfSeparator 6 |
|
4117 | 1680 |
" |
1681 |
! |
|
1682 |
||
1683 |
lastIndexOfSeparatorStartingAt:startIndex |
|
9192 | 1684 |
"return the index of the previous whitespace character, |
1685 |
starting the search at startIndex (and searching backwards); |
|
1686 |
returns 0 if no separator was found" |
|
1687 |
||
1688 |
|start "{ Class: SmallInteger }"| |
|
1689 |
||
1690 |
start := startIndex. |
|
1691 |
||
1692 |
start to:1 by:-1 do:[:index | |
|
1693 |
(self at:index) isSeparator ifTrue:[^ index] |
|
1694 |
]. |
|
1695 |
^ 0 |
|
1696 |
||
1697 |
" |
|
1698 |
'hello world' lastIndexOfSeparatorStartingAt:3 |
|
1699 |
'hello world' lastIndexOfSeparatorStartingAt:7 |
|
1700 |
'helloworld' lastIndexOfSeparatorStartingAt:7 |
|
8874 | 1701 |
' helloworld' lastIndexOfSeparatorStartingAt:7 |
4117 | 1702 |
" |
608 | 1703 |
! ! |
1704 |
||
1705 |
!CharacterArray methodsFor:'comparing'! |
|
1706 |
||
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1707 |
< aString |
608 | 1708 |
"Compare the receiver with the argument and return true if the |
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1709 |
receiver is greater than the argument. Otherwise return false. |
8874 | 1710 |
This comparison is based on the elements ascii code - |
9192 | 1711 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
1712 |
||
1713 |
|mySize "{ Class: SmallInteger }" |
|
1714 |
otherSize "{ Class: SmallInteger }" |
|
1715 |
n "{ Class: SmallInteger }" |
|
1716 |
c1 c2| |
|
1717 |
||
1718 |
mySize := self size. |
|
1719 |
otherSize := aString string size. |
|
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1720 |
n := mySize min:otherSize. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1721 |
|
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1722 |
1 to:n do:[:index | |
9192 | 1723 |
c1 := self at:index. |
1724 |
c2 := aString at:index. |
|
1725 |
(c1 == c2 or:[c1 = c2]) ifFalse:[^ c1 < c2]. |
|
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1726 |
]. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1727 |
^ mySize < otherSize |
608 | 1728 |
! |
1729 |
||
1730 |
= aString |
|
1731 |
"Compare the receiver with the argument and return true if the |
|
1732 |
receiver is equal to the argument. Otherwise return false. |
|
1252 | 1733 |
|
9191 | 1734 |
This compare does NOT ignore case differences, |
608 | 1735 |
therefore 'foo' = 'Foo' will return false. |
1736 |
Since this is incompatible to ST-80 (at least, V2.x) , this may change." |
|
1737 |
||
1738 |
|mySize "{ Class: SmallInteger }" |
|
1739 |
otherSize | |
|
1740 |
||
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
1741 |
(aString isString or:[aString species == self species]) ifFalse:[ |
9192 | 1742 |
^ false |
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
1743 |
]. |
608 | 1744 |
mySize := self size. |
1745 |
otherSize := aString size. |
|
1746 |
mySize == otherSize ifFalse:[^ false]. |
|
1747 |
||
1748 |
1 to:mySize do:[:index | |
|
9192 | 1749 |
(self at:index) = (aString at:index) ifFalse:[^ false]. |
608 | 1750 |
]. |
1751 |
^ true |
|
1752 |
||
1753 |
" |
|
8874 | 1754 |
'foo' = 'Foo' |
1755 |
'foo' = 'bar' |
|
1756 |
'foo' = 'foo' |
|
1757 |
'foo' = 'foo' asText |
|
1758 |
'foo' asText = 'foo' |
|
1759 |
'foo' asText = 'foo' asText |
|
608 | 1760 |
" |
1252 | 1761 |
|
1762 |
"Modified: 22.4.1996 / 15:53:58 / cg" |
|
608 | 1763 |
! |
9192 | 1764 |
|
9191 | 1765 |
> aString |
608 | 1766 |
"Compare the receiver with the argument and return true if the |
1767 |
receiver is greater than the argument. Otherwise return false. |
|
8874 | 1768 |
This comparison is based on the elements ascii code - |
1252 | 1769 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
608 | 1770 |
|
1771 |
|mySize "{ Class: SmallInteger }" |
|
8874 | 1772 |
otherSize "{ Class: SmallInteger }" |
9192 | 1773 |
n "{ Class: SmallInteger }" |
1774 |
c1 c2| |
|
1775 |
||
1776 |
mySize := self size. |
|
5929 | 1777 |
otherSize := aString string size. |
1778 |
n := mySize min:otherSize. |
|
1779 |
||
1780 |
1 to:n do:[:index | |
|
9192 | 1781 |
c1 := self at:index. |
1782 |
c2 := aString at:index. |
|
1783 |
(c1 == c2 or:[c1 = c2]) ifFalse:[^ c1 > c2]. |
|
5929 | 1784 |
]. |
9192 | 1785 |
^ mySize > otherSize |
1786 |
||
1787 |
"Modified: 22.4.1996 / 15:55:00 / cg" |
|
1788 |
! |
|
1789 |
||
1790 |
compareCaselessWith:aString |
|
9190 | 1791 |
"Compare the receiver against the argument, ignoreing case. |
1792 |
Return 1 if the receiver is greater, 0 if equal and -1 if less than the argument. |
|
1793 |
||
8874 | 1794 |
This comparison is based on the elements ascii code - |
9190 | 1795 |
i.e. national characters are NOT treated specially. |
1796 |
'foo' compareWith: 'Foo' will return 0" |
|
608 | 1797 |
|
1798 |
|mySize "{ Class: SmallInteger }" |
|
8874 | 1799 |
otherSize "{ Class: SmallInteger }" |
9192 | 1800 |
n "{ Class: SmallInteger }" |
608 | 1801 |
c1 c2| |
1802 |
||
1803 |
mySize := self size. |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
1804 |
otherSize := aString string size. |
608 | 1805 |
n := mySize min:otherSize. |
1806 |
||
1807 |
1 to:n do:[:index | |
|
9192 | 1808 |
c1 := (self at:index) asLowercase. |
1809 |
c2 := (aString at:index) asLowercase. |
|
1810 |
c1 > c2 ifTrue:[^ 1]. |
|
1811 |
c1 < c2 ifTrue:[^ -1]. |
|
608 | 1812 |
]. |
1813 |
mySize > otherSize ifTrue:[^ 1]. |
|
1814 |
mySize < otherSize ifTrue:[^ -1]. |
|
1815 |
^ 0 |
|
1252 | 1816 |
|
1817 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
608 | 1818 |
! |
1819 |
||
9192 | 1820 |
compareWith:aString |
9190 | 1821 |
"Compare the receiver with the argument and return 1 if the receiver is |
1822 |
greater, 0 if equal and -1 if less than the argument. |
|
11861 | 1823 |
This comparison is based on the elements' codepoints - |
9190 | 1824 |
i.e. upper/lowercase & national characters are NOT treated specially. |
1825 |
'foo' compareWith: 'Foo' will return 1. |
|
1826 |
while 'foo' sameAs:'Foo' will return true" |
|
1827 |
||
1828 |
|mySize "{ Class: SmallInteger }" |
|
1829 |
otherSize "{ Class: SmallInteger }" |
|
9192 | 1830 |
n "{ Class: SmallInteger }" |
1831 |
c1 c2| |
|
1832 |
||
1833 |
mySize := self size. |
|
1834 |
otherSize := aString string size. |
|
1835 |
n := mySize min:otherSize. |
|
1836 |
||
1837 |
1 to:n do:[:index | |
|
11861 | 1838 |
c1 := self at:index. |
1839 |
c2 := aString at:index. |
|
1840 |
c1 > c2 ifTrue:[^ 1]. |
|
1841 |
c1 < c2 ifTrue:[^ -1]. |
|
9192 | 1842 |
]. |
1843 |
mySize > otherSize ifTrue:[^ 1]. |
|
1844 |
mySize < otherSize ifTrue:[^ -1]. |
|
1845 |
^ 0 |
|
1846 |
||
1847 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
1848 |
! |
|
1849 |
||
11861 | 1850 |
endsWith:aStringOrCharacter |
1851 |
"return true, if the receiver ends with something, aStringOrCharacter." |
|
1852 |
||
1853 |
|s| |
|
1854 |
||
1855 |
(s := self string) ~~ self ifTrue:[ |
|
1856 |
^ s endsWith:aStringOrCharacter |
|
1857 |
]. |
|
1858 |
aStringOrCharacter isCharacter ifTrue:[ |
|
1859 |
^ self last = aStringOrCharacter |
|
1860 |
]. |
|
1861 |
^ super endsWith:aStringOrCharacter |
|
1862 |
||
1863 |
" |
|
1864 |
'hello world' endsWith:'world' |
|
1865 |
'hello world' asText allBold endsWith:'world' |
|
1866 |
" |
|
1867 |
||
1868 |
"Modified: 12.5.1996 / 15:49:18 / cg" |
|
1869 |
! |
|
1870 |
||
11838 | 1871 |
hammingDistanceTo:aString |
1872 |
"return the hamming distance (the number of characters which are different). |
|
1873 |
In information theory, the Hamming distance between two strings of equal length |
|
1874 |
is the number of positions for which the corresponding symbols are different. |
|
1875 |
Put another way, it measures the minimum number of substitutions required to change |
|
1876 |
one into the other, or the number of errors that transformed one string into the other." |
|
1877 |
||
1878 |
self assert:(aString size == self size). |
|
1879 |
^ 1 to:self size count:[:idx | (self at:idx) ~= (aString at:idx)] |
|
1880 |
||
1881 |
" |
|
1882 |
'roses' hammingDistanceTo:'toned' |
|
1883 |
" |
|
1884 |
! |
|
1885 |
||
9192 | 1886 |
hash |
1887 |
"return an integer useful as a hash-key" |
|
1888 |
||
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1889 |
|h g| |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1890 |
|
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1891 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1892 |
"/ this is the dragon-book algorithm |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1893 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1894 |
h := 0. |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1895 |
self reverseDo:[:char | |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1896 |
"/ Sorry, stc cannot compile this (as of 10.9.2007) |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1897 |
"/ h := (h bitShift:4) + char asciiValue. |
11483
711ec2b11843
asciiValue obsoleted by codePoint
Claus Gittinger <cg@exept.de>
parents:
11441
diff
changeset
|
1898 |
h := (h bitShift:4). |
711ec2b11843
asciiValue obsoleted by codePoint
Claus Gittinger <cg@exept.de>
parents:
11441
diff
changeset
|
1899 |
h:= h + char codePoint. |
711ec2b11843
asciiValue obsoleted by codePoint
Claus Gittinger <cg@exept.de>
parents:
11441
diff
changeset
|
1900 |
h := h bitAnd:16rFFFFFFFF. |
711ec2b11843
asciiValue obsoleted by codePoint
Claus Gittinger <cg@exept.de>
parents:
11441
diff
changeset
|
1901 |
g := (h bitAnd: 16rF0000000). |
711ec2b11843
asciiValue obsoleted by codePoint
Claus Gittinger <cg@exept.de>
parents:
11441
diff
changeset
|
1902 |
g ~~ 0 ifTrue:[ |
711ec2b11843
asciiValue obsoleted by codePoint
Claus Gittinger <cg@exept.de>
parents:
11441
diff
changeset
|
1903 |
h := h bitXor:(g bitShift:-24). |
711ec2b11843
asciiValue obsoleted by codePoint
Claus Gittinger <cg@exept.de>
parents:
11441
diff
changeset
|
1904 |
h := h bitXor:g. |
711ec2b11843
asciiValue obsoleted by codePoint
Claus Gittinger <cg@exept.de>
parents:
11441
diff
changeset
|
1905 |
]. |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1906 |
]. |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1907 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1908 |
"/ multiply by large prime to spread values |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1909 |
"/ This speeds up Set and Dictionary by a factor of 10!! |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1910 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1911 |
h := h * 31415821. |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1912 |
h := h bitAnd:16r3fffffff. |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1913 |
^ h |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1914 |
|
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1915 |
" |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1916 |
'a' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1917 |
'a' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1918 |
'aa' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1919 |
'aa' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1920 |
'ab' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1921 |
'ab' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1922 |
'ab' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1923 |
'ab' asArray hash |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
1924 |
" |
9190 | 1925 |
! |
1926 |
||
11861 | 1927 |
levenshteinTo:aString |
1928 |
"return the levenshtein distance to the argument, aString; |
|
1929 |
this value corresponds to the number of replacements that have to be |
|
1930 |
made to get aString from the receiver. |
|
1931 |
See IEEE transactions on Computers 1976 Pg 172 ff." |
|
1932 |
||
1933 |
" |
|
1934 |
in the following, we assume that ommiting a character |
|
1935 |
is less of an error than inserting an extra character. |
|
1936 |
Therefore the different insertion (i) and deletion (d) values. |
|
1937 |
s: substitution weight |
|
1938 |
k: keyboard weight (typing a nearby key) - or nil (then use s) |
|
1939 |
c: case weight - or nil (then use s) |
|
1940 |
e: exchange weight - or nil (then use s*2) |
|
1941 |
i: insertion of extra character weight |
|
1942 |
d: delete of a character weight |
|
1943 |
" |
|
1944 |
||
1945 |
^ StringUtilities |
|
1946 |
levenshteinDistanceFrom:self |
|
1947 |
to:aString |
|
1948 |
s:4 k:4 c:4 e:nil i:2 d:6 |
|
1949 |
||
1950 |
" |
|
1951 |
'computer' levenshteinTo:'computer' |
|
1952 |
'cOmputer' levenshteinTo:'computer' |
|
1953 |
'cOmpuTer' levenshteinTo:'computer' |
|
1954 |
'cimputer' levenshteinTo:'computer' |
|
1955 |
'cumputer' levenshteinTo:'computer' |
|
1956 |
||
1957 |
'cmputer' levenshteinTo:'computer' |
|
1958 |
'coomputer' levenshteinTo:'computer' |
|
1959 |
||
1960 |
'ocmprt' levenshteinTo:'computer' |
|
1961 |
'computer' levenshteinTo:'computer' |
|
1962 |
'ocmputer' levenshteinTo:'computer' |
|
1963 |
'cmputer' levenshteinTo:'computer' |
|
1964 |
'computer' levenshteinTo:'cmputer' |
|
1965 |
'Computer' levenshteinTo:'computer' |
|
1966 |
||
1967 |
'compiter' levenshteinTo:'computer' |
|
1968 |
'compoter' levenshteinTo:'computer' |
|
1969 |
||
1970 |
'comptuer' levenshteinTo:'computer' |
|
1971 |
" |
|
1972 |
! |
|
1973 |
||
1974 |
levenshteinTo:aString s:substWeight k:kbdTypoWeight c:caseWeight i:insrtWeight d:deleteWeight |
|
1975 |
"parametrized levenshtein. |
|
1976 |
return the levenshtein distance to the argument, aString; |
|
1977 |
this value corrensponds to the number of replacements that have to be |
|
1978 |
made to get aString from the receiver. |
|
1979 |
The arguments are the costs for |
|
1980 |
s:substitution, |
|
1981 |
k:keyboard type (substitution), |
|
1982 |
c:case-change, |
|
1983 |
i:insertion |
|
1984 |
d:deletion |
|
1985 |
of a character. |
|
1986 |
See IEEE transactions on Computers 1976 Pg 172 ff" |
|
1987 |
||
1988 |
^ StringUtilities |
|
1989 |
levenshteinDistanceFrom:self |
|
1990 |
to:aString |
|
1991 |
s:substWeight k:kbdTypoWeight c:caseWeight e:nil i:insrtWeight d:deleteWeight |
|
1992 |
! |
|
1993 |
||
9190 | 1994 |
sameAs:aString |
1995 |
"Compare the receiver with the argument like =, but ignore case differences. |
|
1996 |
Return true or false." |
|
1997 |
||
1998 |
|mySize "{ Class: SmallInteger }" |
|
1999 |
otherSize c1 c2| |
|
2000 |
||
9192 | 2001 |
self == aString ifTrue:[^ true]. |
2002 |
||
2003 |
mySize := self size. |
|
2004 |
otherSize := aString string size. |
|
2005 |
mySize == otherSize ifFalse:[^ false]. |
|
2006 |
||
2007 |
1 to:mySize do:[:index | |
|
2008 |
c1 := self at:index. |
|
2009 |
c2 := aString at:index. |
|
2010 |
c1 == c2 ifFalse:[ |
|
2011 |
(c1 sameAs:c2) ifFalse:[^ false]. |
|
2012 |
] |
|
2013 |
]. |
|
2014 |
^ true |
|
2015 |
||
608 | 2016 |
" |
8874 | 2017 |
'foo' sameAs: 'Foo' |
2018 |
'foo' sameAs: 'bar' |
|
2019 |
'foo' sameAs: 'foo' |
|
9192 | 2020 |
" |
2021 |
||
2022 |
"Modified: 22.4.1996 / 15:56:17 / cg" |
|
2023 |
! |
|
608 | 2024 |
|
5242 | 2025 |
sameAs:aString ignoreCase:ignoreCase |
2026 |
"Compare the receiver with the argument. |
|
2027 |
If ignoreCase is true, this is the same as #sameAs:, |
|
2028 |
if false, this is the same as #=." |
|
2029 |
||
2030 |
ignoreCase ifTrue:[ |
|
9192 | 2031 |
^ self sameAs:aString |
5242 | 2032 |
]. |
2033 |
^ self = aString |
|
2034 |
||
2035 |
" |
|
8874 | 2036 |
'foo' sameAs:'Foo' ignoreCase:false |
2037 |
'foo' sameAs:'foo' ignoreCase:true |
|
5242 | 2038 |
" |
2039 |
||
2040 |
! |
|
2041 |
||
608 | 2042 |
sameCharacters:aString |
9192 | 2043 |
"count & return the number of characters which are the same |
2044 |
(ignoring case and emphasis) in the receiver and the argument, aString." |
|
2045 |
||
2046 |
|n "{ Class: SmallInteger }" |
|
2047 |
c1 c2 cnt| |
|
2048 |
||
2049 |
n := self size. |
|
2050 |
n := n min:(aString string size). |
|
2051 |
||
2052 |
cnt := 0. |
|
2053 |
1 to:n do:[:index | |
|
2054 |
c1 := self at:index. |
|
2055 |
c2 := aString at:index. |
|
2056 |
((c1 == c2) |
|
2057 |
or:[c1 asLowercase = c2 asLowercase]) ifTrue:[ |
|
2058 |
cnt := cnt + 1 |
|
2059 |
] |
|
2060 |
]. |
|
2061 |
^ cnt |
|
2062 |
||
2063 |
" |
|
2064 |
'foobarbaz' sameCharacters: 'foo' |
|
8874 | 2065 |
'foobarbaz' sameCharacters: 'Foo' |
2066 |
'foobarbaz' sameCharacters: 'baz' |
|
608 | 2067 |
" |
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2068 |
! |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2069 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2070 |
sameEmphasisAs:aStringOrText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2071 |
"compare the receivers and the arguments emphasis" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2072 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2073 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2074 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2075 |
" |
8874 | 2076 |
'hello' asText sameEmphasisAs: 'hello' |
2077 |
'hello' asText sameEmphasisAs: 'hello' asText |
|
2078 |
'hello' asText allBold sameEmphasisAs: 'hello' |
|
2079 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
|
9192 | 2080 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
2081 |
" |
|
2082 |
||
2083 |
||
2084 |
! |
|
2085 |
||
9191 | 2086 |
sameStringAndEmphasisAs:aStringOrText |
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
2087 |
"compare both emphasis and string of the receiver and the argument" |
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2088 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2089 |
aStringOrText isString ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2090 |
(self string = aStringOrText string) ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2091 |
self hasChangeOfEmphasis = aStringOrText hasChangeOfEmphasis ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2092 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2093 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2094 |
" |
8874 | 2095 |
'hello' asText sameEmphasisAs: 'hello' |
2096 |
'hello' asText sameEmphasisAs: 'hello' asText |
|
2097 |
'hello' asText allBold sameEmphasisAs: 'hello' |
|
2098 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
|
2099 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
|
2100 |
||
2101 |
'hello' sameEmphasisAs: 'hello' asText |
|
2102 |
'hello' sameEmphasisAs: 'hello' asText allBold |
|
2103 |
'hello' sameEmphasisAs: 'fooba' |
|
2104 |
'hello' sameEmphasisAs: 'fooba' asText |
|
2105 |
'hello' sameEmphasisAs: 'fooba' asText allBold |
|
2106 |
'hello' sameEmphasisAs: 'fooba' asText allItalic |
|
2107 |
||
2108 |
'hello' asText sameStringAndEmphasisAs: 'hello' |
|
2109 |
'hello' asText sameStringAndEmphasisAs: 'hello' asText |
|
2110 |
'hello' asText allBold sameStringAndEmphasisAs: 'hello' |
|
2111 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allBold |
|
2112 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allItalic |
|
2113 |
||
2114 |
'hello' sameStringAndEmphasisAs: 'hello' asText |
|
2115 |
'hello' sameStringAndEmphasisAs: 'hello' asText allBold |
|
2116 |
'hello' sameStringAndEmphasisAs: 'fooba' |
|
2117 |
'hello' sameStringAndEmphasisAs: 'fooba' asText |
|
2118 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allBold |
|
2119 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allItalic |
|
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2120 |
" |
11861 | 2121 |
! |
2122 |
||
2123 |
spellAgainst: aString |
|
2124 |
"return an integer between 0 and 100 indicating how similar |
|
2125 |
the argument is to the receiver. No case conversion is done. |
|
2126 |
This algorithm is much simpler (but also less exact) than the |
|
2127 |
levenshtein distance. Experiment which is better for your |
|
2128 |
application." |
|
2129 |
||
2130 |
| i1 "{ Class: SmallInteger }" |
|
2131 |
i2 "{ Class: SmallInteger }" |
|
2132 |
next1 "{ Class: SmallInteger }" |
|
2133 |
next2 "{ Class: SmallInteger }" |
|
2134 |
size1 "{ Class: SmallInteger }" |
|
2135 |
size2 "{ Class: SmallInteger }" |
|
2136 |
score "{ Class: SmallInteger }" |
|
2137 |
maxLen "{ Class: SmallInteger }" | |
|
2138 |
||
2139 |
size1 := self size. |
|
2140 |
size2 := aString size. |
|
2141 |
maxLen := size1 max:size2. |
|
2142 |
score := 0. |
|
2143 |
i1 := i2 := 1. |
|
2144 |
[i1 <= size1 and: [i2 <= size2]] whileTrue:[ |
|
2145 |
next1 := i1 + 1. |
|
2146 |
next2 := i2 + 1. |
|
2147 |
(self at:i1) == (aString at:i2) ifTrue: [ |
|
2148 |
score := score+1. |
|
2149 |
i1 := next1. |
|
2150 |
i2 := next2 |
|
2151 |
] ifFalse: [ |
|
2152 |
(i2 < size2 and: [(self at:i1) == (aString at:next2)]) ifTrue: [ |
|
2153 |
i2 := next2 |
|
2154 |
] ifFalse: [ |
|
2155 |
(i1 < size1 and: [(self at:next1) == (aString at:i2)]) ifTrue: [ |
|
2156 |
i1 := next1 |
|
2157 |
] ifFalse: [ |
|
2158 |
i1 := next1. |
|
2159 |
i2 := next2 |
|
2160 |
] |
|
2161 |
] |
|
2162 |
] |
|
2163 |
]. |
|
2164 |
||
2165 |
score == maxLen ifTrue: [^ 100]. |
|
2166 |
^ 100 * score // maxLen |
|
2167 |
||
2168 |
" |
|
2169 |
'Smalltalk' spellAgainst: 'Smalltlak' |
|
2170 |
'Smalltalk' spellAgainst: 'smalltlak' |
|
2171 |
'Smalltalk' spellAgainst: 'smalltalk' |
|
2172 |
'Smalltalk' spellAgainst: 'smalltlk' |
|
2173 |
'Smalltalk' spellAgainst: 'Smalltolk' |
|
2174 |
" |
|
2175 |
! |
|
2176 |
||
2177 |
startsWith:aString |
|
2178 |
"return true, if the receiver starts with something, aString. |
|
2179 |
If the argument is empty, true is returned." |
|
2180 |
||
2181 |
|s| |
|
2182 |
||
2183 |
(s := self string) ~~ self ifTrue:[ |
|
2184 |
^ s startsWith:aString |
|
2185 |
]. |
|
2186 |
^ super startsWith:aString |
|
2187 |
||
2188 |
" |
|
2189 |
'hello world' startsWith:'hello' |
|
2190 |
'hello world' asText allBold startsWith:'hello' |
|
2191 |
'hello world' asText allBold startsWith:'' |
|
2192 |
" |
|
2193 |
||
2194 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
2195 |
"Modified: 12.5.1996 / 15:49:24 / cg" |
|
9192 | 2196 |
! ! |
2197 |
||
2198 |
!CharacterArray methodsFor:'converting'! |
|
2199 |
||
2200 |
asArrayOfSubstrings |
|
2201 |
"return an array of substrings from the receiver, interpreting |
|
2202 |
separators (i.e. spaces & newlines) as word-delimiters. |
|
2203 |
This is a compatibility method - the actual work is done in |
|
2204 |
asCollectionOfWords." |
|
2205 |
||
2206 |
^ self asCollectionOfWords asArray |
|
2207 |
||
2208 |
" |
|
2209 |
'1 one two three four 5 five' asArrayOfSubstrings |
|
2210 |
'1 |
|
2211 |
one |
|
2212 |
two three four 5 five' asArrayOfSubstrings |
|
2213 |
" |
|
2214 |
! |
|
608 | 2215 |
|
11881 | 2216 |
asAsciiZ |
2217 |
"if the receiver does not end with a 0-valued character, return a copy of it, |
|
2218 |
with an additional 0-character. Otherwise return the receiver. This is sometimes |
|
2219 |
needed when a string has to be passed to C, which needs 0-terminated strings. |
|
2220 |
Notice, that all singleByte strings are already 0-terminated in ST/X, whereas wide |
|
2221 |
strings are not." |
|
2222 |
||
2223 |
self last codePoint == 0 ifTrue:[^ self ]. |
|
2224 |
^ self copyWith:(Character value:0). |
|
2225 |
||
2226 |
" |
|
2227 |
'abc' asAsciiZ |
|
2228 |
'abc' asWideString asAsciiZ |
|
2229 |
" |
|
2230 |
! |
|
2231 |
||
608 | 2232 |
asCollectionOfLines |
8874 | 2233 |
"return a collection containing the lines (separated by cr) |
608 | 2234 |
of the receiver. If multiple cr's occur in a row, the result will |
2235 |
contain empty strings." |
|
2236 |
||
2237 |
^ self asCollectionOfSubstringsSeparatedBy:Character cr |
|
2238 |
||
2239 |
" |
|
2240 |
'1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines |
|
8874 | 2241 |
'1 one\\\\2 two\3 three' withCRs asCollectionOfLines |
608 | 2242 |
" |
2243 |
! |
|
2244 |
||
2245 |
asCollectionOfSubstringsSeparatedBy:aCharacter |
|
9192 | 2246 |
"return a collection containing the lines (separated by aCharacter) |
2247 |
of the receiver. If aCharacter occurs multiple times in a row, |
|
608 | 2248 |
the result will contain empty strings." |
2249 |
||
9192 | 2250 |
^ self asCollectionOfSubCollectionsSeparatedBy:aCharacter |
2251 |
||
2252 |
" |
|
2253 |
'1 one:2 two:3 three:4 four:5 five' withCRs asCollectionOfSubstringsSeparatedBy:$: |
|
2254 |
'1 one 2 two 3 three 4 four 5 five' withCRs asCollectionOfSubstringsSeparatedBy:Character space |
|
2255 |
" |
|
2256 |
! |
|
608 | 2257 |
|
11828 | 2258 |
asCollectionOfSubstringsSeparatedBy:aCharacter exceptIn:ch |
2259 |
"return a collection containing the lines (separated by aCharacter) |
|
2260 |
of the receiver. If aCharacter occurs multiple times in a row, |
|
2261 |
the result will contain empty strings. The separation is not done, |
|
2262 |
inside a matching pair of ch-substrings. Can be used to tokenize csv-like strings." |
|
2263 |
||
2264 |
|lines myClass except i c |
|
2265 |
startIndex "{ Class:SmallInteger }" |
|
2266 |
stopIndex "{ Class:SmallInteger }" | |
|
2267 |
||
11905
cbc2191cfe2d
return stringCollections from asCollectionOfXXX
Claus Gittinger <cg@exept.de>
parents:
11904
diff
changeset
|
2268 |
lines := StringCollection new. |
11828 | 2269 |
myClass := self species. |
2270 |
||
2271 |
startIndex := 1. |
|
2272 |
except := false. |
|
2273 |
[ |
|
2274 |
i := startIndex-1. |
|
2275 |
[ |
|
2276 |
i := i+1. |
|
2277 |
c := self at:i. |
|
2278 |
c = ch ifTrue:[ except := except not. ]. |
|
2279 |
i < self size and:[except or:[c ~= aCharacter]] |
|
2280 |
] whileTrue. |
|
2281 |
||
2282 |
c = aCharacter ifTrue:[ |
|
2283 |
stopIndex := i -1. |
|
2284 |
] ifFalse: [ |
|
2285 |
stopIndex := i. |
|
2286 |
]. |
|
2287 |
(stopIndex < startIndex) ifTrue: [ |
|
2288 |
lines add:(myClass new:0) |
|
2289 |
] ifFalse: [ |
|
2290 |
lines add:(self copyFrom:startIndex to:stopIndex) |
|
2291 |
]. |
|
2292 |
startIndex := stopIndex + 2. |
|
2293 |
startIndex <= self size |
|
2294 |
] whileTrue. |
|
2295 |
^ lines |
|
2296 |
||
2297 |
" |
|
2298 |
'asd''f;d''dd;s' asCollectionOfSubstringsSeparatedBy:$; exceptIn:$' |
|
2299 |
" |
|
2300 |
"/ 'asd "hello bla" foo "bla bla" bar' asCollectionOfSubstringsSeparatedBy:$ exceptIn:$" |
|
2301 |
! |
|
2302 |
||
10501
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2303 |
asCollectionOfSubstringsSeparatedBy: aFieldSeparator textSeparator:aTextSeparatorOrNil |
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2304 |
"return a collection containing the words (separated by aFieldSeparator) |
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2305 |
of the receiver. This allows breaking up csv strings." |
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2306 |
|
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2307 |
^ self asCollectionOfSubstringsSeparatedByAll: aFieldSeparator |
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2308 |
|
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2309 |
"/ '"First", "Second,SecondAdd", "Third"' asCollectionOfSubstringsSeparatedBy:',' textSeparator: '"' |
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2310 |
"/ 'First,Second,Third' asCollectionOfSubstringsSeparatedBy:',' textSeparator: nil |
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2311 |
! |
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2312 |
|
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2313 |
asCollectionOfSubstringsSeparatedByAll:aSeparatorString |
8874 | 2314 |
"return a collection containing the lines (separated by aSeparatorString) |
2315 |
of the receiver. If aSeparatorString occurs multiple times in a row, |
|
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2316 |
the result will contain empty strings." |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2317 |
|
8852
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2318 |
^ self asCollectionOfSubCollectionsSeparatedByAll:aSeparatorString |
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2319 |
|
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2320 |
" |
8874 | 2321 |
'1::2::3::4::5::' asCollectionOfSubstringsSeparatedByAll:'::' |
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2322 |
" |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2323 |
! |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2324 |
|
608 | 2325 |
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators |
2326 |
"return a collection containing the words (separated by any character |
|
2327 |
from aCollectionOfSeparators) of the receiver. |
|
2328 |
This allows breaking up strings using any character as separator." |
|
2329 |
||
8852
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2330 |
^ self asCollectionOfSubCollectionsSeparatedByAny:aCollectionOfSeparators |
608 | 2331 |
|
2332 |
" |
|
2333 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:) |
|
8874 | 2334 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' |
2335 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) |
|
2336 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' |
|
2337 |
'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) |
|
608 | 2338 |
" |
2339 |
! |
|
2340 |
||
2341 |
asCollectionOfWords |
|
8874 | 2342 |
"return a collection containing the words (separated by whitespace) |
2343 |
of the receiver. Multiple occurrences of whitespace characters will |
|
608 | 2344 |
be treated like one - i.e. whitespace is skipped." |
2345 |
||
7797 | 2346 |
|words| |
608 | 2347 |
|
11905
cbc2191cfe2d
return stringCollections from asCollectionOfXXX
Claus Gittinger <cg@exept.de>
parents:
11904
diff
changeset
|
2348 |
words := StringCollection new. |
7797 | 2349 |
self asCollectionOfWordsDo:[:w | words add:w]. |
608 | 2350 |
^ words |
2351 |
||
2352 |
" |
|
2353 |
'hello world isnt this nice' asCollectionOfWords |
|
2354 |
' hello world isnt this nice ' asCollectionOfWords |
|
2355 |
'hello' asCollectionOfWords |
|
2356 |
'' asCollectionOfWords |
|
2357 |
' ' asCollectionOfWords |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2358 |
' foo bar__baz__bla__ bar ' asCollectionOfWords |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2359 |
' foo __bar__baz__bla__ bar ' asCollectionOfWords |
608 | 2360 |
" |
9192 | 2361 |
! |
2362 |
||
2363 |
asCollectionOfWordsDo:aBlock |
|
8874 | 2364 |
"evaluate aBlock for each word (separated by whitespace) of the receiver. |
2365 |
Multiple occurrences of whitespace characters will be treated like one |
|
7797 | 2366 |
- i.e. whitespace is skipped. |
2367 |
Returns the number of words (i.e. the number of invocations of aBlock)." |
|
2368 |
||
2369 |
|count "{ Class:SmallInteger }" |
|
8874 | 2370 |
start "{ Class:SmallInteger }" |
2371 |
stop "{ Class:SmallInteger }" |
|
7797 | 2372 |
mySize "{ Class:SmallInteger }"| |
2373 |
||
2374 |
count := 0. |
|
2375 |
start := 1. |
|
2376 |
mySize := self size. |
|
2377 |
[start <= mySize] whileTrue:[ |
|
9192 | 2378 |
start := self indexOfNonSeparatorStartingAt:start. |
2379 |
start == 0 ifTrue:[ |
|
2380 |
^ count |
|
2381 |
]. |
|
2382 |
stop := self indexOfSeparatorStartingAt:start. |
|
2383 |
stop == 0 ifTrue:[ |
|
2384 |
aBlock value:(self copyFrom:start to:mySize). |
|
2385 |
^ count + 1 |
|
2386 |
]. |
|
2387 |
aBlock value:(self copyFrom:start to:(stop - 1)). |
|
2388 |
start := stop. |
|
2389 |
count := count + 1 |
|
7797 | 2390 |
]. |
2391 |
^ count |
|
2392 |
||
2393 |
" |
|
2394 |
'hello world isnt this nice' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
2395 |
' hello world isnt this nice ' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
2396 |
'hello' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
2397 |
'' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
2398 |
' ' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
2399 |
" |
|
9192 | 2400 |
! |
2401 |
||
2402 |
asComposedText |
|
2403 |
"ST-80 compatibility |
|
2404 |
- ST/X does not (as today) support composedTexts." |
|
2405 |
||
2406 |
^ ComposedText fromString:self string |
|
2407 |
||
2408 |
"Modified: 27.4.1996 / 13:30:30 / cg" |
|
2409 |
! |
|
2410 |
||
2411 |
asFilename |
|
2412 |
"return a Filename with pathname taken from the receiver" |
|
2413 |
||
2414 |
^ Filename named:self "(self asSingleByteStringReplaceInvalidWith:$?)" |
|
2415 |
||
2416 |
"Modified: 20.5.1996 / 09:38:15 / cg" |
|
2417 |
! |
|
608 | 2418 |
|
3060 | 2419 |
asFixedPoint |
2420 |
"read a fixedPoint number from the receiver. |
|
8874 | 2421 |
Notice, that errors may occur during the read, |
7423 | 2422 |
so you better setup some signal handler when using this method." |
3060 | 2423 |
|
2424 |
^ FixedPoint readFromString:self |
|
2425 |
||
2426 |
" |
|
8874 | 2427 |
'0.123' asFixedPoint |
2428 |
'12345' asFixedPoint |
|
3060 | 2429 |
'(1/5)' asFixedPoint |
2430 |
'foo' asFixedPoint |
|
9192 | 2431 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asFixedPoint] |
2432 |
" |
|
2433 |
||
2434 |
"Modified: / 25.10.1997 / 15:19:00 / cg" |
|
2435 |
! |
|
2436 |
||
2437 |
asFixedPoint:scale |
|
3060 | 2438 |
"read a fixedPoint number with scale number of post-decimal digits |
2439 |
from the receiver. Scale controls the number of displayed digits, |
|
2440 |
not the number of actually valid digits. |
|
8874 | 2441 |
Notice, that errors may occur during the read, |
7423 | 2442 |
so you better setup some signal handler when using this method." |
3060 | 2443 |
|
2444 |
^ (FixedPoint readFromString:self) scale:scale |
|
2445 |
||
2446 |
" |
|
8874 | 2447 |
'0.123' asFixedPoint:2 |
2448 |
'123456' asFixedPoint:2 |
|
2449 |
('3.14157' asFixedPoint:1) asFixedPoint:5 |
|
2450 |
'3.14157' asFixedPoint:2 |
|
2451 |
'foo' asFixedPoint:2 |
|
3060 | 2452 |
" |
2453 |
||
2454 |
"Modified: / 25.10.1997 / 15:21:57 / cg" |
|
9192 | 2455 |
! |
2456 |
||
2457 |
asFloat |
|
608 | 2458 |
"read a float number from the receiver. |
8874 | 2459 |
Notice, that errors may occur during the read, |
7422 | 2460 |
so you better setup some exception handler when using this method." |
608 | 2461 |
|
2462 |
^ (Number readFromString:self) asFloat |
|
2463 |
||
2464 |
" |
|
8874 | 2465 |
'0.123' asFloat |
608 | 2466 |
'12345' asFloat |
2467 |
'(1/5)' asFloat |
|
8874 | 2468 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asFloat] |
608 | 2469 |
" |
2470 |
! |
|
2471 |
||
2472 |
asInteger |
|
9190 | 2473 |
"convert the receiver into an integer. |
8874 | 2474 |
Notice, that errors may occur during the read, |
9190 | 2475 |
so you better setup some exception handler when using this method. |
2476 |
Also notice, that this method here is more strict than the code found |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2477 |
in other smalltalks. |
9190 | 2478 |
For less strict integer reading, use Integer readFrom:aString" |
608 | 2479 |
|
2480 |
^ Integer readFromString:self |
|
2481 |
||
2482 |
" |
|
2483 |
'12345678901234567890' asInteger |
|
2484 |
'-1234' asInteger |
|
9190 | 2485 |
|
2486 |
The following raises an error: |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2487 |
'0.123' asInteger <- reader finds more after reading 0 |
9190 | 2488 |
|
2489 |
whereas the less strict readFrom does not: |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2490 |
Integer readFrom:'0.123' <- reader stops at ., returning 0 |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2491 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2492 |
'0.123' asInteger |
608 | 2493 |
'0.123' asNumber <- returns what you expect |
8874 | 2494 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asInteger] |
9190 | 2495 |
|
2496 |
" |
|
9192 | 2497 |
! |
2498 |
||
2499 |
asLowercase |
|
608 | 2500 |
"return a copy of myself in lowercase letters" |
2501 |
||
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2502 |
|newStr c bitsPerCharacter |
9192 | 2503 |
mySize "{ Class: SmallInteger }" | |
2504 |
||
2505 |
mySize := self size. |
|
2506 |
mySize == 0 ifTrue:[^ self]. |
|
2507 |
newStr := self species new:mySize. |
|
2508 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
2509 |
||
2510 |
1 to:mySize do:[:i | |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2511 |
c := (self at:i) asLowercase. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2512 |
c bitsPerCharacter > bitsPerCharacter ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2513 |
newStr := c stringSpecies fromString:newStr. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2514 |
]. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2515 |
newStr at:i put:c |
9192 | 2516 |
]. |
2517 |
^ newStr |
|
2518 |
||
2519 |
" |
|
2520 |
'HelloWorld' asLowercase |
|
2521 |
'HelloWorld' asLowercaseFirst |
|
2522 |
" |
|
2523 |
! |
|
2524 |
||
2525 |
asLowercaseFirst |
|
2526 |
"return a copy of myself where the first character is converted to lowercase." |
|
2527 |
||
2528 |
|newString firstChar firstCharAsLowercase| |
|
2529 |
||
11525 | 2530 |
self isEmpty ifTrue:[^ self]. |
9192 | 2531 |
firstChar := (self at:1). |
2532 |
firstCharAsLowercase := firstChar asLowercase. |
|
2533 |
firstChar == firstCharAsLowercase ifTrue:[ ^ self]. |
|
2534 |
||
2535 |
firstCharAsLowercase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
|
11525 | 2536 |
newString := firstCharAsLowercase stringSpecies fromString:self. |
9192 | 2537 |
] ifFalse:[ |
11525 | 2538 |
newString := self stringSpecies fromString:self. |
9192 | 2539 |
]. |
9190 | 2540 |
newString at:1 put:firstCharAsLowercase. |
2541 |
^ newString |
|
608 | 2542 |
|
2543 |
" |
|
8874 | 2544 |
'HelloWorld' asLowercase |
2545 |
'HelloWorld' asLowercaseFirst |
|
608 | 2546 |
" |
2547 |
! |
|
2548 |
||
11828 | 2549 |
asLowercaseLast |
2550 |
"return a copy of myself where the last character is |
|
2551 |
converted to lowercase." |
|
2552 |
||
2553 |
|newString sz| |
|
2554 |
||
2555 |
sz := self size. |
|
2556 |
newString := self copyFrom:1 to:sz. |
|
2557 |
sz > 0 ifTrue:[ |
|
2558 |
newString at:sz put:(newString at:sz) asLowercase |
|
2559 |
]. |
|
2560 |
^ newString |
|
2561 |
||
2562 |
" |
|
2563 |
'HelloWorld' asLowercase |
|
2564 |
'HelloWorlD' asLowercaseLast |
|
2565 |
" |
|
2566 |
! |
|
2567 |
||
9190 | 2568 |
asNumber |
2569 |
"read a number from the receiver. |
|
2570 |
Notice, that (in contrast to ST-80) errors may occur during the read, |
|
2571 |
so you better setup some signal handler when using this method. |
|
2572 |
Also notice, that this is meant to read end-user numbers from a string; |
|
9135 | 2573 |
it does not handle smalltalk numbers (i.e. radix). |
2574 |
To read a smalltalk number, use Number >> readSmalltalkFrom:. |
|
608 | 2575 |
This may change if ANSI specifies it." |
2576 |
||
2577 |
"/ ST-80 behavior: |
|
2578 |
"/ ^ Number readFromString:self onError:0 |
|
2579 |
||
2580 |
^ Number readFromString:self |
|
2581 |
||
2582 |
" |
|
2583 |
'123' asNumber |
|
2584 |
'123.567' asNumber |
|
2585 |
'(5/6)' asNumber |
|
2586 |
'foo' asNumber |
|
8874 | 2587 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] |
608 | 2588 |
" |
9192 | 2589 |
! |
2590 |
||
2591 |
asNumberFromFormatString:ignored |
|
608 | 2592 |
"read a number from the receiver, ignoring any nonDigit characters. |
2593 |
This is typically used to convert from strings which include |
|
2594 |
dollar-signs or millenium digits. However, this method also ignores |
|
2595 |
the decimal point (if any) and therefore should be used with care." |
|
2596 |
||
2597 |
|tempString| |
|
2598 |
||
2599 |
tempString := self collect:[:char | char isDigit]. |
|
2600 |
^ Number readFromString:tempString onError:0 |
|
2601 |
||
2602 |
" |
|
2603 |
'USD 123' asNumberFromFormatString:'foo' |
|
2604 |
'DM 123' asNumberFromFormatString:'foo' |
|
2605 |
'123' asNumberFromFormatString:'foo' |
|
2606 |
'123.567' asNumberFromFormatString:'foo' |
|
2607 |
'(5/6)' asNumberFromFormatString:'foo' |
|
2608 |
'foo' asNumberFromFormatString:'foo' |
|
2609 |
" |
|
9192 | 2610 |
! |
2611 |
||
2612 |
asOneByteString |
|
2613 |
"return the receiver converted to a 'normal' string. |
|
2614 |
Same as asSingleByteString - for compatibility." |
|
2615 |
||
2616 |
^ self asSingleByteString |
|
2617 |
! |
|
2618 |
||
2619 |
asSingleByteString |
|
2620 |
"return the receiver converted to a 'normal' string. |
|
11904 | 2621 |
Raises an error if unrepresentable characters are encountered. |
2622 |
See also: asSingleByteStringIfPossible and asSingleByteStringReplaceInvalidWith:" |
|
9192 | 2623 |
|
2624 |
^ String fromString:self |
|
11904 | 2625 |
|
2626 |
" |
|
2627 |
(Unicode16String with:(Character value:16rFF)) asSingleByteString |
|
2628 |
(Unicode16String with:(Character value:16rFFFF)) asSingleByteString |
|
2629 |
" |
|
9192 | 2630 |
! |
608 | 2631 |
|
7977 | 2632 |
asSingleByteStringIfPossible |
2633 |
"if possible, return the receiver converted to a 'normal' string. |
|
2634 |
It is only possible, if there are no characters with codePoints above 255 in the receiver." |
|
2635 |
||
2636 |
self bitsPerCharacter == 8 ifTrue:[^ self]. |
|
8102
e0537422e2d3
Use the ANSI-blessed #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8083
diff
changeset
|
2637 |
(self contains:[:char | char codePoint > 255]) ifFalse:[^ self asSingleByteString]. |
9192 | 2638 |
^ self |
2639 |
||
2640 |
" |
|
2641 |
'hello' asSingleByteStringIfPossible |
|
2642 |
'hello' asUnicodeString asSingleByteStringIfPossible |
|
2643 |
" |
|
2644 |
! |
|
2645 |
||
2646 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
|
2647 |
"return the receiver converted to a 'normal' string, |
|
2648 |
with invalid characters replaced by replacementCharacter. |
|
2649 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
2650 |
and replace characters above code-255 with some replacement." |
|
2651 |
||
2652 |
|newString| |
|
2653 |
||
2654 |
newString := String new:(self size). |
|
2655 |
1 to:self size do:[:idx | |
|
2656 |
|char| |
|
2657 |
||
2658 |
char := self at:idx. |
|
2659 |
char codePoint <= 16rFF ifTrue:[ |
|
2660 |
newString at:idx put:char |
|
2661 |
] ifFalse:[ |
|
2662 |
newString at:idx put:replacementCharacter |
|
2663 |
]. |
|
9190 | 2664 |
]. |
2665 |
^ newString |
|
2666 |
||
2667 |
"Created: 30.6.1997 / 13:02:14 / cg" |
|
7977 | 2668 |
! |
2669 |
||
9192 | 2670 |
asString |
2671 |
"return myself - I am a string" |
|
2672 |
||
2673 |
^ self |
|
2674 |
! |
|
2675 |
||
2676 |
asStringCollection |
|
2677 |
"return a collection of lines from myself." |
|
2678 |
||
2679 |
^ StringCollection fromString:self "string" |
|
2680 |
||
2681 |
"Modified: 13.5.1996 / 20:36:59 / cg" |
|
2682 |
! |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2683 |
|
1434 | 2684 |
asSymbol |
9230 | 2685 |
"Return a unique symbol with the name taken from the receivers characters. |
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
2686 |
The receiver must be a singleByte-String. |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
2687 |
TwoByte- and FourByteSymbols are (currently ?) not allowed." |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
2688 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
2689 |
|str| |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
2690 |
|
9192 | 2691 |
str := self string. |
2692 |
str ~~ self ifTrue:[ ^ str asSymbol ]. |
|
2693 |
^ self asSingleByteString asSymbol |
|
2694 |
! |
|
2695 |
||
2696 |
asSymbolIfInterned |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2697 |
"If a symbol with the receivers characters is already known, return it. Otherwise, return nil. |
9230 | 2698 |
This can be used to query for an existing symbol and is the same as: |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2699 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
2700 |
but slightly faster, since the symbol lookup operation is only performed once. |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
2701 |
The receiver must be a singleByte-String. |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
2702 |
TwoByte- and FourByteSymbols are (currently ?) not allowed." |
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
2703 |
|
6642 | 2704 |
|s| |
2705 |
||
2706 |
||
2707 |
s := self string. |
|
2708 |
s ~~ self ifTrue:[ |
|
2709 |
^ s asSymbolIfInterned |
|
2710 |
]. |
|
2711 |
^ nil. |
|
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
2712 |
|
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
2713 |
"Created: 22.5.1996 / 16:37:04 / cg" |
9192 | 2714 |
! |
2715 |
||
2716 |
asText |
|
9403 | 2717 |
"return a Text-object (string with emphasis) from myself." |
9192 | 2718 |
|
2719 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
2720 |
Text isNil ifTrue:[^ self]. |
|
2721 |
^ Text fromString:self |
|
2722 |
||
2723 |
"Created: 12.5.1996 / 10:41:14 / cg" |
|
2724 |
! |
|
2725 |
||
2726 |
asTitlecase |
|
8027 | 2727 |
"return a version of the receiver, where the first character is converted to titlecase, |
2728 |
and everything else to lowercase. |
|
2729 |
See the comment in Character on what titlecase is." |
|
2730 |
||
2731 |
|newStr c bitsPerCharacter |
|
2732 |
mySize "{ Class: SmallInteger }" | |
|
2733 |
||
2734 |
mySize := self size. |
|
2735 |
newStr := self species new:mySize. |
|
2736 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
2737 |
||
2738 |
1 to:mySize do:[:i | |
|
9192 | 2739 |
i == 1 ifTrue:[ |
2740 |
c := (self at:i) asTitlecase. |
|
2741 |
] ifFalse:[ |
|
2742 |
c := (self at:i) asLowercase. |
|
2743 |
]. |
|
2744 |
c bitsPerCharacter > bitsPerCharacter ifTrue:[ |
|
2745 |
newStr := c stringSpecies fromString:newStr. |
|
2746 |
]. |
|
2747 |
newStr at:i put:c |
|
8027 | 2748 |
]. |
2749 |
^ newStr |
|
2750 |
||
2751 |
" |
|
8874 | 2752 |
'helloWorld' asTitlecase |
2753 |
'HelloWorld' asTitlecase |
|
2754 |
'HELLOWORLD' asTitlecase |
|
2755 |
'helloworld' asTitlecase |
|
8027 | 2756 |
" |
9192 | 2757 |
! |
2758 |
||
2759 |
asTitlecaseFirst |
|
8023 | 2760 |
"return a version of the receiver, where the first character is converted to titlecase. |
8024 | 2761 |
Titlecase is much like uppercase for most characters, with the exception of some combined |
2762 |
(2-character glyphs), which consist of an upper- and lower-case characters. |
|
2763 |
If the first character is already titlecase, or there is no titlecasepercase for it, return the |
|
8023 | 2764 |
receiver." |
2765 |
||
8026 | 2766 |
" |
8874 | 2767 |
For example, in Unicode, character U+01F3 is LATIN SMALL LETTER DZ. |
2768 |
(Let us write this compound character using ASCII as 'dz'.) |
|
2769 |
This character uppercases to character U+01F1, LATIN CAPITAL LETTER DZ. |
|
2770 |
(Which is basically 'DZ'.) |
|
2771 |
But it titlecases to to character U+01F2, LATIN CAPITAL LETTER D WITH SMALL LETTER Z. |
|
8026 | 2772 |
(Which we can write 'Dz'.) |
2773 |
||
2774 |
character uppercase titlecase |
|
2775 |
--------- --------- --------- |
|
2776 |
dz DZ Dz |
|
2777 |
" |
|
2778 |
||
8023 | 2779 |
|newString firstChar firstCharAsTitlecase| |
2780 |
||
2781 |
firstChar := (self at:1). |
|
8025 | 2782 |
firstCharAsTitlecase := firstChar asTitlecase. |
8023 | 2783 |
firstChar == firstCharAsTitlecase ifTrue:[ ^ self]. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
2784 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
2785 |
firstCharAsTitlecase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
9192 | 2786 |
newString := firstCharAsTitlecase stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
2787 |
] ifFalse:[ |
9192 | 2788 |
newString := self stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
2789 |
]. |
8023 | 2790 |
newString at:1 put:firstCharAsTitlecase. |
2791 |
^ newString |
|
2792 |
||
2793 |
" |
|
8874 | 2794 |
'helloWorld' asTitlecaseFirst |
2795 |
'HelloWorld' asTitlecaseFirst |
|
8023 | 2796 |
" |
9192 | 2797 |
! |
2798 |
||
2799 |
asTwoByteString |
|
2800 |
"return the receiver converted to a two-byte string. |
|
2801 |
Will be obsolete soon." |
|
2802 |
||
2803 |
^ TwoByteString fromString:self |
|
2804 |
! |
|
2805 |
||
2806 |
asURI |
|
2807 |
"return an URI with string taken from the receiver" |
|
2808 |
||
2809 |
^ URI fromString:self |
|
2810 |
! |
|
8710 | 2811 |
|
5776 | 2812 |
asURL |
2813 |
"return an URL-object from myself." |
|
2814 |
||
2815 |
^ URL fromString:self |
|
2816 |
||
2817 |
" |
|
8874 | 2818 |
'http://www.exept.de:80/index.html' asURL host |
2819 |
'http://www.exept.de:80/index.html' asURL port |
|
9192 | 2820 |
'http://www.exept.de:80/index.html' asURL method |
2821 |
'http://www.exept.de:80/index.html' asURL path |
|
2822 |
" |
|
2823 |
! |
|
2824 |
||
2825 |
asUnicode16String |
|
2826 |
"thats not really true - characters above ascii 16r7F may need special treatment" |
|
2827 |
||
2828 |
^ ((Unicode16String new:self size) replaceFrom:1 to:self size with:self startingAt:1) |
|
2829 |
! |
|
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2830 |
|
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2831 |
asUnicode32String |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2832 |
"thats not really true - characters above ascii 16r7F may need special treatment" |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2833 |
|
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2834 |
^ ((Unicode32String new:self size) replaceFrom:1 to:self size with:self startingAt:1) |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2835 |
! |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2836 |
|
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2837 |
asUnicodeString |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2838 |
"thats not really true - characters above ascii 16r7F may need special treatment" |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2839 |
|
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2840 |
^ ((UnicodeString new:self size) replaceFrom:1 to:self size with:self startingAt:1) |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2841 |
! |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
2842 |
|
608 | 2843 |
asUppercase |
2844 |
"return a copy of myself in uppercase letters" |
|
2845 |
||
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2846 |
|newStr c bitsPerCharacter |
608 | 2847 |
mySize "{ Class: SmallInteger }" | |
2848 |
||
2849 |
mySize := self size. |
|
8954
12e701d7b5ac
allow for receiver to be empty in asLowercase and asUppercase.
Claus Gittinger <cg@exept.de>
parents:
8938
diff
changeset
|
2850 |
mySize == 0 ifTrue:[^ self]. |
608 | 2851 |
newStr := self species new:mySize. |
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2852 |
bitsPerCharacter := newStr bitsPerCharacter. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2853 |
|
608 | 2854 |
1 to:mySize do:[:i | |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2855 |
c := (self at:i) asUppercase. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2856 |
c bitsPerCharacter > bitsPerCharacter ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2857 |
newStr := c stringSpecies fromString:newStr. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2858 |
]. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2859 |
newStr at:i put:c |
608 | 2860 |
]. |
2861 |
^ newStr |
|
2862 |
||
2863 |
" |
|
8874 | 2864 |
'helloWorld' asUppercase |
2865 |
'helloWorld' asUppercaseFirst |
|
9192 | 2866 |
(Character value:16rB5) asString asUppercase -- needs 16 bits !! |
2867 |
" |
|
2868 |
! |
|
2869 |
||
2870 |
asUppercaseFirst |
|
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2871 |
"return a version of the receiver, where the first character is converted to uppercase. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2872 |
If the first character is already uppercase, or there is no uppercase for it, return the |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2873 |
receiver." |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2874 |
|
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2875 |
|newString firstChar firstCharAsUppercase| |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2876 |
|
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2877 |
firstChar := (self at:1). |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2878 |
firstCharAsUppercase := firstChar asUppercase. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2879 |
firstChar == firstCharAsUppercase ifTrue:[ ^ self]. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2880 |
|
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
2881 |
firstCharAsUppercase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
9192 | 2882 |
newString := firstCharAsUppercase stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
2883 |
] ifFalse:[ |
9192 | 2884 |
newString := self stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
2885 |
]. |
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
2886 |
newString at:1 put:firstCharAsUppercase. |
608 | 2887 |
^ newString |
2888 |
||
2889 |
" |
|
8874 | 2890 |
'helloWorld' asUppercase |
2891 |
'helloWorld' asUppercaseFirst |
|
2892 |
'HelloWorld' asUppercaseFirst |
|
608 | 2893 |
" |
9192 | 2894 |
! |
2895 |
||
11828 | 2896 |
asUppercaseLast |
2897 |
"return a copy of myself where the last character is |
|
2898 |
converted to uppercase." |
|
2899 |
||
2900 |
|newString sz| |
|
2901 |
||
2902 |
sz := self size. |
|
2903 |
newString := self copyFrom:1 to:sz. |
|
2904 |
sz > 0 ifTrue:[ |
|
2905 |
newString at:sz put:(newString at:sz) asUppercase |
|
2906 |
]. |
|
2907 |
^ newString |
|
2908 |
||
2909 |
" |
|
2910 |
'HelloWorld' asUppercase |
|
2911 |
'HelloWorld' asUppercaseLast |
|
2912 |
" |
|
2913 |
! |
|
2914 |
||
11062 | 2915 |
literalArrayEncoding |
2916 |
"encode myself as an array literal, from which a copy of the receiver |
|
2917 |
can be reconstructed with #decodeAsLiteralArray." |
|
2918 |
||
2919 |
^ self |
|
2920 |
||
2921 |
"Modified: 1.9.1995 / 02:25:45 / claus" |
|
2922 |
"Modified: 22.4.1996 / 13:00:50 / cg" |
|
2923 |
! |
|
2924 |
||
9192 | 2925 |
string |
2926 |
"return the receiver - for ST-80 compatibility" |
|
2927 |
||
2928 |
^ self |
|
2929 |
||
2930 |
"Modified: 27.4.1996 / 13:29:30 / cg" |
|
2931 |
! |
|
2932 |
||
2933 |
tokensBasedOn:aCharacter |
|
2934 |
"this is an ST-80 alias for the ST/X method |
|
2935 |
asCollectionOfSubstringsSeparatedBy:" |
|
2936 |
||
2937 |
^ self asCollectionOfSubstringsSeparatedBy:aCharacter |
|
2938 |
||
2939 |
" |
|
2940 |
'hello:world:isnt:this nice' tokensBasedOn:$: |
|
2941 |
'foo,bar,baz' tokensBasedOn:$, |
|
2942 |
'/etc/passwd' asFilename readStream nextLine tokensBasedOn:$: |
|
2943 |
" |
|
11320 | 2944 |
! |
2945 |
||
11828 | 2946 |
withoutAllSpaces |
2947 |
^ self asCollectionOfWords asStringWith:''. |
|
2948 |
"/ |col string| |
|
2949 |
"/ |
|
2950 |
"/ col := self asCollectionOfWords. |
|
2951 |
"/ string := String new. |
|
2952 |
"/ col do:[:el | |
|
2953 |
"/ string := string,el |
|
2954 |
"/ ]. |
|
2955 |
"/ ^string |
|
2956 |
||
2957 |
" |
|
2958 |
'hello wwww' withoutAllSpaces |
|
2959 |
'hel lo www w' withoutAllSpaces |
|
2960 |
" |
|
2961 |
||
2962 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
2963 |
! |
|
2964 |
||
11320 | 2965 |
writeStream |
2966 |
^ CharacterWriteStream on:self |
|
9192 | 2967 |
! ! |
2968 |
||
2969 |
!CharacterArray methodsFor:'copying'! |
|
2970 |
||
2971 |
, aStringOrCharacter |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
2972 |
"redefined to allow characters and mixed strings to be appended. |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2973 |
This is nonStandard, but convenient" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2974 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
2975 |
|myWidth otherWidth| |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
2976 |
|
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2977 |
aStringOrCharacter isCharacter ifTrue:[ |
9192 | 2978 |
^ self copyWith:aStringOrCharacter |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2979 |
]. |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
2980 |
aStringOrCharacter isText ifTrue:[ |
9192 | 2981 |
^ aStringOrCharacter concatenateFromString:self |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
2982 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
2983 |
aStringOrCharacter isString ifTrue:[ |
9192 | 2984 |
(otherWidth := aStringOrCharacter bitsPerCharacter) ~~ (myWidth := self bitsPerCharacter) ifTrue:[ |
2985 |
otherWidth > myWidth ifTrue:[ |
|
2986 |
^ (aStringOrCharacter species fromString:self) , aStringOrCharacter |
|
2987 |
]. |
|
2988 |
^ self , (self species fromString:aStringOrCharacter) |
|
2989 |
]. |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
2990 |
]. |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2991 |
^ super , aStringOrCharacter |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2992 |
|
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2993 |
" |
8874 | 2994 |
'hello' , $1 |
2995 |
'hello' , '1' |
|
2996 |
'hello' , (' world' asText allBold) |
|
2997 |
'hello' , (JISEncodedString fromString:' world') |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
2998 |
(JISEncodedString fromString:'hello') , ' world' |
1411 | 2999 |
|
1422 | 3000 |
Transcript showCR: |
9192 | 3001 |
(Text string:'hello' emphasis:#italic) , (Text string:' world' emphasis:#bold) |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3002 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3003 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3004 |
"Modified: 28.6.1997 / 00:13:17 / cg" |
9192 | 3005 |
! |
3006 |
||
3007 |
,, aString |
|
7020 | 3008 |
"concatenate with a newLine in between" |
6965 | 3009 |
|
3010 |
^ (self copyWith:Character cr) , aString |
|
3011 |
||
3012 |
" |
|
3013 |
hello ,, world |
|
7020 | 3014 |
'hello' ,, 'world' |
6965 | 3015 |
" |
3016 |
! |
|
3017 |
||
11329 | 3018 |
chopTo:maxLen |
3019 |
"if the receivers size is less or equal to maxLen, return it. |
|
3020 |
Otherwise, return a copy of the receiver, where some characters |
|
3021 |
in the middle have been removed for a total string length |
|
3022 |
of maxLen." |
|
3023 |
||
3024 |
|sz n1 n2| |
|
3025 |
||
3026 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3027 |
||
3028 |
n1 := n2 := maxLen // 2. |
|
3029 |
maxLen odd ifTrue:[ |
|
3030 |
n2 := n1 + 1 |
|
3031 |
]. |
|
3032 |
^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1) |
|
3033 |
||
3034 |
" |
|
3035 |
'12345678901234' chopTo:15 |
|
3036 |
'123456789012345' chopTo:15 |
|
3037 |
'1234567890123456' chopTo:15 |
|
3038 |
'aShortString' chopTo:15 |
|
3039 |
'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 |
|
3040 |
" |
|
3041 |
||
3042 |
"Modified: / 24-10-2006 / 12:32:01 / cg" |
|
3043 |
! |
|
3044 |
||
608 | 3045 |
concatenate:string1 and:string2 |
3046 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
3047 |
This is equivalent to self , string1 , string2 |
|
3048 |
- generated by compiler when such a construct is detected and the receiver |
|
3049 |
is known to be a string." |
|
3050 |
||
3051 |
^ self , string1 , string2 |
|
3052 |
! |
|
3053 |
||
3054 |
concatenate:string1 and:string2 and:string3 |
|
3055 |
"return the concatenation of myself and the string arguments. |
|
3056 |
This is equivalent to self , string1 , string2 , string3 |
|
3057 |
- generated by compiler when such a construct is detected and the receiver |
|
3058 |
is known to be a string." |
|
3059 |
||
3060 |
^ self , string1 , string2 , string3 |
|
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3061 |
! |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3062 |
|
11329 | 3063 |
contractAtBeginningTo:maxLen |
3064 |
"if the receivers size is less or equal to maxLen, return it. |
|
3065 |
Otherwise, return a copy of the receiver, where some characters |
|
3066 |
at the beginning have been replaced by '...' for a total string length |
|
3067 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
3068 |
||
3069 |
|sz| |
|
3070 |
||
3071 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3072 |
||
3073 |
^ '...' , (self copyFrom:(sz - (maxLen - 4))) |
|
3074 |
||
3075 |
" |
|
3076 |
'12345678901234' contractAtBeginningTo:15 |
|
3077 |
'123456789012345' contractAtBeginningTo:15 |
|
3078 |
'1234567890123456' contractAtBeginningTo:15 |
|
3079 |
'aShortString' contractAtBeginningTo:15 |
|
3080 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15 |
|
3081 |
" |
|
3082 |
||
3083 |
"Modified: / 24-10-2006 / 12:32:13 / cg" |
|
3084 |
! |
|
3085 |
||
3086 |
contractAtEndTo:maxLen |
|
3087 |
"if the receivers size is less or equal to maxLen, return it. |
|
3088 |
Otherwise, return a copy of the receiver, where some characters |
|
3089 |
at the end have been replaced by '...' for a total string length |
|
3090 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
3091 |
||
3092 |
|sz| |
|
3093 |
||
3094 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3095 |
||
3096 |
^ (self copyTo:maxLen-3),'...' |
|
3097 |
||
3098 |
" |
|
3099 |
'12345678901234' contractAtEndTo:15 |
|
3100 |
'123456789012345' contractAtEndTo:15 |
|
3101 |
'1234567890123456' contractAtEndTo:15 |
|
3102 |
'aShortString' contractAtEndTo:15 |
|
3103 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 |
|
3104 |
" |
|
3105 |
||
3106 |
"Modified: / 24-10-2006 / 12:32:26 / cg" |
|
3107 |
! |
|
3108 |
||
3109 |
contractLeftTo:maxLen |
|
3110 |
"if the receivers size is less or equal to maxLen, return it. |
|
3111 |
Otherwise, return a copy of the receiver, where some characters |
|
3112 |
near the first quarter have been replaced by '...' for a total string length |
|
3113 |
of maxLen. |
|
3114 |
Very similar to contractTo:, but better to abbreviate long filename entries, |
|
3115 |
where the right part is of more use than the left." |
|
3116 |
||
3117 |
|sz "{ SmallInteger }" |
|
3118 |
halfSize quarterSize "{ SmallInteger }" |
|
3119 |
leftEnd rightEnd rightStart| |
|
3120 |
||
3121 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3122 |
||
3123 |
halfSize := maxLen // 2. |
|
3124 |
quarterSize := maxLen // 4. |
|
3125 |
leftEnd := quarterSize-1. |
|
3126 |
rightEnd := maxLen - leftEnd - 3. |
|
3127 |
rightStart := sz - rightEnd + 1. |
|
3128 |
^ (self copyTo:leftEnd),'...',(self copyFrom:rightStart) |
|
3129 |
||
3130 |
" |
|
3131 |
'12345678901234' contractLeftTo:15 |
|
3132 |
'123456789012345' contractLeftTo:15 |
|
3133 |
'1234567890123456' contractLeftTo:15 |
|
3134 |
'aShortString' contractLeftTo:15 |
|
3135 |
'aVeryLongNameForAStringThatShouldBeShortened' contractLeftTo:15 |
|
3136 |
'C:\Dokumente und Einstellungen\cg\work\bosch\dapas\hw_schnittstellen\DAPAS__HpibDLL.st' contractLeftTo:40 |
|
3137 |
" |
|
3138 |
! |
|
3139 |
||
3140 |
contractTo:maxLen |
|
3141 |
"if the receivers size is less or equal to maxLen, return it. |
|
3142 |
Otherwise, return a copy of the receiver, where some characters |
|
3143 |
in the middle have been replaced by '...' for a total string length |
|
3144 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
3145 |
||
3146 |
|sz "{ SmallInteger }" |
|
3147 |
halfSize "{ SmallInteger }" |
|
3148 |
leftEnd rightStart| |
|
3149 |
||
3150 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3151 |
||
3152 |
halfSize := maxLen // 2. |
|
3153 |
leftEnd := halfSize-1. |
|
3154 |
rightStart := sz-halfSize+2. |
|
3155 |
halfSize even ifTrue:[ |
|
3156 |
rightStart := rightStart+1. |
|
3157 |
]. |
|
3158 |
^ (self copyTo:leftEnd),'...',(self copyFrom:rightStart) |
|
3159 |
||
3160 |
" |
|
3161 |
'12345678901234' contractTo:15 |
|
3162 |
'123456789012345' contractTo:15 |
|
3163 |
'1234567890123456' contractTo:15 |
|
3164 |
'aShortString' contractTo:15 |
|
3165 |
'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 |
|
3166 |
'C:\Dokumente und Einstellungen\cg\work\bosch\dapas\hw_schnittstellen\DAPAS__HpibDLL.st' contractTo:40 |
|
3167 |
" |
|
3168 |
||
3169 |
"Modified: / 24-10-2006 / 12:23:56 / cg" |
|
3170 |
! |
|
3171 |
||
8347 | 3172 |
copyReplaceString:subString withString:newString |
3173 |
"return a copy of the receiver, with all sequences of subString replaced |
|
3174 |
by newString (i.e. slice in the newString in place of the oldString)." |
|
3175 |
||
3176 |
|tmpStream idx idx1| |
|
3177 |
||
11348
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
3178 |
tmpStream := CharacterWriteStream on:(self class new). |
8347 | 3179 |
idx := 1. |
3180 |
[idx ~~ 0] whileTrue:[ |
|
11348
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
3181 |
idx1 := idx. |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
3182 |
idx := self indexOfSubCollection:subString startingAt:idx. |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
3183 |
idx ~~ 0 ifTrue:[ |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
3184 |
tmpStream nextPutAll:(self copyFrom:idx1 to:idx-1). |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
3185 |
tmpStream nextPutAll:newString. |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
3186 |
idx := idx + subString size |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
3187 |
] |
8347 | 3188 |
]. |
3189 |
tmpStream nextPutAll:(self copyFrom:idx1). |
|
3190 |
^ tmpStream contents |
|
3191 |
||
3192 |
" |
|
9306 | 3193 |
'12345678901234567890' copyReplaceString:'123' withString:'OneTwoThree' |
3194 |
'12345678901234567890' copyReplaceString:'123' withString:'*' |
|
3195 |
'12345678901234567890' copyReplaceString:'234' withString:'foo' |
|
3196 |
||
3197 |
('a string with spaces' copyReplaceAll:$ withAll:' foo ') |
|
11348
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
3198 |
copyReplaceString:'foo' withString:'bar' |
8347 | 3199 |
" |
3200 |
||
3201 |
"Modified: / 31-05-1999 / 12:33:59 / cg" |
|
3202 |
"Created: / 12-05-2004 / 12:00:00 / cg" |
|
3203 |
! |
|
3204 |
||
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3205 |
copyWith:aCharacter |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3206 |
"return a new string containing the receivers characters |
8874 | 3207 |
and the single new character, aCharacter. |
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3208 |
This is different from concatentation, which expects another string |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3209 |
as argument, but equivalent to copy-and-addLast. |
8874 | 3210 |
The code below cares for different width characters |
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3211 |
(i.e. when appending a 16bit char to an 8bit string)" |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3212 |
|
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3213 |
|sz newString| |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3214 |
|
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3215 |
aCharacter bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
9192 | 3216 |
sz := self size. |
3217 |
newString := aCharacter stringSpecies new:sz + 1. |
|
3218 |
newString replaceFrom:1 to:sz with:self startingAt:1. |
|
3219 |
newString at:sz+1 put:aCharacter. |
|
3220 |
^ newString. |
|
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3221 |
]. |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3222 |
^ super copyWith:aCharacter |
608 | 3223 |
! ! |
3224 |
||
3225 |
!CharacterArray methodsFor:'displaying'! |
|
3226 |
||
2762 | 3227 |
displayOn:aGC x:x y:y from:start to:stop |
3228 |
"display the receiver on a GC" |
|
3229 |
||
3230 |
"q&d hack" |
|
3231 |
||
3232 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:false |
|
3233 |
||
3234 |
"Modified: 12.5.1996 / 12:49:33 / cg" |
|
3235 |
! |
|
3236 |
||
7082 | 3237 |
displayOn:aGc x:x y:y opaque:opaque |
2762 | 3238 |
"display the receiver in a graphicsContext - this method allows |
3239 |
strings to be used like DisplayObjects." |
|
3240 |
||
3241 |
|s| |
|
3242 |
||
3243 |
s := self string. |
|
7082 | 3244 |
opaque ifTrue:[ |
9192 | 3245 |
aGc displayOpaqueString:s x:x y:y. |
2762 | 3246 |
] ifFalse:[ |
9192 | 3247 |
aGc displayString:s x:x y:y. |
2762 | 3248 |
]. |
1381 | 3249 |
|
3250 |
"Modified: 11.5.1996 / 14:42:48 / cg" |
|
3251 |
! |
|
3252 |
||
2762 | 3253 |
displayOpaqueOn:aGC x:x y:y from:start to:stop |
3254 |
"display the receiver on a GC" |
|
3255 |
||
3256 |
"q&d hack" |
|
3257 |
||
3258 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:true |
|
3259 |
||
3260 |
"Created: 12.5.1996 / 12:29:37 / cg" |
|
3261 |
"Modified: 12.5.1996 / 12:49:19 / cg" |
|
608 | 3262 |
! ! |
3263 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3264 |
!CharacterArray methodsFor:'emphasis'! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3265 |
|
11632
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
3266 |
actionForAll:aBlock |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
3267 |
"change the action block of all characters" |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
3268 |
|
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
3269 |
^ self asText actionForAll:aBlock |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
3270 |
! |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
3271 |
|
5732 | 3272 |
allBold |
3273 |
"return a test object representing the receiver, but all boldified" |
|
3274 |
||
8874 | 3275 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
6187 | 3276 |
Text isNil ifTrue:[^ self]. |
5732 | 3277 |
^ self asText allBold |
3278 |
||
3279 |
" |
|
3280 |
Transcript showCR:'hello' asText allBold |
|
3281 |
Transcript showCR:'hello' allBold |
|
3282 |
" |
|
3283 |
! |
|
3284 |
||
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3285 |
allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3286 |
"return a test object representing the receiver, but all in italic" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3287 |
|
8874 | 3288 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
6187 | 3289 |
Text isNil ifTrue:[^ self]. |
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3290 |
^ self asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3291 |
|
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3292 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3293 |
Transcript showCR:'hello' asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3294 |
Transcript showCR:'hello' allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3295 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3296 |
! |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3297 |
|
11345 | 3298 |
allStrikedOut |
3299 |
"return a test object representing the receiver, but all in strikeout" |
|
3300 |
||
3301 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
3302 |
Text isNil ifTrue:[^ self]. |
|
3303 |
^ self asText allStrikedOut |
|
3304 |
||
3305 |
" |
|
3306 |
Transcript showCR:'hello' asText allStrikedOut |
|
3307 |
Transcript showCR:'hello' allStrikedOut |
|
3308 |
" |
|
3309 |
! |
|
3310 |
||
10862 | 3311 |
allUnderlined |
3312 |
"return a test object representing the receiver, but all with underline" |
|
3313 |
||
3314 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
3315 |
Text isNil ifTrue:[^ self]. |
|
3316 |
^ self asText allUnderlined |
|
3317 |
||
3318 |
" |
|
3319 |
Transcript showCR:'hello' asText allUnderlined |
|
3320 |
Transcript showCR:'hello' allUnderlined |
|
3321 |
" |
|
3322 |
! |
|
3323 |
||
6228 | 3324 |
colorizeAllWith:aColor |
3325 |
^ self asText colorizeAllWith:aColor |
|
3326 |
||
3327 |
" |
|
3328 |
Transcript showCR:('hello' colorizeAllWith:Color red) |
|
3329 |
Transcript showCR:('world' colorizeAllWith:Color green darkened) |
|
3330 |
" |
|
3331 |
! |
|
3332 |
||
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3333 |
emphasis |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3334 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3335 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3336 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3337 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3338 |
^ RunArray new:self size withAll:nil |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3339 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3340 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3341 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3342 |
|
6655 | 3343 |
emphasis:emphasisCollection |
3344 |
^ self asText emphasis:emphasisCollection |
|
3345 |
||
3346 |
" |
|
3347 |
Transcript showCR:('hello' emphasis:#(bold bold bold bold bold)) |
|
3348 |
" |
|
3349 |
! |
|
3350 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3351 |
emphasisAt:characterIndex |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3352 |
"return the emphasis at some index. |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3353 |
Since characterArrays do not hold any emphasis information, |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3354 |
nil (no emphasis) is returned here." |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3355 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3356 |
^ nil |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3357 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3358 |
"Created: 11.5.1996 / 14:13:27 / cg" |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3359 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3360 |
|
11632
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
3361 |
emphasisAtPoint:aPoint on:aGC |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
3362 |
"return the emphasis at a given point, or nil if there is none" |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
3363 |
|
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
3364 |
^ nil |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
3365 |
! |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
3366 |
|
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3367 |
emphasisCollection |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3368 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3369 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3370 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3371 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3372 |
^ RunArray new:(self size) |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3373 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3374 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3375 |
"Modified: 14.5.1996 / 15:02:29 / cg" |
3404 | 3376 |
! |
3377 |
||
11919 | 3378 |
emphasiseFrom:start to:stop with:newEmphasis |
3379 |
"set to the emphasis within some range. return the receiver" |
|
3380 |
||
3381 |
^ self asText emphasiseFrom:start to:stop with:newEmphasis |
|
3382 |
||
3383 |
" |
|
3384 |
'hello' emphasiseFrom:2 with:#italic |
|
3385 |
||
3386 |
Transcript showCR:('hello' emphasiseFrom:2 with:#italic) |
|
3387 |
" |
|
3388 |
! |
|
3389 |
||
3390 |
emphasiseFrom:start with:newEmphasis |
|
3391 |
"set to the emphasis within some range. return the receiver" |
|
3392 |
||
3393 |
^ self emphasiseFrom:start to:(self size) with:newEmphasis |
|
3394 |
||
3395 |
" |
|
3396 |
'hello' emphasiseFrom:2 with:#italic |
|
3397 |
||
3398 |
Transcript showCR:('hello' emphasiseFrom:2 with:#italic) |
|
3399 |
" |
|
3400 |
! |
|
3401 |
||
3404 | 3402 |
emphasizeAllWith:emphasis |
3403 |
^ self asText emphasizeAllWith:emphasis |
|
3404 |
||
3405 |
" |
|
3406 |
Transcript showCR:('hello' emphasizeAllWith:#bold) |
|
3599 | 3407 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
3408 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
|
3409 |
" |
|
3410 |
||
3411 |
"Modified: / 17.6.1998 / 12:51:44 / cg" |
|
5097 | 3412 |
! |
3413 |
||
3414 |
makeSelectorBoldIn:aClass |
|
3415 |
"the receiver represents some source code for |
|
3416 |
a method in aClass. |
|
3417 |
Change myself to boldify the selector. |
|
3418 |
Not yet implemented (could easily use the syntaxHighlighter |
|
3419 |
for this ...)" |
|
3420 |
||
3421 |
^ self |
|
3422 |
||
3423 |
"Modified: / 13.12.1999 / 21:49:11 / cg" |
|
3424 |
"Created: / 13.12.1999 / 21:49:24 / cg" |
|
6653 | 3425 |
! |
3426 |
||
3427 |
withoutEmphasis:emphasisToRemove |
|
3428 |
^ self |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3429 |
! ! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3430 |
|
7265 | 3431 |
!CharacterArray methodsFor:'encoding & decoding'! |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3432 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3433 |
decodeFrom:encodingSymbol |
8874 | 3434 |
"given the receiver encoded as described by encodingSymbol, |
8124
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
3435 |
convert it into internal ST/X (unicode) encoding and return a corresponding CharacterArray." |
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
3436 |
|
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
3437 |
|myEncoding encoder| |
7950 | 3438 |
|
3439 |
encodingSymbol isNil ifTrue:[^ self]. |
|
3440 |
myEncoding := self encoding. |
|
3441 |
encodingSymbol == myEncoding ifTrue:[^ self]. |
|
3442 |
||
3443 |
encoder := CharacterEncoder encoderToEncodeFrom:(self encoding) into:encodingSymbol. |
|
8124
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
3444 |
encoder isNil ifTrue:[^ self]. |
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
3445 |
^ encoder decodeString:self. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3446 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3447 |
|
9192 | 3448 |
encodeFrom:oldEncoding into:newEncoding |
3449 |
^ CharacterEncoder encodeString:self from:oldEncoding into:newEncoding |
|
3450 |
! |
|
3451 |
||
3452 |
rot13 |
|
8874 | 3453 |
"Usenet: from `rotate alphabet 13 places'] |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3454 |
The simple Caesar-cypher encryption that replaces each English |
8874 | 3455 |
letter with the one 13 places forward or back along the alphabet, |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3456 |
so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' |
8874 | 3457 |
Most Usenet news reading and posting programs include a rot13 feature. |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3458 |
It is used to enclose the text in a sealed wrapper that the reader must choose |
8874 | 3459 |
to open -- e.g., for posting things that might offend some readers, or spoilers. |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3460 |
A major advantage of rot13 over rot(N) for other N is that it |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3461 |
is self-inverse, so the same code can be used for encoding and decoding." |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3462 |
|
11865 | 3463 |
^ self rot:13 |
8874 | 3464 |
|
3465 |
" |
|
3466 |
'hello world' rot13 |
|
3467 |
'hello world' rot13 rot13 |
|
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3468 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3469 |
! |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3470 |
|
11865 | 3471 |
rot:n |
3472 |
"Usenet: from `rotate alphabet N places'] |
|
3473 |
The simple Caesar-cypher encryption that replaces each English |
|
3474 |
letter with the one N places forward or back along the alphabet, |
|
3475 |
so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' by rot 13 |
|
3476 |
Most Usenet news reading and posting programs include a rot13 feature. |
|
3477 |
It is used to enclose the text in a sealed wrapper that the reader must choose |
|
3478 |
to open -- e.g., for posting things that might offend some readers, or spoilers. |
|
3479 |
A major advantage of rot13 over rot(N) for other N is that it |
|
3480 |
is self-inverse, so the same code can be used for encoding and decoding." |
|
3481 |
||
3482 |
^ self species |
|
3483 |
streamContents:[:aStream | |
|
3484 |
self do:[:char | |
|
3485 |
aStream nextPut:(char rot:n) ]] |
|
3486 |
||
3487 |
" |
|
3488 |
'hello world' rot:13 |
|
3489 |
('hello world' rot:13) rot:13 |
|
3490 |
" |
|
3491 |
! |
|
3492 |
||
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3493 |
utf8Decoded |
7950 | 3494 |
"Interpreting myself as an UTF-8 representation, decode and return the decoded string." |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3495 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3496 |
|in out is16Bit c| |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3497 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3498 |
is16Bit := false. |
11326
11ce7ae19315
changed #utf8Decoded - use CharacterWriteStream
Stefan Vogel <sv@exept.de>
parents:
11320
diff
changeset
|
3499 |
out := CharacterWriteStream on:(String uninitializedNew:self size). |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3500 |
in := self readStream. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3501 |
[in atEnd] whileFalse:[ |
11326
11ce7ae19315
changed #utf8Decoded - use CharacterWriteStream
Stefan Vogel <sv@exept.de>
parents:
11320
diff
changeset
|
3502 |
c := Character utf8DecodeFrom:in. |
11ce7ae19315
changed #utf8Decoded - use CharacterWriteStream
Stefan Vogel <sv@exept.de>
parents:
11320
diff
changeset
|
3503 |
out nextPut:c. |
8874 | 3504 |
]. |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3505 |
^ out contents |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3506 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3507 |
" |
8874 | 3508 |
#[16rC8 16rA0] asString utf8Decoded |
3509 |
(Character value:16r220) utf8Encoded |
|
3510 |
(Character value:16r220) utf8Encoded utf8Decoded |
|
3511 |
||
3512 |
(Character value:16r800) utf8Encoded |
|
3513 |
(Character value:16r220) utf8Encoded utf8Decoded |
|
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3514 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3515 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3516 |
"test: |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3517 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3518 |
|utf8Encoding original readBack| |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3519 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3520 |
1 to:16rFFFF do:[:ascii | |
11326
11ce7ae19315
changed #utf8Decoded - use CharacterWriteStream
Stefan Vogel <sv@exept.de>
parents:
11320
diff
changeset
|
3521 |
original := (Character value:ascii) asString. |
11ce7ae19315
changed #utf8Decoded - use CharacterWriteStream
Stefan Vogel <sv@exept.de>
parents:
11320
diff
changeset
|
3522 |
utf8Encoding := original utf8Encoded. |
11ce7ae19315
changed #utf8Decoded - use CharacterWriteStream
Stefan Vogel <sv@exept.de>
parents:
11320
diff
changeset
|
3523 |
readBack := utf8Encoding utf8Decoded. |
11ce7ae19315
changed #utf8Decoded - use CharacterWriteStream
Stefan Vogel <sv@exept.de>
parents:
11320
diff
changeset
|
3524 |
readBack = original ifFalse:[ |
11ce7ae19315
changed #utf8Decoded - use CharacterWriteStream
Stefan Vogel <sv@exept.de>
parents:
11320
diff
changeset
|
3525 |
self halt |
11ce7ae19315
changed #utf8Decoded - use CharacterWriteStream
Stefan Vogel <sv@exept.de>
parents:
11320
diff
changeset
|
3526 |
] |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3527 |
] |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3528 |
" |
9192 | 3529 |
! |
3530 |
||
3531 |
utf8DecodedWithTwoByteCharactersReplacedBy:replacementCharacter |
|
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3532 |
"Interpreting myself as an UTF-8 representation, decode and return |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3533 |
the decoded string. Suppress all 2-byte (above 16rFF) characters, |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3534 |
and replace them with replacementCharacter" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3535 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3536 |
|in out c| |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3537 |
|
8222
f2c454a9a038
replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents:
8124
diff
changeset
|
3538 |
out := WriteStream on:(String uninitializedNew:self size). |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3539 |
in := self readStream. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3540 |
[in atEnd] whileFalse:[ |
9192 | 3541 |
c := Character utf8DecodeFrom:in. |
3542 |
c codePoint > 16rFF ifTrue:[ |
|
3543 |
c := replacementCharacter |
|
3544 |
]. |
|
3545 |
out nextPut:c. |
|
8874 | 3546 |
]. |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3547 |
^ out contents |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3548 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
3549 |
" |
8874 | 3550 |
(Character value:16r220) utf8Encoded |
9192 | 3551 |
utf8DecodedWithTwoByteCharactersReplacedBy:(Character space) |
3552 |
" |
|
3553 |
! |
|
3554 |
||
3555 |
utf8Encoded |
|
3556 |
"Return my UTF-8 representation as a new String" |
|
3557 |
||
3558 |
|s| |
|
3559 |
||
3560 |
s := WriteStream on:(String uninitializedNew:self size). |
|
11320 | 3561 |
s nextPutAllUtf8:self. |
9192 | 3562 |
^ s contents |
11320 | 3563 |
|
3564 |
" |
|
3565 |
'abcdeäöüß' utf8Encoded |
|
3566 |
" |
|
9192 | 3567 |
! ! |
3568 |
||
11345 | 3569 |
|
12111 | 3570 |
!CharacterArray methodsFor:'matching - glob expressions'! |
3571 |
||
3572 |
compoundMatch:aString |
|
3573 |
"like match, but the receiver may be a compound match pattern, |
|
3574 |
consisting of multiple simple patterns, separated by semicolons. |
|
3575 |
This is usable with fileName pattern fields. |
|
3576 |
||
3577 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3578 |
NOT the ST-80 meaning. |
|
3579 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3580 |
NOTICE: the receiver is the match pattern" |
|
3581 |
||
3582 |
^self compoundMatch:aString ignoreCase:false |
|
3583 |
||
3584 |
" |
|
3585 |
'f*' match:'foo' |
|
3586 |
'b*' match:'foo' |
|
3587 |
'f*;b*' match:'foo' |
|
3588 |
'f*;b*' match:'bar' |
|
3589 |
'f*;b*' compoundMatch:'foo' |
|
3590 |
'f*;b*' compoundMatch:'bar' |
|
3591 |
" |
|
3592 |
||
3593 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
3594 |
"Modified: / 16.12.1999 / 01:22:08 / cg" |
|
3595 |
! |
|
3596 |
||
3597 |
compoundMatch:aString ignoreCase:ignoreCase |
|
3598 |
"like match, but the receiver may be a compound match pattern, |
|
3599 |
consisting of multiple simple patterns, separated by semicolons. |
|
3600 |
This is usable with fileName pattern fields. |
|
3601 |
||
3602 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3603 |
NOT the ST-80 meaning. |
|
3604 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3605 |
NOTICE: the receiver is the match pattern" |
|
3606 |
||
3607 |
|matchers| |
|
3608 |
||
3609 |
matchers := self asCollectionOfSubstringsSeparatedBy:$;. |
|
3610 |
^ matchers contains:[:aPattern | |
|
3611 |
aPattern match:aString ignoreCase:ignoreCase escapeCharacter:nil |
|
3612 |
]. |
|
3613 |
||
3614 |
"/ matchers do:[:aPattern | |
|
3615 |
"/ (aPattern match:aString ignoreCase:ignoreCase) ifTrue:[^ true]. |
|
3616 |
"/ ]. |
|
3617 |
"/ ^ false. |
|
3618 |
||
3619 |
" |
|
3620 |
'f*' match:'foo' |
|
3621 |
'b*' match:'foo' |
|
3622 |
'f*;b*' match:'foo' |
|
3623 |
'f*;b*' match:'bar' |
|
3624 |
'f*;b*' compoundMatch:'foo' |
|
3625 |
'f*;b*' compoundMatch:'bar' |
|
3626 |
'f*;b*' compoundMatch:'Foo' ignoreCase:true |
|
3627 |
'f*;b*' compoundMatch:'Bar' ignoreCase:true |
|
3628 |
'f*;b*' compoundMatch:'ccc' ignoreCase:true |
|
3629 |
" |
|
3630 |
||
3631 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
3632 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
3633 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
3634 |
! |
|
3635 |
||
3636 |
findMatchString:matchString |
|
3637 |
"like findString/indexOfSubCollection, but allowing match patterns. |
|
3638 |
find matchstring; if found, return the index; |
|
3639 |
if not found, return 0. |
|
3640 |
||
3641 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
3642 |
NOT the ST-80 meaning. |
|
3643 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3644 |
NOTICE: the argument is the match pattern" |
|
3645 |
||
3646 |
^ self findMatchString:matchString startingAt:1 ignoreCase:false ifAbsent:0 |
|
3647 |
! |
|
3648 |
||
3649 |
findMatchString:matchString startingAt:index |
|
3650 |
"like findString, but allowing match patterns. |
|
3651 |
find matchstring, starting at index. if found, return the index; |
|
3652 |
if not found, return 0. |
|
3653 |
||
3654 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3655 |
NOT the ST-80 meaning. |
|
3656 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3657 |
NOTICE: the argument is the match pattern" |
|
3658 |
||
3659 |
^ self findMatchString:matchString startingAt:index ignoreCase:false ifAbsent:0 |
|
3660 |
! |
|
3661 |
||
3662 |
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock |
|
3663 |
"like findString, but allowing match patterns. |
|
3664 |
find matchstring, starting at index. if found, return the index; |
|
3665 |
if not found, return the result of evaluating exceptionBlock. |
|
3666 |
This is a q&d hack - not very efficient. |
|
3667 |
||
3668 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3669 |
NOT the ST-80 meaning. |
|
3670 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3671 |
NOTICE: the argument is the match pattern" |
|
3672 |
||
3673 |
|firstChar firstSet |
|
3674 |
startIndex "{ Class: SmallInteger }" |
|
3675 |
matchSize "{ Class: SmallInteger }" |
|
3676 |
mySize "{ Class: SmallInteger }" |
|
3677 |
realMatchString lcChar ucChar| |
|
3678 |
||
3679 |
matchSize := matchString size. |
|
3680 |
matchSize == 0 ifTrue:[^ index]. "empty string matches" |
|
3681 |
||
3682 |
realMatchString := matchString. |
|
3683 |
(realMatchString endsWith:$*) ifFalse:[ |
|
3684 |
realMatchString := realMatchString , '*'. |
|
3685 |
matchSize := matchSize + 1 |
|
3686 |
]. |
|
3687 |
||
3688 |
mySize := self size. |
|
3689 |
firstChar := realMatchString at:1. |
|
3690 |
firstChar == self class matchEscapeCharacter ifTrue:[ |
|
3691 |
firstChar := realMatchString at:2. |
|
3692 |
]. |
|
3693 |
||
3694 |
firstChar asString includesMatchCharacters ifTrue:[ |
|
3695 |
index to:mySize do:[:col | |
|
3696 |
(realMatchString match:self from:col to:mySize ignoreCase:ignoreCase) |
|
3697 |
ifTrue:[^ col] |
|
3698 |
]. |
|
3699 |
^ exceptionBlock value. |
|
3700 |
]. |
|
3701 |
||
3702 |
lcChar := firstChar asLowercase. |
|
3703 |
ucChar := firstChar asUppercase. |
|
3704 |
(ignoreCase and:[ lcChar ~= ucChar]) ifTrue:[ |
|
3705 |
firstSet := Array with:ucChar with:lcChar. |
|
3706 |
startIndex := self indexOfAny:firstSet startingAt:index. |
|
3707 |
] ifFalse:[ |
|
3708 |
startIndex := self indexOf:firstChar startingAt:index. |
|
3709 |
]. |
|
3710 |
[startIndex == 0] whileFalse:[ |
|
3711 |
(realMatchString match:self from:startIndex to:mySize ignoreCase:ignoreCase) |
|
3712 |
ifTrue:[^ startIndex]. |
|
3713 |
firstSet notNil ifTrue:[ |
|
3714 |
startIndex := self indexOfAny:firstSet startingAt:(startIndex + 1). |
|
3715 |
] ifFalse:[ |
|
3716 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1). |
|
3717 |
]. |
|
3718 |
]. |
|
3719 |
^ exceptionBlock value |
|
3720 |
||
3721 |
" |
|
3722 |
'one two three four' findMatchString:'o[nu]' |
|
3723 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
3724 |
'one two three four one' findMatchString:'ONE' startingAt:3 ignoreCase:true ifAbsent:0 |
|
3725 |
" |
|
3726 |
||
3727 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
|
3728 |
! |
|
3729 |
||
3730 |
includesMatchString:matchString |
|
3731 |
"like includesString, but allowing match patterns. |
|
3732 |
find matchstring; if found, return true, otherwise return false. |
|
3733 |
||
3734 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3735 |
NOT the ST-80 meaning. |
|
3736 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3737 |
NOTICE: the argument is the match pattern" |
|
3738 |
||
3739 |
^ (self findMatchString:matchString) ~~ 0 |
|
3740 |
||
3741 |
" |
|
3742 |
'hello world' includesMatchString:'h*' |
|
3743 |
'hello world' includesMatchString:'h[aeiou]llo' |
|
3744 |
'hello world' includesMatchString:'wor*' |
|
3745 |
'hello world' includesMatchString:'woR*' |
|
3746 |
" |
|
3747 |
! |
|
3748 |
||
3749 |
includesMatchString:matchString caseSensitive:caseSensitive |
|
3750 |
"like includesString, but allowing match patterns. |
|
3751 |
find matchstring; if found, return true, otherwise return false. |
|
3752 |
||
3753 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3754 |
NOT the ST-80 meaning. |
|
3755 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3756 |
NOTICE: the argument is the match pattern" |
|
3757 |
||
3758 |
^ (self findMatchString:matchString startingAt:1 ignoreCase:caseSensitive not ifAbsent:0) ~~ 0 |
|
3759 |
||
3760 |
" |
|
3761 |
'hello world' includesMatchString:'h*' caseSensitive:true |
|
3762 |
'hello world' includesMatchString:'h*' caseSensitive:false |
|
3763 |
'Hello world' includesMatchString:'h*' caseSensitive:true |
|
3764 |
'Hello world' includesMatchString:'h*' caseSensitive:false |
|
3765 |
||
3766 |
'hello world' includesMatchString:'h[aeiou]llo' caseSensitive:true |
|
3767 |
'hello world' includesMatchString:'h[aeiou]llo' caseSensitive:false |
|
3768 |
||
3769 |
'hello world' includesMatchString:'wor*' caseSensitive:true |
|
3770 |
'hello world' includesMatchString:'wor*' caseSensitive:false |
|
3771 |
||
3772 |
'hello world' includesMatchString:'woR*' caseSensitive:true |
|
3773 |
'hello world' includesMatchString:'woR*' caseSensitive:false |
|
3774 |
" |
|
3775 |
! |
|
3776 |
||
3777 |
match:aString |
|
3778 |
"return true if aString matches self, where self may contain meta-match |
|
3779 |
characters $* (to match any string) or $# (to match any character). |
|
3780 |
or [...] to match a set of characters. |
|
3781 |
Lower/uppercase are considered different. |
|
3782 |
The escape character is the backQuote. |
|
3783 |
||
3784 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3785 |
NOT the ST-80 meaning. |
|
3786 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3787 |
NOTICE: the receiver is the match pattern" |
|
3788 |
||
3789 |
^ self match:aString from:1 to:aString size ignoreCase:false |
|
3790 |
||
3791 |
" |
|
3792 |
'\*f*' match:'f' |
|
3793 |
'\*f*' match:'*f' |
|
3794 |
'*\*f*' match:'*f' |
|
3795 |
'*f*' match:'*f' |
|
3796 |
'*ute*' match:'computer' |
|
3797 |
'*uter' match:'computer' |
|
3798 |
'uter*' match:'computer' |
|
3799 |
'*ute*' match:'' |
|
3800 |
'[abcd]*' match:'computer' |
|
3801 |
'[abcd]*' match:'komputer' |
|
3802 |
'*some*compl*ern*' match:'this is some more complicated pattern match' |
|
3803 |
'*some*compl*ern*' match:'this is another complicated pattern match' |
|
3804 |
'*-hh' match:'anton-h' |
|
3805 |
" |
|
3806 |
||
3807 |
"Modified: / 9.6.1998 / 18:50:00 / cg" |
|
3808 |
! |
|
3809 |
||
3810 |
match:aString escapeCharacter:escape |
|
3811 |
"return true if aString matches self, where self may contain meta-match |
|
3812 |
characters $* (to match any string) or $# (to match any character). |
|
3813 |
or [...] to match a set of characters. |
|
3814 |
Lower/uppercase are considered different. |
|
3815 |
||
3816 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3817 |
NOT the ST-80 meaning. |
|
3818 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3819 |
NOTICE: the receiver is the match pattern" |
|
3820 |
||
3821 |
^ self match:aString from:1 to:aString size ignoreCase:false escapeCharacter:escape |
|
3822 |
||
3823 |
" |
|
3824 |
'a\b\c\*' match:'a\b\c\d' |
|
3825 |
'a\b\c\*' match:'a\b\c\d' escapeCharacter:nil |
|
3826 |
" |
|
3827 |
! |
|
3828 |
||
3829 |
match:aString from:start to:stop ignoreCase:ignoreCase |
|
3830 |
"return true if part of aString matches myself, |
|
3831 |
where self may contain meta-match |
|
3832 |
characters $* (to match any string) or $# (to match any character) |
|
3833 |
or [...] to match a set of characters. |
|
3834 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
3835 |
The escape character is the backQuote. |
|
3836 |
||
3837 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3838 |
NOT the ST-80 meaning. |
|
3839 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3840 |
NOTICE: the receiver is the match pattern" |
|
3841 |
||
3842 |
^ self |
|
3843 |
match:aString from:start to:stop ignoreCase:ignoreCase |
|
3844 |
escapeCharacter:(self class matchEscapeCharacter) |
|
3845 |
||
3846 |
" |
|
3847 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
3848 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
3849 |
" |
|
3850 |
||
3851 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
3852 |
! |
|
3853 |
||
3854 |
match:aString from:start to:stop ignoreCase:ignoreCase escapeCharacter:escape |
|
3855 |
"return true if part of aString matches myself, |
|
3856 |
where self may contain meta-match |
|
3857 |
characters $* (to match any string) or $# (to match any character) |
|
3858 |
or [...] to match a set of characters. |
|
3859 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
3860 |
||
3861 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3862 |
NOT the ST-80 meaning. |
|
3863 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3864 |
NOTICE: the receiver is the match pattern" |
|
3865 |
||
3866 |
|matchScanArray| |
|
3867 |
||
3868 |
" |
|
3869 |
keep the matchScanArray from the most recent match - |
|
3870 |
avoids parsing the pattern over-and over if multiple searches |
|
3871 |
are done with the same pattern. |
|
3872 |
" |
|
3873 |
(PreviousMatch notNil |
|
3874 |
and:[PreviousMatch key = self]) ifTrue:[ |
|
3875 |
matchScanArray := PreviousMatch value |
|
3876 |
] ifFalse:[ |
|
3877 |
matchScanArray := self class matchScanArrayFrom:self escapeCharacter:escape. |
|
3878 |
matchScanArray isNil ifTrue:[ |
|
3879 |
'CharacterArray [info]: invalid matchpattern:''' infoPrint. self infoPrint. ''' comparing for equality.' infoPrintCR. |
|
3880 |
^ self = aString |
|
3881 |
"/ ^ false |
|
3882 |
]. |
|
3883 |
PreviousMatch := self -> matchScanArray. |
|
3884 |
]. |
|
3885 |
||
3886 |
^ self class |
|
3887 |
matchScan:matchScanArray |
|
3888 |
from:1 to:matchScanArray size |
|
3889 |
with:aString |
|
3890 |
from:start to:stop |
|
3891 |
ignoreCase:ignoreCase |
|
3892 |
||
3893 |
" |
|
3894 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
3895 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
3896 |
" |
|
3897 |
||
3898 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
3899 |
! |
|
3900 |
||
3901 |
match:aString ignoreCase:ignoreCase |
|
3902 |
"return true if aString matches self, where self may contain meta-match |
|
3903 |
characters $* (to match any string) or $# (to match any character) |
|
3904 |
or [...] to match a set of characters. |
|
3905 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
3906 |
The escape character is the backQuote. |
|
3907 |
||
3908 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3909 |
NOT the ST-80 meaning. |
|
3910 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3911 |
NOTICE: the receiver is the match pattern" |
|
3912 |
||
3913 |
^ self match:aString from:1 to:aString size ignoreCase:ignoreCase |
|
3914 |
||
3915 |
" |
|
3916 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
3917 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
3918 |
'[abcd]*' match:'computer' ignoreCase:false |
|
3919 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
3920 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
3921 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
3922 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
3923 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
3924 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
3925 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
3926 |
||
3927 |
Time millisecondsToRun:[ |
|
3928 |
Symbol allInstancesDo:[:sym | |
|
3929 |
'[ab]*' match:sym ignoreCase:false |
|
3930 |
] |
|
3931 |
]. |
|
3932 |
Time millisecondsToRun:[ |
|
3933 |
Symbol allInstancesDo:[:sym | |
|
3934 |
'*at:*' match:sym ignoreCase:false |
|
3935 |
] |
|
3936 |
]. |
|
3937 |
" |
|
3938 |
||
3939 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
3940 |
! |
|
3941 |
||
3942 |
match:aString ignoreCase:ignoreCase escapeCharacter:escape |
|
3943 |
"return true if aString matches self, where self may contain meta-match |
|
3944 |
characters $* (to match any string) or $# (to match any character) |
|
3945 |
or [...] to match a set of characters. |
|
3946 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
3947 |
||
3948 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3949 |
NOT the ST-80 meaning. |
|
3950 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3951 |
NOTICE: the receiver is the match pattern" |
|
3952 |
||
3953 |
^ self match:aString from:1 to:aString size ignoreCase:ignoreCase escapeCharacter:escape |
|
3954 |
||
3955 |
" |
|
3956 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
3957 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
3958 |
'[abcd]*' match:'computer' ignoreCase:false |
|
3959 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
3960 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
3961 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
3962 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
3963 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
3964 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
3965 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
3966 |
||
3967 |
Time millisecondsToRun:[ |
|
3968 |
Symbol allInstancesDo:[:sym | |
|
3969 |
'[ab]*' match:sym ignoreCase:false |
|
3970 |
] |
|
3971 |
]. |
|
3972 |
Time millisecondsToRun:[ |
|
3973 |
Symbol allInstancesDo:[:sym | |
|
3974 |
'*at:*' match:sym ignoreCase:false |
|
3975 |
] |
|
3976 |
]. |
|
3977 |
" |
|
3978 |
||
3979 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
3980 |
! |
|
3981 |
||
3982 |
matches:aPatternString |
|
3983 |
"return true if the receiver matches aString, where aPatternString may contain meta-match |
|
3984 |
characters $* (to match any string) or $# (to match any character). |
|
3985 |
or [...] to match a set of characters. |
|
3986 |
Lower/uppercase are considered different. |
|
3987 |
||
3988 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
3989 |
NOT the ST-80 meaning. |
|
3990 |
NOTICE: this is different from regex matching (see matchesRegex:) |
|
3991 |
NOTICE: the receiver is the match pattern" |
|
3992 |
||
3993 |
^ aPatternString match:self |
|
3994 |
! ! |
|
3995 |
||
3996 |
||
9192 | 3997 |
!CharacterArray methodsFor:'padded copying'! |
3998 |
||
3999 |
centerPaddedTo:newSize |
|
4000 |
"return a new string consisting of the receivers characters, |
|
4001 |
plus spaces up to length and center the receivers characters in |
|
4002 |
the resulting string. |
|
4003 |
If the receivers size is equal or greater than the length argument, |
|
4004 |
the original receiver is returned unchanged." |
|
4005 |
||
4006 |
^ self centerPaddedTo:newSize with:(Character space) |
|
4007 |
||
4008 |
" |
|
4009 |
'foo' centerPaddedTo:10 |
|
4010 |
123 printString centerPaddedTo:10 |
|
4011 |
" |
|
4012 |
||
4013 |
"Created: 25.11.1995 / 10:53:57 / cg" |
|
4014 |
! |
|
9190 | 4015 |
|
4016 |
centerPaddedTo:size with:padCharacter |
|
4017 |
"return a new string of length size, which contains the receiver |
|
4018 |
centered (i.e. padded on both sides). |
|
4019 |
Characters are filled with padCharacter. |
|
8874 | 4020 |
If the receivers size is equal or greater than the length argument, |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4021 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4022 |
|
9190 | 4023 |
|len s| |
4024 |
||
4025 |
len := self size. |
|
9192 | 4026 |
(len < size) ifTrue:[ |
4027 |
s := self species new:size withAll:padCharacter. |
|
4028 |
s replaceFrom:(size - len) // 2 + 1 with:self. |
|
4029 |
^ s |
|
4030 |
] |
|
4031 |
||
9190 | 4032 |
" |
4033 |
'foo' centerPaddedTo:11 with:$. |
|
4034 |
'fooBar' centerPaddedTo:5 with:$. |
|
4035 |
123 printString centerPaddedTo:10 with:$. |
|
4036 |
(' ' , 123 printString) centerPaddedTo:10 with:$. |
|
4037 |
(Float pi printString) centerPaddedTo:15 with:(Character space) |
|
4038 |
(Float pi printString) centerPaddedTo:15 with:$- |
|
4039 |
(' ' , Float pi class name) centerPaddedTo:15 with:$. |
|
4040 |
" |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4041 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4042 |
|
9190 | 4043 |
decimalPaddedTo:size and:afterPeriod at:decimalCharacter |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4044 |
"return a new string of overall length size, which contains the receiver |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4045 |
aligned at the decimal-period column and afterPeriod characters to the right |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4046 |
of the period. The periodCharacter is passed as arguments (allowing for US and European formats |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4047 |
to be padded). |
8874 | 4048 |
If the receivers size is equal or greater than the length argument, |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4049 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4050 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4051 |
|
8874 | 4052 |
^ self |
9192 | 4053 |
decimalPaddedTo:size |
4054 |
and:afterPeriod |
|
4055 |
at:decimalCharacter |
|
4056 |
withLeft:(Character space) |
|
4057 |
right:$0 |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4058 |
|
8874 | 4059 |
" |
4060 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123 ' |
|
4061 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
|
4062 |
'123.' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4063 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.100' |
8874 | 4064 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.1 ' |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4065 |
'123.123' decimalPaddedTo:10 and:3 at:$. -> ' 123.123' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4066 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4067 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4068 |
"Created: 23.12.1995 / 13:11:52 / cg" |
9192 | 4069 |
! |
4070 |
||
4071 |
decimalPaddedTo:size and:afterPeriod at:decimalCharacter withLeft:leftPadChar right:rightPadChar |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4072 |
"return a new string of overall length size, which contains the receiver |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4073 |
aligned at the decimal-period column and afterPeriod characters to the right |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4074 |
of the period. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4075 |
Characters on the left are filled with leftPadChar. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4076 |
If rightPadChar is nil, characters on the right are filled with leftPadCharacter too; |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4077 |
otherwise, if missing, a decimal point is added and right characters filled with this. |
8874 | 4078 |
If the receivers size is equal or greater than the length argument, |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4079 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4080 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4081 |
|
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4082 |
|s idx n rest| |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4083 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4084 |
idx := self indexOf:decimalCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4085 |
idx == 0 ifTrue:[ |
9192 | 4086 |
"/ |
4087 |
"/ no decimal point found; adjust string to the left of the period column |
|
4088 |
"/ |
|
4089 |
rightPadChar isNil ifTrue:[ |
|
4090 |
s := self , (self species new:afterPeriod + 1 withAll:leftPadChar) |
|
4091 |
] ifFalse:[ |
|
4092 |
s:= self , decimalCharacter asString , (self species new:afterPeriod withAll:rightPadChar). |
|
4093 |
]. |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4094 |
] ifFalse:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4095 |
|
9192 | 4096 |
"/ the number of after-decimalPoint characters |
4097 |
n := self size - idx. |
|
4098 |
rest := afterPeriod - n. |
|
4099 |
rest > 0 ifTrue:[ |
|
4100 |
s := (self species new:rest withAll:(rightPadChar ? leftPadChar)). |
|
4101 |
] ifFalse:[ |
|
4102 |
s := '' |
|
4103 |
]. |
|
4104 |
s := self , s. |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4105 |
]. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4106 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4107 |
^ s leftPaddedTo:size with:leftPadChar |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4108 |
|
8874 | 4109 |
" |
4110 |
'123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:nil -> ' 123 ' |
|
4111 |
'123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.000' |
|
4112 |
'123.' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.000' |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4113 |
'123.1' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.100' |
8874 | 4114 |
'123.1' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:nil -> ' 123.1 ' |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4115 |
'123.123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.123' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4116 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4117 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4118 |
"Modified: 23.12.1995 / 13:08:18 / cg" |
9192 | 4119 |
! |
4120 |
||
4121 |
leftPaddedTo:size |
|
4122 |
"return a new string of length size, which contains the receiver |
|
4123 |
right-adjusted (i.e. padded on the left). |
|
4124 |
Characters on the left are filled with spaces. |
|
4125 |
If the receivers size is equal or greater than the length argument, |
|
4126 |
the original receiver is returned unchanged." |
|
4127 |
||
4128 |
^ self leftPaddedTo:size with:(Character space) |
|
4129 |
||
4130 |
" |
|
4131 |
'foo' leftPaddedTo:10 |
|
4132 |
'fooBar' leftPaddedTo:5 |
|
4133 |
123 printString leftPaddedTo:10 |
|
4134 |
" |
|
4135 |
! |
|
608 | 4136 |
|
4137 |
paddedTo:newSize |
|
4138 |
"return a new string consisting of the receivers characters, |
|
4139 |
plus spaces up to length. |
|
8874 | 4140 |
If the receivers size is equal or greater than the length argument, |
608 | 4141 |
the original receiver is returned unchanged." |
4142 |
||
4143 |
^ self paddedTo:newSize with:(Character space) |
|
4144 |
||
4145 |
" |
|
8874 | 4146 |
'foo' paddedTo:10 |
4147 |
123 printString paddedTo:10 |
|
608 | 4148 |
" |
64 | 4149 |
! ! |
4150 |
||
9192 | 4151 |
!CharacterArray methodsFor:'printing & storing'! |
608 | 4152 |
|
4153 |
article |
|
4154 |
"return an article string for the receiver." |
|
4155 |
||
4156 |
|firstChar| |
|
4157 |
||
8874 | 4158 |
firstChar := (self at:1) asLowercase. |
5848 | 4159 |
((firstChar isVowel and:[firstChar ~~ $u]) or:[firstChar == $x]) ifTrue:[ |
9192 | 4160 |
^ 'an' |
608 | 4161 |
]. |
4162 |
^ 'a' |
|
5848 | 4163 |
|
4164 |
" |
|
9192 | 4165 |
'uboot' article. |
4166 |
'xmas' article. |
|
4167 |
'alarm' article. |
|
4168 |
'baby' article. |
|
5848 | 4169 |
" |
608 | 4170 |
! |
4171 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
4172 |
basicStoreString |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
4173 |
"return a String for storing myself" |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
4174 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
4175 |
|s n index| |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
4176 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
4177 |
n := self occurrencesOf:$'. |
11320 | 4178 |
n ~~ 0 ifTrue:[ |
4179 |
s := String new:(n + 2 + self size). |
|
4180 |
s at:1 put:$'. |
|
4181 |
index := 2. |
|
4182 |
self do:[:thisChar | |
|
4183 |
(thisChar == $') ifTrue:[ |
|
4184 |
s at:index put:thisChar. |
|
4185 |
index := index + 1. |
|
4186 |
]. |
|
4187 |
s at:index put:thisChar. |
|
4188 |
index := index + 1. |
|
4189 |
]. |
|
4190 |
s at:index put:$'. |
|
4191 |
^ s |
|
9192 | 4192 |
]. |
11320 | 4193 |
|
9192 | 4194 |
^ '''' , self , '''' |
4195 |
! |
|
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
4196 |
|
11774
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4197 |
displayOn:aGCOrStream |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4198 |
"Compatibility |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4199 |
append a printed desription on some stream (Dolphin, Squeak) |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4200 |
OR: |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4201 |
display the receiver in a graphicsContext at 0@0 (ST80). |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4202 |
This method allows for any object to be displayed in some view |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4203 |
(although the fallBack is to display its printString ...)" |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4204 |
|
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4205 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4206 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4207 |
(aGCOrStream isStream or:[aGCOrStream == Transcript]) ifTrue:[ |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4208 |
self storeOn:aGCOrStream. |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4209 |
^ self |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4210 |
]. |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4211 |
^ super displayOn:aGCOrStream |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4212 |
! |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4213 |
|
608 | 4214 |
displayString |
11774
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4215 |
"return a string to display the receiver in a view (inspector). |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4216 |
Here, we use storeString to have quotes around." |
608 | 4217 |
|
4218 |
^ self storeString |
|
11774
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4219 |
|
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4220 |
" |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4221 |
'foo' displayString |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
4222 |
" |
608 | 4223 |
! |
4224 |
||
4225 |
printOn:aStream |
|
4226 |
"print the receiver on aStream" |
|
4227 |
||
4228 |
aStream nextPutAll:self |
|
4229 |
! |
|
4230 |
||
4231 |
printString |
|
4232 |
"return a string for printing - thats myself" |
|
4233 |
||
4234 |
^ self |
|
3578 | 4235 |
! |
4236 |
||
4237 |
printWithQuotesDoubledOn:aStream |
|
4238 |
"put the raw storeString of myself on aStream" |
|
4239 |
||
4240 |
self do:[:thisChar | |
|
9192 | 4241 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
4242 |
aStream nextPut:thisChar |
|
3578 | 4243 |
] |
4244 |
||
4245 |
"Modified: / 15.6.1998 / 17:21:17 / cg" |
|
4246 |
"Created: / 15.6.1998 / 17:22:13 / cg" |
|
9192 | 4247 |
! ! |
4248 |
||
11955 | 4249 |
|
9192 | 4250 |
!CharacterArray methodsFor:'queries'! |
608 | 4251 |
|
4429 | 4252 |
bitsPerCharacter |
8874 | 4253 |
"return the underlying strings bitsPerCharacter |
4429 | 4254 |
(i.e. is it a regular String or a TwoByteString)" |
4255 |
||
8457 | 4256 |
|string max| |
4257 |
||
4258 |
(string := self string) ~~ self ifTrue:[ |
|
9192 | 4259 |
^ string bitsPerCharacter |
8457 | 4260 |
]. |
4261 |
||
4262 |
max := 8. |
|
4263 |
self do:[:eachCharacter | |
|
9192 | 4264 |
max := max max:(eachCharacter bitsPerCharacter) |
4265 |
]. |
|
4266 |
^ max |
|
4267 |
||
4268 |
" |
|
4269 |
'hello' bitsPerCharacter |
|
4270 |
'hello' asText allBold bitsPerCharacter |
|
4271 |
" |
|
4272 |
! |
|
8457 | 4273 |
|
4274 |
contains8BitCharacters |
|
8874 | 4275 |
"return true, if the underlying string contains 8BitCharacters (or widers) |
8457 | 4276 |
(i.e. if it is non-ascii)" |
4277 |
||
4278 |
|string| |
|
4279 |
||
4280 |
(string := self string) ~~ self ifTrue:[ |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
4281 |
^ string contains8BitCharacters |
8457 | 4282 |
]. |
8900 | 4283 |
^ self contains:[:aCharacter | aCharacter codePoint > 16r7F ]. |
8457 | 4284 |
|
4285 |
" |
|
8874 | 4286 |
'hello' contains8BitCharacters |
4287 |
'hello' asText allBold contains8BitCharacters |
|
9191 | 4288 |
" |
9192 | 4289 |
! |
4429 | 4290 |
|
10903 | 4291 |
continuesWith:aString startingAt:startIndex |
4292 |
"return true, if the receiver beginning at startIndex |
|
4293 |
contains the characters in aString." |
|
4294 |
||
4295 |
|sz "{Class: SmallInteger }" |
|
4296 |
idx "{Class: SmallInteger }"| |
|
4297 |
||
4298 |
sz := aString size. |
|
4299 |
idx := startIndex. |
|
4300 |
||
4301 |
1 to:sz do:[:i | |
|
4302 |
(self at:idx) ~~ (aString at:i) ifTrue:[^ false]. |
|
4303 |
idx := idx + 1 |
|
4304 |
]. |
|
4305 |
^ true |
|
4306 |
||
4307 |
" |
|
4308 |
'hello world' continuesWith:'world' startingAt:6 |
|
4309 |
'hello world' continuesWith:'world' startingAt:7 |
|
4310 |
" |
|
4311 |
||
4312 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
4313 |
"Modified: 26.7.1996 / 19:08:36 / cg" |
|
4314 |
! |
|
4315 |
||
4316 |
countWords |
|
4317 |
"return the number of words, which are separated by separators" |
|
4318 |
||
4319 |
|tally "{ Class: SmallInteger }" |
|
4320 |
start "{ Class: SmallInteger }" |
|
4321 |
mySize "{ Class: SmallInteger }" |
|
4322 |
stop ch| |
|
4323 |
||
4324 |
tally := 0. |
|
4325 |
start := 1. |
|
4326 |
mySize := self size. |
|
4327 |
[start <= mySize] whileTrue:[ |
|
4328 |
ch := self at:start. |
|
4329 |
ch isSeparator ifTrue:[ |
|
4330 |
start := start + 1 |
|
4331 |
] ifFalse:[ |
|
4332 |
stop := self indexOfSeparatorStartingAt:start. |
|
4333 |
(stop == 0) ifTrue:[ |
|
4334 |
stop := mySize + 1 |
|
4335 |
]. |
|
4336 |
tally := tally + 1. |
|
4337 |
start := stop |
|
4338 |
] |
|
4339 |
]. |
|
4340 |
^ tally |
|
4341 |
||
4342 |
" |
|
4343 |
'hello world isnt this nice' countWords' |
|
4344 |
" |
|
4345 |
! |
|
4346 |
||
11788 | 4347 |
defaultElement |
4348 |
^ Character space |
|
4349 |
! |
|
4350 |
||
608 | 4351 |
encoding |
1311 | 4352 |
"return the strings encoding, as a symbol. |
7982 | 4353 |
Here, by default, we assume unicode-encoding. |
4354 |
Notice, that iso8859-1 is a true subset of unicode, |
|
8874 | 4355 |
and that singleByteStrings are therefore both unicode AND |
7982 | 4356 |
8859-1 encoded." |
4357 |
||
4358 |
^ #'unicode' |
|
608 | 4359 |
! |
4360 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4361 |
hasChangeOfEmphasis |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4362 |
^ false |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4363 |
|
1381 | 4364 |
"Created: 12.5.1996 / 12:31:39 / cg" |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4365 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4366 |
|
7995
8ddbb403d67b
+hasIcon and hasImage for LabelAndIcon compatibility
Claus Gittinger <cg@exept.de>
parents:
7991
diff
changeset
|
4367 |
hasIcon |
9191 | 4368 |
"for LabelAndIcon compatibility" |
4369 |
||
9192 | 4370 |
^ false |
4371 |
! |
|
4372 |
||
4373 |
hasImage |
|
4374 |
"for LabelAndIcon compatibility" |
|
4375 |
||
4376 |
^ false |
|
4377 |
! |
|
7995
8ddbb403d67b
+hasIcon and hasImage for LabelAndIcon compatibility
Claus Gittinger <cg@exept.de>
parents:
7991
diff
changeset
|
4378 |
|
1388 | 4379 |
heightOn:aGC |
4380 |
"return the size of the recevier in device units if displayed on aGC" |
|
4381 |
||
6528 | 4382 |
^ (aGC font onDevice:aGC device) heightOf:self |
1388 | 4383 |
|
4384 |
" |
|
8874 | 4385 |
'hello world' heightOn:(View new) |
1388 | 4386 |
" |
4387 |
||
4388 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
4389 |
"Modified: 12.5.1996 / 20:32:05 / cg" |
|
4390 |
! |
|
4391 |
||
11828 | 4392 |
isLowercaseFirst |
4393 |
"return true, if the first character is a lowercase character." |
|
4394 |
||
4395 |
^ self size ~~ 0 and:[ self first isLowercase ] |
|
4396 |
||
4397 |
" |
|
4398 |
'helloWorld' isLowercaseFirst |
|
4399 |
'HelloWorld' isLowercaseFirst |
|
4400 |
" |
|
4401 |
! |
|
4402 |
||
4403 |
isUppercaseFirst |
|
4404 |
"return true, if the first character is an uppercase character." |
|
4405 |
||
4406 |
^ self size ~~ 0 and:[ self first isUppercase ] |
|
4407 |
||
4408 |
" |
|
4409 |
'helloWorld' isUppercaseFirst |
|
4410 |
'HelloWorld' isUppercaseFirst |
|
4411 |
" |
|
4412 |
! |
|
4413 |
||
9190 | 4414 |
knownAsSymbol |
4415 |
"for now, only single character strings are allowed as symbols. |
|
4416 |
This method is redefined in String." |
|
4417 |
||
4418 |
^ false |
|
4419 |
! |
|
4420 |
||
4421 |
leftIndent |
|
4422 |
"if the receiver starts with spaces, return the number of spaces |
|
4423 |
at the left - otherwise, return 0. |
|
9192 | 4424 |
If the receiver consists of spaces only, return the receivers size." |
4425 |
||
4426 |
|index "{Class: SmallInteger }" |
|
4427 |
end "{Class: SmallInteger }"| |
|
4428 |
||
4429 |
index := 1. |
|
4430 |
end := self size. |
|
4431 |
[index <= end] whileTrue:[ |
|
4432 |
(self at:index) isSeparator ifFalse:[^ index - 1]. |
|
4433 |
index := index + 1 |
|
8350 | 4434 |
]. |
9192 | 4435 |
^ end |
4436 |
||
4437 |
" |
|
4438 |
' hello' leftIndent |
|
4439 |
'foo ' leftIndent |
|
9190 | 4440 |
' ' leftIndent |
4441 |
" |
|
4442 |
||
4443 |
"Modified: 20.4.1996 / 19:28:43 / cg" |
|
8350 | 4444 |
! |
4445 |
||
10437 | 4446 |
nameSpaceSelectorParts |
4447 |
"Answer the namespace and baseSelector parts of a namespace selector. |
|
4448 |
Namespace selectors are those generated by sends from a method in a different |
|
4449 |
namespace; they are prefixed by ':'<ns>'::'. |
|
4450 |
You cannot easily change this algorithm here, as it is also known by the VM's lookup function. |
|
4451 |
Experimental" |
|
4452 |
||
4453 |
|nsPart selPart idx| |
|
4454 |
||
4455 |
(self at:1) == $: ifFalse:[^ Array with:'' with:self]. |
|
4456 |
idx := self indexOf:$: startingAt:3. |
|
4457 |
idx == 0 ifTrue:[^ Array with:'' with:self]. |
|
4458 |
||
4459 |
(idx+2 > self size) ifTrue:[^ Array with:'' with:self]. |
|
4460 |
(self at:idx+1) == $: ifFalse:[^ Array with:'' with:self]. |
|
4461 |
nsPart := self copyFrom:2 to:idx-1. |
|
4462 |
selPart := self copyFrom:idx+2. |
|
4463 |
^ Array with:nsPart with:selPart |
|
4464 |
||
4465 |
"test: |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
4466 |
self assert:('+' nameSpaceSelectorParts) = #('' '+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
4467 |
self assert:(':+' nameSpaceSelectorParts) = #('' ':+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
4468 |
self assert:(':Foo:+' nameSpaceSelectorParts) = #('' ':Foo:+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
4469 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
4470 |
self assert:(':Foo::+' nameSpaceSelectorParts) = #('Foo' '+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
4471 |
self assert:(':Foo::bar:baz:' nameSpaceSelectorParts) = #('Foo' 'bar:baz:'). |
10437 | 4472 |
" |
4473 |
||
4474 |
"Created: / 05-03-2007 / 17:16:58 / cg" |
|
4475 |
"Modified: / 06-03-2007 / 11:51:15 / cg" |
|
4476 |
! |
|
4477 |
||
9190 | 4478 |
stringSpecies |
8874 | 4479 |
"return the underlying strings bitsPerCharacter |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
4480 |
(i.e. is it a regular String or a TwoByteString)" |
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
4481 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
4482 |
|string| |
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
4483 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
4484 |
(string := self string) == self ifTrue:[^ self class]. |
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
4485 |
^ string stringSpecies |
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
4486 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
4487 |
" |
8874 | 4488 |
'hello' stringSpecies |
9192 | 4489 |
'hello' asText allBold stringSpecies |
4490 |
" |
|
4491 |
! |
|
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
4492 |
|
6653 | 4493 |
widthFrom:startIndex to:endIndex on:aGC |
4494 |
"return ths size of part of the recevier in device units if displayed on aGC" |
|
4495 |
||
4496 |
^ (aGC font onDevice:aGC device) widthOf:self from:startIndex to:endIndex |
|
4497 |
||
4498 |
" |
|
8874 | 4499 |
'hello world' widthFrom:1 to:5 on:(View new) |
4500 |
'hello' widthOn:(View new) |
|
6653 | 4501 |
" |
9192 | 4502 |
! |
6653 | 4503 |
|
1388 | 4504 |
widthOn:aGC |
4505 |
"return ths size of the recevier in device units if displayed on aGC" |
|
4506 |
||
6528 | 4507 |
^ (aGC font onDevice:aGC device) widthOf:self |
1388 | 4508 |
|
4509 |
" |
|
8874 | 4510 |
'hello world' widthOn:(View new) |
1388 | 4511 |
" |
4512 |
||
4513 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
2554 | 4514 |
"Modified: 17.4.1997 / 12:50:23 / cg" |
608 | 4515 |
! ! |
4516 |
||
4517 |
!CharacterArray methodsFor:'special string converting'! |
|
4518 |
||
9192 | 4519 |
expandPlaceholdersWith:argArrayOrDictionary |
608 | 4520 |
"return a copy of the receiver, where all %i escapes are |
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4521 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
608 | 4522 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
4523 |
in the new string 'hello world; how is this'. |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4524 |
As an extension, the argument may also be a dictionary, providing |
7313 | 4525 |
values for symbolic keys. |
4842 | 4526 |
In this case, %a .. %z and %(...) are also allowed. |
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4527 |
(%1..%9 require a numeric key in the dictionary, however) |
608 | 4528 |
To get a '%' character, use a '%%'-escape. |
7313 | 4529 |
To get an integer-indexed placeHolder followed by another digit, |
4530 |
or an index > 9, you must use %(digit). |
|
608 | 4531 |
See also bindWith:... for VisualAge compatibility." |
4532 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4533 |
|stream| |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4534 |
|
11028
cb1ee3ddd91a
expandPlaceHolders: care fr Text with emphasis
Claus Gittinger <cg@exept.de>
parents:
11018
diff
changeset
|
4535 |
stream := TextStream on:(self species new:self size + 20). |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4536 |
self expandPlaceholdersWith:argArrayOrDictionary on:stream. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4537 |
^ stream contents. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4538 |
|
608 | 4539 |
|
4540 |
" |
|
8874 | 4541 |
'hello %1' expandPlaceholdersWith:#('world') |
4542 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
4543 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
4544 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
|
4545 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) |
|
4546 |
'%%10 gives %10' expandPlaceholdersWith:#(123) |
|
4547 |
'%%(10) gives %(10)' expandPlaceholdersWith:#(123) |
|
8938
860bbcbd3bd8
Fix #expandPlaceHoldersWith:, when a %a is encountered and and an Array
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4548 |
'%test gives %1' expandPlaceholdersWith:#(123) |
11028
cb1ee3ddd91a
expandPlaceHolders: care fr Text with emphasis
Claus Gittinger <cg@exept.de>
parents:
11018
diff
changeset
|
4549 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' allBold } |
cb1ee3ddd91a
expandPlaceHolders: care fr Text with emphasis
Claus Gittinger <cg@exept.de>
parents:
11018
diff
changeset
|
4550 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' } |
608 | 4551 |
" |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4552 |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4553 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4554 |
|dict| |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4555 |
|
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4556 |
dict := Dictionary new. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4557 |
dict at:1 put:'one'. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4558 |
dict at:$a put:'AAAAA'. |
8794
a5df33935142
nindWith supports blocks in the value dictionary
Claus Gittinger <cg@exept.de>
parents:
8710
diff
changeset
|
4559 |
dict at:$b put:[ Time now ]. |
8874 | 4560 |
'hello %1 %a %b' expandPlaceholdersWith:dict |
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4561 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4562 |
|
2737
9f29aecea39d
care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents:
2736
diff
changeset
|
4563 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
9192 | 4564 |
! |
4565 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4566 |
expandPlaceholdersWith:argArrayOrDictionary on:aStream |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4567 |
"write the receiver to aStream, where all %i escapes are |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4568 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4569 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4570 |
in the new string 'hello world; how is this'. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4571 |
As an extension, the argument may also be a dictionary, providing |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4572 |
values for symbolic keys. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4573 |
In this case, %a .. %z and %(...) are also allowed. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4574 |
(%1..%9 require a numeric key in the dictionary, however) |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4575 |
To get a '%' character, use a '%%'-escape. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4576 |
To get an integer-indexed placeHolder followed by another digit, |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4577 |
or an index > 9, you must use %(digit). |
10935 | 4578 |
See also bindWith:... for VisualAge compatibility. |
10939
d0ca31c1d1e9
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10935
diff
changeset
|
4579 |
Use %<cr> to insert a CR and %<tab> to insert a TAB." |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4580 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4581 |
|next v key keyAsSymbol |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4582 |
idx "{ SmallInteger }" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4583 |
idx2 "{ SmallInteger }" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4584 |
start "{ SmallInteger }" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4585 |
stop "{ SmallInteger }"| |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4586 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4587 |
stop := self size. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4588 |
start := 1. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4589 |
[start <= stop] whileTrue:[ |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4590 |
idx := self indexOf:$% startingAt:start. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4591 |
(idx == 0 or:[idx == stop]) ifTrue:[ |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4592 |
aStream nextPutAll:self startingAt:start to:stop. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4593 |
^ self. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4594 |
]. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4595 |
"found a %" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4596 |
aStream nextPutAll:self startingAt:start to:(idx - 1). |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4597 |
next := self at:(idx + 1). |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4598 |
(next == $%) ifTrue:[ |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4599 |
aStream nextPut:$%. |
11292
d331195c0d2d
do not convert u16 to utf8 when expanding a placeholder
Claus Gittinger <cg@exept.de>
parents:
11243
diff
changeset
|
4600 |
] ifFalse:[ |
d331195c0d2d
do not convert u16 to utf8 when expanding a placeholder
Claus Gittinger <cg@exept.de>
parents:
11243
diff
changeset
|
4601 |
next == $< ifTrue:[ |
10939
d0ca31c1d1e9
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10935
diff
changeset
|
4602 |
idx2 := self indexOf:$> startingAt:idx+2. |
d0ca31c1d1e9
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10935
diff
changeset
|
4603 |
key := self copyFrom:idx+2 to:idx2-1. |
d0ca31c1d1e9
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10935
diff
changeset
|
4604 |
idx := idx2 - 1. |
d0ca31c1d1e9
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10935
diff
changeset
|
4605 |
key := key asSymbolIfInterned. |
d0ca31c1d1e9
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10935
diff
changeset
|
4606 |
(#(cr tab nl return lf ff null) includesIdentical:key) ifTrue:[ |
10940
516744ea6f07
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10939
diff
changeset
|
4607 |
aStream nextPut:(Character perform:key). |
10939
d0ca31c1d1e9
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10935
diff
changeset
|
4608 |
]. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4609 |
] ifFalse:[ |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4610 |
(next between:$1 and:$9) ifTrue:[ |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4611 |
v := argArrayOrDictionary at:(next digitValue) ifAbsent:nil |
10935 | 4612 |
] ifFalse:[next == $( ifTrue:[ |
4613 |
idx2 := self indexOf:$) startingAt:idx+2. |
|
4614 |
key := self copyFrom:idx+2 to:idx2-1. |
|
4615 |
idx := idx2 - 1. |
|
4616 |
key:= key asSymbolIfInterned ? key. |
|
4617 |
(keyAsSymbol notNil and:[ argArrayOrDictionary includesKey:keyAsSymbol ]) ifTrue:[ |
|
4618 |
v := argArrayOrDictionary at:keyAsSymbol |
|
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4619 |
] ifFalse:[ |
10935 | 4620 |
key isNumeric ifTrue:[ |
4621 |
key := Integer readFrom:key onError:nil. |
|
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4622 |
]. |
10935 | 4623 |
v := argArrayOrDictionary at:key ifAbsent:nil |
4624 |
]. |
|
4625 |
] ifFalse:[ |
|
4626 |
"so next is a non-numeric single character. |
|
4627 |
This would not work with Arrays, since they have integer indizes" |
|
4628 |
argArrayOrDictionary isSequenceable ifFalse:[ |
|
4629 |
v := argArrayOrDictionary at:next ifAbsent:[ |
|
4630 |
"try symbol instead of character" |
|
4631 |
argArrayOrDictionary at:next asSymbol ifAbsent:[String with:$% with:next]. |
|
4632 |
]. |
|
4633 |
] ifTrue:[ |
|
4634 |
v := String with:$% with:next. "No match, keep original sequence" |
|
4635 |
]. |
|
10940
516744ea6f07
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10939
diff
changeset
|
4636 |
]]. |
10935 | 4637 |
v notNil ifTrue:[ |
4638 |
v isBlock ifTrue:[ |
|
4639 |
v := v value |
|
4640 |
]. |
|
11320 | 4641 |
|
4642 |
v printOn:aStream. |
|
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4643 |
]. |
10940
516744ea6f07
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10939
diff
changeset
|
4644 |
]]. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4645 |
start := idx + 2 |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4646 |
]. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4647 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4648 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4649 |
String streamContents:[:s| |
10935 | 4650 |
'hello %1' expandPlaceholdersWith:#('world') on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4651 |
s cr. |
10935 | 4652 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4653 |
s cr. |
10935 | 4654 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4655 |
s cr. |
10935 | 4656 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4657 |
s cr. |
10935 | 4658 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4659 |
s cr. |
10935 | 4660 |
'%%10 gives %10' expandPlaceholdersWith:#(123) on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4661 |
s cr. |
10939
d0ca31c1d1e9
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10935
diff
changeset
|
4662 |
'%%(10) gives %(10) %<cr>%<tab>next line' expandPlaceholdersWith:#(123) on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4663 |
s cr. |
10935 | 4664 |
'%test gives %1' expandPlaceholdersWith:#(123) on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4665 |
] |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4666 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4667 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4668 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4669 |
|dict| |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4670 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4671 |
dict := Dictionary new. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4672 |
dict at:1 put:'one'. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4673 |
dict at:$a put:'AAAAA'. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4674 |
dict at:$b put:[ Time now ]. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4675 |
String streamContents:[:s| |
10935 | 4676 |
'hello %1 %a %b' expandPlaceholdersWith:dict on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4677 |
]. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4678 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4679 |
! |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
4680 |
|
9230 | 4681 |
firstLine |
4682 |
^ self asCollectionOfSubCollectionsSeparatedBy:Character cr do:[:line | ^ line]. |
|
4683 |
||
4684 |
" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
4685 |
'hello' firstLine |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
4686 |
'1\2\3' withCRs firstLine |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
4687 |
'\1\2\3' withCRs firstLine |
9230 | 4688 |
" |
4689 |
! |
|
4690 |
||
9192 | 4691 |
withCRs |
4692 |
"return a new string consisting of receivers characters |
|
4693 |
with all \-characters replaced by cr-characters." |
|
4694 |
||
4695 |
^ self copyReplaceAll:$\ with:(Character cr) |
|
4696 |
||
4697 |
" |
|
4698 |
'hello\world' withCRs |
|
4699 |
" |
|
4700 |
||
4701 |
"Modified: / 18.7.1998 / 22:53:02 / cg" |
|
4702 |
! |
|
4703 |
||
4704 |
withEscapes |
|
608 | 4705 |
"return a new string consisting of receivers characters |
4706 |
with all \X-character escapes replaced by corresponding-characters. |
|
4707 |
(similar to the way C-language Strings are converted). |
|
4708 |
The following escapes are supported: |
|
9192 | 4709 |
\r return character |
4710 |
\n newline character |
|
4711 |
\b backspace character |
|
4712 |
\f formfeed character |
|
4713 |
\t tab character |
|
4714 |
\e escape character |
|
4715 |
\\ the \ character itself |
|
4716 |
\nnn three digit octal number defining the characters ascii value |
|
4717 |
\other other |
|
608 | 4718 |
|
4719 |
Notice, that \' is NOT a valid escape, since the general syntax of |
|
4720 |
string constants is not affected by this method. |
|
4721 |
||
4722 |
Although easily implementable, this is NOT done automatically |
|
4723 |
by the compiler (due to a lack of a language standard for this). |
|
4724 |
However, the compiler may detect sends ot #withEscapes to string literals |
|
4725 |
and place a modified string constant into the binary/byte-code. |
|
4726 |
Therefore, no runtime penalty will be payed for using these escapes. |
|
4727 |
(not in pre 2.11 versions) |
|
4728 |
" |
|
4729 |
||
4730 |
|sz "{ SmallInteger }" |
|
4731 |
newSize "{ SmallInteger }" |
|
4732 |
srcIdx "{ SmallInteger }" |
|
4733 |
dstIdx "{ SmallInteger }" |
|
4734 |
val "{ SmallInteger }" |
|
8874 | 4735 |
newString next hasEmphasis e| |
359 | 4736 |
|
4737 |
" |
|
608 | 4738 |
first, count the number of escapes, to allow preallocation |
4739 |
of the new string ... |
|
4740 |
(it is faster to scan the string twice than to reallocate it multiple |
|
4741 |
times in a WriteStream) |
|
4742 |
" |
|
4743 |
sz := newSize := self size. |
|
4744 |
srcIdx := 1. |
|
4745 |
[(srcIdx := self indexOf:$\ startingAt:srcIdx) ~~ 0] whileTrue:[ |
|
9192 | 4746 |
srcIdx == sz ifFalse:[ |
4747 |
newSize := newSize - 1. |
|
4748 |
srcIdx := srcIdx + 1. |
|
4749 |
next := self at:srcIdx. |
|
4750 |
next == $0 ifTrue:[ |
|
4751 |
[srcIdx < sz and:[next isDigit]] whileTrue:[ |
|
4752 |
newSize := newSize - 1. srcIdx := srcIdx + 1. next := self at:srcIdx. |
|
4753 |
] |
|
4754 |
]. |
|
4755 |
]. |
|
4756 |
srcIdx := srcIdx + 1. |
|
608 | 4757 |
]. |
4758 |
||
4759 |
newSize == sz ifTrue:[ |
|
9192 | 4760 |
^ self |
608 | 4761 |
]. |
4762 |
||
4763 |
newString := self species new:newSize. |
|
1381 | 4764 |
|
4765 |
hasEmphasis := self hasChangeOfEmphasis. |
|
4766 |
||
608 | 4767 |
" |
4768 |
copy over, replace escapes |
|
4769 |
" |
|
4770 |
srcIdx := dstIdx := 1. |
|
4771 |
[srcIdx <= sz] whileTrue:[ |
|
9192 | 4772 |
next := self at:srcIdx. |
4773 |
hasEmphasis ifTrue:[ |
|
4774 |
e := self emphasisAt:srcIdx |
|
4775 |
]. |
|
4776 |
srcIdx := srcIdx + 1. |
|
4777 |
next == $\ ifTrue:[ |
|
4778 |
srcIdx <= sz ifTrue:[ |
|
4779 |
next := self at:srcIdx. |
|
4780 |
srcIdx := srcIdx + 1. |
|
4781 |
next == $r ifTrue:[ |
|
4782 |
next := Character return |
|
4783 |
] ifFalse:[ |
|
4784 |
next == $n ifTrue:[ |
|
4785 |
next := Character nl |
|
4786 |
] ifFalse:[ |
|
4787 |
next == $b ifTrue:[ |
|
4788 |
next := Character backspace |
|
4789 |
] ifFalse:[ |
|
4790 |
next == $f ifTrue:[ |
|
4791 |
next := Character newPage |
|
4792 |
] ifFalse:[ |
|
4793 |
next == $t ifTrue:[ |
|
4794 |
next := Character tab |
|
4795 |
] ifFalse:[ |
|
4796 |
next == $e ifTrue:[ |
|
4797 |
next := Character esc |
|
4798 |
] ifFalse:[ |
|
4799 |
next == $0 ifTrue:[ |
|
4800 |
val := 0. |
|
4801 |
[next notNil and:[next isDigit]] whileTrue:[ |
|
4802 |
val := val * 8 + next digitValue. |
|
4803 |
srcIdx <= sz ifTrue:[ |
|
4804 |
next := self at:srcIdx. |
|
4805 |
srcIdx := srcIdx + 1. |
|
4806 |
] ifFalse:[ |
|
4807 |
next := nil |
|
4808 |
] |
|
4809 |
]. |
|
4810 |
next := Character value:val. |
|
4811 |
] |
|
4812 |
] |
|
4813 |
] |
|
4814 |
] |
|
4815 |
] |
|
4816 |
] |
|
4817 |
]. |
|
4818 |
]. |
|
4819 |
]. |
|
4820 |
newString at:dstIdx put:next. |
|
4821 |
hasEmphasis ifTrue:[ |
|
4822 |
newString emphasisAt:dstIdx put:e |
|
4823 |
]. |
|
4824 |
dstIdx := dstIdx + 1. |
|
608 | 4825 |
]. |
4826 |
^ newString |
|
4827 |
||
4828 |
" |
|
8874 | 4829 |
'hello world' withEscapes |
4830 |
'hello\world' withEscapes |
|
4831 |
'hello\world\' withEscapes |
|
4832 |
'hello world\' withEscapes |
|
4833 |
'hello\tworld' withEscapes |
|
4834 |
'hello\nworld\na\n\tnice\n\t\tstring' withEscapes |
|
4835 |
'hello\tworld\n' withEscapes |
|
4836 |
'hello\010world' withEscapes |
|
4837 |
'hello\r\nworld' withEscapes |
|
608 | 4838 |
" |
1008 | 4839 |
|
1381 | 4840 |
"Modified: 12.5.1996 / 12:53:34 / cg" |
9192 | 4841 |
! |
4842 |
||
4843 |
withMatchEscapes |
|
4117 | 4844 |
"return a copy of the receiver with all match characters escaped |
4845 |
by $\ characters (to be usable as a match string). |
|
4846 |
Return the receiver, if there are none." |
|
4847 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
4848 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
4849 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
4850 |
escape := self class matchEscapeCharacter. |
4117 | 4851 |
|
4852 |
in := self readStream. |
|
7986 | 4853 |
out := WriteStream on:(self species new:self size). |
4117 | 4854 |
[in atEnd] whileFalse:[ |
9192 | 4855 |
c := in next. |
4856 |
(c == escape or:['*[#' includes:c]) ifTrue:[ |
|
4857 |
out nextPut:$\. |
|
4858 |
]. |
|
4859 |
out nextPut:c. |
|
4117 | 4860 |
]. |
4861 |
^ out contents. |
|
4862 |
||
4863 |
" |
|
8874 | 4864 |
'*foo' withMatchEscapes |
4865 |
'\*foo' withMatchEscapes |
|
4866 |
'*foo' withMatchEscapes |
|
4867 |
'\\*foo' withMatchEscapes |
|
4868 |
'foo*' withMatchEscapes |
|
4869 |
'foo\*' withMatchEscapes |
|
4870 |
'foo\' withMatchEscapes |
|
4871 |
'f*o*o' withMatchEscapes |
|
4117 | 4872 |
" |
4873 |
||
4874 |
"Modified: 2.4.1997 / 18:13:04 / cg" |
|
9192 | 4875 |
! |
4876 |
||
4877 |
withTabs |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4878 |
"return a string consisting of the receivers characters |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4879 |
where leading spaces are replaced by tabulator characters (assuming 8-col tabs). |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4880 |
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:
678
diff
changeset
|
4881 |
otherwise a new string is returned. |
8874 | 4882 |
Limitation: only the very first spaces are replaced |
9192 | 4883 |
(i.e. if the receiver contains newLine characters, |
4884 |
no tabs are inserted after those lineBreaks)" |
|
8874 | 4885 |
|
4886 |
|idx "{ SmallInteger }" |
|
4887 |
nTabs "{ SmallInteger }" |
|
608 | 4888 |
newString| |
4889 |
||
4890 |
idx := self findFirst:[:c | (c ~~ Character space)]. |
|
4891 |
nTabs := (idx-1) // 8. |
|
5815
4acdd87a77d4
// can return negative numbers.
Stefan Vogel <sv@exept.de>
parents:
5795
diff
changeset
|
4892 |
nTabs <= 0 ifTrue:[^ self]. |
608 | 4893 |
|
4894 |
"any tabs" |
|
4895 |
newString := self class new:(self size - (nTabs * 7)). |
|
4896 |
newString atAll:(1 to:nTabs) put:(Character tab). |
|
4897 |
newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1). |
|
4898 |
^ newString |
|
4899 |
||
4900 |
" |
|
8874 | 4901 |
'12345678901234567890' withTabs |
4902 |
' 8901234567890' withTabs |
|
4903 |
' 901234567890' withTabs |
|
608 | 4904 |
' 67890' withTabs |
4905 |
' 7890' withTabs |
|
4906 |
' 890' withTabs |
|
4907 |
" |
|
9192 | 4908 |
! |
4909 |
||
4910 |
withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4911 |
"return a string consisting of the receivers characters, |
8874 | 4912 |
where all tabulator characters are expanded into spaces (assuming 8-col tabs). |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4913 |
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:
678
diff
changeset
|
4914 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4915 |
This does handle multiline strings." |
608 | 4916 |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4917 |
^ self withTabsExpanded:8 |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4918 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4919 |
" |
8874 | 4920 |
('1' , Character tab asString , 'x') withTabsExpanded |
4921 |
('12345' , Character tab asString , 'x') withTabsExpanded |
|
4922 |
('123456' , Character tab asString , 'x') withTabsExpanded |
|
4923 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
|
4924 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
|
4925 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4926 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4927 |
(String with:Character tab |
9192 | 4928 |
with:Character tab |
4929 |
with:$1) withTabsExpanded |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4930 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4931 |
(String with:Character tab |
9192 | 4932 |
with:$1 |
4933 |
with:Character tab |
|
4934 |
with:$2) withTabsExpanded |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4935 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4936 |
(String with:Character tab |
9192 | 4937 |
with:$1 |
4938 |
with:Character cr |
|
4939 |
with:Character tab |
|
4940 |
with:$2) withTabsExpanded |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4941 |
" |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4942 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4943 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
9192 | 4944 |
! |
4945 |
||
4946 |
withTabsExpanded:numSpaces |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4947 |
"return a string consisting of the receivers characters, |
8874 | 4948 |
where all tabulator characters are expanded into spaces (assuming numSpaces-col tabs). |
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4949 |
Notice: if the receiver does not contain any tabs, it is returned unchanged; |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4950 |
otherwise a new string is returned. |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4951 |
This does handle multiline strings." |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
4952 |
|
8874 | 4953 |
|col "{ SmallInteger }" |
1381 | 4954 |
str ch |
4955 |
dstIdx "{ SmallInteger }" |
|
4956 |
newSz "{ SmallInteger }" |
|
4957 |
sz "{ SmallInteger }" |
|
4958 |
hasEmphasis e| |
|
608 | 4959 |
|
4960 |
(self includes:(Character tab)) ifFalse:[^ self]. |
|
1381 | 4961 |
|
4962 |
sz := self size. |
|
4963 |
||
4964 |
"/ count the new size first, instead of |
|
4965 |
"/ multiple resizing (better for large strings) |
|
4966 |
||
4967 |
col := 1. newSz := 0. |
|
4968 |
1 to:sz do:[:srcIdx | |
|
9192 | 4969 |
ch := self at:srcIdx. |
4970 |
ch == Character tab ifFalse:[ |
|
4971 |
col := col + 1. |
|
4972 |
newSz := newSz + 1. |
|
4973 |
ch == Character cr ifTrue:[ |
|
4974 |
col := 1 |
|
4975 |
]. |
|
4976 |
] ifTrue:[ |
|
4977 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
|
4978 |
newSz := newSz + 1. |
|
4979 |
col := col + 1 |
|
4980 |
]. |
|
4981 |
] |
|
608 | 4982 |
]. |
1381 | 4983 |
|
4984 |
str := self species new:newSz. |
|
4985 |
||
4986 |
hasEmphasis := self hasChangeOfEmphasis. |
|
4987 |
||
4988 |
col := 1. dstIdx := 1. |
|
4989 |
1 to:sz do:[:srcIdx | |
|
9192 | 4990 |
ch := self at:srcIdx. |
4991 |
||
4992 |
ch == Character tab ifFalse:[ |
|
4993 |
col := col + 1. |
|
4994 |
ch == Character cr ifTrue:[ |
|
4995 |
col := 1 |
|
4996 |
]. |
|
4997 |
hasEmphasis ifTrue:[ |
|
4998 |
e := self emphasisAt:srcIdx. |
|
4999 |
str emphasisAt:dstIdx put:e |
|
5000 |
]. |
|
5001 |
str at:dstIdx put:ch. |
|
5002 |
dstIdx := dstIdx + 1 |
|
5003 |
] ifTrue:[ |
|
5004 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
|
5005 |
str at:dstIdx put:Character space. |
|
5006 |
dstIdx := dstIdx + 1. |
|
5007 |
col := col + 1 |
|
5008 |
]. |
|
5009 |
] |
|
1381 | 5010 |
]. |
5011 |
^ str |
|
608 | 5012 |
|
5013 |
" |
|
8874 | 5014 |
('1' , Character tab asString , 'x') withTabsExpanded |
5015 |
('1' , Character tab asString , 'x') withTabsExpanded:4 |
|
5016 |
('12345' , Character tab asString , 'x') withTabsExpanded |
|
5017 |
('123456' , Character tab asString , 'x') withTabsExpanded |
|
5018 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
|
5019 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
|
5020 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5021 |
|
608 | 5022 |
(String with:Character tab |
9192 | 5023 |
with:Character tab |
5024 |
with:$1) withTabsExpanded |
|
608 | 5025 |
|
5026 |
(String with:Character tab |
|
9192 | 5027 |
with:$1 |
5028 |
with:Character tab |
|
5029 |
with:$2) withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5030 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5031 |
(String with:Character tab |
9192 | 5032 |
with:$1 |
5033 |
with:Character cr |
|
5034 |
with:Character tab |
|
5035 |
with:$2) withTabsExpanded |
|
608 | 5036 |
" |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5037 |
|
1381 | 5038 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
9192 | 5039 |
! |
5040 |
||
5041 |
withoutCRs |
|
5042 |
"return a new collection consisting of receivers elements |
|
5043 |
with all cr-characters replaced by \-characters. |
|
5044 |
This is the reverse operation of withCRs." |
|
5045 |
||
5046 |
^ self copyReplaceAll:(Character cr) with:$\ |
|
5047 |
" |
|
5048 |
'hello |
|
5049 |
world' withoutCRs |
|
5050 |
" |
|
5051 |
||
5052 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
5053 |
! |
|
5054 |
||
5055 |
withoutLeadingSeparators |
|
608 | 5056 |
"return a copy of myself without leading separators. |
5057 |
Notice: this does remove tabs, newline or any other whitespace. |
|
5058 |
Returns an empty string, if the receiver consist only of whitespace." |
|
5059 |
||
5060 |
|index| |
|
5061 |
||
5062 |
index := self indexOfNonSeparatorStartingAt:1. |
|
5063 |
index ~~ 0 ifTrue:[ |
|
9192 | 5064 |
index == 1 ifTrue:[ |
5065 |
^ self |
|
5066 |
]. |
|
5067 |
^ self copyFrom:index |
|
608 | 5068 |
]. |
5069 |
^ '' |
|
5070 |
||
5071 |
" |
|
8874 | 5072 |
' foo ' withoutLeadingSeparators |
5073 |
'foo ' withoutLeadingSeparators |
|
5074 |
' foo' withoutLeadingSeparators |
|
5075 |
' ' withoutLeadingSeparators |
|
5076 |
'foo' withoutLeadingSeparators |
|
5077 |
(' ' , Character tab asString , ' foo ') withoutLeadingSeparators inspect |
|
608 | 5078 |
" |
9192 | 5079 |
! |
5080 |
||
5081 |
withoutMatchEscapes |
|
4117 | 5082 |
"return a copy of the receiver with all $\ removed or |
5083 |
the receiver, if there are none." |
|
5084 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5085 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5086 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5087 |
escape := self class matchEscapeCharacter. |
4117 | 5088 |
|
5089 |
in := self readStream. |
|
8222
f2c454a9a038
replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents:
8124
diff
changeset
|
5090 |
out := self species writeStream. |
4117 | 5091 |
[in atEnd] whileFalse:[ |
9192 | 5092 |
c := in next. |
5093 |
c == escape ifTrue:[ |
|
5094 |
in atEnd ifFalse:[ |
|
5095 |
c := in next. |
|
5096 |
] |
|
5097 |
]. |
|
5098 |
out nextPut:c. |
|
4117 | 5099 |
]. |
5100 |
^ out contents. |
|
5101 |
||
5102 |
" |
|
8874 | 5103 |
'*foo' withoutMatchEscapes |
5104 |
'\*foo' withoutMatchEscapes |
|
5105 |
'*foo' withoutMatchEscapes |
|
5106 |
'\\*foo' withoutMatchEscapes |
|
5107 |
'foo*' withoutMatchEscapes |
|
5108 |
'foo\*' withoutMatchEscapes |
|
5109 |
'foo\' withoutMatchEscapes |
|
5110 |
'f\*o\*o' withoutMatchEscapes |
|
4117 | 5111 |
" |
5112 |
||
5113 |
"Modified: 30.6.1997 / 13:40:23 / cg" |
|
9192 | 5114 |
! |
5115 |
||
5116 |
withoutPrefix:aString |
|
5117 |
"if the receiver startsWith aPrefix, return a copy without it. |
|
5118 |
Otherwise return the receiver" |
|
5119 |
||
5120 |
(self startsWith:aString) ifTrue:[ |
|
5121 |
^ self copyFrom:aString size + 1 |
|
5122 |
]. |
|
5123 |
^ self |
|
5124 |
||
5125 |
" |
|
5126 |
'helloworld' withoutPrefix:'hello' |
|
5127 |
'helloworld' withoutPrefix:'foo' |
|
5128 |
" |
|
5129 |
! |
|
5130 |
||
10671 | 5131 |
withoutQuotes |
5132 |
"remove quotes ("" and ') from the front and the end of myself" |
|
5133 |
||
5134 |
|result quote| |
|
5135 |
||
5136 |
result := self. |
|
5137 |
((result startsWith:$") or:[(result startsWith:$')]) ifTrue:[ |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5138 |
quote := result at:1. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5139 |
result := result copyFrom:2. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5140 |
(result endsWith:quote) ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5141 |
result := result copyWithoutLast:1 |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5142 |
]. |
10671 | 5143 |
]. |
5144 |
^ result |
|
5145 |
||
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5146 |
"/ '"hello"' withoutQuotes |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5147 |
"/ '''hello''' withoutQuotes |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5148 |
"/ 'hello' withoutQuotes |
10671 | 5149 |
! |
5150 |
||
9192 | 5151 |
withoutSeparators |
608 | 5152 |
"return a copy of myself without leading and trailing whitespace. |
4156 | 5153 |
(but whiteSpace in-between is preserved) |
608 | 5154 |
Whitespace is space, tab, newline, formfeed. |
5155 |
Use withoutSpaces, if you want to remove spaces only." |
|
5156 |
||
5157 |
|startIndex "{ Class: SmallInteger }" |
|
8874 | 5158 |
endIndex "{ Class: SmallInteger }" |
608 | 5159 |
sz| |
5160 |
||
5161 |
sz := self size. |
|
5162 |
startIndex := 1. |
|
5163 |
endIndex := sz. |
|
5164 |
||
5165 |
[(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[ |
|
9192 | 5166 |
startIndex := startIndex + 1 |
608 | 5167 |
]. |
5168 |
[(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[ |
|
9192 | 5169 |
endIndex := endIndex - 1 |
608 | 5170 |
]. |
5171 |
startIndex > endIndex ifTrue:[ |
|
9192 | 5172 |
^ '' |
608 | 5173 |
]. |
5174 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
|
9192 | 5175 |
^ self |
608 | 5176 |
]. |
5177 |
^ self copyFrom:startIndex to:endIndex |
|
5178 |
||
5179 |
" |
|
8874 | 5180 |
' foo ' withoutSeparators |
5181 |
' foo' withoutSeparators |
|
5182 |
'foo ' withoutSeparators |
|
5183 |
' ' withoutSeparators |
|
5184 |
(' foo' , Character tab asString , ' ') withoutSeparators inspect |
|
608 | 5185 |
" |
9192 | 5186 |
! |
5187 |
||
5188 |
withoutSpaces |
|
608 | 5189 |
"return a copy of myself without leading and trailing spaces. |
4156 | 5190 |
(but spaces in-between are preserved) |
608 | 5191 |
Notice: this does NOT remove tabs, newline or any other whitespace. |
5192 |
Use withoutSeparators for this." |
|
5193 |
||
5194 |
|startIndex "{ Class: SmallInteger }" |
|
8874 | 5195 |
endIndex "{ Class: SmallInteger }" |
608 | 5196 |
sz| |
5197 |
||
5198 |
sz := self size. |
|
5199 |
startIndex := 1. |
|
5200 |
endIndex := sz. |
|
5201 |
||
5202 |
[(startIndex < endIndex) and:[(self at:startIndex) == Character space]] whileTrue:[ |
|
9192 | 5203 |
startIndex := startIndex + 1 |
608 | 5204 |
]. |
5205 |
[(endIndex > 1) and:[(self at:endIndex) == Character space]] whileTrue:[ |
|
9192 | 5206 |
endIndex := endIndex - 1 |
608 | 5207 |
]. |
5208 |
startIndex > endIndex ifTrue:[ |
|
9192 | 5209 |
^ '' |
608 | 5210 |
]. |
5211 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
|
9192 | 5212 |
^ self |
608 | 5213 |
]. |
5214 |
^ self copyFrom:startIndex to:endIndex |
|
5215 |
||
5216 |
" |
|
8874 | 5217 |
' foo ' withoutSpaces |
5218 |
'foo ' withoutSpaces |
|
5219 |
' foo' withoutSpaces |
|
5220 |
' ' withoutSpaces |
|
5221 |
'a b' withoutSpaces |
|
5222 |
(' foo' , Character tab asString , ' ') withoutSpaces inspect |
|
608 | 5223 |
" |
9192 | 5224 |
! |
5225 |
||
5226 |
withoutTrailingSeparators |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5227 |
"return a copy of myself without trailing separators. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5228 |
Notice: this does remove tabs, newline or any other whitespace. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5229 |
Returns an empty string, if the receiver consist only of whitespace." |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5230 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5231 |
|index| |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5232 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5233 |
index := self size. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5234 |
[index ~~ 0] whileTrue:[ |
9192 | 5235 |
(self at:index) isSeparator ifFalse:[ |
5236 |
^ self copyTo:index |
|
5237 |
]. |
|
5238 |
index := index - 1 |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5239 |
]. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5240 |
^ '' |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5241 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5242 |
" |
8874 | 5243 |
' foo ' withoutTrailingSeparators |
5244 |
'foo ' withoutTrailingSeparators |
|
5245 |
' foo' withoutTrailingSeparators |
|
5246 |
' ' withoutTrailingSeparators |
|
5247 |
'foo' withoutTrailingSeparators |
|
5248 |
(' ' , Character tab asString , ' foo ') withoutTrailingSeparators inspect |
|
5249 |
(' foo' , Character tab asString) withoutTrailingSeparators inspect |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5250 |
" |
9192 | 5251 |
! ! |
5252 |
||
5253 |
!CharacterArray methodsFor:'substring searching'! |
|
5254 |
||
5255 |
findString:subString |
|
5256 |
"find a substring. if found, return the index; |
|
5257 |
if not found, return 0." |
|
5258 |
||
5259 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:true |
|
5260 |
||
5261 |
" |
|
5262 |
'hello world' findString:'llo' |
|
5263 |
'hello world' findString:'ole' |
|
5264 |
" |
|
5265 |
! |
|
608 | 5266 |
|
5267 |
findString:subString ifAbsent:exceptionBlock |
|
5268 |
"find a substring. If found, return the index; |
|
5269 |
if not found, return the result of evaluating exceptionBlock." |
|
5270 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5271 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock caseSensitive:true |
608 | 5272 |
! |
5273 |
||
11018 | 5274 |
findString:subString ignoreCase:ignoreCase |
5275 |
"find a substring. if found, return the index; |
|
5276 |
if not found, return 0." |
|
5277 |
||
5278 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:ignoreCase not |
|
5279 |
||
5280 |
" |
|
5281 |
'hello world' findString:'LLo' ignoreCase:false |
|
5282 |
'hello world' findString:'LLo' ignoreCase:true |
|
5283 |
" |
|
5284 |
! |
|
5285 |
||
608 | 5286 |
findString:subString startingAt:index |
5287 |
"find a substring, starting at index. if found, return the index; |
|
5288 |
if not found, return 0." |
|
5289 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5290 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:0 caseSensitive:true |
608 | 5291 |
|
5292 |
" |
|
9192 | 5293 |
'hello yello' findString:'llo' startingAt:1 |
5294 |
'hello yello' findString:'llo' startingAt:5 |
|
5295 |
'hello yello' findString:'llo' startingAt:15 |
|
5296 |
" |
|
5297 |
! |
|
608 | 5298 |
|
5299 |
findString:subString startingAt:index ifAbsent:exceptionBlock |
|
5300 |
"find a substring, starting at index. if found, return the index; |
|
5301 |
if not found, return the result of evaluating exceptionBlock." |
|
5302 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5303 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:true |
608 | 5304 |
! |
5305 |
||
10929 | 5306 |
findString:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
5307 |
"find a substring, starting at index. if found, return the index; |
|
5308 |
if not found, return the result of evaluating exceptionBlock." |
|
5309 |
||
5310 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
|
5311 |
! |
|
5312 |
||
608 | 5313 |
includesString:aString |
5314 |
"return true, if a substring is contained in the receiver" |
|
5315 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5316 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0 caseSensitive:true) ~~ 0 |
608 | 5317 |
|
5318 |
" |
|
11348
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5319 |
'hello world' includesString:'hel' |
8874 | 5320 |
'hello world' includesString:'rld' |
9192 | 5321 |
'hello world' includesString:'llo' |
5322 |
'hello world' includesString:'LLO' |
|
11823
614c2195da0f
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11788
diff
changeset
|
5323 |
'hello world' includesString:'' |
9192 | 5324 |
" |
5325 |
! |
|
9191 | 5326 |
|
5327 |
includesString:aString caseSensitive:caseSensitive |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5328 |
"return true, if a substring is contained in the receiver" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5329 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5330 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0 caseSensitive:caseSensitive) ~~ 0 |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5331 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5332 |
" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5333 |
'hello world' includesString:'hel' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5334 |
'hello world' includesString:'HEL' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5335 |
'hello world' includesString:'HEL' caseSensitive:false |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5336 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5337 |
'hello world' includesString:'wor' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5338 |
'hello world' includesString:'WOR' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5339 |
'hello world' includesString:'WOR' caseSensitive:false |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5340 |
" |
9192 | 5341 |
! |
5342 |
||
5343 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
|
5344 |
"find a substring, starting at index. if found, return the index; |
|
5345 |
if not found, return the result of evaluating exceptionBlock. |
|
5346 |
This is a q&d hack - not very efficient" |
|
5347 |
||
5348 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:true. |
|
5349 |
! |
|
5350 |
||
5351 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5352 |
"find a substring, starting at index. if found, return the index; |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5353 |
if not found, return the result of evaluating exceptionBlock. |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5354 |
This is a q&d hack - not very efficient" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5355 |
|
608 | 5356 |
|firstChar found |
5357 |
startIndex "{ Class: SmallInteger }" |
|
5358 |
subSize "{ Class: SmallInteger }" |
|
5359 |
mySize "{ Class: SmallInteger }" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5360 |
runIdx "{ Class: SmallInteger }" |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5361 |
tester| |
608 | 5362 |
|
5363 |
subSize := subString size. |
|
11823
614c2195da0f
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11788
diff
changeset
|
5364 |
subSize == 0 ifTrue:[ |
11348
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5365 |
subString isString ifFalse:[ |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5366 |
self error:'non string argument' mayProceed:true. |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5367 |
]. |
11823
614c2195da0f
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11788
diff
changeset
|
5368 |
"empty string does not match" |
614c2195da0f
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11788
diff
changeset
|
5369 |
^ 0. |
614c2195da0f
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11788
diff
changeset
|
5370 |
"empty string matches" |
11348
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5371 |
^ index |
6122
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
5372 |
]. |
11823
614c2195da0f
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11788
diff
changeset
|
5373 |
tester := caseSensitive |
614c2195da0f
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11788
diff
changeset
|
5374 |
ifTrue:[ [:c1 :c2 | c1 = c2 ] ] |
614c2195da0f
includesString: emptyString should return false
Claus Gittinger <cg@exept.de>
parents:
11788
diff
changeset
|
5375 |
ifFalse:[ [:c1 :c2 | c1 sameAs: c2 ] ]. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5376 |
|
608 | 5377 |
mySize := self size. |
5378 |
firstChar := subString at:1. |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5379 |
caseSensitive ifTrue:[ |
11348
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5380 |
startIndex := self indexOf:firstChar startingAt:index. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5381 |
] ifFalse:[ |
11348
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5382 |
startIndex := self findFirst:[:c | c sameAs:firstChar] startingAt:index. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
5383 |
]. |
608 | 5384 |
[startIndex == 0] whileFalse:[ |
11348
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5385 |
runIdx := startIndex. |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5386 |
found := true. |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5387 |
1 to:subSize do:[:i | |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5388 |
runIdx > mySize ifTrue:[ |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5389 |
found := false |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5390 |
] ifFalse:[ |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5391 |
(tester value:(subString at:i) value:(self at:runIdx)) ifFalse:[ |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5392 |
found := false |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5393 |
] |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5394 |
]. |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5395 |
runIdx := runIdx + 1 |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5396 |
]. |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5397 |
found ifTrue:[ |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5398 |
^ startIndex |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5399 |
]. |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5400 |
caseSensitive ifTrue:[ |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5401 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1) |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5402 |
] ifFalse:[ |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5403 |
startIndex := self findFirst:[:c | c sameAs:firstChar] startingAt:(startIndex + 1). |
366457915f90
care for wide-character strings in copyReplaceStringWithString
Claus Gittinger <cg@exept.de>
parents:
11345
diff
changeset
|
5404 |
]. |
608 | 5405 |
]. |
5406 |
^ exceptionBlock value |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5407 |
|
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5408 |
"Modified: 23.2.1996 / 15:35:15 / cg" |
9192 | 5409 |
! |
5410 |
||
5411 |
restAfter:keyword withoutSeparators:strip |
|
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5412 |
"compare the left of the receiver with keyword, |
8874 | 5413 |
if it matches return the right. |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5414 |
Finally, if strip is true, remove whiteSpace. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5415 |
This method is used to match and extract lines of the form: |
9192 | 5416 |
something: rest |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
5417 |
where we are interested in rest, but only if the receiver string |
8874 | 5418 |
begins with something. |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5419 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5420 |
You may wonder why such a specialized method exists here |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5421 |
- this is so common when processing mailboxes, |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5422 |
rcs files, nntp/pop3 responses, that is was considered worth |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5423 |
a special method here to avoid having the code below a hundred |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5424 |
times in variuos places." |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5425 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5426 |
|rest| |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5427 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5428 |
(self startsWith:keyword) ifTrue:[ |
9192 | 5429 |
rest := self copyFrom:(keyword size + 1). |
5430 |
strip ifTrue:[ |
|
5431 |
rest := rest withoutSeparators |
|
5432 |
]. |
|
5433 |
^ rest |
|
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5434 |
]. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5435 |
^ nil |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5436 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5437 |
" |
8874 | 5438 |
'foo: hello world' restAfter:'foo:' withoutSeparators:true |
5439 |
'funny: something' restAfter:'foo:' withoutSeparators:true |
|
5440 |
||
5441 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:true |
|
5442 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:false |
|
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5443 |
" |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5444 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5445 |
"Created: 25.11.1995 / 11:04:18 / cg" |
9192 | 5446 |
! ! |
5447 |
||
5448 |
!CharacterArray methodsFor:'testing'! |
|
5449 |
||
5450 |
isAlphaNumeric |
|
5451 |
"return true, if the receiver is some alphanumeric word; |
|
5452 |
i.e. consists of a letter followed by letters or digits." |
|
5453 |
||
5454 |
self size == 0 ifTrue:[ |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5455 |
"mhmh what is this ?" |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5456 |
^ false |
9192 | 5457 |
]. |
5458 |
(self at:1) isLetter ifFalse:[^ false]. |
|
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
5459 |
^ self conform:[:char | char isLetterOrDigit]. |
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
5460 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
5461 |
" |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5462 |
'helloWorld' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5463 |
'foo1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5464 |
'f1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5465 |
'1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5466 |
'+' isAlphaNumeric |
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
5467 |
" |
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
5468 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
5469 |
"Modified: / 13-10-2006 / 12:53:49 / cg" |
9192 | 5470 |
! |
9190 | 5471 |
|
5472 |
isBinarySelector |
|
10903 | 5473 |
"treating the receiver as a message selector, return true if its a binary selector. |
5474 |
Notice, that st/x does not have a size <= 2 limit for unaries" |
|
9190 | 5475 |
|
5476 |
|binopChars| |
|
5477 |
||
5478 |
(self size > 3) ifTrue:[^ false]. |
|
5479 |
||
5480 |
binopChars := Scanner binarySelectorCharacters. |
|
5481 |
^ (self conform:[:char | (binopChars includes:char)]) |
|
5482 |
||
5483 |
" |
|
5484 |
'foo:bar:' isBinarySelector |
|
5485 |
#foo:bar: isBinarySelector |
|
5486 |
'hello' isBinarySelector |
|
5487 |
'+' isBinarySelector |
|
5488 |
'|' isBinarySelector |
|
8874 | 5489 |
'?' isBinarySelector |
5490 |
':' isBinarySelector |
|
5491 |
'a:' isBinarySelector |
|
5492 |
'->' isBinarySelector |
|
5493 |
'<->' isBinarySelector |
|
5494 |
'::' isBinarySelector |
|
7482 | 5495 |
" |
5496 |
||
5497 |
"Modified: 4.1.1997 / 14:16:14 / cg" |
|
9192 | 5498 |
! |
5499 |
||
5500 |
isBlank |
|
5501 |
"return true, if the receiver contains spaces only" |
|
5502 |
||
9230 | 5503 |
^ (self contains:[:char | char ~~ Character space]) not |
5504 |
||
5505 |
" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5506 |
'' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5507 |
' a ' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5508 |
' ' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5509 |
' ' asUnicode16String isBlank |
9230 | 5510 |
" |
9192 | 5511 |
! |
5512 |
||
10903 | 5513 |
isKeywordSelector |
5514 |
"return true, iff there are only alphanumeric or underline characters separated by colons. |
|
5515 |
Must end with a colon." |
|
5516 |
||
5517 |
|state| |
|
5518 |
||
5519 |
state := #initial. |
|
5520 |
self do:[:char | |
|
5521 |
(state == #initial or:[ state == #gotColon]) ifTrue:[ |
|
5522 |
(char isLetter or:[ char == $_ ]) ifFalse:[^ false]. |
|
5523 |
state := #gotCharacter. |
|
5524 |
] ifFalse:[ |
|
5525 |
char == $: ifTrue:[ |
|
5526 |
state := #gotColon. |
|
5527 |
] ifFalse:[ |
|
5528 |
(char isLetterOrDigit or:[char == $_]) ifFalse:[^ false]. |
|
5529 |
]. |
|
5530 |
]. |
|
5531 |
]. |
|
5532 |
^ state == #gotColon. |
|
5533 |
||
5534 |
" |
|
5535 |
self assert:(':' isKeywordSelector not). |
|
5536 |
self assert:(':a' isKeywordSelector not). |
|
5537 |
self assert:('1:' isKeywordSelector not). |
|
5538 |
self assert:('a:' isKeywordSelector). |
|
5539 |
self assert:('_:' isKeywordSelector). |
|
5540 |
self assert:('_a:' isKeywordSelector). |
|
5541 |
self assert:('_1:' isKeywordSelector). |
|
5542 |
self assert:('_1::' isKeywordSelector not). |
|
5543 |
self assert:('_:_:' isKeywordSelector). |
|
5544 |
self assert:('a:b:' isKeywordSelector). |
|
5545 |
self assert:('aa:bb:' isKeywordSelector). |
|
5546 |
self assert:('aa:bb:a' isKeywordSelector not). |
|
5547 |
self assert:('1:2:' isKeywordSelector not). |
|
5548 |
" |
|
5549 |
! |
|
5550 |
||
10431 | 5551 |
isNameSpaceSelector |
5552 |
"Answer true if the receiver contains chars which form a nameSpace selector name. |
|
5553 |
These are of the form ':<ns>::<sel>', where ns is the NameSpace and sel is the regular selector. |
|
5554 |
For example, the #+ selector as seen by the Foo namespace would be actually #':Foo::+'. |
|
5555 |
You cannot easily change this algorithm here, as it is also known by the VM's lookup function." |
|
5556 |
||
5557 |
|i| |
|
5558 |
||
5559 |
(self first == $:) ifFalse:[^ false]. |
|
5560 |
i := self indexOf:$: startingAt:2. |
|
5561 |
i == 0 ifTrue:[^ false]. |
|
5562 |
self size <= (i+1) ifTrue:[^ false]. |
|
5563 |
(self at:i+1) == $: ifFalse:[^ false]. |
|
5564 |
(self at:i+2) == $: ifTrue:[^ false]. |
|
5565 |
"/ could check if the rest after the ns-prefix and colons is a valid selector... |
|
5566 |
^ true |
|
5567 |
||
5568 |
"test: |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5569 |
self assert:('+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5570 |
self assert:(':+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5571 |
self assert:(':Foo:+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5572 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5573 |
self assert:(':Foo::+' isNameSpaceSelector). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5574 |
self assert:(':Foo::bar:baz:' isNameSpaceSelector). |
10431 | 5575 |
" |
5576 |
||
5577 |
"Created: / 05-03-2007 / 11:35:31 / cg" |
|
5578 |
! |
|
5579 |
||
9192 | 5580 |
isNumeric |
5581 |
"return true, if the receiver is some numeric word; |
|
5582 |
i.e. consists only of digits." |
|
5583 |
||
5584 |
self size == 0 ifTrue:[ |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5585 |
^ false |
9192 | 5586 |
]. |
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
5587 |
^ self conform:[:char | char isDigit] |
9192 | 5588 |
|
5589 |
" |
|
5590 |
'helloWorld' isNumeric |
|
5591 |
'foo1234' isNumeric |
|
5592 |
'f1234' isNumeric |
|
5593 |
'1234' isNumeric |
|
5594 |
'+' isNumeric |
|
5595 |
" |
|
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
5596 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
5597 |
"Modified: / 13-10-2006 / 12:54:12 / cg" |
9192 | 5598 |
! |
5599 |
||
9230 | 5600 |
isString |
5601 |
"return true, if the receiver is some kind of string; |
|
5602 |
true is returned here - redefinition of Object>>isString." |
|
5603 |
||
5604 |
^ true |
|
5605 |
! |
|
5606 |
||
5607 |
isUnarySelector |
|
5608 |
"Answer true if the receiver contains only chars in an ANSI unary method selector, false otherwise." |
|
5609 |
||
9471 | 5610 |
^ (self first isLetter or:[ self first == $_ ]) |
9845 | 5611 |
and:[ self conform: [ :chr | chr isLetterOrDigit or:[chr == $_] ]] |
5612 |
||
5613 |
"Modified: / 13-09-2006 / 11:35:15 / cg" |
|
9230 | 5614 |
! |
5615 |
||
5616 |
isValidSmalltalkIdentifier |
|
5617 |
"return true, if the receivers characters make up a valid smalltalk identifier" |
|
5618 |
||
5619 |
|scanner tok| |
|
5620 |
||
5621 |
scanner := Compiler new. |
|
5622 |
scanner source:(self readStream). |
|
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
5623 |
Parser parseErrorSignal handle:[:ex | |
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
5624 |
tok := nil. |
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
5625 |
] do:[ |
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
5626 |
tok := scanner nextToken. |
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
5627 |
]. |
9230 | 5628 |
tok ~~ #Identifier ifTrue:[ |
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
5629 |
^ false |
9230 | 5630 |
]. |
5631 |
scanner tokenPosition == 1 ifFalse:[^ false]. |
|
5632 |
^ scanner sourceStream atEnd. |
|
5633 |
||
5634 |
" |
|
5635 |
'foo' isValidSmalltalkIdentifier |
|
5636 |
'1foo' isValidSmalltalkIdentifier |
|
5637 |
'_foo' isValidSmalltalkIdentifier |
|
5638 |
'_foo_bar_' isValidSmalltalkIdentifier |
|
5639 |
'foo ' isValidSmalltalkIdentifier |
|
5640 |
' foo' isValidSmalltalkIdentifier |
|
5641 |
" |
|
5642 |
! |
|
5643 |
||
9192 | 5644 |
numArgs |
608 | 5645 |
"treating the receiver as a message selector, return how many arguments would it take" |
5646 |
||
9038
d75b89570ec0
numArgs fixed (binOps can now be longer)
Claus Gittinger <cg@exept.de>
parents:
9019
diff
changeset
|
5647 |
|binopChars| |
d75b89570ec0
numArgs fixed (binOps can now be longer)
Claus Gittinger <cg@exept.de>
parents:
9019
diff
changeset
|
5648 |
|
d75b89570ec0
numArgs fixed (binOps can now be longer)
Claus Gittinger <cg@exept.de>
parents:
9019
diff
changeset
|
5649 |
(self size <= Scanner maxBinarySelectorSize) ifTrue:[ |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5650 |
binopChars := Scanner binarySelectorCharacters. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5651 |
(self conform:[:eachChar | (binopChars includes:eachChar)]) ifTrue:[ |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5652 |
^ 1 |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5653 |
]. |
608 | 5654 |
]. |
5655 |
^ self occurrencesOf:$: |
|
5656 |
||
5657 |
" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5658 |
'foo:bar:' numArgs |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5659 |
#foo:bar: numArgs |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5660 |
'hello' numArgs |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5661 |
'+' numArgs |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5662 |
'++' numArgs |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5663 |
'+++' numArgs |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5664 |
'|' numArgs |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5665 |
'?' numArgs |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5666 |
'_' numArgs |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5667 |
'_:' numArgs |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5668 |
'_:_:' numArgs |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5669 |
'<->' numArgs |
608 | 5670 |
" |
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5671 |
|
10088 | 5672 |
"Modified: / 13-10-2006 / 11:52:33 / cg" |
9192 | 5673 |
! |
5674 |
||
5675 |
partsIfSelector |
|
608 | 5676 |
"treat the receiver as a message selector, return a collection of parts." |
5677 |
||
9192 | 5678 |
|idx1 "{ Class: SmallInteger }" |
5679 |
coll idx2 sz| |
|
5680 |
||
5681 |
coll := OrderedCollection new. |
|
5682 |
idx1 := 1. |
|
5683 |
sz := self size. |
|
5684 |
[true] whileTrue:[ |
|
5685 |
idx2 := self indexOf:$: startingAt:idx1 + 1. |
|
5686 |
(idx2 == 0 or:[idx2 == sz]) ifTrue:[ |
|
5687 |
coll add:(self copyFrom:idx1). |
|
5688 |
^ coll |
|
5689 |
]. |
|
5690 |
coll add:(self copyFrom:idx1 to:idx2). |
|
5691 |
idx1 := idx2 + 1 |
|
9190 | 5692 |
]. |
9192 | 5693 |
|
5694 |
" |
|
5695 |
'foo:bar:' partsIfSelector |
|
5696 |
#foo:bar: partsIfSelector |
|
5697 |
'hello' partsIfSelector |
|
5698 |
'+' partsIfSelector |
|
5699 |
" |
|
64 | 5700 |
! ! |
5701 |
||
9192 | 5702 |
!CharacterArray methodsFor:'tracing'! |
5703 |
||
5704 |
traceInto:aRequestor level:level from:referrer |
|
5705 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
5706 |
||
5707 |
^ aRequestor traceCharacterArray:self level:level from:referrer |
|
5708 |
||
5709 |
||
5710 |
! ! |
|
5711 |
||
5712 |
!CharacterArray methodsFor:'visiting'! |
|
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
5713 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
5714 |
acceptVisitor:aVisitor with:aParameter |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
5715 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
5716 |
^ aVisitor visitString:self with:aParameter |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
5717 |
! ! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
5718 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
5719 |
!CharacterArray class methodsFor:'documentation'! |
629 | 5720 |
|
5721 |
version |
|
12170
0a05269657de
comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents:
12111
diff
changeset
|
5722 |
^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.411 2009-10-07 17:36:31 cg Exp $' |
12058 | 5723 |
! |
5724 |
||
5725 |
version_CVS |
|
12170
0a05269657de
comment/format in:6 methods
Claus Gittinger <cg@exept.de>
parents:
12111
diff
changeset
|
5726 |
^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.411 2009-10-07 17:36:31 cg Exp $' |
629 | 5727 |
! ! |
6809 | 5728 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
5729 |
CharacterArray initialize! |