author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 22 Sep 2015 16:28:42 +0100 | |
branch | jv |
changeset 18759 | c1217211909c |
parent 18723 | f7d0ff0386cf |
child 18773 | 4f6a5cbce3a9 |
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, |
|
110 |
taking untranslated bytes from the argument, aByteCollection. |
|
111 |
Only useful, when reading twoByteStrings from external sources." |
|
112 |
||
113 |
|mySize nBytes newString dstIdx| |
|
114 |
||
115 |
nBytes := aByteCollection size. |
|
116 |
mySize := self basicNew bitsPerCharacter. |
|
117 |
mySize == 16 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
118 |
newString := self uninitializedNew:(nBytes // 2). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
119 |
dstIdx := 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
120 |
aByteCollection pairWiseDo:[:hi :lo | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
121 |
newString at:dstIdx put:(Character value:(hi bitShift:8)+lo). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
122 |
dstIdx := dstIdx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
123 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
124 |
^ newString. |
2734 | 125 |
]. |
126 |
||
17625 | 127 |
^ (self uninitializedNew:nBytes) replaceFrom:1 with:aByteCollection |
128 |
||
129 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
130 |
Unicode16String fromBytes:#[16r02 16r20] |
2734 | 131 |
" |
132 |
||
133 |
"Modified: 30.6.1997 / 20:08:37 / cg" |
|
134 |
! |
|
135 |
||
64 | 136 |
fromString:aString |
137 |
"return a copy of the argument, aString" |
|
138 |
||
17625 | 139 |
^ (self uninitializedNew:aString size) replaceFrom:1 with:aString |
140 |
||
141 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
142 |
Unicode16String fromString:'hello' |
17625 | 143 |
" |
581 | 144 |
! |
145 |
||
146 |
fromStringCollection:aCollectionOfStrings |
|
147 |
"return new string formed by concatenating a copy of the argument, aString" |
|
148 |
||
149 |
^ self fromStringCollection:aCollectionOfStrings separatedBy:'' |
|
150 |
||
151 |
" |
|
152 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') |
|
153 |
" |
|
154 |
||
155 |
"Created: 20.11.1995 / 15:26:59 / cg" |
|
156 |
! |
|
157 |
||
158 |
fromStringCollection:aCollectionOfStrings separatedBy:aSeparatorString |
|
159 |
"return new string formed by concatenating a copy of the argument, aString" |
|
160 |
||
17625 | 161 |
|stream| |
162 |
||
163 |
aCollectionOfStrings do:[:eachString | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
164 |
stream isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
165 |
stream := self writeStreamClass with:eachString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
166 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
167 |
stream |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
168 |
nextPutAll:aSeparatorString; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
169 |
nextPutAll:eachString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
170 |
]. |
581 | 171 |
]. |
17700 | 172 |
stream isNil ifTrue:[^ '']. |
17625 | 173 |
^ stream contents |
581 | 174 |
|
175 |
" |
|
176 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:' ' |
|
17625 | 177 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:'È ' |
178 |
Text fromStringCollection:{'hello'. 'world'. 'how' allBold. 'about'. 'this'. 'äöü'} separatedBy:'È ' |
|
581 | 179 |
" |
180 |
||
181 |
"Created: 20.11.1995 / 15:32:17 / cg" |
|
608 | 182 |
! |
183 |
||
5757 | 184 |
fromUTF8Bytes:aByteCollection |
5758 | 185 |
"return a new string which represents the characters as decoded |
186 |
from the utf8 encoded bytes, aByteCollection. |
|
187 |
Returns either a normal String, or a TwoByteString instance. |
|
6810 | 188 |
Only useful, when reading twoByteStrings from external sources. |
189 |
This only handles up-to 16bit characters" |
|
5757 | 190 |
|
7876 | 191 |
^ self decodeFromUTF8:aByteCollection. |
5757 | 192 |
|
193 |
" |
|
8874 | 194 |
CharacterArray fromUTF8Bytes:#[ 16r41 16r42 ] |
195 |
CharacterArray fromUTF8Bytes:#[ 16rC1 16r02 ] |
|
196 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r81 16r02 ] |
|
6810 | 197 |
CharacterArray fromUTF8Bytes:#[ 16rEF 16rBF 16rBF ] |
198 |
||
199 |
rfc2279 examples: |
|
8874 | 200 |
CharacterArray fromUTF8Bytes:#[ 16r41 16rE2 16r89 16rA2 16rCE 16r91 16r2E ] |
201 |
CharacterArray fromUTF8Bytes:#[ 16rED 16r95 16r9C 16rEA 16rB5 16rAD 16rEC 16r96 16rB4 ] |
|
202 |
CharacterArray fromUTF8Bytes:#[ 16rE6 16r97 16rA5 16rE6 16r9C 16rAC 16rE8 16rAA 16r9E ] |
|
6810 | 203 |
|
204 |
invalid: |
|
8874 | 205 |
CharacterArray fromUTF8Bytes:#[ 16rC0 16r80 ] |
206 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r80 16r80 ] |
|
5757 | 207 |
" |
208 |
! |
|
209 |
||
608 | 210 |
new |
211 |
"return a new empty string" |
|
212 |
||
213 |
^ self basicNew:0 |
|
9425 | 214 |
! |
215 |
||
216 |
readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
|
217 |
"read & return the next String from the (character-)stream aStream; |
|
218 |
skipping all whitespace first; return the value of exceptionBlock, |
|
219 |
if no string can be read. The sequence of characters as read from the |
|
220 |
stream must be one as stored via storeOn: or storeString." |
|
221 |
||
222 |
|str collected char| |
|
223 |
||
224 |
str := aStreamOrString readStream. |
|
225 |
||
226 |
"skip whiteSpace" |
|
227 |
str skipSeparators. |
|
11320 | 228 |
|
14452
ef3591302afa
changed: #readSmalltalkStringFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
14451
diff
changeset
|
229 |
(str peekOrNil == $') ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
230 |
str next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
231 |
collected := self writeStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
232 |
[str atEnd] whileFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
233 |
char := str next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
234 |
char == $' ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
235 |
"/ look for another quote |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
236 |
str peekOrNil ~~ $' ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
237 |
"end of string reached" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
238 |
^ collected contents. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
239 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
240 |
"eat doubled quote" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
241 |
str next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
242 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
243 |
((char ~~ Character return) or:[str peekOrNil ~~ Character lf]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
244 |
"compress CRLF to LF, but keep a single CR" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
245 |
collected nextPut:char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
246 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
247 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
248 |
"if we come here, we reached the end without finding a closing $'" |
9425 | 249 |
]. |
250 |
^ exceptionBlock value |
|
251 |
||
252 |
" |
|
253 |
String readFrom:('''hello world''' readStream) |
|
254 |
String readFrom:('''hello '''' world''' readStream) |
|
255 |
String readFrom:('1 ''hello'' ' readStream) |
|
256 |
String readFrom:('1 ''hello'' ' readStream) onError:['foobar'] |
|
257 |
" |
|
258 |
||
259 |
"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
|
260 |
"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
|
261 |
! |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
262 |
|
13201 | 263 |
writeStreamClass |
17213 | 264 |
"the class used by writeStream. |
265 |
Here, we return CharacterWriteStream, which automatically changes |
|
266 |
the underlying collection to a multiByte string (i.e. UnicodeString). |
|
267 |
So you can stream wide characters into it." |
|
13201 | 268 |
|
269 |
^ CharacterWriteStream |
|
11243
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
270 |
|
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
271 |
" |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
272 |
String writeStream |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
273 |
" |
13201 | 274 |
|
275 |
"Created: / 09-01-2011 / 10:37:57 / cg" |
|
64 | 276 |
! ! |
277 |
||
9265 | 278 |
!CharacterArray class methodsFor:'Compatibility-VW'! |
279 |
||
280 |
fromIntegerArray: anArray |
|
281 |
"Answer a new instance of the receiver that is created from the argument, anArray." |
|
282 |
||
283 |
| new | |
|
284 |
||
285 |
new := self new: anArray size. |
|
286 |
1 to: anArray size do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
287 |
new at: index put: (anArray at: index) asCharacter |
9265 | 288 |
]. |
289 |
^new |
|
290 |
||
291 |
" |
|
292 |
String fromIntegerArray: #[8 127] |
|
293 |
" |
|
294 |
! ! |
|
295 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
296 |
!CharacterArray class methodsFor:'Signal constants'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
297 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
298 |
decodingFailedSignal |
2833 | 299 |
"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
|
300 |
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
|
301 |
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
|
302 |
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
|
303 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
304 |
^ DecodingFailedSignal |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
305 |
|
2833 | 306 |
"Created: 28.6.1997 / 20:09:55 / cg" |
307 |
"Modified: 3.8.1997 / 18:16:47 / cg" |
|
308 |
! |
|
309 |
||
310 |
encodingFailedSignal |
|
311 |
"return the (query-) signal, raised when encoding of a string is not possible |
|
312 |
due to invalid characters contained in the source." |
|
313 |
||
314 |
^ EncodingFailedSignal |
|
315 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
316 |
"Modified: 28.6.1997 / 20:09:35 / cg" |
2833 | 317 |
"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
|
318 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
319 |
|
18721 | 320 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
321 |
!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
|
322 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
323 |
lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
324 |
"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
|
325 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
326 |
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
|
327 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
328 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
329 |
CharacterArray lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
330 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
331 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
332 |
"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
|
333 |
"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
|
334 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
335 |
|
7421 | 336 |
!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
|
337 |
|
7876 | 338 |
decodeFromUTF8:aStringOrByteCollection |
339 |
"return a string which represents the characters as decoded |
|
340 |
from the utf8 encoded bytes, aByteCollection. |
|
341 |
Returns either a normal String, or a TwoByteString instance. |
|
342 |
Only useful, when reading twoByteStrings from external sources. |
|
343 |
This only handles up-to 16bit characters." |
|
344 |
||
18612 | 345 |
^ CharacterEncoderImplementations::ISO10646_to_UTF8 new decodeString:aStringOrByteCollection |
7876 | 346 |
|
347 |
" |
|
8874 | 348 |
CharacterArray fromUTF8Bytes:#[ 16r41 16r42 ] |
349 |
CharacterArray fromUTF8Bytes:#[ 16rC1 16r02 ] |
|
350 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r81 16r02 ] |
|
7876 | 351 |
CharacterArray fromUTF8Bytes:#[ 16rEF 16rBF 16rBF ] |
352 |
||
353 |
rfc2279 examples: |
|
8874 | 354 |
CharacterArray fromUTF8Bytes:#[ 16r41 16rE2 16r89 16rA2 16rCE 16r91 16r2E ] |
355 |
CharacterArray fromUTF8Bytes:#[ 16rED 16r95 16r9C 16rEA 16rB5 16rAD 16rEC 16r96 16rB4 ] |
|
356 |
CharacterArray fromUTF8Bytes:#[ 16rE6 16r97 16rA5 16rE6 16r9C 16rAC 16rE8 16rAA 16r9E ] |
|
7876 | 357 |
|
358 |
invalid: |
|
8874 | 359 |
CharacterArray fromUTF8Bytes:#[ 16rC0 16r80 ] |
360 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r80 16r80 ] |
|
7876 | 361 |
" |
443 | 362 |
! ! |
363 |
||
18721 | 364 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
365 |
!CharacterArray class methodsFor:'pattern matching'! |
64 | 366 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
367 |
matchEscapeCharacter |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
368 |
"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
|
369 |
(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
|
370 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
371 |
^ $\ |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
372 |
! |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
373 |
|
15734 | 374 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop caseSensitive:caseSensitive |
327 | 375 |
"helper for match; return true if the characters from start to stop in |
376 |
aString are matching the scan in matchScan from matchStart to matchStop. |
|
328 | 377 |
The matchScan is as created by asMatchScanArray. |
327 | 378 |
|
8874 | 379 |
This algorithm is not at all the most efficient; |
380 |
for heavy duty pattern matching, an interface (primitive) to the regex |
|
328 | 381 |
pattern matching package should be added." |
327 | 382 |
|
8874 | 383 |
|matchEntry |
327 | 384 |
mStart "{ Class: SmallInteger }" |
385 |
mStop "{ Class: SmallInteger }" |
|
386 |
sStart "{ Class: SmallInteger }" |
|
387 |
sStop "{ Class: SmallInteger }" |
|
388 |
mSize "{ Class: SmallInteger }" |
|
389 |
sSize "{ Class: SmallInteger }" |
|
390 |
index "{ Class: SmallInteger }" |
|
2561 | 391 |
quickCheck matchLast nextMatchEntry |
986 | 392 |
checkChar included| |
327 | 393 |
|
394 |
mStart := matchStart. |
|
395 |
mStop := matchStop. |
|
396 |
sStart := start. |
|
397 |
sStop := stop. |
|
398 |
||
16245 | 399 |
[ |
8874 | 400 |
"/ Transcript showCR:('match: ''' , (aString copyFrom:sStart to:sStop) , |
3537 | 401 |
"/ ''' against:' , (matchScanArray copyFrom:mStart to:mStop) printString). |
402 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
403 |
mSize := mStop - mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
404 |
sSize := sStop - sStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
405 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
406 |
"empty strings match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
407 |
(mSize == 0) ifTrue:[^ (sSize == 0)]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
408 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
409 |
matchEntry := matchScanArray at:mStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
410 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
411 |
"/ the most common case first: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
412 |
(sSize ~~ 0 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
413 |
and:[(checkChar := (aString at:sStart)) = matchEntry]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
414 |
"advance by one and continue" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
415 |
mStart := mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
416 |
sStart := sStart + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
417 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
418 |
(matchEntry == #any) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
419 |
"restString empty -> no match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
420 |
(sSize == 0) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
421 |
"# matches single character" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
422 |
((sSize == 1) and:[mSize == 1]) ifTrue:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
423 |
"advance by one and continue" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
424 |
mStart := mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
425 |
sStart := sStart + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
426 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
427 |
(matchEntry == #anyString) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
428 |
"* alone matches anything" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
429 |
(mSize == 1) ifTrue:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
430 |
"restString empty & matchString not empty -> no match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
431 |
(sSize == 0) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
432 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
433 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
434 |
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
|
435 |
character and continue with shortened strings if possible |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
436 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
437 |
quickCheck := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
438 |
(mStop >= mStart) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
439 |
matchLast := matchScanArray at:mStop. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
440 |
(matchLast ~~ #anyString) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
441 |
(matchLast == #any) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
442 |
quickCheck := true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
443 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
444 |
matchLast == (aString at:sStop) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
445 |
quickCheck := true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
446 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
447 |
matchLast isString ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
448 |
quickCheck := matchLast includes:(aString at:sStop) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
449 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
450 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
451 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
452 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
453 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
454 |
quickCheck ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
455 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
456 |
quickCheck ok, advance from the right |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
457 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
458 |
mStop := mStop - 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
459 |
sStop := sStop - 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
460 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
461 |
"/ no quick check; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
462 |
"/ look for the next character(s) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
463 |
"/ and try matching there |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
464 |
"/ (to avoid recursion) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
465 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
466 |
mStart < mStop ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
467 |
nextMatchEntry := matchScanArray at:mStart+1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
468 |
nextMatchEntry isCharacter ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
469 |
sStart <= sStop ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
470 |
[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
471 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
472 |
index := aString indexOf:nextMatchEntry startingAt:sStart |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
473 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
474 |
index := aString findFirst:[:c | c asLowercase = nextMatchEntry asLowercase] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
475 |
startingAt:sStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
476 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
477 |
(index == 0 or:[index > sStop]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
478 |
^ false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
479 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
480 |
(self matchScan:matchScanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
481 |
from:(mStart + 1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
482 |
to:mStop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
483 |
with:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
484 |
from:index |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
485 |
to:sStop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
486 |
caseSensitive:caseSensitive |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
487 |
) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
488 |
^ true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
489 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
490 |
sStart := index + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
491 |
] loop. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
492 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
493 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
494 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
495 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
496 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
497 |
no quick check possible; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
498 |
loop over all possible substrings |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
499 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
500 |
index := sStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
501 |
[index <= sStop] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
502 |
(self matchScan:matchScanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
503 |
from:(mStart + 1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
504 |
to:mStop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
505 |
with:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
506 |
from:index |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
507 |
to:sStop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
508 |
caseSensitive:caseSensitive |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
509 |
) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
510 |
^ true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
511 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
512 |
index := index + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
513 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
514 |
^ false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
515 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
516 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
517 |
(matchEntry isString) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
518 |
"testString empty -> no match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
519 |
(sSize == 0) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
520 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
521 |
included := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
522 |
"/ checkChar := aString at:sStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
523 |
included := matchEntry includes:checkChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
524 |
included ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
525 |
caseSensitive ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
526 |
checkChar isUppercase ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
527 |
included := matchEntry includes:checkChar asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
528 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
529 |
included := matchEntry includes:checkChar asUppercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
530 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
531 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
532 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
533 |
mStart := mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
534 |
mSize := mSize - 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
535 |
included ifFalse:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
536 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
537 |
((sSize == 1) and:[mSize == 0]) ifTrue:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
538 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
539 |
"/ must be single character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
540 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
541 |
"testString empty ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
542 |
(sSize == 0) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
543 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
544 |
"first characters equal ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
545 |
"/ checkChar := aString at:sStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
546 |
caseSensitive ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
547 |
(checkChar asUppercase ~= matchEntry asUppercase) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
548 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
549 |
"advance and continue" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
550 |
mStart := mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
551 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
552 |
"cut off 1st char and continue" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
553 |
sStart := sStart + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
554 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
555 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
556 |
] |
16245 | 557 |
] loop. |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
558 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
559 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
560 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
561 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
562 |
scanArray := self matchScanArrayFrom:'*hello'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
563 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
564 |
CharacterArray |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
565 |
matchScan:scanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
566 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
567 |
to:scanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
568 |
with:s |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
569 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
570 |
to:s size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
571 |
caseSensitive:true |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
572 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
573 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
574 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
575 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
576 |
scanArray := self matchScanArrayFrom:'*hello*'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
577 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
578 |
CharacterArray |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
579 |
matchScan:scanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
580 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
581 |
to:scanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
582 |
with:s |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
583 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
584 |
to:s size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
585 |
caseSensitive:true |
15734 | 586 |
" |
587 |
||
588 |
"Modified: / 24-07-2011 / 07:17:03 / cg" |
|
589 |
"Modified (comment): / 24-07-2011 / 08:55:14 / cg" |
|
590 |
! |
|
591 |
||
592 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop ignoreCase:ignoreCase |
|
593 |
<resource: #obsolete> |
|
594 |
"helper for match; return true if the characters from start to stop in |
|
595 |
aString are matching the scan in matchScan from matchStart to matchStop. |
|
596 |
The matchScan is as created by asMatchScanArray. |
|
597 |
||
598 |
This algorithm is not at all the most efficient; |
|
599 |
for heavy duty pattern matching, an interface (primitive) to the regex |
|
600 |
pattern matching package should be added." |
|
601 |
||
602 |
^ self |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
603 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop caseSensitive:ignoreCase not |
15734 | 604 |
|
605 |
" |
|
606 |
|scanArray s| |
|
607 |
||
608 |
scanArray := self matchScanArrayFrom:'*hello'. |
|
609 |
s := 'foo bar hello world'. |
|
610 |
CharacterArray |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
611 |
matchScan:scanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
612 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
613 |
to:scanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
614 |
with:s |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
615 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
616 |
to:s size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
617 |
ignoreCase:false |
15734 | 618 |
" |
619 |
" |
|
620 |
|scanArray s| |
|
621 |
||
622 |
scanArray := self matchScanArrayFrom:'*hello*'. |
|
623 |
s := 'foo bar hello world'. |
|
624 |
CharacterArray |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
625 |
matchScan:scanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
626 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
627 |
to:scanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
628 |
with:s |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
629 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
630 |
to:s size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
631 |
ignoreCase:false |
13520 | 632 |
" |
633 |
||
634 |
"Modified: / 24-07-2011 / 07:17:03 / cg" |
|
635 |
"Modified (comment): / 24-07-2011 / 08:55:14 / cg" |
|
608 | 636 |
! |
637 |
||
638 |
matchScanArrayFrom:aString |
|
639 |
"scan a pattern string and decompose it into a scanArray. |
|
640 |
This is processed faster (especially with character ranges), and |
|
641 |
can also be reused later. (if the same pattern is to be searched again)" |
|
642 |
||
9282
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
643 |
^ self matchScanArrayFrom:aString escapeCharacter:(self matchEscapeCharacter) |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
644 |
|
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
645 |
" |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
646 |
String matchScanArrayFrom:'*ute*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
647 |
String matchScanArrayFrom:'**ute**' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
648 |
String matchScanArrayFrom:'*uter' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
649 |
String matchScanArrayFrom:'\*uter' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
650 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
651 |
String matchScanArrayFrom:'[abcd]*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
652 |
String matchScanArrayFrom:'[a-k]*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
653 |
String matchScanArrayFrom:'*some*compl*ern*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
654 |
String matchScanArrayFrom:'[a-' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
655 |
String matchScanArrayFrom:'[a-zA-Z]' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
656 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
657 |
" |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
658 |
|
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
659 |
"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
|
660 |
! |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
661 |
|
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
662 |
matchScanArrayFrom:aString escapeCharacter:escape |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
663 |
"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
|
664 |
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
|
665 |
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
|
666 |
|
8874 | 667 |
|coll |
608 | 668 |
idx "{ Class: SmallInteger }" |
9282
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
669 |
end c1 c2 matchSet previous| |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
670 |
|
5487 | 671 |
previous := nil. |
608 | 672 |
|
673 |
coll := OrderedCollection new. |
|
674 |
idx := 1. end := aString size. |
|
675 |
[idx <= end] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
676 |
|char this| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
677 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
678 |
char := aString at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
679 |
char == $* ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
680 |
previous ~~ #anyString ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
681 |
this := #anyString |
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 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
684 |
char == $# ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
685 |
previous ~~ #anyString ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
686 |
this := #any |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
687 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
688 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
689 |
char == $[ ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
690 |
matchSet := IdentitySet new. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
691 |
idx := idx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
692 |
idx > end ifTrue:[^ nil]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
693 |
char := aString at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
694 |
c1 := nil. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
695 |
[char ~~ $]] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
696 |
((char == $-) and:[c1 notNil]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
697 |
idx := idx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
698 |
idx > end ifTrue:[^ nil]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
699 |
c2 := aString at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
700 |
c1 to:c2 do:[:c | matchSet add:c]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
701 |
c1 := nil. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
702 |
idx := idx + 1. |
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 |
(char ~~ $]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
705 |
matchSet add:char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
706 |
c1 := char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
707 |
idx := idx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
708 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
709 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
710 |
idx > end ifTrue:[^ nil]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
711 |
char := aString at:idx |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
712 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
713 |
this := matchSet asString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
714 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
715 |
char == escape ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
716 |
idx := idx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
717 |
idx > end ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
718 |
"/ mhmh - what should we do here ? |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
719 |
this := char |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
720 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
721 |
this := aString at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
722 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
723 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
724 |
this := char |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
725 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
726 |
] |
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 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
729 |
this notNil ifTrue:[coll add:this. previous := this]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
730 |
idx := idx + 1 |
608 | 731 |
]. |
732 |
||
733 |
^ coll asArray |
|
734 |
||
735 |
" |
|
8874 | 736 |
String matchScanArrayFrom:'*ute*' |
737 |
String matchScanArrayFrom:'**ute**' |
|
738 |
String matchScanArrayFrom:'*uter' |
|
739 |
String matchScanArrayFrom:'\*uter' |
|
740 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
|
741 |
String matchScanArrayFrom:'[abcd]*' |
|
742 |
String matchScanArrayFrom:'[a-k]*' |
|
743 |
String matchScanArrayFrom:'*some*compl*ern*' |
|
744 |
String matchScanArrayFrom:'[a-' |
|
745 |
String matchScanArrayFrom:'[a-zA-Z]' |
|
746 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
|
608 | 747 |
" |
2519
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 |
"Modified: 2.4.1997 / 16:20:29 / cg" |
9192 | 750 |
! ! |
751 |
||
752 |
!CharacterArray class methodsFor:'queries'! |
|
753 |
||
754 |
isAbstract |
|
11229 | 755 |
"Return if this class is an abstract class. |
756 |
True is returned for CharacterArray here; false for subclasses. |
|
757 |
Abstract subclasses must redefine again." |
|
758 |
||
9192 | 759 |
^ self == CharacterArray |
18597 | 760 |
! |
761 |
||
762 |
speciesForCharacterSize:characterSize |
|
763 |
"answer the class, that is able to hold characters of size characterSize" |
|
764 |
||
765 |
characterSize <= 8 ifTrue:[^ String]. |
|
766 |
characterSize <= 16 ifTrue:[^ Unicode16String]. |
|
767 |
^ Unicode32String |
|
9192 | 768 |
! ! |
769 |
||
18721 | 770 |
|
9192 | 771 |
!CharacterArray methodsFor:'Compatibility-ANSI'! |
772 |
||
773 |
addLineDelimiters |
|
774 |
"Ansi compatibility - same as withCRs" |
|
775 |
||
776 |
^ self withCRs |
|
777 |
||
778 |
"Modified: / 13.11.2001 / 19:16:25 / cg" |
|
17543 | 779 |
! ! |
780 |
||
781 |
!CharacterArray methodsFor:'Compatibility-Dolphin'! |
|
9192 | 782 |
|
783 |
copyExpanding:expandTable |
|
784 |
"return a copy of myself, with translations from the expandTable sliced in. |
|
18392 | 785 |
The argument is supposed to map from characters to either characters or strings. |
786 |
Added for Dolphin compatibility" |
|
9192 | 787 |
|
788 |
|ds| |
|
789 |
||
790 |
ds := WriteStream on:(self species new). |
|
791 |
self do:[:eachChar | |
|
18392 | 792 |
|repl| |
793 |
||
794 |
repl := expandTable at:eachChar ifAbsent:[nil]. |
|
795 |
repl isNil ifTrue:[ |
|
796 |
ds nextPut:eachChar |
|
797 |
] ifFalse:[ |
|
798 |
repl size == 0 ifTrue:[ |
|
799 |
ds nextPut:repl |
|
800 |
] ifFalse:[ |
|
801 |
ds nextPutAll:repl |
|
802 |
] |
|
803 |
]. |
|
9192 | 804 |
]. |
6870 | 805 |
^ ds contents. |
806 |
! |
|
807 |
||
808 |
formatWith:aString |
|
11955 | 809 |
"Compatibility method - do not use in new code. |
18392 | 810 |
same as #bindWith: for Dolphin compatibility" |
6870 | 811 |
|
812 |
^ self bindWith:aString |
|
813 |
||
814 |
" |
|
815 |
'hello%1world' formatWith:'123' |
|
816 |
" |
|
817 |
! |
|
818 |
||
819 |
formatWith:arg1 with:arg2 |
|
11955 | 820 |
"Compatibility method - do not use in new code. |
18392 | 821 |
same as #bindWith: for Dolphin compatibility" |
6870 | 822 |
|
823 |
^ self bindWith:arg1 with:arg2 |
|
824 |
||
825 |
" |
|
826 |
'hello%1 %2world' formatWith:'123' with:234 |
|
827 |
" |
|
828 |
! |
|
829 |
||
830 |
formatWith:arg1 with:arg2 with:arg3 |
|
11955 | 831 |
"Compatibility method - do not use in new code. |
18392 | 832 |
same as #bindWith: for Dolphin compatibility" |
6870 | 833 |
|
834 |
^ self bindWith:arg1 with:arg2 with:arg3 |
|
835 |
||
836 |
" |
|
837 |
'hello%1 %2 %3world' formatWith:'123' with:234 with:345 |
|
838 |
" |
|
6391 | 839 |
! ! |
840 |
||
14681 | 841 |
!CharacterArray methodsFor:'Compatibility-GNU'! |
842 |
||
843 |
% anArrayOfOperands |
|
844 |
"return a copy of the receiver, where a '%i' escape |
|
845 |
is replaced by the coresponding string from the argument array. |
|
846 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
847 |
Added for GNU-ST compatibility." |
|
848 |
||
849 |
^ self expandPlaceholdersWith:anArrayOfOperands |
|
850 |
||
851 |
" |
|
852 |
'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
|
853 |
% #('smalltalk' 'c++' 'c') |
14681 | 854 |
|
855 |
'do you %(what) ?' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
856 |
% (Dictionary new at:#'what' put:'understand'; yourself) |
14681 | 857 |
" |
858 |
! ! |
|
859 |
||
7261 | 860 |
!CharacterArray methodsFor:'Compatibility-ST/V'! |
608 | 861 |
|
17517 | 862 |
asArrayOfSubstrings |
863 |
"return an array of substrings from the receiver, interpreting |
|
864 |
separators (i.e. spaces & newlines) as word-delimiters. |
|
18390 | 865 |
This has been added for ST/V compatibility |
866 |
- the actual work is done in asCollectionOfWords. |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
867 |
(sigh: it is called #'subStrings' in V'Age, #'substrings' in Squeak |
17517 | 868 |
and #'asCollectionOfWords' in ST/X) " |
869 |
||
870 |
^ self asCollectionOfWords asArray |
|
871 |
||
872 |
" |
|
873 |
'1 one two three four 5 five' asArrayOfSubstrings |
|
874 |
'1 |
|
875 |
one |
|
18390 | 876 |
two three four 5 five' asArrayOfSubstrings |
17517 | 877 |
" |
878 |
! |
|
879 |
||
608 | 880 |
byteAt:index put:aByte |
881 |
"store a byte at given index. |
|
882 |
This is an ST/V compatibility method." |
|
883 |
||
1333
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
884 |
"/ (aByte == 0) ifTrue:[ |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
885 |
"/ "store a space instead" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
886 |
"/ ^ 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
|
887 |
"/ ]. |
11754
5132248cfd6e
common definition of #byteAt:put between CharacterArray and Symbol
Stefan Vogel <sv@exept.de>
parents:
11632
diff
changeset
|
888 |
^ self basicAt:index put:(Character value:aByte) |
9192 | 889 |
|
890 |
" |
|
891 |
'hello' copy at:1 put:$H asciiValue; yourself |
|
892 |
'hello' copy byteAt:1 put:72; yourself |
|
893 |
'hello' copy byteAt:1 put:0; yourself |
|
894 |
" |
|
895 |
||
896 |
"Modified: 6.5.1996 / 10:35:26 / cg" |
|
897 |
! |
|
608 | 898 |
|
899 |
replChar:oldChar with:newChar |
|
900 |
"return a copy of the receiver, with all oldChars replaced |
|
901 |
by newChar. |
|
902 |
This is an ST/V compatibility method." |
|
903 |
||
3656 | 904 |
^ self copyReplaceAll:oldChar with:newChar |
608 | 905 |
|
906 |
" |
|
8874 | 907 |
'12345678901234567890' replChar:$0 with:$* |
608 | 908 |
" |
3656 | 909 |
|
910 |
"Modified: / 18.7.1998 / 22:52:57 / cg" |
|
608 | 911 |
! |
912 |
||
913 |
replChar:oldChar withString:newString |
|
914 |
"return a copy of the receiver, with all oldChars replaced |
|
915 |
by newString (i.e. slice in the newString in place of the oldChar). |
|
916 |
This is an ST/V compatibility method." |
|
917 |
||
918 |
|tmpStream| |
|
919 |
||
15523 | 920 |
tmpStream := self species writeStream. |
608 | 921 |
self do:[:element | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
922 |
element = oldChar ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
923 |
tmpStream nextPutAll:newString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
924 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
925 |
tmpStream nextPut:element |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
926 |
]. |
608 | 927 |
]. |
928 |
^ tmpStream contents |
|
929 |
||
930 |
" |
|
8874 | 931 |
'12345678901234567890' replChar:$0 withString:'foo' |
932 |
'a string with spaces' replChar:$ withString:' foo ' |
|
608 | 933 |
" |
9192 | 934 |
! |
935 |
||
936 |
replString:subString withString:newString |
|
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
937 |
"return a copy of the receiver, with all sequences of subString replaced |
18390 | 938 |
by newString (i.e. slice in the newString in place of the oldString). |
939 |
This is an ST/V compatibility method." |
|
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
940 |
|
8347 | 941 |
^ self copyReplaceString:subString withString:newString |
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
942 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
943 |
" |
8874 | 944 |
'12345678901234567890' replString:'123' withString:'OneTwoThree' |
945 |
'12345678901234567890' replString:'123' withString:'*' |
|
946 |
'12345678901234567890' replString:'234' withString:'foo' |
|
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
947 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
948 |
('a string with spaces' replChar:$ withString:' foo ') |
18390 | 949 |
replString:'foo' withString:'bar' |
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
950 |
" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
951 |
|
8347 | 952 |
"Modified: / 12-05-2004 / 12:00:27 / cg" |
9192 | 953 |
! |
954 |
||
9275 | 955 |
subString:start to:end |
18390 | 956 |
"same as copyFrom:to: |
957 |
This is an ST/V compatibility method." |
|
958 |
||
9275 | 959 |
^ self copyFrom:start to:end |
960 |
||
961 |
" |
|
962 |
'12345678901234567890' subString:3 to:8 |
|
963 |
" |
|
964 |
! |
|
965 |
||
9192 | 966 |
trimBlanks |
14992 | 967 |
"return a copy of the receiver without leading and trailing spaces. |
18464 | 968 |
This is an ST/V compatibility method and an alias for withoutSpaces." |
9192 | 969 |
|
970 |
^ self withoutSpaces |
|
971 |
||
972 |
" |
|
973 |
' spaces at beginning' trimBlanks |
|
974 |
'spaces at end ' trimBlanks |
|
975 |
' spaces at beginning and end ' trimBlanks |
|
976 |
'no spaces' trimBlanks |
|
977 |
" |
|
978 |
! ! |
|
979 |
||
980 |
!CharacterArray methodsFor:'Compatibility-Squeak'! |
|
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
981 |
|
6148 | 982 |
asDate |
983 |
"Many allowed forms, see Date.readFrom:" |
|
984 |
||
985 |
^ Date readFrom: (ReadStream on: self) |
|
986 |
||
987 |
" |
|
8874 | 988 |
'30 Apr 1999' asDate dayName capitalized |
6148 | 989 |
" |
990 |
! |
|
991 |
||
16051 | 992 |
asOneByteString |
993 |
"return the receiver converted to a 'normal' string. |
|
18391 | 994 |
Same as asSingleByteString - for Squeak/Pharo compatibility." |
16051 | 995 |
|
996 |
^ self asSingleByteString |
|
997 |
! |
|
998 |
||
8971 | 999 |
asUrl |
18391 | 1000 |
"Same as asURL - for Squeak/Pharo compatibility." |
1001 |
||
8971 | 1002 |
^ self asURL |
1003 |
! |
|
1004 |
||
10840 | 1005 |
asWideString |
18391 | 1006 |
"return a two-byte string containing the same characters as the receiver. |
1007 |
Same as asTwoByteString - for Squeak/Pharo compatibility." |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1008 |
|
10840 | 1009 |
^ self asTwoByteString |
1010 |
||
1011 |
" |
|
1012 |
'abc' asWideString |
|
1013 |
" |
|
1014 |
! |
|
1015 |
||
4989 | 1016 |
capitalized |
18391 | 1017 |
"same as asUppercaseFirst for Squeak/Pharo compatibility" |
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1018 |
|
4989 | 1019 |
^ self asUppercaseFirst |
1020 |
||
1021 |
" |
|
1022 |
'hello' capitalized |
|
1023 |
" |
|
1024 |
! |
|
1025 |
||
10841 | 1026 |
caseInsensitiveLessOrEqual:aString |
18391 | 1027 |
"compare the receiver against the argument ignoring case differences |
1028 |
For Squeak/Pharo compatibility" |
|
1029 |
||
10841 | 1030 |
^ (self compareCaselessWith:aString) <= 0 |
1031 |
! |
|
1032 |
||
1033 |
caseSensitiveLessOrEqual:aString |
|
18391 | 1034 |
"compare the receiver against the argument caring for case differences |
1035 |
For Squeak/Pharo compatibility" |
|
1036 |
||
10841 | 1037 |
^ self <= aString |
1038 |
! |
|
1039 |
||
1040 |
charactersExactlyMatching:aString |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1041 |
"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
|
1042 |
|
10841 | 1043 |
|idx nMax| |
1044 |
||
1045 |
nMax :=(self size) min:(aString size). |
|
1046 |
idx := 1. |
|
1047 |
[idx <= nMax] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1048 |
(self at:idx) = (aString at:idx) ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1049 |
^ idx - 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1050 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1051 |
idx := idx + 1. |
10841 | 1052 |
]. |
1053 |
^ nMax |
|
1054 |
||
1055 |
" |
|
12177 | 1056 |
'abc' charactersExactlyMatching:'abc' |
1057 |
'abc' charactersExactlyMatching:'abcd' |
|
1058 |
'abcd' charactersExactlyMatching:'abc' |
|
1059 |
'abc' charactersExactlyMatching:'abd' |
|
1060 |
'abc' charactersExactlyMatching:'xxx' |
|
10841 | 1061 |
" |
1062 |
! |
|
1063 |
||
9192 | 1064 |
endsWithDigit |
1065 |
"Answer whether the receiver's final character represents a digit. 3/11/96 sw" |
|
1066 |
||
18391 | 1067 |
|len| |
1068 |
||
1069 |
^ (len := self size) > 0 and: [(self at:len) isDigit] |
|
9192 | 1070 |
! |
1071 |
||
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1072 |
findDelimiters:delimiters startingAt:start |
18391 | 1073 |
"Answer the index of the character within the receiver, starting at start, |
1074 |
that matches one of the delimiters. |
|
1075 |
If the receiver does not contain any of the delimiters, answer size + 1." |
|
9192 | 1076 |
|
1077 |
|idx| |
|
1078 |
||
1079 |
idx := self indexOfAny:delimiters startingAt:start. |
|
1080 |
idx == 0 ifTrue:[^ self size + 1]. |
|
1081 |
^ idx. |
|
1082 |
"/start to: self size do: [:i | |
|
1083 |
"/ |char| |
|
1084 |
"/ |
|
1085 |
"/ char := self at: i. |
|
1086 |
"/ delimiters do: [:delim | delim = char ifTrue: [^ i]] |
|
8971 | 1087 |
"/ ]. |
1088 |
"/ ^ self size + 1 |
|
1089 |
! |
|
1090 |
||
13624 | 1091 |
findTokens:delimiterOrDelimiters |
7270 | 1092 |
"cg: I am not sure, if this is really the squeak semantics (w.r.t. empty fields)" |
1093 |
||
13624 | 1094 |
delimiterOrDelimiters size == 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1095 |
^ self asCollectionOfSubstringsSeparatedBy:delimiterOrDelimiters |
13624 | 1096 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1097 |
^ self asCollectionOfSubstringsSeparatedByAny:delimiterOrDelimiters |
13624 | 1098 |
]. |
7270 | 1099 |
|
1100 |
" |
|
8874 | 1101 |
'a|b#c||e' findTokens:#($# $|) |
13624 | 1102 |
'a|b#c||e' findTokens:$| |
1103 |
" |
|
1104 |
||
1105 |
"Modified: / 04-09-2011 / 20:31:21 / cg" |
|
1106 |
"Modified (comment): / 05-09-2011 / 04:25:28 / cg" |
|
4981 | 1107 |
! |
1108 |
||
4974 | 1109 |
includesSubString:aString |
1110 |
"return true, if a substring is contained in the receiver. |
|
1111 |
The compare is case sensitive." |
|
1112 |
||
1113 |
^ self includesString:aString |
|
1114 |
||
1115 |
" |
|
8874 | 1116 |
'hello world' includesSubString:'Hel' |
9192 | 1117 |
'hello world' includesSubString:'hel' |
1118 |
'hello world' includesSubString:'llo' |
|
1119 |
" |
|
1120 |
||
1121 |
||
1122 |
||
1123 |
! |
|
1124 |
||
11178 | 1125 |
includesSubString:aString caseSensitive:caseSensitive |
18391 | 1126 |
"sigh - an alias; added for Squeak/Pharo compatibility" |
1127 |
||
11179 | 1128 |
^ self includesSubstring:aString caseSensitive:caseSensitive |
11178 | 1129 |
! |
1130 |
||
16875
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1131 |
includesSubstring: aString |
18391 | 1132 |
"sigh - an alias; added for Squeak/Pharo compatibility" |
1133 |
||
16875
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1134 |
^ self includesSubString: aString |
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1135 |
|
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1136 |
"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
|
1137 |
! |
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1138 |
|
9192 | 1139 |
includesSubstring:aString caseSensitive:caseSensitive |
9190 | 1140 |
"return true, if a substring is contained in the receiver. |
9192 | 1141 |
The argument, caseSensitive controls if case is ignored in the compare." |
1142 |
||
1143 |
"/ for now, a q&d hack ... |
|
1144 |
||
1145 |
caseSensitive ifFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1146 |
^ self asLowercase includesString:aString asLowercase |
9192 | 1147 |
]. |
9190 | 1148 |
^ self includesString:aString |
1149 |
||
1150 |
" |
|
9192 | 1151 |
'hello world' includesSubstring:'Hel' caseSensitive:true |
1152 |
'hello world' includesSubstring:'Hel' caseSensitive:false |
|
1153 |
" |
|
1154 |
||
1155 |
||
1156 |
||
1157 |
! |
|
9190 | 1158 |
|
6979 | 1159 |
isAllDigits |
1160 |
"Answer whether the receiver's characters are all digits" |
|
1161 |
||
1162 |
^ self conform:[:eachChar | eachChar isDigit] |
|
1163 |
||
1164 |
" |
|
1165 |
'hello world' isAllDigits |
|
1166 |
'12344' isAllDigits |
|
1167 |
" |
|
1168 |
! |
|
1169 |
||
4890 | 1170 |
lastSpacePosition |
18391 | 1171 |
"return the index of the last space character; 0 if there is none. |
1172 |
Added for Squeak/Pharo compatibility" |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1173 |
|
4890 | 1174 |
^ self lastIndexOfSeparator |
1175 |
! |
|
1176 |
||
7022 | 1177 |
padded:leftOrRight to:paddedSize with:padCharacter |
14053
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1178 |
"pad left (leftOrRight==#left) or right" |
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1179 |
|
7022 | 1180 |
leftOrRight == #left ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1181 |
^ self leftPaddedTo:paddedSize with:padCharacter |
9190 | 1182 |
]. |
1183 |
^ self paddedTo:paddedSize with:padCharacter |
|
1184 |
||
1185 |
" |
|
8874 | 1186 |
'hello' padded:#right to:10 with:$. |
9192 | 1187 |
'hello' padded:#left to:10 with:$. |
1188 |
" |
|
14053
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1189 |
|
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1190 |
"Modified (comment): / 07-03-2012 / 16:31:33 / cg" |
9192 | 1191 |
! |
1192 |
||
1193 |
skipDelimiters:delimiters startingAt:start |
|
1194 |
"Answer the index of the character within the receiver, starting at start, |
|
1195 |
that does NOT match one of the delimiters. |
|
1196 |
If the receiver does not contain any of the delimiters, answer size + 1. |
|
1197 |
Assumes the delimiters to be a non-empty string." |
|
1198 |
||
1199 |
start to:self size do:[:i | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1200 |
delimiters detect:[:delim | delim = (self at:i) ] ifNone:[ ^ i ] |
9192 | 1201 |
]. |
1202 |
^ self size + 1 |
|
1203 |
||
1204 |
" |
|
1205 |
'123***7890' skipDelimiters:'*' startingAt:4 |
|
1206 |
'123***7890' skipDelimiters:'*' startingAt:3 |
|
9190 | 1207 |
'123***7890' skipDelimiters:'*' startingAt:10 |
1208 |
'123*******' skipDelimiters:'*' startingAt:10 |
|
8874 | 1209 |
" |
1210 |
! |
|
1211 |
||
9190 | 1212 |
substrings |
17517 | 1213 |
"return an array consisting of all words contained in the receiver. |
1214 |
Words are separated by whitespace. |
|
1215 |
This has been added for Squeak compatibility. |
|
1216 |
(sigh: it is called #'subStrings' in V'Age, and #'asCollectionOfWords' in ST/X) " |
|
1217 |
||
9190 | 1218 |
^ self asCollectionOfWords |
1219 |
||
1220 |
" |
|
1221 |
'foo bar baz' substrings |
|
1222 |
" |
|
1223 |
! |
|
1224 |
||
12665
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1225 |
substringsSeparatedBy:separatorCharacter |
18391 | 1226 |
"Added for Squeak/Pharo compatibility" |
1227 |
||
12665
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1228 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1229 |
|
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1230 |
" |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1231 |
'foo bar, baz' substringsSeparatedBy:$, |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1232 |
" |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1233 |
! |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1234 |
|
9190 | 1235 |
truncateTo:smallSize |
9192 | 1236 |
"return myself or a copy shortened to smallSize. 1/18/96 sw" |
1237 |
||
1238 |
self size <= smallSize ifTrue:[^ self]. |
|
1239 |
^ self copyFrom: 1 to: smallSize |
|
1240 |
||
1241 |
" |
|
1242 |
'hello world' truncateTo:5 |
|
1243 |
'hello' truncateTo:10 |
|
1244 |
||
1245 |
'hello world' copyTo:5 |
|
1246 |
'hello' copyTo:10 |
|
1247 |
" |
|
1248 |
! |
|
5795 | 1249 |
|
4890 | 1250 |
withBlanksTrimmed |
18464 | 1251 |
"Return a copy of the receiver from which leading and trailing whitespace have been trimmed. |
1252 |
Notice the bad naming - it is trimming separators, not just blanks. |
|
1253 |
Added for Squeak compatibility and an alias for withoutSeparators" |
|
4890 | 1254 |
|
14865 | 1255 |
^ self withoutSeparators "withoutSpaces" "/ cg: it seems that squeak cares for any whitespace |
4890 | 1256 |
|
1257 |
" |
|
8874 | 1258 |
' hello world ' withBlanksTrimmed |
4890 | 1259 |
" |
1260 |
! |
|
1261 |
||
1262 |
withNoLineLongerThan: aNumber |
|
1263 |
"Answer a string with the same content as receiver, but rewrapped so that no line has more characters than the given number" |
|
1264 |
||
9192 | 1265 |
| listOfLines currentLast currentStart resultString putativeLast putativeLine crPosition | |
1266 |
||
14451
c06e7885b675
changed: #withNoLineLongerThan:
Claus Gittinger <cg@exept.de>
parents:
14420
diff
changeset
|
1267 |
(aNumber isNumber not or:[ aNumber < 1] ) ifTrue: [self error: 'too narrow']. |
9192 | 1268 |
listOfLines _ OrderedCollection new. |
1269 |
currentLast _ 0. |
|
1270 |
[currentLast < self size] whileTrue: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1271 |
[currentStart _ currentLast + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1272 |
putativeLast _ (currentStart + aNumber - 1) min: self size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1273 |
putativeLine _ self copyFrom: currentStart to: putativeLast. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1274 |
(crPosition _ putativeLine indexOf: Character cr) > 0 ifTrue: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1275 |
[putativeLast _ currentStart + crPosition - 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1276 |
putativeLine _ self copyFrom: currentStart to: putativeLast]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1277 |
currentLast _ putativeLast == self size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1278 |
ifTrue: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1279 |
[putativeLast] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1280 |
ifFalse: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1281 |
[currentStart + putativeLine lastSpacePosition - 1]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1282 |
currentLast <= currentStart ifTrue: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1283 |
["line has NO spaces; baleout!!" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1284 |
currentLast _ putativeLast]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1285 |
listOfLines add: (self copyFrom: currentStart to: currentLast) withBlanksTrimmed]. |
9192 | 1286 |
|
1287 |
listOfLines size > 0 ifFalse: [^ '']. |
|
1288 |
resultString _ listOfLines first. |
|
1289 |
2 to: listOfLines size do: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1290 |
[:i | resultString _ resultString, Character cr asString, (listOfLines at: i)]. |
9192 | 1291 |
^ resultString |
1292 |
||
1293 |
" |
|
1294 |
#(5 7 20) collect: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1295 |
[: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
|
1296 |
" |
10883 | 1297 |
! |
1298 |
||
12343
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1299 |
withSqueakLineEndings |
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1300 |
"assume the string is textual, and that CR, LF, and CRLF are all |
18391 | 1301 |
valid line endings. Replace each occurence with a single CR" |
12343
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1302 |
|
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1303 |
^ self asStringCollection asStringWith:Character cr. |
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1304 |
! |
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1305 |
|
12188 | 1306 |
withoutLeading: char |
1307 |
"return a copy of myself without leading a char. |
|
1308 |
Returns an empty string, if the receiver consist only of a char." |
|
1309 |
||
1310 |
^ self withoutLeadingForWhich:[:ch | ch = char] |
|
1311 |
||
1312 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1313 |
'****foo****' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1314 |
'foo****' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1315 |
'*' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1316 |
'' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1317 |
'****foo' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1318 |
'*******' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1319 |
'foo' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1320 |
'f***o***o' withoutLeading: $* |
12188 | 1321 |
('**' , Character tab asString , '*foo***') withoutLeading: $* inspect |
1322 |
" |
|
1323 |
! |
|
1324 |
||
11565 | 1325 |
withoutTrailing:char |
1326 |
"return a copy of myself without trailing char. |
|
1327 |
Returns an empty string, if the receiver consist only of char." |
|
1328 |
||
12188 | 1329 |
^ self withoutTrailingForWhich:[:ch | ch = char] |
1330 |
||
1331 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1332 |
' foo....' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1333 |
'foo....' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1334 |
' foo' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1335 |
'.......' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1336 |
'foo' withoutTrailing:$. |
11565 | 1337 |
" |
9190 | 1338 |
! ! |
1339 |
||
1340 |
!CharacterArray methodsFor:'Compatibility-V''Age'! |
|
1341 |
||
1342 |
addLineDelimiter |
|
1343 |
"replace all '\'-characters by line delimiter (cr) - characters. |
|
9192 | 1344 |
This has been added for VisualAge compatibility." |
1345 |
||
1346 |
^ self withCRs |
|
1347 |
! |
|
1348 |
||
1349 |
bindWith:aString |
|
1350 |
"return a copy of the receiver, where a '%1' escape is |
|
1351 |
replaced by aString. |
|
1352 |
This has been added for VisualAge compatibility." |
|
1353 |
||
1354 |
^ self expandPlaceholdersWith:(Array with:aString) |
|
1355 |
||
1356 |
" |
|
1357 |
'do you like %1 ?' bindWith:'smalltalk' |
|
1358 |
" |
|
1359 |
! |
|
608 | 1360 |
|
1361 |
bindWith:string1 with:string2 |
|
1362 |
"return a copy of the receiver, where a '%1' escape is |
|
1363 |
replaced by string1 and '%2' is replaced by string2. |
|
1364 |
This has been added for VisualAge compatibility." |
|
1365 |
||
1366 |
^ self expandPlaceholdersWith:(Array with:string1 with:string2) |
|
1367 |
||
1368 |
" |
|
1369 |
'do you prefer %1 or rather %2 ?' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1370 |
bindWith:'smalltalk' with:'c++' |
9192 | 1371 |
" |
1372 |
! |
|
9190 | 1373 |
|
1374 |
bindWith:str1 with:str2 with:str3 |
|
608 | 1375 |
"return a copy of the receiver, where a '%1', '%2' and '%3' escapes |
1376 |
are replaced by str1, str2 and str3 respectively. |
|
1377 |
This has been added for VisualAge compatibility." |
|
1378 |
||
1379 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3) |
|
1380 |
||
1381 |
" |
|
9192 | 1382 |
'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
|
1383 |
bindWith:'smalltalk' with:'c++' with:'c' |
9192 | 1384 |
" |
1385 |
! |
|
608 | 1386 |
|
1387 |
bindWith:str1 with:str2 with:str3 with:str4 |
|
1388 |
"return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes |
|
1389 |
are replaced by str1, str2, str3 and str4 respectively. |
|
1390 |
This has been added for VisualAge compatibility." |
|
1391 |
||
1392 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4) |
|
1393 |
||
1394 |
" |
|
9192 | 1395 |
'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
|
1396 |
bindWith:'smalltalk' with:'c++' with:'c' with:'assembler' |
9192 | 1397 |
" |
1398 |
! |
|
608 | 1399 |
|
2344 | 1400 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 |
1401 |
"return a copy of the receiver, where a '%1' .. '%5' escapes |
|
1402 |
are replaced by str1 .. str5 respectively. |
|
1403 |
This has been added for VisualAge compatibility." |
|
1404 |
||
1405 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5) |
|
1406 |
||
1407 |
"Created: 31.1.1997 / 16:25:42 / cg" |
|
1408 |
! |
|
1409 |
||
5343 | 1410 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 |
1411 |
"return a copy of the receiver, where a '%1' .. '%6' escapes |
|
11524 | 1412 |
are replaced by str1 .. str6 respectively. |
5343 | 1413 |
This has been added for VisualAge compatibility." |
1414 |
||
8874 | 1415 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1416 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1417 |
with:str5 with:str6) |
11524 | 1418 |
! |
1419 |
||
1420 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 with:str7 |
|
1421 |
"return a copy of the receiver, where a '%1' .. '%7' escapes |
|
1422 |
are replaced by str1 .. str7 respectively. |
|
1423 |
This has been added for VisualAge compatibility." |
|
1424 |
||
1425 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1426 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1427 |
with:str5 with:str6 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1428 |
with:str7) |
5343 | 1429 |
! |
1430 |
||
13996
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1431 |
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
|
1432 |
"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
|
1433 |
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
|
1434 |
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
|
1435 |
|
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1436 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1437 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1438 |
with:str5 with:str6 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1439 |
with:str7 with:str8) |
13996
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1440 |
|
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1441 |
"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
|
1442 |
! |
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1443 |
|
14014
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1444 |
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
|
1445 |
"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
|
1446 |
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
|
1447 |
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
|
1448 |
|
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1449 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1450 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1451 |
with:str5 with:str6 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1452 |
with:str7 with:str8 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1453 |
with:str9) |
14014
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1454 |
|
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1455 |
"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
|
1456 |
! |
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1457 |
|
608 | 1458 |
bindWithArguments:anArrayOfStrings |
1459 |
"return a copy of the receiver, where a '%i' escape |
|
1460 |
is replaced by the coresponding string from the argument array. |
|
1461 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
1462 |
This has been added for VisualAge compatibility." |
|
1463 |
||
9192 | 1464 |
^ self expandPlaceholdersWith:anArrayOfStrings |
1465 |
||
1466 |
" |
|
1467 |
'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
|
1468 |
bindWithArguments:#('smalltalk' 'c++' 'c') |
12196 | 1469 |
|
1470 |
'do you %(what) ?' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1471 |
bindWithArguments:(Dictionary new at:#'what' put:'understand'; yourself) |
9192 | 1472 |
" |
1473 |
! |
|
608 | 1474 |
|
1475 |
subStrings |
|
1476 |
"return an array consisting of all words contained in the receiver. |
|
1477 |
Words are separated by whitespace. |
|
17517 | 1478 |
This has been added for VisualAge compatibility. |
1479 |
(sigh: it is called #'subbtrings' in Squeak, and #'asCollectionOfWords' in ST/X) " |
|
608 | 1480 |
|
1481 |
^ self asCollectionOfWords |
|
1482 |
||
1483 |
" |
|
1484 |
'hello world, this is smalltalk' subStrings |
|
1485 |
" |
|
1486 |
! |
|
1487 |
||
16181 | 1488 |
subStrings:separatorCharacterOrString |
608 | 1489 |
"return an array consisting of all words contained in the receiver. |
1490 |
Words are separated by separatorCharacter. |
|
17233 | 1491 |
This is similar to split: and has been added for VisualAge compatibility." |
608 | 1492 |
|
16181 | 1493 |
separatorCharacterOrString isCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1494 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacterOrString |
16181 | 1495 |
]. |
1496 |
^ self asCollectionOfSubstringsSeparatedByAny:separatorCharacterOrString |
|
1497 |
||
1498 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1499 |
'foo:bar:baz:smalltalk' subStrings:$: |
16181 | 1500 |
'foo:bar:baz:smalltalk' subStrings:':' |
1501 |
'foo.bar,baz-smalltalk' subStrings:'.,-' |
|
9192 | 1502 |
" |
1503 |
! |
|
1504 |
||
1505 |
trimSeparators |
|
18392 | 1506 |
"return a copy of the receiver without leading and trailing whiteSpace. |
18464 | 1507 |
Added for VisualAge compatibility and an alias for withoutSeparators" |
9192 | 1508 |
|
1509 |
^ self withoutSeparators |
|
1510 |
! ! |
|
1511 |
||
1512 |
!CharacterArray methodsFor:'Compatibility-VW'! |
|
5964 | 1513 |
|
6139 | 1514 |
asLogicalFileSpecification |
1515 |
^ self asFilename |
|
1516 |
||
1517 |
"Created: / 30.10.2001 / 17:29:53 / cg" |
|
1518 |
! |
|
1519 |
||
5964 | 1520 |
expandMacros |
1521 |
"ST80 compatibility - expand '<..>' macros with |
|
1522 |
argument strings. Similar to #bindWith:. |
|
1523 |
Read the comment in #expandMacrosWithArguments: about |
|
1524 |
limited compatibility issues." |
|
1525 |
||
1526 |
^ self expandMacrosWithArguments:#() |
|
1527 |
||
1528 |
" |
|
1529 |
'hello<n>foo' expandMacros |
|
1530 |
" |
|
1531 |
||
9192 | 1532 |
"Modified: / 18.6.1998 / 16:03:02 / cg" |
1533 |
! |
|
1534 |
||
1535 |
expandMacrosWith:arg |
|
5964 | 1536 |
"ST80 compatibility - expand '<..>' macros with |
1537 |
argument strings. Similar to #bindWith:. |
|
1538 |
Read the comment in #expandMacrosWithArguments: about |
|
1539 |
limited compatibility issues." |
|
1540 |
||
9192 | 1541 |
^ self expandMacrosWithArguments:(Array with:arg) |
1542 |
||
1543 |
"Created: / 1.11.1997 / 13:01:28 / cg" |
|
1544 |
"Modified: / 1.11.1997 / 13:30:50 / cg" |
|
1545 |
! |
|
5964 | 1546 |
|
1547 |
expandMacrosWith:arg1 with:arg2 |
|
1548 |
"ST80 compatibility - expand '<..>' macros with |
|
1549 |
argument strings. Similar to #bindWith:. |
|
1550 |
Read the comment in #expandMacrosWithArguments: about |
|
1551 |
limited compatibility issues." |
|
1552 |
||
1553 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2) |
|
1554 |
||
1555 |
"Modified: / 6.7.1998 / 21:58:14 / cg" |
|
1556 |
! |
|
1557 |
||
1558 |
expandMacrosWith:arg1 with:arg2 with:arg3 |
|
1559 |
"ST80 compatibility - expand '<..>' macros with |
|
1560 |
argument strings. Similar to #bindWith:. |
|
1561 |
Read the comment in #expandMacrosWithArguments: about |
|
1562 |
limited compatibility issues." |
|
1563 |
||
1564 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2 with:arg3) |
|
1565 |
! |
|
1566 |
||
10353
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1567 |
expandMacrosWith:arg1 with:arg2 with:arg3 with:arg4 |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1568 |
"ST80 compatibility - expand '<..>' macros with |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1569 |
argument strings. Similar to #bindWith:. |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1570 |
Read the comment in #expandMacrosWithArguments: about |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1571 |
limited compatibility issues." |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1572 |
|
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1573 |
^ 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
|
1574 |
! |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1575 |
|
9192 | 1576 |
expandMacrosWithArguments:argArray |
5964 | 1577 |
"ST80 compatibility - expand '<..>' macros with |
1578 |
argument strings. Similar to #bindWith:. |
|
1579 |
WARNING: possibly not all ST80 expansions are supported here." |
|
1580 |
||
1581 |
"/ supported expansions: |
|
1582 |
"/ |
|
1583 |
"/ <#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
|
1584 |
"/ <#s> # is arg Number; slice in the arg itself (must know asString) |
5964 | 1585 |
"/ <#?s1:s2> # is arg Number; slice in s1 if the arg is true, s2 otherwise |
7643 | 1586 |
"/ use first arg if # is not given (i.e. no number before s,p ...) |
5964 | 1587 |
"/ <n> replace by a newLine character |
1588 |
"/ <t> replace by a tab character |
|
6834
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
1589 |
"/ %X the X character itself |
5964 | 1590 |
|
8999
f3fda66ea51e
#expandMacrosWithArguments: - be mor friendly to xml strings.
Stefan Vogel <sv@exept.de>
parents:
8971
diff
changeset
|
1591 |
|in out c fmt nr arg s1 s2 peekc| |
5964 | 1592 |
|
1593 |
in := self readStream. |
|
10721
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1594 |
out := CharacterWriteStream on:(self species uninitializedNew:self size). |
5964 | 1595 |
|
1596 |
[in atEnd] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1597 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1598 |
c == $% ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1599 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1600 |
out nextPut:c |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1601 |
] ifFalse:[c ~~ $< ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1602 |
out nextPut:c. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1603 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1604 |
peekc := in peek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1605 |
[peekc == $<] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1606 |
out nextPut:$<. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1607 |
peekc := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1608 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1609 |
peekc == $n ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1610 |
peekc := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1611 |
peekc == $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1612 |
in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1613 |
out cr. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1614 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1615 |
out nextPutAll:'<n'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1616 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1617 |
] ifFalse:[peekc == $t ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1618 |
peekc := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1619 |
peekc == $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1620 |
in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1621 |
out tab. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1622 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1623 |
out nextPutAll:'<t'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1624 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1625 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1626 |
peekc isDigit ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1627 |
"start an argument expansion ..." |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1628 |
nr := Integer readFrom:in onError:nil. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1629 |
nr isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1630 |
"this cannot happen (there is at least one digit)" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1631 |
self error:'invalid format' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1632 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1633 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1634 |
fmt := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1635 |
(fmt ~~ $? and:[in peek ~~ $>]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1636 |
out nextPut:$<. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1637 |
nr printOn:out. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1638 |
out nextPut:fmt. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1639 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1640 |
(nr between:1 and:argArray size) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1641 |
arg := argArray at:nr. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1642 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1643 |
arg := '' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1644 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1645 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1646 |
fmt == $p ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1647 |
"expand with args printString" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1648 |
arg printOn:out. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1649 |
] ifFalse:[fmt == $s ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1650 |
"expand with arg itself" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1651 |
arg isText ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1652 |
out contentsSpecies isText ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1653 |
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
|
1654 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1655 |
out nextPutAll:arg. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1656 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1657 |
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
|
1658 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1659 |
] ifFalse:[fmt == $? ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1660 |
s1 := in upTo:$:. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1661 |
s2 := in nextUpTo:$>. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1662 |
arg == true ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1663 |
out nextPutAll:s1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1664 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1665 |
out nextPutAll:s2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1666 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1667 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1668 |
"what does VW do here ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1669 |
self error:'invalid format' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1670 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1671 |
]]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1672 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1673 |
c ~~ $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1674 |
"what does VW do here ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1675 |
self error:'invalid format' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1676 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1677 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1678 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1679 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1680 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1681 |
out nextPut:$<. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1682 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1683 |
]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1684 |
]]. |
5964 | 1685 |
]. |
1686 |
^ out contents |
|
1687 |
||
1688 |
" |
|
8874 | 1689 |
'hello <1s> how are you' expandMacrosWith:(OperatingSystem getLoginName) |
1690 |
'one plus one is <1p>' expandMacrosWith:2 |
|
5964 | 1691 |
" |
1692 |
||
10721
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1693 |
"Modified: / 18-09-2007 / 22:50:43 / cg" |
9192 | 1694 |
! |
1695 |
||
1696 |
isCharacters |
|
1697 |
"added for visual works compatibility" |
|
1698 |
^ true |
|
1699 |
! ! |
|
1700 |
||
16295 | 1701 |
!CharacterArray methodsFor:'JavaScript support'! |
1702 |
||
1703 |
unquote |
|
17000 | 1704 |
"removes double quotes from the receiver. |
1705 |
This is the JavaSccript standard unquote function." |
|
1706 |
||
1707 |
|mySize| |
|
1708 |
||
1709 |
(mySize := self size) >= 2 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1710 |
((self first == $") and:[self last == $"]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1711 |
^ self copyFrom:2 to:mySize-1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1712 |
]. |
16295 | 1713 |
]. |
1714 |
^ self |
|
1715 |
||
1716 |
" |
|
17000 | 1717 |
'hello' quote unquote |
1718 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1719 |
JavaScriptParser evaluate:'''hello''.quote.unquote' |
16295 | 1720 |
" |
1721 |
! ! |
|
13510 | 1722 |
|
16175 | 1723 |
|
9192 | 1724 |
!CharacterArray methodsFor:'character searching'! |
1725 |
||
1726 |
includesMatchCharacters |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
1727 |
"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
|
1728 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1729 |
Here, do not care for $\ escapes" |
608 | 1730 |
|
1731 |
^ self includesAny:'*#[' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1732 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1733 |
" |
8874 | 1734 |
'*foo' includesMatchCharacters |
1735 |
'\*foo' includesMatchCharacters |
|
1736 |
'\*foo' includesUnescapedMatchCharacters |
|
1737 |
'*foo' includesMatchCharacters |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1738 |
'\\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1739 |
'foo*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1740 |
'foo\*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1741 |
'foo\' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1742 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1743 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1744 |
"Modified: 2.4.1997 / 18:12:34 / cg" |
9192 | 1745 |
! |
1746 |
||
1747 |
includesSeparator |
|
1748 |
"return true, if the receiver contains any whitespace characters" |
|
1749 |
||
1750 |
^ (self indexOfSeparator ~~ 0) |
|
1751 |
||
1752 |
" |
|
1753 |
'hello world' includesSeparator |
|
1754 |
'helloworld' includesSeparator |
|
1755 |
" |
|
1756 |
! |
|
1757 |
||
1758 |
includesUnescapedMatchCharacters |
|
8874 | 1759 |
"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
|
1760 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1761 |
Here, care for $\ escapes" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1762 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1763 |
|idx sz specialChars escape| |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1764 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1765 |
idx := 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1766 |
sz := self size. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1767 |
specialChars := '*#[\'. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1768 |
(escape := self class matchEscapeCharacter) ~~ $\ ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1769 |
specialChars := specialChars copy. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1770 |
specialChars at:specialChars size put:escape |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1771 |
]. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1772 |
|
16245 | 1773 |
[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1774 |
idx := self indexOfAny:specialChars startingAt:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1775 |
idx == 0 ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1776 |
(self at:idx) == escape ifFalse:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1777 |
idx := idx + 2. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1778 |
idx > sz ifTrue:[^ false]. |
16245 | 1779 |
] loop. |
8874 | 1780 |
|
1781 |
" |
|
1782 |
'*foo' includesUnescapedMatchCharacters |
|
1783 |
'\*foo' includesUnescapedMatchCharacters |
|
1784 |
'\\foo' includesUnescapedMatchCharacters |
|
1785 |
'\\\$foo' includesUnescapedMatchCharacters |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1786 |
'*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1787 |
'\\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1788 |
'foo*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1789 |
'foo\*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1790 |
'foo\' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1791 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1792 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1793 |
"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
|
1794 |
"Created: 2.4.1997 / 17:23:26 / cg" |
9192 | 1795 |
! |
1796 |
||
1797 |
indexOfControlCharacterStartingAt:startIndex |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1798 |
"return the index of the next control character; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1799 |
that is a character with asciiValue < 32. |
15605 | 1800 |
Start the search at startIndex, searching forward. |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1801 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1802 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1803 |
|start "{ Class: SmallInteger }" |
9192 | 1804 |
mySize "{ Class: SmallInteger }"| |
1805 |
||
1806 |
start := startIndex. |
|
1807 |
mySize := self size. |
|
1808 |
||
1809 |
start to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1810 |
(self at:index) isControlCharacter ifTrue:[^ index] |
9192 | 1811 |
]. |
1812 |
^ 0 |
|
1813 |
||
1814 |
" |
|
1815 |
'hello world' asTwoByteString indexOfControlCharacterStartingAt:1 |
|
1816 |
'hello world\foo' withCRsasTwoByteString indexOfControlCharacterStartingAt:1 |
|
1817 |
" |
|
1818 |
||
1819 |
"Modified: / 21.7.1998 / 17:25:07 / cg" |
|
1820 |
! |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1821 |
|
8541 | 1822 |
indexOfNonSeparator |
1823 |
"return the index of the first non-whitespace character. |
|
1824 |
return 0 if no non-separator was found" |
|
1825 |
||
1826 |
^ self indexOfNonSeparatorStartingAt:1. |
|
1827 |
||
1828 |
" |
|
8874 | 1829 |
' hello world' indexOfNonSeparator |
1830 |
' ' indexOfNonSeparator |
|
1831 |
'a ' indexOfNonSeparator |
|
1832 |
'abc' indexOfNonSeparator |
|
1833 |
' ' indexOfNonSeparator |
|
9192 | 1834 |
'' indexOfNonSeparator |
1835 |
" |
|
1836 |
! |
|
1837 |
||
1838 |
indexOfNonSeparatorStartingAt:startIndex |
|
4117 | 1839 |
"return the index of the next non-whitespace character, |
1840 |
starting the search at startIndex, searching forward; |
|
1841 |
return 0 if no non-separator was found" |
|
608 | 1842 |
|
1843 |
|start "{ Class: SmallInteger }" |
|
1844 |
mySize "{ Class: SmallInteger }"| |
|
1845 |
||
1846 |
start := startIndex. |
|
1847 |
mySize := self size. |
|
1848 |
||
1849 |
start to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1850 |
(self at:index) isSeparator ifFalse:[^ index] |
608 | 1851 |
]. |
1852 |
^ 0 |
|
1853 |
||
1854 |
" |
|
8874 | 1855 |
' hello world' indexOfNonSeparatorStartingAt:1 |
1856 |
' ' indexOfNonSeparatorStartingAt:1 |
|
1857 |
'a ' indexOfNonSeparatorStartingAt:2 |
|
4117 | 1858 |
" |
1859 |
||
608 | 1860 |
" |
1861 |
|s index1 index2| |
|
1862 |
s := ' foo bar baz'. |
|
1863 |
index1 := s indexOfNonSeparatorStartingAt:1. |
|
1864 |
index2 := s indexOfSeparatorStartingAt:index1. |
|
1865 |
s copyFrom:index1 to:index2 - 1 |
|
1866 |
" |
|
9192 | 1867 |
! |
1868 |
||
1869 |
indexOfSeparator |
|
1870 |
"return the index of the first whitespace character; |
|
1871 |
starting the search at the beginning, searching forward; |
|
1872 |
return 0 if no separator was found" |
|
1873 |
||
1874 |
^ self indexOfSeparatorStartingAt:1 |
|
1875 |
||
1876 |
" |
|
1877 |
'hello world' indexOfSeparator |
|
1878 |
'helloworld' indexOfSeparator |
|
1879 |
'hello ' indexOfSeparator |
|
1880 |
' hello' indexOfSeparator |
|
1881 |
" |
|
1882 |
! |
|
1883 |
||
15912 | 1884 |
indexOfSeparatorOrEndStartingAt:startIndex |
1885 |
"return the index of the next whitespace character, |
|
1886 |
starting the search at startIndex, searching forward; |
|
1887 |
return the index of one behond the end of the receiver if no separator was found. |
|
1888 |
To extract the word, copy from startIndex to the returned index-1" |
|
1889 |
||
1890 |
|idx| |
|
1891 |
||
1892 |
idx := self indexOfSeparatorStartingAt:startIndex. |
|
1893 |
idx == 0 ifTrue:[^ self size + 1]. |
|
1894 |
^ idx. |
|
1895 |
||
1896 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1897 |
'hello world' indexOfSeparatorOrEndStartingAt:3 |
15912 | 1898 |
' hello world' indexOfSeparatorOrEndStartingAt:3 |
1899 |
'hello world ' indexOfSeparatorOrEndStartingAt:3 |
|
1900 |
'hello world ' indexOfSeparatorOrEndStartingAt:6 |
|
1901 |
'hello world ' indexOfSeparatorOrEndStartingAt:7 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1902 |
'helloworld ' indexOfSeparatorOrEndStartingAt:7 |
15912 | 1903 |
'helloworld' indexOfSeparatorOrEndStartingAt:7 |
1904 |
" |
|
1905 |
! |
|
1906 |
||
9192 | 1907 |
indexOfSeparatorStartingAt:startIndex |
1908 |
"return the index of the next whitespace character, |
|
1909 |
starting the search at startIndex, searching forward; |
|
1910 |
return 0 if no separator was found" |
|
1911 |
||
1912 |
|start "{ Class: SmallInteger }" |
|
1913 |
mySize "{ Class: SmallInteger }"| |
|
1914 |
||
1915 |
start := startIndex. |
|
1916 |
mySize := self size. |
|
1917 |
||
1918 |
start to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1919 |
(self at:index) isSeparator ifTrue:[^ index] |
9192 | 1920 |
]. |
1921 |
^ 0 |
|
1922 |
||
1923 |
" |
|
1924 |
'hello world' indexOfSeparatorStartingAt:3 |
|
1925 |
' hello world' indexOfSeparatorStartingAt:3 |
|
8874 | 1926 |
'hello world ' indexOfSeparatorStartingAt:3 |
1927 |
'hello world ' indexOfSeparatorStartingAt:6 |
|
1928 |
'hello world ' indexOfSeparatorStartingAt:7 |
|
1929 |
'helloworld ' indexOfSeparatorStartingAt:7 |
|
1930 |
'helloworld' indexOfSeparatorStartingAt:7 |
|
4117 | 1931 |
" |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1932 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1933 |
|
4117 | 1934 |
lastIndexOfSeparator |
14150
e13160aa321a
comment/format in: #lastIndexOfSeparator
Claus Gittinger <cg@exept.de>
parents:
14141
diff
changeset
|
1935 |
"return the last index of a whitespace character (space or tab). |
4117 | 1936 |
(i.e. start the search at the end and search backwards); |
1937 |
Returns 0 if no separator is found." |
|
1938 |
||
1939 |
^ self lastIndexOfSeparatorStartingAt:(self size) |
|
1940 |
||
1941 |
" |
|
8874 | 1942 |
'hello world' lastIndexOfSeparator |
1943 |
'helloworld' lastIndexOfSeparator |
|
1944 |
'hel lo wor ld' lastIndexOfSeparator |
|
1945 |
'hel ' lastIndexOfSeparator 6 |
|
4117 | 1946 |
" |
14150
e13160aa321a
comment/format in: #lastIndexOfSeparator
Claus Gittinger <cg@exept.de>
parents:
14141
diff
changeset
|
1947 |
|
e13160aa321a
comment/format in: #lastIndexOfSeparator
Claus Gittinger <cg@exept.de>
parents:
14141
diff
changeset
|
1948 |
"Modified (comment): / 01-06-2012 / 13:10:30 / cg" |
4117 | 1949 |
! |
1950 |
||
1951 |
lastIndexOfSeparatorStartingAt:startIndex |
|
9192 | 1952 |
"return the index of the previous whitespace character, |
1953 |
starting the search at startIndex (and searching backwards); |
|
1954 |
returns 0 if no separator was found" |
|
1955 |
||
1956 |
|start "{ Class: SmallInteger }"| |
|
1957 |
||
1958 |
start := startIndex. |
|
1959 |
||
1960 |
start to:1 by:-1 do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1961 |
(self at:index) isSeparator ifTrue:[^ index] |
9192 | 1962 |
]. |
1963 |
^ 0 |
|
1964 |
||
1965 |
" |
|
1966 |
'hello world' lastIndexOfSeparatorStartingAt:3 |
|
1967 |
'hello world' lastIndexOfSeparatorStartingAt:7 |
|
1968 |
'helloworld' lastIndexOfSeparatorStartingAt:7 |
|
8874 | 1969 |
' helloworld' lastIndexOfSeparatorStartingAt:7 |
4117 | 1970 |
" |
608 | 1971 |
! ! |
1972 |
||
1973 |
!CharacterArray methodsFor:'comparing'! |
|
1974 |
||
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1975 |
< aString |
608 | 1976 |
"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
|
1977 |
receiver is greater than the argument. Otherwise return false. |
8874 | 1978 |
This comparison is based on the elements ascii code - |
9192 | 1979 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
1980 |
||
1981 |
|mySize "{ Class: SmallInteger }" |
|
1982 |
otherSize "{ Class: SmallInteger }" |
|
1983 |
n "{ Class: SmallInteger }" |
|
1984 |
c1 c2| |
|
1985 |
||
1986 |
mySize := self size. |
|
1987 |
otherSize := aString string size. |
|
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1988 |
n := mySize min:otherSize. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1989 |
|
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1990 |
1 to:n do:[:index | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1991 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1992 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1993 |
(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
|
1994 |
]. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1995 |
^ mySize < otherSize |
608 | 1996 |
! |
1997 |
||
1998 |
= aString |
|
1999 |
"Compare the receiver with the argument and return true if the |
|
2000 |
receiver is equal to the argument. Otherwise return false. |
|
1252 | 2001 |
|
9191 | 2002 |
This compare does NOT ignore case differences, |
608 | 2003 |
therefore 'foo' = 'Foo' will return false. |
2004 |
Since this is incompatible to ST-80 (at least, V2.x) , this may change." |
|
2005 |
||
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
2006 |
|mySize "{ Class: SmallInteger }"| |
608 | 2007 |
|
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2008 |
(aString isString or:[aString species == self species]) ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2009 |
^ false |
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2010 |
]. |
608 | 2011 |
mySize := self size. |
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
2012 |
mySize ~~ (aString size) ifTrue:[^ false]. |
608 | 2013 |
|
2014 |
1 to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2015 |
(self at:index) = (aString at:index) ifFalse:[^ false]. |
608 | 2016 |
]. |
2017 |
^ true |
|
2018 |
||
2019 |
" |
|
8874 | 2020 |
'foo' = 'Foo' |
2021 |
'foo' = 'bar' |
|
2022 |
'foo' = 'foo' |
|
2023 |
'foo' = 'foo' asText |
|
2024 |
'foo' asText = 'foo' |
|
2025 |
'foo' asText = 'foo' asText |
|
608 | 2026 |
" |
1252 | 2027 |
|
2028 |
"Modified: 22.4.1996 / 15:53:58 / cg" |
|
608 | 2029 |
! |
9192 | 2030 |
|
9191 | 2031 |
> aString |
608 | 2032 |
"Compare the receiver with the argument and return true if the |
2033 |
receiver is greater than the argument. Otherwise return false. |
|
8874 | 2034 |
This comparison is based on the elements ascii code - |
1252 | 2035 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
608 | 2036 |
|
2037 |
|mySize "{ Class: SmallInteger }" |
|
8874 | 2038 |
otherSize "{ Class: SmallInteger }" |
9192 | 2039 |
n "{ Class: SmallInteger }" |
2040 |
c1 c2| |
|
2041 |
||
2042 |
mySize := self size. |
|
5929 | 2043 |
otherSize := aString string size. |
2044 |
n := mySize min:otherSize. |
|
2045 |
||
2046 |
1 to:n do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2047 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2048 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2049 |
(c1 == c2 or:[c1 = c2]) ifFalse:[^ c1 > c2]. |
5929 | 2050 |
]. |
9192 | 2051 |
^ mySize > otherSize |
2052 |
||
2053 |
"Modified: 22.4.1996 / 15:55:00 / cg" |
|
2054 |
! |
|
2055 |
||
14660 | 2056 |
after:aString |
2057 |
"Compare the receiver with the argument and return true if the |
|
2058 |
receiver should come after the argument in a sorted list. |
|
2059 |
Otherwise return false. |
|
2060 |
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
|
2061 |
LC_COLLATE, which is initialized from the environment. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2062 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2063 |
Currently it is for Strings, but not for UnicodeStrings... |
14660 | 2064 |
|
2065 |
STUPID: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2066 |
#after has a completely different meaning in SeqColl ..." |
14660 | 2067 |
|
2068 |
^ (self compareCollatingWith:aString) > 0 |
|
2069 |
! |
|
2070 |
||
15814 | 2071 |
compareAsVersionNumberWith:aStringOrCollection |
2072 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2073 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
2074 |
Compare as version numbers in the form a.b.c... ." |
|
2075 |
||
2076 |
|rev1 rev2| |
|
2077 |
||
2078 |
rev1 := self asCollectionOfSubstringsSeparatedBy:$.. |
|
2079 |
aStringOrCollection isString ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2080 |
rev2 := aStringOrCollection asCollectionOfSubstringsSeparatedBy:$.. |
15814 | 2081 |
]. |
2082 |
rev1 := rev1 collect:[:each| each asInteger]. |
|
2083 |
rev2 := rev2 collect:[:each| each asInteger]. |
|
2084 |
||
2085 |
^ rev1 compareWith:rev2 |
|
2086 |
||
2087 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2088 |
self assert:('1' compareAsVersionNumberWith:'2') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2089 |
self assert:('2' compareAsVersionNumberWith:'1') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2090 |
self assert:('1.1' compareAsVersionNumberWith:'2.1.2') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2091 |
self assert:('2.1' compareAsVersionNumberWith:'1.2.3') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2092 |
self assert:('1' compareAsVersionNumberWith:'1.1') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2093 |
self assert:('1.1' compareAsVersionNumberWith:'1') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2094 |
self assert:('1.1' compareAsVersionNumberWith:'1.2') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2095 |
self assert:('1.10' compareAsVersionNumberWith:'1.2') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2096 |
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
|
2097 |
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
|
2098 |
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
|
2099 |
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
|
2100 |
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
|
2101 |
self assert:('1.2.3.4' compareAsVersionNumberWith:#(1 2 3 4)) = 0. |
15814 | 2102 |
" |
2103 |
! |
|
2104 |
||
9192 | 2105 |
compareCaselessWith:aString |
9190 | 2106 |
"Compare the receiver against the argument, ignoreing case. |
2107 |
Return 1 if the receiver is greater, 0 if equal and -1 if less than the argument. |
|
2108 |
||
8874 | 2109 |
This comparison is based on the elements ascii code - |
9190 | 2110 |
i.e. national characters are NOT treated specially. |
2111 |
'foo' compareWith: 'Foo' will return 0" |
|
608 | 2112 |
|
2113 |
|mySize "{ Class: SmallInteger }" |
|
8874 | 2114 |
otherSize "{ Class: SmallInteger }" |
9192 | 2115 |
n "{ Class: SmallInteger }" |
608 | 2116 |
c1 c2| |
2117 |
||
2118 |
mySize := self size. |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
2119 |
otherSize := aString string size. |
608 | 2120 |
n := mySize min:otherSize. |
2121 |
||
2122 |
1 to:n do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2123 |
c1 := (self at:index) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2124 |
c2 := (aString at:index) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2125 |
c1 > c2 ifTrue:[^ 1]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2126 |
c1 < c2 ifTrue:[^ -1]. |
608 | 2127 |
]. |
2128 |
mySize > otherSize ifTrue:[^ 1]. |
|
2129 |
mySize < otherSize ifTrue:[^ -1]. |
|
2130 |
^ 0 |
|
1252 | 2131 |
|
2132 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
608 | 2133 |
! |
2134 |
||
14660 | 2135 |
compareCollatingWith:aString |
2136 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2137 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
2138 |
The comparison is language specific, depending on the value of |
|
2139 |
LC_COLLATE, which is in the shell environment." |
|
2140 |
||
2141 |
"TODO not yet defined for unicode" |
|
2142 |
<resource: #todo> |
|
2143 |
||
2144 |
|s| |
|
2145 |
||
2146 |
(s := self string) ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2147 |
^ s compareCollatingWith:aString |
14660 | 2148 |
]. |
2149 |
^ self compareWith:aString |
|
2150 |
! |
|
2151 |
||
9192 | 2152 |
compareWith:aString |
9190 | 2153 |
"Compare the receiver with the argument and return 1 if the receiver is |
2154 |
greater, 0 if equal and -1 if less than the argument. |
|
11861 | 2155 |
This comparison is based on the elements' codepoints - |
9190 | 2156 |
i.e. upper/lowercase & national characters are NOT treated specially. |
2157 |
'foo' compareWith: 'Foo' will return 1. |
|
2158 |
while 'foo' sameAs:'Foo' will return true" |
|
2159 |
||
15814 | 2160 |
|s| |
2161 |
||
2162 |
s := self string. |
|
2163 |
s ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2164 |
^ s compareWith:aString string. |
9192 | 2165 |
]. |
15814 | 2166 |
^ super compareWith:aString string. |
9192 | 2167 |
! |
2168 |
||
11861 | 2169 |
endsWith:aStringOrCharacter |
16175 | 2170 |
"return true, if the receiver ends with something, aStringOrCharacter. |
2171 |
If aStringOrCharacter is empty, true is returned" |
|
11861 | 2172 |
|
2173 |
|s| |
|
2174 |
||
2175 |
(s := self string) ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2176 |
^ s endsWith:aStringOrCharacter |
11861 | 2177 |
]. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2178 |
(self size > 0 and:[aStringOrCharacter isCharacter]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2179 |
^ self last = aStringOrCharacter |
11861 | 2180 |
]. |
2181 |
^ super endsWith:aStringOrCharacter |
|
2182 |
||
2183 |
" |
|
2184 |
'hello world' endsWith:'world' |
|
2185 |
'hello world' asText allBold endsWith:'world' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2186 |
'hello world' endsWith:'' |
16175 | 2187 |
'hello world' asText allBold endsWith:'' |
11861 | 2188 |
" |
2189 |
||
2190 |
"Modified: 12.5.1996 / 15:49:18 / cg" |
|
2191 |
! |
|
2192 |
||
11838 | 2193 |
hammingDistanceTo:aString |
2194 |
"return the hamming distance (the number of characters which are different). |
|
12177 | 2195 |
In information theory, the Hamming distance between two strings of equal length |
2196 |
is the number of positions for which the corresponding symbols are different. |
|
2197 |
Put another way, it measures the minimum number of substitutions required to change |
|
11838 | 2198 |
one into the other, or the number of errors that transformed one string into the other." |
2199 |
||
2200 |
self assert:(aString size == self size). |
|
2201 |
^ 1 to:self size count:[:idx | (self at:idx) ~= (aString at:idx)] |
|
2202 |
||
2203 |
" |
|
2204 |
'roses' hammingDistanceTo:'toned' |
|
2205 |
" |
|
2206 |
! |
|
2207 |
||
9192 | 2208 |
hash |
2209 |
"return an integer useful as a hash-key" |
|
2210 |
||
16898 | 2211 |
"/ whenever changing, also care for String>>hash. |
13879 | 2212 |
"/ immediately after any change, execute (maybe in a debugger): |
2213 |
"/ Set allSubInstancesDo:[:s | s rehash] |
|
16898 | 2214 |
^ self hash_fnv1a |
2215 |
||
2216 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2217 |
'a' hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2218 |
'a' asUnicode16String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2219 |
'a' asUnicode32String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2220 |
'aa' hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2221 |
'aa' asUnicode16String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2222 |
'aa' asUnicode32String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2223 |
'ab' hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2224 |
'ab' asUnicode16String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2225 |
'ab' asUnicode32String hash |
13879 | 2226 |
'ab' hash |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2227 |
'ab' asArray hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2228 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2229 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2230 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2231 |
|syms ms| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2232 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2233 |
syms := Symbol allInstances. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2234 |
Transcript show:'syms: '; showCR:syms size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2235 |
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
|
2236 |
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
|
2237 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2238 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2239 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2240 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2241 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2242 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2243 |
Transcript show:'sdbm hash: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2244 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2245 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2246 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2247 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2248 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2249 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2250 |
Transcript show:'dragonBook: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2251 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2252 |
syms := syms collect:[:each| each asUnicode16String]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2253 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2254 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2255 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2256 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2257 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2258 |
Transcript show:'unicode sdbm hash: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2259 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2260 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2261 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2262 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2263 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2264 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2265 |
Transcript show:'unicode dragonBook:'; showCR:ms. |
14641 | 2266 |
" |
2267 |
||
13879 | 2268 |
"Modified: / 26-12-2011 / 14:09:07 / cg" |
2269 |
! |
|
2270 |
||
2271 |
hash_dragonBook |
|
2272 |
"return an integer useful as a hash-key" |
|
2273 |
||
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2274 |
|h g| |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2275 |
|
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2276 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2277 |
"/ this is the dragon-book algorithm |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2278 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2279 |
h := 0. |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2280 |
self reverseDo:[:char | |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2281 |
"/ 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
|
2282 |
"/ h := (h bitShift:4) + char asciiValue. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2283 |
h := (h bitShift:4). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2284 |
h := h + char codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2285 |
h := h bitAnd:16rFFFFFFFF. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2286 |
g := (h bitAnd: 16rF0000000). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2287 |
g ~~ 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2288 |
h := h bitXor:(g bitShift:-24). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2289 |
h := h bitXor:g. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2290 |
]. |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2291 |
]. |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2292 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2293 |
"/ multiply by large prime to spread values |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2294 |
"/ This speeds up Set and Dictionary by a factor of 10!! |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2295 |
"/ |
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
2296 |
h := h times:31415821. |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2297 |
^ h |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2298 |
|
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2299 |
" |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2300 |
'a' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2301 |
'a' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2302 |
'aa' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2303 |
'aa' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2304 |
'ab' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2305 |
'ab' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2306 |
'ab' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2307 |
'ab' asArray hash |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2308 |
" |
13879 | 2309 |
|
2310 |
"Created: / 26-12-2011 / 13:46:06 / cg" |
|
2311 |
! |
|
2312 |
||
16887 | 2313 |
hash_fnv1a |
2314 |
"return an integer useful as a hash-key. |
|
2315 |
This method uses the fnv-1a algorithm |
|
2316 |
(which is actually a very good one)" |
|
2317 |
||
2318 |
|h| |
|
2319 |
||
2320 |
h := 2166136261. |
|
2321 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2322 |
h := h bitXor:(eachChar codePoint). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2323 |
h := (h * 16777619) bitAnd:16rFFFFFFFF. |
16887 | 2324 |
]. |
16898 | 2325 |
"/ make sure, it fits into a smallInt |
2326 |
h := (h bitXor: (h >> 30)) bitAnd: 16r3FFFFFFF. |
|
16887 | 2327 |
^ h |
2328 |
||
2329 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2330 |
'abc' hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2331 |
'abc' asUnicode16String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2332 |
'abc' asUnicode32String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2333 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2334 |
'foofooHelloWorld' hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2335 |
'foofooHelloWorld' asUnicode16String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2336 |
'foofooHelloWorld' asUnicode32String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2337 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2338 |
'blablaHelloWorld' hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2339 |
'blablaHelloWorld' asUnicode16String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2340 |
'blablaHelloWorld' asUnicode32String hash_fnv1a |
16887 | 2341 |
" |
2342 |
! |
|
2343 |
||
2344 |
hash_java |
|
2345 |
"return an integer useful as a hash-key. |
|
2346 |
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
|
2347 |
the java virtual machine |
16887 | 2348 |
(which is actually not a very good one)." |
2349 |
||
2350 |
|h| |
|
2351 |
||
2352 |
h := 0. |
|
2353 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2354 |
h := (h * 31) + (eachChar codePoint). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2355 |
h := h bitAnd:16rFFFFFFFF. |
16887 | 2356 |
]. |
2357 |
^ h |
|
2358 |
||
2359 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2360 |
'abc' hash_java |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2361 |
'foofooHelloWorld' hash_java |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2362 |
'blablaHelloWorld' hash_java |
16887 | 2363 |
" |
2364 |
! |
|
2365 |
||
16898 | 2366 |
hash_sdbm |
2367 |
"return an integer useful as a hash-key. |
|
2368 |
This method implements the sdbm algorithm." |
|
2369 |
||
2370 |
|h| |
|
2371 |
||
2372 |
"/ |
|
2373 |
"/ this is the sdbm algorithm |
|
2374 |
"/ |
|
2375 |
h := 0. |
|
2376 |
self do:[:char | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2377 |
h := (65599 times:h) plus:char codePoint. |
16898 | 2378 |
]. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2379 |
^ h |
16898 | 2380 |
|
2381 |
" |
|
2382 |
'a' hash |
|
2383 |
'a' asUnicode16String hash |
|
2384 |
'aa' hash |
|
2385 |
'aa' asUnicode16String hash |
|
2386 |
'ab' hash |
|
2387 |
'ab' asUnicode16String hash |
|
2388 |
'ab' hash |
|
2389 |
'ab' asArray hash |
|
2390 |
" |
|
2391 |
||
2392 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2393 |
|syms ms| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2394 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2395 |
syms := Symbol allInstances. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2396 |
Transcript show:'syms: '; showCR:syms size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2397 |
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
|
2398 |
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
|
2399 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2400 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2401 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2402 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2403 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2404 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2405 |
Transcript show:'sdbm hash: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2406 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2407 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2408 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2409 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2410 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2411 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2412 |
Transcript show:'dragonBook: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2413 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2414 |
syms := syms collect:[:each| each asUnicode16String]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2415 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2416 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2417 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2418 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2419 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2420 |
Transcript show:'unicode sdbm hash: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2421 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2422 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2423 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2424 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2425 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2426 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2427 |
Transcript show:'unicode dragonBook:'; showCR:ms. |
16898 | 2428 |
" |
2429 |
||
2430 |
"Modified: / 26-12-2011 / 14:09:07 / cg" |
|
2431 |
! |
|
2432 |
||
11861 | 2433 |
levenshteinTo:aString |
2434 |
"return the levenshtein distance to the argument, aString; |
|
2435 |
this value corresponds to the number of replacements that have to be |
|
2436 |
made to get aString from the receiver. |
|
2437 |
See IEEE transactions on Computers 1976 Pg 172 ff." |
|
2438 |
||
2439 |
" |
|
2440 |
in the following, we assume that ommiting a character |
|
2441 |
is less of an error than inserting an extra character. |
|
2442 |
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
|
2443 |
s: substitution weight (4) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2444 |
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
|
2445 |
c: case weight (4) - or nil (then use s) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2446 |
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
|
2447 |
i: insertion of extra character weight (2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2448 |
d: delete of a character weight (6) |
11861 | 2449 |
" |
2450 |
||
2451 |
^ StringUtilities |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2452 |
levenshteinDistanceFrom:self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2453 |
to:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2454 |
s:4 k:4 c:4 e:nil i:2 d:6 |
12177 | 2455 |
|
2456 |
" |
|
2457 |
'computer' levenshteinTo:'computer' |
|
11861 | 2458 |
'cOmputer' levenshteinTo:'computer' |
12177 | 2459 |
'cOmpuTer' levenshteinTo:'computer' |
11861 | 2460 |
'cimputer' levenshteinTo:'computer' |
2461 |
'cumputer' levenshteinTo:'computer' |
|
2462 |
||
2463 |
'cmputer' levenshteinTo:'computer' |
|
2464 |
'coomputer' levenshteinTo:'computer' |
|
2465 |
||
2466 |
'ocmprt' levenshteinTo:'computer' |
|
2467 |
'computer' levenshteinTo:'computer' |
|
2468 |
'ocmputer' levenshteinTo:'computer' |
|
2469 |
'cmputer' levenshteinTo:'computer' |
|
2470 |
'computer' levenshteinTo:'cmputer' |
|
2471 |
'Computer' levenshteinTo:'computer' |
|
2472 |
||
12177 | 2473 |
'compiter' levenshteinTo:'computer' |
2474 |
'compoter' levenshteinTo:'computer' |
|
2475 |
||
2476 |
'comptuer' levenshteinTo:'computer' |
|
11861 | 2477 |
" |
2478 |
! |
|
2479 |
||
2480 |
levenshteinTo:aString s:substWeight k:kbdTypoWeight c:caseWeight i:insrtWeight d:deleteWeight |
|
2481 |
"parametrized levenshtein. |
|
2482 |
return the levenshtein distance to the argument, aString; |
|
2483 |
this value corrensponds to the number of replacements that have to be |
|
2484 |
made to get aString from the receiver. |
|
2485 |
The arguments are the costs for |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2486 |
s:substitution, |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2487 |
k:keyboard type (substitution), |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2488 |
c:case-change, |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2489 |
i:insertion |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2490 |
d:deletion |
11861 | 2491 |
of a character. |
2492 |
See IEEE transactions on Computers 1976 Pg 172 ff" |
|
2493 |
||
2494 |
^ StringUtilities |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2495 |
levenshteinDistanceFrom:self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2496 |
to:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2497 |
s:substWeight k:kbdTypoWeight c:caseWeight e:nil i:insrtWeight d:deleteWeight |
11861 | 2498 |
! |
2499 |
||
9190 | 2500 |
sameAs:aString |
2501 |
"Compare the receiver with the argument like =, but ignore case differences. |
|
2502 |
Return true or false." |
|
2503 |
||
2504 |
|mySize "{ Class: SmallInteger }" |
|
2505 |
otherSize c1 c2| |
|
2506 |
||
9192 | 2507 |
self == aString ifTrue:[^ true]. |
2508 |
||
2509 |
mySize := self size. |
|
2510 |
otherSize := aString string size. |
|
2511 |
mySize == otherSize ifFalse:[^ false]. |
|
2512 |
||
2513 |
1 to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2514 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2515 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2516 |
c1 == c2 ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2517 |
(c1 sameAs:c2) ifFalse:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2518 |
] |
9192 | 2519 |
]. |
2520 |
^ true |
|
2521 |
||
608 | 2522 |
" |
8874 | 2523 |
'foo' sameAs: 'Foo' |
2524 |
'foo' sameAs: 'bar' |
|
2525 |
'foo' sameAs: 'foo' |
|
9192 | 2526 |
" |
2527 |
||
2528 |
"Modified: 22.4.1996 / 15:56:17 / cg" |
|
2529 |
! |
|
608 | 2530 |
|
15734 | 2531 |
sameAs:aString caseSensitive:caseSensitive |
2532 |
"Compare the receiver with the argument. |
|
2533 |
If caseSensitive is false, this is the same as #sameAs:, |
|
2534 |
if false, this is the same as #=." |
|
2535 |
||
2536 |
caseSensitive ifFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2537 |
^ self sameAs:aString |
15734 | 2538 |
]. |
2539 |
^ self = aString |
|
2540 |
||
2541 |
" |
|
2542 |
'foo' sameAs:'Foo' caseSensitive:false |
|
2543 |
'foo' sameAs:'foo' caseSensitive:true |
|
2544 |
" |
|
2545 |
! |
|
2546 |
||
5242 | 2547 |
sameAs:aString ignoreCase:ignoreCase |
15734 | 2548 |
<resource: #obsolete> |
5242 | 2549 |
"Compare the receiver with the argument. |
2550 |
If ignoreCase is true, this is the same as #sameAs:, |
|
2551 |
if false, this is the same as #=." |
|
2552 |
||
2553 |
ignoreCase ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2554 |
^ self sameAs:aString |
5242 | 2555 |
]. |
2556 |
^ self = aString |
|
2557 |
||
2558 |
" |
|
8874 | 2559 |
'foo' sameAs:'Foo' ignoreCase:false |
2560 |
'foo' sameAs:'foo' ignoreCase:true |
|
5242 | 2561 |
" |
2562 |
||
2563 |
! |
|
2564 |
||
608 | 2565 |
sameCharacters:aString |
9192 | 2566 |
"count & return the number of characters which are the same |
2567 |
(ignoring case and emphasis) in the receiver and the argument, aString." |
|
2568 |
||
2569 |
|n "{ Class: SmallInteger }" |
|
2570 |
c1 c2 cnt| |
|
2571 |
||
2572 |
n := self size. |
|
2573 |
n := n min:(aString string size). |
|
2574 |
||
2575 |
cnt := 0. |
|
2576 |
1 to:n do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2577 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2578 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2579 |
((c1 == c2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2580 |
or:[c1 asLowercase = c2 asLowercase]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2581 |
cnt := cnt + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2582 |
] |
9192 | 2583 |
]. |
2584 |
^ cnt |
|
2585 |
||
2586 |
" |
|
2587 |
'foobarbaz' sameCharacters: 'foo' |
|
8874 | 2588 |
'foobarbaz' sameCharacters: 'Foo' |
2589 |
'foobarbaz' sameCharacters: 'baz' |
|
608 | 2590 |
" |
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2591 |
! |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2592 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2593 |
sameEmphasisAs:aStringOrText |
17215 | 2594 |
"compare the receiver's and the argument's emphasis" |
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2595 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2596 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2597 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2598 |
" |
8874 | 2599 |
'hello' asText sameEmphasisAs: 'hello' |
2600 |
'hello' asText sameEmphasisAs: 'hello' asText |
|
2601 |
'hello' asText allBold sameEmphasisAs: 'hello' |
|
2602 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
|
9192 | 2603 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
2604 |
" |
|
2605 |
! |
|
2606 |
||
9191 | 2607 |
sameStringAndEmphasisAs:aStringOrText |
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
2608 |
"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
|
2609 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2610 |
aStringOrText isString ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2611 |
(self string = aStringOrText string) ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2612 |
self hasChangeOfEmphasis = aStringOrText hasChangeOfEmphasis ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2613 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2614 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2615 |
" |
8874 | 2616 |
'hello' asText sameEmphasisAs: 'hello' |
2617 |
'hello' asText sameEmphasisAs: 'hello' asText |
|
2618 |
'hello' asText allBold sameEmphasisAs: 'hello' |
|
2619 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
|
2620 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
|
2621 |
||
2622 |
'hello' sameEmphasisAs: 'hello' asText |
|
2623 |
'hello' sameEmphasisAs: 'hello' asText allBold |
|
2624 |
'hello' sameEmphasisAs: 'fooba' |
|
2625 |
'hello' sameEmphasisAs: 'fooba' asText |
|
2626 |
'hello' sameEmphasisAs: 'fooba' asText allBold |
|
2627 |
'hello' sameEmphasisAs: 'fooba' asText allItalic |
|
2628 |
||
2629 |
'hello' asText sameStringAndEmphasisAs: 'hello' |
|
2630 |
'hello' asText sameStringAndEmphasisAs: 'hello' asText |
|
2631 |
'hello' asText allBold sameStringAndEmphasisAs: 'hello' |
|
2632 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allBold |
|
2633 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allItalic |
|
2634 |
||
2635 |
'hello' sameStringAndEmphasisAs: 'hello' asText |
|
2636 |
'hello' sameStringAndEmphasisAs: 'hello' asText allBold |
|
2637 |
'hello' sameStringAndEmphasisAs: 'fooba' |
|
2638 |
'hello' sameStringAndEmphasisAs: 'fooba' asText |
|
2639 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allBold |
|
2640 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allItalic |
|
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2641 |
" |
11861 | 2642 |
! |
2643 |
||
2644 |
spellAgainst: aString |
|
2645 |
"return an integer between 0 and 100 indicating how similar |
|
2646 |
the argument is to the receiver. No case conversion is done. |
|
2647 |
This algorithm is much simpler (but also less exact) than the |
|
2648 |
levenshtein distance. Experiment which is better for your |
|
2649 |
application." |
|
2650 |
||
2651 |
| i1 "{ Class: SmallInteger }" |
|
2652 |
i2 "{ Class: SmallInteger }" |
|
2653 |
next1 "{ Class: SmallInteger }" |
|
2654 |
next2 "{ Class: SmallInteger }" |
|
2655 |
size1 "{ Class: SmallInteger }" |
|
2656 |
size2 "{ Class: SmallInteger }" |
|
2657 |
score "{ Class: SmallInteger }" |
|
2658 |
maxLen "{ Class: SmallInteger }" | |
|
2659 |
||
2660 |
size1 := self size. |
|
2661 |
size2 := aString size. |
|
2662 |
maxLen := size1 max:size2. |
|
2663 |
score := 0. |
|
2664 |
i1 := i2 := 1. |
|
2665 |
[i1 <= size1 and: [i2 <= size2]] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2666 |
next1 := i1 + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2667 |
next2 := i2 + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2668 |
(self at:i1) == (aString at:i2) ifTrue: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2669 |
score := score+1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2670 |
i1 := next1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2671 |
i2 := next2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2672 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2673 |
(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
|
2674 |
i2 := next2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2675 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2676 |
(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
|
2677 |
i1 := next1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2678 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2679 |
i1 := next1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2680 |
i2 := next2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2681 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2682 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2683 |
] |
11861 | 2684 |
]. |
2685 |
||
2686 |
score == maxLen ifTrue: [^ 100]. |
|
2687 |
^ 100 * score // maxLen |
|
2688 |
||
2689 |
" |
|
2690 |
'Smalltalk' spellAgainst: 'Smalltlak' |
|
2691 |
'Smalltalk' spellAgainst: 'smalltlak' |
|
2692 |
'Smalltalk' spellAgainst: 'smalltalk' |
|
2693 |
'Smalltalk' spellAgainst: 'smalltlk' |
|
2694 |
'Smalltalk' spellAgainst: 'Smalltolk' |
|
2695 |
" |
|
2696 |
! |
|
2697 |
||
16553 | 2698 |
startsWith:aStringOrCharacter |
2699 |
"return true, if the receiver starts with something, aStringOrCharacter. |
|
17371 | 2700 |
If the argument is empty, true is returned. |
2701 |
Notice, that this is similar to, but slightly different from VW's and Squeak's beginsWith:, |
|
2702 |
which are both inconsistent w.r.t. an empty argument." |
|
11861 | 2703 |
|
2704 |
|s| |
|
2705 |
||
16553 | 2706 |
aStringOrCharacter isCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2707 |
^ (self size > 0) and:[ (self at:1) == aStringOrCharacter ] |
16553 | 2708 |
]. |
11861 | 2709 |
(s := self string) ~~ self ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2710 |
^ s startsWith:aStringOrCharacter |
11861 | 2711 |
]. |
16553 | 2712 |
^ super startsWith:aStringOrCharacter |
11861 | 2713 |
|
2714 |
" |
|
17364 | 2715 |
'abcde' startsWith:#($a $b $c) |
2716 |
'abcde' startsWith:'abc' |
|
2717 |
'abcd' startsWith:'abcde' |
|
2718 |
'abcde' startsWith:'abd' |
|
11861 | 2719 |
'hello world' startsWith:'hello' |
2720 |
'hello world' asText allBold startsWith:'hello' |
|
2721 |
'hello world' asText allBold startsWith:'' |
|
2722 |
" |
|
2723 |
||
2724 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
2725 |
"Modified: 12.5.1996 / 15:49:24 / cg" |
|
9192 | 2726 |
! ! |
2727 |
||
2728 |
!CharacterArray methodsFor:'converting'! |
|
2729 |
||
11881 | 2730 |
asAsciiZ |
2731 |
"if the receiver does not end with a 0-valued character, return a copy of it, |
|
2732 |
with an additional 0-character. Otherwise return the receiver. This is sometimes |
|
2733 |
needed when a string has to be passed to C, which needs 0-terminated strings. |
|
2734 |
Notice, that all singleByte strings are already 0-terminated in ST/X, whereas wide |
|
2735 |
strings are not." |
|
2736 |
||
12658 | 2737 |
(self notEmpty and:[self last codePoint == 0]) ifTrue:[^ self ]. |
11881 | 2738 |
^ self copyWith:(Character value:0). |
2739 |
||
2740 |
" |
|
2741 |
'abc' asAsciiZ |
|
2742 |
'abc' asWideString asAsciiZ |
|
2743 |
" |
|
2744 |
! |
|
2745 |
||
13524 | 2746 |
asByteArray |
15936 | 2747 |
"depending on the size of the characters in the receiver, |
2748 |
return a byteArray containing single-, double- or even 4-bytewise values. |
|
2749 |
The size of the returned byteArray will be the strings size multiplied by the |
|
2750 |
size required for the largest character. |
|
2751 |
Caveat: better use utf8Encoded, to get reproducable results" |
|
2752 |
||
14555 | 2753 |
|bytes sz bytesPerCharacter idx str| |
2754 |
||
2755 |
str := self string. |
|
2756 |
str ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2757 |
"/ for text and other wrappers |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2758 |
^ str asByteArray |
13611
ba8c7372218a
variable renamed in: #inspector2TabBytes
Claus Gittinger <cg@exept.de>
parents:
13524
diff
changeset
|
2759 |
]. |
ba8c7372218a
variable renamed in: #inspector2TabBytes
Claus Gittinger <cg@exept.de>
parents:
13524
diff
changeset
|
2760 |
|
ba8c7372218a
variable renamed in: #inspector2TabBytes
Claus Gittinger <cg@exept.de>
parents:
13524
diff
changeset
|
2761 |
"/ for real strings, a fallback |
13524 | 2762 |
sz := self size. |
2763 |
bytesPerCharacter := self bitsPerCharacter // 8. |
|
2764 |
bytes := ByteArray new:(sz * bytesPerCharacter). |
|
2765 |
idx := 1. |
|
2766 |
self do:[:char | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2767 |
|code| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2768 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2769 |
code := char codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2770 |
bytesPerCharacter == 2 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2771 |
bytes unsignedShortAt:idx put:code |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2772 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2773 |
bytesPerCharacter == 4 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2774 |
bytes unsignedLongAt:idx put:code |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2775 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2776 |
bytes at:idx put:code |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2777 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2778 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2779 |
idx := idx + bytesPerCharacter. |
13524 | 2780 |
]. |
2781 |
^ bytes |
|
2782 |
||
2783 |
"Created: / 27-07-2011 / 00:56:17 / cg" |
|
2784 |
! |
|
2785 |
||
608 | 2786 |
asCollectionOfLines |
8874 | 2787 |
"return a collection containing the lines (separated by cr) |
608 | 2788 |
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
|
2789 |
contain empty strings. |
14456
d7c3e67647f1
comment/format in: #asCollectionOfLines
Claus Gittinger <cg@exept.de>
parents:
14455
diff
changeset
|
2790 |
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
|
2791 |
See also #asCollectionOfLinesWithReturn |
d7c3e67647f1
comment/format in: #asCollectionOfLines
Claus Gittinger <cg@exept.de>
parents:
14455
diff
changeset
|
2792 |
(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
|
2793 |
this method and we did not want to risk any incompatibilities)" |
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2794 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2795 |
^ self asCollectionOfSubstringsSeparatedBy:Character cr. |
608 | 2796 |
|
2797 |
" |
|
2798 |
'1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines |
|
8874 | 2799 |
'1 one\\\\2 two\3 three' withCRs asCollectionOfLines |
608 | 2800 |
" |
2801 |
! |
|
2802 |
||
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2803 |
asCollectionOfLinesWithReturn |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2804 |
"return a collection containing the lines (separated by cr) |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2805 |
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
|
2806 |
contain empty strings." |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2807 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2808 |
|lines| |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2809 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2810 |
lines := self asCollectionOfSubstringsSeparatedBy:Character cr. |
18194 | 2811 |
(lines notEmpty and:[lines last isEmpty]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2812 |
^ lines copyButLast:1 |
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2813 |
]. |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2814 |
^ lines |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2815 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2816 |
" |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2817 |
'1\2\3' withCRs asCollectionOfLines |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2818 |
'1\2\3\' withCRs asCollectionOfLines |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2819 |
'1\2\3' withCRs asCollectionOfLinesWithReturn |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2820 |
'1\2\3\' withCRs asCollectionOfLinesWithReturn |
18194 | 2821 |
'' withCRs asCollectionOfLinesWithReturn |
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2822 |
" |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2823 |
! |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2824 |
|
608 | 2825 |
asCollectionOfSubstringsSeparatedBy:aCharacter |
15740 | 2826 |
"return a collection containing substrings (separated by aCharacter) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2827 |
of the receiver. |
15740 | 2828 |
If aCharacter occurs multiple times in a row, the result will contain empty strings. |
2829 |
If the receiver ends with aCharacter, an empty string with be the last result element." |
|
608 | 2830 |
|
9192 | 2831 |
^ self asCollectionOfSubCollectionsSeparatedBy:aCharacter |
2832 |
||
2833 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2834 |
'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
|
2835 |
'1 one:2 two:3 three:4 four:5 five:' asCollectionOfSubstringsSeparatedBy:$: |
15740 | 2836 |
'1 one 2 two 3 three 4 four 5 five' asCollectionOfSubstringsSeparatedBy:Character space |
9192 | 2837 |
" |
2838 |
! |
|
608 | 2839 |
|
11828 | 2840 |
asCollectionOfSubstringsSeparatedBy:aCharacter exceptIn:ch |
15740 | 2841 |
"return a collection containing the substrings (separated by aCharacter) |
12177 | 2842 |
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
|
2843 |
the result will contain empty strings. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2844 |
The separation is not done, inside a matching pair of ch-substrings. |
15740 | 2845 |
Can be used to tokenize csv-like strings, which may or may not be enclosed in quotes." |
11828 | 2846 |
|
2847 |
|lines myClass except i c |
|
2848 |
startIndex "{ Class:SmallInteger }" |
|
2849 |
stopIndex "{ Class:SmallInteger }" | |
|
2850 |
||
11905
cbc2191cfe2d
return stringCollections from asCollectionOfXXX
Claus Gittinger <cg@exept.de>
parents:
11904
diff
changeset
|
2851 |
lines := StringCollection new. |
11828 | 2852 |
myClass := self species. |
2853 |
||
2854 |
startIndex := 1. |
|
2855 |
except := false. |
|
2856 |
[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2857 |
i := startIndex-1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2858 |
[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2859 |
i := i+1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2860 |
c := self at:i. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2861 |
c = ch ifTrue:[ except := except not. ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2862 |
i < self size and:[except or:[c ~= aCharacter]] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2863 |
] whileTrue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2864 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2865 |
c = aCharacter ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2866 |
stopIndex := i -1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2867 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2868 |
stopIndex := i. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2869 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2870 |
(stopIndex < startIndex) ifTrue: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2871 |
lines add:(myClass new:0) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2872 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2873 |
lines add:(self copyFrom:startIndex to:stopIndex) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2874 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2875 |
startIndex := stopIndex + 2. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2876 |
startIndex <= self size |
11828 | 2877 |
] whileTrue. |
2878 |
^ lines |
|
2879 |
||
2880 |
" |
|
12177 | 2881 |
'asd''f;d''dd;s' asCollectionOfSubstringsSeparatedBy:$; exceptIn:$' |
2882 |
" |
|
2883 |
"/ 'asd "hello bla" foo "bla bla" bar' asCollectionOfSubstringsSeparatedBy:$ exceptIn:$" |
|
11828 | 2884 |
! |
2885 |
||
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2886 |
asCollectionOfSubstringsSeparatedBy:aFieldSeparatorString textSeparator:aTextSeparatorOrNil |
13343
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
2887 |
"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
|
2888 |
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
|
2889 |
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
|
2890 |
|
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2891 |
|aTextSeparatorChar items scanningWord inStream element lastIsFieldSeparator sz| |
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2892 |
|
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2893 |
aTextSeparatorOrNil isNil ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2894 |
^ self asCollectionOfSubstringsSeparatedByAll: aFieldSeparatorString |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2895 |
]. |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2896 |
sz := aTextSeparatorOrNil size. |
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2897 |
sz = 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2898 |
aTextSeparatorChar := aTextSeparatorOrNil |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2899 |
] ifFalse:[sz = 1 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2900 |
"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
|
2901 |
aTextSeparatorChar := aTextSeparatorOrNil first. |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2902 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2903 |
self error:'textSeparatoSize > 1'. |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2904 |
]]. |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2905 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2906 |
items := OrderedCollection new. |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2907 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2908 |
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
|
2909 |
[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2910 |
inStream skipSeparators. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2911 |
inStream atEnd |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2912 |
] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2913 |
lastIsFieldSeparator := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2914 |
inStream peek == aTextSeparatorChar ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2915 |
inStream next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2916 |
element := ''. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2917 |
scanningWord := true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2918 |
[ scanningWord and:[inStream atEnd not] ] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2919 |
element := element , (inStream upTo:aTextSeparatorChar). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2920 |
(inStream peek == aTextSeparatorChar) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2921 |
element := element , aTextSeparatorChar . |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2922 |
inStream next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2923 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2924 |
scanningWord := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2925 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2926 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2927 |
inStream upToAll_positionBefore:aFieldSeparatorString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2928 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2929 |
element := inStream upToAll_positionBefore:aFieldSeparatorString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2930 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2931 |
items add:element. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2932 |
lastIsFieldSeparator := (inStream skipThroughAll:aFieldSeparatorString) notNil. |
13343
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
2933 |
]. |
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
2934 |
lastIsFieldSeparator ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2935 |
"empty element at the end of the line" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2936 |
items add:''. |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2937 |
]. |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2938 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2939 |
^ items |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2940 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2941 |
" |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2942 |
self assert:(('#First#, #Second,SecondAdd#, #Third#' asCollectionOfSubstringsSeparatedBy:',' textSeparator: $#) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2943 |
sameContentsAs:#('First' 'Second,SecondAdd' 'Third')). |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2944 |
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
|
2945 |
sameContentsAs:#('Fir#st' 'Second,SecondAdd' 'Third')). |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2946 |
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
|
2947 |
sameContentsAs:#('Fir#st' 'Second' 'SecondAdd' 'Third')). |
13343
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
2948 |
self assert:(('First,Second,Third,,' asCollectionOfSubstringsSeparatedBy:',' textSeparator:nil) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2949 |
sameContentsAs:#('First' 'Second' 'Third' '' '')). |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2950 |
self assert:(('First,Second,Third,,' asCollectionOfSubstringsSeparatedBy:',' textSeparator:'#') |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2951 |
sameContentsAs:#('First' 'Second' 'Third' '' '')). |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2952 |
" |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2953 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2954 |
"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
|
2955 |
! |
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2956 |
|
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2957 |
asCollectionOfSubstringsSeparatedByAll:aSeparatorString |
8874 | 2958 |
"return a collection containing the lines (separated by aSeparatorString) |
2959 |
of the receiver. If aSeparatorString occurs multiple times in a row, |
|
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2960 |
the result will contain empty strings." |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2961 |
|
8852
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2962 |
^ self asCollectionOfSubCollectionsSeparatedByAll:aSeparatorString |
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2963 |
|
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2964 |
" |
8874 | 2965 |
'1::2::3::4::5::' asCollectionOfSubstringsSeparatedByAll:'::' |
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2966 |
" |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2967 |
! |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2968 |
|
608 | 2969 |
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators |
2970 |
"return a collection containing the words (separated by any character |
|
2971 |
from aCollectionOfSeparators) of the receiver. |
|
2972 |
This allows breaking up strings using any character as separator." |
|
2973 |
||
8852
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2974 |
^ self asCollectionOfSubCollectionsSeparatedByAny:aCollectionOfSeparators |
608 | 2975 |
|
2976 |
" |
|
2977 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:) |
|
8874 | 2978 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' |
2979 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) |
|
2980 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' |
|
2981 |
'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) |
|
608 | 2982 |
" |
2983 |
! |
|
2984 |
||
2985 |
asCollectionOfWords |
|
8874 | 2986 |
"return a collection containing the words (separated by whitespace) |
2987 |
of the receiver. Multiple occurrences of whitespace characters will |
|
17517 | 2988 |
be treated like one - i.e. whitespace is skipped. |
2989 |
(sigh: it is called #'subStrings' in V'Age, and #'substrings' in Squeak) " |
|
608 | 2990 |
|
7797 | 2991 |
|words| |
608 | 2992 |
|
11905
cbc2191cfe2d
return stringCollections from asCollectionOfXXX
Claus Gittinger <cg@exept.de>
parents:
11904
diff
changeset
|
2993 |
words := StringCollection new. |
7797 | 2994 |
self asCollectionOfWordsDo:[:w | words add:w]. |
608 | 2995 |
^ words |
2996 |
||
2997 |
" |
|
2998 |
'hello world isnt this nice' asCollectionOfWords |
|
2999 |
' hello world isnt this nice ' asCollectionOfWords |
|
3000 |
'hello' asCollectionOfWords |
|
3001 |
'' asCollectionOfWords |
|
3002 |
' ' asCollectionOfWords |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
3003 |
' foo bar__baz__bla__ bar ' asCollectionOfWords |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
3004 |
' foo __bar__baz__bla__ bar ' asCollectionOfWords |
608 | 3005 |
" |
9192 | 3006 |
! |
3007 |
||
3008 |
asCollectionOfWordsDo:aBlock |
|
8874 | 3009 |
"evaluate aBlock for each word (separated by whitespace) of the receiver. |
3010 |
Multiple occurrences of whitespace characters will be treated like one |
|
7797 | 3011 |
- i.e. whitespace is skipped. |
3012 |
Returns the number of words (i.e. the number of invocations of aBlock)." |
|
3013 |
||
3014 |
|count "{ Class:SmallInteger }" |
|
8874 | 3015 |
start "{ Class:SmallInteger }" |
3016 |
stop "{ Class:SmallInteger }" |
|
7797 | 3017 |
mySize "{ Class:SmallInteger }"| |
3018 |
||
3019 |
count := 0. |
|
3020 |
start := 1. |
|
3021 |
mySize := self size. |
|
3022 |
[start <= mySize] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3023 |
start := self indexOfNonSeparatorStartingAt:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3024 |
start == 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3025 |
^ count |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3026 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3027 |
stop := self indexOfSeparatorStartingAt:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3028 |
stop == 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3029 |
aBlock value:(self copyFrom:start to:mySize). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3030 |
^ count + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3031 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3032 |
aBlock value:(self copyFrom:start to:(stop - 1)). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3033 |
start := stop. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3034 |
count := count + 1 |
7797 | 3035 |
]. |
3036 |
^ count |
|
3037 |
||
3038 |
" |
|
3039 |
'hello world isnt this nice' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3040 |
' hello world isnt this nice ' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3041 |
'hello' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3042 |
'' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3043 |
' ' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3044 |
" |
|
9192 | 3045 |
! |
3046 |
||
3047 |
asFilename |
|
3048 |
"return a Filename with pathname taken from the receiver" |
|
3049 |
||
3050 |
^ Filename named:self "(self asSingleByteStringReplaceInvalidWith:$?)" |
|
3051 |
||
3052 |
"Modified: 20.5.1996 / 09:38:15 / cg" |
|
3053 |
! |
|
608 | 3054 |
|
3060 | 3055 |
asFixedPoint |
3056 |
"read a fixedPoint number from the receiver. |
|
8874 | 3057 |
Notice, that errors may occur during the read, |
7423 | 3058 |
so you better setup some signal handler when using this method." |
3060 | 3059 |
|
3060 |
^ FixedPoint readFromString:self |
|
3061 |
||
3062 |
" |
|
8874 | 3063 |
'0.123' asFixedPoint |
3064 |
'12345' asFixedPoint |
|
3060 | 3065 |
'(1/5)' asFixedPoint |
3066 |
'foo' asFixedPoint |
|
9192 | 3067 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asFixedPoint] |
3068 |
" |
|
3069 |
||
3070 |
"Modified: / 25.10.1997 / 15:19:00 / cg" |
|
3071 |
! |
|
3072 |
||
3073 |
asFixedPoint:scale |
|
3060 | 3074 |
"read a fixedPoint number with scale number of post-decimal digits |
3075 |
from the receiver. Scale controls the number of displayed digits, |
|
3076 |
not the number of actually valid digits. |
|
8874 | 3077 |
Notice, that errors may occur during the read, |
7423 | 3078 |
so you better setup some signal handler when using this method." |
3060 | 3079 |
|
3080 |
^ (FixedPoint readFromString:self) scale:scale |
|
3081 |
||
3082 |
" |
|
8874 | 3083 |
'0.123' asFixedPoint:2 |
3084 |
'123456' asFixedPoint:2 |
|
3085 |
('3.14157' asFixedPoint:1) asFixedPoint:5 |
|
3086 |
'3.14157' asFixedPoint:2 |
|
3087 |
'foo' asFixedPoint:2 |
|
3060 | 3088 |
" |
3089 |
||
3090 |
"Modified: / 25.10.1997 / 15:21:57 / cg" |
|
9192 | 3091 |
! |
3092 |
||
3093 |
asFloat |
|
608 | 3094 |
"read a float number from the receiver. |
8874 | 3095 |
Notice, that errors may occur during the read, |
7422 | 3096 |
so you better setup some exception handler when using this method." |
608 | 3097 |
|
3098 |
^ (Number readFromString:self) asFloat |
|
3099 |
||
3100 |
" |
|
8874 | 3101 |
'0.123' asFloat |
608 | 3102 |
'12345' asFloat |
3103 |
'(1/5)' asFloat |
|
8874 | 3104 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asFloat] |
608 | 3105 |
" |
3106 |
! |
|
3107 |
||
3108 |
asInteger |
|
9190 | 3109 |
"convert the receiver into an integer. |
8874 | 3110 |
Notice, that errors may occur during the read, |
9190 | 3111 |
so you better setup some exception handler when using this method. |
3112 |
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
|
3113 |
in other smalltalks. |
9190 | 3114 |
For less strict integer reading, use Integer readFrom:aString" |
608 | 3115 |
|
3116 |
^ Integer readFromString:self |
|
3117 |
||
3118 |
" |
|
3119 |
'12345678901234567890' asInteger |
|
3120 |
'-1234' asInteger |
|
9190 | 3121 |
|
3122 |
The following raises an error: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3123 |
'0.123' asInteger <- reader finds more after reading 0 |
9190 | 3124 |
|
3125 |
whereas the less strict readFrom does not: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3126 |
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
|
3127 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
3128 |
'0.123' asInteger |
608 | 3129 |
'0.123' asNumber <- returns what you expect |
8874 | 3130 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asInteger] |
9190 | 3131 |
|
3132 |
" |
|
9192 | 3133 |
! |
3134 |
||
3135 |
asLowercase |
|
608 | 3136 |
"return a copy of myself in lowercase letters" |
3137 |
||
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3138 |
|newStr c bitsPerCharacter |
9192 | 3139 |
mySize "{ Class: SmallInteger }" | |
3140 |
||
3141 |
mySize := self size. |
|
3142 |
mySize == 0 ifTrue:[^ self]. |
|
18657 | 3143 |
|
9192 | 3144 |
newStr := self species new:mySize. |
3145 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
3146 |
||
18657 | 3147 |
"/ handle the very seldom case of an uppercase char which needs |
3148 |
"/ more bits in its lowercase variant |
|
3149 |
"/ (there are only a few of them) |
|
3150 |
||
9192 | 3151 |
1 to:mySize do:[:i | |
18657 | 3152 |
c := (self at:i) asLowercase. |
3153 |
(c bitsPerCharacter > bitsPerCharacter |
|
3154 |
and:[c stringSpecies ~= newStr stringSpecies]) ifTrue:[ |
|
3155 |
newStr := c stringSpecies fromString:newStr. |
|
18662 | 3156 |
bitsPerCharacter := newStr bitsPerCharacter. |
18657 | 3157 |
]. |
3158 |
newStr at:i put:c |
|
9192 | 3159 |
]. |
3160 |
^ newStr |
|
3161 |
||
3162 |
" |
|
3163 |
'HelloWorld' asLowercase |
|
18662 | 3164 |
'HelloWorld' asUnicode16String asLowercase |
9192 | 3165 |
'HelloWorld' asLowercaseFirst |
18657 | 3166 |
'HelloWorld' asUppercase |
9192 | 3167 |
" |
3168 |
! |
|
3169 |
||
3170 |
asLowercaseFirst |
|
17508 | 3171 |
"return a copy of myself where the first character is converted to lowercase. |
3172 |
If the first character is already lowercase, or there is no uppercase for it, return the |
|
3173 |
receiver." |
|
9192 | 3174 |
|
3175 |
|newString firstChar firstCharAsLowercase| |
|
3176 |
||
11525 | 3177 |
self isEmpty ifTrue:[^ self]. |
9192 | 3178 |
firstChar := (self at:1). |
3179 |
firstCharAsLowercase := firstChar asLowercase. |
|
3180 |
firstChar == firstCharAsLowercase ifTrue:[ ^ self]. |
|
3181 |
||
3182 |
firstCharAsLowercase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3183 |
newString := firstCharAsLowercase stringSpecies fromString:self. |
9192 | 3184 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3185 |
newString := self stringSpecies fromString:self. |
9192 | 3186 |
]. |
9190 | 3187 |
newString at:1 put:firstCharAsLowercase. |
3188 |
^ newString |
|
608 | 3189 |
|
3190 |
" |
|
8874 | 3191 |
'HelloWorld' asLowercase |
3192 |
'HelloWorld' asLowercaseFirst |
|
608 | 3193 |
" |
3194 |
! |
|
3195 |
||
11828 | 3196 |
asLowercaseLast |
3197 |
"return a copy of myself where the last character is |
|
3198 |
converted to lowercase." |
|
3199 |
||
3200 |
|newString sz| |
|
3201 |
||
3202 |
sz := self size. |
|
3203 |
newString := self copyFrom:1 to:sz. |
|
3204 |
sz > 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3205 |
newString at:sz put:(newString at:sz) asLowercase |
11828 | 3206 |
]. |
3207 |
^ newString |
|
3208 |
||
3209 |
" |
|
12177 | 3210 |
'HelloWorld' asLowercase |
3211 |
'HelloWorlD' asLowercaseLast |
|
11828 | 3212 |
" |
3213 |
! |
|
3214 |
||
17644 | 3215 |
asMutator |
3216 |
"return a corresponding setter method's selector" |
|
3217 |
||
3218 |
^ (self asOneByteString,':') asSymbol |
|
3219 |
! |
|
3220 |
||
9190 | 3221 |
asNumber |
3222 |
"read a number from the receiver. |
|
3223 |
Notice, that (in contrast to ST-80) errors may occur during the read, |
|
3224 |
so you better setup some signal handler when using this method. |
|
3225 |
Also notice, that this is meant to read end-user numbers from a string; |
|
9135 | 3226 |
it does not handle smalltalk numbers (i.e. radix). |
3227 |
To read a smalltalk number, use Number >> readSmalltalkFrom:. |
|
608 | 3228 |
This may change if ANSI specifies it." |
3229 |
||
3230 |
"/ ST-80 behavior: |
|
3231 |
"/ ^ Number readFromString:self onError:0 |
|
3232 |
||
17061 | 3233 |
^ Number fromString:self |
3234 |
||
3235 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3236 |
'123' asNumber |
608 | 3237 |
'123.567' asNumber |
3238 |
'(5/6)' asNumber |
|
3239 |
'foo' asNumber |
|
17061 | 3240 |
'123a' asNumber |
8874 | 3241 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] |
608 | 3242 |
" |
9192 | 3243 |
! |
3244 |
||
3245 |
asNumberFromFormatString:ignored |
|
608 | 3246 |
"read a number from the receiver, ignoring any nonDigit characters. |
3247 |
This is typically used to convert from strings which include |
|
3248 |
dollar-signs or millenium digits. However, this method also ignores |
|
3249 |
the decimal point (if any) and therefore should be used with care." |
|
3250 |
||
3251 |
|tempString| |
|
3252 |
||
3253 |
tempString := self collect:[:char | char isDigit]. |
|
3254 |
^ Number readFromString:tempString onError:0 |
|
3255 |
||
3256 |
" |
|
3257 |
'USD 123' asNumberFromFormatString:'foo' |
|
3258 |
'DM 123' asNumberFromFormatString:'foo' |
|
3259 |
'123' asNumberFromFormatString:'foo' |
|
3260 |
'123.567' asNumberFromFormatString:'foo' |
|
3261 |
'(5/6)' asNumberFromFormatString:'foo' |
|
3262 |
'foo' asNumberFromFormatString:'foo' |
|
3263 |
" |
|
9192 | 3264 |
! |
3265 |
||
7977 | 3266 |
asSingleByteStringIfPossible |
3267 |
"if possible, return the receiver converted to a 'normal' string. |
|
18181 | 3268 |
It is only possible, if there are no characters with codePoints above 255 in the receiver. |
3269 |
If not possible, the (wideString) receiver is returned." |
|
7977 | 3270 |
|
14555 | 3271 |
self isWideString ifFalse:[^ self]. |
8102
e0537422e2d3
Use the ANSI-blessed #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8083
diff
changeset
|
3272 |
(self contains:[:char | char codePoint > 255]) ifFalse:[^ self asSingleByteString]. |
9192 | 3273 |
^ self |
3274 |
||
3275 |
" |
|
3276 |
'hello' asSingleByteStringIfPossible |
|
3277 |
'hello' asUnicodeString asSingleByteStringIfPossible |
|
3278 |
" |
|
3279 |
! |
|
3280 |
||
3281 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
|
3282 |
"return the receiver converted to a 'normal' string, |
|
3283 |
with invalid characters replaced by replacementCharacter. |
|
3284 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
3285 |
and replace characters above code-255 with some replacement." |
|
3286 |
||
3287 |
|newString| |
|
3288 |
||
3289 |
newString := String new:(self size). |
|
3290 |
1 to:self size do:[:idx | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3291 |
|char| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3292 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3293 |
char := self at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3294 |
char codePoint <= 16rFF ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3295 |
newString at:idx put:char |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3296 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3297 |
newString at:idx put:replacementCharacter |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3298 |
]. |
9190 | 3299 |
]. |
3300 |
^ newString |
|
3301 |
||
3302 |
"Created: 30.6.1997 / 13:02:14 / cg" |
|
7977 | 3303 |
! |
3304 |
||
9192 | 3305 |
asString |
3306 |
"return myself - I am a string" |
|
3307 |
||
3308 |
^ self |
|
3309 |
! |
|
3310 |
||
3311 |
asStringCollection |
|
3312 |
"return a collection of lines from myself." |
|
3313 |
||
3314 |
^ StringCollection fromString:self "string" |
|
3315 |
||
3316 |
"Modified: 13.5.1996 / 20:36:59 / cg" |
|
3317 |
! |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3318 |
|
1434 | 3319 |
asSymbol |
9230 | 3320 |
"Return a unique symbol with the name taken from the receivers characters. |
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3321 |
The receiver must be a singleByte-String. |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3322 |
TwoByte- and FourByteSymbols are (currently ?) not allowed." |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3323 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3324 |
|str| |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3325 |
|
9192 | 3326 |
str := self string. |
3327 |
str ~~ self ifTrue:[ ^ str asSymbol ]. |
|
3328 |
^ self asSingleByteString asSymbol |
|
3329 |
! |
|
3330 |
||
3331 |
asSymbolIfInterned |
|
17183 | 3332 |
"If a symbol with the receiver's characters is already known, return it. Otherwise, return nil. |
9230 | 3333 |
This can be used to query for an existing symbol and is the same as: |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3334 |
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
|
3335 |
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
|
3336 |
The receiver must be a singleByte-String. |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3337 |
TwoByte- and FourByteSymbols are (currently ?) not allowed." |
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3338 |
|
6642 | 3339 |
|s| |
3340 |
||
3341 |
||
3342 |
s := self string. |
|
3343 |
s ~~ self ifTrue:[ |
|
3344 |
^ s asSymbolIfInterned |
|
3345 |
]. |
|
3346 |
^ nil. |
|
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3347 |
|
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3348 |
"Created: 22.5.1996 / 16:37:04 / cg" |
9192 | 3349 |
! |
3350 |
||
3351 |
asText |
|
9403 | 3352 |
"return a Text-object (string with emphasis) from myself." |
9192 | 3353 |
|
3354 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
3355 |
Text isNil ifTrue:[^ self]. |
|
17065 | 3356 |
^ Text string:self |
9192 | 3357 |
|
3358 |
"Created: 12.5.1996 / 10:41:14 / cg" |
|
3359 |
! |
|
3360 |
||
17021 | 3361 |
asTimestamp |
3362 |
"convert the receiver into an Timestamp. |
|
3363 |
Notice, that errors may occur during the read, |
|
3364 |
so you better setup some exception handler when using this method." |
|
3365 |
||
3366 |
^ Timestamp readFromString:self |
|
3367 |
||
3368 |
" |
|
3369 |
'2014-11-10 21:30:22.444' asTimestamp |
|
3370 |
'2014-11-10 21:30:22.444Z' asTimestamp |
|
3371 |
'2014-11-10 21:30:22.444+0200' asTimestamp |
|
3372 |
" |
|
3373 |
! |
|
3374 |
||
9192 | 3375 |
asTitlecase |
8027 | 3376 |
"return a version of the receiver, where the first character is converted to titlecase, |
3377 |
and everything else to lowercase. |
|
3378 |
See the comment in Character on what titlecase is." |
|
3379 |
||
3380 |
|newStr c bitsPerCharacter |
|
3381 |
mySize "{ Class: SmallInteger }" | |
|
3382 |
||
3383 |
mySize := self size. |
|
3384 |
newStr := self species new:mySize. |
|
3385 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
3386 |
||
3387 |
1 to:mySize do:[:i | |
|
18662 | 3388 |
i == 1 ifTrue:[ |
3389 |
c := (self at:i) asTitlecase. |
|
3390 |
] ifFalse:[ |
|
3391 |
c := (self at:i) asLowercase. |
|
3392 |
]. |
|
3393 |
c bitsPerCharacter > bitsPerCharacter ifTrue:[ |
|
3394 |
newStr := c stringSpecies fromString:newStr. |
|
3395 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
3396 |
]. |
|
3397 |
newStr at:i put:c |
|
8027 | 3398 |
]. |
3399 |
^ newStr |
|
3400 |
||
3401 |
" |
|
8874 | 3402 |
'helloWorld' asTitlecase |
3403 |
'HelloWorld' asTitlecase |
|
3404 |
'HELLOWORLD' asTitlecase |
|
3405 |
'helloworld' asTitlecase |
|
8027 | 3406 |
" |
9192 | 3407 |
! |
3408 |
||
3409 |
asTitlecaseFirst |
|
8023 | 3410 |
"return a version of the receiver, where the first character is converted to titlecase. |
8024 | 3411 |
Titlecase is much like uppercase for most characters, with the exception of some combined |
3412 |
(2-character glyphs), which consist of an upper- and lower-case characters. |
|
3413 |
If the first character is already titlecase, or there is no titlecasepercase for it, return the |
|
8023 | 3414 |
receiver." |
3415 |
||
8026 | 3416 |
" |
8874 | 3417 |
For example, in Unicode, character U+01F3 is LATIN SMALL LETTER DZ. |
3418 |
(Let us write this compound character using ASCII as 'dz'.) |
|
3419 |
This character uppercases to character U+01F1, LATIN CAPITAL LETTER DZ. |
|
3420 |
(Which is basically 'DZ'.) |
|
3421 |
But it titlecases to to character U+01F2, LATIN CAPITAL LETTER D WITH SMALL LETTER Z. |
|
8026 | 3422 |
(Which we can write 'Dz'.) |
3423 |
||
3424 |
character uppercase titlecase |
|
3425 |
--------- --------- --------- |
|
3426 |
dz DZ Dz |
|
3427 |
" |
|
3428 |
||
8023 | 3429 |
|newString firstChar firstCharAsTitlecase| |
3430 |
||
3431 |
firstChar := (self at:1). |
|
8025 | 3432 |
firstCharAsTitlecase := firstChar asTitlecase. |
8023 | 3433 |
firstChar == firstCharAsTitlecase ifTrue:[ ^ self]. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3434 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3435 |
firstCharAsTitlecase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3436 |
newString := firstCharAsTitlecase stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3437 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3438 |
newString := self stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3439 |
]. |
8023 | 3440 |
newString at:1 put:firstCharAsTitlecase. |
3441 |
^ newString |
|
3442 |
||
3443 |
" |
|
8874 | 3444 |
'helloWorld' asTitlecaseFirst |
3445 |
'HelloWorld' asTitlecaseFirst |
|
8023 | 3446 |
" |
9192 | 3447 |
! |
3448 |
||
3449 |
asTwoByteString |
|
3450 |
"return the receiver converted to a two-byte string. |
|
16051 | 3451 |
Will be obsolete soon - use asUnicode16String." |
9192 | 3452 |
|
3453 |
^ TwoByteString fromString:self |
|
3454 |
! |
|
3455 |
||
3456 |
asURI |
|
3457 |
"return an URI with string taken from the receiver" |
|
3458 |
||
3459 |
^ URI fromString:self |
|
3460 |
! |
|
8710 | 3461 |
|
5776 | 3462 |
asURL |
3463 |
"return an URL-object from myself." |
|
3464 |
||
3465 |
^ URL fromString:self |
|
3466 |
||
3467 |
" |
|
8874 | 3468 |
'http://www.exept.de:80/index.html' asURL host |
3469 |
'http://www.exept.de:80/index.html' asURL port |
|
9192 | 3470 |
'http://www.exept.de:80/index.html' asURL method |
3471 |
'http://www.exept.de:80/index.html' asURL path |
|
3472 |
" |
|
3473 |
! |
|
3474 |
||
3475 |
asUnicode16String |
|
15035 | 3476 |
"return the receiver in a two-byte per character representation. |
3477 |
Normally, the internal ST/X representation should be transparent and not |
|
3478 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3479 |
such as wide-string ffi calls or file contents." |
|
3480 |
||
17600 | 3481 |
|sz| |
3482 |
||
3483 |
sz := self size. |
|
3484 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3485 |
^ (Unicode16String new:sz) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3486 |
replaceFrom:1 to:sz with:self startingAt:1; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3487 |
yourself. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3488 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3489 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3490 |
'abc' asUnicode16String |
17600 | 3491 |
" |
3492 |
! |
|
3493 |
||
3494 |
asUnicode16StringZ |
|
3495 |
"return the receiver in a two-byte per character representation. |
|
17625 | 3496 |
Make sure that is zero terminated (last char is 16r0000). |
17600 | 3497 |
Normally, the internal ST/X representation should be transparent and not |
3498 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3499 |
such as wide-string ffi calls or file contents." |
|
3500 |
||
3501 |
|sz| |
|
3502 |
||
3503 |
sz := self size. |
|
3504 |
(self at:sz) == (Character codePoint:0) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3505 |
^ self asUnicode16String. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3506 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3507 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3508 |
^ (Unicode16String new:sz+1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3509 |
replaceFrom:1 to:sz with:self startingAt:1; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3510 |
at:sz+1 put:(Character codePoint:0); |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3511 |
yourself. |
17600 | 3512 |
|
3513 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3514 |
'abc' asUnicode16StringZ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3515 |
'abc' asUnicode16String asUnicode16StringZ |
17600 | 3516 |
" |
9192 | 3517 |
! |
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3518 |
|
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3519 |
asUnicode32String |
16051 | 3520 |
"return the receiver in a four-byte per character representation. |
3521 |
Normally, the internal ST/X representation should be transparent and not |
|
3522 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3523 |
such as wide-string ffi calls or file contents." |
|
3524 |
||
3525 |
^ self as:Unicode32String |
|
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3526 |
! |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3527 |
|
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3528 |
asUnicodeString |
16051 | 3529 |
"return the receiver in a two-byte per character representation. |
3530 |
Normally, the internal ST/X representation should be transparent and not |
|
3531 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3532 |
such as wide-string ffi calls or file contents." |
|
3533 |
||
3534 |
^ self asUnicode16String |
|
3535 |
" |
|
3536 |
'Hello World' asUnicodeString |
|
14141
e86d245213b0
comment/format in: #asUnicodeString
Stefan Vogel <sv@exept.de>
parents:
14137
diff
changeset
|
3537 |
" |
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3538 |
! |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3539 |
|
13073 | 3540 |
asUnixFilename |
3541 |
"return a UnixFilename with pathname taken from the receiver" |
|
3542 |
||
3543 |
^ UnixFilename named:self |
|
3544 |
||
3545 |
"Created: / 20-09-2010 / 21:42:55 / cg" |
|
3546 |
! |
|
3547 |
||
608 | 3548 |
asUppercase |
3549 |
"return a copy of myself in uppercase letters" |
|
3550 |
||
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3551 |
|newStr c bitsPerCharacter |
608 | 3552 |
mySize "{ Class: SmallInteger }" | |
3553 |
||
3554 |
mySize := self size. |
|
8954
12e701d7b5ac
allow for receiver to be empty in asLowercase and asUppercase.
Claus Gittinger <cg@exept.de>
parents:
8938
diff
changeset
|
3555 |
mySize == 0 ifTrue:[^ self]. |
608 | 3556 |
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
|
3557 |
bitsPerCharacter := newStr bitsPerCharacter. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3558 |
|
18657 | 3559 |
"/ handle the very seldom case of a lowercase char which needs |
3560 |
"/ more bits in its uppercase variant |
|
3561 |
"/ (there are only a few of them) |
|
3562 |
||
608 | 3563 |
1 to:mySize do:[:i | |
18657 | 3564 |
c := (self at:i) asUppercase. |
3565 |
c bitsPerCharacter > bitsPerCharacter ifTrue:[ |
|
3566 |
newStr := c stringSpecies fromString:newStr. |
|
18662 | 3567 |
bitsPerCharacter := newStr bitsPerCharacter. |
18657 | 3568 |
]. |
3569 |
newStr at:i put:c |
|
608 | 3570 |
]. |
3571 |
^ newStr |
|
3572 |
||
3573 |
" |
|
8874 | 3574 |
'helloWorld' asUppercase |
3575 |
'helloWorld' asUppercaseFirst |
|
9192 | 3576 |
(Character value:16rB5) asString asUppercase -- needs 16 bits !! |
18657 | 3577 |
(Character value:16rFF) asString asUppercase -- needs 16 bits !! |
9192 | 3578 |
" |
3579 |
! |
|
3580 |
||
3581 |
asUppercaseFirst |
|
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3582 |
"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
|
3583 |
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
|
3584 |
receiver." |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3585 |
|
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3586 |
|newString firstChar firstCharAsUppercase| |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3587 |
|
12679 | 3588 |
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
|
3589 |
firstChar := self at:1. |
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3590 |
firstCharAsUppercase := firstChar asUppercase. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3591 |
firstChar == firstCharAsUppercase ifTrue:[ ^ self]. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3592 |
|
12679 | 3593 |
"/ 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
|
3594 |
firstCharAsUppercase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3595 |
newString := firstCharAsUppercase stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3596 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3597 |
newString := self stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3598 |
]. |
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3599 |
newString at:1 put:firstCharAsUppercase. |
608 | 3600 |
^ newString |
3601 |
||
3602 |
" |
|
8874 | 3603 |
'helloWorld' asUppercase |
3604 |
'helloWorld' asUppercaseFirst |
|
3605 |
'HelloWorld' asUppercaseFirst |
|
608 | 3606 |
" |
9192 | 3607 |
! |
3608 |
||
11828 | 3609 |
asUppercaseLast |
3610 |
"return a copy of myself where the last character is |
|
3611 |
converted to uppercase." |
|
3612 |
||
3613 |
|newString sz| |
|
3614 |
||
3615 |
sz := self size. |
|
3616 |
newString := self copyFrom:1 to:sz. |
|
3617 |
sz > 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3618 |
newString at:sz put:(newString at:sz) asUppercase |
11828 | 3619 |
]. |
3620 |
^ newString |
|
3621 |
||
3622 |
" |
|
12177 | 3623 |
'HelloWorld' asUppercase |
3624 |
'HelloWorld' asUppercaseLast |
|
11828 | 3625 |
" |
3626 |
! |
|
3627 |
||
17021 | 3628 |
asUtcTimestamp |
3629 |
"convert the receiver into an UtcTimestamp (Time is interpreted in the UTC timezone). |
|
3630 |
Notice, that errors may occur during the read, |
|
3631 |
so you better setup some exception handler when using this method." |
|
3632 |
||
3633 |
^ UtcTimestamp readFromString:self |
|
3634 |
||
3635 |
" |
|
3636 |
'2014-11-10 21:30:22.444' asUtcTimestamp |
|
3637 |
" |
|
3638 |
! |
|
3639 |
||
11062 | 3640 |
literalArrayEncoding |
3641 |
"encode myself as an array literal, from which a copy of the receiver |
|
3642 |
can be reconstructed with #decodeAsLiteralArray." |
|
3643 |
||
3644 |
^ self |
|
3645 |
||
3646 |
"Modified: 1.9.1995 / 02:25:45 / claus" |
|
3647 |
"Modified: 22.4.1996 / 13:00:50 / cg" |
|
3648 |
! |
|
3649 |
||
9192 | 3650 |
string |
3651 |
"return the receiver - for ST-80 compatibility" |
|
3652 |
||
3653 |
^ self |
|
3654 |
||
3655 |
"Modified: 27.4.1996 / 13:29:30 / cg" |
|
3656 |
! ! |
|
3657 |
||
3658 |
!CharacterArray methodsFor:'copying'! |
|
3659 |
||
3660 |
, aStringOrCharacter |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3661 |
"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
|
3662 |
This is nonStandard, but convenient" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3663 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3664 |
|myWidth otherWidth| |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3665 |
|
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3666 |
aStringOrCharacter isCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3667 |
^ self copyWith:aStringOrCharacter |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3668 |
]. |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3669 |
aStringOrCharacter isText ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3670 |
^ aStringOrCharacter concatenateFromString:self |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3671 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3672 |
aStringOrCharacter isString ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3673 |
(otherWidth := aStringOrCharacter bitsPerCharacter) ~~ (myWidth := self bitsPerCharacter) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3674 |
otherWidth > myWidth ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3675 |
^ (aStringOrCharacter species fromString:self) , aStringOrCharacter |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3676 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3677 |
^ self , (self species fromString:aStringOrCharacter) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3678 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3679 |
]. |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3680 |
^ super , aStringOrCharacter |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3681 |
|
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3682 |
" |
8874 | 3683 |
'hello' , $1 |
3684 |
'hello' , '1' |
|
3685 |
'hello' , (' world' asText allBold) |
|
3686 |
'hello' , (JISEncodedString fromString:' world') |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3687 |
(JISEncodedString fromString:'hello') , ' world' |
1411 | 3688 |
|
1422 | 3689 |
Transcript showCR: |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3690 |
(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
|
3691 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3692 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3693 |
"Modified: 28.6.1997 / 00:13:17 / cg" |
9192 | 3694 |
! |
3695 |
||
3696 |
,, aString |
|
7020 | 3697 |
"concatenate with a newLine in between" |
6965 | 3698 |
|
3699 |
^ (self copyWith:Character cr) , aString |
|
3700 |
||
3701 |
" |
|
3702 |
hello ,, world |
|
7020 | 3703 |
'hello' ,, 'world' |
6965 | 3704 |
" |
3705 |
! |
|
3706 |
||
11329 | 3707 |
chopTo:maxLen |
3708 |
"if the receivers size is less or equal to maxLen, return it. |
|
3709 |
Otherwise, return a copy of the receiver, where some characters |
|
3710 |
in the middle have been removed for a total string length |
|
3711 |
of maxLen." |
|
3712 |
||
3713 |
|sz n1 n2| |
|
3714 |
||
3715 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3716 |
||
3717 |
n1 := n2 := maxLen // 2. |
|
3718 |
maxLen odd ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3719 |
n2 := n1 + 1 |
11329 | 3720 |
]. |
3721 |
^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1) |
|
3722 |
||
3723 |
" |
|
3724 |
'12345678901234' chopTo:15 |
|
3725 |
'123456789012345' chopTo:15 |
|
3726 |
'1234567890123456' chopTo:15 |
|
3727 |
'aShortString' chopTo:15 |
|
3728 |
'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 |
|
3729 |
" |
|
3730 |
||
3731 |
"Modified: / 24-10-2006 / 12:32:01 / cg" |
|
3732 |
! |
|
3733 |
||
608 | 3734 |
concatenate:string1 and:string2 |
3735 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
3736 |
This is equivalent to self , string1 , string2 |
|
3737 |
- generated by compiler when such a construct is detected and the receiver |
|
3738 |
is known to be a string." |
|
3739 |
||
3740 |
^ self , string1 , string2 |
|
3741 |
! |
|
3742 |
||
3743 |
concatenate:string1 and:string2 and:string3 |
|
3744 |
"return the concatenation of myself and the string arguments. |
|
3745 |
This is equivalent to self , string1 , string2 , string3 |
|
3746 |
- generated by compiler when such a construct is detected and the receiver |
|
3747 |
is known to be a string." |
|
3748 |
||
3749 |
^ self , string1 , string2 , string3 |
|
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3750 |
! |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3751 |
|
11329 | 3752 |
contractAtBeginningTo:maxLen |
3753 |
"if the receivers size is less or equal to maxLen, return it. |
|
3754 |
Otherwise, return a copy of the receiver, where some characters |
|
3755 |
at the beginning have been replaced by '...' for a total string length |
|
3756 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
3757 |
||
3758 |
|sz| |
|
3759 |
||
3760 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3761 |
||
3762 |
^ '...' , (self copyFrom:(sz - (maxLen - 4))) |
|
3763 |
||
3764 |
" |
|
3765 |
'12345678901234' contractAtBeginningTo:15 |
|
3766 |
'123456789012345' contractAtBeginningTo:15 |
|
3767 |
'1234567890123456' contractAtBeginningTo:15 |
|
3768 |
'aShortString' contractAtBeginningTo:15 |
|
3769 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15 |
|
3770 |
" |
|
3771 |
||
3772 |
"Modified: / 24-10-2006 / 12:32:13 / cg" |
|
3773 |
! |
|
3774 |
||
3775 |
contractAtEndTo:maxLen |
|
3776 |
"if the receivers size is less or equal to maxLen, return it. |
|
3777 |
Otherwise, return a copy of the receiver, where some characters |
|
3778 |
at the end have been replaced by '...' for a total string length |
|
3779 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
3780 |
||
3781 |
|sz| |
|
3782 |
||
3783 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3784 |
||
3785 |
^ (self copyTo:maxLen-3),'...' |
|
3786 |
||
3787 |
" |
|
3788 |
'12345678901234' contractAtEndTo:15 |
|
3789 |
'123456789012345' contractAtEndTo:15 |
|
3790 |
'1234567890123456' contractAtEndTo:15 |
|
3791 |
'aShortString' contractAtEndTo:15 |
|
3792 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 |
|
3793 |
" |
|
3794 |
||
3795 |
"Modified: / 24-10-2006 / 12:32:26 / cg" |
|
3796 |
! |
|
3797 |
||
3798 |
contractLeftTo:maxLen |
|
3799 |
"if the receivers size is less or equal to maxLen, return it. |
|
3800 |
Otherwise, return a copy of the receiver, where some characters |
|
3801 |
near the first quarter have been replaced by '...' for a total string length |
|
12177 | 3802 |
of maxLen. |
3803 |
Very similar to contractTo:, but better to abbreviate long filename entries, |
|
11329 | 3804 |
where the right part is of more use than the left." |
3805 |
||
3806 |
|sz "{ SmallInteger }" |
|
3807 |
halfSize quarterSize "{ SmallInteger }" |
|
3808 |
leftEnd rightEnd rightStart| |
|
3809 |
||
3810 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3811 |
||
3812 |
halfSize := maxLen // 2. |
|
3813 |
quarterSize := maxLen // 4. |
|
3814 |
leftEnd := quarterSize-1. |
|
3815 |
rightEnd := maxLen - leftEnd - 3. |
|
3816 |
rightStart := sz - rightEnd + 1. |
|
3817 |
^ (self copyTo:leftEnd),'...',(self copyFrom:rightStart) |
|
3818 |
||
3819 |
" |
|
12177 | 3820 |
'12345678901234' contractLeftTo:15 |
3821 |
'123456789012345' contractLeftTo:15 |
|
3822 |
'1234567890123456' contractLeftTo:15 |
|
3823 |
'aShortString' contractLeftTo:15 |
|
3824 |
'aVeryLongNameForAStringThatShouldBeShortened' contractLeftTo:15 |
|
11329 | 3825 |
'C:\Dokumente und Einstellungen\cg\work\bosch\dapas\hw_schnittstellen\DAPAS__HpibDLL.st' contractLeftTo:40 |
3826 |
" |
|
3827 |
! |
|
3828 |
||
3829 |
contractTo:maxLen |
|
3830 |
"if the receivers size is less or equal to maxLen, return it. |
|
3831 |
Otherwise, return a copy of the receiver, where some characters |
|
3832 |
in the middle have been replaced by '...' for a total string length |
|
3833 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
3834 |
||
13362 | 3835 |
|sz "{ SmallInteger }" leftSize rightSize| |
11329 | 3836 |
|
3837 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3838 |
||
13362 | 3839 |
rightSize := maxLen // 2. |
3840 |
leftSize := maxLen - rightSize. |
|
13822 | 3841 |
leftSize := leftSize - 2. |
3842 |
rightSize := rightSize - 1. |
|
13362 | 3843 |
^ (self copyTo:leftSize),'...',(self copyFrom:(sz+1-rightSize)) |
3844 |
||
3845 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3846 |
'12345678901234' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3847 |
'123456789012345' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3848 |
'1234567890123456' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3849 |
'12345678901234567' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3850 |
'123456789012345678' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3851 |
'aShortString' contractTo:15 |
11329 | 3852 |
'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 |
3853 |
'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
|
3854 |
('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
|
3855 |
('1234567890123456789012345678901234567' contractTo:29) size |
13362 | 3856 |
" |
3857 |
||
13822 | 3858 |
"Modified (comment): / 24-11-2011 / 19:17:46 / cg" |
11329 | 3859 |
! |
3860 |
||
16202 | 3861 |
copyReplaceAll:oldElement with:newElement |
3862 |
"return a copy of the receiver as a string, where all elements equal to oldElement |
|
3863 |
have been replaced by newElement." |
|
3864 |
||
3865 |
"/ ANSI seems to allow a sequence to be replaced by another sequence, |
|
3866 |
"/ whereas the old ST80 meant replace all occurrences... - sigh. |
|
3867 |
oldElement isByteCollection ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3868 |
newElement isByteCollection ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3869 |
^ self copyReplaceString:oldElement withString:newElement. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3870 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3871 |
self halt:'check if this is legal'. |
16202 | 3872 |
]. |
3873 |
newElement isByteCollection ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3874 |
self halt:'check if this is legal'. |
16202 | 3875 |
]. |
16212 | 3876 |
^ super copyReplaceAll:oldElement with:newElement |
16202 | 3877 |
! |
3878 |
||
8347 | 3879 |
copyReplaceString:subString withString:newString |
3880 |
"return a copy of the receiver, with all sequences of subString replaced |
|
3881 |
by newString (i.e. slice in the newString in place of the oldString)." |
|
3882 |
||
3883 |
|tmpStream idx idx1| |
|
3884 |
||
15523 | 3885 |
tmpStream := self species writeStream. |
8347 | 3886 |
idx := 1. |
3887 |
[idx ~~ 0] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3888 |
idx1 := idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3889 |
idx := self indexOfSubCollection:subString startingAt:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3890 |
idx ~~ 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3891 |
tmpStream nextPutAll:(self copyFrom:idx1 to:idx-1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3892 |
tmpStream nextPutAll:newString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3893 |
idx := idx + subString size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3894 |
] |
8347 | 3895 |
]. |
3896 |
tmpStream nextPutAll:(self copyFrom:idx1). |
|
3897 |
^ tmpStream contents |
|
3898 |
||
3899 |
" |
|
9306 | 3900 |
'12345678901234567890' copyReplaceString:'123' withString:'OneTwoThree' |
3901 |
'12345678901234567890' copyReplaceString:'123' withString:'*' |
|
3902 |
'12345678901234567890' copyReplaceString:'234' withString:'foo' |
|
3903 |
||
3904 |
('a string with spaces' copyReplaceAll:$ withAll:' foo ') |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3905 |
copyReplaceString:'foo' withString:'bar' |
8347 | 3906 |
" |
3907 |
||
3908 |
"Modified: / 31-05-1999 / 12:33:59 / cg" |
|
3909 |
"Created: / 12-05-2004 / 12:00:00 / cg" |
|
3910 |
! |
|
3911 |
||
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3912 |
copyWith:aCharacter |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3913 |
"return a new string containing the receivers characters |
8874 | 3914 |
and the single new character, aCharacter. |
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3915 |
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
|
3916 |
as argument, but equivalent to copy-and-addLast. |
8874 | 3917 |
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
|
3918 |
(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
|
3919 |
|
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3920 |
|sz newString| |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3921 |
|
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3922 |
aCharacter bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3923 |
sz := self size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3924 |
newString := aCharacter stringSpecies new:sz + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3925 |
newString replaceFrom:1 to:sz with:self startingAt:1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3926 |
newString at:sz+1 put:aCharacter. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3927 |
^ newString. |
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3928 |
]. |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3929 |
^ super copyWith:aCharacter |
17241 | 3930 |
! |
3931 |
||
3932 |
restAfter:keyword withoutSeparators:strip |
|
3933 |
"compare the left of the receiver with keyword, |
|
3934 |
if it matches return the right. |
|
3935 |
Finally, if strip is true, remove whiteSpace. |
|
3936 |
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
|
3937 |
something: rest |
17241 | 3938 |
where we are interested in rest, but only if the receiver string |
3939 |
begins with something. |
|
3940 |
||
3941 |
You may wonder why such a specialized method exists here |
|
3942 |
- this is so common when processing mailboxes, |
|
3943 |
rcs files, nntp/pop3 responses, that is was considered worth |
|
3944 |
a special method here to avoid having the code below a hundred |
|
3945 |
times in variuos places." |
|
3946 |
||
3947 |
|rest| |
|
3948 |
||
3949 |
(self startsWith:keyword) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3950 |
rest := self copyFrom:(keyword size + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3951 |
strip ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3952 |
rest := rest withoutSeparators |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3953 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3954 |
^ rest |
17241 | 3955 |
]. |
3956 |
^ nil |
|
3957 |
||
3958 |
" |
|
3959 |
'foo: hello world' restAfter:'foo:' withoutSeparators:true |
|
3960 |
'funny: something' restAfter:'foo:' withoutSeparators:true |
|
3961 |
||
3962 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:true |
|
3963 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:false |
|
3964 |
" |
|
3965 |
||
3966 |
"Created: 25.11.1995 / 11:04:18 / cg" |
|
3967 |
! |
|
3968 |
||
3969 |
splitAtString:subString withoutSeparators:strip |
|
3970 |
"If the receiver is of the form: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3971 |
<left><subString><right> |
17241 | 3972 |
return a collection containing left and right only. |
3973 |
If strip is true, remove whiteSpace in the returned substrings." |
|
3974 |
||
3975 |
|idx left right| |
|
3976 |
||
3977 |
(idx := self indexOfSubCollection:subString) ~~ 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3978 |
left := self copyTo:(idx - 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3979 |
right := self copyFrom:(idx + subString size). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3980 |
strip ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3981 |
left := left withoutSeparators. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3982 |
right := right withoutSeparators. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3983 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3984 |
^ StringCollection with:left with:right |
17241 | 3985 |
]. |
3986 |
self error:'substring not present in receiver' mayProceed:true. |
|
3987 |
^ self |
|
3988 |
||
3989 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3990 |
'hello -> world' splitAtString:'->' withoutSeparators:false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3991 |
'hello -> world' splitAtString:'->' withoutSeparators:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3992 |
'hello -> ' splitAtString:'->' withoutSeparators:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3993 |
'hello > error' splitAtString:'->' withoutSeparators:true |
17241 | 3994 |
" |
3995 |
||
3996 |
"Created: 25.11.1995 / 11:04:18 / cg" |
|
608 | 3997 |
! ! |
3998 |
||
3999 |
!CharacterArray methodsFor:'displaying'! |
|
4000 |
||
2762 | 4001 |
displayOn:aGC x:x y:y from:start to:stop |
4002 |
"display the receiver on a GC" |
|
4003 |
||
12171 | 4004 |
self displayOn:aGC x:x y:y from:start to:stop opaque:false |
4005 |
||
4006 |
"Modified: 12.5.1996 / 12:49:33 / cg" |
|
4007 |
! |
|
4008 |
||
4009 |
displayOn:aGC x:x y:y from:start to:stop opaque:opaque |
|
4010 |
"display the receiver on a GC" |
|
4011 |
||
2762 | 4012 |
"q&d hack" |
4013 |
||
12177 | 4014 |
(start == 1 and:[stop == self size]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4015 |
self displayOn:aGC x:x y:y opaque:opaque. |
12177 | 4016 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4017 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:opaque. |
12177 | 4018 |
]. |
2762 | 4019 |
! |
4020 |
||
7082 | 4021 |
displayOn:aGc x:x y:y opaque:opaque |
2762 | 4022 |
"display the receiver in a graphicsContext - this method allows |
4023 |
strings to be used like DisplayObjects." |
|
4024 |
||
4025 |
|s| |
|
4026 |
||
4027 |
s := self string. |
|
7082 | 4028 |
opaque ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4029 |
aGc displayOpaqueString:s x:x y:y. |
2762 | 4030 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4031 |
aGc displayString:s x:x y:y. |
2762 | 4032 |
]. |
1381 | 4033 |
|
4034 |
"Modified: 11.5.1996 / 14:42:48 / cg" |
|
4035 |
! |
|
4036 |
||
2762 | 4037 |
displayOpaqueOn:aGC x:x y:y from:start to:stop |
4038 |
"display the receiver on a GC" |
|
4039 |
||
12171 | 4040 |
self displayOn:aGC x:x y:y from:start to:stop opaque:true |
608 | 4041 |
! ! |
4042 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4043 |
!CharacterArray methodsFor:'emphasis'! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4044 |
|
11632
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4045 |
actionForAll:aBlock |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4046 |
"change the action block of all characters. |
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4047 |
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
|
4048 |
|
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4049 |
^ self asText actionForAll:aBlock |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4050 |
! |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4051 |
|
5732 | 4052 |
allBold |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4053 |
"return a text object representing the receiver, but all boldified" |
5732 | 4054 |
|
8874 | 4055 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
6187 | 4056 |
Text isNil ifTrue:[^ self]. |
5732 | 4057 |
^ self asText allBold |
4058 |
||
4059 |
" |
|
4060 |
Transcript showCR:'hello' asText allBold |
|
4061 |
Transcript showCR:'hello' allBold |
|
4062 |
" |
|
4063 |
! |
|
4064 |
||
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4065 |
allItalic |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4066 |
"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
|
4067 |
|
8874 | 4068 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
6187 | 4069 |
Text isNil ifTrue:[^ self]. |
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4070 |
^ self asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4071 |
|
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4072 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4073 |
Transcript showCR:'hello' asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4074 |
Transcript showCR:'hello' allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4075 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4076 |
! |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4077 |
|
11345 | 4078 |
allStrikedOut |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4079 |
"return a text object representing the receiver, but all in strikeout" |
11345 | 4080 |
|
4081 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
4082 |
Text isNil ifTrue:[^ self]. |
|
4083 |
^ self asText allStrikedOut |
|
4084 |
||
4085 |
" |
|
4086 |
Transcript showCR:'hello' asText allStrikedOut |
|
4087 |
Transcript showCR:'hello' allStrikedOut |
|
4088 |
" |
|
4089 |
! |
|
4090 |
||
10862 | 4091 |
allUnderlined |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4092 |
"return a text object representing the receiver, but all with underline" |
10862 | 4093 |
|
4094 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
4095 |
Text isNil ifTrue:[^ self]. |
|
4096 |
^ self asText allUnderlined |
|
4097 |
||
4098 |
" |
|
4099 |
Transcript showCR:'hello' asText allUnderlined |
|
4100 |
Transcript showCR:'hello' allUnderlined |
|
4101 |
" |
|
4102 |
! |
|
4103 |
||
6228 | 4104 |
colorizeAllWith:aColor |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4105 |
"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
|
4106 |
|
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4107 |
"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
|
4108 |
Text isNil ifTrue:[^ self]. |
6228 | 4109 |
^ self asText colorizeAllWith:aColor |
4110 |
||
4111 |
" |
|
4112 |
Transcript showCR:('hello' colorizeAllWith:Color red) |
|
4113 |
Transcript showCR:('world' colorizeAllWith:Color green darkened) |
|
4114 |
" |
|
4115 |
! |
|
4116 |
||
12330
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4117 |
colorizeAllWith:fgColor on:bgColor |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4118 |
"return a text object representing the receiver, but all colorized with |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4119 |
both fg and background color" |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4120 |
|
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4121 |
"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
|
4122 |
Text isNil ifTrue:[^ self]. |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4123 |
^ self asText colorizeAllWith:fgColor on:bgColor |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4124 |
|
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4125 |
" |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4126 |
Transcript showCR:('hello' colorizeAllWith:Color red on:Color yellow) |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4127 |
Transcript showCR:('world' colorizeAllWith:Color red) |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4128 |
" |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4129 |
! |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4130 |
|
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4131 |
emphasis |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4132 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4133 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4134 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4135 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4136 |
^ RunArray new:self size withAll:nil |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4137 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4138 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4139 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4140 |
|
6655 | 4141 |
emphasis:emphasisCollection |
4142 |
^ self asText emphasis:emphasisCollection |
|
4143 |
||
4144 |
" |
|
4145 |
Transcript showCR:('hello' emphasis:#(bold bold bold bold bold)) |
|
4146 |
" |
|
4147 |
! |
|
4148 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4149 |
emphasisAt:characterIndex |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4150 |
"return the emphasis at some index. |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4151 |
Since characterArrays do not hold any emphasis information, |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4152 |
nil (no emphasis) is returned here." |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4153 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4154 |
^ nil |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4155 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4156 |
"Created: 11.5.1996 / 14:13:27 / cg" |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4157 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4158 |
|
11632
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4159 |
emphasisAtPoint:aPoint on:aGC |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4160 |
"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
|
4161 |
|
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4162 |
^ nil |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4163 |
! |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4164 |
|
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4165 |
emphasisCollection |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4166 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4167 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4168 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4169 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4170 |
^ RunArray new:(self size) |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4171 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4172 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4173 |
"Modified: 14.5.1996 / 15:02:29 / cg" |
3404 | 4174 |
! |
4175 |
||
11919 | 4176 |
emphasiseFrom:start to:stop with:newEmphasis |
4177 |
"set to the emphasis within some range. return the receiver" |
|
4178 |
||
4179 |
^ self asText emphasiseFrom:start to:stop with:newEmphasis |
|
4180 |
||
4181 |
" |
|
12177 | 4182 |
'hello' emphasiseFrom:2 with:#italic |
11919 | 4183 |
|
4184 |
Transcript showCR:('hello' emphasiseFrom:2 with:#italic) |
|
4185 |
" |
|
4186 |
! |
|
4187 |
||
4188 |
emphasiseFrom:start with:newEmphasis |
|
4189 |
"set to the emphasis within some range. return the receiver" |
|
4190 |
||
4191 |
^ self emphasiseFrom:start to:(self size) with:newEmphasis |
|
4192 |
||
4193 |
" |
|
12177 | 4194 |
'hello' emphasiseFrom:2 with:#italic |
11919 | 4195 |
|
4196 |
Transcript showCR:('hello' emphasiseFrom:2 with:#italic) |
|
4197 |
" |
|
4198 |
! |
|
4199 |
||
3404 | 4200 |
emphasizeAllWith:emphasis |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4201 |
"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
|
4202 |
|
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4203 |
"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
|
4204 |
Text isNil ifTrue:[^ self]. |
3404 | 4205 |
^ self asText emphasizeAllWith:emphasis |
4206 |
||
4207 |
" |
|
4208 |
Transcript showCR:('hello' emphasizeAllWith:#bold) |
|
3599 | 4209 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
4210 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
|
4211 |
" |
|
4212 |
||
4213 |
"Modified: / 17.6.1998 / 12:51:44 / cg" |
|
5097 | 4214 |
! |
4215 |
||
4216 |
makeSelectorBoldIn:aClass |
|
14050 | 4217 |
"the receiver represents some source code for a method in aClass. |
5097 | 4218 |
Change myself to boldify the selector. |
14050 | 4219 |
Not yet implemented (could easily use the syntaxHighlighter for this ...). |
4220 |
For protocol compatibility with other smalltalks" |
|
5097 | 4221 |
|
4222 |
^ self |
|
4223 |
||
14050 | 4224 |
"Created: / 13-12-1999 / 21:49:24 / cg" |
4225 |
! |
|
4226 |
||
16697 | 4227 |
withColor:aColor |
4228 |
"return a text object representing the receiver, but all colorized" |
|
4229 |
||
4230 |
^ self colorizeAllWith:aColor |
|
4231 |
||
4232 |
" |
|
4233 |
Transcript showCR:('hello' withColor:Color red) |
|
4234 |
Transcript showCR:('world' withColor:Color green darkened) |
|
4235 |
" |
|
4236 |
! |
|
4237 |
||
14050 | 4238 |
withoutAnyColorEmphasis |
4239 |
"for protocol compatibility with Text" |
|
4240 |
||
4241 |
^ self |
|
4242 |
||
4243 |
"Created: / 06-03-2012 / 18:15:38 / cg" |
|
6653 | 4244 |
! |
4245 |
||
12396 | 4246 |
withoutBackgroundColorEmphasis |
14050 | 4247 |
"for protocol compatibility with Text" |
4248 |
||
12396 | 4249 |
^ self |
14050 | 4250 |
|
4251 |
"Modified (comment): / 06-03-2012 / 18:14:27 / cg" |
|
12396 | 4252 |
! |
4253 |
||
6653 | 4254 |
withoutEmphasis:emphasisToRemove |
14050 | 4255 |
"for protocol compatibility with Text" |
4256 |
||
6653 | 4257 |
^ self |
14050 | 4258 |
|
4259 |
"Modified (comment): / 06-03-2012 / 18:14:29 / cg" |
|
12396 | 4260 |
! |
4261 |
||
4262 |
withoutForegroundColorEmphasis |
|
14050 | 4263 |
"for protocol compatibility with Text" |
4264 |
||
12396 | 4265 |
^ self |
14050 | 4266 |
|
4267 |
"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
|
4268 |
! ! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4269 |
|
7265 | 4270 |
!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
|
4271 |
|
12767
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4272 |
decodeAsLiteralArray |
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4273 |
"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
|
4274 |
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
|
4275 |
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
|
4276 |
|
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4277 |
^ self |
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4278 |
! |
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4279 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4280 |
decodeFrom:encodingSymbol |
8874 | 4281 |
"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
|
4282 |
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
|
4283 |
|
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
4284 |
|myEncoding encoder| |
7950 | 4285 |
|
4286 |
encodingSymbol isNil ifTrue:[^ self]. |
|
4287 |
myEncoding := self encoding. |
|
4288 |
encodingSymbol == myEncoding ifTrue:[^ self]. |
|
4289 |
||
4290 |
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
|
4291 |
encoder isNil ifTrue:[^ self]. |
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
4292 |
^ 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
|
4293 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4294 |
|
9192 | 4295 |
encodeFrom:oldEncoding into:newEncoding |
4296 |
^ CharacterEncoder encodeString:self from:oldEncoding into:newEncoding |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
4297 |
|
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
4298 |
" |
17600 | 4299 |
'äüö' encodeFrom:#iso8859 into:#utf8 |
4300 |
('äüö' encodeFrom:#iso8859 into:#utf8) encodeFrom:#utf8 into:#unicode |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
4301 |
" |
9192 | 4302 |
! |
4303 |
||
4304 |
rot13 |
|
8874 | 4305 |
"Usenet: from `rotate alphabet 13 places'] |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4306 |
The simple Caesar-cypher encryption that replaces each English |
8874 | 4307 |
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
|
4308 |
so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' |
8874 | 4309 |
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
|
4310 |
It is used to enclose the text in a sealed wrapper that the reader must choose |
8874 | 4311 |
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
|
4312 |
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
|
4313 |
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
|
4314 |
|
11865 | 4315 |
^ self rot:13 |
8874 | 4316 |
|
4317 |
" |
|
4318 |
'hello world' rot13 |
|
4319 |
'hello world' rot13 rot13 |
|
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4320 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4321 |
! |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4322 |
|
11865 | 4323 |
rot:n |
4324 |
"Usenet: from `rotate alphabet N places'] |
|
4325 |
The simple Caesar-cypher encryption that replaces each English |
|
4326 |
letter with the one N places forward or back along the alphabet, |
|
4327 |
so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' by rot 13 |
|
4328 |
Most Usenet news reading and posting programs include a rot13 feature. |
|
4329 |
It is used to enclose the text in a sealed wrapper that the reader must choose |
|
4330 |
to open -- e.g., for posting things that might offend some readers, or spoilers. |
|
4331 |
A major advantage of rot13 over rot(N) for other N is that it |
|
4332 |
is self-inverse, so the same code can be used for encoding and decoding." |
|
4333 |
||
4334 |
^ self species |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4335 |
streamContents:[:aStream | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4336 |
self do:[:char | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4337 |
aStream nextPut:(char rot:n) ]] |
11865 | 4338 |
|
4339 |
" |
|
4340 |
'hello world' rot:13 |
|
4341 |
('hello world' rot:13) rot:13 |
|
4342 |
" |
|
4343 |
! |
|
4344 |
||
15656 | 4345 |
utf16Encoded |
4346 |
"Return my UTF-16 representation as a new TwoByteString" |
|
4347 |
||
4348 |
|s| |
|
4349 |
||
4350 |
s := WriteStream on:(TwoByteString uninitializedNew:self size). |
|
4351 |
s nextPutAllUtf16:self. |
|
4352 |
^ s contents |
|
4353 |
||
4354 |
" |
|
4355 |
'abcde1234' utf16Encoded |
|
17600 | 4356 |
'abcdeäöüß' utf16Encoded |
15656 | 4357 |
" |
4358 |
||
4359 |
"Modified: / 11-05-2010 / 19:12:37 / cg" |
|
4360 |
! |
|
4361 |
||
9192 | 4362 |
utf8Encoded |
4363 |
"Return my UTF-8 representation as a new String" |
|
4364 |
||
17625 | 4365 |
|string| |
4366 |
||
4367 |
string := self string. |
|
4368 |
string ~~ self ifTrue:[ |
|
18597 | 4369 |
^ string utf8Encoded. |
17625 | 4370 |
]. |
14592 | 4371 |
|
18612 | 4372 |
^ CharacterEncoderImplementations::ISO10646_to_UTF8 new encodeString:self |
18597 | 4373 |
|
4374 |
" |
|
4375 |
'abcde1234' asUnicode32String utf8Encoded |
|
4376 |
'abcdeäöüß' asUnicode32String utf8Encoded |
|
12925
5c0a9a633ca1
comment/format in: #utf8Encoded
Claus Gittinger <cg@exept.de>
parents:
12912
diff
changeset
|
4377 |
" |
5c0a9a633ca1
comment/format in: #utf8Encoded
Claus Gittinger <cg@exept.de>
parents:
12912
diff
changeset
|
4378 |
|
5c0a9a633ca1
comment/format in: #utf8Encoded
Claus Gittinger <cg@exept.de>
parents:
12912
diff
changeset
|
4379 |
"Modified: / 11-05-2010 / 19:12:37 / cg" |
17625 | 4380 |
! |
4381 |
||
4382 |
utf8EncodedOn:aStream |
|
4383 |
"write to aStream in utf8 encoding" |
|
4384 |
||
4385 |
|string| |
|
4386 |
||
4387 |
string := self string. |
|
4388 |
string ~~ self ifTrue:[ |
|
18597 | 4389 |
^ string utf8EncodedOn:aStream. |
4390 |
]. |
|
4391 |
||
4392 |
self containsNon7BitAscii ifTrue:[ |
|
4393 |
aStream nextPutAllUtf8:self. |
|
4394 |
] ifFalse:[ |
|
4395 |
"speed up common case" |
|
4396 |
aStream nextPutAll:self. |
|
17625 | 4397 |
]. |
4398 |
||
18597 | 4399 |
" |
4400 |
String streamContents:[:w| |
|
4401 |
'abcde1234' asUnicode32String utf8EncodedOn:w |
|
4402 |
]. |
|
4403 |
String streamContents:[:w| |
|
4404 |
'abcde1234' asUnicode32String utf8EncodedOn:w |
|
4405 |
]. |
|
4406 |
String streamContents:[:w| |
|
4407 |
'abcdeäöüß' asUnicode32String utf8EncodedOn:w |
|
4408 |
]. |
|
17625 | 4409 |
" |
9192 | 4410 |
! ! |
4411 |
||
11345 | 4412 |
|
18721 | 4413 |
|
4414 |
||
12111 | 4415 |
!CharacterArray methodsFor:'matching - glob expressions'! |
4416 |
||
4417 |
compoundMatch:aString |
|
4418 |
"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
|
4419 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
12111 | 4420 |
This is usable with fileName pattern fields. |
4421 |
||
4422 |
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
|
4423 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4424 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4425 |
NOTICE: the receiver is the match pattern" |
4426 |
||
15890 | 4427 |
^ self compoundMatch:aString caseSensitive:true withoutSeparators:false |
12111 | 4428 |
|
4429 |
" |
|
4430 |
'f*' match:'foo' |
|
4431 |
'b*' match:'foo' |
|
4432 |
'f*;b*' match:'foo' |
|
4433 |
'f*;b*' match:'bar' |
|
4434 |
'f*;b*' compoundMatch:'foo' |
|
4435 |
'f*;b*' compoundMatch:'bar' |
|
4436 |
" |
|
4437 |
||
4438 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4439 |
"Modified: / 16.12.1999 / 01:22:08 / cg" |
|
4440 |
! |
|
4441 |
||
15734 | 4442 |
compoundMatch:aString caseSensitive:caseSensitive |
12111 | 4443 |
"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
|
4444 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
12111 | 4445 |
This is usable with fileName pattern fields. |
4446 |
||
4447 |
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
|
4448 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4449 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4450 |
NOTICE: the receiver is the match pattern" |
4451 |
||
15890 | 4452 |
^self compoundMatch:aString caseSensitive:caseSensitive withoutSeparators:false |
4453 |
||
4454 |
" |
|
4455 |
'f*' match:'foo' |
|
4456 |
'b*' match:'foo' |
|
4457 |
'f*;b*' match:'foo' |
|
4458 |
'f*;b*' match:'bar' |
|
4459 |
'f*;b*' compoundMatch:'foo' |
|
4460 |
'f*;b*' compoundMatch:'bar' |
|
4461 |
'f*;b*' compoundMatch:'Foo' caseSensitive:false |
|
4462 |
'f*;b*' compoundMatch:'Bar' caseSensitive:false |
|
4463 |
'f*;b*' compoundMatch:'ccc' caseSensitive:false |
|
4464 |
" |
|
4465 |
||
4466 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
4467 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4468 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
4469 |
! |
|
4470 |
||
4471 |
compoundMatch:aString caseSensitive:caseSensitive withoutSeparators:withoutSeparators |
|
4472 |
"like match, but the receiver may be a compound match pattern, |
|
4473 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
|
4474 |
If withoutSeparators is true, spaces around individual patterns are stripped off. |
|
4475 |
This is usable with fileName pattern fields. |
|
4476 |
||
4477 |
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
|
4478 |
NOT the ST-80 meaning. |
15890 | 4479 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4480 |
NOTICE: the receiver is the match pattern" |
|
4481 |
||
12111 | 4482 |
|matchers| |
4483 |
||
4484 |
matchers := self asCollectionOfSubstringsSeparatedBy:$;. |
|
15890 | 4485 |
withoutSeparators ifTrue:[ matchers := matchers collect:[:each | each withoutSeparators] ]. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4486 |
^ matchers |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4487 |
contains:[:aPattern | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4488 |
aPattern match:aString ignoreCase:caseSensitive not escapeCharacter:nil |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4489 |
]. |
15734 | 4490 |
|
4491 |
" |
|
4492 |
'f*' match:'foo' |
|
4493 |
'b*' match:'foo' |
|
4494 |
'f*;b*' match:'foo' |
|
4495 |
'f*;b*' match:'bar' |
|
4496 |
'f*;b*' compoundMatch:'foo' |
|
4497 |
'f*;b*' compoundMatch:'bar' |
|
4498 |
'f*;b*' compoundMatch:'Foo' caseSensitive:false |
|
4499 |
'f*;b*' compoundMatch:'Bar' caseSensitive:false |
|
4500 |
'f*;b*' compoundMatch:'ccc' caseSensitive:false |
|
15890 | 4501 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4502 |
'f* ; b*' compoundMatch:'foo' |
15890 | 4503 |
'f* ; b*' compoundMatch:'foo' caseSensitive:true withoutSeparators:true |
15734 | 4504 |
" |
4505 |
||
4506 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
4507 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4508 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
4509 |
! |
|
4510 |
||
4511 |
compoundMatch:aString ignoreCase:ignoreCase |
|
4512 |
<resource: #obsolete> |
|
4513 |
||
4514 |
"like match, but the receiver may be a compound match pattern, |
|
4515 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
|
4516 |
This is usable with fileName pattern fields. |
|
4517 |
||
4518 |
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
|
4519 |
NOT the ST-80 meaning. |
15734 | 4520 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4521 |
NOTICE: the receiver is the match pattern" |
|
4522 |
||
4523 |
^ self compoundMatch:aString caseSensitive:ignoreCase not |
|
12111 | 4524 |
|
4525 |
" |
|
4526 |
'f*' match:'foo' |
|
4527 |
'b*' match:'foo' |
|
4528 |
'f*;b*' match:'foo' |
|
4529 |
'f*;b*' match:'bar' |
|
4530 |
'f*;b*' compoundMatch:'foo' |
|
4531 |
'f*;b*' compoundMatch:'bar' |
|
4532 |
'f*;b*' compoundMatch:'Foo' ignoreCase:true |
|
4533 |
'f*;b*' compoundMatch:'Bar' ignoreCase:true |
|
4534 |
'f*;b*' compoundMatch:'ccc' ignoreCase:true |
|
4535 |
" |
|
4536 |
||
4537 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
4538 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4539 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
4540 |
! |
|
4541 |
||
4542 |
findMatchString:matchString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4543 |
"like findString/indexOfSubCollection, but allowing GLOB match patterns. |
12111 | 4544 |
find matchstring; if found, return the index; |
4545 |
if not found, return 0. |
|
4546 |
||
4547 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4548 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4549 |
NOTICE: this GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4550 |
NOTICE: the argument is the match pattern" |
4551 |
||
4552 |
^ self findMatchString:matchString startingAt:1 ignoreCase:false ifAbsent:0 |
|
4553 |
! |
|
4554 |
||
4555 |
findMatchString:matchString startingAt:index |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4556 |
"like findString, but allowing GLOB match patterns. |
12111 | 4557 |
find matchstring, starting at index. if found, return the index; |
4558 |
if not found, return 0. |
|
4559 |
||
4560 |
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
|
4561 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4562 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4563 |
NOTICE: the argument is the match pattern" |
4564 |
||
4565 |
^ self findMatchString:matchString startingAt:index ignoreCase:false ifAbsent:0 |
|
4566 |
! |
|
4567 |
||
15734 | 4568 |
findMatchString:matchString startingAt:index caseSensitive:caseSensitive ifAbsent:exceptionBlock |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4569 |
"like findString, but allowing GLOB match patterns. |
12111 | 4570 |
find matchstring, starting at index. if found, return the index; |
4571 |
if not found, return the result of evaluating exceptionBlock. |
|
4572 |
This is a q&d hack - not very efficient. |
|
4573 |
||
4574 |
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
|
4575 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4576 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4577 |
NOTICE: the argument is the match pattern" |
4578 |
||
4579 |
|firstChar firstSet |
|
4580 |
startIndex "{ Class: SmallInteger }" |
|
4581 |
matchSize "{ Class: SmallInteger }" |
|
4582 |
mySize "{ Class: SmallInteger }" |
|
4583 |
realMatchString lcChar ucChar| |
|
4584 |
||
4585 |
matchSize := matchString size. |
|
4586 |
matchSize == 0 ifTrue:[^ index]. "empty string matches" |
|
4587 |
||
4588 |
realMatchString := matchString. |
|
4589 |
(realMatchString endsWith:$*) ifFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4590 |
realMatchString := realMatchString , '*'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4591 |
matchSize := matchSize + 1 |
12111 | 4592 |
]. |
4593 |
||
4594 |
mySize := self size. |
|
4595 |
firstChar := realMatchString at:1. |
|
4596 |
firstChar == self class matchEscapeCharacter ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4597 |
firstChar := realMatchString at:2. |
12111 | 4598 |
]. |
4599 |
||
4600 |
firstChar asString includesMatchCharacters ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4601 |
index to:mySize do:[:col | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4602 |
(realMatchString match:self from:col to:mySize caseSensitive:caseSensitive) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4603 |
ifTrue:[^ col] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4604 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4605 |
^ exceptionBlock value. |
12111 | 4606 |
]. |
4607 |
||
4608 |
lcChar := firstChar asLowercase. |
|
4609 |
ucChar := firstChar asUppercase. |
|
15734 | 4610 |
(caseSensitive not and:[ lcChar ~= ucChar ]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4611 |
firstSet := Array with:ucChar with:lcChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4612 |
startIndex := self indexOfAny:firstSet startingAt:index. |
12111 | 4613 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4614 |
startIndex := self indexOf:firstChar startingAt:index. |
12111 | 4615 |
]. |
4616 |
[startIndex == 0] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4617 |
(realMatchString match:self from:startIndex to:mySize caseSensitive:caseSensitive) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4618 |
ifTrue:[^ startIndex]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4619 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4620 |
firstSet notNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4621 |
startIndex := self indexOfAny:firstSet startingAt:(startIndex + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4622 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4623 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4624 |
]. |
12111 | 4625 |
]. |
4626 |
^ exceptionBlock value |
|
4627 |
||
4628 |
" |
|
4629 |
'one two three four' findMatchString:'o[nu]' |
|
4630 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
15734 | 4631 |
'one two three four one' findMatchString:'ONE' startingAt:3 caseSensitive:false ifAbsent:0 |
4632 |
'one two three four one' findMatchString:'ONE' startingAt:3 caseSensitive:true ifAbsent:0 |
|
4633 |
'one two three four ONE' findMatchString:'O#E' startingAt:1 caseSensitive:false ifAbsent:0 |
|
4634 |
'one two three four ONE' findMatchString:'O#E' startingAt:1 caseSensitive:true ifAbsent:0 |
|
4635 |
12345678901234567890 |
|
4636 |
" |
|
4637 |
||
4638 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
|
4639 |
! |
|
4640 |
||
4641 |
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock |
|
4642 |
<resource: #obsolete> |
|
4643 |
"like findString, but allowing GLOB match patterns. |
|
4644 |
find matchstring, starting at index. if found, return the index; |
|
4645 |
if not found, return the result of evaluating exceptionBlock. |
|
4646 |
This is a q&d hack - not very efficient. |
|
4647 |
||
4648 |
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
|
4649 |
NOT the ST-80 meaning. |
15734 | 4650 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4651 |
NOTICE: the argument is the match pattern" |
|
4652 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4653 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4654 |
findMatchString:matchString startingAt:index caseSensitive:ignoreCase not ifAbsent:exceptionBlock |
15734 | 4655 |
|
4656 |
" |
|
4657 |
'one two three four' findMatchString:'o[nu]' |
|
4658 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
12111 | 4659 |
'one two three four one' findMatchString:'ONE' startingAt:3 ignoreCase:true ifAbsent:0 |
4660 |
" |
|
4661 |
||
4662 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
|
4663 |
! |
|
4664 |
||
4665 |
includesMatchString:matchString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4666 |
"like includesString, but allowing GLOB match patterns. |
12111 | 4667 |
find matchstring; if found, return true, otherwise return false. |
4668 |
||
4669 |
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
|
4670 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4671 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4672 |
NOTICE: the argument is the match pattern" |
4673 |
||
4674 |
^ (self findMatchString:matchString) ~~ 0 |
|
4675 |
||
4676 |
" |
|
4677 |
'hello world' includesMatchString:'h*' |
|
4678 |
'hello world' includesMatchString:'h[aeiou]llo' |
|
4679 |
'hello world' includesMatchString:'wor*' |
|
4680 |
'hello world' includesMatchString:'woR*' |
|
4681 |
" |
|
4682 |
! |
|
4683 |
||
4684 |
includesMatchString:matchString caseSensitive:caseSensitive |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4685 |
"like includesString, but allowing GLOB match patterns. |
12111 | 4686 |
find matchstring; if found, return true, otherwise return false. |
4687 |
||
4688 |
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
|
4689 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4690 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4691 |
NOTICE: the argument is the match pattern" |
4692 |
||
4693 |
^ (self findMatchString:matchString startingAt:1 ignoreCase:caseSensitive not ifAbsent:0) ~~ 0 |
|
4694 |
||
4695 |
" |
|
4696 |
'hello world' includesMatchString:'h*' caseSensitive:true |
|
4697 |
'hello world' includesMatchString:'h*' caseSensitive:false |
|
4698 |
'Hello world' includesMatchString:'h*' caseSensitive:true |
|
4699 |
'Hello world' includesMatchString:'h*' caseSensitive:false |
|
4700 |
||
4701 |
'hello world' includesMatchString:'h[aeiou]llo' caseSensitive:true |
|
4702 |
'hello world' includesMatchString:'h[aeiou]llo' caseSensitive:false |
|
4703 |
||
4704 |
'hello world' includesMatchString:'wor*' caseSensitive:true |
|
4705 |
'hello world' includesMatchString:'wor*' caseSensitive:false |
|
4706 |
||
4707 |
'hello world' includesMatchString:'woR*' caseSensitive:true |
|
4708 |
'hello world' includesMatchString:'woR*' caseSensitive:false |
|
4709 |
" |
|
4710 |
! |
|
4711 |
||
4712 |
match:aString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4713 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 4714 |
characters $* (to match any string) or $# (to match any character). |
4715 |
or [...] to match a set of characters. |
|
4716 |
Lower/uppercase are considered different. |
|
4717 |
The escape character is the backQuote. |
|
4718 |
||
4719 |
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
|
4720 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4721 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4722 |
NOTICE: the receiver is the match pattern" |
4723 |
||
15734 | 4724 |
^ self match:aString from:1 to:aString size caseSensitive:true |
12111 | 4725 |
|
4726 |
" |
|
4727 |
'\*f*' match:'f' |
|
4728 |
'\*f*' match:'*f' |
|
4729 |
'*\*f*' match:'*f' |
|
4730 |
'*f*' match:'*f' |
|
4731 |
'*ute*' match:'computer' |
|
4732 |
'*uter' match:'computer' |
|
4733 |
'uter*' match:'computer' |
|
4734 |
'*ute*' match:'' |
|
4735 |
'[abcd]*' match:'computer' |
|
4736 |
'[abcd]*' match:'komputer' |
|
4737 |
'*some*compl*ern*' match:'this is some more complicated pattern match' |
|
4738 |
'*some*compl*ern*' match:'this is another complicated pattern match' |
|
4739 |
'*-hh' match:'anton-h' |
|
4740 |
" |
|
4741 |
||
4742 |
"Modified: / 9.6.1998 / 18:50:00 / cg" |
|
4743 |
! |
|
4744 |
||
15734 | 4745 |
match:aString caseSensitive:caseSensitive |
4746 |
"return true if aString matches self, where self may contain GLOB meta-match |
|
4747 |
characters $* (to match any string) or $# (to match any character) |
|
4748 |
or [...] to match a set of characters. |
|
4749 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
4750 |
The escape character is the backQuote. |
|
4751 |
||
4752 |
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
|
4753 |
NOT the ST-80 meaning. |
15734 | 4754 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4755 |
NOTICE: the receiver is the match pattern" |
|
4756 |
||
4757 |
^ self match:aString from:1 to:aString size caseSensitive:caseSensitive |
|
4758 |
||
4759 |
" |
|
4760 |
'*ute*' match:'COMPUTER' caseSensitive:false |
|
4761 |
'*uter' match:'COMPUTER' caseSensitive:true |
|
4762 |
'[abcd]*' match:'computer' caseSensitive:true |
|
4763 |
'[abcd]*' match:'Computer' caseSensitive:true |
|
4764 |
'[a-k]*' match:'komputer' caseSensitive:true |
|
4765 |
'[a-k]*' match:'zomputer' caseSensitive:true |
|
4766 |
'[a-k]*' match:'Komputer' caseSensitive:true |
|
4767 |
'[a-k]*' match:'Komputer' caseSensitive:false |
|
4768 |
'*some*compl*ern*' match:'this is some more complicated pattern match' caseSensitive:false |
|
4769 |
'*some*compl*ern*' match:'this is another complicated pattern match' caseSensitive:false |
|
4770 |
||
4771 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4772 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4773 |
'[ab]*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4774 |
] |
15734 | 4775 |
]. |
4776 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4777 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4778 |
'*at:*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4779 |
] |
15734 | 4780 |
]. |
4781 |
" |
|
4782 |
||
4783 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
4784 |
! |
|
4785 |
||
4786 |
match:aString caseSensitive:caseSensitive escapeCharacter:escape |
|
4787 |
"return true if aString matches self, where self may contain GLOB meta-match |
|
4788 |
characters $* (to match any string) or $# (to match any character) |
|
4789 |
or [...] to match a set of characters. |
|
4790 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
4791 |
||
4792 |
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
|
4793 |
NOT the ST-80 meaning. |
15734 | 4794 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4795 |
NOTICE: the receiver is the match pattern" |
|
4796 |
||
4797 |
^ self match:aString from:1 to:aString size caseSensitive:caseSensitive escapeCharacter:escape |
|
4798 |
||
4799 |
" |
|
4800 |
'*ute*' match:'COMPUTER' caseSensitive:false |
|
4801 |
'*uter' match:'COMPUTER' caseSensitive:true |
|
4802 |
'[abcd]*' match:'computer' caseSensitive:true |
|
4803 |
'[abcd]*' match:'Computer' caseSensitive:true |
|
4804 |
'[a-k]*' match:'komputer' caseSensitive:true |
|
4805 |
'[a-k]*' match:'zomputer' caseSensitive:true |
|
4806 |
'[a-k]*' match:'Komputer' caseSensitive:true |
|
4807 |
'[a-k]*' match:'Komputer' caseSensitive:false |
|
4808 |
'*some*compl*ern*' match:'this is some more complicated pattern match' caseSensitive:false |
|
4809 |
'*some*compl*ern*' match:'this is another complicated pattern match' caseSensitive:false |
|
4810 |
||
4811 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4812 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4813 |
'[ab]*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4814 |
] |
15734 | 4815 |
]. |
4816 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4817 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4818 |
'*at:*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4819 |
] |
15734 | 4820 |
]. |
4821 |
" |
|
4822 |
||
4823 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
4824 |
! |
|
4825 |
||
12111 | 4826 |
match:aString escapeCharacter:escape |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4827 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 4828 |
characters $* (to match any string) or $# (to match any character). |
4829 |
or [...] to match a set of characters. |
|
4830 |
Lower/uppercase are considered different. |
|
4831 |
||
4832 |
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
|
4833 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4834 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4835 |
NOTICE: the receiver is the match pattern" |
4836 |
||
4837 |
^ self match:aString from:1 to:aString size ignoreCase:false escapeCharacter:escape |
|
4838 |
||
4839 |
" |
|
4840 |
'a\b\c\*' match:'a\b\c\d' |
|
4841 |
'a\b\c\*' match:'a\b\c\d' escapeCharacter:nil |
|
4842 |
" |
|
4843 |
! |
|
4844 |
||
15734 | 4845 |
match:aString from:start to:stop caseSensitive:caseSensitive |
4846 |
"return true if part of aString matches myself, |
|
4847 |
where self may contain GLOB meta-match |
|
4848 |
characters $* (to match any string) or $# (to match any character) |
|
4849 |
or [...] to match a set of characters. |
|
4850 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
4851 |
The escape character is the backQuote. |
|
4852 |
||
4853 |
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
|
4854 |
NOT the ST-80 meaning. |
15734 | 4855 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4856 |
NOTICE: the receiver is the match pattern" |
|
4857 |
||
4858 |
^ self |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4859 |
match:aString from:start to:stop caseSensitive:caseSensitive |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4860 |
escapeCharacter:(self class matchEscapeCharacter) |
15734 | 4861 |
|
4862 |
" |
|
4863 |
'*ute*' match:'12345COMPUTER' from:1 to:5 caseSensitive:false |
|
4864 |
'*ute*' match:'12345COMPUTER' from:6 to:13 caseSensitive:false |
|
4865 |
" |
|
4866 |
||
4867 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
4868 |
! |
|
4869 |
||
4870 |
match:aString from:start to:stop caseSensitive:caseSensitive escapeCharacter:escape |
|
4871 |
"return true if part of aString matches myself, |
|
4872 |
where self may contain GLOB meta-match |
|
4873 |
characters $* (to match any string) or $# (to match any character) |
|
4874 |
or [...] to match a set of characters. |
|
4875 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
4876 |
||
4877 |
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
|
4878 |
NOT the ST-80 meaning. |
15734 | 4879 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4880 |
NOTICE: the receiver is the match pattern" |
|
4881 |
||
4882 |
|matchScanArray| |
|
4883 |
||
4884 |
" |
|
4885 |
keep the matchScanArray from the most recent match - |
|
4886 |
avoids parsing the pattern over-and over if multiple searches |
|
4887 |
are done with the same pattern. |
|
4888 |
" |
|
4889 |
(PreviousMatch notNil |
|
4890 |
and:[PreviousMatch key = self]) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4891 |
matchScanArray := PreviousMatch value |
15734 | 4892 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4893 |
matchScanArray := self class matchScanArrayFrom:self escapeCharacter:escape. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4894 |
matchScanArray isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4895 |
'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
|
4896 |
^ self = aString |
15734 | 4897 |
"/ ^ false |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4898 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4899 |
PreviousMatch := self -> matchScanArray. |
15734 | 4900 |
]. |
4901 |
||
4902 |
^ self class |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4903 |
matchScan:matchScanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4904 |
from:1 to:matchScanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4905 |
with:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4906 |
from:start to:stop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4907 |
caseSensitive:caseSensitive |
15734 | 4908 |
|
4909 |
" |
|
4910 |
'*ute*' match:'12345COMPUTER' from:1 to:5 caseSensitive:false |
|
4911 |
'*ute*' match:'12345COMPUTER' from:6 to:13 caseSensitive:false |
|
4912 |
" |
|
4913 |
||
4914 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
4915 |
! |
|
4916 |
||
12111 | 4917 |
match:aString from:start to:stop ignoreCase:ignoreCase |
15734 | 4918 |
<resource: #obsolete> |
12111 | 4919 |
"return true if part of aString matches myself, |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4920 |
where self may contain GLOB meta-match |
12111 | 4921 |
characters $* (to match any string) or $# (to match any character) |
4922 |
or [...] to match a set of characters. |
|
4923 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
4924 |
The escape character is the backQuote. |
|
4925 |
||
4926 |
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
|
4927 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4928 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4929 |
NOTICE: the receiver is the match pattern" |
4930 |
||
4931 |
^ self |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4932 |
match:aString from:start to:stop ignoreCase:ignoreCase |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4933 |
escapeCharacter:(self class matchEscapeCharacter) |
12111 | 4934 |
|
4935 |
" |
|
4936 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
4937 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
4938 |
" |
|
4939 |
||
4940 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
4941 |
! |
|
4942 |
||
4943 |
match:aString from:start to:stop ignoreCase:ignoreCase escapeCharacter:escape |
|
15734 | 4944 |
<resource: #obsolete> |
12111 | 4945 |
"return true if part of aString matches myself, |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4946 |
where self may contain GLOB meta-match |
12111 | 4947 |
characters $* (to match any string) or $# (to match any character) |
4948 |
or [...] to match a set of characters. |
|
4949 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
4950 |
||
4951 |
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
|
4952 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4953 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4954 |
NOTICE: the receiver is the match pattern" |
4955 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4956 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4957 |
match:aString from:start to:stop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4958 |
caseSensitive:ignoreCase not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4959 |
escapeCharacter:escape |
12111 | 4960 |
|
4961 |
" |
|
4962 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
4963 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
4964 |
" |
|
4965 |
||
4966 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
4967 |
! |
|
4968 |
||
4969 |
match:aString ignoreCase:ignoreCase |
|
15734 | 4970 |
<resource: #obsolete> |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4971 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 4972 |
characters $* (to match any string) or $# (to match any character) |
4973 |
or [...] to match a set of characters. |
|
4974 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
4975 |
The escape character is the backQuote. |
|
4976 |
||
4977 |
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
|
4978 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4979 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4980 |
NOTICE: the receiver is the match pattern" |
4981 |
||
15734 | 4982 |
"/ leave it this way, in case a customer has redefined it for performance (for a while) |
12111 | 4983 |
^ self match:aString from:1 to:aString size ignoreCase:ignoreCase |
4984 |
||
4985 |
" |
|
4986 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
4987 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
4988 |
'[abcd]*' match:'computer' ignoreCase:false |
|
4989 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
4990 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
4991 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
4992 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
4993 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
4994 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
4995 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
4996 |
||
4997 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4998 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4999 |
'[ab]*' match:sym ignoreCase:false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5000 |
] |
12111 | 5001 |
]. |
5002 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5003 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5004 |
'*at:*' match:sym ignoreCase:false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5005 |
] |
12111 | 5006 |
]. |
5007 |
" |
|
5008 |
||
5009 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
5010 |
! |
|
5011 |
||
5012 |
match:aString ignoreCase:ignoreCase escapeCharacter:escape |
|
15734 | 5013 |
<resource: #obsolete> |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5014 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 5015 |
characters $* (to match any string) or $# (to match any character) |
5016 |
or [...] to match a set of characters. |
|
5017 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
5018 |
||
5019 |
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
|
5020 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5021 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5022 |
NOTICE: the receiver is the match pattern" |
5023 |
||
5024 |
^ self match:aString from:1 to:aString size ignoreCase:ignoreCase escapeCharacter:escape |
|
5025 |
||
5026 |
" |
|
5027 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
5028 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
5029 |
'[abcd]*' match:'computer' ignoreCase:false |
|
5030 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
5031 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
5032 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
5033 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
5034 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
5035 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
5036 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
5037 |
||
5038 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5039 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5040 |
'[ab]*' match:sym ignoreCase:false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5041 |
] |
12111 | 5042 |
]. |
5043 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5044 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5045 |
'*at:*' match:sym ignoreCase:false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5046 |
] |
12111 | 5047 |
]. |
5048 |
" |
|
5049 |
||
5050 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
5051 |
! |
|
5052 |
||
5053 |
matches:aPatternString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5054 |
"return true if the receiver matches aString, where aPatternString may contain GLOB meta-match |
12111 | 5055 |
characters $* (to match any string) or $# (to match any character). |
5056 |
or [...] to match a set of characters. |
|
5057 |
Lower/uppercase are considered different. |
|
5058 |
||
5059 |
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
|
5060 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5061 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5062 |
NOTICE: the receiver is the match pattern" |
5063 |
||
5064 |
^ aPatternString match:self |
|
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5065 |
! |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5066 |
|
15734 | 5067 |
matches:aPatternString caseSensitive:caseSensitive |
5068 |
"return true if the receiver matches aString, where aPatternString may contain GLOB meta-match |
|
5069 |
characters $* (to match any string) or $# (to match any character). |
|
5070 |
or [...] to match a set of characters. |
|
5071 |
||
5072 |
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
|
5073 |
NOT the ST-80 meaning. |
15734 | 5074 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
5075 |
NOTICE: the receiver is the match pattern" |
|
5076 |
||
5077 |
^ aPatternString match:self caseSensitive:caseSensitive |
|
5078 |
! |
|
5079 |
||
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5080 |
matches:aPatternString ignoreCase:ignoreCase |
15734 | 5081 |
<resource: #obsolete> |
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5082 |
"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
|
5083 |
characters $* (to match any string) or $# (to match any character). |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5084 |
or [...] to match a set of characters. |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5085 |
Lower/uppercase are considered different. |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5086 |
|
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5087 |
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
|
5088 |
NOT the ST-80 meaning. |
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5089 |
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
|
5090 |
NOTICE: the receiver is the match pattern" |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5091 |
|
15734 | 5092 |
^ aPatternString match:self caseSensitive:ignoreCase not |
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5093 |
|
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5094 |
"Created: / 08-03-2012 / 03:11:11 / cg" |
12111 | 5095 |
! ! |
5096 |
||
5097 |
||
18722 | 5098 |
!CharacterArray methodsFor:'matching - regex'! |
5099 |
||
5100 |
matchesRegex:regexString caseSensitive:aBoolean |
|
5101 |
"Test if the receiver matches a regex. |
|
5102 |
May raise RxParser>>regexErrorSignal or child signals. |
|
5103 |
This is a part of the Regular Expression Matcher package, |
|
5104 |
(c) 1996, 1999 Vassili Bykov. |
|
5105 |
Refer to `documentation' protocol of RxParser class for details." |
|
5106 |
||
5107 |
aBoolean ifFalse:[ |
|
5108 |
^ self matchesRegexIgnoringCase:regexString |
|
5109 |
] ifTrue:[ |
|
5110 |
^ self matchesRegex:regexString |
|
5111 |
]. |
|
5112 |
||
5113 |
" |
|
5114 |
'hello world' matchesRegex:'h.*d'. |
|
5115 |
" |
|
5116 |
||
5117 |
"Created: / 13-12-2010 / 11:01:49 / cg" |
|
5118 |
! ! |
|
17625 | 5119 |
|
9192 | 5120 |
!CharacterArray methodsFor:'padded copying'! |
5121 |
||
5122 |
centerPaddedTo:newSize |
|
5123 |
"return a new string consisting of the receivers characters, |
|
5124 |
plus spaces up to length and center the receivers characters in |
|
5125 |
the resulting string. |
|
5126 |
If the receivers size is equal or greater than the length argument, |
|
5127 |
the original receiver is returned unchanged." |
|
5128 |
||
5129 |
^ self centerPaddedTo:newSize with:(Character space) |
|
5130 |
||
5131 |
" |
|
5132 |
'foo' centerPaddedTo:10 |
|
5133 |
123 printString centerPaddedTo:10 |
|
5134 |
" |
|
5135 |
||
5136 |
"Created: 25.11.1995 / 10:53:57 / cg" |
|
5137 |
! |
|
9190 | 5138 |
|
5139 |
centerPaddedTo:size with:padCharacter |
|
5140 |
"return a new string of length size, which contains the receiver |
|
5141 |
centered (i.e. padded on both sides). |
|
5142 |
Characters are filled with padCharacter. |
|
8874 | 5143 |
If the receivers size is equal or greater than the length argument, |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5144 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5145 |
|
9190 | 5146 |
|len s| |
5147 |
||
5148 |
len := self size. |
|
9192 | 5149 |
(len < size) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5150 |
s := self species new:size withAll:padCharacter. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5151 |
s replaceFrom:(size - len) // 2 + 1 with:self. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5152 |
^ s |
9192 | 5153 |
] |
5154 |
||
9190 | 5155 |
" |
5156 |
'foo' centerPaddedTo:11 with:$. |
|
5157 |
'fooBar' centerPaddedTo:5 with:$. |
|
5158 |
123 printString centerPaddedTo:10 with:$. |
|
5159 |
(' ' , 123 printString) centerPaddedTo:10 with:$. |
|
5160 |
(Float pi printString) centerPaddedTo:15 with:(Character space) |
|
5161 |
(Float pi printString) centerPaddedTo:15 with:$- |
|
5162 |
(' ' , Float pi class name) centerPaddedTo:15 with:$. |
|
5163 |
" |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5164 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5165 |
|
9190 | 5166 |
decimalPaddedTo:size and:afterPeriod at:decimalCharacter |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5167 |
"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
|
5168 |
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
|
5169 |
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
|
5170 |
to be padded). |
8874 | 5171 |
If the receivers size is equal or greater than the length argument, |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5172 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5173 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5174 |
|
8874 | 5175 |
^ self |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5176 |
decimalPaddedTo:size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5177 |
and:afterPeriod |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5178 |
at:decimalCharacter |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5179 |
withLeft:(Character space) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5180 |
right:$0 |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5181 |
|
8874 | 5182 |
" |
5183 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123 ' |
|
5184 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
|
5185 |
'123.' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5186 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.100' |
8874 | 5187 |
'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
|
5188 |
'123.123' decimalPaddedTo:10 and:3 at:$. -> ' 123.123' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5189 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5190 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5191 |
"Created: 23.12.1995 / 13:11:52 / cg" |
9192 | 5192 |
! |
5193 |
||
5194 |
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
|
5195 |
"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
|
5196 |
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
|
5197 |
of the period. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5198 |
Characters on the left are filled with leftPadChar. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5199 |
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
|
5200 |
otherwise, if missing, a decimal point is added and right characters filled with this. |
8874 | 5201 |
If the receivers size is equal or greater than the length argument, |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5202 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5203 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5204 |
|
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
5205 |
|s idx n rest| |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5206 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5207 |
idx := self indexOf:decimalCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5208 |
idx == 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5209 |
"/ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5210 |
"/ no decimal point found; adjust string to the left of the period column |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5211 |
"/ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5212 |
rightPadChar isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5213 |
s := self , (self species new:afterPeriod + 1 withAll:leftPadChar) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5214 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5215 |
s:= self , decimalCharacter asString , (self species new:afterPeriod withAll:rightPadChar). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5216 |
]. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5217 |
] ifFalse:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5218 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5219 |
"/ the number of after-decimalPoint characters |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5220 |
n := self size - idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5221 |
rest := afterPeriod - n. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5222 |
rest > 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5223 |
s := (self species new:rest withAll:(rightPadChar ? leftPadChar)). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5224 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5225 |
s := '' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5226 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5227 |
s := self , s. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5228 |
]. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5229 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5230 |
^ s leftPaddedTo:size with:leftPadChar |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5231 |
|
8874 | 5232 |
" |
5233 |
'123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:nil -> ' 123 ' |
|
5234 |
'123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.000' |
|
5235 |
'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
|
5236 |
'123.1' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.100' |
8874 | 5237 |
'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
|
5238 |
'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
|
5239 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5240 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5241 |
"Modified: 23.12.1995 / 13:08:18 / cg" |
9192 | 5242 |
! |
5243 |
||
5244 |
leftPaddedTo:size |
|
5245 |
"return a new string of length size, which contains the receiver |
|
5246 |
right-adjusted (i.e. padded on the left). |
|
5247 |
Characters on the left are filled with spaces. |
|
5248 |
If the receivers size is equal or greater than the length argument, |
|
5249 |
the original receiver is returned unchanged." |
|
5250 |
||
5251 |
^ self leftPaddedTo:size with:(Character space) |
|
5252 |
||
5253 |
" |
|
5254 |
'foo' leftPaddedTo:10 |
|
5255 |
'fooBar' leftPaddedTo:5 |
|
5256 |
123 printString leftPaddedTo:10 |
|
5257 |
" |
|
5258 |
! |
|
608 | 5259 |
|
5260 |
paddedTo:newSize |
|
5261 |
"return a new string consisting of the receivers characters, |
|
5262 |
plus spaces up to length. |
|
8874 | 5263 |
If the receivers size is equal or greater than the length argument, |
608 | 5264 |
the original receiver is returned unchanged." |
5265 |
||
5266 |
^ self paddedTo:newSize with:(Character space) |
|
5267 |
||
5268 |
" |
|
8874 | 5269 |
'foo' paddedTo:10 |
5270 |
123 printString paddedTo:10 |
|
15734 | 5271 |
'12345678901234' paddedTo:10 |
608 | 5272 |
" |
64 | 5273 |
! ! |
5274 |
||
9192 | 5275 |
!CharacterArray methodsFor:'printing & storing'! |
608 | 5276 |
|
5277 |
article |
|
17137 | 5278 |
"return an article string for the receiver. |
5279 |
The original code only looked at the first character being a vowel; |
|
5280 |
this has been enhanced by some heuristics - not perfect, still." |
|
608 | 5281 |
|
17241 | 5282 |
|firstChar secondChar thirdChar| |
608 | 5283 |
|
8874 | 5284 |
firstChar := (self at:1) asLowercase. |
5848 | 5285 |
((firstChar isVowel and:[firstChar ~~ $u]) or:[firstChar == $x]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5286 |
^ 'an' |
608 | 5287 |
]. |
17043 | 5288 |
|
5289 |
(self size >= 3) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5290 |
secondChar := (self at:2) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5291 |
thirdChar := (self at:3) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5292 |
(firstChar isVowel not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5293 |
and:[(secondChar isVowel or:[secondChar == $y]) not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5294 |
and:[thirdChar isVowel not ]]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5295 |
"/ exceptions: 3 non-vowels in a row: looks like an abbreviation |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5296 |
(self size > 4) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5297 |
(firstChar == $s) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5298 |
((secondChar == $c and:[thirdChar == $r]) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5299 |
or:[ (secondChar == $t and:[thirdChar == $r]) ]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5300 |
(self at:4) isVowel ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5301 |
^ 'a' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5302 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5303 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5304 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5305 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5306 |
"/ an abbreviation; treat x, s as vowels |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5307 |
(firstChar == $x or:[ firstChar == $s ]) ifTrue:[^ 'an']. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5308 |
] |
17043 | 5309 |
]. |
608 | 5310 |
^ 'a' |
5848 | 5311 |
|
5312 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5313 |
'uboot' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5314 |
'xmas' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5315 |
'alarm' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5316 |
'baby' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5317 |
'sql' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5318 |
'scr' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5319 |
'screen' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5320 |
'scrollbar' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5321 |
'scrs' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5322 |
'cvs' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5323 |
'cvssource' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5324 |
'symbol' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5325 |
'string' article. |
5848 | 5326 |
" |
608 | 5327 |
! |
5328 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5329 |
basicStoreString |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5330 |
"return a String for storing myself" |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5331 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5332 |
|s n index| |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5333 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5334 |
n := self occurrencesOf:$'. |
11320 | 5335 |
n ~~ 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5336 |
s := self species new:(n + 2 + self size). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5337 |
s at:1 put:$'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5338 |
index := 2. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5339 |
self do:[:thisChar | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5340 |
(thisChar == $') ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5341 |
s at:index put:thisChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5342 |
index := index + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5343 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5344 |
s at:index put:thisChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5345 |
index := index + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5346 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5347 |
s at:index put:$'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5348 |
^ s |
9192 | 5349 |
]. |
11320 | 5350 |
|
9192 | 5351 |
^ '''' , self , '''' |
15523 | 5352 |
|
5353 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5354 |
'''immutable'' string' asImmutableString basicStoreString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5355 |
'immutable string' asImmutableString basicStoreString |
15523 | 5356 |
" |
5357 |
||
5358 |
"Modified: / 14-07-2013 / 19:20:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
9192 | 5359 |
! |
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5360 |
|
11774
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5361 |
displayOn:aGCOrStream |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5362 |
"Compatibility |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5363 |
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
|
5364 |
OR: |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5365 |
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
|
5366 |
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
|
5367 |
(although the fallBack is to display its printString ...)" |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5368 |
|
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5369 |
"/ 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
|
5370 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
16738 | 5371 |
(aGCOrStream isStream) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5372 |
self storeOn:aGCOrStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5373 |
^ self |
11774
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5374 |
]. |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5375 |
^ super displayOn:aGCOrStream |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5376 |
! |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5377 |
|
608 | 5378 |
printOn:aStream |
5379 |
"print the receiver on aStream" |
|
5380 |
||
5381 |
aStream nextPutAll:self |
|
5382 |
! |
|
5383 |
||
5384 |
printString |
|
13079
111e7e456648
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
13073
diff
changeset
|
5385 |
"return a string for printing - that's myself" |
608 | 5386 |
|
5387 |
^ self |
|
3578 | 5388 |
! |
5389 |
||
5390 |
printWithQuotesDoubledOn:aStream |
|
5391 |
"put the raw storeString of myself on aStream" |
|
5392 |
||
5393 |
self do:[:thisChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5394 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5395 |
aStream nextPut:thisChar |
3578 | 5396 |
] |
5397 |
||
5398 |
"Modified: / 15.6.1998 / 17:21:17 / cg" |
|
5399 |
"Created: / 15.6.1998 / 17:22:13 / cg" |
|
12171 | 5400 |
! |
5401 |
||
15788 | 5402 |
printXmlQuotedOn:aStream |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5403 |
"convert aString to a valid XML string |
15788 | 5404 |
that can be used for attributes, text, comments an PIs |
5405 |
TODO: care for 16bit UNICODE string and escape chars ..." |
|
5406 |
||
5407 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5408 |
eachChar == $< ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5409 |
aStream nextPutAll:'<' "mapping needed for xml text" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5410 |
] ifFalse:[ eachChar == $& ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5411 |
aStream nextPutAll:'&' "mapping needed for all" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5412 |
] ifFalse:[ eachChar == $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5413 |
aStream nextPutAll:'>' "mapping needed for comments" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5414 |
] ifFalse:[ eachChar == $' ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5415 |
aStream nextPutAll:''' "mapping needed for attributes" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5416 |
] ifFalse:[ eachChar == $" ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5417 |
aStream nextPutAll:'"' "mapping needed for attributes" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5418 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5419 |
|codePoint| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5420 |
codePoint := eachChar codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5421 |
(codePoint < 16r20 or:[codePoint >= 16r7F]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5422 |
aStream nextPutAll:'&#'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5423 |
codePoint printOn:aStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5424 |
aStream nextPut:$;. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5425 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5426 |
aStream nextPut:eachChar |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5427 |
]]]]]] |
15788 | 5428 |
]. |
5429 |
! |
|
5430 |
||
5431 |
printXmlTextQuotedOn:aStream |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5432 |
"convert aString to a valid XML string |
15788 | 5433 |
that can be used for XML text. |
5434 |
Here line formatting characters are not escaped. |
|
5435 |
TODO: care for 16bit UNICODE string and escape chars ..." |
|
5436 |
||
5437 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5438 |
eachChar == $< ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5439 |
aStream nextPutAll:'<' "mapping needed for xml text" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5440 |
] ifFalse:[ eachChar == $& ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5441 |
aStream nextPutAll:'&' "mapping needed for all" |
15788 | 5442 |
"/ ] ifFalse:[ eachChar == $> ifTrue:[ |
5443 |
"/ aStream nextPutAll:'>' "mapping needed for comments" |
|
5444 |
"/ ] ifFalse:[ eachChar == $' ifTrue:[ |
|
5445 |
"/ aStream nextPutAll:''' "mapping needed for attributes" |
|
5446 |
"/ ] ifFalse:[ eachChar == $" ifTrue:[ |
|
5447 |
"/ aStream nextPutAll:'"' "mapping needed for attributes" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5448 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5449 |
|codePoint| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5450 |
codePoint := eachChar codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5451 |
((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
|
5452 |
or:[codePoint >= 16r7F]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5453 |
aStream nextPutAll:'&#'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5454 |
codePoint printOn:aStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5455 |
aStream nextPut:$;. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5456 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5457 |
aStream nextPut:eachChar |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5458 |
]]]"/]]] |
15788 | 5459 |
]. |
5460 |
! |
|
5461 |
||
12171 | 5462 |
printfWith:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
12177 | 5463 |
"Format and print the receiver with <argI> formatted in C style, |
12171 | 5464 |
as specified in the Unix C-language manual page for printf(3). |
15712 | 5465 |
Return the resulting string (i.e actually, this is more like an sprintf)." |
12177 | 5466 |
|
12171 | 5467 |
^ self printf:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
5468 |
||
5469 |
" |
|
12177 | 5470 |
Transcript showCR:('%d %05x %08o %b' printfWith:123 with:234 with:345 with:123) |
12171 | 5471 |
" |
15788 | 5472 |
! |
5473 |
||
5474 |
xmlQuotedPrintString |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5475 |
"convert aString to a valid XML string |
15788 | 5476 |
that can be used for attributes, text, comments an PIs |
5477 |
TODO: care for 16bit UNICODE string and escape chars ..." |
|
5478 |
||
5479 |
^ String streamContents:[:s| |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5480 |
self printXmlQuotedOn:s |
15788 | 5481 |
]. |
9192 | 5482 |
! ! |
5483 |
||
11955 | 5484 |
|
9192 | 5485 |
!CharacterArray methodsFor:'queries'! |
608 | 5486 |
|
4429 | 5487 |
bitsPerCharacter |
18662 | 5488 |
"return the underlying string's bitsPerCharacter |
4429 | 5489 |
(i.e. is it a regular String or a TwoByteString)" |
5490 |
||
8457 | 5491 |
|string max| |
5492 |
||
5493 |
(string := self string) ~~ self ifTrue:[ |
|
18662 | 5494 |
^ string bitsPerCharacter |
8457 | 5495 |
]. |
5496 |
||
5497 |
max := 8. |
|
5498 |
self do:[:eachCharacter | |
|
18662 | 5499 |
max := max max:(eachCharacter bitsPerCharacter) |
9192 | 5500 |
]. |
5501 |
^ max |
|
5502 |
||
5503 |
" |
|
5504 |
'hello' bitsPerCharacter |
|
5505 |
'hello' asText allBold bitsPerCharacter |
|
5506 |
" |
|
5507 |
! |
|
8457 | 5508 |
|
10903 | 5509 |
continuesWith:aString startingAt:startIndex |
5510 |
"return true, if the receiver beginning at startIndex |
|
5511 |
contains the characters in aString." |
|
5512 |
||
5513 |
|sz "{Class: SmallInteger }" |
|
5514 |
idx "{Class: SmallInteger }"| |
|
5515 |
||
5516 |
sz := aString size. |
|
5517 |
idx := startIndex. |
|
5518 |
||
5519 |
1 to:sz do:[:i | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5520 |
(self at:idx) ~~ (aString at:i) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5521 |
idx := idx + 1 |
10903 | 5522 |
]. |
5523 |
^ true |
|
5524 |
||
5525 |
" |
|
5526 |
'hello world' continuesWith:'world' startingAt:6 |
|
5527 |
'hello world' continuesWith:'world' startingAt:7 |
|
5528 |
" |
|
5529 |
||
5530 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
5531 |
"Modified: 26.7.1996 / 19:08:36 / cg" |
|
5532 |
! |
|
5533 |
||
5534 |
countWords |
|
5535 |
"return the number of words, which are separated by separators" |
|
5536 |
||
5537 |
|tally "{ Class: SmallInteger }" |
|
5538 |
start "{ Class: SmallInteger }" |
|
5539 |
mySize "{ Class: SmallInteger }" |
|
5540 |
stop ch| |
|
5541 |
||
5542 |
tally := 0. |
|
5543 |
start := 1. |
|
5544 |
mySize := self size. |
|
5545 |
[start <= mySize] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5546 |
ch := self at:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5547 |
ch isSeparator ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5548 |
start := start + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5549 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5550 |
stop := self indexOfSeparatorStartingAt:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5551 |
(stop == 0) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5552 |
stop := mySize + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5553 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5554 |
tally := tally + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5555 |
start := stop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5556 |
] |
10903 | 5557 |
]. |
5558 |
^ tally |
|
5559 |
||
5560 |
" |
|
5561 |
'hello world isnt this nice' countWords' |
|
5562 |
" |
|
5563 |
! |
|
5564 |
||
11788 | 5565 |
defaultElement |
5566 |
^ Character space |
|
5567 |
! |
|
5568 |
||
608 | 5569 |
encoding |
1311 | 5570 |
"return the strings encoding, as a symbol. |
7982 | 5571 |
Here, by default, we assume unicode-encoding. |
5572 |
Notice, that iso8859-1 is a true subset of unicode, |
|
8874 | 5573 |
and that singleByteStrings are therefore both unicode AND |
7982 | 5574 |
8859-1 encoded." |
5575 |
||
14168 | 5576 |
^ #unicode |
608 | 5577 |
! |
5578 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5579 |
hasChangeOfEmphasis |
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
5580 |
"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
|
5581 |
i.e. any non-normal (=emphasized) characters" |
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
5582 |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5583 |
^ false |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5584 |
|
1381 | 5585 |
"Created: 12.5.1996 / 12:31:39 / cg" |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5586 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5587 |
|
7995
8ddbb403d67b
+hasIcon and hasImage for LabelAndIcon compatibility
Claus Gittinger <cg@exept.de>
parents:
7991
diff
changeset
|
5588 |
hasIcon |
9191 | 5589 |
"for LabelAndIcon compatibility" |
5590 |
||
9192 | 5591 |
^ false |
5592 |
! |
|
5593 |
||
5594 |
hasImage |
|
5595 |
"for LabelAndIcon compatibility" |
|
5596 |
||
5597 |
^ false |
|
5598 |
! |
|
7995
8ddbb403d67b
+hasIcon and hasImage for LabelAndIcon compatibility
Claus Gittinger <cg@exept.de>
parents:
7991
diff
changeset
|
5599 |
|
1388 | 5600 |
heightOn:aGC |
5601 |
"return the size of the recevier in device units if displayed on aGC" |
|
5602 |
||
6528 | 5603 |
^ (aGC font onDevice:aGC device) heightOf:self |
1388 | 5604 |
|
5605 |
" |
|
8874 | 5606 |
'hello world' heightOn:(View new) |
1388 | 5607 |
" |
5608 |
||
5609 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
5610 |
"Modified: 12.5.1996 / 20:32:05 / cg" |
|
5611 |
! |
|
5612 |
||
15773 | 5613 |
isKeyword |
5614 |
"return true, if the receiver is a keyword message selector" |
|
5615 |
||
5616 |
^ self includes:$: |
|
5617 |
||
5618 |
" |
|
5619 |
#at:put: isKeyword |
|
5620 |
#at: isKeyword |
|
5621 |
#+ isKeyword |
|
5622 |
#size isKeyword |
|
5623 |
" |
|
5624 |
||
5625 |
"Created: / 1.11.1997 / 12:34:55 / cg" |
|
5626 |
"Modified: / 1.11.1997 / 12:36:37 / cg" |
|
5627 |
! |
|
5628 |
||
11828 | 5629 |
isLowercaseFirst |
5630 |
"return true, if the first character is a lowercase character." |
|
5631 |
||
5632 |
^ self size ~~ 0 and:[ self first isLowercase ] |
|
5633 |
||
5634 |
" |
|
12177 | 5635 |
'helloWorld' isLowercaseFirst |
5636 |
'HelloWorld' isLowercaseFirst |
|
11828 | 5637 |
" |
5638 |
! |
|
5639 |
||
5640 |
isUppercaseFirst |
|
5641 |
"return true, if the first character is an uppercase character." |
|
5642 |
||
5643 |
^ self size ~~ 0 and:[ self first isUppercase ] |
|
5644 |
||
5645 |
" |
|
12177 | 5646 |
'helloWorld' isUppercaseFirst |
5647 |
'HelloWorld' isUppercaseFirst |
|
11828 | 5648 |
" |
5649 |
! |
|
5650 |
||
15773 | 5651 |
keywords |
5652 |
"assuming the receiver is a keyword message selector, |
|
5653 |
return the individual keywords (i.e. break it up at colons) |
|
5654 |
and return these as a collection. |
|
5655 |
For binary and unary selectors, the result may be nonsense (an array containing the receiver)." |
|
5656 |
||
5657 |
|coll s part| |
|
5658 |
||
5659 |
coll := OrderedCollection new. |
|
5660 |
s := ReadStream on:self. |
|
5661 |
[s atEnd] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5662 |
part := s through:$:. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5663 |
coll add:part |
15773 | 5664 |
]. |
5665 |
^ coll asArray |
|
5666 |
||
5667 |
" |
|
5668 |
#at:put: keywords |
|
5669 |
#at: keywords |
|
5670 |
#+ keywords |
|
5671 |
#size keywords |
|
5672 |
" |
|
5673 |
||
5674 |
"Modified (Comment): / 30-06-2011 / 17:46:21 / cg" |
|
5675 |
! |
|
5676 |
||
9190 | 5677 |
knownAsSymbol |
5678 |
"for now, only single character strings are allowed as symbols. |
|
5679 |
This method is redefined in String." |
|
5680 |
||
5681 |
^ false |
|
5682 |
! |
|
5683 |
||
5684 |
leftIndent |
|
5685 |
"if the receiver starts with spaces, return the number of spaces |
|
5686 |
at the left - otherwise, return 0. |
|
9192 | 5687 |
If the receiver consists of spaces only, return the receivers size." |
5688 |
||
5689 |
|index "{Class: SmallInteger }" |
|
5690 |
end "{Class: SmallInteger }"| |
|
5691 |
||
5692 |
index := 1. |
|
5693 |
end := self size. |
|
5694 |
[index <= end] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5695 |
(self at:index) isSeparator ifFalse:[^ index - 1]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5696 |
index := index + 1 |
8350 | 5697 |
]. |
9192 | 5698 |
^ end |
5699 |
||
5700 |
" |
|
5701 |
' hello' leftIndent |
|
5702 |
'foo ' leftIndent |
|
9190 | 5703 |
' ' leftIndent |
5704 |
" |
|
5705 |
||
5706 |
"Modified: 20.4.1996 / 19:28:43 / cg" |
|
8350 | 5707 |
! |
5708 |
||
10437 | 5709 |
nameSpaceSelectorParts |
5710 |
"Answer the namespace and baseSelector parts of a namespace selector. |
|
5711 |
Namespace selectors are those generated by sends from a method in a different |
|
5712 |
namespace; they are prefixed by ':'<ns>'::'. |
|
5713 |
You cannot easily change this algorithm here, as it is also known by the VM's lookup function. |
|
5714 |
Experimental" |
|
5715 |
||
5716 |
|nsPart selPart idx| |
|
5717 |
||
5718 |
(self at:1) == $: ifFalse:[^ Array with:'' with:self]. |
|
5719 |
idx := self indexOf:$: startingAt:3. |
|
5720 |
idx == 0 ifTrue:[^ Array with:'' with:self]. |
|
5721 |
||
5722 |
(idx+2 > self size) ifTrue:[^ Array with:'' with:self]. |
|
5723 |
(self at:idx+1) == $: ifFalse:[^ Array with:'' with:self]. |
|
5724 |
nsPart := self copyFrom:2 to:idx-1. |
|
5725 |
selPart := self copyFrom:idx+2. |
|
5726 |
^ Array with:nsPart with:selPart |
|
5727 |
||
5728 |
"test: |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5729 |
self assert:('+' nameSpaceSelectorParts) = #('' '+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5730 |
self assert:(':+' nameSpaceSelectorParts) = #('' ':+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5731 |
self assert:(':Foo:+' nameSpaceSelectorParts) = #('' ':Foo:+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5732 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5733 |
self assert:(':Foo::+' nameSpaceSelectorParts) = #('Foo' '+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5734 |
self assert:(':Foo::bar:baz:' nameSpaceSelectorParts) = #('Foo' 'bar:baz:'). |
10437 | 5735 |
" |
5736 |
||
5737 |
"Created: / 05-03-2007 / 17:16:58 / cg" |
|
5738 |
"Modified: / 06-03-2007 / 11:51:15 / cg" |
|
5739 |
! |
|
5740 |
||
9190 | 5741 |
stringSpecies |
8874 | 5742 |
"return the underlying strings bitsPerCharacter |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5743 |
(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
|
5744 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5745 |
|string| |
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5746 |
|
15523 | 5747 |
string := self string. |
5748 |
string == self ifTrue:[^ self species]. |
|
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5749 |
^ string stringSpecies |
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5750 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5751 |
" |
8874 | 5752 |
'hello' stringSpecies |
9192 | 5753 |
'hello' asText allBold stringSpecies |
5754 |
" |
|
5755 |
! |
|
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5756 |
|
6653 | 5757 |
widthFrom:startIndex to:endIndex on:aGC |
5758 |
"return ths size of part of the recevier in device units if displayed on aGC" |
|
5759 |
||
5760 |
^ (aGC font onDevice:aGC device) widthOf:self from:startIndex to:endIndex |
|
5761 |
||
5762 |
" |
|
8874 | 5763 |
'hello world' widthFrom:1 to:5 on:(View new) |
5764 |
'hello' widthOn:(View new) |
|
6653 | 5765 |
" |
9192 | 5766 |
! |
6653 | 5767 |
|
1388 | 5768 |
widthOn:aGC |
5769 |
"return ths size of the recevier in device units if displayed on aGC" |
|
5770 |
||
6528 | 5771 |
^ (aGC font onDevice:aGC device) widthOf:self |
1388 | 5772 |
|
5773 |
" |
|
8874 | 5774 |
'hello world' widthOn:(View new) |
1388 | 5775 |
" |
5776 |
||
5777 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
2554 | 5778 |
"Modified: 17.4.1997 / 12:50:23 / cg" |
608 | 5779 |
! ! |
5780 |
||
18721 | 5781 |
|
608 | 5782 |
!CharacterArray methodsFor:'special string converting'! |
5783 |
||
16759 | 5784 |
asUnixFilenameString |
5785 |
"return a new string consisting of receiver's characters |
|
5786 |
with all \-characters replaced by /-characters. |
|
5787 |
If there are no backslashes, return the original" |
|
5788 |
||
5789 |
^ self copyReplaceAll:$\ with:$/ ifNone:self |
|
5790 |
||
5791 |
" |
|
5792 |
'hello\world' asUnixFilenameString |
|
5793 |
" |
|
5794 |
||
5795 |
"Modified: / 18.7.1998 / 22:53:02 / cg" |
|
5796 |
! |
|
5797 |
||
14768 | 5798 |
expandPlaceholders:escapeCharacter with:argArrayOrDictionary |
5799 |
"this is the generic version of the old %-escaping method, allowing for an arbitrary |
|
5800 |
escape character to be used (typically $$ or $% are effectively used). |
|
5801 |
Return a copy of the receiver, where all %i escapes are |
|
5802 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
|
5803 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
|
5804 |
in the new string 'hello world; how is this'. |
|
5805 |
As an extension, the argument may also be a dictionary, providing |
|
5806 |
values for symbolic keys. |
|
5807 |
In this case, %a .. %z and %(...) are also allowed. |
|
5808 |
(%1..%9 require a numeric key in the dictionary, however) |
|
5809 |
To get a '%' character, use a '%%'-escape. |
|
5810 |
To get an integer-indexed placeHolder followed by another digit, |
|
5811 |
or an index > 9, you must use %(digit). |
|
5812 |
See also bindWith:... for VisualAge compatibility." |
|
5813 |
||
5814 |
|stream| |
|
5815 |
||
18269 | 5816 |
stream := (TextStream ? CharacterWriteStream) on:(self species uninitializedNew:self size + 20). |
14768 | 5817 |
self expandPlaceholders:escapeCharacter with:argArrayOrDictionary on:stream. |
5818 |
^ stream contents. |
|
5819 |
||
5820 |
||
5821 |
" |
|
5822 |
'hello %1' expandPlaceholdersWith:#('world') |
|
5823 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
5824 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
5825 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
|
5826 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) |
|
5827 |
'%%10 gives %10' expandPlaceholdersWith:#(123) |
|
5828 |
'%%(10) gives %(10)' expandPlaceholdersWith:#(123) |
|
5829 |
'%test gives %1' expandPlaceholdersWith:#(123) |
|
5830 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' allBold } |
|
5831 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' } |
|
5832 |
" |
|
5833 |
||
5834 |
" |
|
5835 |
|dict| |
|
5836 |
||
5837 |
dict := Dictionary new. |
|
5838 |
dict at:1 put:'one'. |
|
5839 |
dict at:$a put:'AAAAA'. |
|
5840 |
dict at:$b put:[ Time now ]. |
|
5841 |
dict at:'foo' put:[ Date today ]. |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5842 |
'hello $1 %a $b %(foo) $foo ' expandPlaceholders:$$ with:dict. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5843 |
'hello $1 %a $b %(foo) $foo ' expandPlaceholders:$% with:dict. |
14768 | 5844 |
" |
5845 |
||
5846 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
|
5847 |
! |
|
5848 |
||
14765 | 5849 |
expandPlaceholders:escapeCharacter with:argArrayOrDictionary on:aStream |
5850 |
"this is the generic version of the old %-escaping method, allowing for an arbitrary |
|
5851 |
escape character to be used (typically $$ or $% are effectively used). |
|
18425 | 5852 |
|
14765 | 5853 |
Write the receiver to aStream, where all %i escapes are |
5854 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
|
5855 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
|
5856 |
in the new string 'hello world; how is this'. |
|
18425 | 5857 |
|
17192 | 5858 |
As an extension, the argument may also be a dictionary, providing values for symbolic keys. |
14765 | 5859 |
In this case, %a .. %z and %(...) are also allowed. |
5860 |
(%1..%9 require a numeric key in the dictionary, however) |
|
17192 | 5861 |
Also, the values in argArrayOrDictionary may be blocks. |
18425 | 5862 |
|
14765 | 5863 |
To get a '%' character, use a '%%'-escape. |
5864 |
To get an integer-indexed placeHolder followed by another digit, |
|
5865 |
or an index > 9, you must use %(digit). |
|
18425 | 5866 |
|
14765 | 5867 |
See also bindWith:... for VisualAge compatibility. |
5868 |
Use %<cr> to insert a CR and %<tab> to insert a TAB." |
|
5869 |
||
5870 |
|next v key |
|
5871 |
idx "{ SmallInteger }" |
|
5872 |
idx2 "{ SmallInteger }" |
|
5873 |
start "{ SmallInteger }" |
|
5874 |
stop "{ SmallInteger }"| |
|
5875 |
||
5876 |
stop := self size. |
|
5877 |
start := 1. |
|
5878 |
[start <= stop] whileTrue:[ |
|
18425 | 5879 |
idx := self indexOf:escapeCharacter startingAt:start. |
5880 |
(idx == 0 or:[idx == stop]) ifTrue:[ |
|
5881 |
aStream nextPutAll:self startingAt:start to:stop. |
|
5882 |
^ self. |
|
5883 |
]. |
|
5884 |
"found an escapeCharacter" |
|
5885 |
aStream nextPutAll:self startingAt:start to:(idx - 1). |
|
5886 |
next := self at:(idx + 1). |
|
5887 |
(next == escapeCharacter) ifTrue:[ |
|
5888 |
aStream nextPut:escapeCharacter. |
|
5889 |
] ifFalse:[ |
|
5890 |
next == $< ifTrue:[ |
|
5891 |
idx2 := self indexOf:$> startingAt:idx+2. |
|
5892 |
key := self copyFrom:idx+2 to:idx2-1. |
|
5893 |
idx := idx2 - 1. |
|
5894 |
key := key asSymbolIfInterned. |
|
5895 |
(#(cr tab nl return lf ff null) includesIdentical:key) ifTrue:[ |
|
5896 |
aStream nextPut:(Character perform:key). |
|
5897 |
]. |
|
5898 |
] ifFalse:[ |
|
5899 |
next isDigit ifTrue:[ |
|
5900 |
v := argArrayOrDictionary at:(next digitValue) ifAbsent:'' |
|
5901 |
] ifFalse:[ |
|
5902 |
next == $( ifTrue:[ |
|
5903 |
idx2 := self indexOf:$) startingAt:idx+2. |
|
5904 |
key := self copyFrom:idx+2 to:idx2-1. |
|
5905 |
idx := idx2 - 1. |
|
5906 |
(argArrayOrDictionary includesKey:key) ifTrue:[ |
|
5907 |
v := argArrayOrDictionary at:key |
|
5908 |
] ifFalse:[ |
|
5909 |
key := key asSymbolIfInterned ? key. |
|
5910 |
(argArrayOrDictionary includesKey:key) ifTrue:[ |
|
5911 |
v := argArrayOrDictionary at:key |
|
5912 |
] ifFalse:[ |
|
5913 |
(key size == 1 and:[ argArrayOrDictionary includesKey:(key at:1)]) ifTrue:[ |
|
5914 |
v := argArrayOrDictionary at:(key at:1) |
|
5915 |
] ifFalse:[ |
|
5916 |
key isNumeric ifTrue:[ |
|
5917 |
key := Integer readFrom:key onError:nil. |
|
5918 |
]. |
|
5919 |
v := argArrayOrDictionary at:key ifAbsent:'' |
|
5920 |
] |
|
5921 |
]. |
|
5922 |
]. |
|
5923 |
] ifFalse:[ |
|
5924 |
(next isLetter and:[argArrayOrDictionary isSequenceable not "is a Dictionary"]) ifTrue:[ |
|
5925 |
"so next is a non-numeric single character." |
|
5926 |
v := argArrayOrDictionary |
|
5927 |
at:next |
|
5928 |
ifAbsent:[ |
|
5929 |
"try symbol instead of character" |
|
5930 |
argArrayOrDictionary |
|
5931 |
at:next asSymbol |
|
5932 |
ifAbsent:[String with:escapeCharacter with:next]. |
|
5933 |
]. |
|
5934 |
] ifFalse:[ |
|
5935 |
v := String with:$% with:next. |
|
5936 |
]. |
|
5937 |
] |
|
5938 |
]. |
|
5939 |
"/ v notNil ifTrue:[ |
|
5940 |
v isBlock ifTrue:[ |
|
5941 |
v := v value |
|
5942 |
]. |
|
5943 |
||
5944 |
v printOn:aStream. |
|
5945 |
"/ ]. |
|
5946 |
] |
|
5947 |
]. |
|
5948 |
start := idx + 2 |
|
14765 | 5949 |
]. |
5950 |
||
5951 |
" |
|
5952 |
String streamContents:[:s| |
|
18425 | 5953 |
'hello %1' expandPlaceholders:$% with:#('world') on:s. |
5954 |
s cr. |
|
5955 |
'hello $1; how is $2' expandPlaceholders:$$ with:#('world' 'this') on:s. |
|
5956 |
s cr. |
|
5957 |
'hello %2; how is %1' expandPlaceholders:$% with:#('world' 'this') on:s. |
|
5958 |
s cr. |
|
5959 |
'%1 plus %2 gives %3 ' expandPlaceholders:$% with:#(4 5 9) on:s. |
|
5960 |
s cr. |
|
5961 |
'%%(1)0 gives %(1)0' expandPlaceholders:$% with:#(123) on:s. |
|
5962 |
s cr. |
|
5963 |
'%%10 gives %10' expandPlaceholders:$% with:#(123) on:s. |
|
5964 |
s cr. |
|
5965 |
'%%(10) gives %(10) %<cr>%<tab>next line' expandPlaceholders:$% with:#(123) on:s. |
|
5966 |
s cr. |
|
5967 |
'%%test gives %test' expandPlaceholders:$% with:#(123) on:s. |
|
5968 |
s cr. |
|
5969 |
'|%%<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
|
5970 |
] |
14765 | 5971 |
" |
5972 |
||
5973 |
" |
|
5974 |
|dict| |
|
5975 |
||
5976 |
dict := Dictionary new. |
|
5977 |
dict at:1 put:'one'. |
|
5978 |
dict at:$a put:'AAAAA'. |
|
5979 |
dict at:$b put:[ Time now ]. |
|
5980 |
String streamContents:[:s| |
|
18425 | 5981 |
'hello $1 $a $b' expandPlaceholders:$$ with:dict on:s. |
14765 | 5982 |
]. |
5983 |
" |
|
5984 |
||
18425 | 5985 |
"using blocks: |
5986 |
|dict| |
|
5987 |
||
5988 |
dict := Dictionary new. |
|
5989 |
dict at:'time' put:[Time now printString]. |
|
5990 |
dict at:'date' put:[Date today printString]. |
|
5991 |
String streamContents:[:s| |
|
5992 |
'it is $(time) $(date)' expandPlaceholders:$$ with:dict on:s. |
|
5993 |
]. |
|
5994 |
" |
|
5995 |
||
14765 | 5996 |
"Modified: / 18-11-2010 / 15:43:28 / cg" |
5997 |
! |
|
5998 |
||
9192 | 5999 |
expandPlaceholdersWith:argArrayOrDictionary |
608 | 6000 |
"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
|
6001 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
608 | 6002 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
6003 |
in the new string 'hello world; how is this'. |
|
18425 | 6004 |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6005 |
As an extension, the argument may also be a dictionary, providing |
7313 | 6006 |
values for symbolic keys. |
4842 | 6007 |
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
|
6008 |
(%1..%9 require a numeric key in the dictionary, however) |
18425 | 6009 |
Also, the values in argArrayOrDictionary may be blocks. |
6010 |
||
608 | 6011 |
To get a '%' character, use a '%%'-escape. |
7313 | 6012 |
To get an integer-indexed placeHolder followed by another digit, |
6013 |
or an index > 9, you must use %(digit). |
|
608 | 6014 |
See also bindWith:... for VisualAge compatibility." |
6015 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6016 |
|stream| |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6017 |
|
18269 | 6018 |
stream := (TextStream ? CharacterWriteStream) on:(self species uninitializedNew:self size + 20). |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6019 |
self expandPlaceholdersWith:argArrayOrDictionary on:stream. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6020 |
^ stream contents. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6021 |
|
608 | 6022 |
|
6023 |
" |
|
8874 | 6024 |
'hello %1' expandPlaceholdersWith:#('world') |
6025 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
6026 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
6027 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
|
6028 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) |
|
6029 |
'%%10 gives %10' expandPlaceholdersWith:#(123) |
|
6030 |
'%%(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
|
6031 |
'%test gives %1' expandPlaceholdersWith:#(123) |
11028
cb1ee3ddd91a
expandPlaceHolders: care fr Text with emphasis
Claus Gittinger <cg@exept.de>
parents:
11018
diff
changeset
|
6032 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' allBold } |
cb1ee3ddd91a
expandPlaceHolders: care fr Text with emphasis
Claus Gittinger <cg@exept.de>
parents:
11018
diff
changeset
|
6033 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' } |
608 | 6034 |
" |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
6035 |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6036 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6037 |
|dict| |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6038 |
|
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6039 |
dict := Dictionary new. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6040 |
dict at:1 put:'one'. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6041 |
dict at:$a put:'AAAAA'. |
8794
a5df33935142
nindWith supports blocks in the value dictionary
Claus Gittinger <cg@exept.de>
parents:
8710
diff
changeset
|
6042 |
dict at:$b put:[ Time now ]. |
12316
3e78905d70a9
comment/format in: #expandPlaceholdersWith:
Claus Gittinger <cg@exept.de>
parents:
12196
diff
changeset
|
6043 |
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
|
6044 |
'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
|
6045 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6046 |
|
2737
9f29aecea39d
care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents:
2736
diff
changeset
|
6047 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
9192 | 6048 |
! |
6049 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6050 |
expandPlaceholdersWith:argArrayOrDictionary on:aStream |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6051 |
"write the receiver to aStream, where all %i escapes are |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6052 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6053 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6054 |
in the new string 'hello world; how is this'. |
18425 | 6055 |
|
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6056 |
As an extension, the argument may also be a dictionary, providing |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6057 |
values for symbolic keys. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6058 |
In this case, %a .. %z and %(...) are also allowed. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6059 |
(%1..%9 require a numeric key in the dictionary, however) |
18425 | 6060 |
Also, the values in argArrayOrDictionary may be blocks. |
6061 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6062 |
To get a '%' character, use a '%%'-escape. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6063 |
To get an integer-indexed placeHolder followed by another digit, |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6064 |
or an index > 9, you must use %(digit). |
18425 | 6065 |
|
10935 | 6066 |
See also bindWith:... for VisualAge compatibility. |
10939
d0ca31c1d1e9
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10935
diff
changeset
|
6067 |
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
|
6068 |
|
14765 | 6069 |
^ self expandPlaceholders:$% with:argArrayOrDictionary on:aStream |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6070 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6071 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6072 |
String streamContents:[:s| |
18425 | 6073 |
'hello %1' expandPlaceholdersWith:#('world') on:s. |
6074 |
s cr. |
|
6075 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') on:s. |
|
6076 |
s cr. |
|
6077 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') on:s. |
|
6078 |
s cr. |
|
6079 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) on:s. |
|
6080 |
s cr. |
|
6081 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) on:s. |
|
6082 |
s cr. |
|
6083 |
'%%10 gives %10' expandPlaceholdersWith:#(123) on:s. |
|
6084 |
s cr. |
|
6085 |
'%%(10) gives %(10) %<cr>%<tab>next line' expandPlaceholdersWith:#(123) on:s. |
|
6086 |
s cr. |
|
6087 |
'%test gives %1' expandPlaceholdersWith:#(123) on:s. |
|
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6088 |
] |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6089 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6090 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6091 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6092 |
|dict| |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6093 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6094 |
dict := Dictionary new. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6095 |
dict at:1 put:'one'. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6096 |
dict at:$a put:'AAAAA'. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6097 |
dict at:$b put:[ Time now ]. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6098 |
String streamContents:[:s| |
18425 | 6099 |
'hello %1 %a %b' expandPlaceholdersWith:dict on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6100 |
]. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6101 |
" |
13008
a27647c36b31
changed: #expandPlaceholdersWith:on:
Claus Gittinger <cg@exept.de>
parents:
12925
diff
changeset
|
6102 |
|
13138
d2eb0eba5907
changed: #expandPlaceholdersWith:on:
Claus Gittinger <cg@exept.de>
parents:
13137
diff
changeset
|
6103 |
"Modified: / 18-11-2010 / 15:43:28 / cg" |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6104 |
! |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6105 |
|
9230 | 6106 |
firstLine |
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6107 |
"return the first line of a multiline string" |
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6108 |
|
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6109 |
^ self asCollectionOfSubCollectionsSeparatedBy:(Character cr) do:[:line | ^ line]. |
9230 | 6110 |
|
6111 |
" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6112 |
'hello' firstLine |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6113 |
'1\2\3' withCRs firstLine |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6114 |
'\1\2\3' withCRs firstLine |
9230 | 6115 |
" |
6116 |
! |
|
6117 |
||
13987 | 6118 |
tokensBasedOn:aCharacter |
6119 |
"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
|
6120 |
asCollectionOfSubstringsSeparatedBy:" |
13987 | 6121 |
|
6122 |
^ self asCollectionOfSubstringsSeparatedBy:aCharacter |
|
6123 |
||
6124 |
" |
|
6125 |
'hello:world:isnt:this nice' tokensBasedOn:$: |
|
6126 |
'foo,bar,baz' tokensBasedOn:$, |
|
6127 |
'/etc/passwd' asFilename readStream nextLine tokensBasedOn:$: |
|
6128 |
" |
|
6129 |
! |
|
6130 |
||
6131 |
withCEscapes |
|
16863 | 6132 |
"return a new string consisting of receiver's characters |
13987 | 6133 |
with all special and unprintable characters replaced by \X-character escapes. |
6134 |
(similar to the way C-language literal Strings are represented). |
|
6135 |
The resulting string will contain only 7-bit ascii characters. |
|
6136 |
Emphasis is not supported. |
|
6137 |
The following escapes are generated: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6138 |
\' single quote character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6139 |
\dQuote double quote character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6140 |
\r return character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6141 |
\r return character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6142 |
\n newline character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6143 |
\t tab character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6144 |
\\ the \ character itself |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6145 |
\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
|
6146 |
\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
|
6147 |
\Unnnnnnnn eight digit hex number defining the characters ascii value |
16863 | 6148 |
This is the opposite of withoutCEscapes. |
17000 | 6149 |
|
6150 |
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
|
6151 |
but it cannot be changed easily, as these methods are already used heavily |
13987 | 6152 |
" |
6153 |
||
6154 |
|anyEscapeNeeded out seq| |
|
6155 |
||
6156 |
" |
|
6157 |
first, check if any escape is needed and return the receiver unchanged if not |
|
6158 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6159 |
anyEscapeNeeded := self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6160 |
contains:[:ch | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6161 |
((ch codePoint between:32 and:126) not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6162 |
or:[ch == $' or:[ch == $"]]) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6163 |
]. |
13987 | 6164 |
anyEscapeNeeded ifFalse:[ ^ self ]. |
6165 |
||
6166 |
self hasChangeOfEmphasis ifTrue:[ self error:'emphasis not supported' ]. |
|
6167 |
||
18269 | 6168 |
out := WriteStream on:(String uninitializedNew:self size-1). |
13987 | 6169 |
|
6170 |
self do:[:ch | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6171 |
|cp| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6172 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6173 |
(ch == $' or:[ch == $"]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6174 |
out nextPut:$\. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6175 |
out nextPut:ch. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6176 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6177 |
(ch codePoint between:32 and:126) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6178 |
out nextPut:ch |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6179 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6180 |
ch == Character return ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6181 |
seq := '\r' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6182 |
] ifFalse:[ ch == Character nl ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6183 |
seq := '\n' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6184 |
] ifFalse:[ ch == Character tab ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6185 |
seq := '\t' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6186 |
] ifFalse:[ ch == $\ ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6187 |
seq := '\\' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6188 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6189 |
cp := ch codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6190 |
cp <= 16rFF ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6191 |
seq := '\x' , (cp printStringRadix:16 padTo:2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6192 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6193 |
cp <= 16rFFFF ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6194 |
seq := '\u' , (cp printStringRadix:16 padTo:4) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6195 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6196 |
seq := '\U',(cp printStringRadix:16 padTo:8) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6197 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6198 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6199 |
]]]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6200 |
out nextPutAll:seq |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6201 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6202 |
]. |
13987 | 6203 |
]. |
6204 |
^ out contents |
|
6205 |
||
6206 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6207 |
'hello\n\tworld' withoutCEscapes. |
17000 | 6208 |
'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
|
6209 |
('hello ',(Character value:16r1234),' world') withCEscapes |
13987 | 6210 |
" |
6211 |
||
6212 |
"Created: / 25-01-2012 / 11:08:16 / cg" |
|
6213 |
! |
|
6214 |
||
9192 | 6215 |
withCRs |
17205 | 6216 |
"return a new string consisting of the receiver's characters |
16757 | 6217 |
with all \-characters replaced by cr-characters. |
6218 |
If there are no backslashes, return the original" |
|
6219 |
||
16759 | 6220 |
^ self copyReplaceAll:$\ with:(Character cr) ifNone:self |
9192 | 6221 |
|
6222 |
" |
|
6223 |
'hello\world' withCRs |
|
6224 |
" |
|
6225 |
||
6226 |
"Modified: / 18.7.1998 / 22:53:02 / cg" |
|
6227 |
! |
|
6228 |
||
6229 |
withEscapes |
|
15405 | 6230 |
<resource: #obsolete> |
13987 | 6231 |
"has been renamed; the name withEscapes is misleading" |
6232 |
||
6233 |
self obsoleteMethodWarning:'use withoutCEscapes'. |
|
6234 |
^ self withoutCEscapes. |
|
6235 |
||
6236 |
"Modified: / 25-01-2012 / 10:42:30 / cg" |
|
9192 | 6237 |
! |
6238 |
||
6239 |
withMatchEscapes |
|
4117 | 6240 |
"return a copy of the receiver with all match characters escaped |
6241 |
by $\ characters (to be usable as a match string). |
|
6242 |
Return the receiver, if there are none." |
|
6243 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6244 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6245 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6246 |
escape := self class matchEscapeCharacter. |
4117 | 6247 |
|
6248 |
in := self readStream. |
|
7986 | 6249 |
out := WriteStream on:(self species new:self size). |
4117 | 6250 |
[in atEnd] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6251 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6252 |
(c == escape or:['*[#' includes:c]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6253 |
out nextPut:$\. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6254 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6255 |
out nextPut:c. |
4117 | 6256 |
]. |
6257 |
^ out contents. |
|
6258 |
||
6259 |
" |
|
8874 | 6260 |
'*foo' withMatchEscapes |
6261 |
'\*foo' withMatchEscapes |
|
6262 |
'*foo' withMatchEscapes |
|
6263 |
'\\*foo' withMatchEscapes |
|
6264 |
'foo*' withMatchEscapes |
|
6265 |
'foo\*' withMatchEscapes |
|
6266 |
'foo\' withMatchEscapes |
|
6267 |
'f*o*o' withMatchEscapes |
|
4117 | 6268 |
" |
6269 |
||
6270 |
"Modified: 2.4.1997 / 18:13:04 / cg" |
|
9192 | 6271 |
! |
6272 |
||
14992 | 6273 |
withSeparatorsCompacted |
6274 |
"return a new string with each sequence of whiteSpace replaced by a single space character. |
|
6275 |
Preserves a leading/trailing space." |
|
6276 |
||
6277 |
^ self species streamContents:[:s | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6278 |
|skipping| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6279 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6280 |
skipping := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6281 |
1 to:self size do:[:idx | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6282 |
|char| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6283 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6284 |
char := self at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6285 |
char isSeparator ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6286 |
s nextPut:char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6287 |
skipping := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6288 |
] ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6289 |
skipping ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6290 |
s nextPut:(Character space). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6291 |
skipping := true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6292 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6293 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6294 |
] |
14992 | 6295 |
] |
6296 |
||
6297 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6298 |
'hello wwww' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6299 |
'hello wwww' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6300 |
' hello wwww' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6301 |
' hello wwww ' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6302 |
' hello wwww ' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6303 |
'hel lo www w' withSeparatorsCompacted |
14992 | 6304 |
" |
6305 |
! |
|
6306 |
||
18464 | 6307 |
withSeparatorsReplacedBy:replacementCharacter |
6308 |
"return a new string with each separator (whitespace) replaced by replacementCharacter. |
|
6309 |
Typically used with space as replacementCharacter" |
|
6310 |
||
6311 |
^ self species streamContents:[:s | |
|
6312 |
self do:[:ch | |
|
6313 |
ch isSeparator ifTrue:[ |
|
6314 |
s nextPut:replacementCharacter |
|
6315 |
] ifFalse:[ |
|
6316 |
s nextPut:ch. |
|
6317 |
] |
|
6318 |
] |
|
6319 |
] |
|
6320 |
||
6321 |
" |
|
6322 |
'hello wwww' withSeparatorsReplacedBy:$* |
|
6323 |
'hello ww ww' withSeparatorsReplacedBy:$* |
|
6324 |
' hello wwww' withSeparatorsReplacedBy:$* |
|
6325 |
'hel lo www w' withSeparatorsReplacedBy:$* |
|
6326 |
'hel |
|
6327 |
lo www |
|
6328 |
w' withSeparatorsReplacedBy:$* |
|
6329 |
" |
|
6330 |
! |
|
6331 |
||
9192 | 6332 |
withTabs |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6333 |
"return a string consisting of the receivers characters |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6334 |
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
|
6335 |
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
|
6336 |
otherwise a new string is returned. |
8874 | 6337 |
Limitation: only the very first spaces are replaced |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6338 |
(i.e. if the receiver contains newLine characters, |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6339 |
no tabs are inserted after those lineBreaks)" |
8874 | 6340 |
|
6341 |
|idx "{ SmallInteger }" |
|
6342 |
nTabs "{ SmallInteger }" |
|
608 | 6343 |
newString| |
6344 |
||
6345 |
idx := self findFirst:[:c | (c ~~ Character space)]. |
|
6346 |
nTabs := (idx-1) // 8. |
|
5815
4acdd87a77d4
// can return negative numbers.
Stefan Vogel <sv@exept.de>
parents:
5795
diff
changeset
|
6347 |
nTabs <= 0 ifTrue:[^ self]. |
608 | 6348 |
|
6349 |
"any tabs" |
|
15523 | 6350 |
newString := self species new:(self size - (nTabs * 7)). |
608 | 6351 |
newString atAll:(1 to:nTabs) put:(Character tab). |
6352 |
newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1). |
|
6353 |
^ newString |
|
6354 |
||
6355 |
" |
|
8874 | 6356 |
'12345678901234567890' withTabs |
6357 |
' 8901234567890' withTabs |
|
6358 |
' 901234567890' withTabs |
|
608 | 6359 |
' 67890' withTabs |
6360 |
' 7890' withTabs |
|
6361 |
' 890' withTabs |
|
6362 |
" |
|
9192 | 6363 |
! |
6364 |
||
6365 |
withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6366 |
"return a string consisting of the receivers characters, |
8874 | 6367 |
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
|
6368 |
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
|
6369 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6370 |
This does handle multiline strings." |
608 | 6371 |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6372 |
^ self withTabsExpanded:8 |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6373 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6374 |
" |
8874 | 6375 |
('1' , Character tab asString , 'x') withTabsExpanded |
6376 |
('12345' , Character tab asString , 'x') withTabsExpanded |
|
6377 |
('123456' , Character tab asString , 'x') withTabsExpanded |
|
6378 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
|
6379 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
|
6380 |
('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
|
6381 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6382 |
(String with:Character tab |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6383 |
with:Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6384 |
with:$1) withTabsExpanded |
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6385 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6386 |
(String with:Character tab |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6387 |
with:$1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6388 |
with:Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6389 |
with:$2) withTabsExpanded |
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6390 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6391 |
(String with:Character tab |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6392 |
with:$1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6393 |
with:Character cr |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6394 |
with:Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6395 |
with:$2) withTabsExpanded |
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6396 |
" |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6397 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6398 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
9192 | 6399 |
! |
6400 |
||
6401 |
withTabsExpanded:numSpaces |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6402 |
"return a string consisting of the receivers characters, |
8874 | 6403 |
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
|
6404 |
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
|
6405 |
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
|
6406 |
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
|
6407 |
|
8874 | 6408 |
|col "{ SmallInteger }" |
1381 | 6409 |
str ch |
6410 |
dstIdx "{ SmallInteger }" |
|
6411 |
newSz "{ SmallInteger }" |
|
6412 |
sz "{ SmallInteger }" |
|
6413 |
hasEmphasis e| |
|
608 | 6414 |
|
6415 |
(self includes:(Character tab)) ifFalse:[^ self]. |
|
1381 | 6416 |
|
6417 |
sz := self size. |
|
6418 |
||
6419 |
"/ count the new size first, instead of |
|
6420 |
"/ multiple resizing (better for large strings) |
|
6421 |
||
6422 |
col := 1. newSz := 0. |
|
6423 |
1 to:sz do:[:srcIdx | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6424 |
ch := self at:srcIdx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6425 |
ch == Character tab ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6426 |
col := col + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6427 |
newSz := newSz + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6428 |
ch == Character cr ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6429 |
col := 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6430 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6431 |
] ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6432 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6433 |
newSz := newSz + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6434 |
col := col + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6435 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6436 |
] |
608 | 6437 |
]. |
1381 | 6438 |
|
18258
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
6439 |
self isText ifTrue:[ |
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
6440 |
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
|
6441 |
] ifFalse:[ |
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
6442 |
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
|
6443 |
]. |
1381 | 6444 |
|
6445 |
hasEmphasis := self hasChangeOfEmphasis. |
|
6446 |
||
6447 |
col := 1. dstIdx := 1. |
|
6448 |
1 to:sz do:[:srcIdx | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6449 |
ch := self at:srcIdx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6450 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6451 |
ch == Character tab ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6452 |
col := col + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6453 |
ch == Character cr ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6454 |
col := 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6455 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6456 |
hasEmphasis ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6457 |
e := self emphasisAt:srcIdx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6458 |
str emphasisAt:dstIdx put:e |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6459 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6460 |
str at:dstIdx put:ch. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6461 |
dstIdx := dstIdx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6462 |
] ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6463 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6464 |
str at:dstIdx put:Character space. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6465 |
dstIdx := dstIdx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6466 |
col := col + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6467 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6468 |
] |
1381 | 6469 |
]. |
6470 |
^ str |
|
608 | 6471 |
|
6472 |
" |
|
8874 | 6473 |
('1' , Character tab asString , 'x') withTabsExpanded |
6474 |
('1' , Character tab asString , 'x') withTabsExpanded:4 |
|
6475 |
('12345' , Character tab asString , 'x') withTabsExpanded |
|
6476 |
('123456' , Character tab asString , 'x') withTabsExpanded |
|
6477 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
|
6478 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
|
6479 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6480 |
|
608 | 6481 |
(String with:Character tab |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6482 |
with:Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6483 |
with:$1) withTabsExpanded |
608 | 6484 |
|
6485 |
(String with:Character tab |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6486 |
with:$1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6487 |
with:Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6488 |
with:$2) withTabsExpanded |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6489 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6490 |
(String with:Character tab |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6491 |
with:$1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6492 |
with:Character cr |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6493 |
with:Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6494 |
with:$2) withTabsExpanded |
608 | 6495 |
" |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6496 |
|
18258
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
6497 |
"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
|
6498 |
"Modified: / 21-04-2015 / 15:40:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9192 | 6499 |
! |
6500 |
||
13987 | 6501 |
withoutAllSpaces |
16855 | 6502 |
"return a copy of the receiver with all whitespace removed" |
6503 |
||
13987 | 6504 |
^ self asCollectionOfWords asStringWith:''. |
6505 |
"/ |col string| |
|
6506 |
"/ |
|
6507 |
"/ col := self asCollectionOfWords. |
|
6508 |
"/ string := String new. |
|
6509 |
"/ col do:[:el | |
|
6510 |
"/ string := string,el |
|
6511 |
"/ ]. |
|
6512 |
"/ ^string |
|
6513 |
||
6514 |
" |
|
6515 |
'hello wwww' withoutAllSpaces |
|
6516 |
'hel lo www w' withoutAllSpaces |
|
6517 |
" |
|
6518 |
||
6519 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
6520 |
! |
|
6521 |
||
6522 |
withoutCEscapes |
|
15628 | 6523 |
"return a new string consisting of receiver's characters |
13987 | 6524 |
with all \X-character escapes replaced by corresponding-characters. |
6525 |
(similar to the way C-language Strings are converted). |
|
6526 |
The following escapes are supported: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6527 |
\r return character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6528 |
\n newline character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6529 |
\b backspace character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6530 |
\f formfeed character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6531 |
\t tab character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6532 |
\e escape character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6533 |
\\ the \ character itself |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6534 |
\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
|
6535 |
\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
|
6536 |
\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
|
6537 |
\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
|
6538 |
\other other |
13987 | 6539 |
|
6540 |
Notice, that \' is NOT a valid escape, since the general syntax of |
|
6541 |
string constants is not affected by this method. |
|
6542 |
||
6543 |
Although easily implementable, this is NOT done automatically |
|
6544 |
by the compiler (due to a lack of a language standard for this). |
|
6545 |
However, the compiler may detect sends ot #withEscapes to string literals |
|
6546 |
and place a modified string constant into the binary/byte-code. |
|
6547 |
Therefore, no runtime penalty will be payed for using these escapes. |
|
6548 |
(not in pre 2.11 versions) |
|
16863 | 6549 |
|
6550 |
This is the opposite of withCEscapes. |
|
17000 | 6551 |
|
6552 |
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
|
6553 |
but it cannot be changed easily, as these methods are already used heavily |
13987 | 6554 |
" |
6555 |
||
6556 |
|val "{ SmallInteger }" |
|
6557 |
in out nextChar nDigits| |
|
6558 |
||
6559 |
" |
|
6560 |
first, see if there is any escape; if not, return the receiver unchanged |
|
6561 |
" |
|
6562 |
(self includes:$\) ifFalse:[^ self ]. |
|
6563 |
||
6564 |
self hasChangeOfEmphasis ifTrue:[ self error:'emphasis not supported' ]. |
|
6565 |
out := CharacterWriteStream on:(String new:self size - 1). |
|
6566 |
||
6567 |
in := ReadStream on:self. |
|
6568 |
[in atEnd] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6569 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6570 |
nextChar == $\ ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6571 |
in atEnd ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6572 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6573 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6574 |
nextChar == $r ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6575 |
nextChar := Character return |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6576 |
] ifFalse:[ nextChar == $n ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6577 |
nextChar := Character nl |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6578 |
] ifFalse:[ nextChar == $b ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6579 |
nextChar := Character backspace |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6580 |
] ifFalse:[ nextChar == $f ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6581 |
nextChar := Character newPage |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6582 |
] ifFalse:[ nextChar == $t ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6583 |
nextChar := Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6584 |
] ifFalse:[ nextChar == $e ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6585 |
nextChar := Character esc |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6586 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6587 |
nextChar == $0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6588 |
val := 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6589 |
nextChar := in peek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6590 |
nDigits := 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6591 |
[nextChar notNil and:[nextChar isDigit and:[nDigits <= 3]]] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6592 |
val := (val * 8) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6593 |
nextChar := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6594 |
nDigits := nDigits + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6595 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6596 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6597 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6598 |
val := 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6599 |
nextChar == $x ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6600 |
2 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6601 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6602 |
val := (val * 16) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6603 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6604 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6605 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6606 |
nextChar == $u ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6607 |
4 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6608 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6609 |
val := (val * 16) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6610 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6611 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6612 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6613 |
nextChar == $U ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6614 |
8 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6615 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6616 |
val := (val * 16) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6617 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6618 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6619 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6620 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6621 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6622 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6623 |
]]]]]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6624 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6625 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6626 |
out nextPut:nextChar. |
13987 | 6627 |
]. |
6628 |
^ out contents |
|
6629 |
||
6630 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6631 |
'hello world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6632 |
'hello\world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6633 |
'hello\world\' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6634 |
'hello world\' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6635 |
'hello\tworld' withoutCEscapes |
13987 | 6636 |
'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
|
6637 |
'hello\tworld\n' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6638 |
'hello\010world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6639 |
'hello\r\nworld' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6640 |
'hello\r\n\x08world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6641 |
'0\x080' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6642 |
'0\u12340' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6643 |
'0\U123456780' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6644 |
'0\0a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6645 |
'0\00a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6646 |
'0\000a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6647 |
'0\0000a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6648 |
'0\00000a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6649 |
'0\03770' withoutCEscapes |
13987 | 6650 |
" |
6651 |
||
6652 |
"Created: / 25-01-2012 / 10:41:44 / cg" |
|
6653 |
! |
|
6654 |
||
9192 | 6655 |
withoutCRs |
6656 |
"return a new collection consisting of receivers elements |
|
6657 |
with all cr-characters replaced by \-characters. |
|
6658 |
This is the reverse operation of withCRs." |
|
6659 |
||
16759 | 6660 |
^ self copyReplaceAll:(Character cr) with:$\ ifNone:self |
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
6661 |
|
9192 | 6662 |
" |
6663 |
'hello |
|
6664 |
world' withoutCRs |
|
6665 |
" |
|
6666 |
||
6667 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
6668 |
! |
|
6669 |
||
6670 |
withoutLeadingSeparators |
|
608 | 6671 |
"return a copy of myself without leading separators. |
6672 |
Notice: this does remove tabs, newline or any other whitespace. |
|
6673 |
Returns an empty string, if the receiver consist only of whitespace." |
|
6674 |
||
6675 |
|index| |
|
6676 |
||
6677 |
index := self indexOfNonSeparatorStartingAt:1. |
|
6678 |
index ~~ 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6679 |
index == 1 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6680 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6681 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6682 |
^ self copyFrom:index |
608 | 6683 |
]. |
6684 |
^ '' |
|
6685 |
||
6686 |
" |
|
8874 | 6687 |
' foo ' withoutLeadingSeparators |
6688 |
'foo ' withoutLeadingSeparators |
|
6689 |
' foo' withoutLeadingSeparators |
|
6690 |
' ' withoutLeadingSeparators |
|
6691 |
'foo' withoutLeadingSeparators |
|
6692 |
(' ' , Character tab asString , ' foo ') withoutLeadingSeparators inspect |
|
608 | 6693 |
" |
9192 | 6694 |
! |
6695 |
||
6696 |
withoutMatchEscapes |
|
4117 | 6697 |
"return a copy of the receiver with all $\ removed or |
6698 |
the receiver, if there are none." |
|
6699 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6700 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6701 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6702 |
escape := self class matchEscapeCharacter. |
4117 | 6703 |
|
6704 |
in := self readStream. |
|
8222
f2c454a9a038
replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents:
8124
diff
changeset
|
6705 |
out := self species writeStream. |
4117 | 6706 |
[in atEnd] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6707 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6708 |
c == escape ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6709 |
in atEnd ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6710 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6711 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6712 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6713 |
out nextPut:c. |
4117 | 6714 |
]. |
6715 |
^ out contents. |
|
6716 |
||
6717 |
" |
|
8874 | 6718 |
'*foo' withoutMatchEscapes |
6719 |
'\*foo' withoutMatchEscapes |
|
6720 |
'*foo' withoutMatchEscapes |
|
6721 |
'\\*foo' withoutMatchEscapes |
|
6722 |
'foo*' withoutMatchEscapes |
|
6723 |
'foo\*' withoutMatchEscapes |
|
6724 |
'foo\' withoutMatchEscapes |
|
6725 |
'f\*o\*o' withoutMatchEscapes |
|
4117 | 6726 |
" |
6727 |
||
6728 |
"Modified: 30.6.1997 / 13:40:23 / cg" |
|
9192 | 6729 |
! |
6730 |
||
6731 |
withoutPrefix:aString |
|
6732 |
"if the receiver startsWith aPrefix, return a copy without it. |
|
6733 |
Otherwise return the receiver" |
|
6734 |
||
6735 |
(self startsWith:aString) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6736 |
^ self copyFrom:aString size + 1 |
9192 | 6737 |
]. |
6738 |
^ self |
|
6739 |
||
6740 |
" |
|
6741 |
'helloworld' withoutPrefix:'hello' |
|
6742 |
'helloworld' withoutPrefix:'foo' |
|
6743 |
" |
|
6744 |
! |
|
6745 |
||
10671 | 6746 |
withoutQuotes |
17000 | 6747 |
"/ remove quotes ($" and $') from the front and end of myself (if matching)" |
6748 |
||
6749 |
|firstChar| |
|
6750 |
||
17024 | 6751 |
self isEmpty ifTrue:[^ self]. |
6752 |
||
17000 | 6753 |
firstChar := self first. |
6754 |
((firstChar == $") or:[firstChar == $']) ifFalse:[^ self]. |
|
6755 |
||
6756 |
self last == firstChar ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6757 |
^ self copyFrom:2 to:(self size-1) |
10671 | 6758 |
]. |
17000 | 6759 |
^ self |
6760 |
||
6761 |
"/ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6762 |
"/ '"hello"' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6763 |
"/ '''hello''' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6764 |
"/ 'hello' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6765 |
"/ '"hello' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6766 |
"/ 'hello"' withoutQuotes |
17000 | 6767 |
"/ |
10671 | 6768 |
! |
6769 |
||
9192 | 6770 |
withoutSeparators |
608 | 6771 |
"return a copy of myself without leading and trailing whitespace. |
4156 | 6772 |
(but whiteSpace in-between is preserved) |
608 | 6773 |
Whitespace is space, tab, newline, formfeed. |
6774 |
Use withoutSpaces, if you want to remove spaces only." |
|
6775 |
||
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
6776 |
^ self trimForWhich:[:ch | ch isSeparator] |
608 | 6777 |
|
6778 |
" |
|
8874 | 6779 |
' foo ' withoutSeparators |
6780 |
' foo' withoutSeparators |
|
6781 |
'foo ' withoutSeparators |
|
6782 |
' ' withoutSeparators |
|
6783 |
(' foo' , Character tab asString , ' ') withoutSeparators inspect |
|
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
6784 |
' foo ' asUnicode16String withoutSeparators |
608 | 6785 |
" |
9192 | 6786 |
! |
6787 |
||
6788 |
withoutSpaces |
|
608 | 6789 |
"return a copy of myself without leading and trailing spaces. |
4156 | 6790 |
(but spaces in-between are preserved) |
608 | 6791 |
Notice: this does NOT remove tabs, newline or any other whitespace. |
6792 |
Use withoutSeparators for this." |
|
6793 |
||
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
6794 |
^ self trimForWhich:[:ch | ch == Character space] |
608 | 6795 |
|
6796 |
" |
|
8874 | 6797 |
' foo ' withoutSpaces |
6798 |
'foo ' withoutSpaces |
|
6799 |
' foo' withoutSpaces |
|
6800 |
' ' withoutSpaces |
|
6801 |
'a b' withoutSpaces |
|
6802 |
(' foo' , Character tab asString , ' ') withoutSpaces inspect |
|
608 | 6803 |
" |
9192 | 6804 |
! |
6805 |
||
6806 |
withoutTrailingSeparators |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6807 |
"return a copy of myself without trailing separators. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6808 |
Notice: this does remove tabs, newline or any other whitespace. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6809 |
Returns an empty string, if the receiver consist only of whitespace." |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6810 |
|
12188 | 6811 |
^ self withoutTrailingForWhich:[:ch | ch isSeparator] |
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6812 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6813 |
" |
8874 | 6814 |
' foo ' withoutTrailingSeparators |
6815 |
'foo ' withoutTrailingSeparators |
|
6816 |
' foo' withoutTrailingSeparators |
|
6817 |
' ' withoutTrailingSeparators |
|
6818 |
'foo' withoutTrailingSeparators |
|
6819 |
(' ' , Character tab asString , ' foo ') withoutTrailingSeparators inspect |
|
6820 |
(' foo' , Character tab asString) withoutTrailingSeparators inspect |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6821 |
" |
9192 | 6822 |
! ! |
6823 |
||
18721 | 6824 |
|
9192 | 6825 |
!CharacterArray methodsFor:'substring searching'! |
6826 |
||
15055 | 6827 |
findRangeOfString:subString |
6828 |
"find a substring. if found, return the start- and endIndex; |
|
6829 |
if not found, return an empty interval." |
|
6830 |
||
6831 |
^ self rangeOfSubCollection:subString startingAt:1 ifAbsent:[0 to:-1] caseSensitive:true |
|
6832 |
||
6833 |
" |
|
6834 |
'hello world' findRangeOfString:'llo' |
|
6835 |
'hello world' findRangeOfString:'ole' |
|
6836 |
" |
|
6837 |
! |
|
6838 |
||
9192 | 6839 |
findString:subString |
6840 |
"find a substring. if found, return the index; |
|
6841 |
if not found, return 0." |
|
6842 |
||
6843 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:true |
|
6844 |
||
6845 |
" |
|
6846 |
'hello world' findString:'llo' |
|
6847 |
'hello world' findString:'ole' |
|
6848 |
" |
|
6849 |
! |
|
608 | 6850 |
|
15734 | 6851 |
findString:subString caseSensitive:caseSensitive |
6852 |
"find a substring. if found, return the index; |
|
6853 |
if not found, return 0." |
|
6854 |
||
6855 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:caseSensitive |
|
6856 |
||
6857 |
" |
|
6858 |
'hello world' findString:'LLo' caseSensitive:true |
|
6859 |
'hello world' findString:'LLo' caseSensitive:false |
|
6860 |
" |
|
6861 |
! |
|
6862 |
||
608 | 6863 |
findString:subString ifAbsent:exceptionBlock |
6864 |
"find a substring. If found, return the index; |
|
6865 |
if not found, return the result of evaluating exceptionBlock." |
|
6866 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6867 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock caseSensitive:true |
608 | 6868 |
! |
6869 |
||
11018 | 6870 |
findString:subString ignoreCase:ignoreCase |
15734 | 6871 |
<resource: #obsolete> |
11018 | 6872 |
"find a substring. if found, return the index; |
6873 |
if not found, return 0." |
|
6874 |
||
6875 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:ignoreCase not |
|
6876 |
||
6877 |
" |
|
6878 |
'hello world' findString:'LLo' ignoreCase:false |
|
6879 |
'hello world' findString:'LLo' ignoreCase:true |
|
6880 |
" |
|
6881 |
! |
|
6882 |
||
608 | 6883 |
findString:subString startingAt:index |
6884 |
"find a substring, starting at index. if found, return the index; |
|
6885 |
if not found, return 0." |
|
6886 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6887 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:0 caseSensitive:true |
608 | 6888 |
|
6889 |
" |
|
9192 | 6890 |
'hello yello' findString:'llo' startingAt:1 |
6891 |
'hello yello' findString:'llo' startingAt:5 |
|
6892 |
'hello yello' findString:'llo' startingAt:15 |
|
6893 |
" |
|
6894 |
! |
|
608 | 6895 |
|
6896 |
findString:subString startingAt:index ifAbsent:exceptionBlock |
|
6897 |
"find a substring, starting at index. if found, return the index; |
|
6898 |
if not found, return the result of evaluating exceptionBlock." |
|
6899 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6900 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:true |
608 | 6901 |
! |
6902 |
||
12177 | 6903 |
findString:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
10929 | 6904 |
"find a substring, starting at index. if found, return the index; |
6905 |
if not found, return the result of evaluating exceptionBlock." |
|
6906 |
||
6907 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
|
6908 |
! |
|
6909 |
||
608 | 6910 |
includesString:aString |
6911 |
"return true, if a substring is contained in the receiver" |
|
6912 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6913 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0 caseSensitive:true) ~~ 0 |
608 | 6914 |
|
6915 |
" |
|
12177 | 6916 |
'hello world' includesString:'hel' |
8874 | 6917 |
'hello world' includesString:'rld' |
9192 | 6918 |
'hello world' includesString:'llo' |
6919 |
'hello world' includesString:'LLO' |
|
12177 | 6920 |
'hello world' includesString:'' |
9192 | 6921 |
" |
6922 |
! |
|
9191 | 6923 |
|
6924 |
includesString:aString caseSensitive:caseSensitive |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6925 |
"return true, if a substring is contained in the receiver" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6926 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6927 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0 caseSensitive:caseSensitive) ~~ 0 |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6928 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6929 |
" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6930 |
'hello world' includesString:'hel' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6931 |
'hello world' includesString:'HEL' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6932 |
'hello world' includesString:'HEL' caseSensitive:false |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6933 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6934 |
'hello world' includesString:'wor' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6935 |
'hello world' includesString:'WOR' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6936 |
'hello world' includesString:'WOR' caseSensitive:false |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6937 |
" |
9192 | 6938 |
! |
6939 |
||
17486 | 6940 |
indexOfString: aString |
6941 |
"VSE and V'age compatibility" |
|
6942 |
"find a substring. If found, return the index; if not found, return 0." |
|
6943 |
||
6944 |
^ self indexOfSubCollection: aString startingAt: 1 ifAbsent:[0] |
|
6945 |
! |
|
6946 |
||
18721 | 6947 |
indexOfString:aString startingAt:startIndex |
6948 |
"VSE and V'age compatibility" |
|
6949 |
"find a substring. If found, return the index; if not found, return 0." |
|
6950 |
||
6951 |
^ self indexOfSubCollection:aString startingAt:startIndex ifAbsent:[0] |
|
6952 |
! |
|
6953 |
||
6954 |
indexOfString:aString startingAt:startIndex ifAbsent:exceptionalValue |
|
6955 |
"VSE and V'age compatibility" |
|
6956 |
"find a substring. |
|
6957 |
If found, return the index; if not found, the value from exceptionalValue." |
|
6958 |
||
6959 |
^ self indexOfSubCollection:aString startingAt:startIndex ifAbsent:exceptionalValue |
|
6960 |
! |
|
6961 |
||
18671 | 6962 |
indexOfSubCollection:subString caseSensitive:caseSensitive |
6963 |
"find a substring, starting at index. if found, return the index; |
|
6964 |
if not found, return the result of evaluating exceptionBlock. |
|
6965 |
This is a q&d hack - not very efficient" |
|
6966 |
||
6967 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:[0] caseSensitive:caseSensitive. |
|
6968 |
! |
|
6969 |
||
9192 | 6970 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
6971 |
"find a substring, starting at index. if found, return the index; |
|
6972 |
if not found, return the result of evaluating exceptionBlock. |
|
6973 |
This is a q&d hack - not very efficient" |
|
6974 |
||
6975 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:true. |
|
6976 |
! |
|
6977 |
||
6978 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6979 |
"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
|
6980 |
if not found, return the result of evaluating exceptionBlock. |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6981 |
This is a q&d hack - not very efficient" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6982 |
|
608 | 6983 |
|firstChar found |
6984 |
startIndex "{ Class: SmallInteger }" |
|
6985 |
subSize "{ Class: SmallInteger }" |
|
6986 |
mySize "{ Class: SmallInteger }" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6987 |
runIdx "{ Class: SmallInteger }" |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6988 |
tester| |
608 | 6989 |
|
6990 |
subSize := subString size. |
|
12177 | 6991 |
subSize == 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6992 |
subString isString ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6993 |
self error:'non string argument' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6994 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6995 |
"empty string does not match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6996 |
^ 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6997 |
"empty string matches" |
15433 | 6998 |
"/ ^ index |
6122
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
6999 |
]. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7000 |
|
608 | 7001 |
mySize := self size. |
7002 |
firstChar := subString at:1. |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7003 |
caseSensitive ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7004 |
tester := [:c1 :c2 | c1 = c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7005 |
startIndex := self indexOf:firstChar startingAt:index. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7006 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7007 |
tester := [:c1 :c2 | c1 sameAs: c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7008 |
startIndex := self findFirst:[:c | c sameAs:firstChar] startingAt:index. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7009 |
]. |
608 | 7010 |
[startIndex == 0] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7011 |
runIdx := startIndex. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7012 |
found := true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7013 |
1 to:subSize do:[:i | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7014 |
runIdx > mySize ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7015 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7016 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7017 |
(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
|
7018 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7019 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7020 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7021 |
runIdx := runIdx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7022 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7023 |
found ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7024 |
^ startIndex |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7025 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7026 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7027 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7028 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7029 |
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
|
7030 |
]. |
608 | 7031 |
]. |
7032 |
^ exceptionBlock value |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7033 |
|
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7034 |
"Modified: 23.2.1996 / 15:35:15 / cg" |
9192 | 7035 |
! |
7036 |
||
17191 | 7037 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive ignoreDiacritics:ignoreDiacritics |
7038 |
"find a substring, starting at index. if found, return the index; |
|
7039 |
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
|
7040 |
This is a q&d hack - not very efficient |
17191 | 7041 |
(see implementation in string, for a much faster algorithm)" |
7042 |
||
7043 |
|firstChar found |
|
7044 |
startIndex "{ Class: SmallInteger }" |
|
7045 |
subSize "{ Class: SmallInteger }" |
|
7046 |
mySize "{ Class: SmallInteger }" |
|
7047 |
runIdx "{ Class: SmallInteger }" |
|
7048 |
tester charMap firstCharMapped findNextIndex| |
|
7049 |
||
7050 |
subSize := subString size. |
|
7051 |
subSize == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7052 |
subString isString ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7053 |
self error:'non string argument' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7054 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7055 |
"empty string does not match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7056 |
^ 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7057 |
"empty string matches" |
17191 | 7058 |
"/ ^ index |
7059 |
]. |
|
7060 |
||
7061 |
mySize := self size. |
|
7062 |
firstChar := subString at:1. |
|
7063 |
ignoreDiacritics ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7064 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7065 |
charMap := [:ch | ch asLowercase withoutDiacritics]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7066 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7067 |
charMap := [:ch | ch withoutDiacritics]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7068 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7069 |
tester := [:c1 :c2 | (charMap value:c1) = (charMap value:c2) ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7070 |
firstCharMapped := (charMap value:firstChar). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7071 |
findNextIndex := [:index | self findFirst:[:ch | (charMap value:ch) = firstCharMapped] startingAt:index]. |
17191 | 7072 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7073 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7074 |
tester := [:c1 :c2 | c1 = c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7075 |
findNextIndex := [:index | self indexOf:firstChar startingAt:index]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7076 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7077 |
tester := [:c1 :c2 | c1 sameAs: c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7078 |
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
|
7079 |
]. |
17191 | 7080 |
]. |
7081 |
startIndex := findNextIndex value:index. |
|
7082 |
[startIndex == 0] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7083 |
runIdx := startIndex. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7084 |
found := true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7085 |
1 to:subSize do:[:i | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7086 |
runIdx > mySize ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7087 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7088 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7089 |
(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
|
7090 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7091 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7092 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7093 |
runIdx := runIdx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7094 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7095 |
found ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7096 |
^ startIndex |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7097 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7098 |
startIndex := findNextIndex value:(startIndex + 1) |
17191 | 7099 |
]. |
7100 |
^ exceptionBlock value |
|
7101 |
||
7102 |
" |
|
17600 | 7103 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:1 ifAbsent:0 caseSensitive:false ignoreDiacritics:true. 5 |
7104 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:6 ifAbsent:0 caseSensitive:false ignoreDiacritics:true. 0 |
|
7105 |
||
7106 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:1 ifAbsent:0 caseSensitive:false ignoreDiacritics:false. 5 |
|
7107 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:6 ifAbsent:0 caseSensitive:false ignoreDiacritics:false. 0 |
|
17191 | 7108 |
" |
7109 |
! |
|
7110 |
||
15055 | 7111 |
rangeOfSubCollection:subString startingAt:start ifAbsent:exceptionValue caseSensitive:caseSensitive |
7112 |
"find a substring. if found, return the start- and endIndex; |
|
7113 |
if not found, return the value of exceptionValue." |
|
7114 |
||
7115 |
|i| |
|
7116 |
||
7117 |
i := self indexOfSubCollection:subString startingAt:start ifAbsent:0 caseSensitive:caseSensitive. |
|
7118 |
i == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7119 |
^ exceptionValue value |
15055 | 7120 |
]. |
7121 |
^ i to:(i + subString size - 1) |
|
7122 |
||
7123 |
" |
|
7124 |
'hello world' findRangeOfString:'llo' |
|
7125 |
'hello world' findRangeOfString:'ole' |
|
7126 |
" |
|
9192 | 7127 |
! ! |
7128 |
||
7129 |
!CharacterArray methodsFor:'testing'! |
|
7130 |
||
18463 | 7131 |
argumentCount |
7132 |
"treating the receiver as a message selector, return how many arguments would it take (ANSI)" |
|
7133 |
||
7134 |
|binopChars| |
|
7135 |
||
7136 |
(self size <= Method maxBinarySelectorSize) ifTrue:[ |
|
7137 |
binopChars := Method binarySelectorCharacters. |
|
7138 |
(self conform:[:eachChar | (binopChars includes:eachChar)]) ifTrue:[ |
|
7139 |
^ 1 |
|
7140 |
]. |
|
7141 |
]. |
|
7142 |
^ self occurrencesOf:$: |
|
7143 |
||
7144 |
" |
|
7145 |
'foo:bar:' argumentCount |
|
7146 |
#foo:bar: argumentCount |
|
7147 |
'hello' argumentCount |
|
7148 |
'+' argumentCount |
|
7149 |
'++' argumentCount |
|
7150 |
'+++' argumentCount |
|
7151 |
'|' argumentCount |
|
7152 |
'?' argumentCount |
|
7153 |
'_' argumentCount |
|
7154 |
'_:' argumentCount |
|
7155 |
'_:_:' argumentCount |
|
7156 |
'<->' argumentCount |
|
7157 |
" |
|
7158 |
! |
|
7159 |
||
18597 | 7160 |
characterSize |
7161 |
"answer the size in bits of my largest character (actually only 7, 8, 16 or 32)" |
|
7162 |
||
7163 |
|string max |
|
7164 |
sz "{ Class:SmallInteger}" | |
|
15829 | 7165 |
|
7166 |
(string := self string) ~~ self ifTrue:[ |
|
18597 | 7167 |
^ string characterSize. |
7168 |
]. |
|
7169 |
||
7170 |
sz := self size. |
|
7171 |
max := 7. |
|
7172 |
1 to:sz do:[:idx | |
|
7173 |
|thisSize| |
|
7174 |
||
7175 |
thisSize := (self at:idx) characterSize. |
|
7176 |
thisSize > max ifTrue:[ |
|
7177 |
max := thisSize. |
|
7178 |
max == 32 ifTrue:[ |
|
7179 |
"shortcut: we know, that max size is 32" |
|
7180 |
^ 32. |
|
7181 |
]. |
|
7182 |
]. |
|
15829 | 7183 |
]. |
18597 | 7184 |
|
7185 |
^ max. |
|
7186 |
||
7187 |
" |
|
7188 |
'hello' characterSize |
|
7189 |
'hello' asUnicode32String characterSize |
|
7190 |
'helloü' asUnicode32String characterSize |
|
7191 |
'hello' asText allBold characterSize |
|
7192 |
" |
|
7193 |
! |
|
7194 |
||
7195 |
contains8BitCharacters |
|
7196 |
<resource: #obsolete> |
|
7197 |
||
7198 |
^ self containsNon7BitAscii |
|
7199 |
! |
|
7200 |
||
7201 |
containsNon7BitAscii |
|
7202 |
"return true, if the underlying string contains 8BitCharacters (or widers) |
|
7203 |
(i.e. if it is non-ascii)" |
|
7204 |
||
7205 |
|string |
|
7206 |
sz "{ Class:SmallInteger }"| |
|
7207 |
||
7208 |
(string := self string) ~~ self ifTrue:[ |
|
7209 |
^ string containsNon7BitAscii |
|
7210 |
]. |
|
7211 |
sz := self size. |
|
7212 |
1 to:sz do:[:idx| |
|
7213 |
(self at:idx) codePoint > 16r7F ifTrue:[ |
|
7214 |
^ true. |
|
7215 |
]. |
|
7216 |
]. |
|
7217 |
^ false. |
|
7218 |
||
7219 |
" |
|
7220 |
'hello' asUnicode32String containsNon7BitAscii |
|
7221 |
'hello üöä' asUnicode32String containsNon7BitAscii |
|
7222 |
'hello' asUnicode32String asText allBold containsNon7BitAscii |
|
7223 |
'hello üö' asUnicode32String asText allBold containsNon7BitAscii |
|
15829 | 7224 |
" |
7225 |
! |
|
7226 |
||
9192 | 7227 |
isAlphaNumeric |
7228 |
"return true, if the receiver is some alphanumeric word; |
|
7229 |
i.e. consists of a letter followed by letters or digits." |
|
7230 |
||
7231 |
self size == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7232 |
"mhmh what is this ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7233 |
^ false |
9192 | 7234 |
]. |
7235 |
(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
|
7236 |
^ self conform:[:char | char isLetterOrDigit]. |
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7237 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7238 |
" |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7239 |
'helloWorld' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7240 |
'foo1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7241 |
'f1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7242 |
'1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7243 |
'+' isAlphaNumeric |
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7244 |
" |
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7245 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7246 |
"Modified: / 13-10-2006 / 12:53:49 / cg" |
9192 | 7247 |
! |
9190 | 7248 |
|
7249 |
isBinarySelector |
|
10903 | 7250 |
"treating the receiver as a message selector, return true if its a binary selector. |
7251 |
Notice, that st/x does not have a size <= 2 limit for unaries" |
|
9190 | 7252 |
|
7253 |
|binopChars| |
|
7254 |
||
18463 | 7255 |
(self size > Method maxBinarySelectorSize) ifTrue:[^ false]. |
7256 |
||
7257 |
binopChars := Method binarySelectorCharacters. |
|
9190 | 7258 |
^ (self conform:[:char | (binopChars includes:char)]) |
7259 |
||
7260 |
" |
|
7261 |
'foo:bar:' isBinarySelector |
|
7262 |
#foo:bar: isBinarySelector |
|
7263 |
'hello' isBinarySelector |
|
7264 |
'+' isBinarySelector |
|
7265 |
'|' isBinarySelector |
|
8874 | 7266 |
'?' isBinarySelector |
7267 |
':' isBinarySelector |
|
7268 |
'a:' isBinarySelector |
|
7269 |
'->' isBinarySelector |
|
7270 |
'<->' isBinarySelector |
|
7271 |
'::' isBinarySelector |
|
7482 | 7272 |
" |
7273 |
||
7274 |
"Modified: 4.1.1997 / 14:16:14 / cg" |
|
9192 | 7275 |
! |
7276 |
||
7277 |
isBlank |
|
7278 |
"return true, if the receiver contains spaces only" |
|
7279 |
||
9230 | 7280 |
^ (self contains:[:char | char ~~ Character space]) not |
7281 |
||
7282 |
" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7283 |
'' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7284 |
' a ' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7285 |
' ' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7286 |
' ' asUnicode16String isBlank |
9230 | 7287 |
" |
9192 | 7288 |
! |
7289 |
||
10903 | 7290 |
isKeywordSelector |
7291 |
"return true, iff there are only alphanumeric or underline characters separated by colons. |
|
7292 |
Must end with a colon." |
|
7293 |
||
7294 |
|state| |
|
7295 |
||
12177 | 7296 |
state := #initial. |
10903 | 7297 |
self do:[:char | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7298 |
(state == #initial or:[ state == #gotColon]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7299 |
(char isLetterOrUnderline) ifFalse:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7300 |
state := #gotCharacter. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7301 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7302 |
char == $: ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7303 |
state := #gotColon. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7304 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7305 |
(char isLetterOrDigit or:[char == $_]) ifFalse:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7306 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7307 |
]. |
10903 | 7308 |
]. |
7309 |
^ state == #gotColon. |
|
7310 |
||
7311 |
" |
|
12177 | 7312 |
self assert:(':' isKeywordSelector not). |
10903 | 7313 |
self assert:(':a' isKeywordSelector not). |
7314 |
self assert:('1:' isKeywordSelector not). |
|
7315 |
self assert:('a:' isKeywordSelector). |
|
7316 |
self assert:('_:' isKeywordSelector). |
|
7317 |
self assert:('_a:' isKeywordSelector). |
|
7318 |
self assert:('_1:' isKeywordSelector). |
|
7319 |
self assert:('_1::' isKeywordSelector not). |
|
7320 |
self assert:('_:_:' isKeywordSelector). |
|
7321 |
self assert:('a:b:' isKeywordSelector). |
|
7322 |
self assert:('aa:bb:' isKeywordSelector). |
|
7323 |
self assert:('aa:bb:a' isKeywordSelector not). |
|
7324 |
self assert:('1:2:' isKeywordSelector not). |
|
7325 |
" |
|
7326 |
! |
|
7327 |
||
10431 | 7328 |
isNameSpaceSelector |
7329 |
"Answer true if the receiver contains chars which form a nameSpace selector name. |
|
7330 |
These are of the form ':<ns>::<sel>', where ns is the NameSpace and sel is the regular selector. |
|
7331 |
For example, the #+ selector as seen by the Foo namespace would be actually #':Foo::+'. |
|
17511 | 7332 |
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
|
7333 |
is legal, and this can be checked quickly by just looking at the first character. |
10431 | 7334 |
You cannot easily change this algorithm here, as it is also known by the VM's lookup function." |
7335 |
||
7336 |
|i| |
|
7337 |
||
16733 | 7338 |
(self at:1) == $: ifFalse:[^ false]. |
17511 | 7339 |
|
10431 | 7340 |
i := self indexOf:$: startingAt:2. |
7341 |
i == 0 ifTrue:[^ false]. |
|
7342 |
self size <= (i+1) ifTrue:[^ false]. |
|
7343 |
(self at:i+1) == $: ifFalse:[^ false]. |
|
7344 |
(self at:i+2) == $: ifTrue:[^ false]. |
|
7345 |
"/ could check if the rest after the ns-prefix and colons is a valid selector... |
|
7346 |
^ true |
|
7347 |
||
7348 |
"test: |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7349 |
self assert:('+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7350 |
self assert:(':+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7351 |
self assert:(':Foo:+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7352 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7353 |
self assert:(':Foo::+' isNameSpaceSelector). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7354 |
self assert:(':Foo::bar:baz:' isNameSpaceSelector). |
10431 | 7355 |
" |
7356 |
||
7357 |
"Created: / 05-03-2007 / 11:35:31 / cg" |
|
7358 |
! |
|
7359 |
||
9192 | 7360 |
isNumeric |
7361 |
"return true, if the receiver is some numeric word; |
|
7362 |
i.e. consists only of digits." |
|
7363 |
||
7364 |
self size == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7365 |
^ false |
9192 | 7366 |
]. |
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7367 |
^ self conform:[:char | char isDigit] |
9192 | 7368 |
|
7369 |
" |
|
7370 |
'helloWorld' isNumeric |
|
7371 |
'foo1234' isNumeric |
|
7372 |
'f1234' isNumeric |
|
7373 |
'1234' isNumeric |
|
7374 |
'+' isNumeric |
|
7375 |
" |
|
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7376 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7377 |
"Modified: / 13-10-2006 / 12:54:12 / cg" |
9192 | 7378 |
! |
7379 |
||
9230 | 7380 |
isString |
7381 |
"return true, if the receiver is some kind of string; |
|
7382 |
true is returned here - redefinition of Object>>isString." |
|
7383 |
||
7384 |
^ true |
|
7385 |
! |
|
7386 |
||
7387 |
isUnarySelector |
|
7388 |
"Answer true if the receiver contains only chars in an ANSI unary method selector, false otherwise." |
|
7389 |
||
17442 | 7390 |
^ (self first isLetterOrUnderline) |
9845 | 7391 |
and:[ self conform: [ :chr | chr isLetterOrDigit or:[chr == $_] ]] |
7392 |
||
7393 |
"Modified: / 13-09-2006 / 11:35:15 / cg" |
|
9230 | 7394 |
! |
7395 |
||
14122 | 7396 |
isUnicode16String |
7397 |
^ false |
|
7398 |
! |
|
7399 |
||
7400 |
isUnicode32String |
|
7401 |
^ false |
|
7402 |
! |
|
7403 |
||
7404 |
isUnicodeString |
|
7405 |
^ false |
|
7406 |
! |
|
7407 |
||
9230 | 7408 |
isValidSmalltalkIdentifier |
7409 |
"return true, if the receivers characters make up a valid smalltalk identifier" |
|
7410 |
||
7411 |
|scanner tok| |
|
7412 |
||
7413 |
scanner := Compiler new. |
|
7414 |
scanner source:(self readStream). |
|
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
7415 |
Parser parseErrorSignal handle:[:ex | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7416 |
tok := nil. |
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
7417 |
] do:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7418 |
tok := scanner nextToken. |
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
7419 |
]. |
9230 | 7420 |
tok ~~ #Identifier ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7421 |
^ false |
9230 | 7422 |
]. |
7423 |
scanner tokenPosition == 1 ifFalse:[^ false]. |
|
7424 |
^ scanner sourceStream atEnd. |
|
7425 |
||
7426 |
" |
|
7427 |
'foo' isValidSmalltalkIdentifier |
|
7428 |
'1foo' isValidSmalltalkIdentifier |
|
7429 |
'_foo' isValidSmalltalkIdentifier |
|
7430 |
'_foo_bar_' isValidSmalltalkIdentifier |
|
7431 |
'foo ' isValidSmalltalkIdentifier |
|
7432 |
' foo' isValidSmalltalkIdentifier |
|
7433 |
" |
|
7434 |
! |
|
7435 |
||
14555 | 7436 |
isWideString |
15829 | 7437 |
|string| |
7438 |
||
7439 |
(string := self string) ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7440 |
^ string isWideString. |
15829 | 7441 |
]. |
7442 |
^ self contains:[:aCharacter | aCharacter codePoint > 16rFF]. |
|
14555 | 7443 |
! |
7444 |
||
9192 | 7445 |
numArgs |
18463 | 7446 |
<resource: #obsolete> |
608 | 7447 |
"treating the receiver as a message selector, return how many arguments would it take" |
7448 |
||
18463 | 7449 |
^ self argumentCount |
9192 | 7450 |
! |
7451 |
||
7452 |
partsIfSelector |
|
14629 | 7453 |
"treat the receiver as a message selector, return a collection of parts. |
7454 |
Notice: this is more tolerant than Smalltalk's syntax would suggest; |
|
7455 |
especially it allows for empty keyword parts between colons. |
|
7456 |
This is not (and should not be checked here), to allow parsing of |
|
7457 |
degenerate selectors as appearing with objectiveC." |
|
608 | 7458 |
|
9192 | 7459 |
|idx1 "{ Class: SmallInteger }" |
7460 |
coll idx2 sz| |
|
7461 |
||
7462 |
coll := OrderedCollection new. |
|
7463 |
idx1 := 1. |
|
7464 |
sz := self size. |
|
16245 | 7465 |
[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7466 |
idx2 := self indexOf:$: startingAt:idx1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7467 |
(idx2 == 0 or:[idx2 == sz]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7468 |
coll add:(self copyFrom:idx1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7469 |
^ coll |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7470 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7471 |
coll add:(self copyFrom:idx1 to:idx2). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7472 |
idx1 := idx2 + 1 |
16245 | 7473 |
] loop. |
9192 | 7474 |
|
7475 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7476 |
'foo:' partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7477 |
'foo:bar:' partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7478 |
'foo::::' partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7479 |
#foo:bar: partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7480 |
'hello' partsIfSelector |
9192 | 7481 |
'+' partsIfSelector |
7482 |
" |
|
64 | 7483 |
! ! |
7484 |
||
9192 | 7485 |
!CharacterArray methodsFor:'tracing'! |
7486 |
||
7487 |
traceInto:aRequestor level:level from:referrer |
|
7488 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
7489 |
||
7490 |
^ aRequestor traceCharacterArray:self level:level from:referrer |
|
7491 |
||
7492 |
||
7493 |
! ! |
|
7494 |
||
7495 |
!CharacterArray methodsFor:'visiting'! |
|
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7496 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7497 |
acceptVisitor:aVisitor with:aParameter |
16733 | 7498 |
"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
|
7499 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7500 |
^ aVisitor visitString:self with:aParameter |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7501 |
! ! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7502 |
|
18721 | 7503 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
7504 |
!CharacterArray class methodsFor:'documentation'! |
629 | 7505 |
|
7506 |
version |
|
18476 | 7507 |
^ '$Header$' |
12058 | 7508 |
! |
7509 |
||
7510 |
version_CVS |
|
18476 | 7511 |
^ '$Header$' |
18258
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
7512 |
! |
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
7513 |
|
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
7514 |
version_HG |
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
7515 |
|
9f83d8bddcf0
Fix in CharacterArray>>withTabsExpanded: - case for Unicode16/Unicode32 strings
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18200
diff
changeset
|
7516 |
^ '$Changeset: <not expanded> $' |
629 | 7517 |
! ! |
6809 | 7518 |
|
14606 | 7519 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
7520 |
CharacterArray initialize! |