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