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