author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 06 Jun 2016 10:56:12 +0100 | |
branch | jv |
changeset 19948 | be658f466bca |
parent 19946 | 693042e11e81 |
parent 19939 | 4fd56994c47f |
child 19967 | 9b1443c2aab1 |
permissions | -rw-r--r-- |
17600 | 1 |
"{ Encoding: utf8 }" |
2 |
||
64 | 3 |
" |
4 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5 |
All Rights Reserved |
64 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
15 |
|
17364 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
18 |
UninterpretedBytes variableByteSubclass:#CharacterArray |
17205 | 19 |
instanceVariableNames:'' |
20 |
classVariableNames:'PreviousMatch DecoderTables EncoderTables DecodingFailedSignal |
|
21 |
EncodingFailedSignal' |
|
22 |
poolDictionaries:'' |
|
23 |
category:'Collections-Text' |
|
64 | 24 |
! |
25 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
26 |
!CharacterArray class methodsFor:'documentation'! |
64 | 27 |
|
82 | 28 |
copyright |
29 |
" |
|
30 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
31 |
All Rights Reserved |
82 | 32 |
|
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
! |
|
41 |
||
64 | 42 |
documentation |
43 |
" |
|
255 | 44 |
CharacterArray is a superclass for all kinds of Strings (i.e. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
45 |
(singleByte-)Strings, TwoByteStrings, UnicodeStrings |
18318 | 46 |
and whatever my come in the future. |
47 |
||
48 |
This class is abstract, meaning that there are no instances of it; |
|
49 |
concrete subclasses define how the characters are stored (i.e. either as |
|
50 |
single byte, two-byte or four byte strings). |
|
51 |
||
2537 | 52 |
All this class does is provide common protocol for concrete subclasses. |
1290 | 53 |
|
18318 | 54 |
Notice: |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
55 |
internally, ST/X uses a unicode encoding for ALL characters - both |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
56 |
for individual chatacter entities and for strings of characters. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
57 |
When reading/writing files in different encodings, the conversion is |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
58 |
done at read/write time by use of a CharacterEncoder instance. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
59 |
These know how to convert to a wide range of encodings. |
18318 | 60 |
|
61 |
Also notice: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
62 |
UTF8 and UTF16 are external encodings of a Unicode string; they are never |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
63 |
used internally. When interacting with a UTF8 interface (OS-API or files), |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
64 |
you should convert UTF8 into the internal full Unicode right at the interface. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
65 |
Do not keep UTF8 around internally as String instances. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
66 |
The reason is that UTF8 makes it harder to manipulate strings (for example |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
67 |
to insert/extract substrings or to get its size. Of such operations would |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
68 |
require a scan of the UTF8, which would complicate them). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
69 |
Of course, there may be rare exceptions to this, for example if a file's contents |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
70 |
is treated as raw data, and the strings have to be copied/shuffled around only, |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
71 |
without any real processing on it. |
18318 | 72 |
|
1290 | 73 |
[author:] |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
74 |
Claus Gittinger |
1290 | 75 |
|
76 |
[see also:] |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
77 |
String TwoByteString Unicode16String Uniode32String |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
78 |
StringCollection |
64 | 79 |
" |
80 |
! ! |
|
81 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
82 |
!CharacterArray class methodsFor:'initialization'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
83 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
84 |
initialize |
8874 | 85 |
DecodingFailedSignal isNil ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
86 |
DecodingFailedSignal := DecodingError. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
87 |
DecodingFailedSignal notifierString:'error during decode'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
88 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
89 |
EncodingFailedSignal :=EncodingError. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
90 |
EncodingFailedSignal notifierString:'error during encode'. |
5440 | 91 |
] |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
92 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
93 |
" |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
94 |
CharacterArray initialize |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
95 |
" |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
96 |
|
2833 | 97 |
"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
|
98 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
99 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
100 |
!CharacterArray class methodsFor:'instance creation'! |
64 | 101 |
|
102 |
basicNew |
|
103 |
"return a new empty string" |
|
104 |
||
105 |
^ self basicNew:0 |
|
106 |
! |
|
107 |
||
2734 | 108 |
fromBytes:aByteCollection |
109 |
"return an instance of the receiver class, |
|
19757 | 110 |
taking untranslated bytes from the argument, aByteCollection |
111 |
in most-significant first order. |
|
2734 | 112 |
Only useful, when reading twoByteStrings from external sources." |
113 |
||
19757 | 114 |
^ self fromBytes:aByteCollection MSB:true |
115 |
||
116 |
" |
|
117 |
Unicode16String fromBytes:#[16r02 16r20] |
|
118 |
Unicode16String fromBytes:#[16r02 16r20] MSB:true |
|
119 |
Unicode16String fromBytes:#[16r02 16r20] MSB:false |
|
120 |
" |
|
121 |
||
122 |
"Modified: 30.6.1997 / 20:08:37 / cg" |
|
123 |
! |
|
124 |
||
125 |
fromBytes:aByteCollection MSB:msb |
|
126 |
"return an instance of the receiver class, |
|
127 |
taking untranslated bytes from the argument, aByteCollection |
|
128 |
in the given byte order. |
|
129 |
Only useful, when reading twoByteStrings from external sources." |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
130 |
|
2734 | 131 |
|mySize nBytes newString dstIdx| |
132 |
||
19757 | 133 |
self assert:(self ~~ CharacterArray). "/ only works for concrete subclasses. |
134 |
||
135 |
"/ the following is a quite inefficient implementation. |
|
136 |
"/ consider rewriting, if heavily used. |
|
2734 | 137 |
nBytes := aByteCollection size. |
138 |
mySize := self basicNew bitsPerCharacter. |
|
139 |
mySize == 16 ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
140 |
newString := self uninitializedNew:(nBytes // 2). |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
141 |
dstIdx := 1. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
142 |
msb ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
143 |
aByteCollection pairWiseDo:[:hi :lo | |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
144 |
newString at:dstIdx put:(Character value:(hi bitShift:8)+lo). |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
145 |
dstIdx := dstIdx + 1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
146 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
147 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
148 |
aByteCollection pairWiseDo:[:lo :hi | |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
149 |
newString at:dstIdx put:(Character value:(hi bitShift:8)+lo). |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
150 |
dstIdx := dstIdx + 1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
151 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
152 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
153 |
^ newString. |
2734 | 154 |
]. |
155 |
||
17625 | 156 |
^ (self uninitializedNew:nBytes) replaceFrom:1 with:aByteCollection |
157 |
||
158 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
159 |
Unicode16String fromBytes:#[16r02 16r20] |
2734 | 160 |
" |
161 |
||
162 |
"Modified: 30.6.1997 / 20:08:37 / cg" |
|
163 |
! |
|
164 |
||
64 | 165 |
fromString:aString |
166 |
"return a copy of the argument, aString" |
|
167 |
||
18967 | 168 |
|sz| |
169 |
||
170 |
sz := aString size. |
|
171 |
^ (self uninitializedNew:sz) replaceFrom:1 to:sz with:aString startingAt:1 |
|
172 |
||
173 |
" |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
174 |
Unicode16String fromString:'hello' |
17625 | 175 |
" |
581 | 176 |
! |
177 |
||
178 |
fromStringCollection:aCollectionOfStrings |
|
179 |
"return new string formed by concatenating a copy of the argument, aString" |
|
180 |
||
181 |
^ self fromStringCollection:aCollectionOfStrings separatedBy:'' |
|
182 |
||
183 |
" |
|
184 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') |
|
185 |
" |
|
186 |
||
187 |
"Created: 20.11.1995 / 15:26:59 / cg" |
|
188 |
! |
|
189 |
||
190 |
fromStringCollection:aCollectionOfStrings separatedBy:aSeparatorString |
|
191 |
"return new string formed by concatenating a copy of the argument, aString" |
|
192 |
||
17625 | 193 |
|stream| |
194 |
||
195 |
aCollectionOfStrings do:[:eachString | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
196 |
stream isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
197 |
stream := self writeStreamClass with:eachString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
198 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
199 |
stream |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
200 |
nextPutAll:aSeparatorString; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
201 |
nextPutAll:eachString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
202 |
]. |
581 | 203 |
]. |
17700 | 204 |
stream isNil ifTrue:[^ '']. |
17625 | 205 |
^ stream contents |
581 | 206 |
|
207 |
" |
|
208 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:' ' |
|
17625 | 209 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:'È ' |
210 |
Text fromStringCollection:{'hello'. 'world'. 'how' allBold. 'about'. 'this'. 'äöü'} separatedBy:'È ' |
|
581 | 211 |
" |
212 |
||
213 |
"Created: 20.11.1995 / 15:32:17 / cg" |
|
608 | 214 |
! |
215 |
||
5757 | 216 |
fromUTF8Bytes:aByteCollection |
5758 | 217 |
"return a new string which represents the characters as decoded |
218 |
from the utf8 encoded bytes, aByteCollection. |
|
219 |
Returns either a normal String, or a TwoByteString instance. |
|
6810 | 220 |
Only useful, when reading twoByteStrings from external sources. |
221 |
This only handles up-to 16bit characters" |
|
5757 | 222 |
|
7876 | 223 |
^ self decodeFromUTF8:aByteCollection. |
5757 | 224 |
|
225 |
" |
|
8874 | 226 |
CharacterArray fromUTF8Bytes:#[ 16r41 16r42 ] |
227 |
CharacterArray fromUTF8Bytes:#[ 16rC1 16r02 ] |
|
228 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r81 16r02 ] |
|
6810 | 229 |
CharacterArray fromUTF8Bytes:#[ 16rEF 16rBF 16rBF ] |
230 |
||
231 |
rfc2279 examples: |
|
8874 | 232 |
CharacterArray fromUTF8Bytes:#[ 16r41 16rE2 16r89 16rA2 16rCE 16r91 16r2E ] |
233 |
CharacterArray fromUTF8Bytes:#[ 16rED 16r95 16r9C 16rEA 16rB5 16rAD 16rEC 16r96 16rB4 ] |
|
234 |
CharacterArray fromUTF8Bytes:#[ 16rE6 16r97 16rA5 16rE6 16r9C 16rAC 16rE8 16rAA 16r9E ] |
|
6810 | 235 |
|
236 |
invalid: |
|
8874 | 237 |
CharacterArray fromUTF8Bytes:#[ 16rC0 16r80 ] |
238 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r80 16r80 ] |
|
5757 | 239 |
" |
240 |
! |
|
241 |
||
608 | 242 |
new |
243 |
"return a new empty string" |
|
244 |
||
245 |
^ self basicNew:0 |
|
9425 | 246 |
! |
247 |
||
248 |
readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
|
249 |
"read & return the next String from the (character-)stream aStream; |
|
250 |
skipping all whitespace first; return the value of exceptionBlock, |
|
251 |
if no string can be read. The sequence of characters as read from the |
|
252 |
stream must be one as stored via storeOn: or storeString." |
|
253 |
||
254 |
|str collected char| |
|
255 |
||
256 |
str := aStreamOrString readStream. |
|
257 |
||
258 |
"skip whiteSpace" |
|
259 |
str skipSeparators. |
|
11320 | 260 |
|
14452
ef3591302afa
changed: #readSmalltalkStringFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
14451
diff
changeset
|
261 |
(str peekOrNil == $') ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
262 |
str next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
263 |
collected := self writeStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
264 |
[str atEnd] whileFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
265 |
char := str next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
266 |
char == $' ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
267 |
"/ look for another quote |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
268 |
str peekOrNil ~~ $' ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
269 |
"end of string reached" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
270 |
^ collected contents. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
271 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
272 |
"eat doubled quote" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
273 |
str next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
274 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
275 |
((char ~~ Character return) or:[str peekOrNil ~~ Character lf]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
276 |
"compress CRLF to LF, but keep a single CR" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
277 |
collected nextPut:char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
278 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
279 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
280 |
"if we come here, we reached the end without finding a closing $'" |
9425 | 281 |
]. |
282 |
^ exceptionBlock value |
|
283 |
||
284 |
" |
|
285 |
String readFrom:('''hello world''' readStream) |
|
286 |
String readFrom:('''hello '''' world''' readStream) |
|
287 |
String readFrom:('1 ''hello'' ' readStream) |
|
288 |
String readFrom:('1 ''hello'' ' readStream) onError:['foobar'] |
|
289 |
" |
|
290 |
||
291 |
"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
|
292 |
"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
|
293 |
! |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
294 |
|
13201 | 295 |
writeStreamClass |
17213 | 296 |
"the class used by writeStream. |
297 |
Here, we return CharacterWriteStream, which automatically changes |
|
298 |
the underlying collection to a multiByte string (i.e. UnicodeString). |
|
299 |
So you can stream wide characters into it." |
|
13201 | 300 |
|
301 |
^ CharacterWriteStream |
|
11243
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
302 |
|
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
303 |
" |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
304 |
String writeStream |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
305 |
" |
13201 | 306 |
|
307 |
"Created: / 09-01-2011 / 10:37:57 / cg" |
|
64 | 308 |
! ! |
309 |
||
9265 | 310 |
!CharacterArray class methodsFor:'Compatibility-VW'! |
311 |
||
312 |
fromIntegerArray: anArray |
|
313 |
"Answer a new instance of the receiver that is created from the argument, anArray." |
|
314 |
||
315 |
| new | |
|
316 |
||
317 |
new := self new: anArray size. |
|
318 |
1 to: anArray size do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
319 |
new at: index put: (anArray at: index) asCharacter |
9265 | 320 |
]. |
321 |
^new |
|
322 |
||
323 |
" |
|
324 |
String fromIntegerArray: #[8 127] |
|
325 |
" |
|
326 |
! ! |
|
327 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
328 |
!CharacterArray class methodsFor:'Signal constants'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
329 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
330 |
decodingFailedSignal |
2833 | 331 |
"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
|
332 |
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
|
333 |
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
|
334 |
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
|
335 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
336 |
^ DecodingFailedSignal |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
337 |
|
2833 | 338 |
"Created: 28.6.1997 / 20:09:55 / cg" |
339 |
"Modified: 3.8.1997 / 18:16:47 / cg" |
|
340 |
! |
|
341 |
||
342 |
encodingFailedSignal |
|
343 |
"return the (query-) signal, raised when encoding of a string is not possible |
|
344 |
due to invalid characters contained in the source." |
|
345 |
||
346 |
^ EncodingFailedSignal |
|
347 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
348 |
"Modified: 28.6.1997 / 20:09:35 / cg" |
2833 | 349 |
"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
|
350 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
351 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
352 |
!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
|
353 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
354 |
lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
355 |
"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
|
356 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
357 |
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
|
358 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
359 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
360 |
CharacterArray lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
361 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
362 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
363 |
"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
|
364 |
"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
|
365 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
366 |
|
7421 | 367 |
!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
|
368 |
|
7876 | 369 |
decodeFromUTF8:aStringOrByteCollection |
19837 | 370 |
"given a string in UTF8 encoding, |
371 |
return a new string containing the same characters, in Unicode encoding. |
|
372 |
Returns either a normal String, a Unicode16String or a Unicode32String instance. |
|
373 |
This is only useful, when reading from external sources or communicating with |
|
374 |
other systems |
|
375 |
(ST/X never uses utf8 internally, but always uses strings of fully decoded unicode characters). |
|
376 |
This only handles up-to 30bit characters." |
|
377 |
||
378 |
|sz anyAbove7BitAscii nBitsRequired |
|
379 |
ascii "{ Class: SmallInteger }" |
|
380 |
byte "{ Class: SmallInteger }" |
|
381 |
lastIdx "{ Class: SmallInteger }" |
|
382 |
srcIdx "{ Class: SmallInteger }" |
|
383 |
idx "{ Class: SmallInteger }" |
|
384 |
nFollowBytes "{ Class: SmallInteger }" |
|
385 |
minValue "{ Class: SmallInteger }" |
|
386 |
newString| |
|
387 |
||
388 |
"/ fast track, also avoid creation of new strings if aStringOrByteCollection is already a 7-bit string |
|
389 |
aStringOrByteCollection containsNon7BitAscii ifFalse:[ |
|
390 |
^ aStringOrByteCollection asSingleByteString |
|
391 |
]. |
|
392 |
||
393 |
nBitsRequired := 8. |
|
394 |
anyAbove7BitAscii := false. |
|
395 |
sz := 0. |
|
396 |
||
397 |
lastIdx := aStringOrByteCollection size. |
|
398 |
srcIdx := 1. |
|
399 |
||
400 |
"first determine the string size and max element size. |
|
401 |
Check for UTF-8 confomance on the fly." |
|
402 |
[srcIdx <= lastIdx] whileTrue:[ |
|
403 |
byte := ascii := aStringOrByteCollection byteAt:srcIdx. |
|
404 |
srcIdx := srcIdx + 1. |
|
405 |
(byte bitAnd:16r80) ~~ 0 ifTrue:[ |
|
406 |
anyAbove7BitAscii := true. |
|
407 |
(byte bitAnd:2r11100000) == 2r11000000 ifTrue:[ |
|
408 |
"/ 80 .. 7FF |
|
409 |
ascii := byte bitAnd:2r00011111. |
|
410 |
nFollowBytes := 1. |
|
411 |
minValue := 16r80. |
|
412 |
] ifFalse:[(byte bitAnd:2r11110000) == 2r11100000 ifTrue:[ |
|
413 |
"/ 800 .. FFFF |
|
414 |
ascii := byte bitAnd:2r00001111. |
|
415 |
nFollowBytes := 2. |
|
416 |
minValue := 16r800. |
|
417 |
] ifFalse:[(byte bitAnd:2r11111000) == 2r11110000 ifTrue:[ |
|
418 |
"/ 10000 .. 1FFFFF |
|
419 |
ascii := byte bitAnd:2r00000111. |
|
420 |
nFollowBytes := 3. |
|
421 |
minValue := 16r10000. |
|
422 |
] ifFalse:[(byte bitAnd:2r11111100) == 2r11111000 ifTrue:[ |
|
423 |
"/ 200000 .. 3FFFFFF |
|
424 |
ascii := byte bitAnd:2r00000011. |
|
425 |
nFollowBytes := 4. |
|
426 |
minValue := 16r200000. |
|
427 |
] ifFalse:[(byte bitAnd:2r11111110) == 2r11111100 ifTrue:[ |
|
428 |
"/ 4000000 .. 7FFFFFFF |
|
429 |
ascii := byte bitAnd:2r00000001. |
|
430 |
ascii ~~ 0 ifTrue:[ |
|
431 |
"/ ST/X can only represent 30 bit unicode characters. |
|
432 |
"/ but the max unicode character is defined as 16r10 FFFF anyway |
|
433 |
^ DecodingError newException |
|
434 |
defaultValue:aStringOrByteCollection; |
|
435 |
raiseRequestWith:aStringOrByteCollection errorString:'unicode character out of range'. |
|
436 |
]. |
|
437 |
nFollowBytes := 5. |
|
438 |
minValue := 16r4000000. |
|
439 |
] ifFalse:[ |
|
440 |
^ DecodingError newException |
|
441 |
defaultValue:aStringOrByteCollection; |
|
442 |
raiseRequestWith:aStringOrByteCollection errorString:'invalid utf8 encoding'. |
|
443 |
]]]]]. |
|
444 |
||
445 |
nFollowBytes timesRepeat:[ |
|
446 |
byte := aStringOrByteCollection byteAt:srcIdx. |
|
447 |
srcIdx := srcIdx + 1. |
|
448 |
(byte bitAnd:2r11000000) ~~ 2r10000000 ifTrue:[ |
|
449 |
^ DecodingError newException |
|
450 |
defaultValue:aStringOrByteCollection; |
|
451 |
raiseRequestWith:aStringOrByteCollection errorString:'illegal followbyte'. |
|
452 |
]. |
|
453 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:2r00111111). |
|
454 |
]. |
|
455 |
ascii > 16rFFFF ifTrue:[ |
|
456 |
nBitsRequired < 32 ifTrue:[nBitsRequired := 32]. |
|
457 |
] ifFalse:[ascii > 16rFF ifTrue:[ |
|
458 |
nBitsRequired < 16 ifTrue:[nBitsRequired := 16]. |
|
459 |
]]. |
|
460 |
ascii < minValue ifTrue:[ |
|
461 |
"encoding a value in a longer utf8-sequence than required is not allowed |
|
462 |
and imposes a security risk" |
|
463 |
^ DecodingError newException |
|
464 |
defaultValue:aStringOrByteCollection; |
|
465 |
raiseRequestWith:aStringOrByteCollection errorString:'overlong utf8 sequence'. |
|
466 |
]. |
|
467 |
]. |
|
468 |
sz := sz + 1. |
|
469 |
]. |
|
470 |
||
471 |
nBitsRequired == 8 ifTrue:[ |
|
472 |
anyAbove7BitAscii ifFalse:[ |
|
473 |
"/ can return the original string |
|
474 |
^ aStringOrByteCollection asSingleByteString. |
|
475 |
]. |
|
476 |
newString := String uninitializedNew:sz |
|
477 |
] ifFalse:[nBitsRequired <= 16 ifTrue:[ |
|
478 |
newString := Unicode16String new:sz |
|
479 |
] ifFalse:[ |
|
480 |
newString := Unicode32String new:sz |
|
481 |
]]. |
|
482 |
||
483 |
idx := srcIdx := 1. |
|
484 |
||
485 |
"now fill the string" |
|
486 |
[srcIdx <= lastIdx] whileTrue:[ |
|
487 |
byte := ascii := aStringOrByteCollection byteAt:srcIdx. |
|
488 |
srcIdx := srcIdx + 1. |
|
489 |
(byte bitAnd:2r10000000) ~~ 0 ifTrue:[ |
|
490 |
(byte bitAnd:2r11100000) == 2r11000000 ifTrue:[ |
|
491 |
ascii := byte bitAnd:2r00011111. |
|
492 |
nFollowBytes := 1. |
|
493 |
] ifFalse:[(byte bitAnd:2r11110000) == 2r11100000 ifTrue:[ |
|
494 |
ascii := byte bitAnd:2r00001111. |
|
495 |
nFollowBytes := 2. |
|
496 |
] ifFalse:[(byte bitAnd:2r11111000) == 2r11110000 ifTrue:[ |
|
497 |
ascii := byte bitAnd:2r00000111. |
|
498 |
nFollowBytes := 3. |
|
499 |
] ifFalse:[(byte bitAnd:2r11111100) == 2r11111000 ifTrue:[ |
|
500 |
"5 byte sequences do not result in valid unicode" |
|
501 |
ascii := byte bitAnd:2r00000011. |
|
502 |
nFollowBytes := 4. |
|
503 |
] ifFalse:[(byte bitAnd:2r11111110) == 2r11111100 ifTrue:[ |
|
504 |
"6 byte sequences do not result in valid unicode" |
|
505 |
ascii := byte bitAnd:2r00000001. |
|
506 |
nFollowBytes := 5. |
|
507 |
]]]]]. |
|
508 |
nFollowBytes timesRepeat:[ |
|
509 |
byte := aStringOrByteCollection byteAt:srcIdx. |
|
510 |
srcIdx := srcIdx + 1. |
|
511 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:2r00111111). |
|
512 |
]. |
|
513 |
]. |
|
514 |
newString at:idx put:(Character value:ascii). |
|
515 |
idx := idx + 1. |
|
516 |
]. |
|
517 |
^ newString |
|
518 |
||
519 |
" |
|
520 |
CharacterArray decodeFromUTF8:#[ 16r41 16r42 ] |
|
521 |
CharacterArray decodeFromUTF8:#[ 16rC6 16r8F ] |
|
522 |
CharacterArray decodeFromUTF8:#[ 16rE0 16r81 16r02 ] |
|
523 |
CharacterArray decodeFromUTF8:#[ 16rEF 16rBF 16rBF ] |
|
524 |
||
525 |
rfc2279 (deprecated) examples: |
|
526 |
CharacterArray decodeFromUTF8:#[ 16r41 16rE2 16r89 16rA2 16rCE 16r91 16r2E ] |
|
527 |
CharacterArray decodeFromUTF8:#[ 16rED 16r95 16r9C 16rEA 16rB5 16rAD 16rEC 16r96 16rB4 ] |
|
528 |
CharacterArray decodeFromUTF8:#[ 16rE6 16r97 16rA5 16rE6 16r9C 16rAC 16rE8 16rAA 16r9E ] |
|
529 |
||
530 |
invalid: |
|
531 |
CharacterArray decodeFromUTF8:#[ 16rC0 16r80 ] |
|
532 |
CharacterArray decodeFromUTF8:#[ 16rE0 16r80 16r80 ] |
|
533 |
" |
|
534 |
||
535 |
" |
|
536 |
CharacterArray decodeFromUTF8:#[ 16r41 16r42 ] |
|
537 |
CharacterArray decodeFromUTF8:#[ 16rC1 16r02 ] |
|
538 |
CharacterArray decodeFromUTF8:#[ 16rE0 16r81 16r02 ] |
|
539 |
CharacterArray decodeFromUTF8:#[ 16rEF 16rBF 16rBF ] |
|
7876 | 540 |
|
541 |
rfc2279 examples: |
|
19837 | 542 |
CharacterArray decodeFromUTF8:#[ 16r41 16rE2 16r89 16rA2 16rCE 16r91 16r2E ] |
543 |
CharacterArray decodeFromUTF8:#[ 16rED 16r95 16r9C 16rEA 16rB5 16rAD 16rEC 16r96 16rB4 ] |
|
544 |
CharacterArray decodeFromUTF8:#[ 16rE6 16r97 16rA5 16rE6 16r9C 16rAC 16rE8 16rAA 16r9E ] |
|
7876 | 545 |
|
546 |
invalid: |
|
19837 | 547 |
CharacterArray decodeFromUTF8:#[ 16rC0 16r80 ] |
548 |
CharacterArray decodeFromUTF8:#[ 16rE0 16r80 16r80 ] |
|
7876 | 549 |
" |
443 | 550 |
! ! |
551 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
552 |
!CharacterArray class methodsFor:'pattern matching'! |
64 | 553 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
554 |
matchEscapeCharacter |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
555 |
"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
|
556 |
(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
|
557 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
558 |
^ $\ |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
559 |
! |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
560 |
|
15734 | 561 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop caseSensitive:caseSensitive |
327 | 562 |
"helper for match; return true if the characters from start to stop in |
563 |
aString are matching the scan in matchScan from matchStart to matchStop. |
|
328 | 564 |
The matchScan is as created by asMatchScanArray. |
327 | 565 |
|
8874 | 566 |
This algorithm is not at all the most efficient; |
567 |
for heavy duty pattern matching, an interface (primitive) to the regex |
|
328 | 568 |
pattern matching package should be added." |
327 | 569 |
|
8874 | 570 |
|matchEntry |
327 | 571 |
mStart "{ Class: SmallInteger }" |
572 |
mStop "{ Class: SmallInteger }" |
|
573 |
sStart "{ Class: SmallInteger }" |
|
574 |
sStop "{ Class: SmallInteger }" |
|
575 |
mSize "{ Class: SmallInteger }" |
|
576 |
sSize "{ Class: SmallInteger }" |
|
577 |
index "{ Class: SmallInteger }" |
|
2561 | 578 |
quickCheck matchLast nextMatchEntry |
986 | 579 |
checkChar included| |
327 | 580 |
|
581 |
mStart := matchStart. |
|
582 |
mStop := matchStop. |
|
583 |
sStart := start. |
|
584 |
sStop := stop. |
|
585 |
||
16245 | 586 |
[ |
8874 | 587 |
"/ Transcript showCR:('match: ''' , (aString copyFrom:sStart to:sStop) , |
3537 | 588 |
"/ ''' against:' , (matchScanArray copyFrom:mStart to:mStop) printString). |
589 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
590 |
mSize := mStop - mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
591 |
sSize := sStop - sStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
592 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
593 |
"empty strings match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
594 |
(mSize == 0) ifTrue:[^ (sSize == 0)]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
595 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
596 |
matchEntry := matchScanArray at:mStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
597 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
598 |
"/ the most common case first: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
599 |
(sSize ~~ 0 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
600 |
and:[(checkChar := (aString at:sStart)) = matchEntry]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
601 |
"advance by one and continue" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
602 |
mStart := mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
603 |
sStart := sStart + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
604 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
605 |
(matchEntry == #any) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
606 |
"restString empty -> no match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
607 |
(sSize == 0) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
608 |
"# matches single character" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
609 |
((sSize == 1) and:[mSize == 1]) ifTrue:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
610 |
"advance by one and continue" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
611 |
mStart := mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
612 |
sStart := sStart + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
613 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
614 |
(matchEntry == #anyString) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
615 |
"* alone matches anything" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
616 |
(mSize == 1) ifTrue:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
617 |
"restString empty & matchString not empty -> no match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
618 |
(sSize == 0) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
619 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
620 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
621 |
try to avoid some of the recursion by checking last |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
622 |
character and continue with shortened strings if possible |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
623 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
624 |
quickCheck := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
625 |
(mStop >= mStart) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
626 |
matchLast := matchScanArray at:mStop. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
627 |
(matchLast ~~ #anyString) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
628 |
(matchLast == #any) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
629 |
quickCheck := true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
630 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
631 |
matchLast == (aString at:sStop) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
632 |
quickCheck := true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
633 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
634 |
matchLast isString ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
635 |
quickCheck := matchLast includes:(aString at:sStop) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
636 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
637 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
638 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
639 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
640 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
641 |
quickCheck ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
642 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
643 |
quickCheck ok, advance from the right |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
644 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
645 |
mStop := mStop - 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
646 |
sStop := sStop - 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
647 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
648 |
"/ no quick check; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
649 |
"/ look for the next character(s) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
650 |
"/ and try matching there |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
651 |
"/ (to avoid recursion) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
652 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
653 |
mStart < mStop ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
654 |
nextMatchEntry := matchScanArray at:mStart+1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
655 |
nextMatchEntry isCharacter ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
656 |
sStart <= sStop ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
657 |
[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
658 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
659 |
index := aString indexOf:nextMatchEntry startingAt:sStart |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
660 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
661 |
index := aString findFirst:[:c | c asLowercase = nextMatchEntry asLowercase] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
662 |
startingAt:sStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
663 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
664 |
(index == 0 or:[index > sStop]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
665 |
^ false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
666 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
667 |
(self matchScan:matchScanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
668 |
from:(mStart + 1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
669 |
to:mStop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
670 |
with:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
671 |
from:index |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
672 |
to:sStop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
673 |
caseSensitive:caseSensitive |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
674 |
) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
675 |
^ true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
676 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
677 |
sStart := index + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
678 |
] loop. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
679 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
680 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
681 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
682 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
683 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
684 |
no quick check possible; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
685 |
loop over all possible substrings |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
686 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
687 |
index := sStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
688 |
[index <= sStop] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
689 |
(self matchScan:matchScanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
690 |
from:(mStart + 1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
691 |
to:mStop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
692 |
with:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
693 |
from:index |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
694 |
to:sStop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
695 |
caseSensitive:caseSensitive |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
696 |
) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
697 |
^ true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
698 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
699 |
index := index + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
700 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
701 |
^ false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
702 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
703 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
704 |
(matchEntry isString) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
705 |
"testString empty -> no match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
706 |
(sSize == 0) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
707 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
708 |
included := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
709 |
"/ checkChar := aString at:sStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
710 |
included := matchEntry includes:checkChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
711 |
included ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
712 |
caseSensitive ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
713 |
checkChar isUppercase ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
714 |
included := matchEntry includes:checkChar asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
715 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
716 |
included := matchEntry includes:checkChar asUppercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
717 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
718 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
719 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
720 |
mStart := mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
721 |
mSize := mSize - 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
722 |
included ifFalse:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
723 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
724 |
((sSize == 1) and:[mSize == 0]) ifTrue:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
725 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
726 |
"/ must be single character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
727 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
728 |
"testString empty ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
729 |
(sSize == 0) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
730 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
731 |
"first characters equal ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
732 |
"/ checkChar := aString at:sStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
733 |
caseSensitive ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
734 |
(checkChar asUppercase ~= matchEntry asUppercase) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
735 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
736 |
"advance and continue" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
737 |
mStart := mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
738 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
739 |
"cut off 1st char and continue" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
740 |
sStart := sStart + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
741 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
742 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
743 |
] |
16245 | 744 |
] loop. |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
745 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
746 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
747 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
748 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
749 |
scanArray := self matchScanArrayFrom:'*hello'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
750 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
751 |
CharacterArray |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
752 |
matchScan:scanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
753 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
754 |
to:scanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
755 |
with:s |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
756 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
757 |
to:s size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
758 |
caseSensitive:true |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
759 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
760 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
761 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
762 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
763 |
scanArray := self matchScanArrayFrom:'*hello*'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
764 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
765 |
CharacterArray |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
766 |
matchScan:scanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
767 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
768 |
to:scanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
769 |
with:s |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
770 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
771 |
to:s size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
772 |
caseSensitive:true |
15734 | 773 |
" |
774 |
||
775 |
"Modified: / 24-07-2011 / 07:17:03 / cg" |
|
776 |
"Modified (comment): / 24-07-2011 / 08:55:14 / cg" |
|
777 |
! |
|
778 |
||
779 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop ignoreCase:ignoreCase |
|
780 |
<resource: #obsolete> |
|
781 |
"helper for match; return true if the characters from start to stop in |
|
782 |
aString are matching the scan in matchScan from matchStart to matchStop. |
|
783 |
The matchScan is as created by asMatchScanArray. |
|
784 |
||
785 |
This algorithm is not at all the most efficient; |
|
786 |
for heavy duty pattern matching, an interface (primitive) to the regex |
|
787 |
pattern matching package should be added." |
|
788 |
||
789 |
^ self |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
790 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop caseSensitive:ignoreCase not |
15734 | 791 |
|
792 |
" |
|
793 |
|scanArray s| |
|
794 |
||
795 |
scanArray := self matchScanArrayFrom:'*hello'. |
|
796 |
s := 'foo bar hello world'. |
|
797 |
CharacterArray |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
798 |
matchScan:scanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
799 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
800 |
to:scanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
801 |
with:s |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
802 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
803 |
to:s size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
804 |
ignoreCase:false |
15734 | 805 |
" |
806 |
" |
|
807 |
|scanArray s| |
|
808 |
||
809 |
scanArray := self matchScanArrayFrom:'*hello*'. |
|
810 |
s := 'foo bar hello world'. |
|
811 |
CharacterArray |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
812 |
matchScan:scanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
813 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
814 |
to:scanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
815 |
with:s |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
816 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
817 |
to:s size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
818 |
ignoreCase:false |
13520 | 819 |
" |
820 |
||
821 |
"Modified: / 24-07-2011 / 07:17:03 / cg" |
|
822 |
"Modified (comment): / 24-07-2011 / 08:55:14 / cg" |
|
608 | 823 |
! |
824 |
||
825 |
matchScanArrayFrom:aString |
|
826 |
"scan a pattern string and decompose it into a scanArray. |
|
827 |
This is processed faster (especially with character ranges), and |
|
828 |
can also be reused later. (if the same pattern is to be searched again)" |
|
829 |
||
9282
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
830 |
^ self matchScanArrayFrom:aString escapeCharacter:(self matchEscapeCharacter) |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
831 |
|
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
832 |
" |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
833 |
String matchScanArrayFrom:'*ute*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
834 |
String matchScanArrayFrom:'**ute**' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
835 |
String matchScanArrayFrom:'*uter' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
836 |
String matchScanArrayFrom:'\*uter' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
837 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
838 |
String matchScanArrayFrom:'[abcd]*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
839 |
String matchScanArrayFrom:'[a-k]*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
840 |
String matchScanArrayFrom:'*some*compl*ern*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
841 |
String matchScanArrayFrom:'[a-' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
842 |
String matchScanArrayFrom:'[a-zA-Z]' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
843 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
844 |
" |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
845 |
|
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
846 |
"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
|
847 |
! |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
848 |
|
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
849 |
matchScanArrayFrom:aString escapeCharacter:escape |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
850 |
"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
|
851 |
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
|
852 |
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
|
853 |
|
8874 | 854 |
|coll |
608 | 855 |
idx "{ Class: SmallInteger }" |
9282
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
856 |
end c1 c2 matchSet previous| |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
857 |
|
5487 | 858 |
previous := nil. |
608 | 859 |
|
860 |
coll := OrderedCollection new. |
|
861 |
idx := 1. end := aString size. |
|
862 |
[idx <= end] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
863 |
|char this| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
864 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
865 |
char := aString at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
866 |
char == $* ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
867 |
previous ~~ #anyString ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
868 |
this := #anyString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
869 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
870 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
871 |
char == $# ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
872 |
previous ~~ #anyString ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
873 |
this := #any |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
874 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
875 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
876 |
char == $[ ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
877 |
matchSet := IdentitySet new. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
878 |
idx := idx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
879 |
idx > end ifTrue:[^ nil]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
880 |
char := aString at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
881 |
c1 := nil. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
882 |
[char ~~ $]] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
883 |
((char == $-) and:[c1 notNil]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
884 |
idx := idx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
885 |
idx > end ifTrue:[^ nil]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
886 |
c2 := aString at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
887 |
c1 to:c2 do:[:c | matchSet add:c]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
888 |
c1 := nil. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
889 |
idx := idx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
890 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
891 |
(char ~~ $]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
892 |
matchSet add:char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
893 |
c1 := char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
894 |
idx := idx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
895 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
896 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
897 |
idx > end ifTrue:[^ nil]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
898 |
char := aString at:idx |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
899 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
900 |
this := matchSet asString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
901 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
902 |
char == escape ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
903 |
idx := idx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
904 |
idx > end ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
905 |
"/ mhmh - what should we do here ? |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
906 |
this := char |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
907 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
908 |
this := aString at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
909 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
910 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
911 |
this := char |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
912 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
913 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
914 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
915 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
916 |
this notNil ifTrue:[coll add:this. previous := this]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
917 |
idx := idx + 1 |
608 | 918 |
]. |
919 |
||
920 |
^ coll asArray |
|
921 |
||
922 |
" |
|
8874 | 923 |
String matchScanArrayFrom:'*ute*' |
924 |
String matchScanArrayFrom:'**ute**' |
|
925 |
String matchScanArrayFrom:'*uter' |
|
926 |
String matchScanArrayFrom:'\*uter' |
|
927 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
|
928 |
String matchScanArrayFrom:'[abcd]*' |
|
929 |
String matchScanArrayFrom:'[a-k]*' |
|
930 |
String matchScanArrayFrom:'*some*compl*ern*' |
|
931 |
String matchScanArrayFrom:'[a-' |
|
932 |
String matchScanArrayFrom:'[a-zA-Z]' |
|
933 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
|
608 | 934 |
" |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
935 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
936 |
"Modified: 2.4.1997 / 16:20:29 / cg" |
9192 | 937 |
! ! |
938 |
||
939 |
!CharacterArray class methodsFor:'queries'! |
|
940 |
||
941 |
isAbstract |
|
11229 | 942 |
"Return if this class is an abstract class. |
943 |
True is returned for CharacterArray here; false for subclasses. |
|
19464 | 944 |
Abstract subclasses must redefine this again." |
11229 | 945 |
|
9192 | 946 |
^ self == CharacterArray |
18597 | 947 |
! |
948 |
||
949 |
speciesForCharacterSize:characterSize |
|
950 |
"answer the class, that is able to hold characters of size characterSize" |
|
951 |
||
952 |
characterSize <= 8 ifTrue:[^ String]. |
|
953 |
characterSize <= 16 ifTrue:[^ Unicode16String]. |
|
954 |
^ Unicode32String |
|
9192 | 955 |
! ! |
956 |
||
957 |
!CharacterArray methodsFor:'Compatibility-ANSI'! |
|
958 |
||
959 |
addLineDelimiters |
|
960 |
"Ansi compatibility - same as withCRs" |
|
961 |
||
962 |
^ self withCRs |
|
963 |
||
964 |
"Modified: / 13.11.2001 / 19:16:25 / cg" |
|
17543 | 965 |
! ! |
966 |
||
967 |
!CharacterArray methodsFor:'Compatibility-Dolphin'! |
|
9192 | 968 |
|
969 |
copyExpanding:expandTable |
|
970 |
"return a copy of myself, with translations from the expandTable sliced in. |
|
18392 | 971 |
The argument is supposed to map from characters to either characters or strings. |
972 |
Added for Dolphin compatibility" |
|
9192 | 973 |
|
974 |
|ds| |
|
975 |
||
976 |
ds := WriteStream on:(self species new). |
|
977 |
self do:[:eachChar | |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
978 |
|repl| |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
979 |
|
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
980 |
repl := expandTable at:eachChar ifAbsent:[nil]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
981 |
repl isNil ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
982 |
ds nextPut:eachChar |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
983 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
984 |
repl size == 0 ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
985 |
ds nextPut:repl |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
986 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
987 |
ds nextPutAll:repl |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
988 |
] |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
989 |
]. |
9192 | 990 |
]. |
6870 | 991 |
^ ds contents. |
992 |
! |
|
993 |
||
994 |
formatWith:aString |
|
11955 | 995 |
"Compatibility method - do not use in new code. |
18392 | 996 |
same as #bindWith: for Dolphin compatibility" |
6870 | 997 |
|
998 |
^ self bindWith:aString |
|
999 |
||
1000 |
" |
|
1001 |
'hello%1world' formatWith:'123' |
|
1002 |
" |
|
1003 |
! |
|
1004 |
||
1005 |
formatWith:arg1 with:arg2 |
|
11955 | 1006 |
"Compatibility method - do not use in new code. |
18392 | 1007 |
same as #bindWith: for Dolphin compatibility" |
6870 | 1008 |
|
1009 |
^ self bindWith:arg1 with:arg2 |
|
1010 |
||
1011 |
" |
|
1012 |
'hello%1 %2world' formatWith:'123' with:234 |
|
1013 |
" |
|
1014 |
! |
|
1015 |
||
1016 |
formatWith:arg1 with:arg2 with:arg3 |
|
11955 | 1017 |
"Compatibility method - do not use in new code. |
18392 | 1018 |
same as #bindWith: for Dolphin compatibility" |
6870 | 1019 |
|
1020 |
^ self bindWith:arg1 with:arg2 with:arg3 |
|
1021 |
||
1022 |
" |
|
1023 |
'hello%1 %2 %3world' formatWith:'123' with:234 with:345 |
|
1024 |
" |
|
6391 | 1025 |
! ! |
1026 |
||
14681 | 1027 |
!CharacterArray methodsFor:'Compatibility-GNU'! |
1028 |
||
1029 |
% anArrayOfOperands |
|
1030 |
"return a copy of the receiver, where a '%i' escape |
|
1031 |
is replaced by the coresponding string from the argument array. |
|
1032 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
1033 |
Added for GNU-ST compatibility." |
|
1034 |
||
1035 |
^ self expandPlaceholdersWith:anArrayOfOperands |
|
1036 |
||
1037 |
" |
|
1038 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1039 |
% #('smalltalk' 'c++' 'c') |
14681 | 1040 |
|
1041 |
'do you %(what) ?' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1042 |
% (Dictionary new at:#'what' put:'understand'; yourself) |
14681 | 1043 |
" |
1044 |
! ! |
|
1045 |
||
7261 | 1046 |
!CharacterArray methodsFor:'Compatibility-ST/V'! |
608 | 1047 |
|
17517 | 1048 |
asArrayOfSubstrings |
1049 |
"return an array of substrings from the receiver, interpreting |
|
1050 |
separators (i.e. spaces & newlines) as word-delimiters. |
|
18390 | 1051 |
This has been added for ST/V compatibility |
1052 |
- the actual work is done in asCollectionOfWords. |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1053 |
(sigh: it is called #'subStrings' in V'Age, #'substrings' in Squeak |
17517 | 1054 |
and #'asCollectionOfWords' in ST/X) " |
1055 |
||
1056 |
^ self asCollectionOfWords asArray |
|
1057 |
||
1058 |
" |
|
1059 |
'1 one two three four 5 five' asArrayOfSubstrings |
|
1060 |
'1 |
|
1061 |
one |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
1062 |
two three four 5 five' asArrayOfSubstrings |
17517 | 1063 |
" |
1064 |
! |
|
1065 |
||
608 | 1066 |
byteAt:index put:aByte |
1067 |
"store a byte at given index. |
|
1068 |
This is an ST/V compatibility method." |
|
1069 |
||
1333
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
1070 |
"/ (aByte == 0) ifTrue:[ |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
1071 |
"/ "store a space instead" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
1072 |
"/ ^ 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
|
1073 |
"/ ]. |
11754
5132248cfd6e
common definition of #byteAt:put between CharacterArray and Symbol
Stefan Vogel <sv@exept.de>
parents:
11632
diff
changeset
|
1074 |
^ self basicAt:index put:(Character value:aByte) |
9192 | 1075 |
|
1076 |
" |
|
1077 |
'hello' copy at:1 put:$H asciiValue; yourself |
|
1078 |
'hello' copy byteAt:1 put:72; yourself |
|
1079 |
'hello' copy byteAt:1 put:0; yourself |
|
1080 |
" |
|
1081 |
||
1082 |
"Modified: 6.5.1996 / 10:35:26 / cg" |
|
1083 |
! |
|
608 | 1084 |
|
19497 | 1085 |
equalsIgnoreCase:aString |
1086 |
"This is an ST/V compatibility method and an alias for sameAs:." |
|
1087 |
||
1088 |
^ self sameAs:aString |
|
1089 |
||
1090 |
" |
|
1091 |
'abc' equalsIgnoreCase: 'aBC' |
|
1092 |
" |
|
1093 |
! |
|
1094 |
||
608 | 1095 |
replChar:oldChar with:newChar |
19497 | 1096 |
"return a copy of the receiver, with all oldChars replaced by newChar. |
1097 |
This is an ST/V compatibility method and an alias for copyReplaceAll." |
|
608 | 1098 |
|
3656 | 1099 |
^ self copyReplaceAll:oldChar with:newChar |
608 | 1100 |
|
1101 |
" |
|
8874 | 1102 |
'12345678901234567890' replChar:$0 with:$* |
608 | 1103 |
" |
3656 | 1104 |
|
1105 |
"Modified: / 18.7.1998 / 22:52:57 / cg" |
|
608 | 1106 |
! |
1107 |
||
1108 |
replChar:oldChar withString:newString |
|
1109 |
"return a copy of the receiver, with all oldChars replaced |
|
1110 |
by newString (i.e. slice in the newString in place of the oldChar). |
|
1111 |
This is an ST/V compatibility method." |
|
1112 |
||
1113 |
|tmpStream| |
|
1114 |
||
15523 | 1115 |
tmpStream := self species writeStream. |
608 | 1116 |
self do:[:element | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1117 |
element = oldChar ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1118 |
tmpStream nextPutAll:newString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1119 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1120 |
tmpStream nextPut:element |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1121 |
]. |
608 | 1122 |
]. |
1123 |
^ tmpStream contents |
|
1124 |
||
1125 |
" |
|
8874 | 1126 |
'12345678901234567890' replChar:$0 withString:'foo' |
1127 |
'a string with spaces' replChar:$ withString:' foo ' |
|
608 | 1128 |
" |
9192 | 1129 |
! |
1130 |
||
1131 |
replString:subString withString:newString |
|
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
1132 |
"return a copy of the receiver, with all sequences of subString replaced |
18390 | 1133 |
by newString (i.e. slice in the newString in place of the oldString). |
19497 | 1134 |
This is an ST/V compatibility method and an alias for copyReplaceString." |
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
1135 |
|
8347 | 1136 |
^ self copyReplaceString:subString withString:newString |
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
1137 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
1138 |
" |
8874 | 1139 |
'12345678901234567890' replString:'123' withString:'OneTwoThree' |
1140 |
'12345678901234567890' replString:'123' withString:'*' |
|
1141 |
'12345678901234567890' replString:'234' withString:'foo' |
|
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
1142 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
1143 |
('a string with spaces' replChar:$ withString:' foo ') |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
1144 |
replString:'foo' withString:'bar' |
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
1145 |
" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
1146 |
|
8347 | 1147 |
"Modified: / 12-05-2004 / 12:00:27 / cg" |
9192 | 1148 |
! |
1149 |
||
9275 | 1150 |
subString:start to:end |
18390 | 1151 |
"same as copyFrom:to: |
19497 | 1152 |
This is an ST/V compatibility method and an alias for copyFrom:to:." |
18390 | 1153 |
|
9275 | 1154 |
^ self copyFrom:start to:end |
1155 |
||
1156 |
" |
|
1157 |
'12345678901234567890' subString:3 to:8 |
|
1158 |
" |
|
1159 |
! |
|
1160 |
||
9192 | 1161 |
trimBlanks |
14992 | 1162 |
"return a copy of the receiver without leading and trailing spaces. |
18464 | 1163 |
This is an ST/V compatibility method and an alias for withoutSpaces." |
9192 | 1164 |
|
1165 |
^ self withoutSpaces |
|
1166 |
||
1167 |
" |
|
1168 |
' spaces at beginning' trimBlanks |
|
1169 |
'spaces at end ' trimBlanks |
|
1170 |
' spaces at beginning and end ' trimBlanks |
|
1171 |
'no spaces' trimBlanks |
|
1172 |
" |
|
1173 |
! ! |
|
1174 |
||
1175 |
!CharacterArray methodsFor:'Compatibility-Squeak'! |
|
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
1176 |
|
19171 | 1177 |
asBoldText |
1178 |
"return self as a bold text" |
|
1179 |
||
1180 |
^Text string: self emphasis: #bold |
|
1181 |
! |
|
1182 |
||
6148 | 1183 |
asDate |
1184 |
"Many allowed forms, see Date.readFrom:" |
|
1185 |
||
1186 |
^ Date readFrom: (ReadStream on: self) |
|
1187 |
||
1188 |
" |
|
8874 | 1189 |
'30 Apr 1999' asDate dayName capitalized |
6148 | 1190 |
" |
1191 |
! |
|
1192 |
||
16051 | 1193 |
asOneByteString |
1194 |
"return the receiver converted to a 'normal' string. |
|
18391 | 1195 |
Same as asSingleByteString - for Squeak/Pharo compatibility." |
16051 | 1196 |
|
1197 |
^ self asSingleByteString |
|
1198 |
! |
|
1199 |
||
8971 | 1200 |
asUrl |
18391 | 1201 |
"Same as asURL - for Squeak/Pharo compatibility." |
1202 |
||
8971 | 1203 |
^ self asURL |
1204 |
! |
|
1205 |
||
10840 | 1206 |
asWideString |
18391 | 1207 |
"return a two-byte string containing the same characters as the receiver. |
1208 |
Same as asTwoByteString - for Squeak/Pharo compatibility." |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1209 |
|
10840 | 1210 |
^ self asTwoByteString |
1211 |
||
1212 |
" |
|
1213 |
'abc' asWideString |
|
1214 |
" |
|
1215 |
! |
|
1216 |
||
4989 | 1217 |
capitalized |
18391 | 1218 |
"same as asUppercaseFirst for Squeak/Pharo compatibility" |
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1219 |
|
4989 | 1220 |
^ self asUppercaseFirst |
1221 |
||
1222 |
" |
|
1223 |
'hello' capitalized |
|
1224 |
" |
|
1225 |
! |
|
1226 |
||
10841 | 1227 |
caseInsensitiveLessOrEqual:aString |
18391 | 1228 |
"compare the receiver against the argument ignoring case differences |
1229 |
For Squeak/Pharo compatibility" |
|
1230 |
||
10841 | 1231 |
^ (self compareCaselessWith:aString) <= 0 |
1232 |
! |
|
1233 |
||
1234 |
caseSensitiveLessOrEqual:aString |
|
18391 | 1235 |
"compare the receiver against the argument caring for case differences |
1236 |
For Squeak/Pharo compatibility" |
|
1237 |
||
10841 | 1238 |
^ self <= aString |
1239 |
! |
|
1240 |
||
1241 |
charactersExactlyMatching:aString |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1242 |
"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
|
1243 |
|
10841 | 1244 |
|idx nMax| |
1245 |
||
1246 |
nMax :=(self size) min:(aString size). |
|
1247 |
idx := 1. |
|
1248 |
[idx <= nMax] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1249 |
(self at:idx) = (aString at:idx) ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1250 |
^ idx - 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1251 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1252 |
idx := idx + 1. |
10841 | 1253 |
]. |
1254 |
^ nMax |
|
1255 |
||
1256 |
" |
|
12177 | 1257 |
'abc' charactersExactlyMatching:'abc' |
1258 |
'abc' charactersExactlyMatching:'abcd' |
|
1259 |
'abcd' charactersExactlyMatching:'abc' |
|
1260 |
'abc' charactersExactlyMatching:'abd' |
|
1261 |
'abc' charactersExactlyMatching:'xxx' |
|
10841 | 1262 |
" |
1263 |
! |
|
1264 |
||
9192 | 1265 |
endsWithDigit |
1266 |
"Answer whether the receiver's final character represents a digit. 3/11/96 sw" |
|
1267 |
||
18391 | 1268 |
|len| |
1269 |
||
1270 |
^ (len := self size) > 0 and: [(self at:len) isDigit] |
|
9192 | 1271 |
! |
1272 |
||
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1273 |
findDelimiters:delimiters startingAt:start |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
1274 |
"Answer the index of the character within the receiver, starting at start, |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
1275 |
that matches one of the delimiters. |
18391 | 1276 |
If the receiver does not contain any of the delimiters, answer size + 1." |
9192 | 1277 |
|
1278 |
|idx| |
|
1279 |
||
1280 |
idx := self indexOfAny:delimiters startingAt:start. |
|
1281 |
idx == 0 ifTrue:[^ self size + 1]. |
|
1282 |
^ idx. |
|
1283 |
"/start to: self size do: [:i | |
|
1284 |
"/ |char| |
|
1285 |
"/ |
|
1286 |
"/ char := self at: i. |
|
1287 |
"/ delimiters do: [:delim | delim = char ifTrue: [^ i]] |
|
8971 | 1288 |
"/ ]. |
1289 |
"/ ^ self size + 1 |
|
1290 |
! |
|
1291 |
||
13624 | 1292 |
findTokens:delimiterOrDelimiters |
7270 | 1293 |
"cg: I am not sure, if this is really the squeak semantics (w.r.t. empty fields)" |
1294 |
||
13624 | 1295 |
delimiterOrDelimiters size == 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1296 |
^ self asCollectionOfSubstringsSeparatedBy:delimiterOrDelimiters |
13624 | 1297 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1298 |
^ self asCollectionOfSubstringsSeparatedByAny:delimiterOrDelimiters |
13624 | 1299 |
]. |
7270 | 1300 |
|
1301 |
" |
|
8874 | 1302 |
'a|b#c||e' findTokens:#($# $|) |
13624 | 1303 |
'a|b#c||e' findTokens:$| |
1304 |
" |
|
1305 |
||
1306 |
"Modified: / 04-09-2011 / 20:31:21 / cg" |
|
1307 |
"Modified (comment): / 05-09-2011 / 04:25:28 / cg" |
|
4981 | 1308 |
! |
1309 |
||
4974 | 1310 |
includesSubString:aString |
1311 |
"return true, if a substring is contained in the receiver. |
|
1312 |
The compare is case sensitive." |
|
1313 |
||
1314 |
^ self includesString:aString |
|
1315 |
||
1316 |
" |
|
8874 | 1317 |
'hello world' includesSubString:'Hel' |
9192 | 1318 |
'hello world' includesSubString:'hel' |
1319 |
'hello world' includesSubString:'llo' |
|
1320 |
" |
|
1321 |
||
1322 |
||
1323 |
||
1324 |
! |
|
1325 |
||
11178 | 1326 |
includesSubString:aString caseSensitive:caseSensitive |
18391 | 1327 |
"sigh - an alias; added for Squeak/Pharo compatibility" |
1328 |
||
11179 | 1329 |
^ self includesSubstring:aString caseSensitive:caseSensitive |
11178 | 1330 |
! |
1331 |
||
16875
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1332 |
includesSubstring: aString |
18391 | 1333 |
"sigh - an alias; added for Squeak/Pharo compatibility" |
1334 |
||
16875
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1335 |
^ self includesSubString: aString |
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1336 |
|
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1337 |
"Created: / 03-10-2014 / 02:47:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1338 |
! |
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1339 |
|
9192 | 1340 |
includesSubstring:aString caseSensitive:caseSensitive |
9190 | 1341 |
"return true, if a substring is contained in the receiver. |
9192 | 1342 |
The argument, caseSensitive controls if case is ignored in the compare." |
1343 |
||
1344 |
"/ for now, a q&d hack ... |
|
1345 |
||
1346 |
caseSensitive ifFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1347 |
^ self asLowercase includesString:aString asLowercase |
9192 | 1348 |
]. |
9190 | 1349 |
^ self includesString:aString |
1350 |
||
1351 |
" |
|
9192 | 1352 |
'hello world' includesSubstring:'Hel' caseSensitive:true |
1353 |
'hello world' includesSubstring:'Hel' caseSensitive:false |
|
1354 |
" |
|
1355 |
||
1356 |
||
1357 |
||
1358 |
! |
|
9190 | 1359 |
|
6979 | 1360 |
isAllDigits |
1361 |
"Answer whether the receiver's characters are all digits" |
|
1362 |
||
1363 |
^ self conform:[:eachChar | eachChar isDigit] |
|
1364 |
||
1365 |
" |
|
1366 |
'hello world' isAllDigits |
|
1367 |
'12344' isAllDigits |
|
1368 |
" |
|
1369 |
! |
|
1370 |
||
4890 | 1371 |
lastSpacePosition |
18391 | 1372 |
"return the index of the last space character; 0 if there is none. |
1373 |
Added for Squeak/Pharo compatibility" |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1374 |
|
4890 | 1375 |
^ self lastIndexOfSeparator |
1376 |
! |
|
1377 |
||
7022 | 1378 |
padded:leftOrRight to:paddedSize with:padCharacter |
14053
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1379 |
"pad left (leftOrRight==#left) or right" |
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1380 |
|
7022 | 1381 |
leftOrRight == #left ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1382 |
^ self leftPaddedTo:paddedSize with:padCharacter |
9190 | 1383 |
]. |
1384 |
^ self paddedTo:paddedSize with:padCharacter |
|
1385 |
||
1386 |
" |
|
8874 | 1387 |
'hello' padded:#right to:10 with:$. |
9192 | 1388 |
'hello' padded:#left to:10 with:$. |
1389 |
" |
|
14053
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1390 |
|
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1391 |
"Modified (comment): / 07-03-2012 / 16:31:33 / cg" |
9192 | 1392 |
! |
1393 |
||
1394 |
skipDelimiters:delimiters startingAt:start |
|
1395 |
"Answer the index of the character within the receiver, starting at start, |
|
1396 |
that does NOT match one of the delimiters. |
|
1397 |
If the receiver does not contain any of the delimiters, answer size + 1. |
|
1398 |
Assumes the delimiters to be a non-empty string." |
|
1399 |
||
1400 |
start to:self size do:[:i | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1401 |
delimiters detect:[:delim | delim = (self at:i) ] ifNone:[ ^ i ] |
9192 | 1402 |
]. |
1403 |
^ self size + 1 |
|
1404 |
||
1405 |
" |
|
1406 |
'123***7890' skipDelimiters:'*' startingAt:4 |
|
1407 |
'123***7890' skipDelimiters:'*' startingAt:3 |
|
9190 | 1408 |
'123***7890' skipDelimiters:'*' startingAt:10 |
1409 |
'123*******' skipDelimiters:'*' startingAt:10 |
|
8874 | 1410 |
" |
1411 |
! |
|
1412 |
||
9190 | 1413 |
substrings |
18921 | 1414 |
"return a collection consisting of all words contained in the receiver. |
17517 | 1415 |
Words are separated by whitespace. |
1416 |
This has been added for Squeak compatibility. |
|
1417 |
(sigh: it is called #'subStrings' in V'Age, and #'asCollectionOfWords' in ST/X) " |
|
1418 |
||
9190 | 1419 |
^ self asCollectionOfWords |
1420 |
||
1421 |
" |
|
1422 |
'foo bar baz' substrings |
|
1423 |
" |
|
1424 |
! |
|
1425 |
||
12665
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1426 |
substringsSeparatedBy:separatorCharacter |
18921 | 1427 |
"return a collection consisting of all words contained in the receiver. |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
1428 |
Words are separated by the given separator character. |
18921 | 1429 |
This has been added for Squeak/Pharo compatibility. |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
1430 |
(sigh: it is called #'subStrings:' in V'Age, |
18921 | 1431 |
and #'asCollectionOfSubstringsSeparatedBy' in ST/X) " |
18391 | 1432 |
|
12665
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1433 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1434 |
|
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1435 |
" |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1436 |
'foo bar, baz' substringsSeparatedBy:$, |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1437 |
" |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1438 |
! |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1439 |
|
9190 | 1440 |
truncateTo:smallSize |
9192 | 1441 |
"return myself or a copy shortened to smallSize. 1/18/96 sw" |
1442 |
||
1443 |
self size <= smallSize ifTrue:[^ self]. |
|
1444 |
^ self copyFrom: 1 to: smallSize |
|
1445 |
||
1446 |
" |
|
1447 |
'hello world' truncateTo:5 |
|
1448 |
'hello' truncateTo:10 |
|
1449 |
||
1450 |
'hello world' copyTo:5 |
|
1451 |
'hello' copyTo:10 |
|
1452 |
" |
|
1453 |
! |
|
5795 | 1454 |
|
4890 | 1455 |
withBlanksTrimmed |
18464 | 1456 |
"Return a copy of the receiver from which leading and trailing whitespace have been trimmed. |
1457 |
Notice the bad naming - it is trimming separators, not just blanks. |
|
1458 |
Added for Squeak compatibility and an alias for withoutSeparators" |
|
4890 | 1459 |
|
14865 | 1460 |
^ self withoutSeparators "withoutSpaces" "/ cg: it seems that squeak cares for any whitespace |
4890 | 1461 |
|
1462 |
" |
|
8874 | 1463 |
' hello world ' withBlanksTrimmed |
4890 | 1464 |
" |
1465 |
! |
|
1466 |
||
1467 |
withNoLineLongerThan: aNumber |
|
1468 |
"Answer a string with the same content as receiver, but rewrapped so that no line has more characters than the given number" |
|
1469 |
||
9192 | 1470 |
| listOfLines currentLast currentStart resultString putativeLast putativeLine crPosition | |
1471 |
||
14451
c06e7885b675
changed: #withNoLineLongerThan:
Claus Gittinger <cg@exept.de>
parents:
14420
diff
changeset
|
1472 |
(aNumber isNumber not or:[ aNumber < 1] ) ifTrue: [self error: 'too narrow']. |
9192 | 1473 |
listOfLines _ OrderedCollection new. |
1474 |
currentLast _ 0. |
|
1475 |
[currentLast < self size] whileTrue: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1476 |
[currentStart _ currentLast + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1477 |
putativeLast _ (currentStart + aNumber - 1) min: self size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1478 |
putativeLine _ self copyFrom: currentStart to: putativeLast. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1479 |
(crPosition _ putativeLine indexOf: Character cr) > 0 ifTrue: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1480 |
[putativeLast _ currentStart + crPosition - 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1481 |
putativeLine _ self copyFrom: currentStart to: putativeLast]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1482 |
currentLast _ putativeLast == self size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1483 |
ifTrue: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1484 |
[putativeLast] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1485 |
ifFalse: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1486 |
[currentStart + putativeLine lastSpacePosition - 1]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1487 |
currentLast <= currentStart ifTrue: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1488 |
["line has NO spaces; baleout!!" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1489 |
currentLast _ putativeLast]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1490 |
listOfLines add: (self copyFrom: currentStart to: currentLast) withBlanksTrimmed]. |
9192 | 1491 |
|
1492 |
listOfLines size > 0 ifFalse: [^ '']. |
|
1493 |
resultString _ listOfLines first. |
|
1494 |
2 to: listOfLines size do: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1495 |
[:i | resultString _ resultString, Character cr asString, (listOfLines at: i)]. |
9192 | 1496 |
^ resultString |
1497 |
||
1498 |
" |
|
1499 |
#(5 7 20) collect: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1500 |
[:i | 'Fred the bear went down to the brook to read his book in silence' withNoLineLongerThan: i] |
14451
c06e7885b675
changed: #withNoLineLongerThan:
Claus Gittinger <cg@exept.de>
parents:
14420
diff
changeset
|
1501 |
" |
10883 | 1502 |
! |
1503 |
||
12343
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1504 |
withSqueakLineEndings |
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1505 |
"assume the string is textual, and that CR, LF, and CRLF are all |
18391 | 1506 |
valid line endings. Replace each occurence with a single CR" |
12343
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1507 |
|
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1508 |
^ self asStringCollection asStringWith:Character cr. |
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1509 |
! |
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1510 |
|
12188 | 1511 |
withoutLeading: char |
1512 |
"return a copy of myself without leading a char. |
|
1513 |
Returns an empty string, if the receiver consist only of a char." |
|
1514 |
||
1515 |
^ self withoutLeadingForWhich:[:ch | ch = char] |
|
1516 |
||
1517 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1518 |
'****foo****' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1519 |
'foo****' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1520 |
'*' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1521 |
'' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1522 |
'****foo' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1523 |
'*******' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1524 |
'foo' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1525 |
'f***o***o' withoutLeading: $* |
12188 | 1526 |
('**' , Character tab asString , '*foo***') withoutLeading: $* inspect |
1527 |
" |
|
1528 |
! |
|
1529 |
||
11565 | 1530 |
withoutTrailing:char |
1531 |
"return a copy of myself without trailing char. |
|
1532 |
Returns an empty string, if the receiver consist only of char." |
|
1533 |
||
12188 | 1534 |
^ self withoutTrailingForWhich:[:ch | ch = char] |
1535 |
||
1536 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1537 |
' foo....' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1538 |
'foo....' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1539 |
' foo' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1540 |
'.......' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1541 |
'foo' withoutTrailing:$. |
11565 | 1542 |
" |
9190 | 1543 |
! ! |
1544 |
||
1545 |
!CharacterArray methodsFor:'Compatibility-V''Age'! |
|
1546 |
||
1547 |
addLineDelimiter |
|
1548 |
"replace all '\'-characters by line delimiter (cr) - characters. |
|
9192 | 1549 |
This has been added for VisualAge compatibility." |
1550 |
||
1551 |
^ self withCRs |
|
1552 |
! |
|
1553 |
||
1554 |
bindWith:aString |
|
1555 |
"return a copy of the receiver, where a '%1' escape is |
|
1556 |
replaced by aString. |
|
1557 |
This has been added for VisualAge compatibility." |
|
1558 |
||
1559 |
^ self expandPlaceholdersWith:(Array with:aString) |
|
1560 |
||
1561 |
" |
|
1562 |
'do you like %1 ?' bindWith:'smalltalk' |
|
19785 | 1563 |
'do you like %(foo) ?' bindWithArguments:(Dictionary new at:'foo' put:'smalltalk'; yourself) |
9192 | 1564 |
" |
1565 |
! |
|
608 | 1566 |
|
1567 |
bindWith:string1 with:string2 |
|
1568 |
"return a copy of the receiver, where a '%1' escape is |
|
1569 |
replaced by string1 and '%2' is replaced by string2. |
|
1570 |
This has been added for VisualAge compatibility." |
|
1571 |
||
1572 |
^ self expandPlaceholdersWith:(Array with:string1 with:string2) |
|
1573 |
||
1574 |
" |
|
1575 |
'do you prefer %1 or rather %2 ?' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1576 |
bindWith:'smalltalk' with:'c++' |
9192 | 1577 |
" |
1578 |
! |
|
9190 | 1579 |
|
1580 |
bindWith:str1 with:str2 with:str3 |
|
608 | 1581 |
"return a copy of the receiver, where a '%1', '%2' and '%3' escapes |
1582 |
are replaced by str1, str2 and str3 respectively. |
|
1583 |
This has been added for VisualAge compatibility." |
|
1584 |
||
1585 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3) |
|
1586 |
||
1587 |
" |
|
9192 | 1588 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1589 |
bindWith:'smalltalk' with:'c++' with:'c' |
9192 | 1590 |
" |
1591 |
! |
|
608 | 1592 |
|
1593 |
bindWith:str1 with:str2 with:str3 with:str4 |
|
1594 |
"return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes |
|
1595 |
are replaced by str1, str2, str3 and str4 respectively. |
|
1596 |
This has been added for VisualAge compatibility." |
|
1597 |
||
1598 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4) |
|
1599 |
||
1600 |
" |
|
9192 | 1601 |
'do you prefer %1 or rather %2 (not talking about %3 or even %4) ?' |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1602 |
bindWith:'smalltalk' with:'c++' with:'c' with:'assembler' |
9192 | 1603 |
" |
1604 |
! |
|
608 | 1605 |
|
2344 | 1606 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 |
1607 |
"return a copy of the receiver, where a '%1' .. '%5' escapes |
|
1608 |
are replaced by str1 .. str5 respectively. |
|
1609 |
This has been added for VisualAge compatibility." |
|
1610 |
||
1611 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5) |
|
1612 |
||
1613 |
"Created: 31.1.1997 / 16:25:42 / cg" |
|
1614 |
! |
|
1615 |
||
5343 | 1616 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 |
1617 |
"return a copy of the receiver, where a '%1' .. '%6' escapes |
|
11524 | 1618 |
are replaced by str1 .. str6 respectively. |
5343 | 1619 |
This has been added for VisualAge compatibility." |
1620 |
||
8874 | 1621 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1622 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1623 |
with:str5 with:str6) |
11524 | 1624 |
! |
1625 |
||
1626 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 with:str7 |
|
1627 |
"return a copy of the receiver, where a '%1' .. '%7' escapes |
|
1628 |
are replaced by str1 .. str7 respectively. |
|
1629 |
This has been added for VisualAge compatibility." |
|
1630 |
||
1631 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1632 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1633 |
with:str5 with:str6 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1634 |
with:str7) |
5343 | 1635 |
! |
1636 |
||
13996
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1637 |
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
|
1638 |
"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
|
1639 |
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
|
1640 |
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
|
1641 |
|
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1642 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1643 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1644 |
with:str5 with:str6 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1645 |
with:str7 with:str8) |
13996
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1646 |
|
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1647 |
"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
|
1648 |
! |
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1649 |
|
14014
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1650 |
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
|
1651 |
"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
|
1652 |
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
|
1653 |
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
|
1654 |
|
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1655 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1656 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1657 |
with:str5 with:str6 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1658 |
with:str7 with:str8 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1659 |
with:str9) |
14014
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1660 |
|
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1661 |
"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
|
1662 |
! |
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1663 |
|
608 | 1664 |
bindWithArguments:anArrayOfStrings |
1665 |
"return a copy of the receiver, where a '%i' escape |
|
1666 |
is replaced by the coresponding string from the argument array. |
|
1667 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
1668 |
This has been added for VisualAge compatibility." |
|
1669 |
||
9192 | 1670 |
^ self expandPlaceholdersWith:anArrayOfStrings |
1671 |
||
1672 |
" |
|
1673 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1674 |
bindWithArguments:#('smalltalk' 'c++' 'c') |
12196 | 1675 |
|
1676 |
'do you %(what) ?' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1677 |
bindWithArguments:(Dictionary new at:#'what' put:'understand'; yourself) |
9192 | 1678 |
" |
1679 |
! |
|
608 | 1680 |
|
1681 |
subStrings |
|
18921 | 1682 |
"return a collection consisting of all words contained in the receiver. |
608 | 1683 |
Words are separated by whitespace. |
17517 | 1684 |
This has been added for VisualAge compatibility. |
1685 |
(sigh: it is called #'subbtrings' in Squeak, and #'asCollectionOfWords' in ST/X) " |
|
608 | 1686 |
|
1687 |
^ self asCollectionOfWords |
|
1688 |
||
1689 |
" |
|
1690 |
'hello world, this is smalltalk' subStrings |
|
1691 |
" |
|
1692 |
! |
|
1693 |
||
16181 | 1694 |
subStrings:separatorCharacterOrString |
18921 | 1695 |
"return a collection consisting of all words contained in the receiver. |
608 | 1696 |
Words are separated by separatorCharacter. |
18921 | 1697 |
This is similar to split: (squeak) and asCollectionOfSubstringsSeparatedBy: (st/x) |
1698 |
and has been added for VisualAge compatibility." |
|
608 | 1699 |
|
16181 | 1700 |
separatorCharacterOrString isCharacter ifTrue:[ |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
1701 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacterOrString |
16181 | 1702 |
]. |
1703 |
^ self asCollectionOfSubstringsSeparatedByAny:separatorCharacterOrString |
|
1704 |
||
1705 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1706 |
'foo:bar:baz:smalltalk' subStrings:$: |
16181 | 1707 |
'foo:bar:baz:smalltalk' subStrings:':' |
1708 |
'foo.bar,baz-smalltalk' subStrings:'.,-' |
|
9192 | 1709 |
" |
1710 |
! |
|
1711 |
||
1712 |
trimSeparators |
|
18392 | 1713 |
"return a copy of the receiver without leading and trailing whiteSpace. |
18921 | 1714 |
Added for VisualAge compatibility (an alias for withoutSeparators)" |
9192 | 1715 |
|
1716 |
^ self withoutSeparators |
|
1717 |
! ! |
|
1718 |
||
1719 |
!CharacterArray methodsFor:'Compatibility-VW'! |
|
5964 | 1720 |
|
6139 | 1721 |
asLogicalFileSpecification |
1722 |
^ self asFilename |
|
1723 |
||
1724 |
"Created: / 30.10.2001 / 17:29:53 / cg" |
|
1725 |
! |
|
1726 |
||
5964 | 1727 |
expandMacros |
1728 |
"ST80 compatibility - expand '<..>' macros with |
|
1729 |
argument strings. Similar to #bindWith:. |
|
1730 |
Read the comment in #expandMacrosWithArguments: about |
|
1731 |
limited compatibility issues." |
|
1732 |
||
1733 |
^ self expandMacrosWithArguments:#() |
|
1734 |
||
1735 |
" |
|
1736 |
'hello<n>foo' expandMacros |
|
1737 |
" |
|
1738 |
||
9192 | 1739 |
"Modified: / 18.6.1998 / 16:03:02 / cg" |
1740 |
! |
|
1741 |
||
1742 |
expandMacrosWith:arg |
|
5964 | 1743 |
"ST80 compatibility - expand '<..>' macros with |
1744 |
argument strings. Similar to #bindWith:. |
|
1745 |
Read the comment in #expandMacrosWithArguments: about |
|
1746 |
limited compatibility issues." |
|
1747 |
||
9192 | 1748 |
^ self expandMacrosWithArguments:(Array with:arg) |
1749 |
||
1750 |
"Created: / 1.11.1997 / 13:01:28 / cg" |
|
1751 |
"Modified: / 1.11.1997 / 13:30:50 / cg" |
|
1752 |
! |
|
5964 | 1753 |
|
1754 |
expandMacrosWith:arg1 with:arg2 |
|
1755 |
"ST80 compatibility - expand '<..>' macros with |
|
1756 |
argument strings. Similar to #bindWith:. |
|
1757 |
Read the comment in #expandMacrosWithArguments: about |
|
1758 |
limited compatibility issues." |
|
1759 |
||
1760 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2) |
|
1761 |
||
1762 |
"Modified: / 6.7.1998 / 21:58:14 / cg" |
|
1763 |
! |
|
1764 |
||
1765 |
expandMacrosWith:arg1 with:arg2 with:arg3 |
|
1766 |
"ST80 compatibility - expand '<..>' macros with |
|
1767 |
argument strings. Similar to #bindWith:. |
|
1768 |
Read the comment in #expandMacrosWithArguments: about |
|
1769 |
limited compatibility issues." |
|
1770 |
||
1771 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2 with:arg3) |
|
1772 |
! |
|
1773 |
||
10353
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1774 |
expandMacrosWith:arg1 with:arg2 with:arg3 with:arg4 |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1775 |
"ST80 compatibility - expand '<..>' macros with |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1776 |
argument strings. Similar to #bindWith:. |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1777 |
Read the comment in #expandMacrosWithArguments: about |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1778 |
limited compatibility issues." |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1779 |
|
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1780 |
^ 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
|
1781 |
! |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1782 |
|
9192 | 1783 |
expandMacrosWithArguments:argArray |
5964 | 1784 |
"ST80 compatibility - expand '<..>' macros with |
1785 |
argument strings. Similar to #bindWith:. |
|
1786 |
WARNING: possibly not all ST80 expansions are supported here." |
|
1787 |
||
1788 |
"/ supported expansions: |
|
1789 |
"/ |
|
1790 |
"/ <#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
|
1791 |
"/ <#s> # is arg Number; slice in the arg itself (must know asString) |
5964 | 1792 |
"/ <#?s1:s2> # is arg Number; slice in s1 if the arg is true, s2 otherwise |
7643 | 1793 |
"/ use first arg if # is not given (i.e. no number before s,p ...) |
5964 | 1794 |
"/ <n> replace by a newLine character |
1795 |
"/ <t> replace by a tab character |
|
6834
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
1796 |
"/ %X the X character itself |
5964 | 1797 |
|
8999
f3fda66ea51e
#expandMacrosWithArguments: - be mor friendly to xml strings.
Stefan Vogel <sv@exept.de>
parents:
8971
diff
changeset
|
1798 |
|in out c fmt nr arg s1 s2 peekc| |
5964 | 1799 |
|
1800 |
in := self readStream. |
|
10721
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1801 |
out := CharacterWriteStream on:(self species uninitializedNew:self size). |
5964 | 1802 |
|
1803 |
[in atEnd] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1804 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1805 |
c == $% ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1806 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1807 |
out nextPut:c |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1808 |
] ifFalse:[c ~~ $< ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1809 |
out nextPut:c. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1810 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1811 |
peekc := in peek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1812 |
[peekc == $<] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1813 |
out nextPut:$<. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1814 |
peekc := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1815 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1816 |
peekc == $n ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1817 |
peekc := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1818 |
peekc == $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1819 |
in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1820 |
out cr. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1821 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1822 |
out nextPutAll:'<n'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1823 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1824 |
] ifFalse:[peekc == $t ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1825 |
peekc := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1826 |
peekc == $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1827 |
in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1828 |
out tab. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1829 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1830 |
out nextPutAll:'<t'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1831 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1832 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1833 |
peekc isDigit ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1834 |
"start an argument expansion ..." |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1835 |
nr := Integer readFrom:in onError:nil. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1836 |
nr isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1837 |
"this cannot happen (there is at least one digit)" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1838 |
self error:'invalid format' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1839 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1840 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1841 |
fmt := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1842 |
(fmt ~~ $? and:[in peek ~~ $>]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1843 |
out nextPut:$<. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1844 |
nr printOn:out. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1845 |
out nextPut:fmt. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1846 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1847 |
(nr between:1 and:argArray size) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1848 |
arg := argArray at:nr. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1849 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1850 |
arg := '' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1851 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1852 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1853 |
fmt == $p ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1854 |
"expand with args printString" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1855 |
arg printOn:out. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1856 |
] ifFalse:[fmt == $s ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1857 |
"expand with arg itself" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1858 |
arg isText ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1859 |
out contentsSpecies isText ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1860 |
out := (TextStream ? CharacterWriteStream on:Text new) nextPutAll:out contents; yourself. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1861 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1862 |
out nextPutAll:arg. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1863 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1864 |
out nextPutAll:arg asString string. "see method comment: arg must know #asString" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1865 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1866 |
] ifFalse:[fmt == $? ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1867 |
s1 := in upTo:$:. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1868 |
s2 := in nextUpTo:$>. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1869 |
arg == true ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1870 |
out nextPutAll:s1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1871 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1872 |
out nextPutAll:s2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1873 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1874 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1875 |
"what does VW do here ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1876 |
self error:'invalid format' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1877 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1878 |
]]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1879 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1880 |
c ~~ $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1881 |
"what does VW do here ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1882 |
self error:'invalid format' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1883 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1884 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1885 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1886 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1887 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1888 |
out nextPut:$<. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1889 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1890 |
]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1891 |
]]. |
5964 | 1892 |
]. |
1893 |
^ out contents |
|
1894 |
||
1895 |
" |
|
8874 | 1896 |
'hello <1s> how are you' expandMacrosWith:(OperatingSystem getLoginName) |
1897 |
'one plus one is <1p>' expandMacrosWith:2 |
|
5964 | 1898 |
" |
1899 |
||
10721
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1900 |
"Modified: / 18-09-2007 / 22:50:43 / cg" |
9192 | 1901 |
! |
1902 |
||
1903 |
isCharacters |
|
1904 |
"added for visual works compatibility" |
|
1905 |
^ true |
|
1906 |
! ! |
|
1907 |
||
16295 | 1908 |
!CharacterArray methodsFor:'JavaScript support'! |
1909 |
||
1910 |
unquote |
|
17000 | 1911 |
"removes double quotes from the receiver. |
19698 | 1912 |
This is the JavaScript standard unquote function." |
1913 |
||
1914 |
^ self unquote:$" |
|
16295 | 1915 |
|
1916 |
" |
|
17000 | 1917 |
'hello' quote unquote |
1918 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1919 |
JavaScriptParser evaluate:'''hello''.quote.unquote' |
16295 | 1920 |
" |
19698 | 1921 |
! |
1922 |
||
1923 |
unquote:quoteCharacter |
|
1924 |
"removes quoteCharacter from either end of the receiver." |
|
1925 |
||
1926 |
|mySize| |
|
1927 |
||
1928 |
(mySize := self size) >= 2 ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
1929 |
((self first == quoteCharacter) and:[self last == quoteCharacter]) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
1930 |
^ self copyFrom:2 to:mySize-1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
1931 |
]. |
19698 | 1932 |
]. |
1933 |
^ self |
|
1934 |
||
1935 |
" |
|
1936 |
'*hello*' unquote:$* |
|
1937 |
" |
|
16295 | 1938 |
! ! |
13510 | 1939 |
|
16175 | 1940 |
|
9192 | 1941 |
!CharacterArray methodsFor:'character searching'! |
1942 |
||
1943 |
includesMatchCharacters |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
1944 |
"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
|
1945 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1946 |
Here, do not care for $\ escapes" |
608 | 1947 |
|
1948 |
^ self includesAny:'*#[' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1949 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1950 |
" |
8874 | 1951 |
'*foo' includesMatchCharacters |
1952 |
'\*foo' includesMatchCharacters |
|
1953 |
'\*foo' includesUnescapedMatchCharacters |
|
1954 |
'*foo' includesMatchCharacters |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1955 |
'\\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1956 |
'foo*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1957 |
'foo\*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1958 |
'foo\' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1959 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1960 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1961 |
"Modified: 2.4.1997 / 18:12:34 / cg" |
9192 | 1962 |
! |
1963 |
||
1964 |
includesSeparator |
|
1965 |
"return true, if the receiver contains any whitespace characters" |
|
1966 |
||
1967 |
^ (self indexOfSeparator ~~ 0) |
|
1968 |
||
1969 |
" |
|
1970 |
'hello world' includesSeparator |
|
1971 |
'helloworld' includesSeparator |
|
1972 |
" |
|
1973 |
! |
|
1974 |
||
1975 |
includesUnescapedMatchCharacters |
|
8874 | 1976 |
"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
|
1977 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1978 |
Here, care for $\ escapes" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1979 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1980 |
|idx sz specialChars escape| |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1981 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1982 |
idx := 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1983 |
sz := self size. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1984 |
specialChars := '*#[\'. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1985 |
(escape := self class matchEscapeCharacter) ~~ $\ ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1986 |
specialChars := specialChars copy. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1987 |
specialChars at:specialChars size put:escape |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1988 |
]. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1989 |
|
16245 | 1990 |
[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1991 |
idx := self indexOfAny:specialChars startingAt:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1992 |
idx == 0 ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1993 |
(self at:idx) == escape ifFalse:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1994 |
idx := idx + 2. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1995 |
idx > sz ifTrue:[^ false]. |
16245 | 1996 |
] loop. |
8874 | 1997 |
|
1998 |
" |
|
1999 |
'*foo' includesUnescapedMatchCharacters |
|
2000 |
'\*foo' includesUnescapedMatchCharacters |
|
2001 |
'\\foo' includesUnescapedMatchCharacters |
|
2002 |
'\\\$foo' includesUnescapedMatchCharacters |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2003 |
'*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2004 |
'\\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2005 |
'foo*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2006 |
'foo\*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2007 |
'foo\' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2008 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2009 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2010 |
"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
|
2011 |
"Created: 2.4.1997 / 17:23:26 / cg" |
9192 | 2012 |
! |
2013 |
||
2014 |
indexOfControlCharacterStartingAt:startIndex |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2015 |
"return the index of the next control character; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2016 |
that is a character with asciiValue < 32. |
15605 | 2017 |
Start the search at startIndex, searching forward. |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2018 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2019 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2020 |
|start "{ Class: SmallInteger }" |
9192 | 2021 |
mySize "{ Class: SmallInteger }"| |
2022 |
||
2023 |
start := startIndex. |
|
2024 |
mySize := self size. |
|
2025 |
||
2026 |
start to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2027 |
(self at:index) isControlCharacter ifTrue:[^ index] |
9192 | 2028 |
]. |
2029 |
^ 0 |
|
2030 |
||
2031 |
" |
|
2032 |
'hello world' asTwoByteString indexOfControlCharacterStartingAt:1 |
|
2033 |
'hello world\foo' withCRsasTwoByteString indexOfControlCharacterStartingAt:1 |
|
2034 |
" |
|
2035 |
||
2036 |
"Modified: / 21.7.1998 / 17:25:07 / cg" |
|
2037 |
! |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2038 |
|
8541 | 2039 |
indexOfNonSeparator |
2040 |
"return the index of the first non-whitespace character. |
|
2041 |
return 0 if no non-separator was found" |
|
2042 |
||
2043 |
^ self indexOfNonSeparatorStartingAt:1. |
|
2044 |
||
2045 |
" |
|
8874 | 2046 |
' hello world' indexOfNonSeparator |
2047 |
' ' indexOfNonSeparator |
|
2048 |
'a ' indexOfNonSeparator |
|
2049 |
'abc' indexOfNonSeparator |
|
2050 |
' ' indexOfNonSeparator |
|
9192 | 2051 |
'' indexOfNonSeparator |
2052 |
" |
|
2053 |
! |
|
2054 |
||
2055 |
indexOfNonSeparatorStartingAt:startIndex |
|
4117 | 2056 |
"return the index of the next non-whitespace character, |
2057 |
starting the search at startIndex, searching forward; |
|
2058 |
return 0 if no non-separator was found" |
|
608 | 2059 |
|
2060 |
|start "{ Class: SmallInteger }" |
|
2061 |
mySize "{ Class: SmallInteger }"| |
|
2062 |
||
2063 |
start := startIndex. |
|
2064 |
mySize := self size. |
|
2065 |
||
2066 |
start to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2067 |
(self at:index) isSeparator ifFalse:[^ index] |
608 | 2068 |
]. |
2069 |
^ 0 |
|
2070 |
||
2071 |
" |
|
8874 | 2072 |
' hello world' indexOfNonSeparatorStartingAt:1 |
2073 |
' ' indexOfNonSeparatorStartingAt:1 |
|
2074 |
'a ' indexOfNonSeparatorStartingAt:2 |
|
4117 | 2075 |
" |
2076 |
||
608 | 2077 |
" |
2078 |
|s index1 index2| |
|
2079 |
s := ' foo bar baz'. |
|
2080 |
index1 := s indexOfNonSeparatorStartingAt:1. |
|
2081 |
index2 := s indexOfSeparatorStartingAt:index1. |
|
2082 |
s copyFrom:index1 to:index2 - 1 |
|
2083 |
" |
|
9192 | 2084 |
! |
2085 |
||
2086 |
indexOfSeparator |
|
2087 |
"return the index of the first whitespace character; |
|
2088 |
starting the search at the beginning, searching forward; |
|
2089 |
return 0 if no separator was found" |
|
2090 |
||
2091 |
^ self indexOfSeparatorStartingAt:1 |
|
2092 |
||
2093 |
" |
|
2094 |
'hello world' indexOfSeparator |
|
2095 |
'helloworld' indexOfSeparator |
|
2096 |
'hello ' indexOfSeparator |
|
2097 |
' hello' indexOfSeparator |
|
2098 |
" |
|
2099 |
! |
|
2100 |
||
15912 | 2101 |
indexOfSeparatorOrEndStartingAt:startIndex |
2102 |
"return the index of the next whitespace character, |
|
2103 |
starting the search at startIndex, searching forward; |
|
19737 | 2104 |
return the index of one beyond the end of the receiver if no separator was found. |
15912 | 2105 |
To extract the word, copy from startIndex to the returned index-1" |
2106 |
||
2107 |
|idx| |
|
2108 |
||
2109 |
idx := self indexOfSeparatorStartingAt:startIndex. |
|
2110 |
idx == 0 ifTrue:[^ self size + 1]. |
|
2111 |
^ idx. |
|
2112 |
||
2113 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2114 |
'hello world' indexOfSeparatorOrEndStartingAt:3 |
15912 | 2115 |
' hello world' indexOfSeparatorOrEndStartingAt:3 |
2116 |
'hello world ' indexOfSeparatorOrEndStartingAt:3 |
|
2117 |
'hello world ' indexOfSeparatorOrEndStartingAt:6 |
|
2118 |
'hello world ' indexOfSeparatorOrEndStartingAt:7 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2119 |
'helloworld ' indexOfSeparatorOrEndStartingAt:7 |
15912 | 2120 |
'helloworld' indexOfSeparatorOrEndStartingAt:7 |
19737 | 2121 |
'helloworld' indexOfSeparatorStartingAt:7 |
15912 | 2122 |
" |
2123 |
! |
|
2124 |
||
9192 | 2125 |
indexOfSeparatorStartingAt:startIndex |
2126 |
"return the index of the next whitespace character, |
|
2127 |
starting the search at startIndex, searching forward; |
|
2128 |
return 0 if no separator was found" |
|
2129 |
||
2130 |
|start "{ Class: SmallInteger }" |
|
2131 |
mySize "{ Class: SmallInteger }"| |
|
2132 |
||
2133 |
start := startIndex. |
|
2134 |
mySize := self size. |
|
2135 |
||
2136 |
start to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2137 |
(self at:index) isSeparator ifTrue:[^ index] |
9192 | 2138 |
]. |
2139 |
^ 0 |
|
2140 |
||
2141 |
" |
|
2142 |
'hello world' indexOfSeparatorStartingAt:3 |
|
2143 |
' hello world' indexOfSeparatorStartingAt:3 |
|
8874 | 2144 |
'hello world ' indexOfSeparatorStartingAt:3 |
2145 |
'hello world ' indexOfSeparatorStartingAt:6 |
|
2146 |
'hello world ' indexOfSeparatorStartingAt:7 |
|
2147 |
'helloworld ' indexOfSeparatorStartingAt:7 |
|
2148 |
'helloworld' indexOfSeparatorStartingAt:7 |
|
4117 | 2149 |
" |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2150 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2151 |
|
4117 | 2152 |
lastIndexOfSeparator |
14150
e13160aa321a
comment/format in: #lastIndexOfSeparator
Claus Gittinger <cg@exept.de>
parents:
14141
diff
changeset
|
2153 |
"return the last index of a whitespace character (space or tab). |
4117 | 2154 |
(i.e. start the search at the end and search backwards); |
2155 |
Returns 0 if no separator is found." |
|
2156 |
||
2157 |
^ self lastIndexOfSeparatorStartingAt:(self size) |
|
2158 |
||
2159 |
" |
|
8874 | 2160 |
'hello world' lastIndexOfSeparator |
2161 |
'helloworld' lastIndexOfSeparator |
|
2162 |
'hel lo wor ld' lastIndexOfSeparator |
|
2163 |
'hel ' lastIndexOfSeparator 6 |
|
4117 | 2164 |
" |
14150
e13160aa321a
comment/format in: #lastIndexOfSeparator
Claus Gittinger <cg@exept.de>
parents:
14141
diff
changeset
|
2165 |
|
e13160aa321a
comment/format in: #lastIndexOfSeparator
Claus Gittinger <cg@exept.de>
parents:
14141
diff
changeset
|
2166 |
"Modified (comment): / 01-06-2012 / 13:10:30 / cg" |
4117 | 2167 |
! |
2168 |
||
2169 |
lastIndexOfSeparatorStartingAt:startIndex |
|
9192 | 2170 |
"return the index of the previous whitespace character, |
2171 |
starting the search at startIndex (and searching backwards); |
|
2172 |
returns 0 if no separator was found" |
|
2173 |
||
2174 |
|start "{ Class: SmallInteger }"| |
|
2175 |
||
2176 |
start := startIndex. |
|
2177 |
||
2178 |
start to:1 by:-1 do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2179 |
(self at:index) isSeparator ifTrue:[^ index] |
9192 | 2180 |
]. |
2181 |
^ 0 |
|
2182 |
||
2183 |
" |
|
2184 |
'hello world' lastIndexOfSeparatorStartingAt:3 |
|
2185 |
'hello world' lastIndexOfSeparatorStartingAt:7 |
|
2186 |
'helloworld' lastIndexOfSeparatorStartingAt:7 |
|
8874 | 2187 |
' helloworld' lastIndexOfSeparatorStartingAt:7 |
4117 | 2188 |
" |
608 | 2189 |
! ! |
2190 |
||
2191 |
!CharacterArray methodsFor:'comparing'! |
|
2192 |
||
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
2193 |
< aString |
608 | 2194 |
"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
|
2195 |
receiver is greater than the argument. Otherwise return false. |
8874 | 2196 |
This comparison is based on the elements ascii code - |
9192 | 2197 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
2198 |
||
2199 |
|mySize "{ Class: SmallInteger }" |
|
2200 |
otherSize "{ Class: SmallInteger }" |
|
2201 |
n "{ Class: SmallInteger }" |
|
2202 |
c1 c2| |
|
2203 |
||
2204 |
mySize := self size. |
|
2205 |
otherSize := aString string size. |
|
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
2206 |
n := mySize min:otherSize. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
2207 |
|
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
2208 |
1 to:n do:[:index | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2209 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2210 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2211 |
(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
|
2212 |
]. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
2213 |
^ mySize < otherSize |
608 | 2214 |
! |
2215 |
||
2216 |
= aString |
|
2217 |
"Compare the receiver with the argument and return true if the |
|
2218 |
receiver is equal to the argument. Otherwise return false. |
|
1252 | 2219 |
|
9191 | 2220 |
This compare does NOT ignore case differences, |
608 | 2221 |
therefore 'foo' = 'Foo' will return false. |
2222 |
Since this is incompatible to ST-80 (at least, V2.x) , this may change." |
|
2223 |
||
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
2224 |
|mySize "{ Class: SmallInteger }"| |
608 | 2225 |
|
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2226 |
(aString isString or:[aString species == self species]) ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2227 |
^ false |
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2228 |
]. |
608 | 2229 |
mySize := self size. |
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
2230 |
mySize ~~ (aString size) ifTrue:[^ false]. |
608 | 2231 |
|
2232 |
1 to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2233 |
(self at:index) = (aString at:index) ifFalse:[^ false]. |
608 | 2234 |
]. |
2235 |
^ true |
|
2236 |
||
2237 |
" |
|
8874 | 2238 |
'foo' = 'Foo' |
2239 |
'foo' = 'bar' |
|
2240 |
'foo' = 'foo' |
|
2241 |
'foo' = 'foo' asText |
|
2242 |
'foo' asText = 'foo' |
|
2243 |
'foo' asText = 'foo' asText |
|
608 | 2244 |
" |
1252 | 2245 |
|
2246 |
"Modified: 22.4.1996 / 15:53:58 / cg" |
|
608 | 2247 |
! |
9192 | 2248 |
|
9191 | 2249 |
> aString |
608 | 2250 |
"Compare the receiver with the argument and return true if the |
2251 |
receiver is greater than the argument. Otherwise return false. |
|
8874 | 2252 |
This comparison is based on the elements ascii code - |
1252 | 2253 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
608 | 2254 |
|
2255 |
|mySize "{ Class: SmallInteger }" |
|
8874 | 2256 |
otherSize "{ Class: SmallInteger }" |
9192 | 2257 |
n "{ Class: SmallInteger }" |
2258 |
c1 c2| |
|
2259 |
||
2260 |
mySize := self size. |
|
5929 | 2261 |
otherSize := aString string size. |
2262 |
n := mySize min:otherSize. |
|
2263 |
||
2264 |
1 to:n do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2265 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2266 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2267 |
(c1 == c2 or:[c1 = c2]) ifFalse:[^ c1 > c2]. |
5929 | 2268 |
]. |
9192 | 2269 |
^ mySize > otherSize |
2270 |
||
2271 |
"Modified: 22.4.1996 / 15:55:00 / cg" |
|
2272 |
! |
|
2273 |
||
14660 | 2274 |
after:aString |
2275 |
"Compare the receiver with the argument and return true if the |
|
2276 |
receiver should come after the argument in a sorted list. |
|
2277 |
Otherwise return false. |
|
2278 |
NOTE: The comparison should be language specific, depending on the value of |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2279 |
LC_COLLATE, which is initialized from the environment. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2280 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2281 |
Currently it is for Strings, but not for UnicodeStrings... |
14660 | 2282 |
|
2283 |
STUPID: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2284 |
#after has a completely different meaning in SeqColl ..." |
14660 | 2285 |
|
2286 |
^ (self compareCollatingWith:aString) > 0 |
|
2287 |
! |
|
2288 |
||
15814 | 2289 |
compareAsVersionNumberWith:aStringOrCollection |
2290 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2291 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
2292 |
Compare as version numbers in the form a.b.c... ." |
|
2293 |
||
2294 |
|rev1 rev2| |
|
2295 |
||
2296 |
rev1 := self asCollectionOfSubstringsSeparatedBy:$.. |
|
2297 |
aStringOrCollection isString ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2298 |
rev2 := aStringOrCollection asCollectionOfSubstringsSeparatedBy:$.. |
15814 | 2299 |
]. |
2300 |
rev1 := rev1 collect:[:each| each asInteger]. |
|
2301 |
rev2 := rev2 collect:[:each| each asInteger]. |
|
2302 |
||
2303 |
^ rev1 compareWith:rev2 |
|
2304 |
||
2305 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2306 |
self assert:('1' compareAsVersionNumberWith:'2') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2307 |
self assert:('2' compareAsVersionNumberWith:'1') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2308 |
self assert:('1.1' compareAsVersionNumberWith:'2.1.2') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2309 |
self assert:('2.1' compareAsVersionNumberWith:'1.2.3') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2310 |
self assert:('1' compareAsVersionNumberWith:'1.1') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2311 |
self assert:('1.1' compareAsVersionNumberWith:'1') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2312 |
self assert:('1.1' compareAsVersionNumberWith:'1.2') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2313 |
self assert:('1.10' compareAsVersionNumberWith:'1.2') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2314 |
self assert:('1.2.3.4' compareAsVersionNumberWith:'1.2.3.5') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2315 |
self assert:('1.2.3.4' compareAsVersionNumberWith:'1.2.3.3') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2316 |
self assert:('1.2.3.4' compareAsVersionNumberWith:'1.2.3') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2317 |
self assert:('1.2.3.4' compareAsVersionNumberWith:'1.2.3.4') = 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2318 |
self assert:('1.2.3.4' compareAsVersionNumberWith:'01.002.03.004') = 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2319 |
self assert:('1.2.3.4' compareAsVersionNumberWith:#(1 2 3 4)) = 0. |
15814 | 2320 |
" |
2321 |
! |
|
2322 |
||
9192 | 2323 |
compareCaselessWith:aString |
9190 | 2324 |
"Compare the receiver against the argument, ignoreing case. |
2325 |
Return 1 if the receiver is greater, 0 if equal and -1 if less than the argument. |
|
2326 |
||
8874 | 2327 |
This comparison is based on the elements ascii code - |
9190 | 2328 |
i.e. national characters are NOT treated specially. |
2329 |
'foo' compareWith: 'Foo' will return 0" |
|
608 | 2330 |
|
2331 |
|mySize "{ Class: SmallInteger }" |
|
8874 | 2332 |
otherSize "{ Class: SmallInteger }" |
9192 | 2333 |
n "{ Class: SmallInteger }" |
608 | 2334 |
c1 c2| |
2335 |
||
2336 |
mySize := self size. |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
2337 |
otherSize := aString string size. |
608 | 2338 |
n := mySize min:otherSize. |
2339 |
||
2340 |
1 to:n do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2341 |
c1 := (self at:index) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2342 |
c2 := (aString at:index) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2343 |
c1 > c2 ifTrue:[^ 1]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2344 |
c1 < c2 ifTrue:[^ -1]. |
608 | 2345 |
]. |
2346 |
mySize > otherSize ifTrue:[^ 1]. |
|
2347 |
mySize < otherSize ifTrue:[^ -1]. |
|
2348 |
^ 0 |
|
1252 | 2349 |
|
2350 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
608 | 2351 |
! |
2352 |
||
14660 | 2353 |
compareCollatingWith:aString |
2354 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2355 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
2356 |
The comparison is language specific, depending on the value of |
|
2357 |
LC_COLLATE, which is in the shell environment." |
|
2358 |
||
2359 |
"TODO not yet defined for unicode" |
|
2360 |
<resource: #todo> |
|
2361 |
||
2362 |
|s| |
|
2363 |
||
2364 |
(s := self string) ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2365 |
^ s compareCollatingWith:aString |
14660 | 2366 |
]. |
2367 |
^ self compareWith:aString |
|
2368 |
! |
|
2369 |
||
9192 | 2370 |
compareWith:aString |
9190 | 2371 |
"Compare the receiver with the argument and return 1 if the receiver is |
2372 |
greater, 0 if equal and -1 if less than the argument. |
|
11861 | 2373 |
This comparison is based on the elements' codepoints - |
9190 | 2374 |
i.e. upper/lowercase & national characters are NOT treated specially. |
2375 |
'foo' compareWith: 'Foo' will return 1. |
|
2376 |
while 'foo' sameAs:'Foo' will return true" |
|
2377 |
||
15814 | 2378 |
|s| |
2379 |
||
2380 |
s := self string. |
|
2381 |
s ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2382 |
^ s compareWith:aString string. |
9192 | 2383 |
]. |
15814 | 2384 |
^ super compareWith:aString string. |
9192 | 2385 |
! |
2386 |
||
11861 | 2387 |
endsWith:aStringOrCharacter |
16175 | 2388 |
"return true, if the receiver ends with something, aStringOrCharacter. |
2389 |
If aStringOrCharacter is empty, true is returned" |
|
11861 | 2390 |
|
2391 |
|s| |
|
2392 |
||
2393 |
(s := self string) ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2394 |
^ s endsWith:aStringOrCharacter |
11861 | 2395 |
]. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2396 |
(self size > 0 and:[aStringOrCharacter isCharacter]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2397 |
^ self last = aStringOrCharacter |
11861 | 2398 |
]. |
2399 |
^ super endsWith:aStringOrCharacter |
|
2400 |
||
2401 |
" |
|
2402 |
'hello world' endsWith:'world' |
|
2403 |
'hello world' asText allBold endsWith:'world' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2404 |
'hello world' endsWith:'' |
16175 | 2405 |
'hello world' asText allBold endsWith:'' |
11861 | 2406 |
" |
2407 |
||
2408 |
"Modified: 12.5.1996 / 15:49:18 / cg" |
|
2409 |
! |
|
2410 |
||
11838 | 2411 |
hammingDistanceTo:aString |
2412 |
"return the hamming distance (the number of characters which are different). |
|
12177 | 2413 |
In information theory, the Hamming distance between two strings of equal length |
2414 |
is the number of positions for which the corresponding symbols are different. |
|
2415 |
Put another way, it measures the minimum number of substitutions required to change |
|
11838 | 2416 |
one into the other, or the number of errors that transformed one string into the other." |
2417 |
||
2418 |
self assert:(aString size == self size). |
|
2419 |
^ 1 to:self size count:[:idx | (self at:idx) ~= (aString at:idx)] |
|
2420 |
||
2421 |
" |
|
2422 |
'roses' hammingDistanceTo:'toned' |
|
2423 |
" |
|
2424 |
! |
|
2425 |
||
9192 | 2426 |
hash |
2427 |
"return an integer useful as a hash-key" |
|
2428 |
||
16898 | 2429 |
"/ whenever changing, also care for String>>hash. |
13879 | 2430 |
"/ immediately after any change, execute (maybe in a debugger): |
2431 |
"/ Set allSubInstancesDo:[:s | s rehash] |
|
16898 | 2432 |
^ self hash_fnv1a |
2433 |
||
2434 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2435 |
'a' hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2436 |
'a' asUnicode16String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2437 |
'a' asUnicode32String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2438 |
'aa' hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2439 |
'aa' asUnicode16String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2440 |
'aa' asUnicode32String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2441 |
'ab' hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2442 |
'ab' asUnicode16String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2443 |
'ab' asUnicode32String hash |
13879 | 2444 |
'ab' hash |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2445 |
'ab' asArray hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2446 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2447 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2448 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2449 |
|syms ms| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2450 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2451 |
syms := Symbol allInstances. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2452 |
Transcript show:'syms: '; showCR:syms size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2453 |
Transcript show:'sdbm hashes: '; showCR:(syms collect:[:s| s hash]) asSet size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2454 |
Transcript show:'dragonBook hashes: '; showCR:(syms collect:[:s| s hash_dragonBook]) asSet size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2455 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2456 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2457 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2458 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2459 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2460 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2461 |
Transcript show:'sdbm hash: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2462 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2463 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2464 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2465 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2466 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2467 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2468 |
Transcript show:'dragonBook: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2469 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2470 |
syms := syms collect:[:each| each asUnicode16String]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2471 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2472 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2473 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2474 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2475 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2476 |
Transcript show:'unicode sdbm hash: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2477 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2478 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2479 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2480 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2481 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2482 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2483 |
Transcript show:'unicode dragonBook:'; showCR:ms. |
14641 | 2484 |
" |
2485 |
||
13879 | 2486 |
"Modified: / 26-12-2011 / 14:09:07 / cg" |
2487 |
! |
|
2488 |
||
2489 |
hash_dragonBook |
|
2490 |
"return an integer useful as a hash-key" |
|
2491 |
||
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2492 |
|h g| |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2493 |
|
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2494 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2495 |
"/ this is the dragon-book algorithm |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2496 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2497 |
h := 0. |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2498 |
self reverseDo:[:char | |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2499 |
"/ 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
|
2500 |
"/ h := (h bitShift:4) + char asciiValue. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2501 |
h := (h bitShift:4). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2502 |
h := h + char codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2503 |
h := h bitAnd:16rFFFFFFFF. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2504 |
g := (h bitAnd: 16rF0000000). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2505 |
g ~~ 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2506 |
h := h bitXor:(g bitShift:-24). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2507 |
h := h bitXor:g. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2508 |
]. |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2509 |
]. |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2510 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2511 |
"/ multiply by large prime to spread values |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2512 |
"/ This speeds up Set and Dictionary by a factor of 10!! |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2513 |
"/ |
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
2514 |
h := h times:31415821. |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2515 |
^ h |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2516 |
|
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2517 |
" |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2518 |
'a' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2519 |
'a' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2520 |
'aa' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2521 |
'aa' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2522 |
'ab' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2523 |
'ab' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2524 |
'ab' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2525 |
'ab' asArray hash |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2526 |
" |
13879 | 2527 |
|
2528 |
"Created: / 26-12-2011 / 13:46:06 / cg" |
|
2529 |
! |
|
2530 |
||
16887 | 2531 |
hash_fnv1a |
2532 |
"return an integer useful as a hash-key. |
|
2533 |
This method uses the fnv-1a algorithm |
|
19743 | 2534 |
(which is actually a very good one). |
2535 |
Attention: stops when a 0-codepoint is encountered |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2536 |
(for compatibility with the hash used by the VM) |
19743 | 2537 |
Also: on 64bit CPUs, only small 4-byte hashvalues are returned, |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2538 |
(so hash values are independent from the architecture)" |
19743 | 2539 |
|
2540 |
|h byte| |
|
16887 | 2541 |
|
2542 |
h := 2166136261. |
|
2543 |
self do:[:eachChar | |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2544 |
byte := eachChar codePoint. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2545 |
byte == 0 ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2546 |
"/ stop |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2547 |
^ (h bitXor: (h >> 30)) bitAnd: 16r3FFFFFFF. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2548 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2549 |
h := h bitXor:byte. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2550 |
h := (h * 16777619) bitAnd:16rFFFFFFFF. |
16887 | 2551 |
]. |
16898 | 2552 |
"/ make sure, it fits into a smallInt |
2553 |
h := (h bitXor: (h >> 30)) bitAnd: 16r3FFFFFFF. |
|
16887 | 2554 |
^ h |
2555 |
||
2556 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2557 |
'abc' hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2558 |
'abc' asUnicode16String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2559 |
'abc' asUnicode32String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2560 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2561 |
'foofooHelloWorld' hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2562 |
'foofooHelloWorld' asUnicode16String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2563 |
'foofooHelloWorld' asUnicode32String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2564 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2565 |
'blablaHelloWorld' hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2566 |
'blablaHelloWorld' asUnicode16String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2567 |
'blablaHelloWorld' asUnicode32String hash_fnv1a |
16887 | 2568 |
" |
2569 |
! |
|
2570 |
||
2571 |
hash_java |
|
2572 |
"return an integer useful as a hash-key. |
|
2573 |
This method uses the same algorithm as used in |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2574 |
the java virtual machine |
16887 | 2575 |
(which is actually not a very good one)." |
2576 |
||
2577 |
|h| |
|
2578 |
||
2579 |
h := 0. |
|
2580 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2581 |
h := (h * 31) + (eachChar codePoint). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2582 |
h := h bitAnd:16rFFFFFFFF. |
16887 | 2583 |
]. |
2584 |
^ h |
|
2585 |
||
2586 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2587 |
'abc' hash_java |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2588 |
'foofooHelloWorld' hash_java |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2589 |
'blablaHelloWorld' hash_java |
16887 | 2590 |
" |
2591 |
! |
|
2592 |
||
16898 | 2593 |
hash_sdbm |
2594 |
"return an integer useful as a hash-key. |
|
2595 |
This method implements the sdbm algorithm." |
|
2596 |
||
2597 |
|h| |
|
2598 |
||
2599 |
"/ |
|
2600 |
"/ this is the sdbm algorithm |
|
2601 |
"/ |
|
2602 |
h := 0. |
|
2603 |
self do:[:char | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2604 |
h := (65599 times:h) plus:char codePoint. |
16898 | 2605 |
]. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2606 |
^ h |
16898 | 2607 |
|
2608 |
" |
|
2609 |
'a' hash |
|
2610 |
'a' asUnicode16String hash |
|
2611 |
'aa' hash |
|
2612 |
'aa' asUnicode16String hash |
|
2613 |
'ab' hash |
|
2614 |
'ab' asUnicode16String hash |
|
2615 |
'ab' hash |
|
2616 |
'ab' asArray hash |
|
2617 |
" |
|
2618 |
||
2619 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2620 |
|syms ms| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2621 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2622 |
syms := Symbol allInstances. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2623 |
Transcript show:'syms: '; showCR:syms size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2624 |
Transcript show:'sdbm hashes: '; showCR:(syms collect:[:s| s hash]) asSet size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2625 |
Transcript show:'dragonBook hashes: '; showCR:(syms collect:[:s| s hash_dragonBook]) asSet size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2626 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2627 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2628 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2629 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2630 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2631 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2632 |
Transcript show:'sdbm hash: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2633 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2634 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2635 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2636 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2637 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2638 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2639 |
Transcript show:'dragonBook: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2640 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2641 |
syms := syms collect:[:each| each asUnicode16String]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2642 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2643 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2644 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2645 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2646 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2647 |
Transcript show:'unicode sdbm hash: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2648 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2649 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2650 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2651 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2652 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2653 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2654 |
Transcript show:'unicode dragonBook:'; showCR:ms. |
16898 | 2655 |
" |
2656 |
||
2657 |
"Modified: / 26-12-2011 / 14:09:07 / cg" |
|
2658 |
! |
|
2659 |
||
11861 | 2660 |
levenshteinTo:aString |
2661 |
"return the levenshtein distance to the argument, aString; |
|
2662 |
this value corresponds to the number of replacements that have to be |
|
2663 |
made to get aString from the receiver. |
|
2664 |
See IEEE transactions on Computers 1976 Pg 172 ff." |
|
2665 |
||
2666 |
" |
|
2667 |
in the following, we assume that ommiting a character |
|
2668 |
is less of an error than inserting an extra character. |
|
2669 |
Therefore the different insertion (i) and deletion (d) values. |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2670 |
s: substitution weight (4) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2671 |
k: keyboard weight (k) (typing a nearby key) - or nil (then use s) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2672 |
c: case weight (4) - or nil (then use s) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2673 |
e: exchange weight (8) - or nil (then use s*2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2674 |
i: insertion of extra character weight (2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2675 |
d: delete of a character weight (6) |
11861 | 2676 |
" |
2677 |
||
2678 |
^ StringUtilities |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2679 |
levenshteinDistanceFrom:self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2680 |
to:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2681 |
s:4 k:4 c:4 e:nil i:2 d:6 |
12177 | 2682 |
|
2683 |
" |
|
2684 |
'computer' levenshteinTo:'computer' |
|
11861 | 2685 |
'cOmputer' levenshteinTo:'computer' |
12177 | 2686 |
'cOmpuTer' levenshteinTo:'computer' |
11861 | 2687 |
'cimputer' levenshteinTo:'computer' |
2688 |
'cumputer' levenshteinTo:'computer' |
|
2689 |
||
2690 |
'cmputer' levenshteinTo:'computer' |
|
2691 |
'coomputer' levenshteinTo:'computer' |
|
2692 |
||
2693 |
'ocmprt' levenshteinTo:'computer' |
|
2694 |
'computer' levenshteinTo:'computer' |
|
2695 |
'ocmputer' levenshteinTo:'computer' |
|
2696 |
'cmputer' levenshteinTo:'computer' |
|
2697 |
'computer' levenshteinTo:'cmputer' |
|
2698 |
'Computer' levenshteinTo:'computer' |
|
2699 |
||
12177 | 2700 |
'compiter' levenshteinTo:'computer' |
2701 |
'compoter' levenshteinTo:'computer' |
|
2702 |
||
2703 |
'comptuer' levenshteinTo:'computer' |
|
11861 | 2704 |
" |
2705 |
! |
|
2706 |
||
2707 |
levenshteinTo:aString s:substWeight k:kbdTypoWeight c:caseWeight i:insrtWeight d:deleteWeight |
|
2708 |
"parametrized levenshtein. |
|
2709 |
return the levenshtein distance to the argument, aString; |
|
2710 |
this value corrensponds to the number of replacements that have to be |
|
2711 |
made to get aString from the receiver. |
|
2712 |
The arguments are the costs for |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2713 |
s:substitution, |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2714 |
k:keyboard type (substitution), |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2715 |
c:case-change, |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2716 |
i:insertion |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2717 |
d:deletion |
11861 | 2718 |
of a character. |
2719 |
See IEEE transactions on Computers 1976 Pg 172 ff" |
|
2720 |
||
2721 |
^ StringUtilities |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2722 |
levenshteinDistanceFrom:self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2723 |
to:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2724 |
s:substWeight k:kbdTypoWeight c:caseWeight e:nil i:insrtWeight d:deleteWeight |
11861 | 2725 |
! |
2726 |
||
9190 | 2727 |
sameAs:aString |
2728 |
"Compare the receiver with the argument like =, but ignore case differences. |
|
2729 |
Return true or false." |
|
2730 |
||
2731 |
|mySize "{ Class: SmallInteger }" |
|
2732 |
otherSize c1 c2| |
|
2733 |
||
9192 | 2734 |
self == aString ifTrue:[^ true]. |
2735 |
||
2736 |
mySize := self size. |
|
2737 |
otherSize := aString string size. |
|
18884 | 2738 |
mySize ~~ otherSize ifTrue:[^ false]. |
9192 | 2739 |
|
2740 |
1 to:mySize do:[:index | |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2741 |
c1 := self at:index. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2742 |
c2 := aString at:index. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2743 |
c1 ~~ c2 ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2744 |
(c1 sameAs:c2) ifFalse:[^ false]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2745 |
] |
9192 | 2746 |
]. |
2747 |
^ true |
|
2748 |
||
608 | 2749 |
" |
8874 | 2750 |
'foo' sameAs: 'Foo' |
2751 |
'foo' sameAs: 'bar' |
|
2752 |
'foo' sameAs: 'foo' |
|
9192 | 2753 |
" |
2754 |
||
2755 |
"Modified: 22.4.1996 / 15:56:17 / cg" |
|
2756 |
! |
|
608 | 2757 |
|
15734 | 2758 |
sameAs:aString caseSensitive:caseSensitive |
2759 |
"Compare the receiver with the argument. |
|
2760 |
If caseSensitive is false, this is the same as #sameAs:, |
|
2761 |
if false, this is the same as #=." |
|
2762 |
||
2763 |
caseSensitive ifFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2764 |
^ self sameAs:aString |
15734 | 2765 |
]. |
2766 |
^ self = aString |
|
2767 |
||
2768 |
" |
|
2769 |
'foo' sameAs:'Foo' caseSensitive:false |
|
2770 |
'foo' sameAs:'foo' caseSensitive:true |
|
2771 |
" |
|
2772 |
! |
|
2773 |
||
5242 | 2774 |
sameAs:aString ignoreCase:ignoreCase |
15734 | 2775 |
<resource: #obsolete> |
5242 | 2776 |
"Compare the receiver with the argument. |
2777 |
If ignoreCase is true, this is the same as #sameAs:, |
|
2778 |
if false, this is the same as #=." |
|
2779 |
||
2780 |
ignoreCase ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2781 |
^ self sameAs:aString |
5242 | 2782 |
]. |
2783 |
^ self = aString |
|
2784 |
||
2785 |
" |
|
8874 | 2786 |
'foo' sameAs:'Foo' ignoreCase:false |
2787 |
'foo' sameAs:'foo' ignoreCase:true |
|
5242 | 2788 |
" |
2789 |
||
2790 |
! |
|
2791 |
||
608 | 2792 |
sameCharacters:aString |
9192 | 2793 |
"count & return the number of characters which are the same |
2794 |
(ignoring case and emphasis) in the receiver and the argument, aString." |
|
2795 |
||
2796 |
|n "{ Class: SmallInteger }" |
|
2797 |
c1 c2 cnt| |
|
2798 |
||
2799 |
n := self size. |
|
2800 |
n := n min:(aString string size). |
|
2801 |
||
2802 |
cnt := 0. |
|
2803 |
1 to:n do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2804 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2805 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2806 |
((c1 == c2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2807 |
or:[c1 asLowercase = c2 asLowercase]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2808 |
cnt := cnt + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2809 |
] |
9192 | 2810 |
]. |
2811 |
^ cnt |
|
2812 |
||
2813 |
" |
|
2814 |
'foobarbaz' sameCharacters: 'foo' |
|
8874 | 2815 |
'foobarbaz' sameCharacters: 'Foo' |
2816 |
'foobarbaz' sameCharacters: 'baz' |
|
608 | 2817 |
" |
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2818 |
! |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2819 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2820 |
sameEmphasisAs:aStringOrText |
17215 | 2821 |
"compare the receiver's and the argument's emphasis" |
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2822 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2823 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2824 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2825 |
" |
8874 | 2826 |
'hello' asText sameEmphasisAs: 'hello' |
2827 |
'hello' asText sameEmphasisAs: 'hello' asText |
|
2828 |
'hello' asText allBold sameEmphasisAs: 'hello' |
|
2829 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
|
9192 | 2830 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
2831 |
" |
|
2832 |
! |
|
2833 |
||
9191 | 2834 |
sameStringAndEmphasisAs:aStringOrText |
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
2835 |
"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
|
2836 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2837 |
aStringOrText isString ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2838 |
(self string = aStringOrText string) ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2839 |
self hasChangeOfEmphasis = aStringOrText hasChangeOfEmphasis ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2840 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2841 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2842 |
" |
8874 | 2843 |
'hello' asText sameEmphasisAs: 'hello' |
2844 |
'hello' asText sameEmphasisAs: 'hello' asText |
|
2845 |
'hello' asText allBold sameEmphasisAs: 'hello' |
|
2846 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
|
2847 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
|
2848 |
||
2849 |
'hello' sameEmphasisAs: 'hello' asText |
|
2850 |
'hello' sameEmphasisAs: 'hello' asText allBold |
|
2851 |
'hello' sameEmphasisAs: 'fooba' |
|
2852 |
'hello' sameEmphasisAs: 'fooba' asText |
|
2853 |
'hello' sameEmphasisAs: 'fooba' asText allBold |
|
2854 |
'hello' sameEmphasisAs: 'fooba' asText allItalic |
|
2855 |
||
2856 |
'hello' asText sameStringAndEmphasisAs: 'hello' |
|
2857 |
'hello' asText sameStringAndEmphasisAs: 'hello' asText |
|
2858 |
'hello' asText allBold sameStringAndEmphasisAs: 'hello' |
|
2859 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allBold |
|
2860 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allItalic |
|
2861 |
||
2862 |
'hello' sameStringAndEmphasisAs: 'hello' asText |
|
2863 |
'hello' sameStringAndEmphasisAs: 'hello' asText allBold |
|
2864 |
'hello' sameStringAndEmphasisAs: 'fooba' |
|
2865 |
'hello' sameStringAndEmphasisAs: 'fooba' asText |
|
2866 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allBold |
|
2867 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allItalic |
|
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2868 |
" |
11861 | 2869 |
! |
2870 |
||
2871 |
spellAgainst: aString |
|
2872 |
"return an integer between 0 and 100 indicating how similar |
|
2873 |
the argument is to the receiver. No case conversion is done. |
|
2874 |
This algorithm is much simpler (but also less exact) than the |
|
2875 |
levenshtein distance. Experiment which is better for your |
|
2876 |
application." |
|
2877 |
||
2878 |
| i1 "{ Class: SmallInteger }" |
|
2879 |
i2 "{ Class: SmallInteger }" |
|
2880 |
next1 "{ Class: SmallInteger }" |
|
2881 |
next2 "{ Class: SmallInteger }" |
|
2882 |
size1 "{ Class: SmallInteger }" |
|
2883 |
size2 "{ Class: SmallInteger }" |
|
2884 |
score "{ Class: SmallInteger }" |
|
2885 |
maxLen "{ Class: SmallInteger }" | |
|
2886 |
||
2887 |
size1 := self size. |
|
2888 |
size2 := aString size. |
|
2889 |
maxLen := size1 max:size2. |
|
2890 |
score := 0. |
|
2891 |
i1 := i2 := 1. |
|
2892 |
[i1 <= size1 and: [i2 <= size2]] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2893 |
next1 := i1 + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2894 |
next2 := i2 + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2895 |
(self at:i1) == (aString at:i2) ifTrue: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2896 |
score := score+1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2897 |
i1 := next1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2898 |
i2 := next2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2899 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2900 |
(i2 < size2 and: [(self at:i1) == (aString at:next2)]) ifTrue: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2901 |
i2 := next2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2902 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2903 |
(i1 < size1 and: [(self at:next1) == (aString at:i2)]) ifTrue: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2904 |
i1 := next1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2905 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2906 |
i1 := next1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2907 |
i2 := next2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2908 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2909 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2910 |
] |
11861 | 2911 |
]. |
2912 |
||
2913 |
score == maxLen ifTrue: [^ 100]. |
|
2914 |
^ 100 * score // maxLen |
|
2915 |
||
2916 |
" |
|
2917 |
'Smalltalk' spellAgainst: 'Smalltlak' |
|
2918 |
'Smalltalk' spellAgainst: 'smalltlak' |
|
2919 |
'Smalltalk' spellAgainst: 'smalltalk' |
|
2920 |
'Smalltalk' spellAgainst: 'smalltlk' |
|
2921 |
'Smalltalk' spellAgainst: 'Smalltolk' |
|
2922 |
" |
|
2923 |
! |
|
2924 |
||
16553 | 2925 |
startsWith:aStringOrCharacter |
2926 |
"return true, if the receiver starts with something, aStringOrCharacter. |
|
17371 | 2927 |
If the argument is empty, true is returned. |
2928 |
Notice, that this is similar to, but slightly different from VW's and Squeak's beginsWith:, |
|
2929 |
which are both inconsistent w.r.t. an empty argument." |
|
11861 | 2930 |
|
2931 |
|s| |
|
2932 |
||
16553 | 2933 |
aStringOrCharacter isCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2934 |
^ (self size > 0) and:[ (self at:1) == aStringOrCharacter ] |
16553 | 2935 |
]. |
11861 | 2936 |
(s := self string) ~~ self ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2937 |
^ s startsWith:aStringOrCharacter |
11861 | 2938 |
]. |
16553 | 2939 |
^ super startsWith:aStringOrCharacter |
11861 | 2940 |
|
2941 |
" |
|
17364 | 2942 |
'abcde' startsWith:#($a $b $c) |
2943 |
'abcde' startsWith:'abc' |
|
2944 |
'abcd' startsWith:'abcde' |
|
2945 |
'abcde' startsWith:'abd' |
|
11861 | 2946 |
'hello world' startsWith:'hello' |
2947 |
'hello world' asText allBold startsWith:'hello' |
|
2948 |
'hello world' asText allBold startsWith:'' |
|
2949 |
" |
|
2950 |
||
2951 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
2952 |
"Modified: 12.5.1996 / 15:49:24 / cg" |
|
9192 | 2953 |
! ! |
2954 |
||
2955 |
!CharacterArray methodsFor:'converting'! |
|
2956 |
||
11881 | 2957 |
asAsciiZ |
2958 |
"if the receiver does not end with a 0-valued character, return a copy of it, |
|
2959 |
with an additional 0-character. Otherwise return the receiver. This is sometimes |
|
2960 |
needed when a string has to be passed to C, which needs 0-terminated strings. |
|
2961 |
Notice, that all singleByte strings are already 0-terminated in ST/X, whereas wide |
|
2962 |
strings are not." |
|
2963 |
||
12658 | 2964 |
(self notEmpty and:[self last codePoint == 0]) ifTrue:[^ self ]. |
11881 | 2965 |
^ self copyWith:(Character value:0). |
2966 |
||
2967 |
" |
|
2968 |
'abc' asAsciiZ |
|
2969 |
'abc' asWideString asAsciiZ |
|
2970 |
" |
|
2971 |
! |
|
2972 |
||
13524 | 2973 |
asByteArray |
15936 | 2974 |
"depending on the size of the characters in the receiver, |
2975 |
return a byteArray containing single-, double- or even 4-bytewise values. |
|
2976 |
The size of the returned byteArray will be the strings size multiplied by the |
|
2977 |
size required for the largest character. |
|
19233 | 2978 |
Attention: The bytes are in native byte order. |
15936 | 2979 |
Caveat: better use utf8Encoded, to get reproducable results" |
2980 |
||
14555 | 2981 |
|bytes sz bytesPerCharacter idx str| |
2982 |
||
2983 |
str := self string. |
|
2984 |
str ~~ self ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2985 |
"/ for text and other wrappers |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2986 |
^ str asByteArray |
13611
ba8c7372218a
variable renamed in: #inspector2TabBytes
Claus Gittinger <cg@exept.de>
parents:
13524
diff
changeset
|
2987 |
]. |
ba8c7372218a
variable renamed in: #inspector2TabBytes
Claus Gittinger <cg@exept.de>
parents:
13524
diff
changeset
|
2988 |
|
ba8c7372218a
variable renamed in: #inspector2TabBytes
Claus Gittinger <cg@exept.de>
parents:
13524
diff
changeset
|
2989 |
"/ for real strings, a fallback |
13524 | 2990 |
sz := self size. |
19757 | 2991 |
bytesPerCharacter := self bytesPerCharacter. |
13524 | 2992 |
bytes := ByteArray new:(sz * bytesPerCharacter). |
2993 |
idx := 1. |
|
2994 |
self do:[:char | |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2995 |
|code| |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2996 |
|
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2997 |
code := char codePoint. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2998 |
bytesPerCharacter == 2 ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
2999 |
bytes unsignedInt16At:idx put:code |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3000 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3001 |
bytesPerCharacter == 4 ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3002 |
bytes unsignedInt32At:idx put:code |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3003 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3004 |
bytes at:idx put:code |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3005 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3006 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3007 |
idx := idx + bytesPerCharacter. |
13524 | 3008 |
]. |
3009 |
^ bytes |
|
3010 |
||
3011 |
"Created: / 27-07-2011 / 00:56:17 / cg" |
|
3012 |
! |
|
3013 |
||
19233 | 3014 |
asByteArrayMSB:msb |
3015 |
"depending on the size of the characters in the receiver, |
|
3016 |
return a byteArray containing single-, double- or even 4-bytewise values. |
|
3017 |
The size of the returned byteArray will be the strings size multiplied by the |
|
3018 |
size required for the largest character. |
|
3019 |
Caveat: better use utf8Encoded, to get reproducable results" |
|
3020 |
||
3021 |
|ba| |
|
3022 |
||
3023 |
ba := self asByteArray. "/ native order |
|
3024 |
UninterpretedBytes isBigEndian ~~ msb ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3025 |
ba swapBytes |
19233 | 3026 |
]. |
3027 |
^ ba |
|
3028 |
! |
|
3029 |
||
608 | 3030 |
asCollectionOfLines |
8874 | 3031 |
"return a collection containing the lines (separated by cr) |
608 | 3032 |
of the receiver. If multiple cr's occur in a row, the result will |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3033 |
contain empty strings. |
14456
d7c3e67647f1
comment/format in: #asCollectionOfLines
Claus Gittinger <cg@exept.de>
parents:
14455
diff
changeset
|
3034 |
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
|
3035 |
See also #asCollectionOfLinesWithReturn |
d7c3e67647f1
comment/format in: #asCollectionOfLines
Claus Gittinger <cg@exept.de>
parents:
14455
diff
changeset
|
3036 |
(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
|
3037 |
this method and we did not want to risk any incompatibilities)" |
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3038 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3039 |
^ self asCollectionOfSubstringsSeparatedBy:Character cr. |
608 | 3040 |
|
3041 |
" |
|
3042 |
'1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines |
|
8874 | 3043 |
'1 one\\\\2 two\3 three' withCRs asCollectionOfLines |
608 | 3044 |
" |
3045 |
! |
|
3046 |
||
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3047 |
asCollectionOfLinesWithReturn |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3048 |
"return a collection containing the lines (separated by cr) |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3049 |
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
|
3050 |
contain empty strings." |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3051 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3052 |
|lines| |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3053 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3054 |
lines := self asCollectionOfSubstringsSeparatedBy:Character cr. |
18194 | 3055 |
(lines notEmpty and:[lines last isEmpty]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3056 |
^ lines copyButLast:1 |
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3057 |
]. |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3058 |
^ lines |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3059 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3060 |
" |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3061 |
'1\2\3' withCRs asCollectionOfLines |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3062 |
'1\2\3\' withCRs asCollectionOfLines |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3063 |
'1\2\3' withCRs asCollectionOfLinesWithReturn |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3064 |
'1\2\3\' withCRs asCollectionOfLinesWithReturn |
18194 | 3065 |
'' withCRs asCollectionOfLinesWithReturn |
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3066 |
" |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3067 |
! |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
3068 |
|
608 | 3069 |
asCollectionOfSubstringsSeparatedBy:aCharacter |
15740 | 3070 |
"return a collection containing substrings (separated by aCharacter) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3071 |
of the receiver. |
15740 | 3072 |
If aCharacter occurs multiple times in a row, the result will contain empty strings. |
3073 |
If the receiver ends with aCharacter, an empty string with be the last result element." |
|
608 | 3074 |
|
9192 | 3075 |
^ self asCollectionOfSubCollectionsSeparatedBy:aCharacter |
3076 |
||
3077 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3078 |
'1 one:2 two:3 three:4 four:5 five' asCollectionOfSubstringsSeparatedBy:$: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3079 |
'1 one:2 two:3 three:4 four:5 five:' asCollectionOfSubstringsSeparatedBy:$: |
15740 | 3080 |
'1 one 2 two 3 three 4 four 5 five' asCollectionOfSubstringsSeparatedBy:Character space |
9192 | 3081 |
" |
3082 |
! |
|
608 | 3083 |
|
11828 | 3084 |
asCollectionOfSubstringsSeparatedBy:aCharacter exceptIn:ch |
15740 | 3085 |
"return a collection containing the substrings (separated by aCharacter) |
12177 | 3086 |
of the receiver. If aCharacter occurs multiple times in a row, |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3087 |
the result will contain empty strings. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3088 |
The separation is not done, inside a matching pair of ch-substrings. |
15740 | 3089 |
Can be used to tokenize csv-like strings, which may or may not be enclosed in quotes." |
11828 | 3090 |
|
3091 |
|lines myClass except i c |
|
3092 |
startIndex "{ Class:SmallInteger }" |
|
3093 |
stopIndex "{ Class:SmallInteger }" | |
|
3094 |
||
11905
cbc2191cfe2d
return stringCollections from asCollectionOfXXX
Claus Gittinger <cg@exept.de>
parents:
11904
diff
changeset
|
3095 |
lines := StringCollection new. |
11828 | 3096 |
myClass := self species. |
3097 |
||
3098 |
startIndex := 1. |
|
3099 |
except := false. |
|
3100 |
[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3101 |
i := startIndex-1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3102 |
[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3103 |
i := i+1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3104 |
c := self at:i. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3105 |
c = ch ifTrue:[ except := except not. ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3106 |
i < self size and:[except or:[c ~= aCharacter]] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3107 |
] whileTrue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3108 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3109 |
c = aCharacter ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3110 |
stopIndex := i -1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3111 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3112 |
stopIndex := i. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3113 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3114 |
(stopIndex < startIndex) ifTrue: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3115 |
lines add:(myClass new:0) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3116 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3117 |
lines add:(self copyFrom:startIndex to:stopIndex) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3118 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3119 |
startIndex := stopIndex + 2. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3120 |
startIndex <= self size |
11828 | 3121 |
] whileTrue. |
3122 |
^ lines |
|
3123 |
||
3124 |
" |
|
12177 | 3125 |
'asd''f;d''dd;s' asCollectionOfSubstringsSeparatedBy:$; exceptIn:$' |
3126 |
" |
|
3127 |
"/ 'asd "hello bla" foo "bla bla" bar' asCollectionOfSubstringsSeparatedBy:$ exceptIn:$" |
|
11828 | 3128 |
! |
3129 |
||
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
3130 |
asCollectionOfSubstringsSeparatedBy:aFieldSeparatorString textSeparator:aTextSeparatorOrNil |
13343
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
3131 |
"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
|
3132 |
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
|
3133 |
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
|
3134 |
|
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
3135 |
|aTextSeparatorChar items scanningWord inStream element lastIsFieldSeparator sz| |
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
3136 |
|
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
3137 |
aTextSeparatorOrNil isNil ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3138 |
^ self asCollectionOfSubstringsSeparatedByAll: aFieldSeparatorString |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3139 |
]. |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
3140 |
sz := aTextSeparatorOrNil size. |
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
3141 |
sz = 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3142 |
aTextSeparatorChar := aTextSeparatorOrNil |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
3143 |
] ifFalse:[sz = 1 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3144 |
"this is a String. Fetch the first character - compatibility to older expecco libs" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3145 |
aTextSeparatorChar := aTextSeparatorOrNil first. |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
3146 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3147 |
self error:'textSeparatoSize > 1'. |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
3148 |
]]. |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3149 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3150 |
items := OrderedCollection new. |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3151 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3152 |
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
|
3153 |
[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3154 |
inStream skipSeparators. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3155 |
inStream atEnd |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3156 |
] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3157 |
lastIsFieldSeparator := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3158 |
inStream peek == aTextSeparatorChar ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3159 |
inStream next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3160 |
element := ''. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3161 |
scanningWord := true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3162 |
[ scanningWord and:[inStream atEnd not] ] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3163 |
element := element , (inStream upTo:aTextSeparatorChar). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3164 |
(inStream peek == aTextSeparatorChar) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3165 |
element := element , aTextSeparatorChar . |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3166 |
inStream next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3167 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3168 |
scanningWord := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3169 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3170 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3171 |
inStream upToAll_positionBefore:aFieldSeparatorString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3172 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3173 |
element := inStream upToAll_positionBefore:aFieldSeparatorString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3174 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3175 |
items add:element. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3176 |
lastIsFieldSeparator := (inStream skipThroughAll:aFieldSeparatorString) notNil. |
13343
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
3177 |
]. |
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
3178 |
lastIsFieldSeparator ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3179 |
"empty element at the end of the line" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3180 |
items add:''. |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3181 |
]. |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3182 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3183 |
^ items |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3184 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3185 |
" |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3186 |
self assert:(('#First#, #Second,SecondAdd#, #Third#' asCollectionOfSubstringsSeparatedBy:',' textSeparator: $#) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3187 |
sameContentsAs:#('First' 'Second,SecondAdd' 'Third')). |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3188 |
self assert:(('#Fir##st#, #Second,SecondAdd#, #Third#' asCollectionOfSubstringsSeparatedBy:',' textSeparator: $#) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3189 |
sameContentsAs:#('Fir#st' 'Second,SecondAdd' 'Third')). |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3190 |
self assert:(('#Fir##st#, Second,SecondAdd, #Third#' asCollectionOfSubstringsSeparatedBy:',' textSeparator: $#) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3191 |
sameContentsAs:#('Fir#st' 'Second' 'SecondAdd' 'Third')). |
13343
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
3192 |
self assert:(('First,Second,Third,,' asCollectionOfSubstringsSeparatedBy:',' textSeparator:nil) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3193 |
sameContentsAs:#('First' 'Second' 'Third' '' '')). |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
3194 |
self assert:(('First,Second,Third,,' asCollectionOfSubstringsSeparatedBy:',' textSeparator:'#') |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3195 |
sameContentsAs:#('First' 'Second' 'Third' '' '')). |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3196 |
" |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3197 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
3198 |
"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
|
3199 |
! |
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
3200 |
|
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3201 |
asCollectionOfSubstringsSeparatedByAll:aSeparatorString |
8874 | 3202 |
"return a collection containing the lines (separated by aSeparatorString) |
3203 |
of the receiver. If aSeparatorString occurs multiple times in a row, |
|
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3204 |
the result will contain empty strings." |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3205 |
|
8852
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
3206 |
^ self asCollectionOfSubCollectionsSeparatedByAll:aSeparatorString |
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
3207 |
|
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
3208 |
" |
8874 | 3209 |
'1::2::3::4::5::' asCollectionOfSubstringsSeparatedByAll:'::' |
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3210 |
" |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3211 |
! |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3212 |
|
608 | 3213 |
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators |
3214 |
"return a collection containing the words (separated by any character |
|
3215 |
from aCollectionOfSeparators) of the receiver. |
|
3216 |
This allows breaking up strings using any character as separator." |
|
3217 |
||
8852
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
3218 |
^ self asCollectionOfSubCollectionsSeparatedByAny:aCollectionOfSeparators |
608 | 3219 |
|
3220 |
" |
|
3221 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:) |
|
8874 | 3222 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' |
3223 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) |
|
3224 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' |
|
3225 |
'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) |
|
608 | 3226 |
" |
3227 |
! |
|
3228 |
||
3229 |
asCollectionOfWords |
|
8874 | 3230 |
"return a collection containing the words (separated by whitespace) |
3231 |
of the receiver. Multiple occurrences of whitespace characters will |
|
17517 | 3232 |
be treated like one - i.e. whitespace is skipped. |
3233 |
(sigh: it is called #'subStrings' in V'Age, and #'substrings' in Squeak) " |
|
608 | 3234 |
|
7797 | 3235 |
|words| |
608 | 3236 |
|
11905
cbc2191cfe2d
return stringCollections from asCollectionOfXXX
Claus Gittinger <cg@exept.de>
parents:
11904
diff
changeset
|
3237 |
words := StringCollection new. |
7797 | 3238 |
self asCollectionOfWordsDo:[:w | words add:w]. |
608 | 3239 |
^ words |
3240 |
||
3241 |
" |
|
3242 |
'hello world isnt this nice' asCollectionOfWords |
|
3243 |
' hello world isnt this nice ' asCollectionOfWords |
|
3244 |
'hello' asCollectionOfWords |
|
3245 |
'' asCollectionOfWords |
|
3246 |
' ' asCollectionOfWords |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
3247 |
' foo bar__baz__bla__ bar ' asCollectionOfWords |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
3248 |
' foo __bar__baz__bla__ bar ' asCollectionOfWords |
608 | 3249 |
" |
9192 | 3250 |
! |
3251 |
||
3252 |
asCollectionOfWordsDo:aBlock |
|
8874 | 3253 |
"evaluate aBlock for each word (separated by whitespace) of the receiver. |
3254 |
Multiple occurrences of whitespace characters will be treated like one |
|
7797 | 3255 |
- i.e. whitespace is skipped. |
3256 |
Returns the number of words (i.e. the number of invocations of aBlock)." |
|
3257 |
||
3258 |
|count "{ Class:SmallInteger }" |
|
8874 | 3259 |
start "{ Class:SmallInteger }" |
3260 |
stop "{ Class:SmallInteger }" |
|
7797 | 3261 |
mySize "{ Class:SmallInteger }"| |
3262 |
||
3263 |
count := 0. |
|
3264 |
start := 1. |
|
3265 |
mySize := self size. |
|
3266 |
[start <= mySize] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3267 |
start := self indexOfNonSeparatorStartingAt:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3268 |
start == 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3269 |
^ count |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3270 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3271 |
stop := self indexOfSeparatorStartingAt:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3272 |
stop == 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3273 |
aBlock value:(self copyFrom:start to:mySize). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3274 |
^ count + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3275 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3276 |
aBlock value:(self copyFrom:start to:(stop - 1)). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3277 |
start := stop. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3278 |
count := count + 1 |
7797 | 3279 |
]. |
3280 |
^ count |
|
3281 |
||
3282 |
" |
|
3283 |
'hello world isnt this nice' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3284 |
' hello world isnt this nice ' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3285 |
'hello' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3286 |
'' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3287 |
' ' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3288 |
" |
|
9192 | 3289 |
! |
3290 |
||
3291 |
asFilename |
|
3292 |
"return a Filename with pathname taken from the receiver" |
|
3293 |
||
3294 |
^ Filename named:self "(self asSingleByteStringReplaceInvalidWith:$?)" |
|
3295 |
||
3296 |
"Modified: 20.5.1996 / 09:38:15 / cg" |
|
3297 |
! |
|
608 | 3298 |
|
3060 | 3299 |
asFixedPoint |
3300 |
"read a fixedPoint number from the receiver. |
|
8874 | 3301 |
Notice, that errors may occur during the read, |
7423 | 3302 |
so you better setup some signal handler when using this method." |
3060 | 3303 |
|
3304 |
^ FixedPoint readFromString:self |
|
3305 |
||
3306 |
" |
|
8874 | 3307 |
'0.123' asFixedPoint |
3308 |
'12345' asFixedPoint |
|
3060 | 3309 |
'(1/5)' asFixedPoint |
3310 |
'foo' asFixedPoint |
|
9192 | 3311 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asFixedPoint] |
3312 |
" |
|
3313 |
||
3314 |
"Modified: / 25.10.1997 / 15:19:00 / cg" |
|
3315 |
! |
|
3316 |
||
3317 |
asFixedPoint:scale |
|
3060 | 3318 |
"read a fixedPoint number with scale number of post-decimal digits |
3319 |
from the receiver. Scale controls the number of displayed digits, |
|
3320 |
not the number of actually valid digits. |
|
8874 | 3321 |
Notice, that errors may occur during the read, |
7423 | 3322 |
so you better setup some signal handler when using this method." |
3060 | 3323 |
|
3324 |
^ (FixedPoint readFromString:self) scale:scale |
|
3325 |
||
3326 |
" |
|
8874 | 3327 |
'0.123' asFixedPoint:2 |
3328 |
'123456' asFixedPoint:2 |
|
3329 |
('3.14157' asFixedPoint:1) asFixedPoint:5 |
|
3330 |
'3.14157' asFixedPoint:2 |
|
3331 |
'foo' asFixedPoint:2 |
|
3060 | 3332 |
" |
3333 |
||
3334 |
"Modified: / 25.10.1997 / 15:21:57 / cg" |
|
9192 | 3335 |
! |
3336 |
||
3337 |
asFloat |
|
608 | 3338 |
"read a float number from the receiver. |
8874 | 3339 |
Notice, that errors may occur during the read, |
7422 | 3340 |
so you better setup some exception handler when using this method." |
608 | 3341 |
|
3342 |
^ (Number readFromString:self) asFloat |
|
3343 |
||
3344 |
" |
|
8874 | 3345 |
'0.123' asFloat |
608 | 3346 |
'12345' asFloat |
3347 |
'(1/5)' asFloat |
|
8874 | 3348 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asFloat] |
608 | 3349 |
" |
3350 |
! |
|
3351 |
||
3352 |
asInteger |
|
9190 | 3353 |
"convert the receiver into an integer. |
8874 | 3354 |
Notice, that errors may occur during the read, |
9190 | 3355 |
so you better setup some exception handler when using this method. |
3356 |
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
|
3357 |
in other smalltalks. |
9190 | 3358 |
For less strict integer reading, use Integer readFrom:aString" |
608 | 3359 |
|
3360 |
^ Integer readFromString:self |
|
3361 |
||
3362 |
" |
|
3363 |
'12345678901234567890' asInteger |
|
3364 |
'-1234' asInteger |
|
9190 | 3365 |
|
3366 |
The following raises an error: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3367 |
'0.123' asInteger <- reader finds more after reading 0 |
9190 | 3368 |
|
3369 |
whereas the less strict readFrom does not: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3370 |
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
|
3371 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
3372 |
'0.123' asInteger |
608 | 3373 |
'0.123' asNumber <- returns what you expect |
8874 | 3374 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asInteger] |
9190 | 3375 |
|
3376 |
" |
|
9192 | 3377 |
! |
3378 |
||
3379 |
asLowercase |
|
608 | 3380 |
"return a copy of myself in lowercase letters" |
3381 |
||
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3382 |
|newStr c bitsPerCharacter |
9192 | 3383 |
mySize "{ Class: SmallInteger }" | |
3384 |
||
3385 |
mySize := self size. |
|
3386 |
mySize == 0 ifTrue:[^ self]. |
|
18657 | 3387 |
|
9192 | 3388 |
newStr := self species new:mySize. |
3389 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
3390 |
||
18657 | 3391 |
"/ handle the very seldom case of an uppercase char which needs |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3392 |
"/ more bits in its lowercase variant |
18657 | 3393 |
"/ (there are only a few of them) |
3394 |
||
9192 | 3395 |
1 to:mySize do:[:i | |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3396 |
c := (self at:i) asLowercase. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3397 |
(c bitsPerCharacter > bitsPerCharacter |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3398 |
and:[c stringSpecies ~= newStr stringSpecies]) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3399 |
newStr := c stringSpecies fromString:newStr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3400 |
bitsPerCharacter := newStr bitsPerCharacter. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3401 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3402 |
newStr at:i put:c |
9192 | 3403 |
]. |
3404 |
^ newStr |
|
3405 |
||
3406 |
" |
|
3407 |
'HelloWorld' asLowercase |
|
18662 | 3408 |
'HelloWorld' asUnicode16String asLowercase |
9192 | 3409 |
'HelloWorld' asLowercaseFirst |
18657 | 3410 |
'HelloWorld' asUppercase |
9192 | 3411 |
" |
3412 |
! |
|
3413 |
||
3414 |
asLowercaseFirst |
|
17508 | 3415 |
"return a copy of myself where the first character is converted to lowercase. |
3416 |
If the first character is already lowercase, or there is no uppercase for it, return the |
|
3417 |
receiver." |
|
9192 | 3418 |
|
3419 |
|newString firstChar firstCharAsLowercase| |
|
3420 |
||
11525 | 3421 |
self isEmpty ifTrue:[^ self]. |
9192 | 3422 |
firstChar := (self at:1). |
3423 |
firstCharAsLowercase := firstChar asLowercase. |
|
3424 |
firstChar == firstCharAsLowercase ifTrue:[ ^ self]. |
|
3425 |
||
3426 |
firstCharAsLowercase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3427 |
newString := firstCharAsLowercase stringSpecies fromString:self. |
9192 | 3428 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3429 |
newString := self stringSpecies fromString:self. |
9192 | 3430 |
]. |
9190 | 3431 |
newString at:1 put:firstCharAsLowercase. |
3432 |
^ newString |
|
608 | 3433 |
|
3434 |
" |
|
8874 | 3435 |
'HelloWorld' asLowercase |
3436 |
'HelloWorld' asLowercaseFirst |
|
608 | 3437 |
" |
3438 |
! |
|
3439 |
||
11828 | 3440 |
asLowercaseLast |
3441 |
"return a copy of myself where the last character is |
|
3442 |
converted to lowercase." |
|
3443 |
||
3444 |
|newString sz| |
|
3445 |
||
3446 |
sz := self size. |
|
3447 |
newString := self copyFrom:1 to:sz. |
|
3448 |
sz > 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3449 |
newString at:sz put:(newString at:sz) asLowercase |
11828 | 3450 |
]. |
3451 |
^ newString |
|
3452 |
||
3453 |
" |
|
12177 | 3454 |
'HelloWorld' asLowercase |
3455 |
'HelloWorlD' asLowercaseLast |
|
11828 | 3456 |
" |
3457 |
! |
|
3458 |
||
17644 | 3459 |
asMutator |
19473 | 3460 |
"return a corresponding setter method's selector. |
3461 |
I.e. #foo asMutator returns #foo:" |
|
17644 | 3462 |
|
3463 |
^ (self asOneByteString,':') asSymbol |
|
3464 |
! |
|
3465 |
||
9190 | 3466 |
asNumber |
3467 |
"read a number from the receiver. |
|
3468 |
Notice, that (in contrast to ST-80) errors may occur during the read, |
|
3469 |
so you better setup some signal handler when using this method. |
|
3470 |
Also notice, that this is meant to read end-user numbers from a string; |
|
9135 | 3471 |
it does not handle smalltalk numbers (i.e. radix). |
3472 |
To read a smalltalk number, use Number >> readSmalltalkFrom:. |
|
608 | 3473 |
This may change if ANSI specifies it." |
3474 |
||
3475 |
"/ ST-80 behavior: |
|
3476 |
"/ ^ Number readFromString:self onError:0 |
|
3477 |
||
17061 | 3478 |
^ Number fromString:self |
3479 |
||
3480 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3481 |
'123' asNumber |
608 | 3482 |
'123.567' asNumber |
3483 |
'(5/6)' asNumber |
|
3484 |
'foo' asNumber |
|
17061 | 3485 |
'123a' asNumber |
8874 | 3486 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] |
608 | 3487 |
" |
9192 | 3488 |
! |
3489 |
||
3490 |
asNumberFromFormatString:ignored |
|
608 | 3491 |
"read a number from the receiver, ignoring any nonDigit characters. |
3492 |
This is typically used to convert from strings which include |
|
3493 |
dollar-signs or millenium digits. However, this method also ignores |
|
3494 |
the decimal point (if any) and therefore should be used with care." |
|
3495 |
||
3496 |
|tempString| |
|
3497 |
||
3498 |
tempString := self collect:[:char | char isDigit]. |
|
3499 |
^ Number readFromString:tempString onError:0 |
|
3500 |
||
3501 |
" |
|
3502 |
'USD 123' asNumberFromFormatString:'foo' |
|
3503 |
'DM 123' asNumberFromFormatString:'foo' |
|
3504 |
'123' asNumberFromFormatString:'foo' |
|
3505 |
'123.567' asNumberFromFormatString:'foo' |
|
3506 |
'(5/6)' asNumberFromFormatString:'foo' |
|
3507 |
'foo' asNumberFromFormatString:'foo' |
|
3508 |
" |
|
9192 | 3509 |
! |
3510 |
||
7977 | 3511 |
asSingleByteStringIfPossible |
3512 |
"if possible, return the receiver converted to a 'normal' string. |
|
18181 | 3513 |
It is only possible, if there are no characters with codePoints above 255 in the receiver. |
3514 |
If not possible, the (wideString) receiver is returned." |
|
7977 | 3515 |
|
14555 | 3516 |
self isWideString ifFalse:[^ self]. |
18967 | 3517 |
self containsNon8BitElements ifTrue:[^ self]. |
3518 |
^ self asSingleByteString |
|
9192 | 3519 |
|
3520 |
" |
|
3521 |
'hello' asSingleByteStringIfPossible |
|
18967 | 3522 |
'hello' asText asSingleByteStringIfPossible |
3523 |
'hello' asUnicodeString asText asSingleByteStringIfPossible |
|
9192 | 3524 |
'hello' asUnicodeString asSingleByteStringIfPossible |
3525 |
" |
|
3526 |
! |
|
3527 |
||
3528 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
|
3529 |
"return the receiver converted to a 'normal' string, |
|
3530 |
with invalid characters replaced by replacementCharacter. |
|
3531 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
3532 |
and replace characters above code-255 with some replacement." |
|
3533 |
||
3534 |
|newString| |
|
3535 |
||
3536 |
newString := String new:(self size). |
|
3537 |
1 to:self size do:[:idx | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3538 |
|char| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3539 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3540 |
char := self at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3541 |
char codePoint <= 16rFF ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3542 |
newString at:idx put:char |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3543 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3544 |
newString at:idx put:replacementCharacter |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3545 |
]. |
9190 | 3546 |
]. |
3547 |
^ newString |
|
3548 |
||
3549 |
"Created: 30.6.1997 / 13:02:14 / cg" |
|
7977 | 3550 |
! |
3551 |
||
9192 | 3552 |
asString |
3553 |
"return myself - I am a string" |
|
3554 |
||
3555 |
^ self |
|
3556 |
! |
|
3557 |
||
3558 |
asStringCollection |
|
3559 |
"return a collection of lines from myself." |
|
3560 |
||
3561 |
^ StringCollection fromString:self "string" |
|
3562 |
||
3563 |
"Modified: 13.5.1996 / 20:36:59 / cg" |
|
3564 |
! |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3565 |
|
1434 | 3566 |
asSymbol |
19039 | 3567 |
"Return a unique symbol with the name taken from the receiver's characters. |
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3568 |
The receiver must be a singleByte-String. |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3569 |
TwoByte- and FourByteSymbols are (currently ?) not allowed." |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3570 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3571 |
|str| |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3572 |
|
9192 | 3573 |
str := self string. |
3574 |
str ~~ self ifTrue:[ ^ str asSymbol ]. |
|
3575 |
^ self asSingleByteString asSymbol |
|
3576 |
! |
|
3577 |
||
3578 |
asSymbolIfInterned |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3579 |
"If a symbol with the receiver's characters is already known, return it. |
19692 | 3580 |
Otherwise, return nil. |
9230 | 3581 |
This can be used to query for an existing symbol and is the same as: |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3582 |
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
|
3583 |
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
|
3584 |
The receiver must be a singleByte-String. |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3585 |
TwoByte- and FourByteSymbols are (currently ?) not allowed." |
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3586 |
|
18967 | 3587 |
|str| |
3588 |
||
3589 |
str := self string. |
|
3590 |
str == self ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3591 |
"must be some kind of N-ByteString" |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3592 |
str := self asSingleByteStringIfPossible. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3593 |
str == self ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3594 |
"single byte string conversion is not possible" |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3595 |
^ nil. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3596 |
]. |
6642 | 3597 |
]. |
18967 | 3598 |
^ str asSymbolIfInterned |
3599 |
||
3600 |
" |
|
3601 |
(Unicode16String with:(Character value:16rFFFF)) asSymbolIfInterned |
|
3602 |
'new' asUnicodeString asSymbolIfInterned |
|
3603 |
'new' asText asSymbolIfInterned |
|
3604 |
'new' asUnicodeString asText asSymbolIfInterned |
|
3605 |
" |
|
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3606 |
|
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3607 |
"Created: 22.5.1996 / 16:37:04 / cg" |
9192 | 3608 |
! |
3609 |
||
3610 |
asText |
|
9403 | 3611 |
"return a Text-object (string with emphasis) from myself." |
9192 | 3612 |
|
3613 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
3614 |
Text isNil ifTrue:[^ self]. |
|
17065 | 3615 |
^ Text string:self |
9192 | 3616 |
|
3617 |
"Created: 12.5.1996 / 10:41:14 / cg" |
|
3618 |
! |
|
3619 |
||
17021 | 3620 |
asTimestamp |
3621 |
"convert the receiver into an Timestamp. |
|
3622 |
Notice, that errors may occur during the read, |
|
3623 |
so you better setup some exception handler when using this method." |
|
3624 |
||
3625 |
^ Timestamp readFromString:self |
|
3626 |
||
3627 |
" |
|
3628 |
'2014-11-10 21:30:22.444' asTimestamp |
|
3629 |
'2014-11-10 21:30:22.444Z' asTimestamp |
|
3630 |
'2014-11-10 21:30:22.444+0200' asTimestamp |
|
3631 |
" |
|
3632 |
! |
|
3633 |
||
9192 | 3634 |
asTitlecase |
8027 | 3635 |
"return a version of the receiver, where the first character is converted to titlecase, |
3636 |
and everything else to lowercase. |
|
3637 |
See the comment in Character on what titlecase is." |
|
3638 |
||
3639 |
|newStr c bitsPerCharacter |
|
3640 |
mySize "{ Class: SmallInteger }" | |
|
3641 |
||
3642 |
mySize := self size. |
|
3643 |
newStr := self species new:mySize. |
|
3644 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
3645 |
||
3646 |
1 to:mySize do:[:i | |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3647 |
i == 1 ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3648 |
c := (self at:i) asTitlecase. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3649 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3650 |
c := (self at:i) asLowercase. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3651 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3652 |
c bitsPerCharacter > bitsPerCharacter ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3653 |
newStr := c stringSpecies fromString:newStr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3654 |
bitsPerCharacter := newStr bitsPerCharacter. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3655 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3656 |
newStr at:i put:c |
8027 | 3657 |
]. |
3658 |
^ newStr |
|
3659 |
||
3660 |
" |
|
8874 | 3661 |
'helloWorld' asTitlecase |
3662 |
'HelloWorld' asTitlecase |
|
3663 |
'HELLOWORLD' asTitlecase |
|
3664 |
'helloworld' asTitlecase |
|
8027 | 3665 |
" |
9192 | 3666 |
! |
3667 |
||
3668 |
asTitlecaseFirst |
|
8023 | 3669 |
"return a version of the receiver, where the first character is converted to titlecase. |
8024 | 3670 |
Titlecase is much like uppercase for most characters, with the exception of some combined |
3671 |
(2-character glyphs), which consist of an upper- and lower-case characters. |
|
3672 |
If the first character is already titlecase, or there is no titlecasepercase for it, return the |
|
8023 | 3673 |
receiver." |
3674 |
||
8026 | 3675 |
" |
8874 | 3676 |
For example, in Unicode, character U+01F3 is LATIN SMALL LETTER DZ. |
3677 |
(Let us write this compound character using ASCII as 'dz'.) |
|
3678 |
This character uppercases to character U+01F1, LATIN CAPITAL LETTER DZ. |
|
3679 |
(Which is basically 'DZ'.) |
|
3680 |
But it titlecases to to character U+01F2, LATIN CAPITAL LETTER D WITH SMALL LETTER Z. |
|
8026 | 3681 |
(Which we can write 'Dz'.) |
3682 |
||
3683 |
character uppercase titlecase |
|
3684 |
--------- --------- --------- |
|
3685 |
dz DZ Dz |
|
3686 |
" |
|
3687 |
||
8023 | 3688 |
|newString firstChar firstCharAsTitlecase| |
3689 |
||
3690 |
firstChar := (self at:1). |
|
8025 | 3691 |
firstCharAsTitlecase := firstChar asTitlecase. |
8023 | 3692 |
firstChar == firstCharAsTitlecase ifTrue:[ ^ self]. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3693 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3694 |
firstCharAsTitlecase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3695 |
newString := firstCharAsTitlecase stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3696 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3697 |
newString := self stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3698 |
]. |
8023 | 3699 |
newString at:1 put:firstCharAsTitlecase. |
3700 |
^ newString |
|
3701 |
||
3702 |
" |
|
8874 | 3703 |
'helloWorld' asTitlecaseFirst |
3704 |
'HelloWorld' asTitlecaseFirst |
|
8023 | 3705 |
" |
9192 | 3706 |
! |
3707 |
||
3708 |
asTwoByteString |
|
3709 |
"return the receiver converted to a two-byte string. |
|
16051 | 3710 |
Will be obsolete soon - use asUnicode16String." |
9192 | 3711 |
|
3712 |
^ TwoByteString fromString:self |
|
3713 |
! |
|
3714 |
||
3715 |
asURI |
|
3716 |
"return an URI with string taken from the receiver" |
|
3717 |
||
3718 |
^ URI fromString:self |
|
3719 |
! |
|
8710 | 3720 |
|
5776 | 3721 |
asURL |
3722 |
"return an URL-object from myself." |
|
3723 |
||
3724 |
^ URL fromString:self |
|
3725 |
||
3726 |
" |
|
8874 | 3727 |
'http://www.exept.de:80/index.html' asURL host |
3728 |
'http://www.exept.de:80/index.html' asURL port |
|
9192 | 3729 |
'http://www.exept.de:80/index.html' asURL method |
3730 |
'http://www.exept.de:80/index.html' asURL path |
|
3731 |
" |
|
3732 |
! |
|
3733 |
||
18901 | 3734 |
asUUID |
3735 |
"return self as a UUID" |
|
3736 |
||
3737 |
^ UUID fromString:self |
|
3738 |
||
3739 |
" |
|
3740 |
UUID genUUID asString asUUID |
|
3741 |
'{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' asUUID |
|
3742 |
'{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' asUnicodeString asUUID |
|
3743 |
'EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B' asUUID |
|
3744 |
'EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B quatsch' asUUID |
|
3745 |
'quark EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B' asUUID |
|
3746 |
" |
|
3747 |
||
3748 |
"Modified: / 02-08-2007 / 16:43:29 / cg" |
|
3749 |
! |
|
3750 |
||
9192 | 3751 |
asUnicode16String |
15035 | 3752 |
"return the receiver in a two-byte per character representation. |
3753 |
Normally, the internal ST/X representation should be transparent and not |
|
3754 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3755 |
such as wide-string ffi calls or file contents." |
|
3756 |
||
17600 | 3757 |
|sz| |
3758 |
||
3759 |
sz := self size. |
|
3760 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3761 |
^ (Unicode16String new:sz) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3762 |
replaceFrom:1 to:sz with:self startingAt:1; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3763 |
yourself. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3764 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3765 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3766 |
'abc' asUnicode16String |
17600 | 3767 |
" |
3768 |
! |
|
3769 |
||
3770 |
asUnicode16StringZ |
|
3771 |
"return the receiver in a two-byte per character representation. |
|
17625 | 3772 |
Make sure that is zero terminated (last char is 16r0000). |
17600 | 3773 |
Normally, the internal ST/X representation should be transparent and not |
3774 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3775 |
such as wide-string ffi calls or file contents." |
|
3776 |
||
3777 |
|sz| |
|
3778 |
||
3779 |
sz := self size. |
|
3780 |
(self at:sz) == (Character codePoint:0) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3781 |
^ self asUnicode16String. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3782 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3783 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3784 |
^ (Unicode16String new:sz+1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3785 |
replaceFrom:1 to:sz with:self startingAt:1; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3786 |
at:sz+1 put:(Character codePoint:0); |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3787 |
yourself. |
17600 | 3788 |
|
3789 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3790 |
'abc' asUnicode16StringZ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3791 |
'abc' asUnicode16String asUnicode16StringZ |
17600 | 3792 |
" |
9192 | 3793 |
! |
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3794 |
|
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3795 |
asUnicode32String |
16051 | 3796 |
"return the receiver in a four-byte per character representation. |
3797 |
Normally, the internal ST/X representation should be transparent and not |
|
3798 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3799 |
such as wide-string ffi calls or file contents." |
|
3800 |
||
3801 |
^ self as:Unicode32String |
|
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3802 |
! |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3803 |
|
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3804 |
asUnicodeString |
16051 | 3805 |
"return the receiver in a two-byte per character representation. |
3806 |
Normally, the internal ST/X representation should be transparent and not |
|
3807 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3808 |
such as wide-string ffi calls or file contents." |
|
3809 |
||
3810 |
^ self asUnicode16String |
|
3811 |
" |
|
3812 |
'Hello World' asUnicodeString |
|
14141
e86d245213b0
comment/format in: #asUnicodeString
Stefan Vogel <sv@exept.de>
parents:
14137
diff
changeset
|
3813 |
" |
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3814 |
! |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3815 |
|
13073 | 3816 |
asUnixFilename |
3817 |
"return a UnixFilename with pathname taken from the receiver" |
|
3818 |
||
3819 |
^ UnixFilename named:self |
|
3820 |
||
3821 |
"Created: / 20-09-2010 / 21:42:55 / cg" |
|
3822 |
! |
|
3823 |
||
608 | 3824 |
asUppercase |
3825 |
"return a copy of myself in uppercase letters" |
|
3826 |
||
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3827 |
|newStr c bitsPerCharacter |
608 | 3828 |
mySize "{ Class: SmallInteger }" | |
3829 |
||
3830 |
mySize := self size. |
|
8954
12e701d7b5ac
allow for receiver to be empty in asLowercase and asUppercase.
Claus Gittinger <cg@exept.de>
parents:
8938
diff
changeset
|
3831 |
mySize == 0 ifTrue:[^ self]. |
608 | 3832 |
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
|
3833 |
bitsPerCharacter := newStr bitsPerCharacter. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3834 |
|
18657 | 3835 |
"/ handle the very seldom case of a lowercase char which needs |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3836 |
"/ more bits in its uppercase variant |
18657 | 3837 |
"/ (there are only a few of them) |
3838 |
||
608 | 3839 |
1 to:mySize do:[:i | |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3840 |
c := (self at:i) asUppercase. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3841 |
c bitsPerCharacter > bitsPerCharacter ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3842 |
newStr := c stringSpecies fromString:newStr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3843 |
bitsPerCharacter := newStr bitsPerCharacter. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3844 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3845 |
newStr at:i put:c |
608 | 3846 |
]. |
3847 |
^ newStr |
|
3848 |
||
3849 |
" |
|
8874 | 3850 |
'helloWorld' asUppercase |
3851 |
'helloWorld' asUppercaseFirst |
|
9192 | 3852 |
(Character value:16rB5) asString asUppercase -- needs 16 bits !! |
18657 | 3853 |
(Character value:16rFF) asString asUppercase -- needs 16 bits !! |
9192 | 3854 |
" |
3855 |
! |
|
3856 |
||
3857 |
asUppercaseFirst |
|
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3858 |
"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
|
3859 |
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
|
3860 |
receiver." |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3861 |
|
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3862 |
|newString firstChar firstCharAsUppercase| |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3863 |
|
12679 | 3864 |
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
|
3865 |
firstChar := self at:1. |
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3866 |
firstCharAsUppercase := firstChar asUppercase. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3867 |
firstChar == firstCharAsUppercase ifTrue:[ ^ self]. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3868 |
|
12679 | 3869 |
"/ 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
|
3870 |
firstCharAsUppercase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3871 |
newString := firstCharAsUppercase stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3872 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3873 |
newString := self stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3874 |
]. |
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3875 |
newString at:1 put:firstCharAsUppercase. |
608 | 3876 |
^ newString |
3877 |
||
3878 |
" |
|
8874 | 3879 |
'helloWorld' asUppercase |
3880 |
'helloWorld' asUppercaseFirst |
|
3881 |
'HelloWorld' asUppercaseFirst |
|
608 | 3882 |
" |
9192 | 3883 |
! |
3884 |
||
11828 | 3885 |
asUppercaseLast |
3886 |
"return a copy of myself where the last character is |
|
3887 |
converted to uppercase." |
|
3888 |
||
3889 |
|newString sz| |
|
3890 |
||
3891 |
sz := self size. |
|
3892 |
newString := self copyFrom:1 to:sz. |
|
3893 |
sz > 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3894 |
newString at:sz put:(newString at:sz) asUppercase |
11828 | 3895 |
]. |
3896 |
^ newString |
|
3897 |
||
3898 |
" |
|
12177 | 3899 |
'HelloWorld' asUppercase |
3900 |
'HelloWorld' asUppercaseLast |
|
11828 | 3901 |
" |
3902 |
! |
|
3903 |
||
17021 | 3904 |
asUtcTimestamp |
3905 |
"convert the receiver into an UtcTimestamp (Time is interpreted in the UTC timezone). |
|
3906 |
Notice, that errors may occur during the read, |
|
3907 |
so you better setup some exception handler when using this method." |
|
3908 |
||
3909 |
^ UtcTimestamp readFromString:self |
|
3910 |
||
3911 |
" |
|
3912 |
'2014-11-10 21:30:22.444' asUtcTimestamp |
|
3913 |
" |
|
3914 |
! |
|
3915 |
||
11062 | 3916 |
literalArrayEncoding |
3917 |
"encode myself as an array literal, from which a copy of the receiver |
|
3918 |
can be reconstructed with #decodeAsLiteralArray." |
|
3919 |
||
3920 |
^ self |
|
3921 |
||
3922 |
"Modified: 1.9.1995 / 02:25:45 / claus" |
|
3923 |
"Modified: 22.4.1996 / 13:00:50 / cg" |
|
3924 |
! |
|
3925 |
||
9192 | 3926 |
string |
3927 |
"return the receiver - for ST-80 compatibility" |
|
3928 |
||
3929 |
^ self |
|
3930 |
||
3931 |
"Modified: 27.4.1996 / 13:29:30 / cg" |
|
3932 |
! ! |
|
3933 |
||
3934 |
!CharacterArray methodsFor:'copying'! |
|
3935 |
||
3936 |
, aStringOrCharacter |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3937 |
"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
|
3938 |
This is nonStandard, but convenient" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3939 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3940 |
|myWidth otherWidth| |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3941 |
|
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3942 |
aStringOrCharacter isCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3943 |
^ self copyWith:aStringOrCharacter |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3944 |
]. |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3945 |
aStringOrCharacter isText ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3946 |
^ aStringOrCharacter concatenateFromString:self |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3947 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3948 |
aStringOrCharacter isString ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3949 |
(otherWidth := aStringOrCharacter bitsPerCharacter) ~~ (myWidth := self bitsPerCharacter) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3950 |
otherWidth > myWidth ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3951 |
^ (aStringOrCharacter species fromString:self) , aStringOrCharacter |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3952 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3953 |
^ self , (self species fromString:aStringOrCharacter) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3954 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3955 |
]. |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3956 |
^ super , aStringOrCharacter |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3957 |
|
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3958 |
" |
8874 | 3959 |
'hello' , $1 |
3960 |
'hello' , '1' |
|
3961 |
'hello' , (' world' asText allBold) |
|
3962 |
'hello' , (JISEncodedString fromString:' world') |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3963 |
(JISEncodedString fromString:'hello') , ' world' |
1411 | 3964 |
|
1422 | 3965 |
Transcript showCR: |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3966 |
(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
|
3967 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3968 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3969 |
"Modified: 28.6.1997 / 00:13:17 / cg" |
9192 | 3970 |
! |
3971 |
||
3972 |
,, aString |
|
7020 | 3973 |
"concatenate with a newLine in between" |
6965 | 3974 |
|
3975 |
^ (self copyWith:Character cr) , aString |
|
3976 |
||
3977 |
" |
|
3978 |
hello ,, world |
|
7020 | 3979 |
'hello' ,, 'world' |
6965 | 3980 |
" |
3981 |
! |
|
3982 |
||
11329 | 3983 |
chopTo:maxLen |
19464 | 3984 |
"if the receiver's size is less or equal to maxLen, return it. |
11329 | 3985 |
Otherwise, return a copy of the receiver, where some characters |
3986 |
in the middle have been removed for a total string length |
|
3987 |
of maxLen." |
|
3988 |
||
3989 |
|sz n1 n2| |
|
3990 |
||
3991 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3992 |
||
3993 |
n1 := n2 := maxLen // 2. |
|
3994 |
maxLen odd ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
3995 |
n2 := n1 + 1 |
11329 | 3996 |
]. |
3997 |
^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1) |
|
3998 |
||
3999 |
" |
|
4000 |
'12345678901234' chopTo:15 |
|
4001 |
'123456789012345' chopTo:15 |
|
4002 |
'1234567890123456' chopTo:15 |
|
4003 |
'aShortString' chopTo:15 |
|
4004 |
'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 |
|
4005 |
" |
|
4006 |
||
4007 |
"Modified: / 24-10-2006 / 12:32:01 / cg" |
|
4008 |
! |
|
4009 |
||
4010 |
contractAtBeginningTo:maxLen |
|
19464 | 4011 |
"if the receiver's size is less or equal to maxLen, return it. |
11329 | 4012 |
Otherwise, return a copy of the receiver, where some characters |
4013 |
at the beginning have been replaced by '...' for a total string length |
|
4014 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
4015 |
||
4016 |
|sz| |
|
4017 |
||
4018 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
4019 |
||
4020 |
^ '...' , (self copyFrom:(sz - (maxLen - 4))) |
|
4021 |
||
4022 |
" |
|
4023 |
'12345678901234' contractAtBeginningTo:15 |
|
4024 |
'123456789012345' contractAtBeginningTo:15 |
|
4025 |
'1234567890123456' contractAtBeginningTo:15 |
|
4026 |
'aShortString' contractAtBeginningTo:15 |
|
4027 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15 |
|
4028 |
" |
|
4029 |
||
4030 |
"Modified: / 24-10-2006 / 12:32:13 / cg" |
|
4031 |
! |
|
4032 |
||
4033 |
contractAtEndTo:maxLen |
|
19464 | 4034 |
"if the receiver's size is less or equal to maxLen, return it. |
11329 | 4035 |
Otherwise, return a copy of the receiver, where some characters |
4036 |
at the end have been replaced by '...' for a total string length |
|
4037 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
4038 |
||
4039 |
|sz| |
|
4040 |
||
4041 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
4042 |
||
4043 |
^ (self copyTo:maxLen-3),'...' |
|
4044 |
||
4045 |
" |
|
4046 |
'12345678901234' contractAtEndTo:15 |
|
4047 |
'123456789012345' contractAtEndTo:15 |
|
4048 |
'1234567890123456' contractAtEndTo:15 |
|
4049 |
'aShortString' contractAtEndTo:15 |
|
4050 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 |
|
4051 |
" |
|
4052 |
||
4053 |
"Modified: / 24-10-2006 / 12:32:26 / cg" |
|
4054 |
! |
|
4055 |
||
4056 |
contractLeftTo:maxLen |
|
19464 | 4057 |
"if the receiver's size is less or equal to maxLen, return it. |
11329 | 4058 |
Otherwise, return a copy of the receiver, where some characters |
4059 |
near the first quarter have been replaced by '...' for a total string length |
|
12177 | 4060 |
of maxLen. |
4061 |
Very similar to contractTo:, but better to abbreviate long filename entries, |
|
11329 | 4062 |
where the right part is of more use than the left." |
4063 |
||
4064 |
|sz "{ SmallInteger }" |
|
4065 |
halfSize quarterSize "{ SmallInteger }" |
|
4066 |
leftEnd rightEnd rightStart| |
|
4067 |
||
4068 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
4069 |
||
4070 |
halfSize := maxLen // 2. |
|
4071 |
quarterSize := maxLen // 4. |
|
4072 |
leftEnd := quarterSize-1. |
|
4073 |
rightEnd := maxLen - leftEnd - 3. |
|
4074 |
rightStart := sz - rightEnd + 1. |
|
4075 |
^ (self copyTo:leftEnd),'...',(self copyFrom:rightStart) |
|
4076 |
||
4077 |
" |
|
12177 | 4078 |
'12345678901234' contractLeftTo:15 |
4079 |
'123456789012345' contractLeftTo:15 |
|
4080 |
'1234567890123456' contractLeftTo:15 |
|
4081 |
'aShortString' contractLeftTo:15 |
|
4082 |
'aVeryLongNameForAStringThatShouldBeShortened' contractLeftTo:15 |
|
11329 | 4083 |
'C:\Dokumente und Einstellungen\cg\work\bosch\dapas\hw_schnittstellen\DAPAS__HpibDLL.st' contractLeftTo:40 |
4084 |
" |
|
4085 |
! |
|
4086 |
||
4087 |
contractTo:maxLen |
|
19464 | 4088 |
"if the receiver's size is less or equal to maxLen, return it. |
11329 | 4089 |
Otherwise, return a copy of the receiver, where some characters |
4090 |
in the middle have been replaced by '...' for a total string length |
|
4091 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
4092 |
||
13362 | 4093 |
|sz "{ SmallInteger }" leftSize rightSize| |
11329 | 4094 |
|
4095 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
4096 |
||
13362 | 4097 |
rightSize := maxLen // 2. |
4098 |
leftSize := maxLen - rightSize. |
|
13822 | 4099 |
leftSize := leftSize - 2. |
4100 |
rightSize := rightSize - 1. |
|
13362 | 4101 |
^ (self copyTo:leftSize),'...',(self copyFrom:(sz+1-rightSize)) |
4102 |
||
4103 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
4104 |
'12345678901234' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
4105 |
'123456789012345' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
4106 |
'1234567890123456' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
4107 |
'12345678901234567' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
4108 |
'123456789012345678' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
4109 |
'aShortString' contractTo:15 |
11329 | 4110 |
'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 |
4111 |
'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
|
4112 |
('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
|
4113 |
('1234567890123456789012345678901234567' contractTo:29) size |
13362 | 4114 |
" |
4115 |
||
13822 | 4116 |
"Modified (comment): / 24-11-2011 / 19:17:46 / cg" |
11329 | 4117 |
! |
4118 |
||
16202 | 4119 |
copyReplaceAll:oldElement with:newElement |
4120 |
"return a copy of the receiver as a string, where all elements equal to oldElement |
|
4121 |
have been replaced by newElement." |
|
4122 |
||
4123 |
"/ ANSI seems to allow a sequence to be replaced by another sequence, |
|
4124 |
"/ whereas the old ST80 meant replace all occurrences... - sigh. |
|
4125 |
oldElement isByteCollection ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4126 |
newElement isByteCollection ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4127 |
^ self copyReplaceString:oldElement withString:newElement. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4128 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4129 |
self halt:'check if this is legal'. |
16202 | 4130 |
]. |
4131 |
newElement isByteCollection ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4132 |
self halt:'check if this is legal'. |
16202 | 4133 |
]. |
16212 | 4134 |
^ super copyReplaceAll:oldElement with:newElement |
16202 | 4135 |
! |
4136 |
||
8347 | 4137 |
copyReplaceString:subString withString:newString |
4138 |
"return a copy of the receiver, with all sequences of subString replaced |
|
4139 |
by newString (i.e. slice in the newString in place of the oldString)." |
|
4140 |
||
4141 |
|tmpStream idx idx1| |
|
4142 |
||
15523 | 4143 |
tmpStream := self species writeStream. |
8347 | 4144 |
idx := 1. |
4145 |
[idx ~~ 0] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4146 |
idx1 := idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4147 |
idx := self indexOfSubCollection:subString startingAt:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4148 |
idx ~~ 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4149 |
tmpStream nextPutAll:(self copyFrom:idx1 to:idx-1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4150 |
tmpStream nextPutAll:newString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4151 |
idx := idx + subString size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4152 |
] |
8347 | 4153 |
]. |
4154 |
tmpStream nextPutAll:(self copyFrom:idx1). |
|
4155 |
^ tmpStream contents |
|
4156 |
||
4157 |
" |
|
9306 | 4158 |
'12345678901234567890' copyReplaceString:'123' withString:'OneTwoThree' |
4159 |
'12345678901234567890' copyReplaceString:'123' withString:'*' |
|
4160 |
'12345678901234567890' copyReplaceString:'234' withString:'foo' |
|
4161 |
||
4162 |
('a string with spaces' copyReplaceAll:$ withAll:' foo ') |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4163 |
copyReplaceString:'foo' withString:'bar' |
8347 | 4164 |
" |
4165 |
||
4166 |
"Modified: / 31-05-1999 / 12:33:59 / cg" |
|
4167 |
"Created: / 12-05-2004 / 12:00:00 / cg" |
|
4168 |
! |
|
4169 |
||
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
4170 |
copyWith:aCharacter |
19464 | 4171 |
"return a new string containing the receiver's characters |
8874 | 4172 |
and the single new character, aCharacter. |
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
4173 |
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
|
4174 |
as argument, but equivalent to copy-and-addLast. |
8874 | 4175 |
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
|
4176 |
(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
|
4177 |
|
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
4178 |
|sz newString| |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
4179 |
|
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
4180 |
aCharacter bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
4181 |
sz := self size. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
4182 |
newString := aCharacter stringSpecies new:sz + 1. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
4183 |
newString replaceFrom:1 to:sz with:self startingAt:1. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
4184 |
newString at:sz+1 put:aCharacter. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
4185 |
^ newString. |
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
4186 |
]. |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
4187 |
^ super copyWith:aCharacter |
17241 | 4188 |
! |
4189 |
||
4190 |
restAfter:keyword withoutSeparators:strip |
|
4191 |
"compare the left of the receiver with keyword, |
|
4192 |
if it matches return the right. |
|
4193 |
Finally, if strip is true, remove whiteSpace. |
|
4194 |
This method is used to match and extract lines of the form: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4195 |
something: rest |
17241 | 4196 |
where we are interested in rest, but only if the receiver string |
4197 |
begins with something. |
|
4198 |
||
4199 |
You may wonder why such a specialized method exists here |
|
4200 |
- this is so common when processing mailboxes, |
|
4201 |
rcs files, nntp/pop3 responses, that is was considered worth |
|
4202 |
a special method here to avoid having the code below a hundred |
|
4203 |
times in variuos places." |
|
4204 |
||
4205 |
|rest| |
|
4206 |
||
4207 |
(self startsWith:keyword) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4208 |
rest := self copyFrom:(keyword size + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4209 |
strip ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4210 |
rest := rest withoutSeparators |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4211 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4212 |
^ rest |
17241 | 4213 |
]. |
4214 |
^ nil |
|
4215 |
||
4216 |
" |
|
4217 |
'foo: hello world' restAfter:'foo:' withoutSeparators:true |
|
4218 |
'funny: something' restAfter:'foo:' withoutSeparators:true |
|
4219 |
||
4220 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:true |
|
4221 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:false |
|
4222 |
" |
|
4223 |
||
4224 |
"Created: 25.11.1995 / 11:04:18 / cg" |
|
4225 |
! |
|
4226 |
||
4227 |
splitAtString:subString withoutSeparators:strip |
|
4228 |
"If the receiver is of the form: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4229 |
<left><subString><right> |
17241 | 4230 |
return a collection containing left and right only. |
4231 |
If strip is true, remove whiteSpace in the returned substrings." |
|
4232 |
||
4233 |
|idx left right| |
|
4234 |
||
4235 |
(idx := self indexOfSubCollection:subString) ~~ 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4236 |
left := self copyTo:(idx - 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4237 |
right := self copyFrom:(idx + subString size). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4238 |
strip ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4239 |
left := left withoutSeparators. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4240 |
right := right withoutSeparators. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4241 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4242 |
^ StringCollection with:left with:right |
17241 | 4243 |
]. |
4244 |
self error:'substring not present in receiver' mayProceed:true. |
|
4245 |
^ self |
|
4246 |
||
4247 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4248 |
'hello -> world' splitAtString:'->' withoutSeparators:false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4249 |
'hello -> world' splitAtString:'->' withoutSeparators:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4250 |
'hello -> ' splitAtString:'->' withoutSeparators:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4251 |
'hello > error' splitAtString:'->' withoutSeparators:true |
17241 | 4252 |
" |
4253 |
||
4254 |
"Created: 25.11.1995 / 11:04:18 / cg" |
|
608 | 4255 |
! ! |
4256 |
||
4257 |
!CharacterArray methodsFor:'displaying'! |
|
4258 |
||
2762 | 4259 |
displayOn:aGC x:x y:y from:start to:stop |
4260 |
"display the receiver on a GC" |
|
4261 |
||
12171 | 4262 |
self displayOn:aGC x:x y:y from:start to:stop opaque:false |
4263 |
||
4264 |
"Modified: 12.5.1996 / 12:49:33 / cg" |
|
4265 |
! |
|
4266 |
||
4267 |
displayOn:aGC x:x y:y from:start to:stop opaque:opaque |
|
4268 |
"display the receiver on a GC" |
|
4269 |
||
2762 | 4270 |
"q&d hack" |
4271 |
||
12177 | 4272 |
(start == 1 and:[stop == self size]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4273 |
self displayOn:aGC x:x y:y opaque:opaque. |
12177 | 4274 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4275 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:opaque. |
12177 | 4276 |
]. |
2762 | 4277 |
! |
4278 |
||
7082 | 4279 |
displayOn:aGc x:x y:y opaque:opaque |
2762 | 4280 |
"display the receiver in a graphicsContext - this method allows |
4281 |
strings to be used like DisplayObjects." |
|
4282 |
||
4283 |
|s| |
|
4284 |
||
4285 |
s := self string. |
|
7082 | 4286 |
opaque ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4287 |
aGc displayOpaqueString:s x:x y:y. |
2762 | 4288 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4289 |
aGc displayString:s x:x y:y. |
2762 | 4290 |
]. |
1381 | 4291 |
|
4292 |
"Modified: 11.5.1996 / 14:42:48 / cg" |
|
4293 |
! |
|
4294 |
||
2762 | 4295 |
displayOpaqueOn:aGC x:x y:y from:start to:stop |
4296 |
"display the receiver on a GC" |
|
4297 |
||
12171 | 4298 |
self displayOn:aGC x:x y:y from:start to:stop opaque:true |
608 | 4299 |
! ! |
4300 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4301 |
!CharacterArray methodsFor:'emphasis'! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4302 |
|
11632
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4303 |
actionForAll:aBlock |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4304 |
"change the action block of all characters. |
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4305 |
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
|
4306 |
|
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4307 |
^ self asText actionForAll:aBlock |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4308 |
! |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4309 |
|
5732 | 4310 |
allBold |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4311 |
"return a text object representing the receiver, but all boldified" |
5732 | 4312 |
|
8874 | 4313 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
6187 | 4314 |
Text isNil ifTrue:[^ self]. |
5732 | 4315 |
^ self asText allBold |
4316 |
||
4317 |
" |
|
4318 |
Transcript showCR:'hello' asText allBold |
|
4319 |
Transcript showCR:'hello' allBold |
|
4320 |
" |
|
4321 |
! |
|
4322 |
||
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4323 |
allItalic |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4324 |
"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
|
4325 |
|
8874 | 4326 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
6187 | 4327 |
Text isNil ifTrue:[^ self]. |
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4328 |
^ self asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4329 |
|
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4330 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4331 |
Transcript showCR:'hello' asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4332 |
Transcript showCR:'hello' allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4333 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4334 |
! |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4335 |
|
11345 | 4336 |
allStrikedOut |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4337 |
"return a text object representing the receiver, but all in strikeout" |
11345 | 4338 |
|
4339 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
4340 |
Text isNil ifTrue:[^ self]. |
|
4341 |
^ self asText allStrikedOut |
|
4342 |
||
4343 |
" |
|
4344 |
Transcript showCR:'hello' asText allStrikedOut |
|
4345 |
Transcript showCR:'hello' allStrikedOut |
|
4346 |
" |
|
4347 |
! |
|
4348 |
||
10862 | 4349 |
allUnderlined |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4350 |
"return a text object representing the receiver, but all with underline" |
10862 | 4351 |
|
4352 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
4353 |
Text isNil ifTrue:[^ self]. |
|
4354 |
^ self asText allUnderlined |
|
4355 |
||
4356 |
" |
|
4357 |
Transcript showCR:'hello' asText allUnderlined |
|
4358 |
Transcript showCR:'hello' allUnderlined |
|
4359 |
" |
|
4360 |
! |
|
4361 |
||
19774 | 4362 |
asActionLinkTo:aBlock |
4363 |
"change the action block of all characters and colorize as a link. |
|
4364 |
Some widgets use this like a href if clicked onto the text |
|
4365 |
(for example, the system-browser's info at the bottom is such a widget)." |
|
4366 |
||
4367 |
"/ the blue may become a user-setting some time later.. |
|
4368 |
^ (self actionForAll:aBlock) withColor:(Color blue) |
|
4369 |
! |
|
4370 |
||
6228 | 4371 |
colorizeAllWith:aColor |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4372 |
"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
|
4373 |
|
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4374 |
"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
|
4375 |
Text isNil ifTrue:[^ self]. |
6228 | 4376 |
^ self asText colorizeAllWith:aColor |
4377 |
||
4378 |
" |
|
4379 |
Transcript showCR:('hello' colorizeAllWith:Color red) |
|
4380 |
Transcript showCR:('world' colorizeAllWith:Color green darkened) |
|
4381 |
" |
|
4382 |
! |
|
4383 |
||
12330
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4384 |
colorizeAllWith:fgColor on:bgColor |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4385 |
"return a text object representing the receiver, but all colorized with |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4386 |
both fg and background color" |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4387 |
|
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4388 |
"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
|
4389 |
Text isNil ifTrue:[^ self]. |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4390 |
^ self asText colorizeAllWith:fgColor on:bgColor |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4391 |
|
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4392 |
" |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4393 |
Transcript showCR:('hello' colorizeAllWith:Color red on:Color yellow) |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4394 |
Transcript showCR:('world' colorizeAllWith:Color red) |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4395 |
" |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4396 |
! |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4397 |
|
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4398 |
emphasis |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4399 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4400 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4401 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4402 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4403 |
^ RunArray new:self size withAll:nil |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4404 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4405 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4406 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4407 |
|
6655 | 4408 |
emphasis:emphasisCollection |
4409 |
^ self asText emphasis:emphasisCollection |
|
4410 |
||
4411 |
" |
|
4412 |
Transcript showCR:('hello' emphasis:#(bold bold bold bold bold)) |
|
4413 |
" |
|
4414 |
! |
|
4415 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4416 |
emphasisAt:characterIndex |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4417 |
"return the emphasis at some index. |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4418 |
Since characterArrays do not hold any emphasis information, |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4419 |
nil (no emphasis) is returned here." |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4420 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4421 |
^ nil |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4422 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4423 |
"Created: 11.5.1996 / 14:13:27 / cg" |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4424 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4425 |
|
11632
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4426 |
emphasisAtPoint:aPoint on:aGC |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4427 |
"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
|
4428 |
|
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4429 |
^ nil |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4430 |
! |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4431 |
|
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4432 |
emphasisCollection |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4433 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4434 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4435 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4436 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4437 |
^ RunArray new:(self size) |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4438 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4439 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4440 |
"Modified: 14.5.1996 / 15:02:29 / cg" |
3404 | 4441 |
! |
4442 |
||
11919 | 4443 |
emphasiseFrom:start to:stop with:newEmphasis |
4444 |
"set to the emphasis within some range. return the receiver" |
|
4445 |
||
4446 |
^ self asText emphasiseFrom:start to:stop with:newEmphasis |
|
4447 |
||
4448 |
" |
|
12177 | 4449 |
'hello' emphasiseFrom:2 with:#italic |
11919 | 4450 |
|
4451 |
Transcript showCR:('hello' emphasiseFrom:2 with:#italic) |
|
4452 |
" |
|
4453 |
! |
|
4454 |
||
4455 |
emphasiseFrom:start with:newEmphasis |
|
4456 |
"set to the emphasis within some range. return the receiver" |
|
4457 |
||
4458 |
^ self emphasiseFrom:start to:(self size) with:newEmphasis |
|
4459 |
||
4460 |
" |
|
12177 | 4461 |
'hello' emphasiseFrom:2 with:#italic |
11919 | 4462 |
|
4463 |
Transcript showCR:('hello' emphasiseFrom:2 with:#italic) |
|
4464 |
" |
|
4465 |
! |
|
4466 |
||
3404 | 4467 |
emphasizeAllWith:emphasis |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4468 |
"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
|
4469 |
|
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4470 |
"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
|
4471 |
Text isNil ifTrue:[^ self]. |
3404 | 4472 |
^ self asText emphasizeAllWith:emphasis |
4473 |
||
4474 |
" |
|
4475 |
Transcript showCR:('hello' emphasizeAllWith:#bold) |
|
3599 | 4476 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
4477 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
|
4478 |
" |
|
4479 |
||
4480 |
"Modified: / 17.6.1998 / 12:51:44 / cg" |
|
5097 | 4481 |
! |
4482 |
||
4483 |
makeSelectorBoldIn:aClass |
|
14050 | 4484 |
"the receiver represents some source code for a method in aClass. |
5097 | 4485 |
Change myself to boldify the selector. |
14050 | 4486 |
Not yet implemented (could easily use the syntaxHighlighter for this ...). |
4487 |
For protocol compatibility with other smalltalks" |
|
5097 | 4488 |
|
4489 |
^ self |
|
4490 |
||
14050 | 4491 |
"Created: / 13-12-1999 / 21:49:24 / cg" |
4492 |
! |
|
4493 |
||
19762 | 4494 |
withColor:aColorOrColorSymbol |
16697 | 4495 |
"return a text object representing the receiver, but all colorized" |
4496 |
||
19762 | 4497 |
aColorOrColorSymbol isSymbol ifTrue:[ |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
4498 |
^ self colorizeAllWith:(Color perform:aColorOrColorSymbol) |
19762 | 4499 |
]. |
4500 |
^ self colorizeAllWith:aColorOrColorSymbol |
|
4501 |
||
4502 |
" |
|
4503 |
Transcript showCR:('hello' withColor:#red) |
|
16697 | 4504 |
Transcript showCR:('hello' withColor:Color red) |
4505 |
Transcript showCR:('world' withColor:Color green darkened) |
|
4506 |
" |
|
4507 |
! |
|
4508 |
||
14050 | 4509 |
withoutAnyColorEmphasis |
4510 |
"for protocol compatibility with Text" |
|
4511 |
||
4512 |
^ self |
|
4513 |
||
4514 |
"Created: / 06-03-2012 / 18:15:38 / cg" |
|
6653 | 4515 |
! |
4516 |
||
12396 | 4517 |
withoutBackgroundColorEmphasis |
14050 | 4518 |
"for protocol compatibility with Text" |
4519 |
||
12396 | 4520 |
^ self |
14050 | 4521 |
|
4522 |
"Modified (comment): / 06-03-2012 / 18:14:27 / cg" |
|
12396 | 4523 |
! |
4524 |
||
6653 | 4525 |
withoutEmphasis:emphasisToRemove |
14050 | 4526 |
"for protocol compatibility with Text" |
4527 |
||
6653 | 4528 |
^ self |
14050 | 4529 |
|
4530 |
"Modified (comment): / 06-03-2012 / 18:14:29 / cg" |
|
12396 | 4531 |
! |
4532 |
||
4533 |
withoutForegroundColorEmphasis |
|
14050 | 4534 |
"for protocol compatibility with Text" |
4535 |
||
12396 | 4536 |
^ self |
14050 | 4537 |
|
4538 |
"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
|
4539 |
! ! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4540 |
|
7265 | 4541 |
!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
|
4542 |
|
12767
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4543 |
decodeAsLiteralArray |
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4544 |
"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
|
4545 |
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
|
4546 |
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
|
4547 |
|
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4548 |
^ self |
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4549 |
! |
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4550 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4551 |
decodeFrom:encodingSymbol |
8874 | 4552 |
"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
|
4553 |
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
|
4554 |
|
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
4555 |
|myEncoding encoder| |
7950 | 4556 |
|
4557 |
encodingSymbol isNil ifTrue:[^ self]. |
|
4558 |
myEncoding := self encoding. |
|
4559 |
encodingSymbol == myEncoding ifTrue:[^ self]. |
|
4560 |
||
4561 |
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
|
4562 |
encoder isNil ifTrue:[^ self]. |
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
4563 |
^ 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
|
4564 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4565 |
|
9192 | 4566 |
encodeFrom:oldEncoding into:newEncoding |
4567 |
^ CharacterEncoder encodeString:self from:oldEncoding into:newEncoding |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
4568 |
|
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
4569 |
" |
17600 | 4570 |
'äüö' encodeFrom:#iso8859 into:#utf8 |
4571 |
('äüö' encodeFrom:#iso8859 into:#utf8) encodeFrom:#utf8 into:#unicode |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
4572 |
" |
9192 | 4573 |
! |
4574 |
||
4575 |
rot13 |
|
8874 | 4576 |
"Usenet: from `rotate alphabet 13 places'] |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4577 |
The simple Caesar-cypher encryption that replaces each English |
8874 | 4578 |
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
|
4579 |
so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' |
8874 | 4580 |
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
|
4581 |
It is used to enclose the text in a sealed wrapper that the reader must choose |
8874 | 4582 |
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
|
4583 |
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
|
4584 |
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
|
4585 |
|
11865 | 4586 |
^ self rot:13 |
8874 | 4587 |
|
4588 |
" |
|
4589 |
'hello world' rot13 |
|
4590 |
'hello world' rot13 rot13 |
|
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4591 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4592 |
! |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4593 |
|
11865 | 4594 |
rot:n |
4595 |
"Usenet: from `rotate alphabet N places'] |
|
4596 |
The simple Caesar-cypher encryption that replaces each English |
|
4597 |
letter with the one N places forward or back along the alphabet, |
|
4598 |
so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' by rot 13 |
|
4599 |
Most Usenet news reading and posting programs include a rot13 feature. |
|
4600 |
It is used to enclose the text in a sealed wrapper that the reader must choose |
|
4601 |
to open -- e.g., for posting things that might offend some readers, or spoilers. |
|
4602 |
A major advantage of rot13 over rot(N) for other N is that it |
|
4603 |
is self-inverse, so the same code can be used for encoding and decoding." |
|
4604 |
||
4605 |
^ self species |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4606 |
streamContents:[:aStream | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4607 |
self do:[:char | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4608 |
aStream nextPut:(char rot:n) ]] |
11865 | 4609 |
|
4610 |
" |
|
4611 |
'hello world' rot:13 |
|
4612 |
('hello world' rot:13) rot:13 |
|
4613 |
" |
|
4614 |
! |
|
4615 |
||
15656 | 4616 |
utf16Encoded |
4617 |
"Return my UTF-16 representation as a new TwoByteString" |
|
4618 |
||
4619 |
|s| |
|
4620 |
||
4621 |
s := WriteStream on:(TwoByteString uninitializedNew:self size). |
|
4622 |
s nextPutAllUtf16:self. |
|
4623 |
^ s contents |
|
4624 |
||
4625 |
" |
|
4626 |
'abcde1234' utf16Encoded |
|
17600 | 4627 |
'abcdeäöüß' utf16Encoded |
15656 | 4628 |
" |
4629 |
||
4630 |
"Modified: / 11-05-2010 / 19:12:37 / cg" |
|
4631 |
! |
|
4632 |
||
9192 | 4633 |
utf8Encoded |
19837 | 4634 |
"return the UTF-8 representation of a Unicode string. |
4635 |
The resulting string is only useful to be stored on some external file, |
|
4636 |
not for being used inside ST/X." |
|
4637 |
||
4638 |
|string stream| |
|
17625 | 4639 |
|
4640 |
string := self string. |
|
19837 | 4641 |
|
4642 |
"/ avoid creation of new strings if possible |
|
4643 |
string containsNon7BitAscii ifFalse:[ |
|
4644 |
^ string asSingleByteString |
|
4645 |
]. |
|
4646 |
||
4647 |
"make it size 2 for 1-byte strings" |
|
4648 |
stream := WriteStream on:(String uninitializedNew:(1 + (string size * 3 // 2))). |
|
4649 |
string utf8EncodedOn:stream. |
|
4650 |
^ stream contents. |
|
4651 |
||
4652 |
" |
|
4653 |
'hello' utf8Encoded asByteArray #[104 101 108 108 111] |
|
4654 |
(Character value:16r40) asString utf8Encoded asByteArray #[64] |
|
4655 |
(Character value:16r7F) asString utf8Encoded asByteArray #[127] |
|
4656 |
(Character value:16r80) asString utf8Encoded asByteArray #[194 128] |
|
4657 |
(Character value:16rFF) asString utf8Encoded asByteArray #[195 191] |
|
4658 |
(Character value:16r100) asString utf8Encoded asByteArray #[196 128] |
|
4659 |
(Character value:16r200) asString utf8Encoded asByteArray #[200 128] |
|
4660 |
(Character value:16r400) asString utf8Encoded asByteArray #[208 128] |
|
4661 |
(Character value:16r800) asString utf8Encoded asByteArray #[224 160 128] |
|
4662 |
(Character value:16r1000) asString utf8Encoded asByteArray #[225 128 128] |
|
4663 |
(Character value:16r2000) asString utf8Encoded asByteArray #[226 128 128] |
|
4664 |
(Character value:16r4000) asString utf8Encoded asByteArray #[228 128 128] |
|
4665 |
(Character value:16r8000) asString utf8Encoded asByteArray #[232 128 128] |
|
4666 |
(Character value:16rFFFF) asString utf8Encoded asByteArray #[239 191 191] |
|
4667 |
||
18597 | 4668 |
'abcde1234' asUnicode32String utf8Encoded |
4669 |
'abcdeäöüß' asUnicode32String utf8Encoded |
|
12925
5c0a9a633ca1
comment/format in: #utf8Encoded
Claus Gittinger <cg@exept.de>
parents:
12912
diff
changeset
|
4670 |
" |
17625 | 4671 |
! |
4672 |
||
4673 |
utf8EncodedOn:aStream |
|
19837 | 4674 |
"return the UTF-8 representation of a Unicode string. |
4675 |
The resulting string is only useful to be stored on some external file, |
|
4676 |
not for being used inside ST/X." |
|
4677 |
||
4678 |
|string |
|
4679 |
stringSize "{ Class: SmallInteger }" |
|
4680 |
codePoint "{Class: SmallInteger }" |
|
4681 |
v "{Class: SmallInteger }" |
|
4682 |
character b1 b2 b3 b4 b5| |
|
17625 | 4683 |
|
4684 |
string := self string. |
|
19837 | 4685 |
|
4686 |
"/ avoid creation of new strings if possible |
|
4687 |
string containsNon7BitAscii ifFalse:[ |
|
4688 |
aStream nextPutAll:string asSingleByteString. |
|
4689 |
^ self. |
|
4690 |
]. |
|
4691 |
||
4692 |
stringSize := string size. |
|
4693 |
||
4694 |
1 to:stringSize do:[:idx | |
|
4695 |
character := string at:idx. |
|
4696 |
codePoint := character codePoint. |
|
4697 |
codePoint < 16r80 ifTrue:[ |
|
4698 |
aStream nextPutByte:codePoint. |
|
4699 |
] ifFalse:[ |
|
4700 |
b1 := (codePoint bitAnd:16r3F) bitOr:2r10000000. |
|
4701 |
v := codePoint bitShift:-6. |
|
4702 |
v <= 16r1F ifTrue:[ |
|
4703 |
aStream nextPutByte:(v bitOr:2r11000000). |
|
4704 |
aStream nextPutByte:b1. |
|
4705 |
] ifFalse:[ |
|
4706 |
b2 := (v bitAnd:16r3F) bitOr:2r10000000. |
|
4707 |
v := v bitShift:-6. |
|
4708 |
v <= 16r0F ifTrue:[ |
|
4709 |
aStream nextPutByte:(v bitOr:2r11100000). |
|
4710 |
aStream nextPutByte:b2; nextPutByte:b1. |
|
4711 |
] ifFalse:[ |
|
4712 |
b3 := (v bitAnd:16r3F) bitOr:2r10000000. |
|
4713 |
v := v bitShift:-6. |
|
4714 |
v <= 16r07 ifTrue:[ |
|
4715 |
aStream nextPutByte:(v bitOr:2r11110000). |
|
4716 |
aStream nextPutByte:b3; nextPutByte:b2; nextPutByte:b1. |
|
4717 |
] ifFalse:[ |
|
4718 |
b4 := (v bitAnd:16r3F) bitOr:2r10000000. |
|
4719 |
v := v bitShift:-6. |
|
4720 |
v <= 16r03 ifTrue:[ |
|
4721 |
aStream nextPutByte:(v bitOr:2r11111000). |
|
4722 |
aStream nextPutByte:b4; nextPutByte:b3; nextPutByte:b2; nextPutByte:b1. |
|
4723 |
] ifFalse:[ |
|
4724 |
b5 := (v bitAnd:16r3F) bitOr:2r10000000. |
|
4725 |
v := v bitShift:-6. |
|
4726 |
v <= 16r01 ifTrue:[ |
|
4727 |
aStream nextPutByte:(v bitOr:2r11111100). |
|
4728 |
aStream nextPutByte:b5; nextPutByte:b4; nextPutByte:b3; nextPutByte:b2; nextPutByte:b1. |
|
4729 |
] ifFalse:[ |
|
4730 |
"/ cannot happen - we only support up to 30 bit characters |
|
4731 |
EncodingError raiseWith:character errorString:'codePoint > 31bit in #utf8Encode'. |
|
4732 |
] |
|
4733 |
]. |
|
4734 |
]. |
|
4735 |
]. |
|
4736 |
]. |
|
4737 |
]. |
|
4738 |
]. |
|
4739 |
||
4740 |
" |
|
4741 |
String streamContents:[:s| |
|
4742 |
'hallo' utf8EncodedOn:s |
|
4743 |
]. |
|
4744 |
||
4745 |
ByteArray streamContents:[:s| |
|
4746 |
'hallo' utf8EncodedOn:s |
|
4747 |
]. |
|
4748 |
||
4749 |
String streamContents:[:s| |
|
4750 |
'abcdeäöüß' asUnicode32String utf8EncodedOn:s |
|
4751 |
]. |
|
4752 |
. |
|
4753 |
ByteArray streamContents:[:s| |
|
4754 |
'abcdeäöüß' asUnicode32String utf8EncodedOn:s |
|
4755 |
]. |
|
4756 |
||
4757 |
'/tmp/bytes' asFilename writingFileDo:[:s| |
|
4758 |
'abcdeäöüß' utf8EncodedOn:s |
|
4759 |
]. |
|
17625 | 4760 |
" |
9192 | 4761 |
! ! |
4762 |
||
11345 | 4763 |
|
12111 | 4764 |
!CharacterArray methodsFor:'matching - glob expressions'! |
4765 |
||
4766 |
compoundMatch:aString |
|
4767 |
"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
|
4768 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
12111 | 4769 |
This is usable with fileName pattern fields. |
4770 |
||
4771 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4772 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4773 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4774 |
NOTICE: the receiver is the match pattern" |
4775 |
||
15890 | 4776 |
^ self compoundMatch:aString caseSensitive:true withoutSeparators:false |
12111 | 4777 |
|
4778 |
" |
|
4779 |
'f*' match:'foo' |
|
4780 |
'b*' match:'foo' |
|
4781 |
'f*;b*' match:'foo' |
|
4782 |
'f*;b*' match:'bar' |
|
4783 |
'f*;b*' compoundMatch:'foo' |
|
4784 |
'f*;b*' compoundMatch:'bar' |
|
4785 |
" |
|
4786 |
||
4787 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4788 |
"Modified: / 16.12.1999 / 01:22:08 / cg" |
|
4789 |
! |
|
4790 |
||
15734 | 4791 |
compoundMatch:aString caseSensitive:caseSensitive |
12111 | 4792 |
"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
|
4793 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
12111 | 4794 |
This is usable with fileName pattern fields. |
4795 |
||
4796 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4797 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4798 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4799 |
NOTICE: the receiver is the match pattern" |
4800 |
||
15890 | 4801 |
^self compoundMatch:aString caseSensitive:caseSensitive withoutSeparators:false |
4802 |
||
4803 |
" |
|
4804 |
'f*' match:'foo' |
|
4805 |
'b*' match:'foo' |
|
4806 |
'f*;b*' match:'foo' |
|
4807 |
'f*;b*' match:'bar' |
|
4808 |
'f*;b*' compoundMatch:'foo' |
|
4809 |
'f*;b*' compoundMatch:'bar' |
|
4810 |
'f*;b*' compoundMatch:'Foo' caseSensitive:false |
|
4811 |
'f*;b*' compoundMatch:'Bar' caseSensitive:false |
|
4812 |
'f*;b*' compoundMatch:'ccc' caseSensitive:false |
|
4813 |
" |
|
4814 |
||
4815 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
4816 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4817 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
4818 |
! |
|
4819 |
||
4820 |
compoundMatch:aString caseSensitive:caseSensitive withoutSeparators:withoutSeparators |
|
4821 |
"like match, but the receiver may be a compound match pattern, |
|
4822 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
|
4823 |
If withoutSeparators is true, spaces around individual patterns are stripped off. |
|
4824 |
This is usable with fileName pattern fields. |
|
4825 |
||
4826 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
4827 |
NOT the ST-80 meaning. |
15890 | 4828 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4829 |
NOTICE: the receiver is the match pattern" |
|
4830 |
||
12111 | 4831 |
|matchers| |
4832 |
||
4833 |
matchers := self asCollectionOfSubstringsSeparatedBy:$;. |
|
15890 | 4834 |
withoutSeparators ifTrue:[ matchers := matchers collect:[:each | each withoutSeparators] ]. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4835 |
^ matchers |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
4836 |
contains:[:aPattern | |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
4837 |
aPattern match:aString caseSensitive:caseSensitive escapeCharacter:nil |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
4838 |
]. |
15734 | 4839 |
|
4840 |
" |
|
4841 |
'f*' match:'foo' |
|
4842 |
'b*' match:'foo' |
|
4843 |
'f*;b*' match:'foo' |
|
4844 |
'f*;b*' match:'bar' |
|
4845 |
'f*;b*' compoundMatch:'foo' |
|
4846 |
'f*;b*' compoundMatch:'bar' |
|
4847 |
'f*;b*' compoundMatch:'Foo' caseSensitive:false |
|
4848 |
'f*;b*' compoundMatch:'Bar' caseSensitive:false |
|
4849 |
'f*;b*' compoundMatch:'ccc' caseSensitive:false |
|
15890 | 4850 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4851 |
'f* ; b*' compoundMatch:'foo' |
15890 | 4852 |
'f* ; b*' compoundMatch:'foo' caseSensitive:true withoutSeparators:true |
15734 | 4853 |
" |
4854 |
||
4855 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
4856 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4857 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
4858 |
! |
|
4859 |
||
4860 |
compoundMatch:aString ignoreCase:ignoreCase |
|
4861 |
<resource: #obsolete> |
|
4862 |
||
4863 |
"like match, but the receiver may be a compound match pattern, |
|
4864 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
|
4865 |
This is usable with fileName pattern fields. |
|
4866 |
||
4867 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4868 |
NOT the ST-80 meaning. |
15734 | 4869 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4870 |
NOTICE: the receiver is the match pattern" |
|
4871 |
||
4872 |
^ self compoundMatch:aString caseSensitive:ignoreCase not |
|
12111 | 4873 |
|
4874 |
" |
|
4875 |
'f*' match:'foo' |
|
4876 |
'b*' match:'foo' |
|
4877 |
'f*;b*' match:'foo' |
|
4878 |
'f*;b*' match:'bar' |
|
4879 |
'f*;b*' compoundMatch:'foo' |
|
4880 |
'f*;b*' compoundMatch:'bar' |
|
4881 |
'f*;b*' compoundMatch:'Foo' ignoreCase:true |
|
4882 |
'f*;b*' compoundMatch:'Bar' ignoreCase:true |
|
4883 |
'f*;b*' compoundMatch:'ccc' ignoreCase:true |
|
4884 |
" |
|
4885 |
||
4886 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
4887 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4888 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
4889 |
! |
|
4890 |
||
4891 |
findMatchString:matchString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4892 |
"like findString/indexOfSubCollection, but allowing GLOB match patterns. |
12111 | 4893 |
find matchstring; if found, return the index; |
4894 |
if not found, return 0. |
|
4895 |
||
4896 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
4897 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4898 |
NOTICE: this GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4899 |
NOTICE: the argument is the match pattern" |
4900 |
||
19033 | 4901 |
^ self findMatchString:matchString startingAt:1 caseSensitive:true ifAbsent:0 |
4902 |
||
4903 |
" |
|
4904 |
1234567890123 |
|
4905 |
'hello world bla foo baz' findMatchString:'b* ' |
|
4906 |
" |
|
12111 | 4907 |
! |
4908 |
||
4909 |
findMatchString:matchString startingAt:index |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4910 |
"like findString, but allowing GLOB match patterns. |
12111 | 4911 |
find matchstring, starting at index. if found, return the index; |
4912 |
if not found, return 0. |
|
4913 |
||
4914 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
4915 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4916 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4917 |
NOTICE: the argument is the match pattern" |
4918 |
||
19033 | 4919 |
^ self findMatchString:matchString startingAt:index caseSensitive:true ifAbsent:0 |
12111 | 4920 |
! |
4921 |
||
15734 | 4922 |
findMatchString:matchString startingAt:index caseSensitive:caseSensitive ifAbsent:exceptionBlock |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4923 |
"like findString, but allowing GLOB match patterns. |
12111 | 4924 |
find matchstring, starting at index. if found, return the index; |
4925 |
if not found, return the result of evaluating exceptionBlock. |
|
4926 |
This is a q&d hack - not very efficient. |
|
4927 |
||
4928 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4929 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4930 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4931 |
NOTICE: the argument is the match pattern" |
4932 |
||
4933 |
|firstChar firstSet |
|
4934 |
startIndex "{ Class: SmallInteger }" |
|
4935 |
matchSize "{ Class: SmallInteger }" |
|
4936 |
mySize "{ Class: SmallInteger }" |
|
4937 |
realMatchString lcChar ucChar| |
|
4938 |
||
4939 |
matchSize := matchString size. |
|
4940 |
matchSize == 0 ifTrue:[^ index]. "empty string matches" |
|
4941 |
||
4942 |
realMatchString := matchString. |
|
4943 |
(realMatchString endsWith:$*) ifFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4944 |
realMatchString := realMatchString , '*'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4945 |
matchSize := matchSize + 1 |
12111 | 4946 |
]. |
4947 |
||
4948 |
mySize := self size. |
|
4949 |
firstChar := realMatchString at:1. |
|
4950 |
firstChar == self class matchEscapeCharacter ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4951 |
firstChar := realMatchString at:2. |
12111 | 4952 |
]. |
4953 |
||
4954 |
firstChar asString includesMatchCharacters ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4955 |
index to:mySize do:[:col | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4956 |
(realMatchString match:self from:col to:mySize caseSensitive:caseSensitive) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4957 |
ifTrue:[^ col] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4958 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4959 |
^ exceptionBlock value. |
12111 | 4960 |
]. |
4961 |
||
4962 |
lcChar := firstChar asLowercase. |
|
4963 |
ucChar := firstChar asUppercase. |
|
15734 | 4964 |
(caseSensitive not and:[ lcChar ~= ucChar ]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4965 |
firstSet := Array with:ucChar with:lcChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4966 |
startIndex := self indexOfAny:firstSet startingAt:index. |
12111 | 4967 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4968 |
startIndex := self indexOf:firstChar startingAt:index. |
12111 | 4969 |
]. |
4970 |
[startIndex == 0] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4971 |
(realMatchString match:self from:startIndex to:mySize caseSensitive:caseSensitive) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4972 |
ifTrue:[^ startIndex]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4973 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4974 |
firstSet notNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4975 |
startIndex := self indexOfAny:firstSet startingAt:(startIndex + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4976 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4977 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4978 |
]. |
12111 | 4979 |
]. |
4980 |
^ exceptionBlock value |
|
4981 |
||
4982 |
" |
|
4983 |
'one two three four' findMatchString:'o[nu]' |
|
4984 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
15734 | 4985 |
'one two three four one' findMatchString:'ONE' startingAt:3 caseSensitive:false ifAbsent:0 |
4986 |
'one two three four one' findMatchString:'ONE' startingAt:3 caseSensitive:true ifAbsent:0 |
|
4987 |
'one two three four ONE' findMatchString:'O#E' startingAt:1 caseSensitive:false ifAbsent:0 |
|
4988 |
'one two three four ONE' findMatchString:'O#E' startingAt:1 caseSensitive:true ifAbsent:0 |
|
4989 |
12345678901234567890 |
|
4990 |
" |
|
4991 |
||
4992 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
|
4993 |
! |
|
4994 |
||
4995 |
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock |
|
4996 |
<resource: #obsolete> |
|
4997 |
"like findString, but allowing GLOB match patterns. |
|
4998 |
find matchstring, starting at index. if found, return the index; |
|
4999 |
if not found, return the result of evaluating exceptionBlock. |
|
5000 |
This is a q&d hack - not very efficient. |
|
5001 |
||
5002 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5003 |
NOT the ST-80 meaning. |
15734 | 5004 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
5005 |
NOTICE: the argument is the match pattern" |
|
5006 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5007 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5008 |
findMatchString:matchString startingAt:index caseSensitive:ignoreCase not ifAbsent:exceptionBlock |
15734 | 5009 |
|
5010 |
" |
|
5011 |
'one two three four' findMatchString:'o[nu]' |
|
5012 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
12111 | 5013 |
'one two three four one' findMatchString:'ONE' startingAt:3 ignoreCase:true ifAbsent:0 |
5014 |
" |
|
5015 |
||
5016 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
|
5017 |
! |
|
5018 |
||
19746 | 5019 |
globPatternAsRegexPattern |
5020 |
"taking the receiver as a GLOB pattern, |
|
5021 |
return a corresponding regex pattern. |
|
5022 |
As regex does provide information about the matching substring, |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5023 |
it may be useful to apply a regex after a GLOB match, |
19746 | 5024 |
in order to highlight matching substrings (eg. in a CodeView after a search). |
5025 |
If it turns out to be better, we may convert all GLOB searches to regex and use it right away. |
|
5026 |
(currently, it is not sure, if GLOB is not better for most simple searches, as they are encountered |
|
5027 |
in typical real life)" |
|
5028 |
||
5029 |
^ self species streamContents:[:s | |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5030 |
|addCharacter| |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5031 |
|
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5032 |
addCharacter := |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5033 |
[:ch | |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5034 |
ch isLetterOrDigit ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5035 |
s nextPut:$\. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5036 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5037 |
s nextPut:ch |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5038 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5039 |
|
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5040 |
(String matchScanArrayFrom:self) do:[:matchEntry | |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5041 |
matchEntry isCharacter ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5042 |
addCharacter value:matchEntry |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5043 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5044 |
matchEntry == #anyString ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5045 |
s nextPutAll:'.*' |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5046 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5047 |
matchEntry == #any ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5048 |
s nextPut:$. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5049 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5050 |
matchEntry isString ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5051 |
|set min max| |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5052 |
|
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5053 |
s nextPut:$[. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5054 |
set := matchEntry copy sort. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5055 |
min := set min. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5056 |
max := set max. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5057 |
set asSet = (min to:max) asSet ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5058 |
addCharacter value:min. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5059 |
s nextPut:$-. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5060 |
addCharacter value:max. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5061 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5062 |
set do:addCharacter. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5063 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5064 |
s nextPut:$]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5065 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5066 |
self halt. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5067 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5068 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5069 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5070 |
] |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5071 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5072 |
]. |
19746 | 5073 |
|
5074 |
" |
|
5075 |
'hello' globPatternAsRegexPattern |
|
5076 |
'hello*' globPatternAsRegexPattern |
|
5077 |
'*hello*' globPatternAsRegexPattern |
|
5078 |
'h###' globPatternAsRegexPattern |
|
5079 |
'h[0-9]' globPatternAsRegexPattern |
|
5080 |
'h[0-9][0-9][0-9]' globPatternAsRegexPattern |
|
5081 |
'h[0-9]*' globPatternAsRegexPattern |
|
19747 | 5082 |
'h[-+]*' globPatternAsRegexPattern |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5083 |
|
19747 | 5084 |
'hello world' matches:'h*w' |
5085 |
'hello world' matchesRegex:('h*w' globPatternAsRegexPattern) |
|
5086 |
'hello world' matches:'h*d' |
|
5087 |
'hello world' matchesRegex:('h*d' globPatternAsRegexPattern) |
|
19746 | 5088 |
" |
5089 |
! |
|
5090 |
||
12111 | 5091 |
includesMatchString:matchString |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5092 |
"like includesString, but allowing GLOB match patterns. |
12111 | 5093 |
find matchstring; if found, return true, otherwise return false. |
5094 |
||
5095 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5096 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5097 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5098 |
NOTICE: the argument is the match pattern" |
5099 |
||
5100 |
^ (self findMatchString:matchString) ~~ 0 |
|
5101 |
||
5102 |
" |
|
5103 |
'hello world' includesMatchString:'h*' |
|
5104 |
'hello world' includesMatchString:'h[aeiou]llo' |
|
5105 |
'hello world' includesMatchString:'wor*' |
|
5106 |
'hello world' includesMatchString:'woR*' |
|
5107 |
" |
|
5108 |
! |
|
5109 |
||
5110 |
includesMatchString:matchString caseSensitive:caseSensitive |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5111 |
"like includesString, but allowing GLOB match patterns. |
12111 | 5112 |
find matchstring; if found, return true, otherwise return false. |
5113 |
||
5114 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5115 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5116 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5117 |
NOTICE: the argument is the match pattern" |
5118 |
||
19033 | 5119 |
^ (self findMatchString:matchString startingAt:1 caseSensitive:caseSensitive ifAbsent:0) ~~ 0 |
12111 | 5120 |
|
5121 |
" |
|
5122 |
'hello world' includesMatchString:'h*' caseSensitive:true |
|
5123 |
'hello world' includesMatchString:'h*' caseSensitive:false |
|
5124 |
'Hello world' includesMatchString:'h*' caseSensitive:true |
|
5125 |
'Hello world' includesMatchString:'h*' caseSensitive:false |
|
5126 |
||
5127 |
'hello world' includesMatchString:'h[aeiou]llo' caseSensitive:true |
|
5128 |
'hello world' includesMatchString:'h[aeiou]llo' caseSensitive:false |
|
5129 |
||
5130 |
'hello world' includesMatchString:'wor*' caseSensitive:true |
|
5131 |
'hello world' includesMatchString:'wor*' caseSensitive:false |
|
5132 |
||
5133 |
'hello world' includesMatchString:'woR*' caseSensitive:true |
|
5134 |
'hello world' includesMatchString:'woR*' caseSensitive:false |
|
5135 |
" |
|
5136 |
! |
|
5137 |
||
5138 |
match:aString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5139 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 5140 |
characters $* (to match any string) or $# (to match any character). |
5141 |
or [...] to match a set of characters. |
|
5142 |
Lower/uppercase are considered different. |
|
5143 |
The escape character is the backQuote. |
|
5144 |
||
5145 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5146 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5147 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5148 |
NOTICE: the receiver is the match pattern" |
5149 |
||
15734 | 5150 |
^ self match:aString from:1 to:aString size caseSensitive:true |
12111 | 5151 |
|
5152 |
" |
|
5153 |
'\*f*' match:'f' |
|
5154 |
'\*f*' match:'*f' |
|
5155 |
'*\*f*' match:'*f' |
|
5156 |
'*f*' match:'*f' |
|
5157 |
'*ute*' match:'computer' |
|
5158 |
'*uter' match:'computer' |
|
5159 |
'uter*' match:'computer' |
|
5160 |
'*ute*' match:'' |
|
5161 |
'[abcd]*' match:'computer' |
|
5162 |
'[abcd]*' match:'komputer' |
|
5163 |
'*some*compl*ern*' match:'this is some more complicated pattern match' |
|
5164 |
'*some*compl*ern*' match:'this is another complicated pattern match' |
|
5165 |
'*-hh' match:'anton-h' |
|
5166 |
" |
|
5167 |
||
5168 |
"Modified: / 9.6.1998 / 18:50:00 / cg" |
|
5169 |
! |
|
5170 |
||
15734 | 5171 |
match:aString caseSensitive:caseSensitive |
5172 |
"return true if aString matches self, where self may contain GLOB meta-match |
|
5173 |
characters $* (to match any string) or $# (to match any character) |
|
5174 |
or [...] to match a set of characters. |
|
5175 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
5176 |
The escape character is the backQuote. |
|
5177 |
||
5178 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5179 |
NOT the ST-80 meaning. |
15734 | 5180 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
5181 |
NOTICE: the receiver is the match pattern" |
|
5182 |
||
5183 |
^ self match:aString from:1 to:aString size caseSensitive:caseSensitive |
|
5184 |
||
5185 |
" |
|
5186 |
'*ute*' match:'COMPUTER' caseSensitive:false |
|
5187 |
'*uter' match:'COMPUTER' caseSensitive:true |
|
5188 |
'[abcd]*' match:'computer' caseSensitive:true |
|
5189 |
'[abcd]*' match:'Computer' caseSensitive:true |
|
5190 |
'[a-k]*' match:'komputer' caseSensitive:true |
|
5191 |
'[a-k]*' match:'zomputer' caseSensitive:true |
|
5192 |
'[a-k]*' match:'Komputer' caseSensitive:true |
|
5193 |
'[a-k]*' match:'Komputer' caseSensitive:false |
|
5194 |
'*some*compl*ern*' match:'this is some more complicated pattern match' caseSensitive:false |
|
5195 |
'*some*compl*ern*' match:'this is another complicated pattern match' caseSensitive:false |
|
5196 |
||
5197 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5198 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5199 |
'[ab]*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5200 |
] |
15734 | 5201 |
]. |
5202 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5203 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5204 |
'*at:*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5205 |
] |
15734 | 5206 |
]. |
5207 |
" |
|
5208 |
||
5209 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
5210 |
! |
|
5211 |
||
5212 |
match:aString caseSensitive:caseSensitive escapeCharacter:escape |
|
5213 |
"return true if aString matches self, where self may contain GLOB meta-match |
|
5214 |
characters $* (to match any string) or $# (to match any character) |
|
5215 |
or [...] to match a set of characters. |
|
5216 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
5217 |
||
5218 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5219 |
NOT the ST-80 meaning. |
15734 | 5220 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
5221 |
NOTICE: the receiver is the match pattern" |
|
5222 |
||
5223 |
^ self match:aString from:1 to:aString size caseSensitive:caseSensitive escapeCharacter:escape |
|
5224 |
||
5225 |
" |
|
5226 |
'*ute*' match:'COMPUTER' caseSensitive:false |
|
5227 |
'*uter' match:'COMPUTER' caseSensitive:true |
|
5228 |
'[abcd]*' match:'computer' caseSensitive:true |
|
5229 |
'[abcd]*' match:'Computer' caseSensitive:true |
|
5230 |
'[a-k]*' match:'komputer' caseSensitive:true |
|
5231 |
'[a-k]*' match:'zomputer' caseSensitive:true |
|
5232 |
'[a-k]*' match:'Komputer' caseSensitive:true |
|
5233 |
'[a-k]*' match:'Komputer' caseSensitive:false |
|
5234 |
'*some*compl*ern*' match:'this is some more complicated pattern match' caseSensitive:false |
|
5235 |
'*some*compl*ern*' match:'this is another complicated pattern match' caseSensitive:false |
|
5236 |
||
5237 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5238 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5239 |
'[ab]*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5240 |
] |
15734 | 5241 |
]. |
5242 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5243 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5244 |
'*at:*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5245 |
] |
15734 | 5246 |
]. |
5247 |
" |
|
5248 |
||
5249 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
5250 |
! |
|
5251 |
||
12111 | 5252 |
match:aString escapeCharacter:escape |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5253 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 5254 |
characters $* (to match any string) or $# (to match any character). |
5255 |
or [...] to match a set of characters. |
|
5256 |
Lower/uppercase are considered different. |
|
5257 |
||
5258 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5259 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5260 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5261 |
NOTICE: the receiver is the match pattern" |
5262 |
||
19033 | 5263 |
^ self match:aString from:1 to:aString size caseSensitive:true escapeCharacter:escape |
12111 | 5264 |
|
5265 |
" |
|
5266 |
'a\b\c\*' match:'a\b\c\d' |
|
5267 |
'a\b\c\*' match:'a\b\c\d' escapeCharacter:nil |
|
5268 |
" |
|
5269 |
! |
|
5270 |
||
15734 | 5271 |
match:aString from:start to:stop caseSensitive:caseSensitive |
5272 |
"return true if part of aString matches myself, |
|
5273 |
where self may contain GLOB meta-match |
|
5274 |
characters $* (to match any string) or $# (to match any character) |
|
5275 |
or [...] to match a set of characters. |
|
5276 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
5277 |
The escape character is the backQuote. |
|
5278 |
||
5279 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5280 |
NOT the ST-80 meaning. |
15734 | 5281 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
5282 |
NOTICE: the receiver is the match pattern" |
|
5283 |
||
5284 |
^ self |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5285 |
match:aString from:start to:stop caseSensitive:caseSensitive |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5286 |
escapeCharacter:(self class matchEscapeCharacter) |
15734 | 5287 |
|
5288 |
" |
|
5289 |
'*ute*' match:'12345COMPUTER' from:1 to:5 caseSensitive:false |
|
5290 |
'*ute*' match:'12345COMPUTER' from:6 to:13 caseSensitive:false |
|
5291 |
" |
|
5292 |
||
5293 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
5294 |
! |
|
5295 |
||
5296 |
match:aString from:start to:stop caseSensitive:caseSensitive escapeCharacter:escape |
|
5297 |
"return true if part of aString matches myself, |
|
5298 |
where self may contain GLOB meta-match |
|
5299 |
characters $* (to match any string) or $# (to match any character) |
|
5300 |
or [...] to match a set of characters. |
|
5301 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
5302 |
||
5303 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5304 |
NOT the ST-80 meaning. |
15734 | 5305 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
5306 |
NOTICE: the receiver is the match pattern" |
|
5307 |
||
5308 |
|matchScanArray| |
|
5309 |
||
5310 |
" |
|
5311 |
keep the matchScanArray from the most recent match - |
|
5312 |
avoids parsing the pattern over-and over if multiple searches |
|
5313 |
are done with the same pattern. |
|
5314 |
" |
|
5315 |
(PreviousMatch notNil |
|
5316 |
and:[PreviousMatch key = self]) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5317 |
matchScanArray := PreviousMatch value |
15734 | 5318 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5319 |
matchScanArray := self class matchScanArrayFrom:self escapeCharacter:escape. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5320 |
matchScanArray isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5321 |
'CharacterArray [info]: invalid matchpattern:''' infoPrint. self infoPrint. ''' comparing for equality.' infoPrintCR. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5322 |
^ self = aString |
15734 | 5323 |
"/ ^ false |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5324 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5325 |
PreviousMatch := self -> matchScanArray. |
15734 | 5326 |
]. |
5327 |
||
5328 |
^ self class |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5329 |
matchScan:matchScanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5330 |
from:1 to:matchScanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5331 |
with:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5332 |
from:start to:stop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5333 |
caseSensitive:caseSensitive |
15734 | 5334 |
|
5335 |
" |
|
5336 |
'*ute*' match:'12345COMPUTER' from:1 to:5 caseSensitive:false |
|
5337 |
'*ute*' match:'12345COMPUTER' from:6 to:13 caseSensitive:false |
|
5338 |
" |
|
5339 |
||
5340 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
5341 |
! |
|
5342 |
||
12111 | 5343 |
match:aString from:start to:stop ignoreCase:ignoreCase |
15734 | 5344 |
<resource: #obsolete> |
12111 | 5345 |
"return true if part of aString matches myself, |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5346 |
where self may contain GLOB meta-match |
12111 | 5347 |
characters $* (to match any string) or $# (to match any character) |
5348 |
or [...] to match a set of characters. |
|
5349 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
5350 |
The escape character is the backQuote. |
|
5351 |
||
5352 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5353 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5354 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5355 |
NOTICE: the receiver is the match pattern" |
5356 |
||
5357 |
^ self |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5358 |
match:aString from:start to:stop caseSensitive:ignoreCase not |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5359 |
escapeCharacter:(self class matchEscapeCharacter) |
12111 | 5360 |
|
5361 |
" |
|
5362 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
5363 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
5364 |
" |
|
5365 |
||
5366 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
5367 |
! |
|
5368 |
||
5369 |
match:aString from:start to:stop ignoreCase:ignoreCase escapeCharacter:escape |
|
15734 | 5370 |
<resource: #obsolete> |
12111 | 5371 |
"return true if part of aString matches myself, |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5372 |
where self may contain GLOB meta-match |
12111 | 5373 |
characters $* (to match any string) or $# (to match any character) |
5374 |
or [...] to match a set of characters. |
|
5375 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
5376 |
||
5377 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5378 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5379 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5380 |
NOTICE: the receiver is the match pattern" |
5381 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5382 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5383 |
match:aString from:start to:stop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5384 |
caseSensitive:ignoreCase not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5385 |
escapeCharacter:escape |
12111 | 5386 |
|
5387 |
" |
|
5388 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
5389 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
5390 |
" |
|
5391 |
||
5392 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
5393 |
! |
|
5394 |
||
5395 |
match:aString ignoreCase:ignoreCase |
|
15734 | 5396 |
<resource: #obsolete> |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5397 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 5398 |
characters $* (to match any string) or $# (to match any character) |
5399 |
or [...] to match a set of characters. |
|
5400 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
5401 |
The escape character is the backQuote. |
|
5402 |
||
5403 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5404 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5405 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5406 |
NOTICE: the receiver is the match pattern" |
5407 |
||
15734 | 5408 |
"/ leave it this way, in case a customer has redefined it for performance (for a while) |
19033 | 5409 |
^ self match:aString from:1 to:aString size caseSensitive:ignoreCase not |
12111 | 5410 |
|
5411 |
" |
|
5412 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
5413 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
5414 |
'[abcd]*' match:'computer' ignoreCase:false |
|
5415 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
5416 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
5417 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
5418 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
5419 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
5420 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
5421 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
5422 |
||
5423 |
Time millisecondsToRun:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5424 |
Symbol allInstancesDo:[:sym | |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5425 |
'[ab]*' match:sym ignoreCase:false |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5426 |
] |
12111 | 5427 |
]. |
5428 |
Time millisecondsToRun:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5429 |
Symbol allInstancesDo:[:sym | |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5430 |
'*at:*' match:sym ignoreCase:false |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5431 |
] |
12111 | 5432 |
]. |
5433 |
" |
|
5434 |
||
5435 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
5436 |
! |
|
5437 |
||
5438 |
match:aString ignoreCase:ignoreCase escapeCharacter:escape |
|
15734 | 5439 |
<resource: #obsolete> |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5440 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 5441 |
characters $* (to match any string) or $# (to match any character) |
5442 |
or [...] to match a set of characters. |
|
5443 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
5444 |
||
5445 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5446 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5447 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5448 |
NOTICE: the receiver is the match pattern" |
5449 |
||
19033 | 5450 |
^ self match:aString from:1 to:aString size caseSensitive:ignoreCase not escapeCharacter:escape |
12111 | 5451 |
|
5452 |
" |
|
5453 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
5454 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
5455 |
'[abcd]*' match:'computer' ignoreCase:false |
|
5456 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
5457 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
5458 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
5459 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
5460 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
5461 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
5462 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
5463 |
||
5464 |
Time millisecondsToRun:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5465 |
Symbol allInstancesDo:[:sym | |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5466 |
'[ab]*' match:sym ignoreCase:false |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5467 |
] |
12111 | 5468 |
]. |
5469 |
Time millisecondsToRun:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5470 |
Symbol allInstancesDo:[:sym | |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5471 |
'*at:*' match:sym ignoreCase:false |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5472 |
] |
12111 | 5473 |
]. |
5474 |
" |
|
5475 |
||
5476 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
5477 |
! |
|
5478 |
||
5479 |
matches:aPatternString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5480 |
"return true if the receiver matches aString, where aPatternString may contain GLOB meta-match |
12111 | 5481 |
characters $* (to match any string) or $# (to match any character). |
5482 |
or [...] to match a set of characters. |
|
5483 |
Lower/uppercase are considered different. |
|
5484 |
||
5485 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5486 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5487 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5488 |
NOTICE: the receiver is the match pattern" |
5489 |
||
5490 |
^ aPatternString match:self |
|
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5491 |
! |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5492 |
|
15734 | 5493 |
matches:aPatternString caseSensitive:caseSensitive |
5494 |
"return true if the receiver matches aString, where aPatternString may contain GLOB meta-match |
|
5495 |
characters $* (to match any string) or $# (to match any character). |
|
5496 |
or [...] to match a set of characters. |
|
5497 |
||
5498 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5499 |
NOT the ST-80 meaning. |
15734 | 5500 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
5501 |
NOTICE: the receiver is the match pattern" |
|
5502 |
||
5503 |
^ aPatternString match:self caseSensitive:caseSensitive |
|
5504 |
! |
|
5505 |
||
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5506 |
matches:aPatternString ignoreCase:ignoreCase |
15734 | 5507 |
<resource: #obsolete> |
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5508 |
"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
|
5509 |
characters $* (to match any string) or $# (to match any character). |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5510 |
or [...] to match a set of characters. |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5511 |
Lower/uppercase are considered different. |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5512 |
|
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5513 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5514 |
NOT the ST-80 meaning. |
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5515 |
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
|
5516 |
NOTICE: the receiver is the match pattern" |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5517 |
|
15734 | 5518 |
^ aPatternString match:self caseSensitive:ignoreCase not |
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5519 |
|
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5520 |
"Created: / 08-03-2012 / 03:11:11 / cg" |
12111 | 5521 |
! ! |
5522 |
||
5523 |
||
18722 | 5524 |
!CharacterArray methodsFor:'matching - regex'! |
5525 |
||
5526 |
matchesRegex:regexString caseSensitive:aBoolean |
|
5527 |
"Test if the receiver matches a regex. |
|
5528 |
May raise RxParser>>regexErrorSignal or child signals. |
|
5529 |
This is a part of the Regular Expression Matcher package, |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5530 |
(c) 1996, 1999 Vassili Bykov. |
18722 | 5531 |
Refer to `documentation' protocol of RxParser class for details." |
5532 |
||
5533 |
aBoolean ifFalse:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5534 |
^ self matchesRegexIgnoringCase:regexString |
18722 | 5535 |
] ifTrue:[ |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5536 |
^ self matchesRegex:regexString |
18722 | 5537 |
]. |
5538 |
||
5539 |
" |
|
5540 |
'hello world' matchesRegex:'h.*d'. |
|
5541 |
" |
|
5542 |
||
5543 |
"Created: / 13-12-2010 / 11:01:49 / cg" |
|
5544 |
! ! |
|
17625 | 5545 |
|
9192 | 5546 |
!CharacterArray methodsFor:'padded copying'! |
5547 |
||
5548 |
centerPaddedTo:newSize |
|
19464 | 5549 |
"return a new string consisting of the receiver's characters, |
5550 |
plus spaces up to length and center the receiver's characters in |
|
5551 |
the resulting string. |
|
5552 |
If the receiver's size is equal or greater than the length argument, |
|
5553 |
the original receiver is returned unchanged." |
|
9192 | 5554 |
|
5555 |
^ self centerPaddedTo:newSize with:(Character space) |
|
5556 |
||
5557 |
" |
|
5558 |
'foo' centerPaddedTo:10 |
|
5559 |
123 printString centerPaddedTo:10 |
|
5560 |
" |
|
5561 |
||
5562 |
"Created: 25.11.1995 / 10:53:57 / cg" |
|
5563 |
! |
|
9190 | 5564 |
|
5565 |
centerPaddedTo:size with:padCharacter |
|
5566 |
"return a new string of length size, which contains the receiver |
|
5567 |
centered (i.e. padded on both sides). |
|
5568 |
Characters are filled with padCharacter. |
|
19464 | 5569 |
If the receiver's 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
|
5570 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5571 |
|
9190 | 5572 |
|len s| |
5573 |
||
5574 |
len := self size. |
|
9192 | 5575 |
(len < size) ifTrue:[ |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5576 |
s := self species new:size withAll:padCharacter. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5577 |
s replaceFrom:(size - len) // 2 + 1 with:self. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5578 |
^ s |
9192 | 5579 |
] |
5580 |
||
9190 | 5581 |
" |
5582 |
'foo' centerPaddedTo:11 with:$. |
|
5583 |
'fooBar' centerPaddedTo:5 with:$. |
|
5584 |
123 printString centerPaddedTo:10 with:$. |
|
5585 |
(' ' , 123 printString) centerPaddedTo:10 with:$. |
|
5586 |
(Float pi printString) centerPaddedTo:15 with:(Character space) |
|
5587 |
(Float pi printString) centerPaddedTo:15 with:$- |
|
5588 |
(' ' , Float pi class name) centerPaddedTo:15 with:$. |
|
5589 |
" |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5590 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5591 |
|
9190 | 5592 |
decimalPaddedTo:size and:afterPeriod at:decimalCharacter |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5593 |
"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
|
5594 |
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
|
5595 |
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
|
5596 |
to be padded). |
19464 | 5597 |
If the receiver's 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
|
5598 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5599 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5600 |
|
8874 | 5601 |
^ self |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5602 |
decimalPaddedTo:size |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5603 |
and:afterPeriod |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5604 |
at:decimalCharacter |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5605 |
withLeft:(Character space) |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5606 |
right:$0 |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5607 |
|
8874 | 5608 |
" |
5609 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123 ' |
|
5610 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
|
5611 |
'123.' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5612 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.100' |
8874 | 5613 |
'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
|
5614 |
'123.123' decimalPaddedTo:10 and:3 at:$. -> ' 123.123' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5615 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5616 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5617 |
"Created: 23.12.1995 / 13:11:52 / cg" |
9192 | 5618 |
! |
5619 |
||
5620 |
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
|
5621 |
"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
|
5622 |
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
|
5623 |
of the period. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5624 |
Characters on the left are filled with leftPadChar. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5625 |
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
|
5626 |
otherwise, if missing, a decimal point is added and right characters filled with this. |
19464 | 5627 |
If the receiver's 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
|
5628 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5629 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5630 |
|
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
5631 |
|s idx n rest| |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5632 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5633 |
idx := self indexOf:decimalCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5634 |
idx == 0 ifTrue:[ |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5635 |
"/ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5636 |
"/ no decimal point found; adjust string to the left of the period column |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5637 |
"/ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5638 |
rightPadChar isNil ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5639 |
s := self , (self species new:afterPeriod + 1 withAll:leftPadChar) |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5640 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5641 |
s:= self , decimalCharacter asString , (self species new:afterPeriod withAll:rightPadChar). |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5642 |
]. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5643 |
] ifFalse:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5644 |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5645 |
"/ the number of after-decimalPoint characters |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5646 |
n := self size - idx. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5647 |
rest := afterPeriod - n. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5648 |
rest > 0 ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5649 |
s := (self species new:rest withAll:(rightPadChar ? leftPadChar)). |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5650 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5651 |
s := '' |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5652 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5653 |
s := self , s. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5654 |
]. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5655 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5656 |
^ s leftPaddedTo:size with:leftPadChar |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5657 |
|
8874 | 5658 |
" |
5659 |
'123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:nil -> ' 123 ' |
|
5660 |
'123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.000' |
|
5661 |
'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
|
5662 |
'123.1' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.100' |
8874 | 5663 |
'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
|
5664 |
'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
|
5665 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5666 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5667 |
"Modified: 23.12.1995 / 13:08:18 / cg" |
9192 | 5668 |
! |
5669 |
||
5670 |
leftPaddedTo:size |
|
5671 |
"return a new string of length size, which contains the receiver |
|
5672 |
right-adjusted (i.e. padded on the left). |
|
5673 |
Characters on the left are filled with spaces. |
|
19464 | 5674 |
If the receiver's size is equal or greater than the length argument, |
9192 | 5675 |
the original receiver is returned unchanged." |
5676 |
||
5677 |
^ self leftPaddedTo:size with:(Character space) |
|
5678 |
||
5679 |
" |
|
5680 |
'foo' leftPaddedTo:10 |
|
5681 |
'fooBar' leftPaddedTo:5 |
|
5682 |
123 printString leftPaddedTo:10 |
|
5683 |
" |
|
5684 |
! |
|
608 | 5685 |
|
5686 |
paddedTo:newSize |
|
19753 | 5687 |
"return a new string consisting of the receiver's characters, |
608 | 5688 |
plus spaces up to length. |
19464 | 5689 |
If the receiver's size is equal or greater than the length argument, |
608 | 5690 |
the original receiver is returned unchanged." |
5691 |
||
5692 |
^ self paddedTo:newSize with:(Character space) |
|
5693 |
||
5694 |
" |
|
8874 | 5695 |
'foo' paddedTo:10 |
5696 |
123 printString paddedTo:10 |
|
15734 | 5697 |
'12345678901234' paddedTo:10 |
608 | 5698 |
" |
64 | 5699 |
! ! |
5700 |
||
9192 | 5701 |
!CharacterArray methodsFor:'printing & storing'! |
608 | 5702 |
|
5703 |
article |
|
17137 | 5704 |
"return an article string for the receiver. |
5705 |
The original code only looked at the first character being a vowel; |
|
5706 |
this has been enhanced by some heuristics - not perfect, still." |
|
608 | 5707 |
|
17241 | 5708 |
|firstChar secondChar thirdChar| |
608 | 5709 |
|
8874 | 5710 |
firstChar := (self at:1) asLowercase. |
5848 | 5711 |
((firstChar isVowel and:[firstChar ~~ $u]) or:[firstChar == $x]) ifTrue:[ |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5712 |
^ 'an' |
608 | 5713 |
]. |
17043 | 5714 |
|
5715 |
(self size >= 3) ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5716 |
secondChar := (self at:2) asLowercase. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5717 |
|
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5718 |
"/ may need more here... |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5719 |
( #('rb') includes:(String with:firstChar with:secondChar)) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5720 |
^ 'an' |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5721 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5722 |
|
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5723 |
thirdChar := (self at:3) asLowercase. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5724 |
|
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5725 |
(firstChar isVowel not |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5726 |
and:[(secondChar isVowel or:[secondChar == $y]) not |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5727 |
and:[thirdChar isVowel not ]]) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5728 |
"/ exceptions: 3 non-vowels in a row: looks like an abbreviation |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5729 |
(self size > 4) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5730 |
(firstChar == $s) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5731 |
((secondChar == $c and:[thirdChar == $r]) |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5732 |
or:[ (secondChar == $t and:[thirdChar == $r]) ]) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5733 |
(self at:4) isVowel ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5734 |
^ 'a' |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5735 |
] |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5736 |
] |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5737 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5738 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5739 |
"/ an abbreviation; treat x, s as vowels |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5740 |
(firstChar == $x or:[ firstChar == $s ]) ifTrue:[^ 'an']. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5741 |
] |
17043 | 5742 |
]. |
608 | 5743 |
^ 'a' |
5848 | 5744 |
|
5745 |
" |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5746 |
'uboot' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5747 |
'xmas' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5748 |
'alarm' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5749 |
'baby' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5750 |
'sql' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5751 |
'scr' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5752 |
'screen' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5753 |
'scrollbar' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5754 |
'scrs' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5755 |
'cvs' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5756 |
'cvssource' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5757 |
'symbol' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5758 |
'string' article. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5759 |
'rbparser' article. |
19683 | 5760 |
" |
5761 |
||
5762 |
"Modified (comment): / 01-05-2016 / 10:57:25 / cg" |
|
608 | 5763 |
! |
5764 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5765 |
basicStoreString |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5766 |
"return a String for storing myself" |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5767 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5768 |
|s n index| |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5769 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5770 |
n := self occurrencesOf:$'. |
11320 | 5771 |
n ~~ 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5772 |
s := self species new:(n + 2 + self size). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5773 |
s at:1 put:$'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5774 |
index := 2. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5775 |
self do:[:thisChar | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5776 |
(thisChar == $') ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5777 |
s at:index put:thisChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5778 |
index := index + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5779 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5780 |
s at:index put:thisChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5781 |
index := index + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5782 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5783 |
s at:index put:$'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5784 |
^ s |
9192 | 5785 |
]. |
11320 | 5786 |
|
9192 | 5787 |
^ '''' , self , '''' |
15523 | 5788 |
|
5789 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5790 |
'''immutable'' string' asImmutableString basicStoreString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5791 |
'immutable string' asImmutableString basicStoreString |
15523 | 5792 |
" |
5793 |
||
5794 |
"Modified: / 14-07-2013 / 19:20:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
9192 | 5795 |
! |
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5796 |
|
11774
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5797 |
displayOn:aGCOrStream |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5798 |
"Compatibility |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5799 |
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
|
5800 |
OR: |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5801 |
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
|
5802 |
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
|
5803 |
(although the fallBack is to display its printString ...)" |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5804 |
|
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5805 |
"/ 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
|
5806 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
16738 | 5807 |
(aGCOrStream isStream) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5808 |
self storeOn:aGCOrStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5809 |
^ self |
11774
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5810 |
]. |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5811 |
^ super displayOn:aGCOrStream |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5812 |
! |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5813 |
|
608 | 5814 |
printOn:aStream |
5815 |
"print the receiver on aStream" |
|
5816 |
||
5817 |
aStream nextPutAll:self |
|
5818 |
! |
|
5819 |
||
5820 |
printString |
|
13079
111e7e456648
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
13073
diff
changeset
|
5821 |
"return a string for printing - that's myself" |
608 | 5822 |
|
5823 |
^ self |
|
3578 | 5824 |
! |
5825 |
||
5826 |
printWithQuotesDoubledOn:aStream |
|
5827 |
"put the raw storeString of myself on aStream" |
|
5828 |
||
5829 |
self do:[:thisChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5830 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5831 |
aStream nextPut:thisChar |
3578 | 5832 |
] |
5833 |
||
5834 |
"Modified: / 15.6.1998 / 17:21:17 / cg" |
|
5835 |
"Created: / 15.6.1998 / 17:22:13 / cg" |
|
12171 | 5836 |
! |
5837 |
||
15788 | 5838 |
printXmlQuotedOn:aStream |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5839 |
"convert aString to a valid XML string |
15788 | 5840 |
that can be used for attributes, text, comments an PIs |
5841 |
TODO: care for 16bit UNICODE string and escape chars ..." |
|
5842 |
||
5843 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5844 |
eachChar == $< ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5845 |
aStream nextPutAll:'<' "mapping needed for xml text" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5846 |
] ifFalse:[ eachChar == $& ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5847 |
aStream nextPutAll:'&' "mapping needed for all" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5848 |
] ifFalse:[ eachChar == $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5849 |
aStream nextPutAll:'>' "mapping needed for comments" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5850 |
] ifFalse:[ eachChar == $' ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5851 |
aStream nextPutAll:''' "mapping needed for attributes" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5852 |
] ifFalse:[ eachChar == $" ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5853 |
aStream nextPutAll:'"' "mapping needed for attributes" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5854 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5855 |
|codePoint| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5856 |
codePoint := eachChar codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5857 |
(codePoint < 16r20 or:[codePoint >= 16r7F]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5858 |
aStream nextPutAll:'&#'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5859 |
codePoint printOn:aStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5860 |
aStream nextPut:$;. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5861 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5862 |
aStream nextPut:eachChar |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5863 |
]]]]]] |
15788 | 5864 |
]. |
5865 |
! |
|
5866 |
||
5867 |
printXmlTextQuotedOn:aStream |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5868 |
"convert aString to a valid XML string |
15788 | 5869 |
that can be used for XML text. |
5870 |
Here line formatting characters are not escaped. |
|
5871 |
TODO: care for 16bit UNICODE string and escape chars ..." |
|
5872 |
||
5873 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5874 |
eachChar == $< ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5875 |
aStream nextPutAll:'<' "mapping needed for xml text" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5876 |
] ifFalse:[ eachChar == $& ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5877 |
aStream nextPutAll:'&' "mapping needed for all" |
15788 | 5878 |
"/ ] ifFalse:[ eachChar == $> ifTrue:[ |
5879 |
"/ aStream nextPutAll:'>' "mapping needed for comments" |
|
5880 |
"/ ] ifFalse:[ eachChar == $' ifTrue:[ |
|
5881 |
"/ aStream nextPutAll:''' "mapping needed for attributes" |
|
5882 |
"/ ] ifFalse:[ eachChar == $" ifTrue:[ |
|
5883 |
"/ aStream nextPutAll:'"' "mapping needed for attributes" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5884 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5885 |
|codePoint| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5886 |
codePoint := eachChar codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5887 |
((codePoint < 16r20 and:[codePoint ~~ 9 and:[codePoint ~~ 10 and:[codePoint ~~ 13]]]) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5888 |
or:[codePoint >= 16r7F]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5889 |
aStream nextPutAll:'&#'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5890 |
codePoint printOn:aStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5891 |
aStream nextPut:$;. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5892 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5893 |
aStream nextPut:eachChar |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5894 |
]]]"/]]] |
15788 | 5895 |
]. |
5896 |
! |
|
5897 |
||
12171 | 5898 |
printfWith:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
12177 | 5899 |
"Format and print the receiver with <argI> formatted in C style, |
12171 | 5900 |
as specified in the Unix C-language manual page for printf(3). |
15712 | 5901 |
Return the resulting string (i.e actually, this is more like an sprintf)." |
12177 | 5902 |
|
12171 | 5903 |
^ self printf:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
5904 |
||
5905 |
" |
|
12177 | 5906 |
Transcript showCR:('%d %05x %08o %b' printfWith:123 with:234 with:345 with:123) |
12171 | 5907 |
" |
15788 | 5908 |
! |
5909 |
||
5910 |
xmlQuotedPrintString |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5911 |
"convert aString to a valid XML string |
15788 | 5912 |
that can be used for attributes, text, comments an PIs |
5913 |
TODO: care for 16bit UNICODE string and escape chars ..." |
|
5914 |
||
5915 |
^ String streamContents:[:s| |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5916 |
self printXmlQuotedOn:s |
15788 | 5917 |
]. |
9192 | 5918 |
! ! |
5919 |
||
11955 | 5920 |
|
9192 | 5921 |
!CharacterArray methodsFor:'queries'! |
608 | 5922 |
|
4429 | 5923 |
bitsPerCharacter |
18662 | 5924 |
"return the underlying string's bitsPerCharacter |
4429 | 5925 |
(i.e. is it a regular String or a TwoByteString)" |
5926 |
||
8457 | 5927 |
|string max| |
5928 |
||
5929 |
(string := self string) ~~ self ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5930 |
^ string bitsPerCharacter |
8457 | 5931 |
]. |
5932 |
||
5933 |
max := 8. |
|
5934 |
self do:[:eachCharacter | |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5935 |
max := max max:(eachCharacter bitsPerCharacter) |
9192 | 5936 |
]. |
5937 |
^ max |
|
5938 |
||
5939 |
" |
|
5940 |
'hello' bitsPerCharacter |
|
5941 |
'hello' asText allBold bitsPerCharacter |
|
5942 |
" |
|
5943 |
! |
|
8457 | 5944 |
|
19757 | 5945 |
bytesPerCharacter |
5946 |
"return the underlying string's required |
|
5947 |
bytesPerCharacter |
|
5948 |
(i.e. is it a regular String or a TwoByteString)" |
|
5949 |
||
5950 |
|string max| |
|
5951 |
||
5952 |
(string := self string) ~~ self ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5953 |
^ string bytesPerCharacter |
19757 | 5954 |
]. |
5955 |
||
5956 |
max := 1. |
|
5957 |
self do:[:eachCharacter | |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5958 |
max := max max:(eachCharacter bytesPerCharacter) |
19757 | 5959 |
]. |
5960 |
^ max |
|
5961 |
||
5962 |
" |
|
5963 |
'hello' bytesPerCharacter |
|
5964 |
'hello' asUnicode16String bytesPerCharacter |
|
5965 |
'hello' asText allBold bytesPerCharacter |
|
5966 |
" |
|
5967 |
! |
|
5968 |
||
18967 | 5969 |
containsNon8BitElements |
5970 |
"return true, if the underlying string contains elements larger than a single byte" |
|
5971 |
||
5972 |
|sz "{ Class:SmallInteger }"| |
|
5973 |
||
5974 |
sz := self size. |
|
5975 |
1 to:sz do:[:idx| |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5976 |
(self at:idx) codePoint > 16rFF ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5977 |
^ true. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
5978 |
]. |
18967 | 5979 |
]. |
5980 |
^ false. |
|
5981 |
! |
|
5982 |
||
10903 | 5983 |
continuesWith:aString startingAt:startIndex |
5984 |
"return true, if the receiver beginning at startIndex |
|
5985 |
contains the characters in aString." |
|
5986 |
||
5987 |
|sz "{Class: SmallInteger }" |
|
5988 |
idx "{Class: SmallInteger }"| |
|
5989 |
||
5990 |
sz := aString size. |
|
5991 |
idx := startIndex. |
|
5992 |
||
5993 |
1 to:sz do:[:i | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5994 |
(self at:idx) ~~ (aString at:i) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5995 |
idx := idx + 1 |
10903 | 5996 |
]. |
5997 |
^ true |
|
5998 |
||
5999 |
" |
|
6000 |
'hello world' continuesWith:'world' startingAt:6 |
|
6001 |
'hello world' continuesWith:'world' startingAt:7 |
|
6002 |
" |
|
6003 |
||
6004 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
6005 |
"Modified: 26.7.1996 / 19:08:36 / cg" |
|
6006 |
! |
|
6007 |
||
6008 |
countWords |
|
6009 |
"return the number of words, which are separated by separators" |
|
6010 |
||
6011 |
|tally "{ Class: SmallInteger }" |
|
6012 |
start "{ Class: SmallInteger }" |
|
6013 |
mySize "{ Class: SmallInteger }" |
|
6014 |
stop ch| |
|
6015 |
||
6016 |
tally := 0. |
|
6017 |
start := 1. |
|
6018 |
mySize := self size. |
|
6019 |
[start <= mySize] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6020 |
ch := self at:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6021 |
ch isSeparator ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6022 |
start := start + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6023 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6024 |
stop := self indexOfSeparatorStartingAt:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6025 |
(stop == 0) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6026 |
stop := mySize + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6027 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6028 |
tally := tally + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6029 |
start := stop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6030 |
] |
10903 | 6031 |
]. |
6032 |
^ tally |
|
6033 |
||
6034 |
" |
|
6035 |
'hello world isnt this nice' countWords' |
|
6036 |
" |
|
6037 |
! |
|
6038 |
||
11788 | 6039 |
defaultElement |
6040 |
^ Character space |
|
6041 |
! |
|
6042 |
||
608 | 6043 |
encoding |
1311 | 6044 |
"return the strings encoding, as a symbol. |
7982 | 6045 |
Here, by default, we assume unicode-encoding. |
6046 |
Notice, that iso8859-1 is a true subset of unicode, |
|
8874 | 6047 |
and that singleByteStrings are therefore both unicode AND |
7982 | 6048 |
8859-1 encoded." |
6049 |
||
14168 | 6050 |
^ #unicode |
608 | 6051 |
! |
6052 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
6053 |
hasChangeOfEmphasis |
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6054 |
"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
|
6055 |
i.e. any non-normal (=emphasized) characters" |
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6056 |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
6057 |
^ false |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
6058 |
|
1381 | 6059 |
"Created: 12.5.1996 / 12:31:39 / cg" |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
6060 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
6061 |
|
7995
8ddbb403d67b
+hasIcon and hasImage for LabelAndIcon compatibility
Claus Gittinger <cg@exept.de>
parents:
7991
diff
changeset
|
6062 |
hasIcon |
9191 | 6063 |
"for LabelAndIcon compatibility" |
6064 |
||
9192 | 6065 |
^ false |
6066 |
! |
|
6067 |
||
6068 |
hasImage |
|
6069 |
"for LabelAndIcon compatibility" |
|
6070 |
||
6071 |
^ false |
|
6072 |
! |
|
7995
8ddbb403d67b
+hasIcon and hasImage for LabelAndIcon compatibility
Claus Gittinger <cg@exept.de>
parents:
7991
diff
changeset
|
6073 |
|
1388 | 6074 |
heightOn:aGC |
19464 | 6075 |
"return the size of the receiver in device units if displayed on aGC" |
1388 | 6076 |
|
6528 | 6077 |
^ (aGC font onDevice:aGC device) heightOf:self |
1388 | 6078 |
|
6079 |
" |
|
8874 | 6080 |
'hello world' heightOn:(View new) |
1388 | 6081 |
" |
6082 |
||
6083 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
6084 |
"Modified: 12.5.1996 / 20:32:05 / cg" |
|
6085 |
! |
|
6086 |
||
11828 | 6087 |
isLowercaseFirst |
6088 |
"return true, if the first character is a lowercase character." |
|
6089 |
||
6090 |
^ self size ~~ 0 and:[ self first isLowercase ] |
|
6091 |
||
6092 |
" |
|
12177 | 6093 |
'helloWorld' isLowercaseFirst |
6094 |
'HelloWorld' isLowercaseFirst |
|
11828 | 6095 |
" |
6096 |
! |
|
6097 |
||
6098 |
isUppercaseFirst |
|
6099 |
"return true, if the first character is an uppercase character." |
|
6100 |
||
6101 |
^ self size ~~ 0 and:[ self first isUppercase ] |
|
6102 |
||
6103 |
" |
|
12177 | 6104 |
'helloWorld' isUppercaseFirst |
6105 |
'HelloWorld' isUppercaseFirst |
|
11828 | 6106 |
" |
6107 |
! |
|
6108 |
||
15773 | 6109 |
keywords |
6110 |
"assuming the receiver is a keyword message selector, |
|
6111 |
return the individual keywords (i.e. break it up at colons) |
|
6112 |
and return these as a collection. |
|
6113 |
For binary and unary selectors, the result may be nonsense (an array containing the receiver)." |
|
6114 |
||
6115 |
|coll s part| |
|
6116 |
||
6117 |
coll := OrderedCollection new. |
|
6118 |
s := ReadStream on:self. |
|
6119 |
[s atEnd] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6120 |
part := s through:$:. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6121 |
coll add:part |
15773 | 6122 |
]. |
6123 |
^ coll asArray |
|
6124 |
||
6125 |
" |
|
6126 |
#at:put: keywords |
|
6127 |
#at: keywords |
|
6128 |
#+ keywords |
|
6129 |
#size keywords |
|
6130 |
" |
|
6131 |
||
6132 |
"Modified (Comment): / 30-06-2011 / 17:46:21 / cg" |
|
6133 |
! |
|
6134 |
||
9190 | 6135 |
knownAsSymbol |
6136 |
"for now, only single character strings are allowed as symbols. |
|
6137 |
This method is redefined in String." |
|
6138 |
||
6139 |
^ false |
|
6140 |
! |
|
6141 |
||
6142 |
leftIndent |
|
6143 |
"if the receiver starts with spaces, return the number of spaces |
|
6144 |
at the left - otherwise, return 0. |
|
19464 | 6145 |
If the receiver consists of spaces only, return the receiver's size." |
9192 | 6146 |
|
6147 |
|index "{Class: SmallInteger }" |
|
6148 |
end "{Class: SmallInteger }"| |
|
6149 |
||
6150 |
index := 1. |
|
6151 |
end := self size. |
|
6152 |
[index <= end] whileTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6153 |
(self at:index) isSeparator ifFalse:[^ index - 1]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6154 |
index := index + 1 |
8350 | 6155 |
]. |
9192 | 6156 |
^ end |
6157 |
||
6158 |
" |
|
6159 |
' hello' leftIndent |
|
6160 |
'foo ' leftIndent |
|
9190 | 6161 |
' ' leftIndent |
6162 |
" |
|
6163 |
||
6164 |
"Modified: 20.4.1996 / 19:28:43 / cg" |
|
8350 | 6165 |
! |
6166 |
||
10437 | 6167 |
nameSpaceSelectorParts |
6168 |
"Answer the namespace and baseSelector parts of a namespace selector. |
|
6169 |
Namespace selectors are those generated by sends from a method in a different |
|
6170 |
namespace; they are prefixed by ':'<ns>'::'. |
|
6171 |
You cannot easily change this algorithm here, as it is also known by the VM's lookup function. |
|
6172 |
Experimental" |
|
6173 |
||
6174 |
|nsPart selPart idx| |
|
6175 |
||
6176 |
(self at:1) == $: ifFalse:[^ Array with:'' with:self]. |
|
6177 |
idx := self indexOf:$: startingAt:3. |
|
6178 |
idx == 0 ifTrue:[^ Array with:'' with:self]. |
|
6179 |
||
6180 |
(idx+2 > self size) ifTrue:[^ Array with:'' with:self]. |
|
6181 |
(self at:idx+1) == $: ifFalse:[^ Array with:'' with:self]. |
|
6182 |
nsPart := self copyFrom:2 to:idx-1. |
|
6183 |
selPart := self copyFrom:idx+2. |
|
6184 |
^ Array with:nsPart with:selPart |
|
6185 |
||
6186 |
"test: |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6187 |
self assert:('+' nameSpaceSelectorParts) = #('' '+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6188 |
self assert:(':+' nameSpaceSelectorParts) = #('' ':+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6189 |
self assert:(':Foo:+' nameSpaceSelectorParts) = #('' ':Foo:+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6190 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6191 |
self assert:(':Foo::+' nameSpaceSelectorParts) = #('Foo' '+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6192 |
self assert:(':Foo::bar:baz:' nameSpaceSelectorParts) = #('Foo' 'bar:baz:'). |
10437 | 6193 |
" |
6194 |
||
6195 |
"Created: / 05-03-2007 / 17:16:58 / cg" |
|
6196 |
"Modified: / 06-03-2007 / 11:51:15 / cg" |
|
6197 |
! |
|
6198 |
||
9190 | 6199 |
stringSpecies |
8874 | 6200 |
"return the underlying strings bitsPerCharacter |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
6201 |
(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
|
6202 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
6203 |
|string| |
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
6204 |
|
15523 | 6205 |
string := self string. |
6206 |
string == self ifTrue:[^ self species]. |
|
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
6207 |
^ string stringSpecies |
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
6208 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
6209 |
" |
8874 | 6210 |
'hello' stringSpecies |
9192 | 6211 |
'hello' asText allBold stringSpecies |
6212 |
" |
|
6213 |
! |
|
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
6214 |
|
6653 | 6215 |
widthFrom:startIndex to:endIndex on:aGC |
19464 | 6216 |
"return ths size of part of the receiver in device units if displayed on aGC" |
6653 | 6217 |
|
6218 |
^ (aGC font onDevice:aGC device) widthOf:self from:startIndex to:endIndex |
|
6219 |
||
6220 |
" |
|
8874 | 6221 |
'hello world' widthFrom:1 to:5 on:(View new) |
6222 |
'hello' widthOn:(View new) |
|
6653 | 6223 |
" |
9192 | 6224 |
! |
6653 | 6225 |
|
1388 | 6226 |
widthOn:aGC |
19464 | 6227 |
"return ths size of the receiver in device units if displayed on aGC" |
1388 | 6228 |
|
6528 | 6229 |
^ (aGC font onDevice:aGC device) widthOf:self |
1388 | 6230 |
|
6231 |
" |
|
8874 | 6232 |
'hello world' widthOn:(View new) |
1388 | 6233 |
" |
6234 |
||
6235 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
2554 | 6236 |
"Modified: 17.4.1997 / 12:50:23 / cg" |
608 | 6237 |
! ! |
6238 |
||
6239 |
!CharacterArray methodsFor:'special string converting'! |
|
6240 |
||
16759 | 6241 |
asUnixFilenameString |
6242 |
"return a new string consisting of receiver's characters |
|
6243 |
with all \-characters replaced by /-characters. |
|
6244 |
If there are no backslashes, return the original" |
|
6245 |
||
6246 |
^ self copyReplaceAll:$\ with:$/ ifNone:self |
|
6247 |
||
6248 |
" |
|
6249 |
'hello\world' asUnixFilenameString |
|
6250 |
" |
|
6251 |
||
6252 |
"Modified: / 18.7.1998 / 22:53:02 / cg" |
|
6253 |
! |
|
6254 |
||
14768 | 6255 |
expandPlaceholders:escapeCharacter with:argArrayOrDictionary |
6256 |
"this is the generic version of the old %-escaping method, allowing for an arbitrary |
|
6257 |
escape character to be used (typically $$ or $% are effectively used). |
|
6258 |
Return a copy of the receiver, where all %i escapes are |
|
6259 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
|
6260 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
|
6261 |
in the new string 'hello world; how is this'. |
|
6262 |
As an extension, the argument may also be a dictionary, providing |
|
6263 |
values for symbolic keys. |
|
6264 |
In this case, %a .. %z and %(...) are also allowed. |
|
6265 |
(%1..%9 require a numeric key in the dictionary, however) |
|
6266 |
To get a '%' character, use a '%%'-escape. |
|
6267 |
To get an integer-indexed placeHolder followed by another digit, |
|
6268 |
or an index > 9, you must use %(digit). |
|
6269 |
See also bindWith:... for VisualAge compatibility." |
|
6270 |
||
6271 |
|stream| |
|
6272 |
||
18269 | 6273 |
stream := (TextStream ? CharacterWriteStream) on:(self species uninitializedNew:self size + 20). |
14768 | 6274 |
self expandPlaceholders:escapeCharacter with:argArrayOrDictionary on:stream. |
6275 |
^ stream contents. |
|
6276 |
||
6277 |
||
6278 |
" |
|
6279 |
'hello %1' expandPlaceholdersWith:#('world') |
|
6280 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
6281 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
6282 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
|
6283 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) |
|
6284 |
'%%10 gives %10' expandPlaceholdersWith:#(123) |
|
6285 |
'%%(10) gives %(10)' expandPlaceholdersWith:#(123) |
|
6286 |
'%test gives %1' expandPlaceholdersWith:#(123) |
|
6287 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' allBold } |
|
6288 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' } |
|
6289 |
" |
|
6290 |
||
6291 |
" |
|
6292 |
|dict| |
|
6293 |
||
6294 |
dict := Dictionary new. |
|
6295 |
dict at:1 put:'one'. |
|
6296 |
dict at:$a put:'AAAAA'. |
|
6297 |
dict at:$b put:[ Time now ]. |
|
6298 |
dict at:'foo' put:[ Date today ]. |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6299 |
'hello $1 %a $b %(foo) $foo ' expandPlaceholders:$$ with:dict. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6300 |
'hello $1 %a $b %(foo) $foo ' expandPlaceholders:$% with:dict. |
14768 | 6301 |
" |
6302 |
||
6303 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
|
6304 |
! |
|
6305 |
||
14765 | 6306 |
expandPlaceholders:escapeCharacter with:argArrayOrDictionary on:aStream |
6307 |
"this is the generic version of the old %-escaping method, allowing for an arbitrary |
|
6308 |
escape character to be used (typically $$ or $% are effectively used). |
|
18425 | 6309 |
|
14765 | 6310 |
Write the receiver to aStream, where all %i escapes are |
6311 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
|
6312 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
|
6313 |
in the new string 'hello world; how is this'. |
|
18425 | 6314 |
|
17192 | 6315 |
As an extension, the argument may also be a dictionary, providing values for symbolic keys. |
14765 | 6316 |
In this case, %a .. %z and %(...) are also allowed. |
6317 |
(%1..%9 require a numeric key in the dictionary, however) |
|
17192 | 6318 |
Also, the values in argArrayOrDictionary may be blocks. |
18425 | 6319 |
|
14765 | 6320 |
To get a '%' character, use a '%%'-escape. |
6321 |
To get an integer-indexed placeHolder followed by another digit, |
|
6322 |
or an index > 9, you must use %(digit). |
|
18425 | 6323 |
|
14765 | 6324 |
See also bindWith:... for VisualAge compatibility. |
6325 |
Use %<cr> to insert a CR and %<tab> to insert a TAB." |
|
6326 |
||
6327 |
|next v key |
|
6328 |
idx "{ SmallInteger }" |
|
6329 |
idx2 "{ SmallInteger }" |
|
6330 |
start "{ SmallInteger }" |
|
6331 |
stop "{ SmallInteger }"| |
|
6332 |
||
6333 |
stop := self size. |
|
6334 |
start := 1. |
|
6335 |
[start <= stop] whileTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6336 |
idx := self indexOf:escapeCharacter startingAt:start. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6337 |
(idx == 0 or:[idx == stop]) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6338 |
aStream nextPutAll:self startingAt:start to:stop. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6339 |
^ self. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6340 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6341 |
"found an escapeCharacter" |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6342 |
aStream nextPutAll:self startingAt:start to:(idx - 1). |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6343 |
next := self at:(idx + 1). |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6344 |
(next == escapeCharacter) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6345 |
aStream nextPut:escapeCharacter. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6346 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6347 |
next == $< ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6348 |
idx2 := self indexOf:$> startingAt:idx+2. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6349 |
key := self copyFrom:idx+2 to:idx2-1. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6350 |
idx := idx2 - 1. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6351 |
key := key asSymbolIfInterned. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6352 |
(#(cr tab nl return lf ff null) includesIdentical:key) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6353 |
aStream nextPut:(Character perform:key). |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6354 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6355 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6356 |
next isDigit ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6357 |
v := argArrayOrDictionary at:(next digitValue) ifAbsent:'' |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6358 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6359 |
next == $( ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6360 |
idx2 := self indexOf:$) startingAt:idx+2. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6361 |
key := self copyFrom:idx+2 to:idx2-1. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6362 |
idx := idx2 - 1. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6363 |
(argArrayOrDictionary includesKey:key) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6364 |
v := argArrayOrDictionary at:key |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6365 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6366 |
key := key asSymbolIfInterned ? key. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6367 |
(argArrayOrDictionary includesKey:key) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6368 |
v := argArrayOrDictionary at:key |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6369 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6370 |
(key size == 1 and:[ argArrayOrDictionary includesKey:(key at:1)]) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6371 |
v := argArrayOrDictionary at:(key at:1) |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6372 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6373 |
key isNumeric ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6374 |
key := Integer readFrom:key onError:nil. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6375 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6376 |
v := argArrayOrDictionary at:key ifAbsent:'' |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6377 |
] |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6378 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6379 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6380 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6381 |
(next isLetter and:[argArrayOrDictionary isSequenceable not "is a Dictionary"]) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6382 |
"so next is a non-numeric single character." |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6383 |
v := argArrayOrDictionary |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6384 |
at:next |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6385 |
ifAbsent:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6386 |
"try symbol instead of character" |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6387 |
argArrayOrDictionary |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6388 |
at:next asSymbol |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6389 |
ifAbsent:[String with:escapeCharacter with:next]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6390 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6391 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6392 |
v := String with:$% with:next. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6393 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6394 |
] |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6395 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6396 |
"/ v notNil ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6397 |
v isBlock ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6398 |
v := v value |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6399 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6400 |
|
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6401 |
v printOn:aStream. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6402 |
"/ ]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6403 |
] |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6404 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6405 |
start := idx + 2 |
14765 | 6406 |
]. |
6407 |
||
6408 |
" |
|
6409 |
String streamContents:[:s| |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6410 |
'hello %1' expandPlaceholders:$% with:#('world') on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6411 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6412 |
'hello $1; how is $2' expandPlaceholders:$$ with:#('world' 'this') on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6413 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6414 |
'hello %2; how is %1' expandPlaceholders:$% with:#('world' 'this') on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6415 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6416 |
'%1 plus %2 gives %3 ' expandPlaceholders:$% with:#(4 5 9) on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6417 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6418 |
'%%(1)0 gives %(1)0' expandPlaceholders:$% with:#(123) on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6419 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6420 |
'%%10 gives %10' expandPlaceholders:$% with:#(123) on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6421 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6422 |
'%%(10) gives %(10) %<cr>%<tab>next line' expandPlaceholders:$% with:#(123) on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6423 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6424 |
'%%test gives %test' expandPlaceholders:$% with:#(123) on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6425 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6426 |
'|%%<tab>|%%1|%%<cr>| gives |%<tab>|%1|%<cr>|' expandPlaceholders:$% with:#(foo) on:s. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6427 |
] |
14765 | 6428 |
" |
6429 |
||
6430 |
" |
|
6431 |
|dict| |
|
6432 |
||
6433 |
dict := Dictionary new. |
|
6434 |
dict at:1 put:'one'. |
|
6435 |
dict at:$a put:'AAAAA'. |
|
6436 |
dict at:$b put:[ Time now ]. |
|
6437 |
String streamContents:[:s| |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6438 |
'hello $1 $a $b' expandPlaceholders:$$ with:dict on:s. |
14765 | 6439 |
]. |
6440 |
" |
|
6441 |
||
18425 | 6442 |
"using blocks: |
6443 |
|dict| |
|
6444 |
||
6445 |
dict := Dictionary new. |
|
6446 |
dict at:'time' put:[Time now printString]. |
|
6447 |
dict at:'date' put:[Date today printString]. |
|
6448 |
String streamContents:[:s| |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6449 |
'it is $(time) $(date)' expandPlaceholders:$$ with:dict on:s. |
18425 | 6450 |
]. |
6451 |
" |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6452 |
|
14765 | 6453 |
"Modified: / 18-11-2010 / 15:43:28 / cg" |
6454 |
! |
|
6455 |
||
9192 | 6456 |
expandPlaceholdersWith:argArrayOrDictionary |
608 | 6457 |
"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
|
6458 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
608 | 6459 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
6460 |
in the new string 'hello world; how is this'. |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6461 |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6462 |
As an extension, the argument may also be a dictionary, providing |
7313 | 6463 |
values for symbolic keys. |
4842 | 6464 |
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
|
6465 |
(%1..%9 require a numeric key in the dictionary, however) |
18425 | 6466 |
Also, the values in argArrayOrDictionary may be blocks. |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6467 |
|
608 | 6468 |
To get a '%' character, use a '%%'-escape. |
7313 | 6469 |
To get an integer-indexed placeHolder followed by another digit, |
6470 |
or an index > 9, you must use %(digit). |
|
608 | 6471 |
See also bindWith:... for VisualAge compatibility." |
6472 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6473 |
|stream| |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6474 |
|
18269 | 6475 |
stream := (TextStream ? CharacterWriteStream) on:(self species uninitializedNew:self size + 20). |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6476 |
self expandPlaceholdersWith:argArrayOrDictionary on:stream. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6477 |
^ stream contents. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6478 |
|
608 | 6479 |
" |
8874 | 6480 |
'hello %1' expandPlaceholdersWith:#('world') |
6481 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
6482 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
6483 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
|
6484 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) |
|
6485 |
'%%10 gives %10' expandPlaceholdersWith:#(123) |
|
6486 |
'%%(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
|
6487 |
'%test gives %1' expandPlaceholdersWith:#(123) |
11028
cb1ee3ddd91a
expandPlaceHolders: care fr Text with emphasis
Claus Gittinger <cg@exept.de>
parents:
11018
diff
changeset
|
6488 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' allBold } |
cb1ee3ddd91a
expandPlaceHolders: care fr Text with emphasis
Claus Gittinger <cg@exept.de>
parents:
11018
diff
changeset
|
6489 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' } |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6490 |
('bla %1 bla' withColor:Color red) |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6491 |
expandPlaceholdersWith:{ 'hello' } |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6492 |
('bla %1 bla' withColor:Color red) |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6493 |
expandPlaceholdersWith:{ 'hello' withColor:Color blue } |
608 | 6494 |
" |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
6495 |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6496 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6497 |
|dict| |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6498 |
|
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6499 |
dict := Dictionary new. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6500 |
dict at:1 put:'one'. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6501 |
dict at:$a put:'AAAAA'. |
8794
a5df33935142
nindWith supports blocks in the value dictionary
Claus Gittinger <cg@exept.de>
parents:
8710
diff
changeset
|
6502 |
dict at:$b put:[ Time now ]. |
12316
3e78905d70a9
comment/format in: #expandPlaceholdersWith:
Claus Gittinger <cg@exept.de>
parents:
12196
diff
changeset
|
6503 |
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
|
6504 |
'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
|
6505 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6506 |
|
2737
9f29aecea39d
care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents:
2736
diff
changeset
|
6507 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
9192 | 6508 |
! |
6509 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6510 |
expandPlaceholdersWith:argArrayOrDictionary on:aStream |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6511 |
"write the receiver to aStream, where all %i escapes are |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6512 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6513 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6514 |
in the new string 'hello world; how is this'. |
18425 | 6515 |
|
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6516 |
As an extension, the argument may also be a dictionary, providing |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6517 |
values for symbolic keys. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6518 |
In this case, %a .. %z and %(...) are also allowed. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6519 |
(%1..%9 require a numeric key in the dictionary, however) |
18425 | 6520 |
Also, the values in argArrayOrDictionary may be blocks. |
6521 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6522 |
To get a '%' character, use a '%%'-escape. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6523 |
To get an integer-indexed placeHolder followed by another digit, |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6524 |
or an index > 9, you must use %(digit). |
18425 | 6525 |
|
10935 | 6526 |
See also bindWith:... for VisualAge compatibility. |
10939
d0ca31c1d1e9
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10935
diff
changeset
|
6527 |
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
|
6528 |
|
14765 | 6529 |
^ self expandPlaceholders:$% with:argArrayOrDictionary on:aStream |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6530 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6531 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6532 |
String streamContents:[:s| |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6533 |
'hello %1' expandPlaceholdersWith:#('world') on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6534 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6535 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6536 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6537 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6538 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6539 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6540 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6541 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6542 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6543 |
'%%10 gives %10' expandPlaceholdersWith:#(123) on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6544 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6545 |
'%%(10) gives %(10) %<cr>%<tab>next line' expandPlaceholdersWith:#(123) on:s. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6546 |
s cr. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6547 |
'%test gives %1' expandPlaceholdersWith:#(123) on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6548 |
] |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6549 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6550 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6551 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6552 |
|dict| |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6553 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6554 |
dict := Dictionary new. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6555 |
dict at:1 put:'one'. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6556 |
dict at:$a put:'AAAAA'. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6557 |
dict at:$b put:[ Time now ]. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6558 |
String streamContents:[:s| |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6559 |
'hello %1 %a %b' expandPlaceholdersWith:dict on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6560 |
]. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6561 |
" |
13008
a27647c36b31
changed: #expandPlaceholdersWith:on:
Claus Gittinger <cg@exept.de>
parents:
12925
diff
changeset
|
6562 |
|
13138
d2eb0eba5907
changed: #expandPlaceholdersWith:on:
Claus Gittinger <cg@exept.de>
parents:
13137
diff
changeset
|
6563 |
"Modified: / 18-11-2010 / 15:43:28 / cg" |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6564 |
! |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6565 |
|
9230 | 6566 |
firstLine |
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6567 |
"return the first line of a multiline string" |
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6568 |
|
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6569 |
^ self asCollectionOfSubCollectionsSeparatedBy:(Character cr) do:[:line | ^ line]. |
9230 | 6570 |
|
6571 |
" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6572 |
'hello' firstLine |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6573 |
'1\2\3' withCRs firstLine |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6574 |
'\1\2\3' withCRs firstLine |
9230 | 6575 |
" |
6576 |
! |
|
6577 |
||
13987 | 6578 |
tokensBasedOn:aCharacter |
6579 |
"this is an ST-80 alias for the ST/X method |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6580 |
asCollectionOfSubstringsSeparatedBy:" |
13987 | 6581 |
|
6582 |
^ self asCollectionOfSubstringsSeparatedBy:aCharacter |
|
6583 |
||
6584 |
" |
|
6585 |
'hello:world:isnt:this nice' tokensBasedOn:$: |
|
6586 |
'foo,bar,baz' tokensBasedOn:$, |
|
6587 |
'/etc/passwd' asFilename readStream nextLine tokensBasedOn:$: |
|
6588 |
" |
|
6589 |
! |
|
6590 |
||
6591 |
withCEscapes |
|
16863 | 6592 |
"return a new string consisting of receiver's characters |
13987 | 6593 |
with all special and unprintable characters replaced by \X-character escapes. |
6594 |
(similar to the way C-language literal Strings are represented). |
|
6595 |
The resulting string will contain only 7-bit ascii characters. |
|
6596 |
Emphasis is not supported. |
|
6597 |
The following escapes are generated: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6598 |
\' single quote character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6599 |
\dQuote double quote character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6600 |
\r return character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6601 |
\r return character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6602 |
\n newline character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6603 |
\t tab character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6604 |
\\ the \ character itself |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6605 |
\xnn two digit hex number defining the characters ascii value |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6606 |
\unnnn four digit hex number defining the characters ascii value |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6607 |
\Unnnnnnnn eight digit hex number defining the characters ascii value |
16863 | 6608 |
This is the opposite of withoutCEscapes. |
17000 | 6609 |
|
6610 |
Sigh: this is named completely wrong (opposite naming of withCRs/witoutCRs), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6611 |
but it cannot be changed easily, as these methods are already used heavily |
13987 | 6612 |
" |
6613 |
||
6614 |
|anyEscapeNeeded out seq| |
|
6615 |
||
6616 |
" |
|
6617 |
first, check if any escape is needed and return the receiver unchanged if not |
|
6618 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6619 |
anyEscapeNeeded := self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6620 |
contains:[:ch | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6621 |
((ch codePoint between:32 and:126) not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6622 |
or:[ch == $' or:[ch == $"]]) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6623 |
]. |
13987 | 6624 |
anyEscapeNeeded ifFalse:[ ^ self ]. |
6625 |
||
6626 |
self hasChangeOfEmphasis ifTrue:[ self error:'emphasis not supported' ]. |
|
6627 |
||
18269 | 6628 |
out := WriteStream on:(String uninitializedNew:self size-1). |
13987 | 6629 |
|
6630 |
self do:[:ch | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6631 |
|cp| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6632 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6633 |
(ch == $' or:[ch == $"]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6634 |
out nextPut:$\. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6635 |
out nextPut:ch. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6636 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6637 |
(ch codePoint between:32 and:126) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6638 |
out nextPut:ch |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6639 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6640 |
ch == Character return ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6641 |
seq := '\r' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6642 |
] ifFalse:[ ch == Character nl ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6643 |
seq := '\n' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6644 |
] ifFalse:[ ch == Character tab ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6645 |
seq := '\t' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6646 |
] ifFalse:[ ch == $\ ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6647 |
seq := '\\' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6648 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6649 |
cp := ch codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6650 |
cp <= 16rFF ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6651 |
seq := '\x' , (cp printStringRadix:16 padTo:2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6652 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6653 |
cp <= 16rFFFF ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6654 |
seq := '\u' , (cp printStringRadix:16 padTo:4) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6655 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6656 |
seq := '\U',(cp printStringRadix:16 padTo:8) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6657 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6658 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6659 |
]]]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6660 |
out nextPutAll:seq |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6661 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6662 |
]. |
13987 | 6663 |
]. |
6664 |
^ out contents |
|
6665 |
||
6666 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6667 |
'hello\n\tworld' withoutCEscapes. |
17000 | 6668 |
'hello\nworld\na\n\tnice\n\t\tstring' withoutCEscapes withCEscapes. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6669 |
('hello ',(Character value:16r1234),' world') withCEscapes |
13987 | 6670 |
" |
6671 |
||
6672 |
"Created: / 25-01-2012 / 11:08:16 / cg" |
|
6673 |
! |
|
6674 |
||
9192 | 6675 |
withCRs |
17205 | 6676 |
"return a new string consisting of the receiver's characters |
16757 | 6677 |
with all \-characters replaced by cr-characters. |
6678 |
If there are no backslashes, return the original" |
|
6679 |
||
16759 | 6680 |
^ self copyReplaceAll:$\ with:(Character cr) ifNone:self |
9192 | 6681 |
|
6682 |
" |
|
6683 |
'hello\world' withCRs |
|
6684 |
" |
|
6685 |
||
6686 |
"Modified: / 18.7.1998 / 22:53:02 / cg" |
|
6687 |
! |
|
6688 |
||
6689 |
withEscapes |
|
15405 | 6690 |
<resource: #obsolete> |
13987 | 6691 |
"has been renamed; the name withEscapes is misleading" |
6692 |
||
6693 |
self obsoleteMethodWarning:'use withoutCEscapes'. |
|
6694 |
^ self withoutCEscapes. |
|
6695 |
||
6696 |
"Modified: / 25-01-2012 / 10:42:30 / cg" |
|
9192 | 6697 |
! |
6698 |
||
6699 |
withMatchEscapes |
|
4117 | 6700 |
"return a copy of the receiver with all match characters escaped |
6701 |
by $\ characters (to be usable as a match string). |
|
6702 |
Return the receiver, if there are none." |
|
6703 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6704 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6705 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6706 |
escape := self class matchEscapeCharacter. |
4117 | 6707 |
|
6708 |
in := self readStream. |
|
7986 | 6709 |
out := WriteStream on:(self species new:self size). |
4117 | 6710 |
[in atEnd] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6711 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6712 |
(c == escape or:['*[#' includes:c]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6713 |
out nextPut:$\. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6714 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6715 |
out nextPut:c. |
4117 | 6716 |
]. |
6717 |
^ out contents. |
|
6718 |
||
6719 |
" |
|
8874 | 6720 |
'*foo' withMatchEscapes |
6721 |
'\*foo' withMatchEscapes |
|
6722 |
'*foo' withMatchEscapes |
|
6723 |
'\\*foo' withMatchEscapes |
|
6724 |
'foo*' withMatchEscapes |
|
6725 |
'foo\*' withMatchEscapes |
|
6726 |
'foo\' withMatchEscapes |
|
6727 |
'f*o*o' withMatchEscapes |
|
4117 | 6728 |
" |
6729 |
||
6730 |
"Modified: 2.4.1997 / 18:13:04 / cg" |
|
9192 | 6731 |
! |
6732 |
||
14992 | 6733 |
withSeparatorsCompacted |
6734 |
"return a new string with each sequence of whiteSpace replaced by a single space character. |
|
6735 |
Preserves a leading/trailing space." |
|
6736 |
||
6737 |
^ self species streamContents:[:s | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6738 |
|skipping| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6739 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6740 |
skipping := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6741 |
1 to:self size do:[:idx | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6742 |
|char| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6743 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6744 |
char := self at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6745 |
char isSeparator ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6746 |
s nextPut:char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6747 |
skipping := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6748 |
] ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6749 |
skipping ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6750 |
s nextPut:(Character space). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6751 |
skipping := true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6752 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6753 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6754 |
] |
14992 | 6755 |
] |
6756 |
||
6757 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6758 |
'hello wwww' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6759 |
'hello wwww' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6760 |
' hello wwww' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6761 |
' hello wwww ' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6762 |
' hello wwww ' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6763 |
'hel lo www w' withSeparatorsCompacted |
14992 | 6764 |
" |
6765 |
! |
|
6766 |
||
18464 | 6767 |
withSeparatorsReplacedBy:replacementCharacter |
6768 |
"return a new string with each separator (whitespace) replaced by replacementCharacter. |
|
6769 |
Typically used with space as replacementCharacter" |
|
6770 |
||
6771 |
^ self species streamContents:[:s | |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6772 |
self do:[:ch | |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6773 |
ch isSeparator ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6774 |
s nextPut:replacementCharacter |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6775 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6776 |
s nextPut:ch. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6777 |
] |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6778 |
] |
18464 | 6779 |
] |
6780 |
||
6781 |
" |
|
6782 |
'hello wwww' withSeparatorsReplacedBy:$* |
|
6783 |
'hello ww ww' withSeparatorsReplacedBy:$* |
|
6784 |
' hello wwww' withSeparatorsReplacedBy:$* |
|
6785 |
'hel lo www w' withSeparatorsReplacedBy:$* |
|
6786 |
'hel |
|
6787 |
lo www |
|
6788 |
w' withSeparatorsReplacedBy:$* |
|
6789 |
" |
|
6790 |
! |
|
6791 |
||
9192 | 6792 |
withTabs |
19464 | 6793 |
"return a string consisting of the receiver's characters |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6794 |
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
|
6795 |
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
|
6796 |
otherwise a new string is returned. |
8874 | 6797 |
Limitation: only the very first spaces are replaced |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6798 |
(i.e. if the receiver contains newLine characters, |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6799 |
no tabs are inserted after those lineBreaks)" |
8874 | 6800 |
|
6801 |
|idx "{ SmallInteger }" |
|
6802 |
nTabs "{ SmallInteger }" |
|
608 | 6803 |
newString| |
6804 |
||
6805 |
idx := self findFirst:[:c | (c ~~ Character space)]. |
|
6806 |
nTabs := (idx-1) // 8. |
|
5815
4acdd87a77d4
// can return negative numbers.
Stefan Vogel <sv@exept.de>
parents:
5795
diff
changeset
|
6807 |
nTabs <= 0 ifTrue:[^ self]. |
608 | 6808 |
|
6809 |
"any tabs" |
|
15523 | 6810 |
newString := self species new:(self size - (nTabs * 7)). |
608 | 6811 |
newString atAll:(1 to:nTabs) put:(Character tab). |
6812 |
newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1). |
|
6813 |
^ newString |
|
6814 |
||
6815 |
" |
|
8874 | 6816 |
'12345678901234567890' withTabs |
6817 |
' 8901234567890' withTabs |
|
6818 |
' 901234567890' withTabs |
|
608 | 6819 |
' 67890' withTabs |
6820 |
' 7890' withTabs |
|
6821 |
' 890' withTabs |
|
6822 |
" |
|
9192 | 6823 |
! |
6824 |
||
6825 |
withTabsExpanded |
|
19464 | 6826 |
"return a string consisting of the receiver's characters, |
8874 | 6827 |
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
|
6828 |
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
|
6829 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6830 |
This does handle multiline strings." |
608 | 6831 |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6832 |
^ self withTabsExpanded:8 |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6833 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6834 |
" |
8874 | 6835 |
('1' , Character tab asString , 'x') withTabsExpanded |
6836 |
('12345' , Character tab asString , 'x') withTabsExpanded |
|
6837 |
('123456' , Character tab asString , 'x') withTabsExpanded |
|
6838 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
|
6839 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
|
6840 |
('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
|
6841 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6842 |
(String with:Character tab |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6843 |
with:Character tab |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6844 |
with:$1) withTabsExpanded |
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6845 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6846 |
(String with:Character tab |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6847 |
with:$1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6848 |
with:Character tab |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6849 |
with:$2) withTabsExpanded |
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6850 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6851 |
(String with:Character tab |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6852 |
with:$1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6853 |
with:Character cr |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6854 |
with:Character tab |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6855 |
with:$2) withTabsExpanded |
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6856 |
" |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6857 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6858 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
9192 | 6859 |
! |
6860 |
||
6861 |
withTabsExpanded:numSpaces |
|
19464 | 6862 |
"return a string consisting of the receiver's characters, |
8874 | 6863 |
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
|
6864 |
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
|
6865 |
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
|
6866 |
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
|
6867 |
|
8874 | 6868 |
|col "{ SmallInteger }" |
1381 | 6869 |
str ch |
6870 |
dstIdx "{ SmallInteger }" |
|
6871 |
newSz "{ SmallInteger }" |
|
6872 |
sz "{ SmallInteger }" |
|
6873 |
hasEmphasis e| |
|
608 | 6874 |
|
6875 |
(self includes:(Character tab)) ifFalse:[^ self]. |
|
1381 | 6876 |
|
6877 |
sz := self size. |
|
6878 |
||
6879 |
"/ count the new size first, instead of |
|
6880 |
"/ multiple resizing (better for large strings) |
|
6881 |
||
6882 |
col := 1. newSz := 0. |
|
6883 |
1 to:sz do:[:srcIdx | |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6884 |
ch := self at:srcIdx. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6885 |
ch == Character tab ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6886 |
col := col + 1. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6887 |
newSz := newSz + 1. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6888 |
ch == Character cr ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6889 |
col := 1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6890 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6891 |
] ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6892 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6893 |
newSz := newSz + 1. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6894 |
col := col + 1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6895 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6896 |
] |
608 | 6897 |
]. |
1381 | 6898 |
|
18258
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
6899 |
self isText ifTrue:[ |
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
6900 |
str := Text string: (self string class new: newSz). |
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
6901 |
] ifFalse:[ |
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
6902 |
str := self species new:newSz. |
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
6903 |
]. |
1381 | 6904 |
|
6905 |
hasEmphasis := self hasChangeOfEmphasis. |
|
6906 |
||
6907 |
col := 1. dstIdx := 1. |
|
6908 |
1 to:sz do:[:srcIdx | |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6909 |
ch := self at:srcIdx. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6910 |
|
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6911 |
ch == Character tab ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6912 |
col := col + 1. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6913 |
ch == Character cr ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6914 |
col := 1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6915 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6916 |
hasEmphasis ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6917 |
e := self emphasisAt:srcIdx. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6918 |
str emphasisAt:dstIdx put:e |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6919 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6920 |
str at:dstIdx put:ch. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6921 |
dstIdx := dstIdx + 1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6922 |
] ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6923 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6924 |
str at:dstIdx put:Character space. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6925 |
dstIdx := dstIdx + 1. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6926 |
col := col + 1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6927 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6928 |
] |
1381 | 6929 |
]. |
6930 |
^ str |
|
608 | 6931 |
|
6932 |
" |
|
8874 | 6933 |
('1' , Character tab asString , 'x') withTabsExpanded |
6934 |
('1' , Character tab asString , 'x') withTabsExpanded:4 |
|
6935 |
('12345' , Character tab asString , 'x') withTabsExpanded |
|
6936 |
('123456' , Character tab asString , 'x') withTabsExpanded |
|
6937 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
|
6938 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
|
6939 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6940 |
|
608 | 6941 |
(String with:Character tab |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6942 |
with:Character tab |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6943 |
with:$1) withTabsExpanded |
608 | 6944 |
|
6945 |
(String with:Character tab |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6946 |
with:$1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6947 |
with:Character tab |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6948 |
with:$2) withTabsExpanded |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6949 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6950 |
(String with:Character tab |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6951 |
with:$1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6952 |
with:Character cr |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6953 |
with:Character tab |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
6954 |
with:$2) withTabsExpanded |
608 | 6955 |
" |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6956 |
|
18258
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
6957 |
"Modified: / 12-05-1996 / 13:05:10 / cg" |
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
6958 |
"Modified: / 21-04-2015 / 15:40:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9192 | 6959 |
! |
6960 |
||
13987 | 6961 |
withoutAllSpaces |
16855 | 6962 |
"return a copy of the receiver with all whitespace removed" |
6963 |
||
13987 | 6964 |
^ self asCollectionOfWords asStringWith:''. |
6965 |
"/ |col string| |
|
6966 |
"/ |
|
6967 |
"/ col := self asCollectionOfWords. |
|
6968 |
"/ string := String new. |
|
6969 |
"/ col do:[:el | |
|
6970 |
"/ string := string,el |
|
6971 |
"/ ]. |
|
6972 |
"/ ^string |
|
6973 |
||
6974 |
" |
|
6975 |
'hello wwww' withoutAllSpaces |
|
6976 |
'hel lo www w' withoutAllSpaces |
|
6977 |
" |
|
6978 |
||
6979 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
6980 |
! |
|
6981 |
||
6982 |
withoutCEscapes |
|
15628 | 6983 |
"return a new string consisting of receiver's characters |
13987 | 6984 |
with all \X-character escapes replaced by corresponding-characters. |
6985 |
(similar to the way C-language Strings are converted). |
|
6986 |
The following escapes are supported: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6987 |
\r return character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6988 |
\n newline character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6989 |
\b backspace character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6990 |
\f formfeed character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6991 |
\t tab character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6992 |
\e escape character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6993 |
\\ the \ character itself |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6994 |
\nnn three digit octal number defining the characters ascii value |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6995 |
\xnn two digit hex number defining the characters ascii value |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6996 |
\unnnn four digit hex number defining the characters unicode value |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6997 |
\Unnnnnnnn eight digit hex number defining the characters unicode value |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6998 |
\other other |
13987 | 6999 |
|
7000 |
Notice, that \' is NOT a valid escape, since the general syntax of |
|
7001 |
string constants is not affected by this method. |
|
7002 |
||
7003 |
Although easily implementable, this is NOT done automatically |
|
7004 |
by the compiler (due to a lack of a language standard for this). |
|
7005 |
However, the compiler may detect sends ot #withEscapes to string literals |
|
7006 |
and place a modified string constant into the binary/byte-code. |
|
7007 |
Therefore, no runtime penalty will be payed for using these escapes. |
|
7008 |
(not in pre 2.11 versions) |
|
16863 | 7009 |
|
7010 |
This is the opposite of withCEscapes. |
|
17000 | 7011 |
|
7012 |
Sigh: this is named completely wrong (opposite naming of withCRs/witoutCRs), |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7013 |
but it cannot be changed easily, as these methods are already used heavily |
13987 | 7014 |
" |
7015 |
||
7016 |
|val "{ SmallInteger }" |
|
7017 |
in out nextChar nDigits| |
|
7018 |
||
7019 |
" |
|
7020 |
first, see if there is any escape; if not, return the receiver unchanged |
|
7021 |
" |
|
7022 |
(self includes:$\) ifFalse:[^ self ]. |
|
7023 |
||
7024 |
self hasChangeOfEmphasis ifTrue:[ self error:'emphasis not supported' ]. |
|
7025 |
out := CharacterWriteStream on:(String new:self size - 1). |
|
7026 |
||
7027 |
in := ReadStream on:self. |
|
7028 |
[in atEnd] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7029 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7030 |
nextChar == $\ ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7031 |
in atEnd ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7032 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7033 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7034 |
nextChar == $r ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7035 |
nextChar := Character return |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7036 |
] ifFalse:[ nextChar == $n ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7037 |
nextChar := Character nl |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7038 |
] ifFalse:[ nextChar == $b ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7039 |
nextChar := Character backspace |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7040 |
] ifFalse:[ nextChar == $f ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7041 |
nextChar := Character newPage |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7042 |
] ifFalse:[ nextChar == $t ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7043 |
nextChar := Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7044 |
] ifFalse:[ nextChar == $e ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7045 |
nextChar := Character esc |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7046 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7047 |
nextChar == $0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7048 |
val := 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7049 |
nextChar := in peek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7050 |
nDigits := 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7051 |
[nextChar notNil and:[nextChar isDigit and:[nDigits <= 3]]] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7052 |
val := (val * 8) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7053 |
nextChar := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7054 |
nDigits := nDigits + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7055 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7056 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7057 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7058 |
val := 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7059 |
nextChar == $x ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7060 |
2 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7061 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7062 |
val := (val * 16) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7063 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7064 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7065 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7066 |
nextChar == $u ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7067 |
4 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7068 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7069 |
val := (val * 16) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7070 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7071 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7072 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7073 |
nextChar == $U ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7074 |
8 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7075 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7076 |
val := (val * 16) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7077 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7078 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7079 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7080 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7081 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7082 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7083 |
]]]]]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7084 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7085 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7086 |
out nextPut:nextChar. |
13987 | 7087 |
]. |
7088 |
^ out contents |
|
7089 |
||
7090 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7091 |
'hello world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7092 |
'hello\world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7093 |
'hello\world\' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7094 |
'hello world\' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7095 |
'hello\tworld' withoutCEscapes |
13987 | 7096 |
'hello\nworld\na\n\tnice\n\t\tstring' withoutCEscapes |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7097 |
'hello\tworld\n' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7098 |
'hello\010world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7099 |
'hello\r\nworld' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7100 |
'hello\r\n\x08world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7101 |
'0\x080' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7102 |
'0\u12340' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7103 |
'0\U123456780' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7104 |
'0\0a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7105 |
'0\00a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7106 |
'0\000a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7107 |
'0\0000a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7108 |
'0\00000a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7109 |
'0\03770' withoutCEscapes |
13987 | 7110 |
" |
7111 |
||
7112 |
"Created: / 25-01-2012 / 10:41:44 / cg" |
|
7113 |
! |
|
7114 |
||
9192 | 7115 |
withoutCRs |
19464 | 7116 |
"return a new collection consisting of receiver's elements |
9192 | 7117 |
with all cr-characters replaced by \-characters. |
7118 |
This is the reverse operation of withCRs." |
|
7119 |
||
16759 | 7120 |
^ self copyReplaceAll:(Character cr) with:$\ ifNone:self |
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
7121 |
|
9192 | 7122 |
" |
7123 |
'hello |
|
7124 |
world' withoutCRs |
|
7125 |
" |
|
7126 |
||
7127 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
7128 |
! |
|
7129 |
||
7130 |
withoutLeadingSeparators |
|
608 | 7131 |
"return a copy of myself without leading separators. |
7132 |
Notice: this does remove tabs, newline or any other whitespace. |
|
7133 |
Returns an empty string, if the receiver consist only of whitespace." |
|
7134 |
||
7135 |
|index| |
|
7136 |
||
7137 |
index := self indexOfNonSeparatorStartingAt:1. |
|
7138 |
index ~~ 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7139 |
index == 1 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7140 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7141 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7142 |
^ self copyFrom:index |
608 | 7143 |
]. |
7144 |
^ '' |
|
7145 |
||
7146 |
" |
|
8874 | 7147 |
' foo ' withoutLeadingSeparators |
7148 |
'foo ' withoutLeadingSeparators |
|
7149 |
' foo' withoutLeadingSeparators |
|
7150 |
' ' withoutLeadingSeparators |
|
7151 |
'foo' withoutLeadingSeparators |
|
7152 |
(' ' , Character tab asString , ' foo ') withoutLeadingSeparators inspect |
|
608 | 7153 |
" |
9192 | 7154 |
! |
7155 |
||
7156 |
withoutMatchEscapes |
|
4117 | 7157 |
"return a copy of the receiver with all $\ removed or |
7158 |
the receiver, if there are none." |
|
7159 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
7160 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
7161 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
7162 |
escape := self class matchEscapeCharacter. |
4117 | 7163 |
|
7164 |
in := self readStream. |
|
8222
f2c454a9a038
replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents:
8124
diff
changeset
|
7165 |
out := self species writeStream. |
4117 | 7166 |
[in atEnd] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7167 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7168 |
c == escape ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7169 |
in atEnd ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7170 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7171 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7172 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7173 |
out nextPut:c. |
4117 | 7174 |
]. |
7175 |
^ out contents. |
|
7176 |
||
7177 |
" |
|
8874 | 7178 |
'*foo' withoutMatchEscapes |
7179 |
'\*foo' withoutMatchEscapes |
|
7180 |
'*foo' withoutMatchEscapes |
|
7181 |
'\\*foo' withoutMatchEscapes |
|
7182 |
'foo*' withoutMatchEscapes |
|
7183 |
'foo\*' withoutMatchEscapes |
|
7184 |
'foo\' withoutMatchEscapes |
|
7185 |
'f\*o\*o' withoutMatchEscapes |
|
4117 | 7186 |
" |
7187 |
||
7188 |
"Modified: 30.6.1997 / 13:40:23 / cg" |
|
9192 | 7189 |
! |
7190 |
||
7191 |
withoutPrefix:aString |
|
19677 | 7192 |
"if the receiver startsWith aString, return a copy without it. |
9192 | 7193 |
Otherwise return the receiver" |
7194 |
||
7195 |
(self startsWith:aString) ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7196 |
^ self copyFrom:aString size+1 |
9192 | 7197 |
]. |
7198 |
^ self |
|
7199 |
||
7200 |
" |
|
7201 |
'helloworld' withoutPrefix:'hello' |
|
7202 |
'helloworld' withoutPrefix:'foo' |
|
7203 |
" |
|
19677 | 7204 |
|
7205 |
"Modified: / 30-04-2016 / 10:01:00 / cg" |
|
9192 | 7206 |
! |
7207 |
||
10671 | 7208 |
withoutQuotes |
17000 | 7209 |
"/ remove quotes ($" and $') from the front and end of myself (if matching)" |
7210 |
||
7211 |
|firstChar| |
|
7212 |
||
17024 | 7213 |
self isEmpty ifTrue:[^ self]. |
7214 |
||
17000 | 7215 |
firstChar := self first. |
7216 |
((firstChar == $") or:[firstChar == $']) ifFalse:[^ self]. |
|
7217 |
||
7218 |
self last == firstChar ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7219 |
^ self copyFrom:2 to:(self size-1) |
10671 | 7220 |
]. |
17000 | 7221 |
^ self |
7222 |
||
7223 |
"/ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7224 |
"/ '"hello"' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7225 |
"/ '''hello''' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7226 |
"/ 'hello' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7227 |
"/ '"hello' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7228 |
"/ 'hello"' withoutQuotes |
17000 | 7229 |
"/ |
10671 | 7230 |
! |
7231 |
||
9192 | 7232 |
withoutSeparators |
608 | 7233 |
"return a copy of myself without leading and trailing whitespace. |
4156 | 7234 |
(but whiteSpace in-between is preserved) |
608 | 7235 |
Whitespace is space, tab, newline, formfeed. |
7236 |
Use withoutSpaces, if you want to remove spaces only." |
|
7237 |
||
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
7238 |
^ self trimForWhich:[:ch | ch isSeparator] |
608 | 7239 |
|
7240 |
" |
|
8874 | 7241 |
' foo ' withoutSeparators |
7242 |
' foo' withoutSeparators |
|
7243 |
'foo ' withoutSeparators |
|
7244 |
' ' withoutSeparators |
|
7245 |
(' foo' , Character tab asString , ' ') withoutSeparators inspect |
|
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
7246 |
' foo ' asUnicode16String withoutSeparators |
608 | 7247 |
" |
9192 | 7248 |
! |
7249 |
||
7250 |
withoutSpaces |
|
608 | 7251 |
"return a copy of myself without leading and trailing spaces. |
4156 | 7252 |
(but spaces in-between are preserved) |
608 | 7253 |
Notice: this does NOT remove tabs, newline or any other whitespace. |
7254 |
Use withoutSeparators for this." |
|
7255 |
||
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
7256 |
^ self trimForWhich:[:ch | ch == Character space] |
608 | 7257 |
|
7258 |
" |
|
8874 | 7259 |
' foo ' withoutSpaces |
7260 |
'foo ' withoutSpaces |
|
7261 |
' foo' withoutSpaces |
|
7262 |
' ' withoutSpaces |
|
7263 |
'a b' withoutSpaces |
|
7264 |
(' foo' , Character tab asString , ' ') withoutSpaces inspect |
|
608 | 7265 |
" |
9192 | 7266 |
! |
7267 |
||
7268 |
withoutTrailingSeparators |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
7269 |
"return a copy of myself without trailing separators. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
7270 |
Notice: this does remove tabs, newline or any other whitespace. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
7271 |
Returns an empty string, if the receiver consist only of whitespace." |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
7272 |
|
12188 | 7273 |
^ self withoutTrailingForWhich:[:ch | ch isSeparator] |
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
7274 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
7275 |
" |
8874 | 7276 |
' foo ' withoutTrailingSeparators |
7277 |
'foo ' withoutTrailingSeparators |
|
7278 |
' foo' withoutTrailingSeparators |
|
7279 |
' ' withoutTrailingSeparators |
|
7280 |
'foo' withoutTrailingSeparators |
|
7281 |
(' ' , Character tab asString , ' foo ') withoutTrailingSeparators inspect |
|
7282 |
(' foo' , Character tab asString) withoutTrailingSeparators inspect |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
7283 |
" |
9192 | 7284 |
! ! |
7285 |
||
7286 |
!CharacterArray methodsFor:'substring searching'! |
|
7287 |
||
15055 | 7288 |
findRangeOfString:subString |
7289 |
"find a substring. if found, return the start- and endIndex; |
|
7290 |
if not found, return an empty interval." |
|
7291 |
||
7292 |
^ self rangeOfSubCollection:subString startingAt:1 ifAbsent:[0 to:-1] caseSensitive:true |
|
7293 |
||
7294 |
" |
|
7295 |
'hello world' findRangeOfString:'llo' |
|
7296 |
'hello world' findRangeOfString:'ole' |
|
7297 |
" |
|
7298 |
! |
|
7299 |
||
9192 | 7300 |
findString:subString |
7301 |
"find a substring. if found, return the index; |
|
7302 |
if not found, return 0." |
|
7303 |
||
7304 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:true |
|
7305 |
||
7306 |
" |
|
7307 |
'hello world' findString:'llo' |
|
7308 |
'hello world' findString:'ole' |
|
7309 |
" |
|
7310 |
! |
|
608 | 7311 |
|
15734 | 7312 |
findString:subString caseSensitive:caseSensitive |
7313 |
"find a substring. if found, return the index; |
|
7314 |
if not found, return 0." |
|
7315 |
||
7316 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:caseSensitive |
|
7317 |
||
7318 |
" |
|
7319 |
'hello world' findString:'LLo' caseSensitive:true |
|
7320 |
'hello world' findString:'LLo' caseSensitive:false |
|
7321 |
" |
|
7322 |
! |
|
7323 |
||
608 | 7324 |
findString:subString ifAbsent:exceptionBlock |
7325 |
"find a substring. If found, return the index; |
|
7326 |
if not found, return the result of evaluating exceptionBlock." |
|
7327 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7328 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock caseSensitive:true |
608 | 7329 |
! |
7330 |
||
11018 | 7331 |
findString:subString ignoreCase:ignoreCase |
15734 | 7332 |
<resource: #obsolete> |
11018 | 7333 |
"find a substring. if found, return the index; |
7334 |
if not found, return 0." |
|
7335 |
||
7336 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:ignoreCase not |
|
7337 |
||
7338 |
" |
|
7339 |
'hello world' findString:'LLo' ignoreCase:false |
|
7340 |
'hello world' findString:'LLo' ignoreCase:true |
|
7341 |
" |
|
7342 |
! |
|
7343 |
||
608 | 7344 |
findString:subString startingAt:index |
7345 |
"find a substring, starting at index. if found, return the index; |
|
7346 |
if not found, return 0." |
|
7347 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7348 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:0 caseSensitive:true |
608 | 7349 |
|
7350 |
" |
|
9192 | 7351 |
'hello yello' findString:'llo' startingAt:1 |
7352 |
'hello yello' findString:'llo' startingAt:5 |
|
7353 |
'hello yello' findString:'llo' startingAt:15 |
|
7354 |
" |
|
7355 |
! |
|
608 | 7356 |
|
7357 |
findString:subString startingAt:index ifAbsent:exceptionBlock |
|
7358 |
"find a substring, starting at index. if found, return the index; |
|
7359 |
if not found, return the result of evaluating exceptionBlock." |
|
7360 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7361 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:true |
608 | 7362 |
! |
7363 |
||
12177 | 7364 |
findString:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
10929 | 7365 |
"find a substring, starting at index. if found, return the index; |
7366 |
if not found, return the result of evaluating exceptionBlock." |
|
7367 |
||
7368 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
|
7369 |
! |
|
7370 |
||
608 | 7371 |
includesString:aString |
7372 |
"return true, if a substring is contained in the receiver" |
|
7373 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7374 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0 caseSensitive:true) ~~ 0 |
608 | 7375 |
|
7376 |
" |
|
12177 | 7377 |
'hello world' includesString:'hel' |
8874 | 7378 |
'hello world' includesString:'rld' |
9192 | 7379 |
'hello world' includesString:'llo' |
7380 |
'hello world' includesString:'LLO' |
|
12177 | 7381 |
'hello world' includesString:'' |
9192 | 7382 |
" |
7383 |
! |
|
9191 | 7384 |
|
7385 |
includesString:aString caseSensitive:caseSensitive |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7386 |
"return true, if a substring is contained in the receiver" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7387 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7388 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0 caseSensitive:caseSensitive) ~~ 0 |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7389 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7390 |
" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7391 |
'hello world' includesString:'hel' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7392 |
'hello world' includesString:'HEL' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7393 |
'hello world' includesString:'HEL' caseSensitive:false |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7394 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7395 |
'hello world' includesString:'wor' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7396 |
'hello world' includesString:'WOR' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7397 |
'hello world' includesString:'WOR' caseSensitive:false |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7398 |
" |
9192 | 7399 |
! |
7400 |
||
17486 | 7401 |
indexOfString: aString |
7402 |
"VSE and V'age compatibility" |
|
7403 |
"find a substring. If found, return the index; if not found, return 0." |
|
7404 |
||
18939 | 7405 |
^ self indexOfSubCollection: aString startingAt:1 ifAbsent:[0] |
7406 |
! |
|
7407 |
||
7408 |
indexOfString:aString ifAbsent:exceptionValue |
|
7409 |
"VSE and V'age compatibility" |
|
7410 |
"find a substring. If found, return the index; if not found, return 0." |
|
7411 |
||
7412 |
^ self indexOfSubCollection: aString startingAt:1 ifAbsent:exceptionValue |
|
7413 |
||
7414 |
" |
|
7415 |
'abcdefabcdef' indexOfString:'fab' ifAbsent:[999] |
|
7416 |
'abcdefabcdef' indexOfString:'xxx' ifAbsent:[999] |
|
7417 |
" |
|
17486 | 7418 |
! |
7419 |
||
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7420 |
indexOfString:aString startingAt:startIndex |
18721 | 7421 |
"VSE and V'age compatibility" |
7422 |
"find a substring. If found, return the index; if not found, return 0." |
|
7423 |
||
7424 |
^ self indexOfSubCollection:aString startingAt:startIndex ifAbsent:[0] |
|
7425 |
! |
|
7426 |
||
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7427 |
indexOfString:aString startingAt:startIndex ifAbsent:exceptionalValue |
18721 | 7428 |
"VSE and V'age compatibility" |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7429 |
"find a substring. |
18721 | 7430 |
If found, return the index; if not found, the value from exceptionalValue." |
7431 |
||
7432 |
^ self indexOfSubCollection:aString startingAt:startIndex ifAbsent:exceptionalValue |
|
7433 |
! |
|
7434 |
||
18671 | 7435 |
indexOfSubCollection:subString caseSensitive:caseSensitive |
7436 |
"find a substring, starting at index. if found, return the index; |
|
7437 |
if not found, return the result of evaluating exceptionBlock. |
|
7438 |
This is a q&d hack - not very efficient" |
|
7439 |
||
7440 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:[0] caseSensitive:caseSensitive. |
|
7441 |
! |
|
7442 |
||
9192 | 7443 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
7444 |
"find a substring, starting at index. if found, return the index; |
|
7445 |
if not found, return the result of evaluating exceptionBlock. |
|
7446 |
This is a q&d hack - not very efficient" |
|
7447 |
||
7448 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:true. |
|
7449 |
! |
|
7450 |
||
7451 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7452 |
"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
|
7453 |
if not found, return the result of evaluating exceptionBlock. |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7454 |
This is a q&d hack - not very efficient" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7455 |
|
608 | 7456 |
|firstChar found |
7457 |
startIndex "{ Class: SmallInteger }" |
|
7458 |
subSize "{ Class: SmallInteger }" |
|
7459 |
mySize "{ Class: SmallInteger }" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7460 |
runIdx "{ Class: SmallInteger }" |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7461 |
tester| |
608 | 7462 |
|
7463 |
subSize := subString size. |
|
12177 | 7464 |
subSize == 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7465 |
subString isString ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7466 |
self error:'non string argument' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7467 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7468 |
"empty string does not match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7469 |
^ 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7470 |
"empty string matches" |
15433 | 7471 |
"/ ^ index |
6122
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
7472 |
]. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7473 |
|
608 | 7474 |
mySize := self size. |
7475 |
firstChar := subString at:1. |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7476 |
caseSensitive ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7477 |
tester := [:c1 :c2 | c1 = c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7478 |
startIndex := self indexOf:firstChar startingAt:index. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7479 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7480 |
tester := [:c1 :c2 | c1 sameAs: c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7481 |
startIndex := self findFirst:[:c | c sameAs:firstChar] startingAt:index. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7482 |
]. |
608 | 7483 |
[startIndex == 0] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7484 |
runIdx := startIndex. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7485 |
found := true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7486 |
1 to:subSize do:[:i | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7487 |
runIdx > mySize ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7488 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7489 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7490 |
(tester value:(subString at:i) value:(self at:runIdx)) ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7491 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7492 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7493 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7494 |
runIdx := runIdx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7495 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7496 |
found ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7497 |
^ startIndex |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7498 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7499 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7500 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7501 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7502 |
startIndex := self findFirst:[:c | c sameAs:firstChar] startingAt:(startIndex + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7503 |
]. |
608 | 7504 |
]. |
7505 |
^ exceptionBlock value |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7506 |
|
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7507 |
"Modified: 23.2.1996 / 15:35:15 / cg" |
9192 | 7508 |
! |
7509 |
||
17191 | 7510 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive ignoreDiacritics:ignoreDiacritics |
7511 |
"find a substring, starting at index. if found, return the index; |
|
7512 |
if not found, return the result of evaluating exceptionBlock. |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7513 |
This is a q&d hack - not very efficient |
17191 | 7514 |
(see implementation in string, for a much faster algorithm)" |
7515 |
||
7516 |
|firstChar found |
|
7517 |
startIndex "{ Class: SmallInteger }" |
|
7518 |
subSize "{ Class: SmallInteger }" |
|
7519 |
mySize "{ Class: SmallInteger }" |
|
7520 |
runIdx "{ Class: SmallInteger }" |
|
7521 |
tester charMap firstCharMapped findNextIndex| |
|
7522 |
||
7523 |
subSize := subString size. |
|
7524 |
subSize == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7525 |
subString isString ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7526 |
self error:'non string argument' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7527 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7528 |
"empty string does not match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7529 |
^ 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7530 |
"empty string matches" |
17191 | 7531 |
"/ ^ index |
7532 |
]. |
|
7533 |
||
7534 |
mySize := self size. |
|
7535 |
firstChar := subString at:1. |
|
7536 |
ignoreDiacritics ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7537 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7538 |
charMap := [:ch | ch asLowercase withoutDiacritics]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7539 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7540 |
charMap := [:ch | ch withoutDiacritics]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7541 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7542 |
tester := [:c1 :c2 | (charMap value:c1) = (charMap value:c2) ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7543 |
firstCharMapped := (charMap value:firstChar). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7544 |
findNextIndex := [:index | self findFirst:[:ch | (charMap value:ch) = firstCharMapped] startingAt:index]. |
17191 | 7545 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7546 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7547 |
tester := [:c1 :c2 | c1 = c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7548 |
findNextIndex := [:index | self indexOf:firstChar startingAt:index]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7549 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7550 |
tester := [:c1 :c2 | c1 sameAs: c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7551 |
findNextIndex := [:index | self findFirst:[:c | c sameAs:firstChar] startingAt:index]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7552 |
]. |
17191 | 7553 |
]. |
7554 |
startIndex := findNextIndex value:index. |
|
7555 |
[startIndex == 0] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7556 |
runIdx := startIndex. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7557 |
found := true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7558 |
1 to:subSize do:[:i | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7559 |
runIdx > mySize ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7560 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7561 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7562 |
(tester value:(subString at:i) value:(self at:runIdx)) ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7563 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7564 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7565 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7566 |
runIdx := runIdx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7567 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7568 |
found ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7569 |
^ startIndex |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7570 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7571 |
startIndex := findNextIndex value:(startIndex + 1) |
17191 | 7572 |
]. |
7573 |
^ exceptionBlock value |
|
7574 |
||
7575 |
" |
|
17600 | 7576 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:1 ifAbsent:0 caseSensitive:false ignoreDiacritics:true. 5 |
7577 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:6 ifAbsent:0 caseSensitive:false ignoreDiacritics:true. 0 |
|
7578 |
||
7579 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:1 ifAbsent:0 caseSensitive:false ignoreDiacritics:false. 5 |
|
7580 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:6 ifAbsent:0 caseSensitive:false ignoreDiacritics:false. 0 |
|
17191 | 7581 |
" |
7582 |
! |
|
7583 |
||
18939 | 7584 |
lastIndexOfString:aString |
7585 |
"VSE and V'age compatibility" |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7586 |
"find the last occurrence of substring. |
18939 | 7587 |
If found, return the index; if not found, return 0." |
7588 |
||
7589 |
^ self lastIndexOfSubCollection:aString startingAt:(self size-aString size+1) ifAbsent:[0] |
|
7590 |
||
7591 |
" 123456789012 |
|
7592 |
'abcdefabcdef' lastIndexOfString:'abc' |
|
7593 |
'abcdefabcdef' lastIndexOfString:'abc' startingAt:6 |
|
7594 |
'abcdefabcdef' lastIndexOfString:'xxx' startingAt:6 |
|
7595 |
" |
|
7596 |
! |
|
7597 |
||
7598 |
lastIndexOfString:aString ifAbsent:exceptionValue |
|
7599 |
"VSE and V'age compatibility" |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7600 |
"find the last occurrence of substring. |
18939 | 7601 |
If found, return the index; if not found, return 0." |
7602 |
||
7603 |
^ self lastIndexOfSubCollection:aString startingAt:(self size-aString size+1) ifAbsent:exceptionValue |
|
7604 |
||
7605 |
" 123456789012 |
|
7606 |
'abcdefabcdef' lastIndexOfString:'abc' ifAbsent:[999] |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7607 |
'abcdefabcdef' lastIndexOfString:'xxx' ifAbsent:[999] |
18939 | 7608 |
" |
7609 |
! |
|
7610 |
||
7611 |
lastIndexOfString:aString startingAt:startIndex |
|
7612 |
"VSE and V'age compatibility" |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7613 |
"find the last occurrence of a substring. |
18939 | 7614 |
If found, return the index; if not found, return 0." |
7615 |
||
7616 |
^ self lastIndexOfSubCollection:aString startingAt:startIndex ifAbsent:[0] |
|
7617 |
||
7618 |
" 123456789012 |
|
7619 |
'abcdefabcdef' lastIndexOfString:'abc' |
|
7620 |
'abcdefabcdef' lastIndexOfString:'abc' startingAt:6 |
|
7621 |
" |
|
7622 |
! |
|
7623 |
||
7624 |
lastIndexOfString:aString startingAt:startIndex ifAbsent:exceptionValue |
|
7625 |
"VSE and V'age compatibility" |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7626 |
"find the last occurrence of a substring. |
18939 | 7627 |
If found, return the index; if not found, return 0." |
7628 |
||
7629 |
^ self lastIndexOfSubCollection:aString startingAt:startIndex ifAbsent:exceptionValue |
|
7630 |
||
7631 |
" 123456789012 |
|
7632 |
'abcdefabcdef' lastIndexOfString:'abc' |
|
7633 |
'abcdefabcdef' lastIndexOfString:'abc' startingAt:6 |
|
7634 |
'abcdefabcdef' lastIndexOfString:'xxx' startingAt:6 ifAbsent:999 |
|
7635 |
" |
|
7636 |
! |
|
7637 |
||
15055 | 7638 |
rangeOfSubCollection:subString startingAt:start ifAbsent:exceptionValue caseSensitive:caseSensitive |
7639 |
"find a substring. if found, return the start- and endIndex; |
|
7640 |
if not found, return the value of exceptionValue." |
|
7641 |
||
7642 |
|i| |
|
7643 |
||
7644 |
i := self indexOfSubCollection:subString startingAt:start ifAbsent:0 caseSensitive:caseSensitive. |
|
7645 |
i == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7646 |
^ exceptionValue value |
15055 | 7647 |
]. |
7648 |
^ i to:(i + subString size - 1) |
|
7649 |
||
7650 |
" |
|
7651 |
'hello world' findRangeOfString:'llo' |
|
7652 |
'hello world' findRangeOfString:'ole' |
|
7653 |
" |
|
9192 | 7654 |
! ! |
7655 |
||
7656 |
!CharacterArray methodsFor:'testing'! |
|
7657 |
||
18463 | 7658 |
argumentCount |
7659 |
"treating the receiver as a message selector, return how many arguments would it take (ANSI)" |
|
7660 |
||
7661 |
|binopChars| |
|
7662 |
||
7663 |
(self size <= Method maxBinarySelectorSize) ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7664 |
binopChars := Method binarySelectorCharacters. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7665 |
(self conform:[:eachChar | (binopChars includes:eachChar)]) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7666 |
^ 1 |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7667 |
]. |
18463 | 7668 |
]. |
7669 |
^ self occurrencesOf:$: |
|
7670 |
||
7671 |
" |
|
7672 |
'foo:bar:' argumentCount |
|
7673 |
#foo:bar: argumentCount |
|
7674 |
'hello' argumentCount |
|
7675 |
'+' argumentCount |
|
7676 |
'++' argumentCount |
|
7677 |
'+++' argumentCount |
|
7678 |
'|' argumentCount |
|
7679 |
'?' argumentCount |
|
7680 |
'_' argumentCount |
|
7681 |
'_:' argumentCount |
|
7682 |
'_:_:' argumentCount |
|
7683 |
'<->' argumentCount |
|
7684 |
" |
|
7685 |
! |
|
7686 |
||
18597 | 7687 |
characterSize |
7688 |
"answer the size in bits of my largest character (actually only 7, 8, 16 or 32)" |
|
7689 |
||
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7690 |
|string max |
18597 | 7691 |
sz "{ Class:SmallInteger}" | |
15829 | 7692 |
|
7693 |
(string := self string) ~~ self ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7694 |
^ string characterSize. |
18597 | 7695 |
]. |
7696 |
||
7697 |
sz := self size. |
|
7698 |
max := 7. |
|
7699 |
1 to:sz do:[:idx | |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7700 |
|thisSize| |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7701 |
|
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7702 |
thisSize := (self at:idx) characterSize. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7703 |
thisSize > max ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7704 |
max := thisSize. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7705 |
max == 32 ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7706 |
"shortcut: we know, that max size is 32" |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7707 |
^ 32. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7708 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7709 |
]. |
15829 | 7710 |
]. |
18597 | 7711 |
|
7712 |
^ max. |
|
7713 |
||
7714 |
" |
|
7715 |
'hello' characterSize |
|
7716 |
'hello' asUnicode32String characterSize |
|
7717 |
'helloü' asUnicode32String characterSize |
|
7718 |
'hello' asText allBold characterSize |
|
7719 |
" |
|
7720 |
! |
|
7721 |
||
7722 |
contains8BitCharacters |
|
7723 |
<resource: #obsolete> |
|
7724 |
||
7725 |
^ self containsNon7BitAscii |
|
7726 |
! |
|
7727 |
||
7728 |
containsNon7BitAscii |
|
7729 |
"return true, if the underlying string contains 8BitCharacters (or widers) |
|
7730 |
(i.e. if it is non-ascii)" |
|
7731 |
||
7732 |
|string |
|
7733 |
sz "{ Class:SmallInteger }"| |
|
7734 |
||
7735 |
(string := self string) ~~ self ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7736 |
^ string containsNon7BitAscii |
18597 | 7737 |
]. |
7738 |
sz := self size. |
|
7739 |
1 to:sz do:[:idx| |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7740 |
(self at:idx) codePoint > 16r7F ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7741 |
^ true. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7742 |
]. |
18597 | 7743 |
]. |
7744 |
^ false. |
|
7745 |
||
7746 |
" |
|
7747 |
'hello' asUnicode32String containsNon7BitAscii |
|
7748 |
'hello üöä' asUnicode32String containsNon7BitAscii |
|
7749 |
'hello' asUnicode32String asText allBold containsNon7BitAscii |
|
7750 |
'hello üö' asUnicode32String asText allBold containsNon7BitAscii |
|
15829 | 7751 |
" |
7752 |
! |
|
7753 |
||
9192 | 7754 |
isAlphaNumeric |
7755 |
"return true, if the receiver is some alphanumeric word; |
|
7756 |
i.e. consists of a letter followed by letters or digits." |
|
7757 |
||
7758 |
self size == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7759 |
"mhmh what is this ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7760 |
^ false |
9192 | 7761 |
]. |
7762 |
(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
|
7763 |
^ self conform:[:char | char isLetterOrDigit]. |
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7764 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7765 |
" |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7766 |
'helloWorld' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7767 |
'foo1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7768 |
'f1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7769 |
'1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7770 |
'+' isAlphaNumeric |
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7771 |
" |
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7772 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7773 |
"Modified: / 13-10-2006 / 12:53:49 / cg" |
9192 | 7774 |
! |
9190 | 7775 |
|
7776 |
isBinarySelector |
|
10903 | 7777 |
"treating the receiver as a message selector, return true if its a binary selector. |
7778 |
Notice, that st/x does not have a size <= 2 limit for unaries" |
|
9190 | 7779 |
|
7780 |
|binopChars| |
|
7781 |
||
18463 | 7782 |
(self size > Method maxBinarySelectorSize) ifTrue:[^ false]. |
7783 |
||
7784 |
binopChars := Method binarySelectorCharacters. |
|
9190 | 7785 |
^ (self conform:[:char | (binopChars includes:char)]) |
7786 |
||
7787 |
" |
|
7788 |
'foo:bar:' isBinarySelector |
|
7789 |
#foo:bar: isBinarySelector |
|
7790 |
'hello' isBinarySelector |
|
7791 |
'+' isBinarySelector |
|
7792 |
'|' isBinarySelector |
|
8874 | 7793 |
'?' isBinarySelector |
7794 |
':' isBinarySelector |
|
7795 |
'a:' isBinarySelector |
|
7796 |
'->' isBinarySelector |
|
7797 |
'<->' isBinarySelector |
|
7798 |
'::' isBinarySelector |
|
7482 | 7799 |
" |
7800 |
||
7801 |
"Modified: 4.1.1997 / 14:16:14 / cg" |
|
9192 | 7802 |
! |
7803 |
||
7804 |
isBlank |
|
7805 |
"return true, if the receiver contains spaces only" |
|
7806 |
||
9230 | 7807 |
^ (self contains:[:char | char ~~ Character space]) not |
7808 |
||
7809 |
" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7810 |
'' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7811 |
' a ' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7812 |
' ' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7813 |
' ' asUnicode16String isBlank |
9230 | 7814 |
" |
9192 | 7815 |
! |
7816 |
||
10903 | 7817 |
isKeywordSelector |
7818 |
"return true, iff there are only alphanumeric or underline characters separated by colons. |
|
19682 | 7819 |
Must end with a colon. |
7820 |
You can use this to check an arbitrary string for being valid as a keyword. |
|
7821 |
If you have a valid selector at hand, and need to know if it is a keyword or not, |
|
7822 |
use #isKeyword, which is much faster." |
|
10903 | 7823 |
|
7824 |
|state| |
|
7825 |
||
19682 | 7826 |
(self size == 0) ifTrue:[^ false]. |
7827 |
(self last == $:) ifFalse:[^ false]. |
|
7828 |
||
12177 | 7829 |
state := #initial. |
10903 | 7830 |
self do:[:char | |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7831 |
(state == #initial or:[ state == #gotColon]) ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7832 |
(char isLetterOrUnderline) ifFalse:[^ false]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7833 |
state := #gotCharacter. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7834 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7835 |
char == $: ifTrue:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7836 |
state := #gotColon. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7837 |
] ifFalse:[ |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7838 |
(char isLetterOrDigit or:[char == $_]) ifFalse:[^ false]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7839 |
]. |
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7840 |
]. |
10903 | 7841 |
]. |
7842 |
^ state == #gotColon. |
|
7843 |
||
7844 |
" |
|
12177 | 7845 |
self assert:(':' isKeywordSelector not). |
10903 | 7846 |
self assert:(':a' isKeywordSelector not). |
7847 |
self assert:('1:' isKeywordSelector not). |
|
7848 |
self assert:('a:' isKeywordSelector). |
|
7849 |
self assert:('_:' isKeywordSelector). |
|
7850 |
self assert:('_a:' isKeywordSelector). |
|
7851 |
self assert:('_1:' isKeywordSelector). |
|
7852 |
self assert:('_1::' isKeywordSelector not). |
|
7853 |
self assert:('_:_:' isKeywordSelector). |
|
7854 |
self assert:('a:b:' isKeywordSelector). |
|
7855 |
self assert:('aa:bb:' isKeywordSelector). |
|
7856 |
self assert:('aa:bb:a' isKeywordSelector not). |
|
7857 |
self assert:('1:2:' isKeywordSelector not). |
|
7858 |
" |
|
19682 | 7859 |
|
7860 |
"Modified (comment): / 30-04-2016 / 18:20:14 / cg" |
|
10903 | 7861 |
! |
7862 |
||
10431 | 7863 |
isNameSpaceSelector |
7864 |
"Answer true if the receiver contains chars which form a nameSpace selector name. |
|
7865 |
These are of the form ':<ns>::<sel>', where ns is the NameSpace and sel is the regular selector. |
|
7866 |
For example, the #+ selector as seen by the Foo namespace would be actually #':Foo::+'. |
|
17511 | 7867 |
This special format (a symbol starting with a colon) was chosen, because almost every other selector |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7868 |
is legal, and this can be checked quickly by just looking at the first character. |
10431 | 7869 |
You cannot easily change this algorithm here, as it is also known by the VM's lookup function." |
7870 |
||
7871 |
|i| |
|
7872 |
||
16733 | 7873 |
(self at:1) == $: ifFalse:[^ false]. |
17511 | 7874 |
|
10431 | 7875 |
i := self indexOf:$: startingAt:2. |
7876 |
i == 0 ifTrue:[^ false]. |
|
7877 |
self size <= (i+1) ifTrue:[^ false]. |
|
7878 |
(self at:i+1) == $: ifFalse:[^ false]. |
|
7879 |
(self at:i+2) == $: ifTrue:[^ false]. |
|
7880 |
"/ could check if the rest after the ns-prefix and colons is a valid selector... |
|
7881 |
^ true |
|
7882 |
||
7883 |
"test: |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7884 |
self assert:('+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7885 |
self assert:(':+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7886 |
self assert:(':Foo:+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7887 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7888 |
self assert:(':Foo::+' isNameSpaceSelector). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7889 |
self assert:(':Foo::bar:baz:' isNameSpaceSelector). |
10431 | 7890 |
" |
7891 |
||
7892 |
"Created: / 05-03-2007 / 11:35:31 / cg" |
|
7893 |
! |
|
7894 |
||
9192 | 7895 |
isNumeric |
7896 |
"return true, if the receiver is some numeric word; |
|
7897 |
i.e. consists only of digits." |
|
7898 |
||
7899 |
self size == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7900 |
^ false |
9192 | 7901 |
]. |
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7902 |
^ self conform:[:char | char isDigit] |
9192 | 7903 |
|
7904 |
" |
|
7905 |
'helloWorld' isNumeric |
|
7906 |
'foo1234' isNumeric |
|
7907 |
'f1234' isNumeric |
|
7908 |
'1234' isNumeric |
|
7909 |
'+' isNumeric |
|
7910 |
" |
|
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7911 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7912 |
"Modified: / 13-10-2006 / 12:54:12 / cg" |
9192 | 7913 |
! |
7914 |
||
18893 | 7915 |
isPlainString |
7916 |
"return true, if the receiver is a plain string (without attributes); |
|
7917 |
true is returned here - redefinition of Object>>isPlainString." |
|
7918 |
||
7919 |
^ true |
|
7920 |
! |
|
7921 |
||
9230 | 7922 |
isString |
7923 |
"return true, if the receiver is some kind of string; |
|
7924 |
true is returned here - redefinition of Object>>isString." |
|
7925 |
||
7926 |
^ true |
|
7927 |
! |
|
7928 |
||
7929 |
isUnarySelector |
|
7930 |
"Answer true if the receiver contains only chars in an ANSI unary method selector, false otherwise." |
|
7931 |
||
17442 | 7932 |
^ (self first isLetterOrUnderline) |
9845 | 7933 |
and:[ self conform: [ :chr | chr isLetterOrDigit or:[chr == $_] ]] |
7934 |
||
7935 |
"Modified: / 13-09-2006 / 11:35:15 / cg" |
|
9230 | 7936 |
! |
7937 |
||
14122 | 7938 |
isUnicode16String |
7939 |
^ false |
|
7940 |
! |
|
7941 |
||
7942 |
isUnicode32String |
|
19939 | 7943 |
"true if this is a 4-byte unicode string" |
7944 |
||
14122 | 7945 |
^ false |
7946 |
! |
|
7947 |
||
7948 |
isUnicodeString |
|
19938 | 7949 |
"true if this is a 2- or 4-byte unicode string |
7950 |
(i.e. not a single byte string). |
|
7951 |
Notice, that the name is misleading: |
|
7952 |
all strings are use unicode encoding" |
|
7953 |
||
14122 | 7954 |
^ false |
7955 |
! |
|
7956 |
||
9230 | 7957 |
isValidSmalltalkIdentifier |
19464 | 7958 |
"return true, if the receiver's characters make up a valid smalltalk identifier" |
9230 | 7959 |
|
7960 |
|scanner tok| |
|
7961 |
||
7962 |
scanner := Compiler new. |
|
7963 |
scanner source:(self readStream). |
|
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
7964 |
Parser parseErrorSignal handle:[:ex | |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7965 |
tok := nil. |
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
7966 |
] do:[ |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7967 |
tok := scanner nextToken. |
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
7968 |
]. |
9230 | 7969 |
tok ~~ #Identifier ifTrue:[ |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7970 |
^ false |
9230 | 7971 |
]. |
7972 |
scanner tokenPosition == 1 ifFalse:[^ false]. |
|
7973 |
^ scanner sourceStream atEnd. |
|
7974 |
||
7975 |
" |
|
7976 |
'foo' isValidSmalltalkIdentifier |
|
7977 |
'1foo' isValidSmalltalkIdentifier |
|
7978 |
'_foo' isValidSmalltalkIdentifier |
|
7979 |
'_foo_bar_' isValidSmalltalkIdentifier |
|
7980 |
'foo ' isValidSmalltalkIdentifier |
|
7981 |
' foo' isValidSmalltalkIdentifier |
|
7982 |
" |
|
7983 |
! |
|
7984 |
||
14555 | 7985 |
isWideString |
19580 | 7986 |
"true if I require more than one byte per character" |
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7987 |
|
15829 | 7988 |
|string| |
7989 |
||
7990 |
(string := self string) ~~ self ifTrue:[ |
|
19775
cfffb072d9a3
withoutPrefix/withoutSuffix
Claus Gittinger <cg@exept.de>
parents:
19774
diff
changeset
|
7991 |
^ string isWideString. |
15829 | 7992 |
]. |
7993 |
^ self contains:[:aCharacter | aCharacter codePoint > 16rFF]. |
|
14555 | 7994 |
! |
7995 |
||
9192 | 7996 |
numArgs |
18463 | 7997 |
<resource: #obsolete> |
608 | 7998 |
"treating the receiver as a message selector, return how many arguments would it take" |
7999 |
||
18463 | 8000 |
^ self argumentCount |
9192 | 8001 |
! |
8002 |
||
8003 |
partsIfSelector |
|
14629 | 8004 |
"treat the receiver as a message selector, return a collection of parts. |
8005 |
Notice: this is more tolerant than Smalltalk's syntax would suggest; |
|
8006 |
especially it allows for empty keyword parts between colons. |
|
8007 |
This is not (and should not be checked here), to allow parsing of |
|
8008 |
degenerate selectors as appearing with objectiveC." |
|
608 | 8009 |
|
9192 | 8010 |
|idx1 "{ Class: SmallInteger }" |
8011 |
coll idx2 sz| |
|
8012 |
||
8013 |
coll := OrderedCollection new. |
|
8014 |
idx1 := 1. |
|
8015 |
sz := self size. |
|
16245 | 8016 |
[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
8017 |
idx2 := self indexOf:$: startingAt:idx1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
8018 |
(idx2 == 0 or:[idx2 == sz]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
8019 |
coll add:(self copyFrom:idx1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
8020 |
^ coll |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
8021 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
8022 |
coll add:(self copyFrom:idx1 to:idx2). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
8023 |
idx1 := idx2 + 1 |
16245 | 8024 |
] loop. |
9192 | 8025 |
|
8026 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
8027 |
'foo:' partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
8028 |
'foo:bar:' partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
8029 |
'foo::::' partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
8030 |
#foo:bar: partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
8031 |
'hello' partsIfSelector |
9192 | 8032 |
'+' partsIfSelector |
8033 |
" |
|
64 | 8034 |
! ! |
8035 |
||
9192 | 8036 |
!CharacterArray methodsFor:'tracing'! |
8037 |
||
8038 |
traceInto:aRequestor level:level from:referrer |
|
8039 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
8040 |
||
8041 |
^ aRequestor traceCharacterArray:self level:level from:referrer |
|
8042 |
||
8043 |
||
8044 |
! ! |
|
8045 |
||
8046 |
!CharacterArray methodsFor:'visiting'! |
|
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
8047 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
8048 |
acceptVisitor:aVisitor with:aParameter |
16733 | 8049 |
"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
|
8050 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
8051 |
^ aVisitor visitString:self with:aParameter |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
8052 |
! ! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
8053 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
8054 |
!CharacterArray class methodsFor:'documentation'! |
629 | 8055 |
|
8056 |
version |
|
18476 | 8057 |
^ '$Header$' |
12058 | 8058 |
! |
8059 |
||
8060 |
version_CVS |
|
18476 | 8061 |
^ '$Header$' |
18258
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
8062 |
! |
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
8063 |
|
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
8064 |
version_HG |
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
8065 |
|
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
8066 |
^ '$Changeset: <not expanded> $' |
629 | 8067 |
! ! |
6809 | 8068 |
|
14606 | 8069 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
8070 |
CharacterArray initialize! |