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