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