author | Claus Gittinger <cg@exept.de> |
Thu, 14 Apr 2016 12:53:39 +0200 | |
changeset 19580 | fdd3c217ff36 |
parent 19497 | 65e69b6a0972 |
child 19610 | a9a6940944a9 |
child 19677 | 4abe8b6cab72 |
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 |
||
18967 | 139 |
|sz| |
140 |
||
141 |
sz := aString size. |
|
142 |
^ (self uninitializedNew:sz) replaceFrom:1 to:sz with:aString startingAt:1 |
|
143 |
||
144 |
" |
|
145 |
Unicode16String fromString:'hello' |
|
17625 | 146 |
" |
581 | 147 |
! |
148 |
||
149 |
fromStringCollection:aCollectionOfStrings |
|
150 |
"return new string formed by concatenating a copy of the argument, aString" |
|
151 |
||
152 |
^ self fromStringCollection:aCollectionOfStrings separatedBy:'' |
|
153 |
||
154 |
" |
|
155 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') |
|
156 |
" |
|
157 |
||
158 |
"Created: 20.11.1995 / 15:26:59 / cg" |
|
159 |
! |
|
160 |
||
161 |
fromStringCollection:aCollectionOfStrings separatedBy:aSeparatorString |
|
162 |
"return new string formed by concatenating a copy of the argument, aString" |
|
163 |
||
17625 | 164 |
|stream| |
165 |
||
166 |
aCollectionOfStrings do:[:eachString | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
167 |
stream isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
168 |
stream := self writeStreamClass with:eachString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
169 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
170 |
stream |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
171 |
nextPutAll:aSeparatorString; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
172 |
nextPutAll:eachString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
173 |
]. |
581 | 174 |
]. |
17700 | 175 |
stream isNil ifTrue:[^ '']. |
17625 | 176 |
^ stream contents |
581 | 177 |
|
178 |
" |
|
179 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:' ' |
|
17625 | 180 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:'È ' |
181 |
Text fromStringCollection:{'hello'. 'world'. 'how' allBold. 'about'. 'this'. 'äöü'} separatedBy:'È ' |
|
581 | 182 |
" |
183 |
||
184 |
"Created: 20.11.1995 / 15:32:17 / cg" |
|
608 | 185 |
! |
186 |
||
5757 | 187 |
fromUTF8Bytes:aByteCollection |
5758 | 188 |
"return a new string which represents the characters as decoded |
189 |
from the utf8 encoded bytes, aByteCollection. |
|
190 |
Returns either a normal String, or a TwoByteString instance. |
|
6810 | 191 |
Only useful, when reading twoByteStrings from external sources. |
192 |
This only handles up-to 16bit characters" |
|
5757 | 193 |
|
7876 | 194 |
^ self decodeFromUTF8:aByteCollection. |
5757 | 195 |
|
196 |
" |
|
8874 | 197 |
CharacterArray fromUTF8Bytes:#[ 16r41 16r42 ] |
198 |
CharacterArray fromUTF8Bytes:#[ 16rC1 16r02 ] |
|
199 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r81 16r02 ] |
|
6810 | 200 |
CharacterArray fromUTF8Bytes:#[ 16rEF 16rBF 16rBF ] |
201 |
||
202 |
rfc2279 examples: |
|
8874 | 203 |
CharacterArray fromUTF8Bytes:#[ 16r41 16rE2 16r89 16rA2 16rCE 16r91 16r2E ] |
204 |
CharacterArray fromUTF8Bytes:#[ 16rED 16r95 16r9C 16rEA 16rB5 16rAD 16rEC 16r96 16rB4 ] |
|
205 |
CharacterArray fromUTF8Bytes:#[ 16rE6 16r97 16rA5 16rE6 16r9C 16rAC 16rE8 16rAA 16r9E ] |
|
6810 | 206 |
|
207 |
invalid: |
|
8874 | 208 |
CharacterArray fromUTF8Bytes:#[ 16rC0 16r80 ] |
209 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r80 16r80 ] |
|
5757 | 210 |
" |
211 |
! |
|
212 |
||
608 | 213 |
new |
214 |
"return a new empty string" |
|
215 |
||
216 |
^ self basicNew:0 |
|
9425 | 217 |
! |
218 |
||
219 |
readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
|
220 |
"read & return the next String from the (character-)stream aStream; |
|
221 |
skipping all whitespace first; return the value of exceptionBlock, |
|
222 |
if no string can be read. The sequence of characters as read from the |
|
223 |
stream must be one as stored via storeOn: or storeString." |
|
224 |
||
225 |
|str collected char| |
|
226 |
||
227 |
str := aStreamOrString readStream. |
|
228 |
||
229 |
"skip whiteSpace" |
|
230 |
str skipSeparators. |
|
11320 | 231 |
|
14452
ef3591302afa
changed: #readSmalltalkStringFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
14451
diff
changeset
|
232 |
(str peekOrNil == $') ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
233 |
str next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
234 |
collected := self writeStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
235 |
[str atEnd] whileFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
236 |
char := str next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
237 |
char == $' ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
238 |
"/ look for another quote |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
239 |
str peekOrNil ~~ $' ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
240 |
"end of string reached" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
241 |
^ collected contents. |
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 |
"eat doubled quote" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
244 |
str next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
245 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
246 |
((char ~~ Character return) or:[str peekOrNil ~~ Character lf]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
247 |
"compress CRLF to LF, but keep a single CR" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
248 |
collected nextPut:char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
249 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
250 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
251 |
"if we come here, we reached the end without finding a closing $'" |
9425 | 252 |
]. |
253 |
^ exceptionBlock value |
|
254 |
||
255 |
" |
|
256 |
String readFrom:('''hello world''' readStream) |
|
257 |
String readFrom:('''hello '''' world''' readStream) |
|
258 |
String readFrom:('1 ''hello'' ' readStream) |
|
259 |
String readFrom:('1 ''hello'' ' readStream) onError:['foobar'] |
|
260 |
" |
|
261 |
||
262 |
"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
|
263 |
"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
|
264 |
! |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
265 |
|
13201 | 266 |
writeStreamClass |
17213 | 267 |
"the class used by writeStream. |
268 |
Here, we return CharacterWriteStream, which automatically changes |
|
269 |
the underlying collection to a multiByte string (i.e. UnicodeString). |
|
270 |
So you can stream wide characters into it." |
|
13201 | 271 |
|
272 |
^ CharacterWriteStream |
|
11243
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
273 |
|
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
274 |
" |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
275 |
String writeStream |
4bf099f5bb56
CharacterArray class>>#writeStream - answer a CharacterWriteStrem
Stefan Vogel <sv@exept.de>
parents:
11229
diff
changeset
|
276 |
" |
13201 | 277 |
|
278 |
"Created: / 09-01-2011 / 10:37:57 / cg" |
|
64 | 279 |
! ! |
280 |
||
9265 | 281 |
!CharacterArray class methodsFor:'Compatibility-VW'! |
282 |
||
283 |
fromIntegerArray: anArray |
|
284 |
"Answer a new instance of the receiver that is created from the argument, anArray." |
|
285 |
||
286 |
| new | |
|
287 |
||
288 |
new := self new: anArray size. |
|
289 |
1 to: anArray size do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
290 |
new at: index put: (anArray at: index) asCharacter |
9265 | 291 |
]. |
292 |
^new |
|
293 |
||
294 |
" |
|
295 |
String fromIntegerArray: #[8 127] |
|
296 |
" |
|
297 |
! ! |
|
298 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
299 |
!CharacterArray class methodsFor:'Signal constants'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
300 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
301 |
decodingFailedSignal |
2833 | 302 |
"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
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
307 |
^ DecodingFailedSignal |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
308 |
|
2833 | 309 |
"Created: 28.6.1997 / 20:09:55 / cg" |
310 |
"Modified: 3.8.1997 / 18:16:47 / cg" |
|
311 |
! |
|
312 |
||
313 |
encodingFailedSignal |
|
314 |
"return the (query-) signal, raised when encoding of a string is not possible |
|
315 |
due to invalid characters contained in the source." |
|
316 |
||
317 |
^ EncodingFailedSignal |
|
318 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
319 |
"Modified: 28.6.1997 / 20:09:35 / cg" |
2833 | 320 |
"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
|
321 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
322 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
323 |
!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
|
324 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
325 |
lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
326 |
"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
|
327 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
328 |
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
|
329 |
|
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 |
CharacterArray lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
332 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
333 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
334 |
"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
|
335 |
"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
|
336 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
337 |
|
7421 | 338 |
!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
|
339 |
|
7876 | 340 |
decodeFromUTF8:aStringOrByteCollection |
341 |
"return a string which represents the characters as decoded |
|
342 |
from the utf8 encoded bytes, aByteCollection. |
|
343 |
Returns either a normal String, or a TwoByteString instance. |
|
344 |
Only useful, when reading twoByteStrings from external sources. |
|
345 |
This only handles up-to 16bit characters." |
|
346 |
||
18612 | 347 |
^ CharacterEncoderImplementations::ISO10646_to_UTF8 new decodeString:aStringOrByteCollection |
7876 | 348 |
|
349 |
" |
|
8874 | 350 |
CharacterArray fromUTF8Bytes:#[ 16r41 16r42 ] |
351 |
CharacterArray fromUTF8Bytes:#[ 16rC1 16r02 ] |
|
352 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r81 16r02 ] |
|
7876 | 353 |
CharacterArray fromUTF8Bytes:#[ 16rEF 16rBF 16rBF ] |
354 |
||
355 |
rfc2279 examples: |
|
8874 | 356 |
CharacterArray fromUTF8Bytes:#[ 16r41 16rE2 16r89 16rA2 16rCE 16r91 16r2E ] |
357 |
CharacterArray fromUTF8Bytes:#[ 16rED 16r95 16r9C 16rEA 16rB5 16rAD 16rEC 16r96 16rB4 ] |
|
358 |
CharacterArray fromUTF8Bytes:#[ 16rE6 16r97 16rA5 16rE6 16r9C 16rAC 16rE8 16rAA 16r9E ] |
|
7876 | 359 |
|
360 |
invalid: |
|
8874 | 361 |
CharacterArray fromUTF8Bytes:#[ 16rC0 16r80 ] |
362 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r80 16r80 ] |
|
7876 | 363 |
" |
443 | 364 |
! ! |
365 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
366 |
!CharacterArray class methodsFor:'pattern matching'! |
64 | 367 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
368 |
matchEscapeCharacter |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
369 |
"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
|
370 |
(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
|
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 |
! |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
374 |
|
15734 | 375 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop caseSensitive:caseSensitive |
327 | 376 |
"helper for match; return true if the characters from start to stop in |
377 |
aString are matching the scan in matchScan from matchStart to matchStop. |
|
328 | 378 |
The matchScan is as created by asMatchScanArray. |
327 | 379 |
|
8874 | 380 |
This algorithm is not at all the most efficient; |
381 |
for heavy duty pattern matching, an interface (primitive) to the regex |
|
328 | 382 |
pattern matching package should be added." |
327 | 383 |
|
8874 | 384 |
|matchEntry |
327 | 385 |
mStart "{ Class: SmallInteger }" |
386 |
mStop "{ Class: SmallInteger }" |
|
387 |
sStart "{ Class: SmallInteger }" |
|
388 |
sStop "{ Class: SmallInteger }" |
|
389 |
mSize "{ Class: SmallInteger }" |
|
390 |
sSize "{ Class: SmallInteger }" |
|
391 |
index "{ Class: SmallInteger }" |
|
2561 | 392 |
quickCheck matchLast nextMatchEntry |
986 | 393 |
checkChar included| |
327 | 394 |
|
395 |
mStart := matchStart. |
|
396 |
mStop := matchStop. |
|
397 |
sStart := start. |
|
398 |
sStop := stop. |
|
399 |
||
16245 | 400 |
[ |
8874 | 401 |
"/ Transcript showCR:('match: ''' , (aString copyFrom:sStart to:sStop) , |
3537 | 402 |
"/ ''' against:' , (matchScanArray copyFrom:mStart to:mStop) printString). |
403 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
404 |
mSize := mStop - mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
405 |
sSize := sStop - sStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
406 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
407 |
"empty strings match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
408 |
(mSize == 0) ifTrue:[^ (sSize == 0)]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
409 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
410 |
matchEntry := matchScanArray at:mStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
411 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
412 |
"/ the most common case first: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
413 |
(sSize ~~ 0 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
414 |
and:[(checkChar := (aString at:sStart)) = matchEntry]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
415 |
"advance by one and continue" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
416 |
mStart := mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
417 |
sStart := sStart + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
418 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
419 |
(matchEntry == #any) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
420 |
"restString empty -> no match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
421 |
(sSize == 0) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
422 |
"# matches single character" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
423 |
((sSize == 1) and:[mSize == 1]) ifTrue:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
424 |
"advance by one and continue" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
425 |
mStart := mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
426 |
sStart := sStart + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
427 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
428 |
(matchEntry == #anyString) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
429 |
"* alone matches anything" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
430 |
(mSize == 1) ifTrue:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
431 |
"restString empty & matchString not empty -> no match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
432 |
(sSize == 0) ifTrue:[^ false]. |
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 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
435 |
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
|
436 |
character and continue with shortened strings if possible |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
437 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
438 |
quickCheck := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
439 |
(mStop >= mStart) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
440 |
matchLast := matchScanArray at:mStop. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
441 |
(matchLast ~~ #anyString) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
442 |
(matchLast == #any) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
443 |
quickCheck := true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
444 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
445 |
matchLast == (aString at:sStop) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
446 |
quickCheck := true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
447 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
448 |
matchLast isString ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
449 |
quickCheck := matchLast includes:(aString at:sStop) |
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 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
455 |
quickCheck ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
456 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
457 |
quickCheck ok, advance from the right |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
458 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
459 |
mStop := mStop - 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
460 |
sStop := sStop - 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
461 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
462 |
"/ no quick check; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
463 |
"/ look for the next character(s) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
464 |
"/ and try matching there |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
465 |
"/ (to avoid recursion) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
466 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
467 |
mStart < mStop ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
468 |
nextMatchEntry := matchScanArray at:mStart+1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
469 |
nextMatchEntry isCharacter ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
470 |
sStart <= sStop ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
471 |
[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
472 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
473 |
index := aString indexOf:nextMatchEntry startingAt:sStart |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
474 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
475 |
index := aString findFirst:[:c | c asLowercase = nextMatchEntry asLowercase] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
476 |
startingAt:sStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
477 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
478 |
(index == 0 or:[index > sStop]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
479 |
^ false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
480 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
481 |
(self matchScan:matchScanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
482 |
from:(mStart + 1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
483 |
to:mStop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
484 |
with:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
485 |
from:index |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
486 |
to:sStop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
487 |
caseSensitive:caseSensitive |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
488 |
) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
489 |
^ true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
490 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
491 |
sStart := index + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
492 |
] loop. |
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 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
498 |
no quick check possible; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
499 |
loop over all possible substrings |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
500 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
501 |
index := sStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
502 |
[index <= sStop] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
503 |
(self matchScan:matchScanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
504 |
from:(mStart + 1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
505 |
to:mStop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
506 |
with:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
507 |
from:index |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
508 |
to:sStop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
509 |
caseSensitive:caseSensitive |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
510 |
) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
511 |
^ true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
512 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
513 |
index := index + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
514 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
515 |
^ false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
516 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
517 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
518 |
(matchEntry isString) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
519 |
"testString empty -> no match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
520 |
(sSize == 0) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
521 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
522 |
included := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
523 |
"/ checkChar := aString at:sStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
524 |
included := matchEntry includes:checkChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
525 |
included ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
526 |
caseSensitive ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
527 |
checkChar isUppercase ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
528 |
included := matchEntry includes:checkChar asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
529 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
530 |
included := matchEntry includes:checkChar asUppercase. |
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 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
534 |
mStart := mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
535 |
mSize := mSize - 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
536 |
included ifFalse:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
537 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
538 |
((sSize == 1) and:[mSize == 0]) ifTrue:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
539 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
540 |
"/ must be single character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
541 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
542 |
"testString empty ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
543 |
(sSize == 0) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
544 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
545 |
"first characters equal ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
546 |
"/ checkChar := aString at:sStart. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
547 |
caseSensitive ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
548 |
(checkChar asUppercase ~= matchEntry asUppercase) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
549 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
550 |
"advance and continue" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
551 |
mStart := mStart + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
552 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
553 |
"cut off 1st char and continue" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
554 |
sStart := sStart + 1 |
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 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
557 |
] |
16245 | 558 |
] loop. |
2519
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 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
561 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
562 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
563 |
scanArray := self matchScanArrayFrom:'*hello'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
564 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
565 |
CharacterArray |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
566 |
matchScan:scanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
567 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
568 |
to:scanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
569 |
with:s |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
570 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
571 |
to:s size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
572 |
caseSensitive:true |
2519
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 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
575 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
576 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
577 |
scanArray := self matchScanArrayFrom:'*hello*'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
578 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
579 |
CharacterArray |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
580 |
matchScan:scanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
581 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
582 |
to:scanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
583 |
with:s |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
584 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
585 |
to:s size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
586 |
caseSensitive:true |
15734 | 587 |
" |
588 |
||
589 |
"Modified: / 24-07-2011 / 07:17:03 / cg" |
|
590 |
"Modified (comment): / 24-07-2011 / 08:55:14 / cg" |
|
591 |
! |
|
592 |
||
593 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop ignoreCase:ignoreCase |
|
594 |
<resource: #obsolete> |
|
595 |
"helper for match; return true if the characters from start to stop in |
|
596 |
aString are matching the scan in matchScan from matchStart to matchStop. |
|
597 |
The matchScan is as created by asMatchScanArray. |
|
598 |
||
599 |
This algorithm is not at all the most efficient; |
|
600 |
for heavy duty pattern matching, an interface (primitive) to the regex |
|
601 |
pattern matching package should be added." |
|
602 |
||
603 |
^ self |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
604 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop caseSensitive:ignoreCase not |
15734 | 605 |
|
606 |
" |
|
607 |
|scanArray s| |
|
608 |
||
609 |
scanArray := self matchScanArrayFrom:'*hello'. |
|
610 |
s := 'foo bar hello world'. |
|
611 |
CharacterArray |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
612 |
matchScan:scanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
613 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
614 |
to:scanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
615 |
with:s |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
616 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
617 |
to:s size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
618 |
ignoreCase:false |
15734 | 619 |
" |
620 |
" |
|
621 |
|scanArray s| |
|
622 |
||
623 |
scanArray := self matchScanArrayFrom:'*hello*'. |
|
624 |
s := 'foo bar hello world'. |
|
625 |
CharacterArray |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
626 |
matchScan:scanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
627 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
628 |
to:scanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
629 |
with:s |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
630 |
from:1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
631 |
to:s size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
632 |
ignoreCase:false |
13520 | 633 |
" |
634 |
||
635 |
"Modified: / 24-07-2011 / 07:17:03 / cg" |
|
636 |
"Modified (comment): / 24-07-2011 / 08:55:14 / cg" |
|
608 | 637 |
! |
638 |
||
639 |
matchScanArrayFrom:aString |
|
640 |
"scan a pattern string and decompose it into a scanArray. |
|
641 |
This is processed faster (especially with character ranges), and |
|
642 |
can also be reused later. (if the same pattern is to be searched again)" |
|
643 |
||
9282
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
644 |
^ self matchScanArrayFrom:aString escapeCharacter:(self matchEscapeCharacter) |
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 |
" |
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:'**ute**' |
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:'\*uter' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
651 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
652 |
String matchScanArrayFrom:'[abcd]*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
653 |
String matchScanArrayFrom:'[a-k]*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
654 |
String matchScanArrayFrom:'*some*compl*ern*' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
655 |
String matchScanArrayFrom:'[a-' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
656 |
String matchScanArrayFrom:'[a-zA-Z]' |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
657 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
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 |
|
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
660 |
"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
|
661 |
! |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
662 |
|
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
663 |
matchScanArrayFrom:aString escapeCharacter:escape |
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
664 |
"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
|
665 |
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
|
666 |
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
|
667 |
|
8874 | 668 |
|coll |
608 | 669 |
idx "{ Class: SmallInteger }" |
9282
f6d9d4129919
allow for different escape cahracter in matches
Claus Gittinger <cg@exept.de>
parents:
9275
diff
changeset
|
670 |
end c1 c2 matchSet previous| |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
671 |
|
5487 | 672 |
previous := nil. |
608 | 673 |
|
674 |
coll := OrderedCollection new. |
|
675 |
idx := 1. end := aString size. |
|
676 |
[idx <= end] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
677 |
|char this| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
678 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
679 |
char := aString at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
680 |
char == $* ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
681 |
previous ~~ #anyString ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
682 |
this := #anyString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
683 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
684 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
685 |
char == $# ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
686 |
previous ~~ #anyString ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
687 |
this := #any |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
688 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
689 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
690 |
char == $[ ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
691 |
matchSet := IdentitySet new. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
692 |
idx := idx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
693 |
idx > end ifTrue:[^ nil]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
694 |
char := aString at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
695 |
c1 := nil. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
696 |
[char ~~ $]] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
697 |
((char == $-) and:[c1 notNil]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
698 |
idx := idx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
699 |
idx > end ifTrue:[^ nil]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
700 |
c2 := aString at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
701 |
c1 to:c2 do:[:c | matchSet add:c]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
702 |
c1 := nil. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
703 |
idx := idx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
704 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
705 |
(char ~~ $]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
706 |
matchSet add:char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
707 |
c1 := char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
708 |
idx := idx + 1 |
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 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
711 |
idx > end ifTrue:[^ nil]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
712 |
char := aString at:idx |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
713 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
714 |
this := matchSet asString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
715 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
716 |
char == escape ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
717 |
idx := idx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
718 |
idx > end ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
719 |
"/ mhmh - what should we do here ? |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
720 |
this := char |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
721 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
722 |
this := aString at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
723 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
724 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
725 |
this := char |
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 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
730 |
this notNil ifTrue:[coll add:this. previous := this]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
731 |
idx := idx + 1 |
608 | 732 |
]. |
733 |
||
734 |
^ coll asArray |
|
735 |
||
736 |
" |
|
8874 | 737 |
String matchScanArrayFrom:'*ute*' |
738 |
String matchScanArrayFrom:'**ute**' |
|
739 |
String matchScanArrayFrom:'*uter' |
|
740 |
String matchScanArrayFrom:'\*uter' |
|
741 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
|
742 |
String matchScanArrayFrom:'[abcd]*' |
|
743 |
String matchScanArrayFrom:'[a-k]*' |
|
744 |
String matchScanArrayFrom:'*some*compl*ern*' |
|
745 |
String matchScanArrayFrom:'[a-' |
|
746 |
String matchScanArrayFrom:'[a-zA-Z]' |
|
747 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
|
608 | 748 |
" |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
749 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
750 |
"Modified: 2.4.1997 / 16:20:29 / cg" |
9192 | 751 |
! ! |
752 |
||
753 |
!CharacterArray class methodsFor:'queries'! |
|
754 |
||
755 |
isAbstract |
|
11229 | 756 |
"Return if this class is an abstract class. |
757 |
True is returned for CharacterArray here; false for subclasses. |
|
19464 | 758 |
Abstract subclasses must redefine this again." |
11229 | 759 |
|
9192 | 760 |
^ self == CharacterArray |
18597 | 761 |
! |
762 |
||
763 |
speciesForCharacterSize:characterSize |
|
764 |
"answer the class, that is able to hold characters of size characterSize" |
|
765 |
||
766 |
characterSize <= 8 ifTrue:[^ String]. |
|
767 |
characterSize <= 16 ifTrue:[^ Unicode16String]. |
|
768 |
^ Unicode32String |
|
9192 | 769 |
! ! |
770 |
||
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 |
|
19497 | 899 |
equalsIgnoreCase:aString |
900 |
"This is an ST/V compatibility method and an alias for sameAs:." |
|
901 |
||
902 |
^ self sameAs:aString |
|
903 |
||
904 |
" |
|
905 |
'abc' equalsIgnoreCase: 'aBC' |
|
906 |
" |
|
907 |
! |
|
908 |
||
608 | 909 |
replChar:oldChar with:newChar |
19497 | 910 |
"return a copy of the receiver, with all oldChars replaced by newChar. |
911 |
This is an ST/V compatibility method and an alias for copyReplaceAll." |
|
608 | 912 |
|
3656 | 913 |
^ self copyReplaceAll:oldChar with:newChar |
608 | 914 |
|
915 |
" |
|
8874 | 916 |
'12345678901234567890' replChar:$0 with:$* |
608 | 917 |
" |
3656 | 918 |
|
919 |
"Modified: / 18.7.1998 / 22:52:57 / cg" |
|
608 | 920 |
! |
921 |
||
922 |
replChar:oldChar withString:newString |
|
923 |
"return a copy of the receiver, with all oldChars replaced |
|
924 |
by newString (i.e. slice in the newString in place of the oldChar). |
|
925 |
This is an ST/V compatibility method." |
|
926 |
||
927 |
|tmpStream| |
|
928 |
||
15523 | 929 |
tmpStream := self species writeStream. |
608 | 930 |
self do:[:element | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
931 |
element = oldChar ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
932 |
tmpStream nextPutAll:newString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
933 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
934 |
tmpStream nextPut:element |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
935 |
]. |
608 | 936 |
]. |
937 |
^ tmpStream contents |
|
938 |
||
939 |
" |
|
8874 | 940 |
'12345678901234567890' replChar:$0 withString:'foo' |
941 |
'a string with spaces' replChar:$ withString:' foo ' |
|
608 | 942 |
" |
9192 | 943 |
! |
944 |
||
945 |
replString:subString withString:newString |
|
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
946 |
"return a copy of the receiver, with all sequences of subString replaced |
18390 | 947 |
by newString (i.e. slice in the newString in place of the oldString). |
19497 | 948 |
This is an ST/V compatibility method and an alias for copyReplaceString." |
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
949 |
|
8347 | 950 |
^ self copyReplaceString:subString withString:newString |
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
951 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
952 |
" |
8874 | 953 |
'12345678901234567890' replString:'123' withString:'OneTwoThree' |
954 |
'12345678901234567890' replString:'123' withString:'*' |
|
955 |
'12345678901234567890' replString:'234' withString:'foo' |
|
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
956 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
957 |
('a string with spaces' replChar:$ withString:' foo ') |
18390 | 958 |
replString:'foo' withString:'bar' |
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
959 |
" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
960 |
|
8347 | 961 |
"Modified: / 12-05-2004 / 12:00:27 / cg" |
9192 | 962 |
! |
963 |
||
9275 | 964 |
subString:start to:end |
18390 | 965 |
"same as copyFrom:to: |
19497 | 966 |
This is an ST/V compatibility method and an alias for copyFrom:to:." |
18390 | 967 |
|
9275 | 968 |
^ self copyFrom:start to:end |
969 |
||
970 |
" |
|
971 |
'12345678901234567890' subString:3 to:8 |
|
972 |
" |
|
973 |
! |
|
974 |
||
9192 | 975 |
trimBlanks |
14992 | 976 |
"return a copy of the receiver without leading and trailing spaces. |
18464 | 977 |
This is an ST/V compatibility method and an alias for withoutSpaces." |
9192 | 978 |
|
979 |
^ self withoutSpaces |
|
980 |
||
981 |
" |
|
982 |
' spaces at beginning' trimBlanks |
|
983 |
'spaces at end ' trimBlanks |
|
984 |
' spaces at beginning and end ' trimBlanks |
|
985 |
'no spaces' trimBlanks |
|
986 |
" |
|
987 |
! ! |
|
988 |
||
989 |
!CharacterArray methodsFor:'Compatibility-Squeak'! |
|
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
990 |
|
19171 | 991 |
asBoldText |
992 |
"return self as a bold text" |
|
993 |
||
994 |
^Text string: self emphasis: #bold |
|
995 |
! |
|
996 |
||
6148 | 997 |
asDate |
998 |
"Many allowed forms, see Date.readFrom:" |
|
999 |
||
1000 |
^ Date readFrom: (ReadStream on: self) |
|
1001 |
||
1002 |
" |
|
8874 | 1003 |
'30 Apr 1999' asDate dayName capitalized |
6148 | 1004 |
" |
1005 |
! |
|
1006 |
||
16051 | 1007 |
asOneByteString |
1008 |
"return the receiver converted to a 'normal' string. |
|
18391 | 1009 |
Same as asSingleByteString - for Squeak/Pharo compatibility." |
16051 | 1010 |
|
1011 |
^ self asSingleByteString |
|
1012 |
! |
|
1013 |
||
8971 | 1014 |
asUrl |
18391 | 1015 |
"Same as asURL - for Squeak/Pharo compatibility." |
1016 |
||
8971 | 1017 |
^ self asURL |
1018 |
! |
|
1019 |
||
10840 | 1020 |
asWideString |
18391 | 1021 |
"return a two-byte string containing the same characters as the receiver. |
1022 |
Same as asTwoByteString - for Squeak/Pharo compatibility." |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1023 |
|
10840 | 1024 |
^ self asTwoByteString |
1025 |
||
1026 |
" |
|
1027 |
'abc' asWideString |
|
1028 |
" |
|
1029 |
! |
|
1030 |
||
4989 | 1031 |
capitalized |
18391 | 1032 |
"same as asUppercaseFirst for Squeak/Pharo compatibility" |
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1033 |
|
4989 | 1034 |
^ self asUppercaseFirst |
1035 |
||
1036 |
" |
|
1037 |
'hello' capitalized |
|
1038 |
" |
|
1039 |
! |
|
1040 |
||
10841 | 1041 |
caseInsensitiveLessOrEqual:aString |
18391 | 1042 |
"compare the receiver against the argument ignoring case differences |
1043 |
For Squeak/Pharo compatibility" |
|
1044 |
||
10841 | 1045 |
^ (self compareCaselessWith:aString) <= 0 |
1046 |
! |
|
1047 |
||
1048 |
caseSensitiveLessOrEqual:aString |
|
18391 | 1049 |
"compare the receiver against the argument caring for case differences |
1050 |
For Squeak/Pharo compatibility" |
|
1051 |
||
10841 | 1052 |
^ self <= aString |
1053 |
! |
|
1054 |
||
1055 |
charactersExactlyMatching:aString |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1056 |
"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
|
1057 |
|
10841 | 1058 |
|idx nMax| |
1059 |
||
1060 |
nMax :=(self size) min:(aString size). |
|
1061 |
idx := 1. |
|
1062 |
[idx <= nMax] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1063 |
(self at:idx) = (aString at:idx) ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1064 |
^ idx - 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1065 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1066 |
idx := idx + 1. |
10841 | 1067 |
]. |
1068 |
^ nMax |
|
1069 |
||
1070 |
" |
|
12177 | 1071 |
'abc' charactersExactlyMatching:'abc' |
1072 |
'abc' charactersExactlyMatching:'abcd' |
|
1073 |
'abcd' charactersExactlyMatching:'abc' |
|
1074 |
'abc' charactersExactlyMatching:'abd' |
|
1075 |
'abc' charactersExactlyMatching:'xxx' |
|
10841 | 1076 |
" |
1077 |
! |
|
1078 |
||
9192 | 1079 |
endsWithDigit |
1080 |
"Answer whether the receiver's final character represents a digit. 3/11/96 sw" |
|
1081 |
||
18391 | 1082 |
|len| |
1083 |
||
1084 |
^ (len := self size) > 0 and: [(self at:len) isDigit] |
|
9192 | 1085 |
! |
1086 |
||
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1087 |
findDelimiters:delimiters startingAt:start |
18391 | 1088 |
"Answer the index of the character within the receiver, starting at start, |
1089 |
that matches one of the delimiters. |
|
1090 |
If the receiver does not contain any of the delimiters, answer size + 1." |
|
9192 | 1091 |
|
1092 |
|idx| |
|
1093 |
||
1094 |
idx := self indexOfAny:delimiters startingAt:start. |
|
1095 |
idx == 0 ifTrue:[^ self size + 1]. |
|
1096 |
^ idx. |
|
1097 |
"/start to: self size do: [:i | |
|
1098 |
"/ |char| |
|
1099 |
"/ |
|
1100 |
"/ char := self at: i. |
|
1101 |
"/ delimiters do: [:delim | delim = char ifTrue: [^ i]] |
|
8971 | 1102 |
"/ ]. |
1103 |
"/ ^ self size + 1 |
|
1104 |
! |
|
1105 |
||
13624 | 1106 |
findTokens:delimiterOrDelimiters |
7270 | 1107 |
"cg: I am not sure, if this is really the squeak semantics (w.r.t. empty fields)" |
1108 |
||
13624 | 1109 |
delimiterOrDelimiters size == 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1110 |
^ self asCollectionOfSubstringsSeparatedBy:delimiterOrDelimiters |
13624 | 1111 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1112 |
^ self asCollectionOfSubstringsSeparatedByAny:delimiterOrDelimiters |
13624 | 1113 |
]. |
7270 | 1114 |
|
1115 |
" |
|
8874 | 1116 |
'a|b#c||e' findTokens:#($# $|) |
13624 | 1117 |
'a|b#c||e' findTokens:$| |
1118 |
" |
|
1119 |
||
1120 |
"Modified: / 04-09-2011 / 20:31:21 / cg" |
|
1121 |
"Modified (comment): / 05-09-2011 / 04:25:28 / cg" |
|
4981 | 1122 |
! |
1123 |
||
4974 | 1124 |
includesSubString:aString |
1125 |
"return true, if a substring is contained in the receiver. |
|
1126 |
The compare is case sensitive." |
|
1127 |
||
1128 |
^ self includesString:aString |
|
1129 |
||
1130 |
" |
|
8874 | 1131 |
'hello world' includesSubString:'Hel' |
9192 | 1132 |
'hello world' includesSubString:'hel' |
1133 |
'hello world' includesSubString:'llo' |
|
1134 |
" |
|
1135 |
||
1136 |
||
1137 |
||
1138 |
! |
|
1139 |
||
11178 | 1140 |
includesSubString:aString caseSensitive:caseSensitive |
18391 | 1141 |
"sigh - an alias; added for Squeak/Pharo compatibility" |
1142 |
||
11179 | 1143 |
^ self includesSubstring:aString caseSensitive:caseSensitive |
11178 | 1144 |
! |
1145 |
||
16875
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1146 |
includesSubstring: aString |
18391 | 1147 |
"sigh - an alias; added for Squeak/Pharo compatibility" |
1148 |
||
16875
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1149 |
^ self includesSubString: aString |
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1150 |
|
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1151 |
"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
|
1152 |
! |
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1153 |
|
9192 | 1154 |
includesSubstring:aString caseSensitive:caseSensitive |
9190 | 1155 |
"return true, if a substring is contained in the receiver. |
9192 | 1156 |
The argument, caseSensitive controls if case is ignored in the compare." |
1157 |
||
1158 |
"/ for now, a q&d hack ... |
|
1159 |
||
1160 |
caseSensitive ifFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1161 |
^ self asLowercase includesString:aString asLowercase |
9192 | 1162 |
]. |
9190 | 1163 |
^ self includesString:aString |
1164 |
||
1165 |
" |
|
9192 | 1166 |
'hello world' includesSubstring:'Hel' caseSensitive:true |
1167 |
'hello world' includesSubstring:'Hel' caseSensitive:false |
|
1168 |
" |
|
1169 |
||
1170 |
||
1171 |
||
1172 |
! |
|
9190 | 1173 |
|
6979 | 1174 |
isAllDigits |
1175 |
"Answer whether the receiver's characters are all digits" |
|
1176 |
||
1177 |
^ self conform:[:eachChar | eachChar isDigit] |
|
1178 |
||
1179 |
" |
|
1180 |
'hello world' isAllDigits |
|
1181 |
'12344' isAllDigits |
|
1182 |
" |
|
1183 |
! |
|
1184 |
||
4890 | 1185 |
lastSpacePosition |
18391 | 1186 |
"return the index of the last space character; 0 if there is none. |
1187 |
Added for Squeak/Pharo compatibility" |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1188 |
|
4890 | 1189 |
^ self lastIndexOfSeparator |
1190 |
! |
|
1191 |
||
7022 | 1192 |
padded:leftOrRight to:paddedSize with:padCharacter |
14053
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1193 |
"pad left (leftOrRight==#left) or right" |
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1194 |
|
7022 | 1195 |
leftOrRight == #left ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1196 |
^ self leftPaddedTo:paddedSize with:padCharacter |
9190 | 1197 |
]. |
1198 |
^ self paddedTo:paddedSize with:padCharacter |
|
1199 |
||
1200 |
" |
|
8874 | 1201 |
'hello' padded:#right to:10 with:$. |
9192 | 1202 |
'hello' padded:#left to:10 with:$. |
1203 |
" |
|
14053
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1204 |
|
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1205 |
"Modified (comment): / 07-03-2012 / 16:31:33 / cg" |
9192 | 1206 |
! |
1207 |
||
1208 |
skipDelimiters:delimiters startingAt:start |
|
1209 |
"Answer the index of the character within the receiver, starting at start, |
|
1210 |
that does NOT match one of the delimiters. |
|
1211 |
If the receiver does not contain any of the delimiters, answer size + 1. |
|
1212 |
Assumes the delimiters to be a non-empty string." |
|
1213 |
||
1214 |
start to:self size do:[:i | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1215 |
delimiters detect:[:delim | delim = (self at:i) ] ifNone:[ ^ i ] |
9192 | 1216 |
]. |
1217 |
^ self size + 1 |
|
1218 |
||
1219 |
" |
|
1220 |
'123***7890' skipDelimiters:'*' startingAt:4 |
|
1221 |
'123***7890' skipDelimiters:'*' startingAt:3 |
|
9190 | 1222 |
'123***7890' skipDelimiters:'*' startingAt:10 |
1223 |
'123*******' skipDelimiters:'*' startingAt:10 |
|
8874 | 1224 |
" |
1225 |
! |
|
1226 |
||
9190 | 1227 |
substrings |
18921 | 1228 |
"return a collection consisting of all words contained in the receiver. |
17517 | 1229 |
Words are separated by whitespace. |
1230 |
This has been added for Squeak compatibility. |
|
1231 |
(sigh: it is called #'subStrings' in V'Age, and #'asCollectionOfWords' in ST/X) " |
|
1232 |
||
9190 | 1233 |
^ self asCollectionOfWords |
1234 |
||
1235 |
" |
|
1236 |
'foo bar baz' substrings |
|
1237 |
" |
|
1238 |
! |
|
1239 |
||
12665
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1240 |
substringsSeparatedBy:separatorCharacter |
18921 | 1241 |
"return a collection consisting of all words contained in the receiver. |
1242 |
Words are separated by the given separator character. |
|
1243 |
This has been added for Squeak/Pharo compatibility. |
|
1244 |
(sigh: it is called #'subStrings:' in V'Age, |
|
1245 |
and #'asCollectionOfSubstringsSeparatedBy' in ST/X) " |
|
18391 | 1246 |
|
12665
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1247 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1248 |
|
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1249 |
" |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1250 |
'foo bar, baz' substringsSeparatedBy:$, |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1251 |
" |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1252 |
! |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1253 |
|
9190 | 1254 |
truncateTo:smallSize |
9192 | 1255 |
"return myself or a copy shortened to smallSize. 1/18/96 sw" |
1256 |
||
1257 |
self size <= smallSize ifTrue:[^ self]. |
|
1258 |
^ self copyFrom: 1 to: smallSize |
|
1259 |
||
1260 |
" |
|
1261 |
'hello world' truncateTo:5 |
|
1262 |
'hello' truncateTo:10 |
|
1263 |
||
1264 |
'hello world' copyTo:5 |
|
1265 |
'hello' copyTo:10 |
|
1266 |
" |
|
1267 |
! |
|
5795 | 1268 |
|
4890 | 1269 |
withBlanksTrimmed |
18464 | 1270 |
"Return a copy of the receiver from which leading and trailing whitespace have been trimmed. |
1271 |
Notice the bad naming - it is trimming separators, not just blanks. |
|
1272 |
Added for Squeak compatibility and an alias for withoutSeparators" |
|
4890 | 1273 |
|
14865 | 1274 |
^ self withoutSeparators "withoutSpaces" "/ cg: it seems that squeak cares for any whitespace |
4890 | 1275 |
|
1276 |
" |
|
8874 | 1277 |
' hello world ' withBlanksTrimmed |
4890 | 1278 |
" |
1279 |
! |
|
1280 |
||
1281 |
withNoLineLongerThan: aNumber |
|
1282 |
"Answer a string with the same content as receiver, but rewrapped so that no line has more characters than the given number" |
|
1283 |
||
9192 | 1284 |
| listOfLines currentLast currentStart resultString putativeLast putativeLine crPosition | |
1285 |
||
14451
c06e7885b675
changed: #withNoLineLongerThan:
Claus Gittinger <cg@exept.de>
parents:
14420
diff
changeset
|
1286 |
(aNumber isNumber not or:[ aNumber < 1] ) ifTrue: [self error: 'too narrow']. |
9192 | 1287 |
listOfLines _ OrderedCollection new. |
1288 |
currentLast _ 0. |
|
1289 |
[currentLast < self size] whileTrue: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1290 |
[currentStart _ currentLast + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1291 |
putativeLast _ (currentStart + aNumber - 1) min: self size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1292 |
putativeLine _ self copyFrom: currentStart to: putativeLast. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1293 |
(crPosition _ putativeLine indexOf: Character cr) > 0 ifTrue: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1294 |
[putativeLast _ currentStart + crPosition - 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1295 |
putativeLine _ self copyFrom: currentStart to: putativeLast]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1296 |
currentLast _ putativeLast == self size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1297 |
ifTrue: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1298 |
[putativeLast] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1299 |
ifFalse: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1300 |
[currentStart + putativeLine lastSpacePosition - 1]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1301 |
currentLast <= currentStart ifTrue: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1302 |
["line has NO spaces; baleout!!" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1303 |
currentLast _ putativeLast]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1304 |
listOfLines add: (self copyFrom: currentStart to: currentLast) withBlanksTrimmed]. |
9192 | 1305 |
|
1306 |
listOfLines size > 0 ifFalse: [^ '']. |
|
1307 |
resultString _ listOfLines first. |
|
1308 |
2 to: listOfLines size do: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1309 |
[:i | resultString _ resultString, Character cr asString, (listOfLines at: i)]. |
9192 | 1310 |
^ resultString |
1311 |
||
1312 |
" |
|
1313 |
#(5 7 20) collect: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1314 |
[: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
|
1315 |
" |
10883 | 1316 |
! |
1317 |
||
12343
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1318 |
withSqueakLineEndings |
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1319 |
"assume the string is textual, and that CR, LF, and CRLF are all |
18391 | 1320 |
valid line endings. Replace each occurence with a single CR" |
12343
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1321 |
|
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1322 |
^ self asStringCollection asStringWith:Character cr. |
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1323 |
! |
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1324 |
|
12188 | 1325 |
withoutLeading: char |
1326 |
"return a copy of myself without leading a char. |
|
1327 |
Returns an empty string, if the receiver consist only of a char." |
|
1328 |
||
1329 |
^ self withoutLeadingForWhich:[: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****' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1333 |
'foo****' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1334 |
'*' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1335 |
'' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1336 |
'****foo' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1337 |
'*******' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1338 |
'foo' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1339 |
'f***o***o' withoutLeading: $* |
12188 | 1340 |
('**' , Character tab asString , '*foo***') withoutLeading: $* inspect |
1341 |
" |
|
1342 |
! |
|
1343 |
||
11565 | 1344 |
withoutTrailing:char |
1345 |
"return a copy of myself without trailing char. |
|
1346 |
Returns an empty string, if the receiver consist only of char." |
|
1347 |
||
12188 | 1348 |
^ self withoutTrailingForWhich:[:ch | ch = char] |
1349 |
||
1350 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1351 |
' foo....' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1352 |
'foo....' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1353 |
' foo' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1354 |
'.......' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1355 |
'foo' withoutTrailing:$. |
11565 | 1356 |
" |
9190 | 1357 |
! ! |
1358 |
||
1359 |
!CharacterArray methodsFor:'Compatibility-V''Age'! |
|
1360 |
||
1361 |
addLineDelimiter |
|
1362 |
"replace all '\'-characters by line delimiter (cr) - characters. |
|
9192 | 1363 |
This has been added for VisualAge compatibility." |
1364 |
||
1365 |
^ self withCRs |
|
1366 |
! |
|
1367 |
||
1368 |
bindWith:aString |
|
1369 |
"return a copy of the receiver, where a '%1' escape is |
|
1370 |
replaced by aString. |
|
1371 |
This has been added for VisualAge compatibility." |
|
1372 |
||
1373 |
^ self expandPlaceholdersWith:(Array with:aString) |
|
1374 |
||
1375 |
" |
|
1376 |
'do you like %1 ?' bindWith:'smalltalk' |
|
1377 |
" |
|
1378 |
! |
|
608 | 1379 |
|
1380 |
bindWith:string1 with:string2 |
|
1381 |
"return a copy of the receiver, where a '%1' escape is |
|
1382 |
replaced by string1 and '%2' is replaced by string2. |
|
1383 |
This has been added for VisualAge compatibility." |
|
1384 |
||
1385 |
^ self expandPlaceholdersWith:(Array with:string1 with:string2) |
|
1386 |
||
1387 |
" |
|
1388 |
'do you prefer %1 or rather %2 ?' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1389 |
bindWith:'smalltalk' with:'c++' |
9192 | 1390 |
" |
1391 |
! |
|
9190 | 1392 |
|
1393 |
bindWith:str1 with:str2 with:str3 |
|
608 | 1394 |
"return a copy of the receiver, where a '%1', '%2' and '%3' escapes |
1395 |
are replaced by str1, str2 and str3 respectively. |
|
1396 |
This has been added for VisualAge compatibility." |
|
1397 |
||
1398 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3) |
|
1399 |
||
1400 |
" |
|
9192 | 1401 |
'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
|
1402 |
bindWith:'smalltalk' with:'c++' with:'c' |
9192 | 1403 |
" |
1404 |
! |
|
608 | 1405 |
|
1406 |
bindWith:str1 with:str2 with:str3 with:str4 |
|
1407 |
"return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes |
|
1408 |
are replaced by str1, str2, str3 and str4 respectively. |
|
1409 |
This has been added for VisualAge compatibility." |
|
1410 |
||
1411 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4) |
|
1412 |
||
1413 |
" |
|
9192 | 1414 |
'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
|
1415 |
bindWith:'smalltalk' with:'c++' with:'c' with:'assembler' |
9192 | 1416 |
" |
1417 |
! |
|
608 | 1418 |
|
2344 | 1419 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 |
1420 |
"return a copy of the receiver, where a '%1' .. '%5' escapes |
|
1421 |
are replaced by str1 .. str5 respectively. |
|
1422 |
This has been added for VisualAge compatibility." |
|
1423 |
||
1424 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5) |
|
1425 |
||
1426 |
"Created: 31.1.1997 / 16:25:42 / cg" |
|
1427 |
! |
|
1428 |
||
5343 | 1429 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 |
1430 |
"return a copy of the receiver, where a '%1' .. '%6' escapes |
|
11524 | 1431 |
are replaced by str1 .. str6 respectively. |
5343 | 1432 |
This has been added for VisualAge compatibility." |
1433 |
||
8874 | 1434 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1435 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1436 |
with:str5 with:str6) |
11524 | 1437 |
! |
1438 |
||
1439 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 with:str7 |
|
1440 |
"return a copy of the receiver, where a '%1' .. '%7' escapes |
|
1441 |
are replaced by str1 .. str7 respectively. |
|
1442 |
This has been added for VisualAge compatibility." |
|
1443 |
||
1444 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1445 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1446 |
with:str5 with:str6 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1447 |
with:str7) |
5343 | 1448 |
! |
1449 |
||
13996
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1450 |
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
|
1451 |
"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
|
1452 |
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
|
1453 |
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
|
1454 |
|
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1455 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1456 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1457 |
with:str5 with:str6 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1458 |
with:str7 with:str8) |
13996
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1459 |
|
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1460 |
"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
|
1461 |
! |
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1462 |
|
14014
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1463 |
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
|
1464 |
"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
|
1465 |
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
|
1466 |
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
|
1467 |
|
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1468 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1469 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1470 |
with:str5 with:str6 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1471 |
with:str7 with:str8 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1472 |
with:str9) |
14014
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1473 |
|
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1474 |
"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
|
1475 |
! |
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1476 |
|
608 | 1477 |
bindWithArguments:anArrayOfStrings |
1478 |
"return a copy of the receiver, where a '%i' escape |
|
1479 |
is replaced by the coresponding string from the argument array. |
|
1480 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
1481 |
This has been added for VisualAge compatibility." |
|
1482 |
||
9192 | 1483 |
^ self expandPlaceholdersWith:anArrayOfStrings |
1484 |
||
1485 |
" |
|
1486 |
'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
|
1487 |
bindWithArguments:#('smalltalk' 'c++' 'c') |
12196 | 1488 |
|
1489 |
'do you %(what) ?' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1490 |
bindWithArguments:(Dictionary new at:#'what' put:'understand'; yourself) |
9192 | 1491 |
" |
1492 |
! |
|
608 | 1493 |
|
1494 |
subStrings |
|
18921 | 1495 |
"return a collection consisting of all words contained in the receiver. |
608 | 1496 |
Words are separated by whitespace. |
17517 | 1497 |
This has been added for VisualAge compatibility. |
1498 |
(sigh: it is called #'subbtrings' in Squeak, and #'asCollectionOfWords' in ST/X) " |
|
608 | 1499 |
|
1500 |
^ self asCollectionOfWords |
|
1501 |
||
1502 |
" |
|
1503 |
'hello world, this is smalltalk' subStrings |
|
1504 |
" |
|
1505 |
! |
|
1506 |
||
16181 | 1507 |
subStrings:separatorCharacterOrString |
18921 | 1508 |
"return a collection consisting of all words contained in the receiver. |
608 | 1509 |
Words are separated by separatorCharacter. |
18921 | 1510 |
This is similar to split: (squeak) and asCollectionOfSubstringsSeparatedBy: (st/x) |
1511 |
and has been added for VisualAge compatibility." |
|
608 | 1512 |
|
16181 | 1513 |
separatorCharacterOrString isCharacter ifTrue:[ |
18921 | 1514 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacterOrString |
16181 | 1515 |
]. |
1516 |
^ self asCollectionOfSubstringsSeparatedByAny:separatorCharacterOrString |
|
1517 |
||
1518 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1519 |
'foo:bar:baz:smalltalk' subStrings:$: |
16181 | 1520 |
'foo:bar:baz:smalltalk' subStrings:':' |
1521 |
'foo.bar,baz-smalltalk' subStrings:'.,-' |
|
9192 | 1522 |
" |
1523 |
! |
|
1524 |
||
1525 |
trimSeparators |
|
18392 | 1526 |
"return a copy of the receiver without leading and trailing whiteSpace. |
18921 | 1527 |
Added for VisualAge compatibility (an alias for withoutSeparators)" |
9192 | 1528 |
|
1529 |
^ self withoutSeparators |
|
1530 |
! ! |
|
1531 |
||
1532 |
!CharacterArray methodsFor:'Compatibility-VW'! |
|
5964 | 1533 |
|
6139 | 1534 |
asLogicalFileSpecification |
1535 |
^ self asFilename |
|
1536 |
||
1537 |
"Created: / 30.10.2001 / 17:29:53 / cg" |
|
1538 |
! |
|
1539 |
||
5964 | 1540 |
expandMacros |
1541 |
"ST80 compatibility - expand '<..>' macros with |
|
1542 |
argument strings. Similar to #bindWith:. |
|
1543 |
Read the comment in #expandMacrosWithArguments: about |
|
1544 |
limited compatibility issues." |
|
1545 |
||
1546 |
^ self expandMacrosWithArguments:#() |
|
1547 |
||
1548 |
" |
|
1549 |
'hello<n>foo' expandMacros |
|
1550 |
" |
|
1551 |
||
9192 | 1552 |
"Modified: / 18.6.1998 / 16:03:02 / cg" |
1553 |
! |
|
1554 |
||
1555 |
expandMacrosWith:arg |
|
5964 | 1556 |
"ST80 compatibility - expand '<..>' macros with |
1557 |
argument strings. Similar to #bindWith:. |
|
1558 |
Read the comment in #expandMacrosWithArguments: about |
|
1559 |
limited compatibility issues." |
|
1560 |
||
9192 | 1561 |
^ self expandMacrosWithArguments:(Array with:arg) |
1562 |
||
1563 |
"Created: / 1.11.1997 / 13:01:28 / cg" |
|
1564 |
"Modified: / 1.11.1997 / 13:30:50 / cg" |
|
1565 |
! |
|
5964 | 1566 |
|
1567 |
expandMacrosWith:arg1 with:arg2 |
|
1568 |
"ST80 compatibility - expand '<..>' macros with |
|
1569 |
argument strings. Similar to #bindWith:. |
|
1570 |
Read the comment in #expandMacrosWithArguments: about |
|
1571 |
limited compatibility issues." |
|
1572 |
||
1573 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2) |
|
1574 |
||
1575 |
"Modified: / 6.7.1998 / 21:58:14 / cg" |
|
1576 |
! |
|
1577 |
||
1578 |
expandMacrosWith:arg1 with:arg2 with:arg3 |
|
1579 |
"ST80 compatibility - expand '<..>' macros with |
|
1580 |
argument strings. Similar to #bindWith:. |
|
1581 |
Read the comment in #expandMacrosWithArguments: about |
|
1582 |
limited compatibility issues." |
|
1583 |
||
1584 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2 with:arg3) |
|
1585 |
! |
|
1586 |
||
10353
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1587 |
expandMacrosWith:arg1 with:arg2 with:arg3 with:arg4 |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1588 |
"ST80 compatibility - expand '<..>' macros with |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1589 |
argument strings. Similar to #bindWith:. |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1590 |
Read the comment in #expandMacrosWithArguments: about |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1591 |
limited compatibility issues." |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1592 |
|
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1593 |
^ 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
|
1594 |
! |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1595 |
|
9192 | 1596 |
expandMacrosWithArguments:argArray |
5964 | 1597 |
"ST80 compatibility - expand '<..>' macros with |
1598 |
argument strings. Similar to #bindWith:. |
|
1599 |
WARNING: possibly not all ST80 expansions are supported here." |
|
1600 |
||
1601 |
"/ supported expansions: |
|
1602 |
"/ |
|
1603 |
"/ <#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
|
1604 |
"/ <#s> # is arg Number; slice in the arg itself (must know asString) |
5964 | 1605 |
"/ <#?s1:s2> # is arg Number; slice in s1 if the arg is true, s2 otherwise |
7643 | 1606 |
"/ use first arg if # is not given (i.e. no number before s,p ...) |
5964 | 1607 |
"/ <n> replace by a newLine character |
1608 |
"/ <t> replace by a tab character |
|
6834
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
1609 |
"/ %X the X character itself |
5964 | 1610 |
|
8999
f3fda66ea51e
#expandMacrosWithArguments: - be mor friendly to xml strings.
Stefan Vogel <sv@exept.de>
parents:
8971
diff
changeset
|
1611 |
|in out c fmt nr arg s1 s2 peekc| |
5964 | 1612 |
|
1613 |
in := self readStream. |
|
10721
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1614 |
out := CharacterWriteStream on:(self species uninitializedNew:self size). |
5964 | 1615 |
|
1616 |
[in atEnd] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1617 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1618 |
c == $% ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1619 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1620 |
out nextPut:c |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1621 |
] ifFalse:[c ~~ $< ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1622 |
out nextPut:c. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1623 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1624 |
peekc := in peek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1625 |
[peekc == $<] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1626 |
out nextPut:$<. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1627 |
peekc := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1628 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1629 |
peekc == $n ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1630 |
peekc := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1631 |
peekc == $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1632 |
in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1633 |
out cr. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1634 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1635 |
out nextPutAll:'<n'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1636 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1637 |
] ifFalse:[peekc == $t ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1638 |
peekc := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1639 |
peekc == $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1640 |
in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1641 |
out tab. |
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 |
out nextPutAll:'<t'. |
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 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1646 |
peekc isDigit ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1647 |
"start an argument expansion ..." |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1648 |
nr := Integer readFrom:in onError:nil. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1649 |
nr isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1650 |
"this cannot happen (there is at least one digit)" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1651 |
self error:'invalid format' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1652 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1653 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1654 |
fmt := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1655 |
(fmt ~~ $? and:[in peek ~~ $>]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1656 |
out nextPut:$<. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1657 |
nr printOn:out. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1658 |
out nextPut:fmt. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1659 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1660 |
(nr between:1 and:argArray size) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1661 |
arg := argArray at:nr. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1662 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1663 |
arg := '' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1664 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1665 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1666 |
fmt == $p ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1667 |
"expand with args printString" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1668 |
arg printOn:out. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1669 |
] ifFalse:[fmt == $s ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1670 |
"expand with arg itself" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1671 |
arg isText ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1672 |
out contentsSpecies isText ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1673 |
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
|
1674 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1675 |
out nextPutAll:arg. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1676 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1677 |
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
|
1678 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1679 |
] ifFalse:[fmt == $? ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1680 |
s1 := in upTo:$:. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1681 |
s2 := in nextUpTo:$>. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1682 |
arg == true ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1683 |
out nextPutAll:s1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1684 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1685 |
out nextPutAll:s2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1686 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1687 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1688 |
"what does VW do here ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1689 |
self error:'invalid format' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1690 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1691 |
]]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1692 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1693 |
c ~~ $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1694 |
"what does VW do here ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1695 |
self error:'invalid format' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1696 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1697 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1698 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1699 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1700 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1701 |
out nextPut:$<. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1702 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1703 |
]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1704 |
]]. |
5964 | 1705 |
]. |
1706 |
^ out contents |
|
1707 |
||
1708 |
" |
|
8874 | 1709 |
'hello <1s> how are you' expandMacrosWith:(OperatingSystem getLoginName) |
1710 |
'one plus one is <1p>' expandMacrosWith:2 |
|
5964 | 1711 |
" |
1712 |
||
10721
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1713 |
"Modified: / 18-09-2007 / 22:50:43 / cg" |
9192 | 1714 |
! |
1715 |
||
1716 |
isCharacters |
|
1717 |
"added for visual works compatibility" |
|
1718 |
^ true |
|
1719 |
! ! |
|
1720 |
||
16295 | 1721 |
!CharacterArray methodsFor:'JavaScript support'! |
1722 |
||
1723 |
unquote |
|
17000 | 1724 |
"removes double quotes from the receiver. |
1725 |
This is the JavaSccript standard unquote function." |
|
1726 |
||
1727 |
|mySize| |
|
1728 |
||
1729 |
(mySize := self size) >= 2 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1730 |
((self first == $") and:[self last == $"]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1731 |
^ self copyFrom:2 to:mySize-1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1732 |
]. |
16295 | 1733 |
]. |
1734 |
^ self |
|
1735 |
||
1736 |
" |
|
17000 | 1737 |
'hello' quote unquote |
1738 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1739 |
JavaScriptParser evaluate:'''hello''.quote.unquote' |
16295 | 1740 |
" |
1741 |
! ! |
|
13510 | 1742 |
|
16175 | 1743 |
|
9192 | 1744 |
!CharacterArray methodsFor:'character searching'! |
1745 |
||
1746 |
includesMatchCharacters |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
1747 |
"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
|
1748 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1749 |
Here, do not care for $\ escapes" |
608 | 1750 |
|
1751 |
^ self includesAny:'*#[' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1752 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1753 |
" |
8874 | 1754 |
'*foo' includesMatchCharacters |
1755 |
'\*foo' includesMatchCharacters |
|
1756 |
'\*foo' includesUnescapedMatchCharacters |
|
1757 |
'*foo' includesMatchCharacters |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1758 |
'\\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1759 |
'foo*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1760 |
'foo\*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1761 |
'foo\' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1762 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1763 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1764 |
"Modified: 2.4.1997 / 18:12:34 / cg" |
9192 | 1765 |
! |
1766 |
||
1767 |
includesSeparator |
|
1768 |
"return true, if the receiver contains any whitespace characters" |
|
1769 |
||
1770 |
^ (self indexOfSeparator ~~ 0) |
|
1771 |
||
1772 |
" |
|
1773 |
'hello world' includesSeparator |
|
1774 |
'helloworld' includesSeparator |
|
1775 |
" |
|
1776 |
! |
|
1777 |
||
1778 |
includesUnescapedMatchCharacters |
|
8874 | 1779 |
"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
|
1780 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1781 |
Here, care for $\ escapes" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1782 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1783 |
|idx sz specialChars escape| |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1784 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1785 |
idx := 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1786 |
sz := self size. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1787 |
specialChars := '*#[\'. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1788 |
(escape := self class matchEscapeCharacter) ~~ $\ ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1789 |
specialChars := specialChars copy. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1790 |
specialChars at:specialChars size put:escape |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1791 |
]. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1792 |
|
16245 | 1793 |
[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1794 |
idx := self indexOfAny:specialChars startingAt:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1795 |
idx == 0 ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1796 |
(self at:idx) == escape ifFalse:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1797 |
idx := idx + 2. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1798 |
idx > sz ifTrue:[^ false]. |
16245 | 1799 |
] loop. |
8874 | 1800 |
|
1801 |
" |
|
1802 |
'*foo' includesUnescapedMatchCharacters |
|
1803 |
'\*foo' includesUnescapedMatchCharacters |
|
1804 |
'\\foo' includesUnescapedMatchCharacters |
|
1805 |
'\\\$foo' includesUnescapedMatchCharacters |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1806 |
'*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1807 |
'\\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1808 |
'foo*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1809 |
'foo\*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1810 |
'foo\' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1811 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1812 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1813 |
"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
|
1814 |
"Created: 2.4.1997 / 17:23:26 / cg" |
9192 | 1815 |
! |
1816 |
||
1817 |
indexOfControlCharacterStartingAt:startIndex |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1818 |
"return the index of the next control character; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1819 |
that is a character with asciiValue < 32. |
15605 | 1820 |
Start the search at startIndex, searching forward. |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1821 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1822 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1823 |
|start "{ Class: SmallInteger }" |
9192 | 1824 |
mySize "{ Class: SmallInteger }"| |
1825 |
||
1826 |
start := startIndex. |
|
1827 |
mySize := self size. |
|
1828 |
||
1829 |
start to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1830 |
(self at:index) isControlCharacter ifTrue:[^ index] |
9192 | 1831 |
]. |
1832 |
^ 0 |
|
1833 |
||
1834 |
" |
|
1835 |
'hello world' asTwoByteString indexOfControlCharacterStartingAt:1 |
|
1836 |
'hello world\foo' withCRsasTwoByteString indexOfControlCharacterStartingAt:1 |
|
1837 |
" |
|
1838 |
||
1839 |
"Modified: / 21.7.1998 / 17:25:07 / cg" |
|
1840 |
! |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1841 |
|
8541 | 1842 |
indexOfNonSeparator |
1843 |
"return the index of the first non-whitespace character. |
|
1844 |
return 0 if no non-separator was found" |
|
1845 |
||
1846 |
^ self indexOfNonSeparatorStartingAt:1. |
|
1847 |
||
1848 |
" |
|
8874 | 1849 |
' hello world' indexOfNonSeparator |
1850 |
' ' indexOfNonSeparator |
|
1851 |
'a ' indexOfNonSeparator |
|
1852 |
'abc' indexOfNonSeparator |
|
1853 |
' ' indexOfNonSeparator |
|
9192 | 1854 |
'' indexOfNonSeparator |
1855 |
" |
|
1856 |
! |
|
1857 |
||
1858 |
indexOfNonSeparatorStartingAt:startIndex |
|
4117 | 1859 |
"return the index of the next non-whitespace character, |
1860 |
starting the search at startIndex, searching forward; |
|
1861 |
return 0 if no non-separator was found" |
|
608 | 1862 |
|
1863 |
|start "{ Class: SmallInteger }" |
|
1864 |
mySize "{ Class: SmallInteger }"| |
|
1865 |
||
1866 |
start := startIndex. |
|
1867 |
mySize := self size. |
|
1868 |
||
1869 |
start to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1870 |
(self at:index) isSeparator ifFalse:[^ index] |
608 | 1871 |
]. |
1872 |
^ 0 |
|
1873 |
||
1874 |
" |
|
8874 | 1875 |
' hello world' indexOfNonSeparatorStartingAt:1 |
1876 |
' ' indexOfNonSeparatorStartingAt:1 |
|
1877 |
'a ' indexOfNonSeparatorStartingAt:2 |
|
4117 | 1878 |
" |
1879 |
||
608 | 1880 |
" |
1881 |
|s index1 index2| |
|
1882 |
s := ' foo bar baz'. |
|
1883 |
index1 := s indexOfNonSeparatorStartingAt:1. |
|
1884 |
index2 := s indexOfSeparatorStartingAt:index1. |
|
1885 |
s copyFrom:index1 to:index2 - 1 |
|
1886 |
" |
|
9192 | 1887 |
! |
1888 |
||
1889 |
indexOfSeparator |
|
1890 |
"return the index of the first whitespace character; |
|
1891 |
starting the search at the beginning, searching forward; |
|
1892 |
return 0 if no separator was found" |
|
1893 |
||
1894 |
^ self indexOfSeparatorStartingAt:1 |
|
1895 |
||
1896 |
" |
|
1897 |
'hello world' indexOfSeparator |
|
1898 |
'helloworld' indexOfSeparator |
|
1899 |
'hello ' indexOfSeparator |
|
1900 |
' hello' indexOfSeparator |
|
1901 |
" |
|
1902 |
! |
|
1903 |
||
15912 | 1904 |
indexOfSeparatorOrEndStartingAt:startIndex |
1905 |
"return the index of the next whitespace character, |
|
1906 |
starting the search at startIndex, searching forward; |
|
1907 |
return the index of one behond the end of the receiver if no separator was found. |
|
1908 |
To extract the word, copy from startIndex to the returned index-1" |
|
1909 |
||
1910 |
|idx| |
|
1911 |
||
1912 |
idx := self indexOfSeparatorStartingAt:startIndex. |
|
1913 |
idx == 0 ifTrue:[^ self size + 1]. |
|
1914 |
^ idx. |
|
1915 |
||
1916 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1917 |
'hello world' indexOfSeparatorOrEndStartingAt:3 |
15912 | 1918 |
' hello world' indexOfSeparatorOrEndStartingAt:3 |
1919 |
'hello world ' indexOfSeparatorOrEndStartingAt:3 |
|
1920 |
'hello world ' indexOfSeparatorOrEndStartingAt:6 |
|
1921 |
'hello world ' indexOfSeparatorOrEndStartingAt:7 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1922 |
'helloworld ' indexOfSeparatorOrEndStartingAt:7 |
15912 | 1923 |
'helloworld' indexOfSeparatorOrEndStartingAt:7 |
1924 |
" |
|
1925 |
! |
|
1926 |
||
9192 | 1927 |
indexOfSeparatorStartingAt:startIndex |
1928 |
"return the index of the next whitespace character, |
|
1929 |
starting the search at startIndex, searching forward; |
|
1930 |
return 0 if no separator was found" |
|
1931 |
||
1932 |
|start "{ Class: SmallInteger }" |
|
1933 |
mySize "{ Class: SmallInteger }"| |
|
1934 |
||
1935 |
start := startIndex. |
|
1936 |
mySize := self size. |
|
1937 |
||
1938 |
start to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1939 |
(self at:index) isSeparator ifTrue:[^ index] |
9192 | 1940 |
]. |
1941 |
^ 0 |
|
1942 |
||
1943 |
" |
|
1944 |
'hello world' indexOfSeparatorStartingAt:3 |
|
1945 |
' hello world' indexOfSeparatorStartingAt:3 |
|
8874 | 1946 |
'hello world ' indexOfSeparatorStartingAt:3 |
1947 |
'hello world ' indexOfSeparatorStartingAt:6 |
|
1948 |
'hello world ' indexOfSeparatorStartingAt:7 |
|
1949 |
'helloworld ' indexOfSeparatorStartingAt:7 |
|
1950 |
'helloworld' indexOfSeparatorStartingAt:7 |
|
4117 | 1951 |
" |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1952 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1953 |
|
4117 | 1954 |
lastIndexOfSeparator |
14150
e13160aa321a
comment/format in: #lastIndexOfSeparator
Claus Gittinger <cg@exept.de>
parents:
14141
diff
changeset
|
1955 |
"return the last index of a whitespace character (space or tab). |
4117 | 1956 |
(i.e. start the search at the end and search backwards); |
1957 |
Returns 0 if no separator is found." |
|
1958 |
||
1959 |
^ self lastIndexOfSeparatorStartingAt:(self size) |
|
1960 |
||
1961 |
" |
|
8874 | 1962 |
'hello world' lastIndexOfSeparator |
1963 |
'helloworld' lastIndexOfSeparator |
|
1964 |
'hel lo wor ld' lastIndexOfSeparator |
|
1965 |
'hel ' lastIndexOfSeparator 6 |
|
4117 | 1966 |
" |
14150
e13160aa321a
comment/format in: #lastIndexOfSeparator
Claus Gittinger <cg@exept.de>
parents:
14141
diff
changeset
|
1967 |
|
e13160aa321a
comment/format in: #lastIndexOfSeparator
Claus Gittinger <cg@exept.de>
parents:
14141
diff
changeset
|
1968 |
"Modified (comment): / 01-06-2012 / 13:10:30 / cg" |
4117 | 1969 |
! |
1970 |
||
1971 |
lastIndexOfSeparatorStartingAt:startIndex |
|
9192 | 1972 |
"return the index of the previous whitespace character, |
1973 |
starting the search at startIndex (and searching backwards); |
|
1974 |
returns 0 if no separator was found" |
|
1975 |
||
1976 |
|start "{ Class: SmallInteger }"| |
|
1977 |
||
1978 |
start := startIndex. |
|
1979 |
||
1980 |
start to:1 by:-1 do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1981 |
(self at:index) isSeparator ifTrue:[^ index] |
9192 | 1982 |
]. |
1983 |
^ 0 |
|
1984 |
||
1985 |
" |
|
1986 |
'hello world' lastIndexOfSeparatorStartingAt:3 |
|
1987 |
'hello world' lastIndexOfSeparatorStartingAt:7 |
|
1988 |
'helloworld' lastIndexOfSeparatorStartingAt:7 |
|
8874 | 1989 |
' helloworld' lastIndexOfSeparatorStartingAt:7 |
4117 | 1990 |
" |
608 | 1991 |
! ! |
1992 |
||
1993 |
!CharacterArray methodsFor:'comparing'! |
|
1994 |
||
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1995 |
< aString |
608 | 1996 |
"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
|
1997 |
receiver is greater than the argument. Otherwise return false. |
8874 | 1998 |
This comparison is based on the elements ascii code - |
9192 | 1999 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
2000 |
||
2001 |
|mySize "{ Class: SmallInteger }" |
|
2002 |
otherSize "{ Class: SmallInteger }" |
|
2003 |
n "{ Class: SmallInteger }" |
|
2004 |
c1 c2| |
|
2005 |
||
2006 |
mySize := self size. |
|
2007 |
otherSize := aString string size. |
|
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
2008 |
n := mySize min:otherSize. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
2009 |
|
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
2010 |
1 to:n do:[:index | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2011 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2012 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2013 |
(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
|
2014 |
]. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
2015 |
^ mySize < otherSize |
608 | 2016 |
! |
2017 |
||
2018 |
= aString |
|
2019 |
"Compare the receiver with the argument and return true if the |
|
2020 |
receiver is equal to the argument. Otherwise return false. |
|
1252 | 2021 |
|
9191 | 2022 |
This compare does NOT ignore case differences, |
608 | 2023 |
therefore 'foo' = 'Foo' will return false. |
2024 |
Since this is incompatible to ST-80 (at least, V2.x) , this may change." |
|
2025 |
||
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
2026 |
|mySize "{ Class: SmallInteger }"| |
608 | 2027 |
|
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2028 |
(aString isString or:[aString species == self species]) ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2029 |
^ false |
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2030 |
]. |
608 | 2031 |
mySize := self size. |
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
2032 |
mySize ~~ (aString size) ifTrue:[^ false]. |
608 | 2033 |
|
2034 |
1 to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2035 |
(self at:index) = (aString at:index) ifFalse:[^ false]. |
608 | 2036 |
]. |
2037 |
^ true |
|
2038 |
||
2039 |
" |
|
8874 | 2040 |
'foo' = 'Foo' |
2041 |
'foo' = 'bar' |
|
2042 |
'foo' = 'foo' |
|
2043 |
'foo' = 'foo' asText |
|
2044 |
'foo' asText = 'foo' |
|
2045 |
'foo' asText = 'foo' asText |
|
608 | 2046 |
" |
1252 | 2047 |
|
2048 |
"Modified: 22.4.1996 / 15:53:58 / cg" |
|
608 | 2049 |
! |
9192 | 2050 |
|
9191 | 2051 |
> aString |
608 | 2052 |
"Compare the receiver with the argument and return true if the |
2053 |
receiver is greater than the argument. Otherwise return false. |
|
8874 | 2054 |
This comparison is based on the elements ascii code - |
1252 | 2055 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
608 | 2056 |
|
2057 |
|mySize "{ Class: SmallInteger }" |
|
8874 | 2058 |
otherSize "{ Class: SmallInteger }" |
9192 | 2059 |
n "{ Class: SmallInteger }" |
2060 |
c1 c2| |
|
2061 |
||
2062 |
mySize := self size. |
|
5929 | 2063 |
otherSize := aString string size. |
2064 |
n := mySize min:otherSize. |
|
2065 |
||
2066 |
1 to:n do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2067 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2068 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2069 |
(c1 == c2 or:[c1 = c2]) ifFalse:[^ c1 > c2]. |
5929 | 2070 |
]. |
9192 | 2071 |
^ mySize > otherSize |
2072 |
||
2073 |
"Modified: 22.4.1996 / 15:55:00 / cg" |
|
2074 |
! |
|
2075 |
||
14660 | 2076 |
after:aString |
2077 |
"Compare the receiver with the argument and return true if the |
|
2078 |
receiver should come after the argument in a sorted list. |
|
2079 |
Otherwise return false. |
|
2080 |
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
|
2081 |
LC_COLLATE, which is initialized from the environment. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2082 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2083 |
Currently it is for Strings, but not for UnicodeStrings... |
14660 | 2084 |
|
2085 |
STUPID: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2086 |
#after has a completely different meaning in SeqColl ..." |
14660 | 2087 |
|
2088 |
^ (self compareCollatingWith:aString) > 0 |
|
2089 |
! |
|
2090 |
||
15814 | 2091 |
compareAsVersionNumberWith:aStringOrCollection |
2092 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2093 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
2094 |
Compare as version numbers in the form a.b.c... ." |
|
2095 |
||
2096 |
|rev1 rev2| |
|
2097 |
||
2098 |
rev1 := self asCollectionOfSubstringsSeparatedBy:$.. |
|
2099 |
aStringOrCollection isString ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2100 |
rev2 := aStringOrCollection asCollectionOfSubstringsSeparatedBy:$.. |
15814 | 2101 |
]. |
2102 |
rev1 := rev1 collect:[:each| each asInteger]. |
|
2103 |
rev2 := rev2 collect:[:each| each asInteger]. |
|
2104 |
||
2105 |
^ rev1 compareWith:rev2 |
|
2106 |
||
2107 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2108 |
self assert:('1' compareAsVersionNumberWith:'2') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2109 |
self assert:('2' compareAsVersionNumberWith:'1') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2110 |
self assert:('1.1' compareAsVersionNumberWith:'2.1.2') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2111 |
self assert:('2.1' compareAsVersionNumberWith:'1.2.3') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2112 |
self assert:('1' compareAsVersionNumberWith:'1.1') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2113 |
self assert:('1.1' compareAsVersionNumberWith:'1') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2114 |
self assert:('1.1' compareAsVersionNumberWith:'1.2') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2115 |
self assert:('1.10' compareAsVersionNumberWith:'1.2') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2116 |
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
|
2117 |
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
|
2118 |
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
|
2119 |
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
|
2120 |
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
|
2121 |
self assert:('1.2.3.4' compareAsVersionNumberWith:#(1 2 3 4)) = 0. |
15814 | 2122 |
" |
2123 |
! |
|
2124 |
||
9192 | 2125 |
compareCaselessWith:aString |
9190 | 2126 |
"Compare the receiver against the argument, ignoreing case. |
2127 |
Return 1 if the receiver is greater, 0 if equal and -1 if less than the argument. |
|
2128 |
||
8874 | 2129 |
This comparison is based on the elements ascii code - |
9190 | 2130 |
i.e. national characters are NOT treated specially. |
2131 |
'foo' compareWith: 'Foo' will return 0" |
|
608 | 2132 |
|
2133 |
|mySize "{ Class: SmallInteger }" |
|
8874 | 2134 |
otherSize "{ Class: SmallInteger }" |
9192 | 2135 |
n "{ Class: SmallInteger }" |
608 | 2136 |
c1 c2| |
2137 |
||
2138 |
mySize := self size. |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
2139 |
otherSize := aString string size. |
608 | 2140 |
n := mySize min:otherSize. |
2141 |
||
2142 |
1 to:n do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2143 |
c1 := (self at:index) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2144 |
c2 := (aString at:index) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2145 |
c1 > c2 ifTrue:[^ 1]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2146 |
c1 < c2 ifTrue:[^ -1]. |
608 | 2147 |
]. |
2148 |
mySize > otherSize ifTrue:[^ 1]. |
|
2149 |
mySize < otherSize ifTrue:[^ -1]. |
|
2150 |
^ 0 |
|
1252 | 2151 |
|
2152 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
608 | 2153 |
! |
2154 |
||
14660 | 2155 |
compareCollatingWith:aString |
2156 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2157 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
2158 |
The comparison is language specific, depending on the value of |
|
2159 |
LC_COLLATE, which is in the shell environment." |
|
2160 |
||
2161 |
"TODO not yet defined for unicode" |
|
2162 |
<resource: #todo> |
|
2163 |
||
2164 |
|s| |
|
2165 |
||
2166 |
(s := self string) ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2167 |
^ s compareCollatingWith:aString |
14660 | 2168 |
]. |
2169 |
^ self compareWith:aString |
|
2170 |
! |
|
2171 |
||
9192 | 2172 |
compareWith:aString |
9190 | 2173 |
"Compare the receiver with the argument and return 1 if the receiver is |
2174 |
greater, 0 if equal and -1 if less than the argument. |
|
11861 | 2175 |
This comparison is based on the elements' codepoints - |
9190 | 2176 |
i.e. upper/lowercase & national characters are NOT treated specially. |
2177 |
'foo' compareWith: 'Foo' will return 1. |
|
2178 |
while 'foo' sameAs:'Foo' will return true" |
|
2179 |
||
15814 | 2180 |
|s| |
2181 |
||
2182 |
s := self string. |
|
2183 |
s ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2184 |
^ s compareWith:aString string. |
9192 | 2185 |
]. |
15814 | 2186 |
^ super compareWith:aString string. |
9192 | 2187 |
! |
2188 |
||
11861 | 2189 |
endsWith:aStringOrCharacter |
16175 | 2190 |
"return true, if the receiver ends with something, aStringOrCharacter. |
2191 |
If aStringOrCharacter is empty, true is returned" |
|
11861 | 2192 |
|
2193 |
|s| |
|
2194 |
||
2195 |
(s := self string) ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2196 |
^ s endsWith:aStringOrCharacter |
11861 | 2197 |
]. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2198 |
(self size > 0 and:[aStringOrCharacter isCharacter]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2199 |
^ self last = aStringOrCharacter |
11861 | 2200 |
]. |
2201 |
^ super endsWith:aStringOrCharacter |
|
2202 |
||
2203 |
" |
|
2204 |
'hello world' endsWith:'world' |
|
2205 |
'hello world' asText allBold endsWith:'world' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2206 |
'hello world' endsWith:'' |
16175 | 2207 |
'hello world' asText allBold endsWith:'' |
11861 | 2208 |
" |
2209 |
||
2210 |
"Modified: 12.5.1996 / 15:49:18 / cg" |
|
2211 |
! |
|
2212 |
||
11838 | 2213 |
hammingDistanceTo:aString |
2214 |
"return the hamming distance (the number of characters which are different). |
|
12177 | 2215 |
In information theory, the Hamming distance between two strings of equal length |
2216 |
is the number of positions for which the corresponding symbols are different. |
|
2217 |
Put another way, it measures the minimum number of substitutions required to change |
|
11838 | 2218 |
one into the other, or the number of errors that transformed one string into the other." |
2219 |
||
2220 |
self assert:(aString size == self size). |
|
2221 |
^ 1 to:self size count:[:idx | (self at:idx) ~= (aString at:idx)] |
|
2222 |
||
2223 |
" |
|
2224 |
'roses' hammingDistanceTo:'toned' |
|
2225 |
" |
|
2226 |
! |
|
2227 |
||
9192 | 2228 |
hash |
2229 |
"return an integer useful as a hash-key" |
|
2230 |
||
16898 | 2231 |
"/ whenever changing, also care for String>>hash. |
13879 | 2232 |
"/ immediately after any change, execute (maybe in a debugger): |
2233 |
"/ Set allSubInstancesDo:[:s | s rehash] |
|
16898 | 2234 |
^ self hash_fnv1a |
2235 |
||
2236 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2237 |
'a' hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2238 |
'a' asUnicode16String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2239 |
'a' asUnicode32String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2240 |
'aa' hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2241 |
'aa' asUnicode16String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2242 |
'aa' asUnicode32String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2243 |
'ab' hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2244 |
'ab' asUnicode16String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2245 |
'ab' asUnicode32String hash |
13879 | 2246 |
'ab' hash |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2247 |
'ab' asArray hash |
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 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2251 |
|syms ms| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2252 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2253 |
syms := Symbol allInstances. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2254 |
Transcript show:'syms: '; showCR:syms size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2255 |
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
|
2256 |
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
|
2257 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2258 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2259 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2260 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2261 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2262 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2263 |
Transcript show:'sdbm hash: '; showCR:ms. |
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 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2266 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2267 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2268 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2269 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2270 |
Transcript show:'dragonBook: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2271 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2272 |
syms := syms collect:[:each| each asUnicode16String]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2273 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2274 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2275 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2276 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2277 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2278 |
Transcript show:'unicode sdbm hash: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2279 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2280 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2281 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2282 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2283 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2284 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2285 |
Transcript show:'unicode dragonBook:'; showCR:ms. |
14641 | 2286 |
" |
2287 |
||
13879 | 2288 |
"Modified: / 26-12-2011 / 14:09:07 / cg" |
2289 |
! |
|
2290 |
||
2291 |
hash_dragonBook |
|
2292 |
"return an integer useful as a hash-key" |
|
2293 |
||
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2294 |
|h g| |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2295 |
|
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2296 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2297 |
"/ this is the dragon-book algorithm |
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 |
h := 0. |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2300 |
self reverseDo:[:char | |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2301 |
"/ 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
|
2302 |
"/ h := (h bitShift:4) + char asciiValue. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2303 |
h := (h bitShift:4). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2304 |
h := h + char codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2305 |
h := h bitAnd:16rFFFFFFFF. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2306 |
g := (h bitAnd: 16rF0000000). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2307 |
g ~~ 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2308 |
h := h bitXor:(g bitShift:-24). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2309 |
h := h bitXor:g. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2310 |
]. |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2311 |
]. |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2312 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2313 |
"/ multiply by large prime to spread values |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2314 |
"/ This speeds up Set and Dictionary by a factor of 10!! |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2315 |
"/ |
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
2316 |
h := h times:31415821. |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2317 |
^ h |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2318 |
|
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2319 |
" |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2320 |
'a' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2321 |
'a' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2322 |
'aa' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2323 |
'aa' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2324 |
'ab' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2325 |
'ab' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2326 |
'ab' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2327 |
'ab' asArray hash |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2328 |
" |
13879 | 2329 |
|
2330 |
"Created: / 26-12-2011 / 13:46:06 / cg" |
|
2331 |
! |
|
2332 |
||
16887 | 2333 |
hash_fnv1a |
2334 |
"return an integer useful as a hash-key. |
|
2335 |
This method uses the fnv-1a algorithm |
|
2336 |
(which is actually a very good one)" |
|
2337 |
||
2338 |
|h| |
|
2339 |
||
2340 |
h := 2166136261. |
|
2341 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2342 |
h := h bitXor:(eachChar codePoint). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2343 |
h := (h * 16777619) bitAnd:16rFFFFFFFF. |
16887 | 2344 |
]. |
16898 | 2345 |
"/ make sure, it fits into a smallInt |
2346 |
h := (h bitXor: (h >> 30)) bitAnd: 16r3FFFFFFF. |
|
16887 | 2347 |
^ h |
2348 |
||
2349 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2350 |
'abc' hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2351 |
'abc' asUnicode16String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2352 |
'abc' asUnicode32String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2353 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2354 |
'foofooHelloWorld' hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2355 |
'foofooHelloWorld' asUnicode16String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2356 |
'foofooHelloWorld' asUnicode32String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2357 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2358 |
'blablaHelloWorld' hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2359 |
'blablaHelloWorld' asUnicode16String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2360 |
'blablaHelloWorld' asUnicode32String hash_fnv1a |
16887 | 2361 |
" |
2362 |
! |
|
2363 |
||
2364 |
hash_java |
|
2365 |
"return an integer useful as a hash-key. |
|
2366 |
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
|
2367 |
the java virtual machine |
16887 | 2368 |
(which is actually not a very good one)." |
2369 |
||
2370 |
|h| |
|
2371 |
||
2372 |
h := 0. |
|
2373 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2374 |
h := (h * 31) + (eachChar codePoint). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2375 |
h := h bitAnd:16rFFFFFFFF. |
16887 | 2376 |
]. |
2377 |
^ h |
|
2378 |
||
2379 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2380 |
'abc' hash_java |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2381 |
'foofooHelloWorld' hash_java |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2382 |
'blablaHelloWorld' hash_java |
16887 | 2383 |
" |
2384 |
! |
|
2385 |
||
16898 | 2386 |
hash_sdbm |
2387 |
"return an integer useful as a hash-key. |
|
2388 |
This method implements the sdbm algorithm." |
|
2389 |
||
2390 |
|h| |
|
2391 |
||
2392 |
"/ |
|
2393 |
"/ this is the sdbm algorithm |
|
2394 |
"/ |
|
2395 |
h := 0. |
|
2396 |
self do:[:char | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2397 |
h := (65599 times:h) plus:char codePoint. |
16898 | 2398 |
]. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2399 |
^ h |
16898 | 2400 |
|
2401 |
" |
|
2402 |
'a' hash |
|
2403 |
'a' asUnicode16String hash |
|
2404 |
'aa' hash |
|
2405 |
'aa' asUnicode16String hash |
|
2406 |
'ab' hash |
|
2407 |
'ab' asUnicode16String hash |
|
2408 |
'ab' hash |
|
2409 |
'ab' asArray hash |
|
2410 |
" |
|
2411 |
||
2412 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2413 |
|syms ms| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2414 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2415 |
syms := Symbol allInstances. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2416 |
Transcript show:'syms: '; showCR:syms size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2417 |
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
|
2418 |
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
|
2419 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2420 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2421 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2422 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2423 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2424 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2425 |
Transcript show:'sdbm hash: '; showCR:ms. |
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 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2428 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2429 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2430 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2431 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2432 |
Transcript show:'dragonBook: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2433 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2434 |
syms := syms collect:[:each| each asUnicode16String]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2435 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2436 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2437 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2438 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2439 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2440 |
Transcript show:'unicode sdbm hash: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2441 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2442 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2443 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2444 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2445 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2446 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2447 |
Transcript show:'unicode dragonBook:'; showCR:ms. |
16898 | 2448 |
" |
2449 |
||
2450 |
"Modified: / 26-12-2011 / 14:09:07 / cg" |
|
2451 |
! |
|
2452 |
||
11861 | 2453 |
levenshteinTo:aString |
2454 |
"return the levenshtein distance to the argument, aString; |
|
2455 |
this value corresponds to the number of replacements that have to be |
|
2456 |
made to get aString from the receiver. |
|
2457 |
See IEEE transactions on Computers 1976 Pg 172 ff." |
|
2458 |
||
2459 |
" |
|
2460 |
in the following, we assume that ommiting a character |
|
2461 |
is less of an error than inserting an extra character. |
|
2462 |
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
|
2463 |
s: substitution weight (4) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2464 |
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
|
2465 |
c: case weight (4) - or nil (then use s) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2466 |
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
|
2467 |
i: insertion of extra character weight (2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2468 |
d: delete of a character weight (6) |
11861 | 2469 |
" |
2470 |
||
2471 |
^ StringUtilities |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2472 |
levenshteinDistanceFrom:self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2473 |
to:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2474 |
s:4 k:4 c:4 e:nil i:2 d:6 |
12177 | 2475 |
|
2476 |
" |
|
2477 |
'computer' levenshteinTo:'computer' |
|
11861 | 2478 |
'cOmputer' levenshteinTo:'computer' |
12177 | 2479 |
'cOmpuTer' levenshteinTo:'computer' |
11861 | 2480 |
'cimputer' levenshteinTo:'computer' |
2481 |
'cumputer' levenshteinTo:'computer' |
|
2482 |
||
2483 |
'cmputer' levenshteinTo:'computer' |
|
2484 |
'coomputer' levenshteinTo:'computer' |
|
2485 |
||
2486 |
'ocmprt' levenshteinTo:'computer' |
|
2487 |
'computer' levenshteinTo:'computer' |
|
2488 |
'ocmputer' levenshteinTo:'computer' |
|
2489 |
'cmputer' levenshteinTo:'computer' |
|
2490 |
'computer' levenshteinTo:'cmputer' |
|
2491 |
'Computer' levenshteinTo:'computer' |
|
2492 |
||
12177 | 2493 |
'compiter' levenshteinTo:'computer' |
2494 |
'compoter' levenshteinTo:'computer' |
|
2495 |
||
2496 |
'comptuer' levenshteinTo:'computer' |
|
11861 | 2497 |
" |
2498 |
! |
|
2499 |
||
2500 |
levenshteinTo:aString s:substWeight k:kbdTypoWeight c:caseWeight i:insrtWeight d:deleteWeight |
|
2501 |
"parametrized levenshtein. |
|
2502 |
return the levenshtein distance to the argument, aString; |
|
2503 |
this value corrensponds to the number of replacements that have to be |
|
2504 |
made to get aString from the receiver. |
|
2505 |
The arguments are the costs for |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2506 |
s:substitution, |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2507 |
k:keyboard type (substitution), |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2508 |
c:case-change, |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2509 |
i:insertion |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2510 |
d:deletion |
11861 | 2511 |
of a character. |
2512 |
See IEEE transactions on Computers 1976 Pg 172 ff" |
|
2513 |
||
2514 |
^ StringUtilities |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2515 |
levenshteinDistanceFrom:self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2516 |
to:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2517 |
s:substWeight k:kbdTypoWeight c:caseWeight e:nil i:insrtWeight d:deleteWeight |
11861 | 2518 |
! |
2519 |
||
9190 | 2520 |
sameAs:aString |
2521 |
"Compare the receiver with the argument like =, but ignore case differences. |
|
2522 |
Return true or false." |
|
2523 |
||
2524 |
|mySize "{ Class: SmallInteger }" |
|
2525 |
otherSize c1 c2| |
|
2526 |
||
9192 | 2527 |
self == aString ifTrue:[^ true]. |
2528 |
||
2529 |
mySize := self size. |
|
2530 |
otherSize := aString string size. |
|
18884 | 2531 |
mySize ~~ otherSize ifTrue:[^ false]. |
9192 | 2532 |
|
2533 |
1 to:mySize do:[:index | |
|
18884 | 2534 |
c1 := self at:index. |
2535 |
c2 := aString at:index. |
|
2536 |
c1 ~~ c2 ifTrue:[ |
|
2537 |
(c1 sameAs:c2) ifFalse:[^ false]. |
|
2538 |
] |
|
9192 | 2539 |
]. |
2540 |
^ true |
|
2541 |
||
608 | 2542 |
" |
8874 | 2543 |
'foo' sameAs: 'Foo' |
2544 |
'foo' sameAs: 'bar' |
|
2545 |
'foo' sameAs: 'foo' |
|
9192 | 2546 |
" |
2547 |
||
2548 |
"Modified: 22.4.1996 / 15:56:17 / cg" |
|
2549 |
! |
|
608 | 2550 |
|
15734 | 2551 |
sameAs:aString caseSensitive:caseSensitive |
2552 |
"Compare the receiver with the argument. |
|
2553 |
If caseSensitive is false, this is the same as #sameAs:, |
|
2554 |
if false, this is the same as #=." |
|
2555 |
||
2556 |
caseSensitive ifFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2557 |
^ self sameAs:aString |
15734 | 2558 |
]. |
2559 |
^ self = aString |
|
2560 |
||
2561 |
" |
|
2562 |
'foo' sameAs:'Foo' caseSensitive:false |
|
2563 |
'foo' sameAs:'foo' caseSensitive:true |
|
2564 |
" |
|
2565 |
! |
|
2566 |
||
5242 | 2567 |
sameAs:aString ignoreCase:ignoreCase |
15734 | 2568 |
<resource: #obsolete> |
5242 | 2569 |
"Compare the receiver with the argument. |
2570 |
If ignoreCase is true, this is the same as #sameAs:, |
|
2571 |
if false, this is the same as #=." |
|
2572 |
||
2573 |
ignoreCase ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2574 |
^ self sameAs:aString |
5242 | 2575 |
]. |
2576 |
^ self = aString |
|
2577 |
||
2578 |
" |
|
8874 | 2579 |
'foo' sameAs:'Foo' ignoreCase:false |
2580 |
'foo' sameAs:'foo' ignoreCase:true |
|
5242 | 2581 |
" |
2582 |
||
2583 |
! |
|
2584 |
||
608 | 2585 |
sameCharacters:aString |
9192 | 2586 |
"count & return the number of characters which are the same |
2587 |
(ignoring case and emphasis) in the receiver and the argument, aString." |
|
2588 |
||
2589 |
|n "{ Class: SmallInteger }" |
|
2590 |
c1 c2 cnt| |
|
2591 |
||
2592 |
n := self size. |
|
2593 |
n := n min:(aString string size). |
|
2594 |
||
2595 |
cnt := 0. |
|
2596 |
1 to:n do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2597 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2598 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2599 |
((c1 == c2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2600 |
or:[c1 asLowercase = c2 asLowercase]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2601 |
cnt := cnt + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2602 |
] |
9192 | 2603 |
]. |
2604 |
^ cnt |
|
2605 |
||
2606 |
" |
|
2607 |
'foobarbaz' sameCharacters: 'foo' |
|
8874 | 2608 |
'foobarbaz' sameCharacters: 'Foo' |
2609 |
'foobarbaz' sameCharacters: 'baz' |
|
608 | 2610 |
" |
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2611 |
! |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2612 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2613 |
sameEmphasisAs:aStringOrText |
17215 | 2614 |
"compare the receiver's and the argument's emphasis" |
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2615 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2616 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2617 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2618 |
" |
8874 | 2619 |
'hello' asText sameEmphasisAs: 'hello' |
2620 |
'hello' asText sameEmphasisAs: 'hello' asText |
|
2621 |
'hello' asText allBold sameEmphasisAs: 'hello' |
|
2622 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
|
9192 | 2623 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
2624 |
" |
|
2625 |
! |
|
2626 |
||
9191 | 2627 |
sameStringAndEmphasisAs:aStringOrText |
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
2628 |
"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
|
2629 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2630 |
aStringOrText isString ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2631 |
(self string = aStringOrText string) ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2632 |
self hasChangeOfEmphasis = aStringOrText hasChangeOfEmphasis ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2633 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2634 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2635 |
" |
8874 | 2636 |
'hello' asText sameEmphasisAs: 'hello' |
2637 |
'hello' asText sameEmphasisAs: 'hello' asText |
|
2638 |
'hello' asText allBold sameEmphasisAs: 'hello' |
|
2639 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
|
2640 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
|
2641 |
||
2642 |
'hello' sameEmphasisAs: 'hello' asText |
|
2643 |
'hello' sameEmphasisAs: 'hello' asText allBold |
|
2644 |
'hello' sameEmphasisAs: 'fooba' |
|
2645 |
'hello' sameEmphasisAs: 'fooba' asText |
|
2646 |
'hello' sameEmphasisAs: 'fooba' asText allBold |
|
2647 |
'hello' sameEmphasisAs: 'fooba' asText allItalic |
|
2648 |
||
2649 |
'hello' asText sameStringAndEmphasisAs: 'hello' |
|
2650 |
'hello' asText sameStringAndEmphasisAs: 'hello' asText |
|
2651 |
'hello' asText allBold sameStringAndEmphasisAs: 'hello' |
|
2652 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allBold |
|
2653 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allItalic |
|
2654 |
||
2655 |
'hello' sameStringAndEmphasisAs: 'hello' asText |
|
2656 |
'hello' sameStringAndEmphasisAs: 'hello' asText allBold |
|
2657 |
'hello' sameStringAndEmphasisAs: 'fooba' |
|
2658 |
'hello' sameStringAndEmphasisAs: 'fooba' asText |
|
2659 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allBold |
|
2660 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allItalic |
|
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2661 |
" |
11861 | 2662 |
! |
2663 |
||
2664 |
spellAgainst: aString |
|
2665 |
"return an integer between 0 and 100 indicating how similar |
|
2666 |
the argument is to the receiver. No case conversion is done. |
|
2667 |
This algorithm is much simpler (but also less exact) than the |
|
2668 |
levenshtein distance. Experiment which is better for your |
|
2669 |
application." |
|
2670 |
||
2671 |
| i1 "{ Class: SmallInteger }" |
|
2672 |
i2 "{ Class: SmallInteger }" |
|
2673 |
next1 "{ Class: SmallInteger }" |
|
2674 |
next2 "{ Class: SmallInteger }" |
|
2675 |
size1 "{ Class: SmallInteger }" |
|
2676 |
size2 "{ Class: SmallInteger }" |
|
2677 |
score "{ Class: SmallInteger }" |
|
2678 |
maxLen "{ Class: SmallInteger }" | |
|
2679 |
||
2680 |
size1 := self size. |
|
2681 |
size2 := aString size. |
|
2682 |
maxLen := size1 max:size2. |
|
2683 |
score := 0. |
|
2684 |
i1 := i2 := 1. |
|
2685 |
[i1 <= size1 and: [i2 <= size2]] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2686 |
next1 := i1 + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2687 |
next2 := i2 + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2688 |
(self at:i1) == (aString at:i2) ifTrue: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2689 |
score := score+1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2690 |
i1 := next1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2691 |
i2 := next2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2692 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2693 |
(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
|
2694 |
i2 := next2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2695 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2696 |
(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
|
2697 |
i1 := next1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2698 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2699 |
i1 := next1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2700 |
i2 := next2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2701 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2702 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2703 |
] |
11861 | 2704 |
]. |
2705 |
||
2706 |
score == maxLen ifTrue: [^ 100]. |
|
2707 |
^ 100 * score // maxLen |
|
2708 |
||
2709 |
" |
|
2710 |
'Smalltalk' spellAgainst: 'Smalltlak' |
|
2711 |
'Smalltalk' spellAgainst: 'smalltlak' |
|
2712 |
'Smalltalk' spellAgainst: 'smalltalk' |
|
2713 |
'Smalltalk' spellAgainst: 'smalltlk' |
|
2714 |
'Smalltalk' spellAgainst: 'Smalltolk' |
|
2715 |
" |
|
2716 |
! |
|
2717 |
||
16553 | 2718 |
startsWith:aStringOrCharacter |
2719 |
"return true, if the receiver starts with something, aStringOrCharacter. |
|
17371 | 2720 |
If the argument is empty, true is returned. |
2721 |
Notice, that this is similar to, but slightly different from VW's and Squeak's beginsWith:, |
|
2722 |
which are both inconsistent w.r.t. an empty argument." |
|
11861 | 2723 |
|
2724 |
|s| |
|
2725 |
||
16553 | 2726 |
aStringOrCharacter isCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2727 |
^ (self size > 0) and:[ (self at:1) == aStringOrCharacter ] |
16553 | 2728 |
]. |
11861 | 2729 |
(s := self string) ~~ self ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2730 |
^ s startsWith:aStringOrCharacter |
11861 | 2731 |
]. |
16553 | 2732 |
^ super startsWith:aStringOrCharacter |
11861 | 2733 |
|
2734 |
" |
|
17364 | 2735 |
'abcde' startsWith:#($a $b $c) |
2736 |
'abcde' startsWith:'abc' |
|
2737 |
'abcd' startsWith:'abcde' |
|
2738 |
'abcde' startsWith:'abd' |
|
11861 | 2739 |
'hello world' startsWith:'hello' |
2740 |
'hello world' asText allBold startsWith:'hello' |
|
2741 |
'hello world' asText allBold startsWith:'' |
|
2742 |
" |
|
2743 |
||
2744 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
2745 |
"Modified: 12.5.1996 / 15:49:24 / cg" |
|
9192 | 2746 |
! ! |
2747 |
||
2748 |
!CharacterArray methodsFor:'converting'! |
|
2749 |
||
11881 | 2750 |
asAsciiZ |
2751 |
"if the receiver does not end with a 0-valued character, return a copy of it, |
|
2752 |
with an additional 0-character. Otherwise return the receiver. This is sometimes |
|
2753 |
needed when a string has to be passed to C, which needs 0-terminated strings. |
|
2754 |
Notice, that all singleByte strings are already 0-terminated in ST/X, whereas wide |
|
2755 |
strings are not." |
|
2756 |
||
12658 | 2757 |
(self notEmpty and:[self last codePoint == 0]) ifTrue:[^ self ]. |
11881 | 2758 |
^ self copyWith:(Character value:0). |
2759 |
||
2760 |
" |
|
2761 |
'abc' asAsciiZ |
|
2762 |
'abc' asWideString asAsciiZ |
|
2763 |
" |
|
2764 |
! |
|
2765 |
||
13524 | 2766 |
asByteArray |
15936 | 2767 |
"depending on the size of the characters in the receiver, |
2768 |
return a byteArray containing single-, double- or even 4-bytewise values. |
|
2769 |
The size of the returned byteArray will be the strings size multiplied by the |
|
2770 |
size required for the largest character. |
|
19233 | 2771 |
Attention: The bytes are in native byte order. |
15936 | 2772 |
Caveat: better use utf8Encoded, to get reproducable results" |
2773 |
||
14555 | 2774 |
|bytes sz bytesPerCharacter idx str| |
2775 |
||
2776 |
str := self string. |
|
2777 |
str ~~ self ifTrue:[ |
|
19233 | 2778 |
"/ for text and other wrappers |
2779 |
^ str asByteArray |
|
13611
ba8c7372218a
variable renamed in: #inspector2TabBytes
Claus Gittinger <cg@exept.de>
parents:
13524
diff
changeset
|
2780 |
]. |
ba8c7372218a
variable renamed in: #inspector2TabBytes
Claus Gittinger <cg@exept.de>
parents:
13524
diff
changeset
|
2781 |
|
ba8c7372218a
variable renamed in: #inspector2TabBytes
Claus Gittinger <cg@exept.de>
parents:
13524
diff
changeset
|
2782 |
"/ for real strings, a fallback |
13524 | 2783 |
sz := self size. |
2784 |
bytesPerCharacter := self bitsPerCharacter // 8. |
|
2785 |
bytes := ByteArray new:(sz * bytesPerCharacter). |
|
2786 |
idx := 1. |
|
2787 |
self do:[:char | |
|
19233 | 2788 |
|code| |
2789 |
||
2790 |
code := char codePoint. |
|
2791 |
bytesPerCharacter == 2 ifTrue:[ |
|
19420 | 2792 |
bytes unsignedInt16At:idx put:code |
19233 | 2793 |
] ifFalse:[ |
2794 |
bytesPerCharacter == 4 ifTrue:[ |
|
19420 | 2795 |
bytes unsignedInt32At:idx put:code |
19233 | 2796 |
] ifFalse:[ |
2797 |
bytes at:idx put:code |
|
2798 |
]. |
|
2799 |
]. |
|
2800 |
idx := idx + bytesPerCharacter. |
|
13524 | 2801 |
]. |
2802 |
^ bytes |
|
2803 |
||
2804 |
"Created: / 27-07-2011 / 00:56:17 / cg" |
|
2805 |
! |
|
2806 |
||
19233 | 2807 |
asByteArrayMSB:msb |
2808 |
"depending on the size of the characters in the receiver, |
|
2809 |
return a byteArray containing single-, double- or even 4-bytewise values. |
|
2810 |
The size of the returned byteArray will be the strings size multiplied by the |
|
2811 |
size required for the largest character. |
|
2812 |
Caveat: better use utf8Encoded, to get reproducable results" |
|
2813 |
||
2814 |
|ba| |
|
2815 |
||
2816 |
ba := self asByteArray. "/ native order |
|
2817 |
UninterpretedBytes isBigEndian ~~ msb ifTrue:[ |
|
2818 |
ba swapBytes |
|
2819 |
]. |
|
2820 |
^ ba |
|
2821 |
! |
|
2822 |
||
608 | 2823 |
asCollectionOfLines |
8874 | 2824 |
"return a collection containing the lines (separated by cr) |
608 | 2825 |
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
|
2826 |
contain empty strings. |
14456
d7c3e67647f1
comment/format in: #asCollectionOfLines
Claus Gittinger <cg@exept.de>
parents:
14455
diff
changeset
|
2827 |
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
|
2828 |
See also #asCollectionOfLinesWithReturn |
d7c3e67647f1
comment/format in: #asCollectionOfLines
Claus Gittinger <cg@exept.de>
parents:
14455
diff
changeset
|
2829 |
(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
|
2830 |
this method and we did not want to risk any incompatibilities)" |
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2831 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2832 |
^ self asCollectionOfSubstringsSeparatedBy:Character cr. |
608 | 2833 |
|
2834 |
" |
|
2835 |
'1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines |
|
8874 | 2836 |
'1 one\\\\2 two\3 three' withCRs asCollectionOfLines |
608 | 2837 |
" |
2838 |
! |
|
2839 |
||
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2840 |
asCollectionOfLinesWithReturn |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2841 |
"return a collection containing the lines (separated by cr) |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2842 |
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
|
2843 |
contain empty strings." |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2844 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2845 |
|lines| |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2846 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2847 |
lines := self asCollectionOfSubstringsSeparatedBy:Character cr. |
18194 | 2848 |
(lines notEmpty and:[lines last isEmpty]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2849 |
^ lines copyButLast:1 |
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2850 |
]. |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2851 |
^ lines |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2852 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2853 |
" |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2854 |
'1\2\3' withCRs asCollectionOfLines |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2855 |
'1\2\3\' withCRs asCollectionOfLines |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2856 |
'1\2\3' withCRs asCollectionOfLinesWithReturn |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2857 |
'1\2\3\' withCRs asCollectionOfLinesWithReturn |
18194 | 2858 |
'' withCRs asCollectionOfLinesWithReturn |
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2859 |
" |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2860 |
! |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2861 |
|
608 | 2862 |
asCollectionOfSubstringsSeparatedBy:aCharacter |
15740 | 2863 |
"return a collection containing substrings (separated by aCharacter) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2864 |
of the receiver. |
15740 | 2865 |
If aCharacter occurs multiple times in a row, the result will contain empty strings. |
2866 |
If the receiver ends with aCharacter, an empty string with be the last result element." |
|
608 | 2867 |
|
9192 | 2868 |
^ self asCollectionOfSubCollectionsSeparatedBy:aCharacter |
2869 |
||
2870 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2871 |
'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
|
2872 |
'1 one:2 two:3 three:4 four:5 five:' asCollectionOfSubstringsSeparatedBy:$: |
15740 | 2873 |
'1 one 2 two 3 three 4 four 5 five' asCollectionOfSubstringsSeparatedBy:Character space |
9192 | 2874 |
" |
2875 |
! |
|
608 | 2876 |
|
11828 | 2877 |
asCollectionOfSubstringsSeparatedBy:aCharacter exceptIn:ch |
15740 | 2878 |
"return a collection containing the substrings (separated by aCharacter) |
12177 | 2879 |
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
|
2880 |
the result will contain empty strings. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2881 |
The separation is not done, inside a matching pair of ch-substrings. |
15740 | 2882 |
Can be used to tokenize csv-like strings, which may or may not be enclosed in quotes." |
11828 | 2883 |
|
2884 |
|lines myClass except i c |
|
2885 |
startIndex "{ Class:SmallInteger }" |
|
2886 |
stopIndex "{ Class:SmallInteger }" | |
|
2887 |
||
11905
cbc2191cfe2d
return stringCollections from asCollectionOfXXX
Claus Gittinger <cg@exept.de>
parents:
11904
diff
changeset
|
2888 |
lines := StringCollection new. |
11828 | 2889 |
myClass := self species. |
2890 |
||
2891 |
startIndex := 1. |
|
2892 |
except := false. |
|
2893 |
[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2894 |
i := startIndex-1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2895 |
[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2896 |
i := i+1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2897 |
c := self at:i. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2898 |
c = ch ifTrue:[ except := except not. ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2899 |
i < self size and:[except or:[c ~= aCharacter]] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2900 |
] whileTrue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2901 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2902 |
c = aCharacter ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2903 |
stopIndex := i -1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2904 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2905 |
stopIndex := i. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2906 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2907 |
(stopIndex < startIndex) ifTrue: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2908 |
lines add:(myClass new:0) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2909 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2910 |
lines add:(self copyFrom:startIndex to:stopIndex) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2911 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2912 |
startIndex := stopIndex + 2. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2913 |
startIndex <= self size |
11828 | 2914 |
] whileTrue. |
2915 |
^ lines |
|
2916 |
||
2917 |
" |
|
12177 | 2918 |
'asd''f;d''dd;s' asCollectionOfSubstringsSeparatedBy:$; exceptIn:$' |
2919 |
" |
|
2920 |
"/ 'asd "hello bla" foo "bla bla" bar' asCollectionOfSubstringsSeparatedBy:$ exceptIn:$" |
|
11828 | 2921 |
! |
2922 |
||
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2923 |
asCollectionOfSubstringsSeparatedBy:aFieldSeparatorString textSeparator:aTextSeparatorOrNil |
13343
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
2924 |
"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
|
2925 |
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
|
2926 |
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
|
2927 |
|
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2928 |
|aTextSeparatorChar items scanningWord inStream element lastIsFieldSeparator sz| |
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2929 |
|
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2930 |
aTextSeparatorOrNil isNil ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2931 |
^ self asCollectionOfSubstringsSeparatedByAll: aFieldSeparatorString |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2932 |
]. |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2933 |
sz := aTextSeparatorOrNil size. |
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2934 |
sz = 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2935 |
aTextSeparatorChar := aTextSeparatorOrNil |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2936 |
] ifFalse:[sz = 1 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2937 |
"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
|
2938 |
aTextSeparatorChar := aTextSeparatorOrNil first. |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2939 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2940 |
self error:'textSeparatoSize > 1'. |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2941 |
]]. |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2942 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2943 |
items := OrderedCollection new. |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2944 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2945 |
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
|
2946 |
[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2947 |
inStream skipSeparators. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2948 |
inStream atEnd |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2949 |
] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2950 |
lastIsFieldSeparator := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2951 |
inStream peek == aTextSeparatorChar ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2952 |
inStream next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2953 |
element := ''. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2954 |
scanningWord := true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2955 |
[ scanningWord and:[inStream atEnd not] ] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2956 |
element := element , (inStream upTo:aTextSeparatorChar). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2957 |
(inStream peek == aTextSeparatorChar) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2958 |
element := element , aTextSeparatorChar . |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2959 |
inStream next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2960 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2961 |
scanningWord := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2962 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2963 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2964 |
inStream upToAll_positionBefore:aFieldSeparatorString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2965 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2966 |
element := inStream upToAll_positionBefore:aFieldSeparatorString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2967 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2968 |
items add:element. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2969 |
lastIsFieldSeparator := (inStream skipThroughAll:aFieldSeparatorString) notNil. |
13343
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
2970 |
]. |
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
2971 |
lastIsFieldSeparator ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2972 |
"empty element at the end of the line" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2973 |
items add:''. |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2974 |
]. |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2975 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2976 |
^ items |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2977 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2978 |
" |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2979 |
self assert:(('#First#, #Second,SecondAdd#, #Third#' asCollectionOfSubstringsSeparatedBy:',' textSeparator: $#) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2980 |
sameContentsAs:#('First' 'Second,SecondAdd' 'Third')). |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2981 |
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
|
2982 |
sameContentsAs:#('Fir#st' 'Second,SecondAdd' 'Third')). |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2983 |
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
|
2984 |
sameContentsAs:#('Fir#st' 'Second' 'SecondAdd' 'Third')). |
13343
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
2985 |
self assert:(('First,Second,Third,,' asCollectionOfSubstringsSeparatedBy:',' textSeparator:nil) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2986 |
sameContentsAs:#('First' 'Second' 'Third' '' '')). |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2987 |
self assert:(('First,Second,Third,,' asCollectionOfSubstringsSeparatedBy:',' textSeparator:'#') |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2988 |
sameContentsAs:#('First' 'Second' 'Third' '' '')). |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2989 |
" |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2990 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2991 |
"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
|
2992 |
! |
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2993 |
|
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2994 |
asCollectionOfSubstringsSeparatedByAll:aSeparatorString |
8874 | 2995 |
"return a collection containing the lines (separated by aSeparatorString) |
2996 |
of the receiver. If aSeparatorString occurs multiple times in a row, |
|
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2997 |
the result will contain empty strings." |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2998 |
|
8852
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2999 |
^ self asCollectionOfSubCollectionsSeparatedByAll:aSeparatorString |
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
3000 |
|
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
3001 |
" |
8874 | 3002 |
'1::2::3::4::5::' asCollectionOfSubstringsSeparatedByAll:'::' |
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3003 |
" |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3004 |
! |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3005 |
|
608 | 3006 |
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators |
3007 |
"return a collection containing the words (separated by any character |
|
3008 |
from aCollectionOfSeparators) of the receiver. |
|
3009 |
This allows breaking up strings using any character as separator." |
|
3010 |
||
8852
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
3011 |
^ self asCollectionOfSubCollectionsSeparatedByAny:aCollectionOfSeparators |
608 | 3012 |
|
3013 |
" |
|
3014 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:) |
|
8874 | 3015 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' |
3016 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) |
|
3017 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' |
|
3018 |
'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) |
|
608 | 3019 |
" |
3020 |
! |
|
3021 |
||
3022 |
asCollectionOfWords |
|
8874 | 3023 |
"return a collection containing the words (separated by whitespace) |
3024 |
of the receiver. Multiple occurrences of whitespace characters will |
|
17517 | 3025 |
be treated like one - i.e. whitespace is skipped. |
3026 |
(sigh: it is called #'subStrings' in V'Age, and #'substrings' in Squeak) " |
|
608 | 3027 |
|
7797 | 3028 |
|words| |
608 | 3029 |
|
11905
cbc2191cfe2d
return stringCollections from asCollectionOfXXX
Claus Gittinger <cg@exept.de>
parents:
11904
diff
changeset
|
3030 |
words := StringCollection new. |
7797 | 3031 |
self asCollectionOfWordsDo:[:w | words add:w]. |
608 | 3032 |
^ words |
3033 |
||
3034 |
" |
|
3035 |
'hello world isnt this nice' asCollectionOfWords |
|
3036 |
' hello world isnt this nice ' asCollectionOfWords |
|
3037 |
'hello' asCollectionOfWords |
|
3038 |
'' asCollectionOfWords |
|
3039 |
' ' asCollectionOfWords |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
3040 |
' foo bar__baz__bla__ bar ' asCollectionOfWords |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
3041 |
' foo __bar__baz__bla__ bar ' asCollectionOfWords |
608 | 3042 |
" |
9192 | 3043 |
! |
3044 |
||
3045 |
asCollectionOfWordsDo:aBlock |
|
8874 | 3046 |
"evaluate aBlock for each word (separated by whitespace) of the receiver. |
3047 |
Multiple occurrences of whitespace characters will be treated like one |
|
7797 | 3048 |
- i.e. whitespace is skipped. |
3049 |
Returns the number of words (i.e. the number of invocations of aBlock)." |
|
3050 |
||
3051 |
|count "{ Class:SmallInteger }" |
|
8874 | 3052 |
start "{ Class:SmallInteger }" |
3053 |
stop "{ Class:SmallInteger }" |
|
7797 | 3054 |
mySize "{ Class:SmallInteger }"| |
3055 |
||
3056 |
count := 0. |
|
3057 |
start := 1. |
|
3058 |
mySize := self size. |
|
3059 |
[start <= mySize] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3060 |
start := self indexOfNonSeparatorStartingAt:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3061 |
start == 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3062 |
^ count |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3063 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3064 |
stop := self indexOfSeparatorStartingAt:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3065 |
stop == 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3066 |
aBlock value:(self copyFrom:start to:mySize). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3067 |
^ count + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3068 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3069 |
aBlock value:(self copyFrom:start to:(stop - 1)). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3070 |
start := stop. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3071 |
count := count + 1 |
7797 | 3072 |
]. |
3073 |
^ count |
|
3074 |
||
3075 |
" |
|
3076 |
'hello world isnt this nice' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3077 |
' hello world isnt this nice ' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3078 |
'hello' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3079 |
'' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3080 |
' ' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3081 |
" |
|
9192 | 3082 |
! |
3083 |
||
3084 |
asFilename |
|
3085 |
"return a Filename with pathname taken from the receiver" |
|
3086 |
||
3087 |
^ Filename named:self "(self asSingleByteStringReplaceInvalidWith:$?)" |
|
3088 |
||
3089 |
"Modified: 20.5.1996 / 09:38:15 / cg" |
|
3090 |
! |
|
608 | 3091 |
|
3060 | 3092 |
asFixedPoint |
3093 |
"read a fixedPoint number from the receiver. |
|
8874 | 3094 |
Notice, that errors may occur during the read, |
7423 | 3095 |
so you better setup some signal handler when using this method." |
3060 | 3096 |
|
3097 |
^ FixedPoint readFromString:self |
|
3098 |
||
3099 |
" |
|
8874 | 3100 |
'0.123' asFixedPoint |
3101 |
'12345' asFixedPoint |
|
3060 | 3102 |
'(1/5)' asFixedPoint |
3103 |
'foo' asFixedPoint |
|
9192 | 3104 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asFixedPoint] |
3105 |
" |
|
3106 |
||
3107 |
"Modified: / 25.10.1997 / 15:19:00 / cg" |
|
3108 |
! |
|
3109 |
||
3110 |
asFixedPoint:scale |
|
3060 | 3111 |
"read a fixedPoint number with scale number of post-decimal digits |
3112 |
from the receiver. Scale controls the number of displayed digits, |
|
3113 |
not the number of actually valid digits. |
|
8874 | 3114 |
Notice, that errors may occur during the read, |
7423 | 3115 |
so you better setup some signal handler when using this method." |
3060 | 3116 |
|
3117 |
^ (FixedPoint readFromString:self) scale:scale |
|
3118 |
||
3119 |
" |
|
8874 | 3120 |
'0.123' asFixedPoint:2 |
3121 |
'123456' asFixedPoint:2 |
|
3122 |
('3.14157' asFixedPoint:1) asFixedPoint:5 |
|
3123 |
'3.14157' asFixedPoint:2 |
|
3124 |
'foo' asFixedPoint:2 |
|
3060 | 3125 |
" |
3126 |
||
3127 |
"Modified: / 25.10.1997 / 15:21:57 / cg" |
|
9192 | 3128 |
! |
3129 |
||
3130 |
asFloat |
|
608 | 3131 |
"read a float number from the receiver. |
8874 | 3132 |
Notice, that errors may occur during the read, |
7422 | 3133 |
so you better setup some exception handler when using this method." |
608 | 3134 |
|
3135 |
^ (Number readFromString:self) asFloat |
|
3136 |
||
3137 |
" |
|
8874 | 3138 |
'0.123' asFloat |
608 | 3139 |
'12345' asFloat |
3140 |
'(1/5)' asFloat |
|
8874 | 3141 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asFloat] |
608 | 3142 |
" |
3143 |
! |
|
3144 |
||
3145 |
asInteger |
|
9190 | 3146 |
"convert the receiver into an integer. |
8874 | 3147 |
Notice, that errors may occur during the read, |
9190 | 3148 |
so you better setup some exception handler when using this method. |
3149 |
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
|
3150 |
in other smalltalks. |
9190 | 3151 |
For less strict integer reading, use Integer readFrom:aString" |
608 | 3152 |
|
3153 |
^ Integer readFromString:self |
|
3154 |
||
3155 |
" |
|
3156 |
'12345678901234567890' asInteger |
|
3157 |
'-1234' asInteger |
|
9190 | 3158 |
|
3159 |
The following raises an error: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3160 |
'0.123' asInteger <- reader finds more after reading 0 |
9190 | 3161 |
|
3162 |
whereas the less strict readFrom does not: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3163 |
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
|
3164 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
3165 |
'0.123' asInteger |
608 | 3166 |
'0.123' asNumber <- returns what you expect |
8874 | 3167 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asInteger] |
9190 | 3168 |
|
3169 |
" |
|
9192 | 3170 |
! |
3171 |
||
3172 |
asLowercase |
|
608 | 3173 |
"return a copy of myself in lowercase letters" |
3174 |
||
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3175 |
|newStr c bitsPerCharacter |
9192 | 3176 |
mySize "{ Class: SmallInteger }" | |
3177 |
||
3178 |
mySize := self size. |
|
3179 |
mySize == 0 ifTrue:[^ self]. |
|
18657 | 3180 |
|
9192 | 3181 |
newStr := self species new:mySize. |
3182 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
3183 |
||
18657 | 3184 |
"/ handle the very seldom case of an uppercase char which needs |
3185 |
"/ more bits in its lowercase variant |
|
3186 |
"/ (there are only a few of them) |
|
3187 |
||
9192 | 3188 |
1 to:mySize do:[:i | |
18657 | 3189 |
c := (self at:i) asLowercase. |
3190 |
(c bitsPerCharacter > bitsPerCharacter |
|
3191 |
and:[c stringSpecies ~= newStr stringSpecies]) ifTrue:[ |
|
3192 |
newStr := c stringSpecies fromString:newStr. |
|
18662 | 3193 |
bitsPerCharacter := newStr bitsPerCharacter. |
18657 | 3194 |
]. |
3195 |
newStr at:i put:c |
|
9192 | 3196 |
]. |
3197 |
^ newStr |
|
3198 |
||
3199 |
" |
|
3200 |
'HelloWorld' asLowercase |
|
18662 | 3201 |
'HelloWorld' asUnicode16String asLowercase |
9192 | 3202 |
'HelloWorld' asLowercaseFirst |
18657 | 3203 |
'HelloWorld' asUppercase |
9192 | 3204 |
" |
3205 |
! |
|
3206 |
||
3207 |
asLowercaseFirst |
|
17508 | 3208 |
"return a copy of myself where the first character is converted to lowercase. |
3209 |
If the first character is already lowercase, or there is no uppercase for it, return the |
|
3210 |
receiver." |
|
9192 | 3211 |
|
3212 |
|newString firstChar firstCharAsLowercase| |
|
3213 |
||
11525 | 3214 |
self isEmpty ifTrue:[^ self]. |
9192 | 3215 |
firstChar := (self at:1). |
3216 |
firstCharAsLowercase := firstChar asLowercase. |
|
3217 |
firstChar == firstCharAsLowercase ifTrue:[ ^ self]. |
|
3218 |
||
3219 |
firstCharAsLowercase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3220 |
newString := firstCharAsLowercase stringSpecies fromString:self. |
9192 | 3221 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3222 |
newString := self stringSpecies fromString:self. |
9192 | 3223 |
]. |
9190 | 3224 |
newString at:1 put:firstCharAsLowercase. |
3225 |
^ newString |
|
608 | 3226 |
|
3227 |
" |
|
8874 | 3228 |
'HelloWorld' asLowercase |
3229 |
'HelloWorld' asLowercaseFirst |
|
608 | 3230 |
" |
3231 |
! |
|
3232 |
||
11828 | 3233 |
asLowercaseLast |
3234 |
"return a copy of myself where the last character is |
|
3235 |
converted to lowercase." |
|
3236 |
||
3237 |
|newString sz| |
|
3238 |
||
3239 |
sz := self size. |
|
3240 |
newString := self copyFrom:1 to:sz. |
|
3241 |
sz > 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3242 |
newString at:sz put:(newString at:sz) asLowercase |
11828 | 3243 |
]. |
3244 |
^ newString |
|
3245 |
||
3246 |
" |
|
12177 | 3247 |
'HelloWorld' asLowercase |
3248 |
'HelloWorlD' asLowercaseLast |
|
11828 | 3249 |
" |
3250 |
! |
|
3251 |
||
17644 | 3252 |
asMutator |
19473 | 3253 |
"return a corresponding setter method's selector. |
3254 |
I.e. #foo asMutator returns #foo:" |
|
17644 | 3255 |
|
3256 |
^ (self asOneByteString,':') asSymbol |
|
3257 |
! |
|
3258 |
||
9190 | 3259 |
asNumber |
3260 |
"read a number from the receiver. |
|
3261 |
Notice, that (in contrast to ST-80) errors may occur during the read, |
|
3262 |
so you better setup some signal handler when using this method. |
|
3263 |
Also notice, that this is meant to read end-user numbers from a string; |
|
9135 | 3264 |
it does not handle smalltalk numbers (i.e. radix). |
3265 |
To read a smalltalk number, use Number >> readSmalltalkFrom:. |
|
608 | 3266 |
This may change if ANSI specifies it." |
3267 |
||
3268 |
"/ ST-80 behavior: |
|
3269 |
"/ ^ Number readFromString:self onError:0 |
|
3270 |
||
17061 | 3271 |
^ Number fromString:self |
3272 |
||
3273 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3274 |
'123' asNumber |
608 | 3275 |
'123.567' asNumber |
3276 |
'(5/6)' asNumber |
|
3277 |
'foo' asNumber |
|
17061 | 3278 |
'123a' asNumber |
8874 | 3279 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] |
608 | 3280 |
" |
9192 | 3281 |
! |
3282 |
||
3283 |
asNumberFromFormatString:ignored |
|
608 | 3284 |
"read a number from the receiver, ignoring any nonDigit characters. |
3285 |
This is typically used to convert from strings which include |
|
3286 |
dollar-signs or millenium digits. However, this method also ignores |
|
3287 |
the decimal point (if any) and therefore should be used with care." |
|
3288 |
||
3289 |
|tempString| |
|
3290 |
||
3291 |
tempString := self collect:[:char | char isDigit]. |
|
3292 |
^ Number readFromString:tempString onError:0 |
|
3293 |
||
3294 |
" |
|
3295 |
'USD 123' asNumberFromFormatString:'foo' |
|
3296 |
'DM 123' asNumberFromFormatString:'foo' |
|
3297 |
'123' asNumberFromFormatString:'foo' |
|
3298 |
'123.567' asNumberFromFormatString:'foo' |
|
3299 |
'(5/6)' asNumberFromFormatString:'foo' |
|
3300 |
'foo' asNumberFromFormatString:'foo' |
|
3301 |
" |
|
9192 | 3302 |
! |
3303 |
||
7977 | 3304 |
asSingleByteStringIfPossible |
3305 |
"if possible, return the receiver converted to a 'normal' string. |
|
18181 | 3306 |
It is only possible, if there are no characters with codePoints above 255 in the receiver. |
3307 |
If not possible, the (wideString) receiver is returned." |
|
7977 | 3308 |
|
14555 | 3309 |
self isWideString ifFalse:[^ self]. |
18967 | 3310 |
self containsNon8BitElements ifTrue:[^ self]. |
3311 |
^ self asSingleByteString |
|
9192 | 3312 |
|
3313 |
" |
|
3314 |
'hello' asSingleByteStringIfPossible |
|
18967 | 3315 |
'hello' asText asSingleByteStringIfPossible |
3316 |
'hello' asUnicodeString asText asSingleByteStringIfPossible |
|
9192 | 3317 |
'hello' asUnicodeString asSingleByteStringIfPossible |
3318 |
" |
|
3319 |
! |
|
3320 |
||
3321 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
|
3322 |
"return the receiver converted to a 'normal' string, |
|
3323 |
with invalid characters replaced by replacementCharacter. |
|
3324 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
3325 |
and replace characters above code-255 with some replacement." |
|
3326 |
||
3327 |
|newString| |
|
3328 |
||
3329 |
newString := String new:(self size). |
|
3330 |
1 to:self size do:[:idx | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3331 |
|char| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3332 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3333 |
char := self at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3334 |
char codePoint <= 16rFF ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3335 |
newString at:idx put:char |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3336 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3337 |
newString at:idx put:replacementCharacter |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3338 |
]. |
9190 | 3339 |
]. |
3340 |
^ newString |
|
3341 |
||
3342 |
"Created: 30.6.1997 / 13:02:14 / cg" |
|
7977 | 3343 |
! |
3344 |
||
9192 | 3345 |
asString |
3346 |
"return myself - I am a string" |
|
3347 |
||
3348 |
^ self |
|
3349 |
! |
|
3350 |
||
3351 |
asStringCollection |
|
3352 |
"return a collection of lines from myself." |
|
3353 |
||
3354 |
^ StringCollection fromString:self "string" |
|
3355 |
||
3356 |
"Modified: 13.5.1996 / 20:36:59 / cg" |
|
3357 |
! |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3358 |
|
1434 | 3359 |
asSymbol |
19039 | 3360 |
"Return a unique symbol with the name taken from the receiver's characters. |
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3361 |
The receiver must be a singleByte-String. |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3362 |
TwoByte- and FourByteSymbols are (currently ?) not allowed." |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3363 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3364 |
|str| |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3365 |
|
9192 | 3366 |
str := self string. |
3367 |
str ~~ self ifTrue:[ ^ str asSymbol ]. |
|
3368 |
^ self asSingleByteString asSymbol |
|
3369 |
! |
|
3370 |
||
3371 |
asSymbolIfInterned |
|
17183 | 3372 |
"If a symbol with the receiver's characters is already known, return it. Otherwise, return nil. |
9230 | 3373 |
This can be used to query for an existing symbol and is the same as: |
18967 | 3374 |
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
|
3375 |
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
|
3376 |
The receiver must be a singleByte-String. |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3377 |
TwoByte- and FourByteSymbols are (currently ?) not allowed." |
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3378 |
|
18967 | 3379 |
|str| |
3380 |
||
3381 |
str := self string. |
|
3382 |
str == self ifTrue:[ |
|
3383 |
"must be some kind of N-ByteString" |
|
3384 |
str := self asSingleByteStringIfPossible. |
|
3385 |
str == self ifTrue:[ |
|
3386 |
"single byte string conversion is not possible" |
|
3387 |
^ nil. |
|
3388 |
]. |
|
6642 | 3389 |
]. |
18967 | 3390 |
^ str asSymbolIfInterned |
3391 |
||
3392 |
" |
|
3393 |
(Unicode16String with:(Character value:16rFFFF)) asSymbolIfInterned |
|
3394 |
'new' asUnicodeString asSymbolIfInterned |
|
3395 |
'new' asText asSymbolIfInterned |
|
3396 |
'new' asUnicodeString asText asSymbolIfInterned |
|
3397 |
" |
|
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3398 |
|
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3399 |
"Created: 22.5.1996 / 16:37:04 / cg" |
9192 | 3400 |
! |
3401 |
||
3402 |
asText |
|
9403 | 3403 |
"return a Text-object (string with emphasis) from myself." |
9192 | 3404 |
|
3405 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
3406 |
Text isNil ifTrue:[^ self]. |
|
17065 | 3407 |
^ Text string:self |
9192 | 3408 |
|
3409 |
"Created: 12.5.1996 / 10:41:14 / cg" |
|
3410 |
! |
|
3411 |
||
17021 | 3412 |
asTimestamp |
3413 |
"convert the receiver into an Timestamp. |
|
3414 |
Notice, that errors may occur during the read, |
|
3415 |
so you better setup some exception handler when using this method." |
|
3416 |
||
3417 |
^ Timestamp readFromString:self |
|
3418 |
||
3419 |
" |
|
3420 |
'2014-11-10 21:30:22.444' asTimestamp |
|
3421 |
'2014-11-10 21:30:22.444Z' asTimestamp |
|
3422 |
'2014-11-10 21:30:22.444+0200' asTimestamp |
|
3423 |
" |
|
3424 |
! |
|
3425 |
||
9192 | 3426 |
asTitlecase |
8027 | 3427 |
"return a version of the receiver, where the first character is converted to titlecase, |
3428 |
and everything else to lowercase. |
|
3429 |
See the comment in Character on what titlecase is." |
|
3430 |
||
3431 |
|newStr c bitsPerCharacter |
|
3432 |
mySize "{ Class: SmallInteger }" | |
|
3433 |
||
3434 |
mySize := self size. |
|
3435 |
newStr := self species new:mySize. |
|
3436 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
3437 |
||
3438 |
1 to:mySize do:[:i | |
|
18662 | 3439 |
i == 1 ifTrue:[ |
3440 |
c := (self at:i) asTitlecase. |
|
3441 |
] ifFalse:[ |
|
3442 |
c := (self at:i) asLowercase. |
|
3443 |
]. |
|
3444 |
c bitsPerCharacter > bitsPerCharacter ifTrue:[ |
|
3445 |
newStr := c stringSpecies fromString:newStr. |
|
3446 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
3447 |
]. |
|
3448 |
newStr at:i put:c |
|
8027 | 3449 |
]. |
3450 |
^ newStr |
|
3451 |
||
3452 |
" |
|
8874 | 3453 |
'helloWorld' asTitlecase |
3454 |
'HelloWorld' asTitlecase |
|
3455 |
'HELLOWORLD' asTitlecase |
|
3456 |
'helloworld' asTitlecase |
|
8027 | 3457 |
" |
9192 | 3458 |
! |
3459 |
||
3460 |
asTitlecaseFirst |
|
8023 | 3461 |
"return a version of the receiver, where the first character is converted to titlecase. |
8024 | 3462 |
Titlecase is much like uppercase for most characters, with the exception of some combined |
3463 |
(2-character glyphs), which consist of an upper- and lower-case characters. |
|
3464 |
If the first character is already titlecase, or there is no titlecasepercase for it, return the |
|
8023 | 3465 |
receiver." |
3466 |
||
8026 | 3467 |
" |
8874 | 3468 |
For example, in Unicode, character U+01F3 is LATIN SMALL LETTER DZ. |
3469 |
(Let us write this compound character using ASCII as 'dz'.) |
|
3470 |
This character uppercases to character U+01F1, LATIN CAPITAL LETTER DZ. |
|
3471 |
(Which is basically 'DZ'.) |
|
3472 |
But it titlecases to to character U+01F2, LATIN CAPITAL LETTER D WITH SMALL LETTER Z. |
|
8026 | 3473 |
(Which we can write 'Dz'.) |
3474 |
||
3475 |
character uppercase titlecase |
|
3476 |
--------- --------- --------- |
|
3477 |
dz DZ Dz |
|
3478 |
" |
|
3479 |
||
8023 | 3480 |
|newString firstChar firstCharAsTitlecase| |
3481 |
||
3482 |
firstChar := (self at:1). |
|
8025 | 3483 |
firstCharAsTitlecase := firstChar asTitlecase. |
8023 | 3484 |
firstChar == firstCharAsTitlecase ifTrue:[ ^ self]. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3485 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3486 |
firstCharAsTitlecase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3487 |
newString := firstCharAsTitlecase stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3488 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3489 |
newString := self stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3490 |
]. |
8023 | 3491 |
newString at:1 put:firstCharAsTitlecase. |
3492 |
^ newString |
|
3493 |
||
3494 |
" |
|
8874 | 3495 |
'helloWorld' asTitlecaseFirst |
3496 |
'HelloWorld' asTitlecaseFirst |
|
8023 | 3497 |
" |
9192 | 3498 |
! |
3499 |
||
3500 |
asTwoByteString |
|
3501 |
"return the receiver converted to a two-byte string. |
|
16051 | 3502 |
Will be obsolete soon - use asUnicode16String." |
9192 | 3503 |
|
3504 |
^ TwoByteString fromString:self |
|
3505 |
! |
|
3506 |
||
3507 |
asURI |
|
3508 |
"return an URI with string taken from the receiver" |
|
3509 |
||
3510 |
^ URI fromString:self |
|
3511 |
! |
|
8710 | 3512 |
|
5776 | 3513 |
asURL |
3514 |
"return an URL-object from myself." |
|
3515 |
||
3516 |
^ URL fromString:self |
|
3517 |
||
3518 |
" |
|
8874 | 3519 |
'http://www.exept.de:80/index.html' asURL host |
3520 |
'http://www.exept.de:80/index.html' asURL port |
|
9192 | 3521 |
'http://www.exept.de:80/index.html' asURL method |
3522 |
'http://www.exept.de:80/index.html' asURL path |
|
3523 |
" |
|
3524 |
! |
|
3525 |
||
18901 | 3526 |
asUUID |
3527 |
"return self as a UUID" |
|
3528 |
||
3529 |
^ UUID fromString:self |
|
3530 |
||
3531 |
" |
|
3532 |
UUID genUUID asString asUUID |
|
3533 |
'{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' asUUID |
|
3534 |
'{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' asUnicodeString asUUID |
|
3535 |
'EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B' asUUID |
|
3536 |
'EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B quatsch' asUUID |
|
3537 |
'quark EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B' asUUID |
|
3538 |
" |
|
3539 |
||
3540 |
"Modified: / 02-08-2007 / 16:43:29 / cg" |
|
3541 |
! |
|
3542 |
||
9192 | 3543 |
asUnicode16String |
15035 | 3544 |
"return the receiver in a two-byte per character representation. |
3545 |
Normally, the internal ST/X representation should be transparent and not |
|
3546 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3547 |
such as wide-string ffi calls or file contents." |
|
3548 |
||
17600 | 3549 |
|sz| |
3550 |
||
3551 |
sz := self size. |
|
3552 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3553 |
^ (Unicode16String new:sz) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3554 |
replaceFrom:1 to:sz with:self startingAt:1; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3555 |
yourself. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3556 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3557 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3558 |
'abc' asUnicode16String |
17600 | 3559 |
" |
3560 |
! |
|
3561 |
||
3562 |
asUnicode16StringZ |
|
3563 |
"return the receiver in a two-byte per character representation. |
|
17625 | 3564 |
Make sure that is zero terminated (last char is 16r0000). |
17600 | 3565 |
Normally, the internal ST/X representation should be transparent and not |
3566 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3567 |
such as wide-string ffi calls or file contents." |
|
3568 |
||
3569 |
|sz| |
|
3570 |
||
3571 |
sz := self size. |
|
3572 |
(self at:sz) == (Character codePoint:0) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3573 |
^ self asUnicode16String. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3574 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3575 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3576 |
^ (Unicode16String new:sz+1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3577 |
replaceFrom:1 to:sz with:self startingAt:1; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3578 |
at:sz+1 put:(Character codePoint:0); |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3579 |
yourself. |
17600 | 3580 |
|
3581 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3582 |
'abc' asUnicode16StringZ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3583 |
'abc' asUnicode16String asUnicode16StringZ |
17600 | 3584 |
" |
9192 | 3585 |
! |
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3586 |
|
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3587 |
asUnicode32String |
16051 | 3588 |
"return the receiver in a four-byte per character representation. |
3589 |
Normally, the internal ST/X representation should be transparent and not |
|
3590 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3591 |
such as wide-string ffi calls or file contents." |
|
3592 |
||
3593 |
^ self as:Unicode32String |
|
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3594 |
! |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3595 |
|
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3596 |
asUnicodeString |
16051 | 3597 |
"return the receiver in a two-byte per character representation. |
3598 |
Normally, the internal ST/X representation should be transparent and not |
|
3599 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3600 |
such as wide-string ffi calls or file contents." |
|
3601 |
||
3602 |
^ self asUnicode16String |
|
3603 |
" |
|
3604 |
'Hello World' asUnicodeString |
|
14141
e86d245213b0
comment/format in: #asUnicodeString
Stefan Vogel <sv@exept.de>
parents:
14137
diff
changeset
|
3605 |
" |
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3606 |
! |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3607 |
|
13073 | 3608 |
asUnixFilename |
3609 |
"return a UnixFilename with pathname taken from the receiver" |
|
3610 |
||
3611 |
^ UnixFilename named:self |
|
3612 |
||
3613 |
"Created: / 20-09-2010 / 21:42:55 / cg" |
|
3614 |
! |
|
3615 |
||
608 | 3616 |
asUppercase |
3617 |
"return a copy of myself in uppercase letters" |
|
3618 |
||
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3619 |
|newStr c bitsPerCharacter |
608 | 3620 |
mySize "{ Class: SmallInteger }" | |
3621 |
||
3622 |
mySize := self size. |
|
8954
12e701d7b5ac
allow for receiver to be empty in asLowercase and asUppercase.
Claus Gittinger <cg@exept.de>
parents:
8938
diff
changeset
|
3623 |
mySize == 0 ifTrue:[^ self]. |
608 | 3624 |
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
|
3625 |
bitsPerCharacter := newStr bitsPerCharacter. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3626 |
|
18657 | 3627 |
"/ handle the very seldom case of a lowercase char which needs |
3628 |
"/ more bits in its uppercase variant |
|
3629 |
"/ (there are only a few of them) |
|
3630 |
||
608 | 3631 |
1 to:mySize do:[:i | |
18657 | 3632 |
c := (self at:i) asUppercase. |
3633 |
c bitsPerCharacter > bitsPerCharacter ifTrue:[ |
|
3634 |
newStr := c stringSpecies fromString:newStr. |
|
18662 | 3635 |
bitsPerCharacter := newStr bitsPerCharacter. |
18657 | 3636 |
]. |
3637 |
newStr at:i put:c |
|
608 | 3638 |
]. |
3639 |
^ newStr |
|
3640 |
||
3641 |
" |
|
8874 | 3642 |
'helloWorld' asUppercase |
3643 |
'helloWorld' asUppercaseFirst |
|
9192 | 3644 |
(Character value:16rB5) asString asUppercase -- needs 16 bits !! |
18657 | 3645 |
(Character value:16rFF) asString asUppercase -- needs 16 bits !! |
9192 | 3646 |
" |
3647 |
! |
|
3648 |
||
3649 |
asUppercaseFirst |
|
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3650 |
"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
|
3651 |
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
|
3652 |
receiver." |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3653 |
|
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3654 |
|newString firstChar firstCharAsUppercase| |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3655 |
|
12679 | 3656 |
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
|
3657 |
firstChar := self at:1. |
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3658 |
firstCharAsUppercase := firstChar asUppercase. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3659 |
firstChar == firstCharAsUppercase ifTrue:[ ^ self]. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3660 |
|
12679 | 3661 |
"/ 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
|
3662 |
firstCharAsUppercase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3663 |
newString := firstCharAsUppercase stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3664 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3665 |
newString := self stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3666 |
]. |
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3667 |
newString at:1 put:firstCharAsUppercase. |
608 | 3668 |
^ newString |
3669 |
||
3670 |
" |
|
8874 | 3671 |
'helloWorld' asUppercase |
3672 |
'helloWorld' asUppercaseFirst |
|
3673 |
'HelloWorld' asUppercaseFirst |
|
608 | 3674 |
" |
9192 | 3675 |
! |
3676 |
||
11828 | 3677 |
asUppercaseLast |
3678 |
"return a copy of myself where the last character is |
|
3679 |
converted to uppercase." |
|
3680 |
||
3681 |
|newString sz| |
|
3682 |
||
3683 |
sz := self size. |
|
3684 |
newString := self copyFrom:1 to:sz. |
|
3685 |
sz > 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3686 |
newString at:sz put:(newString at:sz) asUppercase |
11828 | 3687 |
]. |
3688 |
^ newString |
|
3689 |
||
3690 |
" |
|
12177 | 3691 |
'HelloWorld' asUppercase |
3692 |
'HelloWorld' asUppercaseLast |
|
11828 | 3693 |
" |
3694 |
! |
|
3695 |
||
17021 | 3696 |
asUtcTimestamp |
3697 |
"convert the receiver into an UtcTimestamp (Time is interpreted in the UTC timezone). |
|
3698 |
Notice, that errors may occur during the read, |
|
3699 |
so you better setup some exception handler when using this method." |
|
3700 |
||
3701 |
^ UtcTimestamp readFromString:self |
|
3702 |
||
3703 |
" |
|
3704 |
'2014-11-10 21:30:22.444' asUtcTimestamp |
|
3705 |
" |
|
3706 |
! |
|
3707 |
||
11062 | 3708 |
literalArrayEncoding |
3709 |
"encode myself as an array literal, from which a copy of the receiver |
|
3710 |
can be reconstructed with #decodeAsLiteralArray." |
|
3711 |
||
3712 |
^ self |
|
3713 |
||
3714 |
"Modified: 1.9.1995 / 02:25:45 / claus" |
|
3715 |
"Modified: 22.4.1996 / 13:00:50 / cg" |
|
3716 |
! |
|
3717 |
||
9192 | 3718 |
string |
3719 |
"return the receiver - for ST-80 compatibility" |
|
3720 |
||
3721 |
^ self |
|
3722 |
||
3723 |
"Modified: 27.4.1996 / 13:29:30 / cg" |
|
3724 |
! ! |
|
3725 |
||
3726 |
!CharacterArray methodsFor:'copying'! |
|
3727 |
||
3728 |
, aStringOrCharacter |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3729 |
"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
|
3730 |
This is nonStandard, but convenient" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3731 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3732 |
|myWidth otherWidth| |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3733 |
|
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3734 |
aStringOrCharacter isCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3735 |
^ self copyWith:aStringOrCharacter |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3736 |
]. |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3737 |
aStringOrCharacter isText ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3738 |
^ aStringOrCharacter concatenateFromString:self |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3739 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3740 |
aStringOrCharacter isString ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3741 |
(otherWidth := aStringOrCharacter bitsPerCharacter) ~~ (myWidth := self bitsPerCharacter) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3742 |
otherWidth > myWidth ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3743 |
^ (aStringOrCharacter species fromString:self) , aStringOrCharacter |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3744 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3745 |
^ self , (self species fromString:aStringOrCharacter) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3746 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3747 |
]. |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3748 |
^ super , aStringOrCharacter |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3749 |
|
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3750 |
" |
8874 | 3751 |
'hello' , $1 |
3752 |
'hello' , '1' |
|
3753 |
'hello' , (' world' asText allBold) |
|
3754 |
'hello' , (JISEncodedString fromString:' world') |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3755 |
(JISEncodedString fromString:'hello') , ' world' |
1411 | 3756 |
|
1422 | 3757 |
Transcript showCR: |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3758 |
(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
|
3759 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3760 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3761 |
"Modified: 28.6.1997 / 00:13:17 / cg" |
9192 | 3762 |
! |
3763 |
||
3764 |
,, aString |
|
7020 | 3765 |
"concatenate with a newLine in between" |
6965 | 3766 |
|
3767 |
^ (self copyWith:Character cr) , aString |
|
3768 |
||
3769 |
" |
|
3770 |
hello ,, world |
|
7020 | 3771 |
'hello' ,, 'world' |
6965 | 3772 |
" |
3773 |
! |
|
3774 |
||
11329 | 3775 |
chopTo:maxLen |
19464 | 3776 |
"if the receiver's size is less or equal to maxLen, return it. |
11329 | 3777 |
Otherwise, return a copy of the receiver, where some characters |
3778 |
in the middle have been removed for a total string length |
|
3779 |
of maxLen." |
|
3780 |
||
3781 |
|sz n1 n2| |
|
3782 |
||
3783 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3784 |
||
3785 |
n1 := n2 := maxLen // 2. |
|
3786 |
maxLen odd ifTrue:[ |
|
19464 | 3787 |
n2 := n1 + 1 |
11329 | 3788 |
]. |
3789 |
^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1) |
|
3790 |
||
3791 |
" |
|
3792 |
'12345678901234' chopTo:15 |
|
3793 |
'123456789012345' chopTo:15 |
|
3794 |
'1234567890123456' chopTo:15 |
|
3795 |
'aShortString' chopTo:15 |
|
3796 |
'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 |
|
3797 |
" |
|
3798 |
||
3799 |
"Modified: / 24-10-2006 / 12:32:01 / cg" |
|
3800 |
! |
|
3801 |
||
3802 |
contractAtBeginningTo:maxLen |
|
19464 | 3803 |
"if the receiver's size is less or equal to maxLen, return it. |
11329 | 3804 |
Otherwise, return a copy of the receiver, where some characters |
3805 |
at the beginning have been replaced by '...' for a total string length |
|
3806 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
3807 |
||
3808 |
|sz| |
|
3809 |
||
3810 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3811 |
||
3812 |
^ '...' , (self copyFrom:(sz - (maxLen - 4))) |
|
3813 |
||
3814 |
" |
|
3815 |
'12345678901234' contractAtBeginningTo:15 |
|
3816 |
'123456789012345' contractAtBeginningTo:15 |
|
3817 |
'1234567890123456' contractAtBeginningTo:15 |
|
3818 |
'aShortString' contractAtBeginningTo:15 |
|
3819 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15 |
|
3820 |
" |
|
3821 |
||
3822 |
"Modified: / 24-10-2006 / 12:32:13 / cg" |
|
3823 |
! |
|
3824 |
||
3825 |
contractAtEndTo:maxLen |
|
19464 | 3826 |
"if the receiver's size is less or equal to maxLen, return it. |
11329 | 3827 |
Otherwise, return a copy of the receiver, where some characters |
3828 |
at the end have been replaced by '...' for a total string length |
|
3829 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
3830 |
||
3831 |
|sz| |
|
3832 |
||
3833 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3834 |
||
3835 |
^ (self copyTo:maxLen-3),'...' |
|
3836 |
||
3837 |
" |
|
3838 |
'12345678901234' contractAtEndTo:15 |
|
3839 |
'123456789012345' contractAtEndTo:15 |
|
3840 |
'1234567890123456' contractAtEndTo:15 |
|
3841 |
'aShortString' contractAtEndTo:15 |
|
3842 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 |
|
3843 |
" |
|
3844 |
||
3845 |
"Modified: / 24-10-2006 / 12:32:26 / cg" |
|
3846 |
! |
|
3847 |
||
3848 |
contractLeftTo:maxLen |
|
19464 | 3849 |
"if the receiver's size is less or equal to maxLen, return it. |
11329 | 3850 |
Otherwise, return a copy of the receiver, where some characters |
3851 |
near the first quarter have been replaced by '...' for a total string length |
|
12177 | 3852 |
of maxLen. |
3853 |
Very similar to contractTo:, but better to abbreviate long filename entries, |
|
11329 | 3854 |
where the right part is of more use than the left." |
3855 |
||
3856 |
|sz "{ SmallInteger }" |
|
3857 |
halfSize quarterSize "{ SmallInteger }" |
|
3858 |
leftEnd rightEnd rightStart| |
|
3859 |
||
3860 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3861 |
||
3862 |
halfSize := maxLen // 2. |
|
3863 |
quarterSize := maxLen // 4. |
|
3864 |
leftEnd := quarterSize-1. |
|
3865 |
rightEnd := maxLen - leftEnd - 3. |
|
3866 |
rightStart := sz - rightEnd + 1. |
|
3867 |
^ (self copyTo:leftEnd),'...',(self copyFrom:rightStart) |
|
3868 |
||
3869 |
" |
|
12177 | 3870 |
'12345678901234' contractLeftTo:15 |
3871 |
'123456789012345' contractLeftTo:15 |
|
3872 |
'1234567890123456' contractLeftTo:15 |
|
3873 |
'aShortString' contractLeftTo:15 |
|
3874 |
'aVeryLongNameForAStringThatShouldBeShortened' contractLeftTo:15 |
|
11329 | 3875 |
'C:\Dokumente und Einstellungen\cg\work\bosch\dapas\hw_schnittstellen\DAPAS__HpibDLL.st' contractLeftTo:40 |
3876 |
" |
|
3877 |
! |
|
3878 |
||
3879 |
contractTo:maxLen |
|
19464 | 3880 |
"if the receiver's size is less or equal to maxLen, return it. |
11329 | 3881 |
Otherwise, return a copy of the receiver, where some characters |
3882 |
in the middle have been replaced by '...' for a total string length |
|
3883 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
3884 |
||
13362 | 3885 |
|sz "{ SmallInteger }" leftSize rightSize| |
11329 | 3886 |
|
3887 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3888 |
||
13362 | 3889 |
rightSize := maxLen // 2. |
3890 |
leftSize := maxLen - rightSize. |
|
13822 | 3891 |
leftSize := leftSize - 2. |
3892 |
rightSize := rightSize - 1. |
|
13362 | 3893 |
^ (self copyTo:leftSize),'...',(self copyFrom:(sz+1-rightSize)) |
3894 |
||
3895 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3896 |
'12345678901234' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3897 |
'123456789012345' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3898 |
'1234567890123456' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3899 |
'12345678901234567' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3900 |
'123456789012345678' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3901 |
'aShortString' contractTo:15 |
11329 | 3902 |
'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 |
3903 |
'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
|
3904 |
('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
|
3905 |
('1234567890123456789012345678901234567' contractTo:29) size |
13362 | 3906 |
" |
3907 |
||
13822 | 3908 |
"Modified (comment): / 24-11-2011 / 19:17:46 / cg" |
11329 | 3909 |
! |
3910 |
||
16202 | 3911 |
copyReplaceAll:oldElement with:newElement |
3912 |
"return a copy of the receiver as a string, where all elements equal to oldElement |
|
3913 |
have been replaced by newElement." |
|
3914 |
||
3915 |
"/ ANSI seems to allow a sequence to be replaced by another sequence, |
|
3916 |
"/ whereas the old ST80 meant replace all occurrences... - sigh. |
|
3917 |
oldElement isByteCollection ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3918 |
newElement isByteCollection ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3919 |
^ self copyReplaceString:oldElement withString:newElement. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3920 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3921 |
self halt:'check if this is legal'. |
16202 | 3922 |
]. |
3923 |
newElement isByteCollection ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3924 |
self halt:'check if this is legal'. |
16202 | 3925 |
]. |
16212 | 3926 |
^ super copyReplaceAll:oldElement with:newElement |
16202 | 3927 |
! |
3928 |
||
8347 | 3929 |
copyReplaceString:subString withString:newString |
3930 |
"return a copy of the receiver, with all sequences of subString replaced |
|
3931 |
by newString (i.e. slice in the newString in place of the oldString)." |
|
3932 |
||
3933 |
|tmpStream idx idx1| |
|
3934 |
||
15523 | 3935 |
tmpStream := self species writeStream. |
8347 | 3936 |
idx := 1. |
3937 |
[idx ~~ 0] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3938 |
idx1 := idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3939 |
idx := self indexOfSubCollection:subString startingAt:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3940 |
idx ~~ 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3941 |
tmpStream nextPutAll:(self copyFrom:idx1 to:idx-1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3942 |
tmpStream nextPutAll:newString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3943 |
idx := idx + subString size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3944 |
] |
8347 | 3945 |
]. |
3946 |
tmpStream nextPutAll:(self copyFrom:idx1). |
|
3947 |
^ tmpStream contents |
|
3948 |
||
3949 |
" |
|
9306 | 3950 |
'12345678901234567890' copyReplaceString:'123' withString:'OneTwoThree' |
3951 |
'12345678901234567890' copyReplaceString:'123' withString:'*' |
|
3952 |
'12345678901234567890' copyReplaceString:'234' withString:'foo' |
|
3953 |
||
3954 |
('a string with spaces' copyReplaceAll:$ withAll:' foo ') |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3955 |
copyReplaceString:'foo' withString:'bar' |
8347 | 3956 |
" |
3957 |
||
3958 |
"Modified: / 31-05-1999 / 12:33:59 / cg" |
|
3959 |
"Created: / 12-05-2004 / 12:00:00 / cg" |
|
3960 |
! |
|
3961 |
||
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3962 |
copyWith:aCharacter |
19464 | 3963 |
"return a new string containing the receiver's characters |
8874 | 3964 |
and the single new character, aCharacter. |
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3965 |
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
|
3966 |
as argument, but equivalent to copy-and-addLast. |
8874 | 3967 |
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
|
3968 |
(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
|
3969 |
|
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3970 |
|sz newString| |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3971 |
|
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3972 |
aCharacter bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
19464 | 3973 |
sz := self size. |
3974 |
newString := aCharacter stringSpecies new:sz + 1. |
|
3975 |
newString replaceFrom:1 to:sz with:self startingAt:1. |
|
3976 |
newString at:sz+1 put:aCharacter. |
|
3977 |
^ newString. |
|
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3978 |
]. |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3979 |
^ super copyWith:aCharacter |
17241 | 3980 |
! |
3981 |
||
3982 |
restAfter:keyword withoutSeparators:strip |
|
3983 |
"compare the left of the receiver with keyword, |
|
3984 |
if it matches return the right. |
|
3985 |
Finally, if strip is true, remove whiteSpace. |
|
3986 |
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
|
3987 |
something: rest |
17241 | 3988 |
where we are interested in rest, but only if the receiver string |
3989 |
begins with something. |
|
3990 |
||
3991 |
You may wonder why such a specialized method exists here |
|
3992 |
- this is so common when processing mailboxes, |
|
3993 |
rcs files, nntp/pop3 responses, that is was considered worth |
|
3994 |
a special method here to avoid having the code below a hundred |
|
3995 |
times in variuos places." |
|
3996 |
||
3997 |
|rest| |
|
3998 |
||
3999 |
(self startsWith:keyword) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4000 |
rest := self copyFrom:(keyword size + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4001 |
strip ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4002 |
rest := rest withoutSeparators |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4003 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4004 |
^ rest |
17241 | 4005 |
]. |
4006 |
^ nil |
|
4007 |
||
4008 |
" |
|
4009 |
'foo: hello world' restAfter:'foo:' withoutSeparators:true |
|
4010 |
'funny: something' restAfter:'foo:' withoutSeparators:true |
|
4011 |
||
4012 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:true |
|
4013 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:false |
|
4014 |
" |
|
4015 |
||
4016 |
"Created: 25.11.1995 / 11:04:18 / cg" |
|
4017 |
! |
|
4018 |
||
4019 |
splitAtString:subString withoutSeparators:strip |
|
4020 |
"If the receiver is of the form: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4021 |
<left><subString><right> |
17241 | 4022 |
return a collection containing left and right only. |
4023 |
If strip is true, remove whiteSpace in the returned substrings." |
|
4024 |
||
4025 |
|idx left right| |
|
4026 |
||
4027 |
(idx := self indexOfSubCollection:subString) ~~ 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4028 |
left := self copyTo:(idx - 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4029 |
right := self copyFrom:(idx + subString size). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4030 |
strip ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4031 |
left := left withoutSeparators. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4032 |
right := right withoutSeparators. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4033 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4034 |
^ StringCollection with:left with:right |
17241 | 4035 |
]. |
4036 |
self error:'substring not present in receiver' mayProceed:true. |
|
4037 |
^ self |
|
4038 |
||
4039 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4040 |
'hello -> world' splitAtString:'->' withoutSeparators:false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4041 |
'hello -> world' splitAtString:'->' withoutSeparators:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4042 |
'hello -> ' splitAtString:'->' withoutSeparators:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4043 |
'hello > error' splitAtString:'->' withoutSeparators:true |
17241 | 4044 |
" |
4045 |
||
4046 |
"Created: 25.11.1995 / 11:04:18 / cg" |
|
608 | 4047 |
! ! |
4048 |
||
4049 |
!CharacterArray methodsFor:'displaying'! |
|
4050 |
||
2762 | 4051 |
displayOn:aGC x:x y:y from:start to:stop |
4052 |
"display the receiver on a GC" |
|
4053 |
||
12171 | 4054 |
self displayOn:aGC x:x y:y from:start to:stop opaque:false |
4055 |
||
4056 |
"Modified: 12.5.1996 / 12:49:33 / cg" |
|
4057 |
! |
|
4058 |
||
4059 |
displayOn:aGC x:x y:y from:start to:stop opaque:opaque |
|
4060 |
"display the receiver on a GC" |
|
4061 |
||
2762 | 4062 |
"q&d hack" |
4063 |
||
12177 | 4064 |
(start == 1 and:[stop == self size]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4065 |
self displayOn:aGC x:x y:y opaque:opaque. |
12177 | 4066 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4067 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:opaque. |
12177 | 4068 |
]. |
2762 | 4069 |
! |
4070 |
||
7082 | 4071 |
displayOn:aGc x:x y:y opaque:opaque |
2762 | 4072 |
"display the receiver in a graphicsContext - this method allows |
4073 |
strings to be used like DisplayObjects." |
|
4074 |
||
4075 |
|s| |
|
4076 |
||
4077 |
s := self string. |
|
7082 | 4078 |
opaque ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4079 |
aGc displayOpaqueString:s x:x y:y. |
2762 | 4080 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4081 |
aGc displayString:s x:x y:y. |
2762 | 4082 |
]. |
1381 | 4083 |
|
4084 |
"Modified: 11.5.1996 / 14:42:48 / cg" |
|
4085 |
! |
|
4086 |
||
2762 | 4087 |
displayOpaqueOn:aGC x:x y:y from:start to:stop |
4088 |
"display the receiver on a GC" |
|
4089 |
||
12171 | 4090 |
self displayOn:aGC x:x y:y from:start to:stop opaque:true |
608 | 4091 |
! ! |
4092 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4093 |
!CharacterArray methodsFor:'emphasis'! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4094 |
|
11632
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4095 |
actionForAll:aBlock |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4096 |
"change the action block of all characters. |
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4097 |
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
|
4098 |
|
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4099 |
^ self asText actionForAll:aBlock |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4100 |
! |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4101 |
|
5732 | 4102 |
allBold |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4103 |
"return a text object representing the receiver, but all boldified" |
5732 | 4104 |
|
8874 | 4105 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
6187 | 4106 |
Text isNil ifTrue:[^ self]. |
5732 | 4107 |
^ self asText allBold |
4108 |
||
4109 |
" |
|
4110 |
Transcript showCR:'hello' asText allBold |
|
4111 |
Transcript showCR:'hello' allBold |
|
4112 |
" |
|
4113 |
! |
|
4114 |
||
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4115 |
allItalic |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4116 |
"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
|
4117 |
|
8874 | 4118 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
6187 | 4119 |
Text isNil ifTrue:[^ self]. |
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4120 |
^ self asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4121 |
|
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4122 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4123 |
Transcript showCR:'hello' asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4124 |
Transcript showCR:'hello' allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4125 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4126 |
! |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4127 |
|
11345 | 4128 |
allStrikedOut |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4129 |
"return a text object representing the receiver, but all in strikeout" |
11345 | 4130 |
|
4131 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
4132 |
Text isNil ifTrue:[^ self]. |
|
4133 |
^ self asText allStrikedOut |
|
4134 |
||
4135 |
" |
|
4136 |
Transcript showCR:'hello' asText allStrikedOut |
|
4137 |
Transcript showCR:'hello' allStrikedOut |
|
4138 |
" |
|
4139 |
! |
|
4140 |
||
10862 | 4141 |
allUnderlined |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4142 |
"return a text object representing the receiver, but all with underline" |
10862 | 4143 |
|
4144 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
4145 |
Text isNil ifTrue:[^ self]. |
|
4146 |
^ self asText allUnderlined |
|
4147 |
||
4148 |
" |
|
4149 |
Transcript showCR:'hello' asText allUnderlined |
|
4150 |
Transcript showCR:'hello' allUnderlined |
|
4151 |
" |
|
4152 |
! |
|
4153 |
||
6228 | 4154 |
colorizeAllWith:aColor |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4155 |
"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
|
4156 |
|
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4157 |
"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
|
4158 |
Text isNil ifTrue:[^ self]. |
6228 | 4159 |
^ self asText colorizeAllWith:aColor |
4160 |
||
4161 |
" |
|
4162 |
Transcript showCR:('hello' colorizeAllWith:Color red) |
|
4163 |
Transcript showCR:('world' colorizeAllWith:Color green darkened) |
|
4164 |
" |
|
4165 |
! |
|
4166 |
||
12330
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4167 |
colorizeAllWith:fgColor on:bgColor |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4168 |
"return a text object representing the receiver, but all colorized with |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4169 |
both fg and background color" |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4170 |
|
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4171 |
"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
|
4172 |
Text isNil ifTrue:[^ self]. |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4173 |
^ self asText colorizeAllWith:fgColor on:bgColor |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4174 |
|
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4175 |
" |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4176 |
Transcript showCR:('hello' colorizeAllWith:Color red on:Color yellow) |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4177 |
Transcript showCR:('world' colorizeAllWith:Color red) |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4178 |
" |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4179 |
! |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4180 |
|
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4181 |
emphasis |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4182 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4183 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4184 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4185 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4186 |
^ RunArray new:self size withAll:nil |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4187 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4188 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4189 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4190 |
|
6655 | 4191 |
emphasis:emphasisCollection |
4192 |
^ self asText emphasis:emphasisCollection |
|
4193 |
||
4194 |
" |
|
4195 |
Transcript showCR:('hello' emphasis:#(bold bold bold bold bold)) |
|
4196 |
" |
|
4197 |
! |
|
4198 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4199 |
emphasisAt:characterIndex |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4200 |
"return the emphasis at some index. |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4201 |
Since characterArrays do not hold any emphasis information, |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4202 |
nil (no emphasis) is returned here." |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4203 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4204 |
^ nil |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4205 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4206 |
"Created: 11.5.1996 / 14:13:27 / cg" |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4207 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4208 |
|
11632
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4209 |
emphasisAtPoint:aPoint on:aGC |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4210 |
"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
|
4211 |
|
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4212 |
^ nil |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4213 |
! |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4214 |
|
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4215 |
emphasisCollection |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4216 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4217 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4218 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4219 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4220 |
^ RunArray new:(self size) |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4221 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4222 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4223 |
"Modified: 14.5.1996 / 15:02:29 / cg" |
3404 | 4224 |
! |
4225 |
||
11919 | 4226 |
emphasiseFrom:start to:stop with:newEmphasis |
4227 |
"set to the emphasis within some range. return the receiver" |
|
4228 |
||
4229 |
^ self asText emphasiseFrom:start to:stop with:newEmphasis |
|
4230 |
||
4231 |
" |
|
12177 | 4232 |
'hello' emphasiseFrom:2 with:#italic |
11919 | 4233 |
|
4234 |
Transcript showCR:('hello' emphasiseFrom:2 with:#italic) |
|
4235 |
" |
|
4236 |
! |
|
4237 |
||
4238 |
emphasiseFrom:start with:newEmphasis |
|
4239 |
"set to the emphasis within some range. return the receiver" |
|
4240 |
||
4241 |
^ self emphasiseFrom:start to:(self size) with:newEmphasis |
|
4242 |
||
4243 |
" |
|
12177 | 4244 |
'hello' emphasiseFrom:2 with:#italic |
11919 | 4245 |
|
4246 |
Transcript showCR:('hello' emphasiseFrom:2 with:#italic) |
|
4247 |
" |
|
4248 |
! |
|
4249 |
||
3404 | 4250 |
emphasizeAllWith:emphasis |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4251 |
"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
|
4252 |
|
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4253 |
"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
|
4254 |
Text isNil ifTrue:[^ self]. |
3404 | 4255 |
^ self asText emphasizeAllWith:emphasis |
4256 |
||
4257 |
" |
|
4258 |
Transcript showCR:('hello' emphasizeAllWith:#bold) |
|
3599 | 4259 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
4260 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
|
4261 |
" |
|
4262 |
||
4263 |
"Modified: / 17.6.1998 / 12:51:44 / cg" |
|
5097 | 4264 |
! |
4265 |
||
4266 |
makeSelectorBoldIn:aClass |
|
14050 | 4267 |
"the receiver represents some source code for a method in aClass. |
5097 | 4268 |
Change myself to boldify the selector. |
14050 | 4269 |
Not yet implemented (could easily use the syntaxHighlighter for this ...). |
4270 |
For protocol compatibility with other smalltalks" |
|
5097 | 4271 |
|
4272 |
^ self |
|
4273 |
||
14050 | 4274 |
"Created: / 13-12-1999 / 21:49:24 / cg" |
4275 |
! |
|
4276 |
||
16697 | 4277 |
withColor:aColor |
4278 |
"return a text object representing the receiver, but all colorized" |
|
4279 |
||
4280 |
^ self colorizeAllWith:aColor |
|
4281 |
||
4282 |
" |
|
4283 |
Transcript showCR:('hello' withColor:Color red) |
|
4284 |
Transcript showCR:('world' withColor:Color green darkened) |
|
4285 |
" |
|
4286 |
! |
|
4287 |
||
14050 | 4288 |
withoutAnyColorEmphasis |
4289 |
"for protocol compatibility with Text" |
|
4290 |
||
4291 |
^ self |
|
4292 |
||
4293 |
"Created: / 06-03-2012 / 18:15:38 / cg" |
|
6653 | 4294 |
! |
4295 |
||
12396 | 4296 |
withoutBackgroundColorEmphasis |
14050 | 4297 |
"for protocol compatibility with Text" |
4298 |
||
12396 | 4299 |
^ self |
14050 | 4300 |
|
4301 |
"Modified (comment): / 06-03-2012 / 18:14:27 / cg" |
|
12396 | 4302 |
! |
4303 |
||
6653 | 4304 |
withoutEmphasis:emphasisToRemove |
14050 | 4305 |
"for protocol compatibility with Text" |
4306 |
||
6653 | 4307 |
^ self |
14050 | 4308 |
|
4309 |
"Modified (comment): / 06-03-2012 / 18:14:29 / cg" |
|
12396 | 4310 |
! |
4311 |
||
4312 |
withoutForegroundColorEmphasis |
|
14050 | 4313 |
"for protocol compatibility with Text" |
4314 |
||
12396 | 4315 |
^ self |
14050 | 4316 |
|
4317 |
"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
|
4318 |
! ! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4319 |
|
7265 | 4320 |
!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
|
4321 |
|
12767
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4322 |
decodeAsLiteralArray |
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4323 |
"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
|
4324 |
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
|
4325 |
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
|
4326 |
|
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4327 |
^ self |
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4328 |
! |
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4329 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4330 |
decodeFrom:encodingSymbol |
8874 | 4331 |
"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
|
4332 |
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
|
4333 |
|
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
4334 |
|myEncoding encoder| |
7950 | 4335 |
|
4336 |
encodingSymbol isNil ifTrue:[^ self]. |
|
4337 |
myEncoding := self encoding. |
|
4338 |
encodingSymbol == myEncoding ifTrue:[^ self]. |
|
4339 |
||
4340 |
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
|
4341 |
encoder isNil ifTrue:[^ self]. |
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
4342 |
^ 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
|
4343 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4344 |
|
9192 | 4345 |
encodeFrom:oldEncoding into:newEncoding |
4346 |
^ CharacterEncoder encodeString:self from:oldEncoding into:newEncoding |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
4347 |
|
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
4348 |
" |
17600 | 4349 |
'äüö' encodeFrom:#iso8859 into:#utf8 |
4350 |
('äüö' encodeFrom:#iso8859 into:#utf8) encodeFrom:#utf8 into:#unicode |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
4351 |
" |
9192 | 4352 |
! |
4353 |
||
4354 |
rot13 |
|
8874 | 4355 |
"Usenet: from `rotate alphabet 13 places'] |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4356 |
The simple Caesar-cypher encryption that replaces each English |
8874 | 4357 |
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
|
4358 |
so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' |
8874 | 4359 |
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
|
4360 |
It is used to enclose the text in a sealed wrapper that the reader must choose |
8874 | 4361 |
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
|
4362 |
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
|
4363 |
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
|
4364 |
|
11865 | 4365 |
^ self rot:13 |
8874 | 4366 |
|
4367 |
" |
|
4368 |
'hello world' rot13 |
|
4369 |
'hello world' rot13 rot13 |
|
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4370 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4371 |
! |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4372 |
|
11865 | 4373 |
rot:n |
4374 |
"Usenet: from `rotate alphabet N places'] |
|
4375 |
The simple Caesar-cypher encryption that replaces each English |
|
4376 |
letter with the one N places forward or back along the alphabet, |
|
4377 |
so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' by rot 13 |
|
4378 |
Most Usenet news reading and posting programs include a rot13 feature. |
|
4379 |
It is used to enclose the text in a sealed wrapper that the reader must choose |
|
4380 |
to open -- e.g., for posting things that might offend some readers, or spoilers. |
|
4381 |
A major advantage of rot13 over rot(N) for other N is that it |
|
4382 |
is self-inverse, so the same code can be used for encoding and decoding." |
|
4383 |
||
4384 |
^ self species |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4385 |
streamContents:[:aStream | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4386 |
self do:[:char | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4387 |
aStream nextPut:(char rot:n) ]] |
11865 | 4388 |
|
4389 |
" |
|
4390 |
'hello world' rot:13 |
|
4391 |
('hello world' rot:13) rot:13 |
|
4392 |
" |
|
4393 |
! |
|
4394 |
||
15656 | 4395 |
utf16Encoded |
4396 |
"Return my UTF-16 representation as a new TwoByteString" |
|
4397 |
||
4398 |
|s| |
|
4399 |
||
4400 |
s := WriteStream on:(TwoByteString uninitializedNew:self size). |
|
4401 |
s nextPutAllUtf16:self. |
|
4402 |
^ s contents |
|
4403 |
||
4404 |
" |
|
4405 |
'abcde1234' utf16Encoded |
|
17600 | 4406 |
'abcdeäöüß' utf16Encoded |
15656 | 4407 |
" |
4408 |
||
4409 |
"Modified: / 11-05-2010 / 19:12:37 / cg" |
|
4410 |
! |
|
4411 |
||
9192 | 4412 |
utf8Encoded |
4413 |
"Return my UTF-8 representation as a new String" |
|
4414 |
||
17625 | 4415 |
|string| |
4416 |
||
4417 |
string := self string. |
|
4418 |
string ~~ self ifTrue:[ |
|
18597 | 4419 |
^ string utf8Encoded. |
17625 | 4420 |
]. |
14592 | 4421 |
|
18612 | 4422 |
^ CharacterEncoderImplementations::ISO10646_to_UTF8 new encodeString:self |
18597 | 4423 |
|
4424 |
" |
|
4425 |
'abcde1234' asUnicode32String utf8Encoded |
|
4426 |
'abcdeäöüß' asUnicode32String utf8Encoded |
|
12925
5c0a9a633ca1
comment/format in: #utf8Encoded
Claus Gittinger <cg@exept.de>
parents:
12912
diff
changeset
|
4427 |
" |
5c0a9a633ca1
comment/format in: #utf8Encoded
Claus Gittinger <cg@exept.de>
parents:
12912
diff
changeset
|
4428 |
|
5c0a9a633ca1
comment/format in: #utf8Encoded
Claus Gittinger <cg@exept.de>
parents:
12912
diff
changeset
|
4429 |
"Modified: / 11-05-2010 / 19:12:37 / cg" |
17625 | 4430 |
! |
4431 |
||
4432 |
utf8EncodedOn:aStream |
|
4433 |
"write to aStream in utf8 encoding" |
|
4434 |
||
4435 |
|string| |
|
4436 |
||
4437 |
string := self string. |
|
4438 |
string ~~ self ifTrue:[ |
|
18597 | 4439 |
^ string utf8EncodedOn:aStream. |
4440 |
]. |
|
4441 |
||
4442 |
self containsNon7BitAscii ifTrue:[ |
|
4443 |
aStream nextPutAllUtf8:self. |
|
4444 |
] ifFalse:[ |
|
4445 |
"speed up common case" |
|
4446 |
aStream nextPutAll:self. |
|
17625 | 4447 |
]. |
4448 |
||
18597 | 4449 |
" |
4450 |
String streamContents:[:w| |
|
4451 |
'abcde1234' asUnicode32String utf8EncodedOn:w |
|
4452 |
]. |
|
4453 |
String streamContents:[:w| |
|
4454 |
'abcde1234' asUnicode32String utf8EncodedOn:w |
|
4455 |
]. |
|
4456 |
String streamContents:[:w| |
|
4457 |
'abcdeäöüß' asUnicode32String utf8EncodedOn:w |
|
4458 |
]. |
|
17625 | 4459 |
" |
9192 | 4460 |
! ! |
4461 |
||
11345 | 4462 |
|
12111 | 4463 |
!CharacterArray methodsFor:'matching - glob expressions'! |
4464 |
||
4465 |
compoundMatch:aString |
|
4466 |
"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
|
4467 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
12111 | 4468 |
This is usable with fileName pattern fields. |
4469 |
||
4470 |
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
|
4471 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4472 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4473 |
NOTICE: the receiver is the match pattern" |
4474 |
||
15890 | 4475 |
^ self compoundMatch:aString caseSensitive:true withoutSeparators:false |
12111 | 4476 |
|
4477 |
" |
|
4478 |
'f*' match:'foo' |
|
4479 |
'b*' match:'foo' |
|
4480 |
'f*;b*' match:'foo' |
|
4481 |
'f*;b*' match:'bar' |
|
4482 |
'f*;b*' compoundMatch:'foo' |
|
4483 |
'f*;b*' compoundMatch:'bar' |
|
4484 |
" |
|
4485 |
||
4486 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4487 |
"Modified: / 16.12.1999 / 01:22:08 / cg" |
|
4488 |
! |
|
4489 |
||
15734 | 4490 |
compoundMatch:aString caseSensitive:caseSensitive |
12111 | 4491 |
"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
|
4492 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
12111 | 4493 |
This is usable with fileName pattern fields. |
4494 |
||
4495 |
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
|
4496 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4497 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4498 |
NOTICE: the receiver is the match pattern" |
4499 |
||
15890 | 4500 |
^self compoundMatch:aString caseSensitive:caseSensitive withoutSeparators:false |
4501 |
||
4502 |
" |
|
4503 |
'f*' match:'foo' |
|
4504 |
'b*' match:'foo' |
|
4505 |
'f*;b*' match:'foo' |
|
4506 |
'f*;b*' match:'bar' |
|
4507 |
'f*;b*' compoundMatch:'foo' |
|
4508 |
'f*;b*' compoundMatch:'bar' |
|
4509 |
'f*;b*' compoundMatch:'Foo' caseSensitive:false |
|
4510 |
'f*;b*' compoundMatch:'Bar' caseSensitive:false |
|
4511 |
'f*;b*' compoundMatch:'ccc' caseSensitive:false |
|
4512 |
" |
|
4513 |
||
4514 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
4515 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4516 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
4517 |
! |
|
4518 |
||
4519 |
compoundMatch:aString caseSensitive:caseSensitive withoutSeparators:withoutSeparators |
|
4520 |
"like match, but the receiver may be a compound match pattern, |
|
4521 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
|
4522 |
If withoutSeparators is true, spaces around individual patterns are stripped off. |
|
4523 |
This is usable with fileName pattern fields. |
|
4524 |
||
4525 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 4526 |
NOT the ST-80 meaning. |
15890 | 4527 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4528 |
NOTICE: the receiver is the match pattern" |
|
4529 |
||
12111 | 4530 |
|matchers| |
4531 |
||
4532 |
matchers := self asCollectionOfSubstringsSeparatedBy:$;. |
|
15890 | 4533 |
withoutSeparators ifTrue:[ matchers := matchers collect:[:each | each withoutSeparators] ]. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4534 |
^ matchers |
19033 | 4535 |
contains:[:aPattern | |
4536 |
aPattern match:aString caseSensitive:caseSensitive escapeCharacter:nil |
|
4537 |
]. |
|
15734 | 4538 |
|
4539 |
" |
|
4540 |
'f*' match:'foo' |
|
4541 |
'b*' match:'foo' |
|
4542 |
'f*;b*' match:'foo' |
|
4543 |
'f*;b*' match:'bar' |
|
4544 |
'f*;b*' compoundMatch:'foo' |
|
4545 |
'f*;b*' compoundMatch:'bar' |
|
4546 |
'f*;b*' compoundMatch:'Foo' caseSensitive:false |
|
4547 |
'f*;b*' compoundMatch:'Bar' caseSensitive:false |
|
4548 |
'f*;b*' compoundMatch:'ccc' caseSensitive:false |
|
15890 | 4549 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4550 |
'f* ; b*' compoundMatch:'foo' |
15890 | 4551 |
'f* ; b*' compoundMatch:'foo' caseSensitive:true withoutSeparators:true |
15734 | 4552 |
" |
4553 |
||
4554 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
4555 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4556 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
4557 |
! |
|
4558 |
||
4559 |
compoundMatch:aString ignoreCase:ignoreCase |
|
4560 |
<resource: #obsolete> |
|
4561 |
||
4562 |
"like match, but the receiver may be a compound match pattern, |
|
4563 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
|
4564 |
This is usable with fileName pattern fields. |
|
4565 |
||
4566 |
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
|
4567 |
NOT the ST-80 meaning. |
15734 | 4568 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4569 |
NOTICE: the receiver is the match pattern" |
|
4570 |
||
4571 |
^ self compoundMatch:aString caseSensitive:ignoreCase not |
|
12111 | 4572 |
|
4573 |
" |
|
4574 |
'f*' match:'foo' |
|
4575 |
'b*' match:'foo' |
|
4576 |
'f*;b*' match:'foo' |
|
4577 |
'f*;b*' match:'bar' |
|
4578 |
'f*;b*' compoundMatch:'foo' |
|
4579 |
'f*;b*' compoundMatch:'bar' |
|
4580 |
'f*;b*' compoundMatch:'Foo' ignoreCase:true |
|
4581 |
'f*;b*' compoundMatch:'Bar' ignoreCase:true |
|
4582 |
'f*;b*' compoundMatch:'ccc' ignoreCase:true |
|
4583 |
" |
|
4584 |
||
4585 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
4586 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4587 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
4588 |
! |
|
4589 |
||
4590 |
findMatchString:matchString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4591 |
"like findString/indexOfSubCollection, but allowing GLOB match patterns. |
12111 | 4592 |
find matchstring; if found, return the index; |
4593 |
if not found, return 0. |
|
4594 |
||
4595 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
19033 | 4596 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4597 |
NOTICE: this GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4598 |
NOTICE: the argument is the match pattern" |
4599 |
||
19033 | 4600 |
^ self findMatchString:matchString startingAt:1 caseSensitive:true ifAbsent:0 |
4601 |
||
4602 |
" |
|
4603 |
1234567890123 |
|
4604 |
'hello world bla foo baz' findMatchString:'b* ' |
|
4605 |
" |
|
12111 | 4606 |
! |
4607 |
||
4608 |
findMatchString:matchString startingAt:index |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4609 |
"like findString, but allowing GLOB match patterns. |
12111 | 4610 |
find matchstring, starting at index. if found, return the index; |
4611 |
if not found, return 0. |
|
4612 |
||
4613 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 4614 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4615 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4616 |
NOTICE: the argument is the match pattern" |
4617 |
||
19033 | 4618 |
^ self findMatchString:matchString startingAt:index caseSensitive:true ifAbsent:0 |
12111 | 4619 |
! |
4620 |
||
15734 | 4621 |
findMatchString:matchString startingAt:index caseSensitive:caseSensitive ifAbsent:exceptionBlock |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4622 |
"like findString, but allowing GLOB match patterns. |
12111 | 4623 |
find matchstring, starting at index. if found, return the index; |
4624 |
if not found, return the result of evaluating exceptionBlock. |
|
4625 |
This is a q&d hack - not very efficient. |
|
4626 |
||
4627 |
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
|
4628 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4629 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4630 |
NOTICE: the argument is the match pattern" |
4631 |
||
4632 |
|firstChar firstSet |
|
4633 |
startIndex "{ Class: SmallInteger }" |
|
4634 |
matchSize "{ Class: SmallInteger }" |
|
4635 |
mySize "{ Class: SmallInteger }" |
|
4636 |
realMatchString lcChar ucChar| |
|
4637 |
||
4638 |
matchSize := matchString size. |
|
4639 |
matchSize == 0 ifTrue:[^ index]. "empty string matches" |
|
4640 |
||
4641 |
realMatchString := matchString. |
|
4642 |
(realMatchString endsWith:$*) ifFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4643 |
realMatchString := realMatchString , '*'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4644 |
matchSize := matchSize + 1 |
12111 | 4645 |
]. |
4646 |
||
4647 |
mySize := self size. |
|
4648 |
firstChar := realMatchString at:1. |
|
4649 |
firstChar == self class matchEscapeCharacter ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4650 |
firstChar := realMatchString at:2. |
12111 | 4651 |
]. |
4652 |
||
4653 |
firstChar asString includesMatchCharacters ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4654 |
index to:mySize do:[:col | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4655 |
(realMatchString match:self from:col to:mySize caseSensitive:caseSensitive) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4656 |
ifTrue:[^ col] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4657 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4658 |
^ exceptionBlock value. |
12111 | 4659 |
]. |
4660 |
||
4661 |
lcChar := firstChar asLowercase. |
|
4662 |
ucChar := firstChar asUppercase. |
|
15734 | 4663 |
(caseSensitive not and:[ lcChar ~= ucChar ]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4664 |
firstSet := Array with:ucChar with:lcChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4665 |
startIndex := self indexOfAny:firstSet startingAt:index. |
12111 | 4666 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4667 |
startIndex := self indexOf:firstChar startingAt:index. |
12111 | 4668 |
]. |
4669 |
[startIndex == 0] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4670 |
(realMatchString match:self from:startIndex to:mySize caseSensitive:caseSensitive) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4671 |
ifTrue:[^ startIndex]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4672 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4673 |
firstSet notNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4674 |
startIndex := self indexOfAny:firstSet startingAt:(startIndex + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4675 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4676 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4677 |
]. |
12111 | 4678 |
]. |
4679 |
^ exceptionBlock value |
|
4680 |
||
4681 |
" |
|
4682 |
'one two three four' findMatchString:'o[nu]' |
|
4683 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
15734 | 4684 |
'one two three four one' findMatchString:'ONE' startingAt:3 caseSensitive:false ifAbsent:0 |
4685 |
'one two three four one' findMatchString:'ONE' startingAt:3 caseSensitive:true ifAbsent:0 |
|
4686 |
'one two three four ONE' findMatchString:'O#E' startingAt:1 caseSensitive:false ifAbsent:0 |
|
4687 |
'one two three four ONE' findMatchString:'O#E' startingAt:1 caseSensitive:true ifAbsent:0 |
|
4688 |
12345678901234567890 |
|
4689 |
" |
|
4690 |
||
4691 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
|
4692 |
! |
|
4693 |
||
4694 |
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock |
|
4695 |
<resource: #obsolete> |
|
4696 |
"like findString, but allowing GLOB match patterns. |
|
4697 |
find matchstring, starting at index. if found, return the index; |
|
4698 |
if not found, return the result of evaluating exceptionBlock. |
|
4699 |
This is a q&d hack - not very efficient. |
|
4700 |
||
4701 |
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
|
4702 |
NOT the ST-80 meaning. |
15734 | 4703 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4704 |
NOTICE: the argument is the match pattern" |
|
4705 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4706 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4707 |
findMatchString:matchString startingAt:index caseSensitive:ignoreCase not ifAbsent:exceptionBlock |
15734 | 4708 |
|
4709 |
" |
|
4710 |
'one two three four' findMatchString:'o[nu]' |
|
4711 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
12111 | 4712 |
'one two three four one' findMatchString:'ONE' startingAt:3 ignoreCase:true ifAbsent:0 |
4713 |
" |
|
4714 |
||
4715 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
|
4716 |
! |
|
4717 |
||
4718 |
includesMatchString:matchString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4719 |
"like includesString, but allowing GLOB match patterns. |
12111 | 4720 |
find matchstring; if found, return true, otherwise return false. |
4721 |
||
4722 |
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
|
4723 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4724 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4725 |
NOTICE: the argument is the match pattern" |
4726 |
||
4727 |
^ (self findMatchString:matchString) ~~ 0 |
|
4728 |
||
4729 |
" |
|
4730 |
'hello world' includesMatchString:'h*' |
|
4731 |
'hello world' includesMatchString:'h[aeiou]llo' |
|
4732 |
'hello world' includesMatchString:'wor*' |
|
4733 |
'hello world' includesMatchString:'woR*' |
|
4734 |
" |
|
4735 |
! |
|
4736 |
||
4737 |
includesMatchString:matchString caseSensitive:caseSensitive |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4738 |
"like includesString, but allowing GLOB match patterns. |
12111 | 4739 |
find matchstring; if found, return true, otherwise return false. |
4740 |
||
4741 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 4742 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4743 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4744 |
NOTICE: the argument is the match pattern" |
4745 |
||
19033 | 4746 |
^ (self findMatchString:matchString startingAt:1 caseSensitive:caseSensitive ifAbsent:0) ~~ 0 |
12111 | 4747 |
|
4748 |
" |
|
4749 |
'hello world' includesMatchString:'h*' caseSensitive:true |
|
4750 |
'hello world' includesMatchString:'h*' caseSensitive:false |
|
4751 |
'Hello world' includesMatchString:'h*' caseSensitive:true |
|
4752 |
'Hello world' includesMatchString:'h*' caseSensitive:false |
|
4753 |
||
4754 |
'hello world' includesMatchString:'h[aeiou]llo' caseSensitive:true |
|
4755 |
'hello world' includesMatchString:'h[aeiou]llo' caseSensitive:false |
|
4756 |
||
4757 |
'hello world' includesMatchString:'wor*' caseSensitive:true |
|
4758 |
'hello world' includesMatchString:'wor*' caseSensitive:false |
|
4759 |
||
4760 |
'hello world' includesMatchString:'woR*' caseSensitive:true |
|
4761 |
'hello world' includesMatchString:'woR*' caseSensitive:false |
|
4762 |
" |
|
4763 |
! |
|
4764 |
||
4765 |
match:aString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4766 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 4767 |
characters $* (to match any string) or $# (to match any character). |
4768 |
or [...] to match a set of characters. |
|
4769 |
Lower/uppercase are considered different. |
|
4770 |
The escape character is the backQuote. |
|
4771 |
||
4772 |
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
|
4773 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4774 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4775 |
NOTICE: the receiver is the match pattern" |
4776 |
||
15734 | 4777 |
^ self match:aString from:1 to:aString size caseSensitive:true |
12111 | 4778 |
|
4779 |
" |
|
4780 |
'\*f*' match:'f' |
|
4781 |
'\*f*' match:'*f' |
|
4782 |
'*\*f*' match:'*f' |
|
4783 |
'*f*' match:'*f' |
|
4784 |
'*ute*' match:'computer' |
|
4785 |
'*uter' match:'computer' |
|
4786 |
'uter*' match:'computer' |
|
4787 |
'*ute*' match:'' |
|
4788 |
'[abcd]*' match:'computer' |
|
4789 |
'[abcd]*' match:'komputer' |
|
4790 |
'*some*compl*ern*' match:'this is some more complicated pattern match' |
|
4791 |
'*some*compl*ern*' match:'this is another complicated pattern match' |
|
4792 |
'*-hh' match:'anton-h' |
|
4793 |
" |
|
4794 |
||
4795 |
"Modified: / 9.6.1998 / 18:50:00 / cg" |
|
4796 |
! |
|
4797 |
||
15734 | 4798 |
match:aString caseSensitive:caseSensitive |
4799 |
"return true if aString matches self, where self may contain GLOB meta-match |
|
4800 |
characters $* (to match any string) or $# (to match any character) |
|
4801 |
or [...] to match a set of characters. |
|
4802 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
4803 |
The escape character is the backQuote. |
|
4804 |
||
4805 |
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
|
4806 |
NOT the ST-80 meaning. |
15734 | 4807 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4808 |
NOTICE: the receiver is the match pattern" |
|
4809 |
||
4810 |
^ self match:aString from:1 to:aString size caseSensitive:caseSensitive |
|
4811 |
||
4812 |
" |
|
4813 |
'*ute*' match:'COMPUTER' caseSensitive:false |
|
4814 |
'*uter' match:'COMPUTER' caseSensitive:true |
|
4815 |
'[abcd]*' match:'computer' caseSensitive:true |
|
4816 |
'[abcd]*' match:'Computer' caseSensitive:true |
|
4817 |
'[a-k]*' match:'komputer' caseSensitive:true |
|
4818 |
'[a-k]*' match:'zomputer' caseSensitive:true |
|
4819 |
'[a-k]*' match:'Komputer' caseSensitive:true |
|
4820 |
'[a-k]*' match:'Komputer' caseSensitive:false |
|
4821 |
'*some*compl*ern*' match:'this is some more complicated pattern match' caseSensitive:false |
|
4822 |
'*some*compl*ern*' match:'this is another complicated pattern match' caseSensitive:false |
|
4823 |
||
4824 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4825 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4826 |
'[ab]*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4827 |
] |
15734 | 4828 |
]. |
4829 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4830 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4831 |
'*at:*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4832 |
] |
15734 | 4833 |
]. |
4834 |
" |
|
4835 |
||
4836 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
4837 |
! |
|
4838 |
||
4839 |
match:aString caseSensitive:caseSensitive escapeCharacter:escape |
|
4840 |
"return true if aString matches self, where self may contain GLOB meta-match |
|
4841 |
characters $* (to match any string) or $# (to match any character) |
|
4842 |
or [...] to match a set of characters. |
|
4843 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
4844 |
||
4845 |
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
|
4846 |
NOT the ST-80 meaning. |
15734 | 4847 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4848 |
NOTICE: the receiver is the match pattern" |
|
4849 |
||
4850 |
^ self match:aString from:1 to:aString size caseSensitive:caseSensitive escapeCharacter:escape |
|
4851 |
||
4852 |
" |
|
4853 |
'*ute*' match:'COMPUTER' caseSensitive:false |
|
4854 |
'*uter' match:'COMPUTER' caseSensitive:true |
|
4855 |
'[abcd]*' match:'computer' caseSensitive:true |
|
4856 |
'[abcd]*' match:'Computer' caseSensitive:true |
|
4857 |
'[a-k]*' match:'komputer' caseSensitive:true |
|
4858 |
'[a-k]*' match:'zomputer' caseSensitive:true |
|
4859 |
'[a-k]*' match:'Komputer' caseSensitive:true |
|
4860 |
'[a-k]*' match:'Komputer' caseSensitive:false |
|
4861 |
'*some*compl*ern*' match:'this is some more complicated pattern match' caseSensitive:false |
|
4862 |
'*some*compl*ern*' match:'this is another complicated pattern match' caseSensitive:false |
|
4863 |
||
4864 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4865 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4866 |
'[ab]*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4867 |
] |
15734 | 4868 |
]. |
4869 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4870 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4871 |
'*at:*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4872 |
] |
15734 | 4873 |
]. |
4874 |
" |
|
4875 |
||
4876 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
4877 |
! |
|
4878 |
||
12111 | 4879 |
match:aString escapeCharacter:escape |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4880 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 4881 |
characters $* (to match any string) or $# (to match any character). |
4882 |
or [...] to match a set of characters. |
|
4883 |
Lower/uppercase are considered different. |
|
4884 |
||
4885 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 4886 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4887 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4888 |
NOTICE: the receiver is the match pattern" |
4889 |
||
19033 | 4890 |
^ self match:aString from:1 to:aString size caseSensitive:true escapeCharacter:escape |
12111 | 4891 |
|
4892 |
" |
|
4893 |
'a\b\c\*' match:'a\b\c\d' |
|
4894 |
'a\b\c\*' match:'a\b\c\d' escapeCharacter:nil |
|
4895 |
" |
|
4896 |
! |
|
4897 |
||
15734 | 4898 |
match:aString from:start to:stop caseSensitive:caseSensitive |
4899 |
"return true if part of aString matches myself, |
|
4900 |
where self may contain GLOB meta-match |
|
4901 |
characters $* (to match any string) or $# (to match any character) |
|
4902 |
or [...] to match a set of characters. |
|
4903 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
4904 |
The escape character is the backQuote. |
|
4905 |
||
4906 |
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
|
4907 |
NOT the ST-80 meaning. |
15734 | 4908 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4909 |
NOTICE: the receiver is the match pattern" |
|
4910 |
||
4911 |
^ self |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4912 |
match:aString from:start to:stop caseSensitive:caseSensitive |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4913 |
escapeCharacter:(self class matchEscapeCharacter) |
15734 | 4914 |
|
4915 |
" |
|
4916 |
'*ute*' match:'12345COMPUTER' from:1 to:5 caseSensitive:false |
|
4917 |
'*ute*' match:'12345COMPUTER' from:6 to:13 caseSensitive:false |
|
4918 |
" |
|
4919 |
||
4920 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
4921 |
! |
|
4922 |
||
4923 |
match:aString from:start to:stop caseSensitive:caseSensitive escapeCharacter:escape |
|
4924 |
"return true if part of aString matches myself, |
|
4925 |
where self may contain GLOB meta-match |
|
4926 |
characters $* (to match any string) or $# (to match any character) |
|
4927 |
or [...] to match a set of characters. |
|
4928 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
4929 |
||
4930 |
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
|
4931 |
NOT the ST-80 meaning. |
15734 | 4932 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4933 |
NOTICE: the receiver is the match pattern" |
|
4934 |
||
4935 |
|matchScanArray| |
|
4936 |
||
4937 |
" |
|
4938 |
keep the matchScanArray from the most recent match - |
|
4939 |
avoids parsing the pattern over-and over if multiple searches |
|
4940 |
are done with the same pattern. |
|
4941 |
" |
|
4942 |
(PreviousMatch notNil |
|
4943 |
and:[PreviousMatch key = self]) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4944 |
matchScanArray := PreviousMatch value |
15734 | 4945 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4946 |
matchScanArray := self class matchScanArrayFrom:self escapeCharacter:escape. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4947 |
matchScanArray isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4948 |
'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
|
4949 |
^ self = aString |
15734 | 4950 |
"/ ^ false |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4951 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4952 |
PreviousMatch := self -> matchScanArray. |
15734 | 4953 |
]. |
4954 |
||
4955 |
^ self class |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4956 |
matchScan:matchScanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4957 |
from:1 to:matchScanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4958 |
with:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4959 |
from:start to:stop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4960 |
caseSensitive:caseSensitive |
15734 | 4961 |
|
4962 |
" |
|
4963 |
'*ute*' match:'12345COMPUTER' from:1 to:5 caseSensitive:false |
|
4964 |
'*ute*' match:'12345COMPUTER' from:6 to:13 caseSensitive:false |
|
4965 |
" |
|
4966 |
||
4967 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
4968 |
! |
|
4969 |
||
12111 | 4970 |
match:aString from:start to:stop ignoreCase:ignoreCase |
15734 | 4971 |
<resource: #obsolete> |
12111 | 4972 |
"return true if part of aString matches myself, |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4973 |
where self may contain GLOB meta-match |
12111 | 4974 |
characters $* (to match any string) or $# (to match any character) |
4975 |
or [...] to match a set of characters. |
|
4976 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
4977 |
The escape character is the backQuote. |
|
4978 |
||
4979 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 4980 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4981 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4982 |
NOTICE: the receiver is the match pattern" |
4983 |
||
4984 |
^ self |
|
19033 | 4985 |
match:aString from:start to:stop caseSensitive:ignoreCase not |
4986 |
escapeCharacter:(self class matchEscapeCharacter) |
|
12111 | 4987 |
|
4988 |
" |
|
4989 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
4990 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
4991 |
" |
|
4992 |
||
4993 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
4994 |
! |
|
4995 |
||
4996 |
match:aString from:start to:stop ignoreCase:ignoreCase escapeCharacter:escape |
|
15734 | 4997 |
<resource: #obsolete> |
12111 | 4998 |
"return true if part of aString matches myself, |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4999 |
where self may contain GLOB meta-match |
12111 | 5000 |
characters $* (to match any string) or $# (to match any character) |
5001 |
or [...] to match a set of characters. |
|
5002 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
5003 |
||
5004 |
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
|
5005 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5006 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5007 |
NOTICE: the receiver is the match pattern" |
5008 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5009 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5010 |
match:aString from:start to:stop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5011 |
caseSensitive:ignoreCase not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5012 |
escapeCharacter:escape |
12111 | 5013 |
|
5014 |
" |
|
5015 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
5016 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
5017 |
" |
|
5018 |
||
5019 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
5020 |
! |
|
5021 |
||
5022 |
match:aString ignoreCase:ignoreCase |
|
15734 | 5023 |
<resource: #obsolete> |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5024 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 5025 |
characters $* (to match any string) or $# (to match any character) |
5026 |
or [...] to match a set of characters. |
|
5027 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
5028 |
The escape character is the backQuote. |
|
5029 |
||
5030 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 5031 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5032 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5033 |
NOTICE: the receiver is the match pattern" |
5034 |
||
15734 | 5035 |
"/ leave it this way, in case a customer has redefined it for performance (for a while) |
19033 | 5036 |
^ self match:aString from:1 to:aString size caseSensitive:ignoreCase not |
12111 | 5037 |
|
5038 |
" |
|
5039 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
5040 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
5041 |
'[abcd]*' match:'computer' ignoreCase:false |
|
5042 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
5043 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
5044 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
5045 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
5046 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
5047 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
5048 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
5049 |
||
5050 |
Time millisecondsToRun:[ |
|
19033 | 5051 |
Symbol allInstancesDo:[:sym | |
5052 |
'[ab]*' match:sym ignoreCase:false |
|
5053 |
] |
|
12111 | 5054 |
]. |
5055 |
Time millisecondsToRun:[ |
|
19033 | 5056 |
Symbol allInstancesDo:[:sym | |
5057 |
'*at:*' match:sym ignoreCase:false |
|
5058 |
] |
|
12111 | 5059 |
]. |
5060 |
" |
|
5061 |
||
5062 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
5063 |
! |
|
5064 |
||
5065 |
match:aString ignoreCase:ignoreCase escapeCharacter:escape |
|
15734 | 5066 |
<resource: #obsolete> |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5067 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 5068 |
characters $* (to match any string) or $# (to match any character) |
5069 |
or [...] to match a set of characters. |
|
5070 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
5071 |
||
5072 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 5073 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5074 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5075 |
NOTICE: the receiver is the match pattern" |
5076 |
||
19033 | 5077 |
^ self match:aString from:1 to:aString size caseSensitive:ignoreCase not escapeCharacter:escape |
12111 | 5078 |
|
5079 |
" |
|
5080 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
5081 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
5082 |
'[abcd]*' match:'computer' ignoreCase:false |
|
5083 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
5084 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
5085 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
5086 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
5087 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
5088 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
5089 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
5090 |
||
5091 |
Time millisecondsToRun:[ |
|
19033 | 5092 |
Symbol allInstancesDo:[:sym | |
5093 |
'[ab]*' match:sym ignoreCase:false |
|
5094 |
] |
|
12111 | 5095 |
]. |
5096 |
Time millisecondsToRun:[ |
|
19033 | 5097 |
Symbol allInstancesDo:[:sym | |
5098 |
'*at:*' match:sym ignoreCase:false |
|
5099 |
] |
|
12111 | 5100 |
]. |
5101 |
" |
|
5102 |
||
5103 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
5104 |
! |
|
5105 |
||
5106 |
matches:aPatternString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5107 |
"return true if the receiver matches aString, where aPatternString may contain GLOB meta-match |
12111 | 5108 |
characters $* (to match any string) or $# (to match any character). |
5109 |
or [...] to match a set of characters. |
|
5110 |
Lower/uppercase are considered different. |
|
5111 |
||
5112 |
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
|
5113 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5114 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5115 |
NOTICE: the receiver is the match pattern" |
5116 |
||
5117 |
^ aPatternString match:self |
|
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5118 |
! |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5119 |
|
15734 | 5120 |
matches:aPatternString caseSensitive:caseSensitive |
5121 |
"return true if the receiver matches aString, where aPatternString may contain GLOB meta-match |
|
5122 |
characters $* (to match any string) or $# (to match any character). |
|
5123 |
or [...] to match a set of characters. |
|
5124 |
||
5125 |
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
|
5126 |
NOT the ST-80 meaning. |
15734 | 5127 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
5128 |
NOTICE: the receiver is the match pattern" |
|
5129 |
||
5130 |
^ aPatternString match:self caseSensitive:caseSensitive |
|
5131 |
! |
|
5132 |
||
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5133 |
matches:aPatternString ignoreCase:ignoreCase |
15734 | 5134 |
<resource: #obsolete> |
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5135 |
"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
|
5136 |
characters $* (to match any string) or $# (to match any character). |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5137 |
or [...] to match a set of characters. |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5138 |
Lower/uppercase are considered different. |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5139 |
|
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5140 |
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
|
5141 |
NOT the ST-80 meaning. |
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5142 |
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
|
5143 |
NOTICE: the receiver is the match pattern" |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5144 |
|
15734 | 5145 |
^ aPatternString match:self caseSensitive:ignoreCase not |
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5146 |
|
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5147 |
"Created: / 08-03-2012 / 03:11:11 / cg" |
12111 | 5148 |
! ! |
5149 |
||
5150 |
||
18722 | 5151 |
!CharacterArray methodsFor:'matching - regex'! |
5152 |
||
5153 |
matchesRegex:regexString caseSensitive:aBoolean |
|
5154 |
"Test if the receiver matches a regex. |
|
5155 |
May raise RxParser>>regexErrorSignal or child signals. |
|
5156 |
This is a part of the Regular Expression Matcher package, |
|
5157 |
(c) 1996, 1999 Vassili Bykov. |
|
5158 |
Refer to `documentation' protocol of RxParser class for details." |
|
5159 |
||
5160 |
aBoolean ifFalse:[ |
|
5161 |
^ self matchesRegexIgnoringCase:regexString |
|
5162 |
] ifTrue:[ |
|
5163 |
^ self matchesRegex:regexString |
|
5164 |
]. |
|
5165 |
||
5166 |
" |
|
5167 |
'hello world' matchesRegex:'h.*d'. |
|
5168 |
" |
|
5169 |
||
5170 |
"Created: / 13-12-2010 / 11:01:49 / cg" |
|
5171 |
! ! |
|
17625 | 5172 |
|
9192 | 5173 |
!CharacterArray methodsFor:'padded copying'! |
5174 |
||
5175 |
centerPaddedTo:newSize |
|
19464 | 5176 |
"return a new string consisting of the receiver's characters, |
5177 |
plus spaces up to length and center the receiver's characters in |
|
5178 |
the resulting string. |
|
5179 |
If the receiver's size is equal or greater than the length argument, |
|
5180 |
the original receiver is returned unchanged." |
|
9192 | 5181 |
|
5182 |
^ self centerPaddedTo:newSize with:(Character space) |
|
5183 |
||
5184 |
" |
|
5185 |
'foo' centerPaddedTo:10 |
|
5186 |
123 printString centerPaddedTo:10 |
|
5187 |
" |
|
5188 |
||
5189 |
"Created: 25.11.1995 / 10:53:57 / cg" |
|
5190 |
! |
|
9190 | 5191 |
|
5192 |
centerPaddedTo:size with:padCharacter |
|
5193 |
"return a new string of length size, which contains the receiver |
|
5194 |
centered (i.e. padded on both sides). |
|
5195 |
Characters are filled with padCharacter. |
|
19464 | 5196 |
If the receiver's size is equal or greater than the length argument, |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5197 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5198 |
|
9190 | 5199 |
|len s| |
5200 |
||
5201 |
len := self size. |
|
9192 | 5202 |
(len < size) ifTrue:[ |
19464 | 5203 |
s := self species new:size withAll:padCharacter. |
5204 |
s replaceFrom:(size - len) // 2 + 1 with:self. |
|
5205 |
^ s |
|
9192 | 5206 |
] |
5207 |
||
9190 | 5208 |
" |
5209 |
'foo' centerPaddedTo:11 with:$. |
|
5210 |
'fooBar' centerPaddedTo:5 with:$. |
|
5211 |
123 printString centerPaddedTo:10 with:$. |
|
5212 |
(' ' , 123 printString) centerPaddedTo:10 with:$. |
|
5213 |
(Float pi printString) centerPaddedTo:15 with:(Character space) |
|
5214 |
(Float pi printString) centerPaddedTo:15 with:$- |
|
5215 |
(' ' , Float pi class name) centerPaddedTo:15 with:$. |
|
5216 |
" |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5217 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5218 |
|
9190 | 5219 |
decimalPaddedTo:size and:afterPeriod at:decimalCharacter |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5220 |
"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
|
5221 |
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
|
5222 |
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
|
5223 |
to be padded). |
19464 | 5224 |
If the receiver's size is equal or greater than the length argument, |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5225 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5226 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5227 |
|
8874 | 5228 |
^ self |
19464 | 5229 |
decimalPaddedTo:size |
5230 |
and:afterPeriod |
|
5231 |
at:decimalCharacter |
|
5232 |
withLeft:(Character space) |
|
5233 |
right:$0 |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5234 |
|
8874 | 5235 |
" |
5236 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123 ' |
|
5237 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
|
5238 |
'123.' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5239 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.100' |
8874 | 5240 |
'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
|
5241 |
'123.123' decimalPaddedTo:10 and:3 at:$. -> ' 123.123' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5242 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5243 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5244 |
"Created: 23.12.1995 / 13:11:52 / cg" |
9192 | 5245 |
! |
5246 |
||
5247 |
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
|
5248 |
"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
|
5249 |
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
|
5250 |
of the period. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5251 |
Characters on the left are filled with leftPadChar. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5252 |
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
|
5253 |
otherwise, if missing, a decimal point is added and right characters filled with this. |
19464 | 5254 |
If the receiver's size is equal or greater than the length argument, |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5255 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5256 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5257 |
|
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
5258 |
|s idx n rest| |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5259 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5260 |
idx := self indexOf:decimalCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5261 |
idx == 0 ifTrue:[ |
19464 | 5262 |
"/ |
5263 |
"/ no decimal point found; adjust string to the left of the period column |
|
5264 |
"/ |
|
5265 |
rightPadChar isNil ifTrue:[ |
|
5266 |
s := self , (self species new:afterPeriod + 1 withAll:leftPadChar) |
|
5267 |
] ifFalse:[ |
|
5268 |
s:= self , decimalCharacter asString , (self species new:afterPeriod withAll:rightPadChar). |
|
5269 |
]. |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5270 |
] ifFalse:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5271 |
|
19464 | 5272 |
"/ the number of after-decimalPoint characters |
5273 |
n := self size - idx. |
|
5274 |
rest := afterPeriod - n. |
|
5275 |
rest > 0 ifTrue:[ |
|
5276 |
s := (self species new:rest withAll:(rightPadChar ? leftPadChar)). |
|
5277 |
] ifFalse:[ |
|
5278 |
s := '' |
|
5279 |
]. |
|
5280 |
s := self , s. |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5281 |
]. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5282 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5283 |
^ s leftPaddedTo:size with:leftPadChar |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5284 |
|
8874 | 5285 |
" |
5286 |
'123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:nil -> ' 123 ' |
|
5287 |
'123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.000' |
|
5288 |
'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
|
5289 |
'123.1' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.100' |
8874 | 5290 |
'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
|
5291 |
'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
|
5292 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5293 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5294 |
"Modified: 23.12.1995 / 13:08:18 / cg" |
9192 | 5295 |
! |
5296 |
||
5297 |
leftPaddedTo:size |
|
5298 |
"return a new string of length size, which contains the receiver |
|
5299 |
right-adjusted (i.e. padded on the left). |
|
5300 |
Characters on the left are filled with spaces. |
|
19464 | 5301 |
If the receiver's size is equal or greater than the length argument, |
9192 | 5302 |
the original receiver is returned unchanged." |
5303 |
||
5304 |
^ self leftPaddedTo:size with:(Character space) |
|
5305 |
||
5306 |
" |
|
5307 |
'foo' leftPaddedTo:10 |
|
5308 |
'fooBar' leftPaddedTo:5 |
|
5309 |
123 printString leftPaddedTo:10 |
|
5310 |
" |
|
5311 |
! |
|
608 | 5312 |
|
5313 |
paddedTo:newSize |
|
5314 |
"return a new string consisting of the receivers characters, |
|
5315 |
plus spaces up to length. |
|
19464 | 5316 |
If the receiver's size is equal or greater than the length argument, |
608 | 5317 |
the original receiver is returned unchanged." |
5318 |
||
5319 |
^ self paddedTo:newSize with:(Character space) |
|
5320 |
||
5321 |
" |
|
8874 | 5322 |
'foo' paddedTo:10 |
5323 |
123 printString paddedTo:10 |
|
15734 | 5324 |
'12345678901234' paddedTo:10 |
608 | 5325 |
" |
64 | 5326 |
! ! |
5327 |
||
9192 | 5328 |
!CharacterArray methodsFor:'printing & storing'! |
608 | 5329 |
|
5330 |
article |
|
17137 | 5331 |
"return an article string for the receiver. |
5332 |
The original code only looked at the first character being a vowel; |
|
5333 |
this has been enhanced by some heuristics - not perfect, still." |
|
608 | 5334 |
|
17241 | 5335 |
|firstChar secondChar thirdChar| |
608 | 5336 |
|
8874 | 5337 |
firstChar := (self at:1) asLowercase. |
5848 | 5338 |
((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
|
5339 |
^ 'an' |
608 | 5340 |
]. |
17043 | 5341 |
|
5342 |
(self size >= 3) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5343 |
secondChar := (self at:2) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5344 |
thirdChar := (self at:3) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5345 |
(firstChar isVowel not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5346 |
and:[(secondChar isVowel or:[secondChar == $y]) not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5347 |
and:[thirdChar isVowel not ]]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5348 |
"/ 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
|
5349 |
(self size > 4) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5350 |
(firstChar == $s) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5351 |
((secondChar == $c and:[thirdChar == $r]) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5352 |
or:[ (secondChar == $t and:[thirdChar == $r]) ]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5353 |
(self at:4) isVowel ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5354 |
^ 'a' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5355 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5356 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5357 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5358 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5359 |
"/ an abbreviation; treat x, s as vowels |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5360 |
(firstChar == $x or:[ firstChar == $s ]) ifTrue:[^ 'an']. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5361 |
] |
17043 | 5362 |
]. |
608 | 5363 |
^ 'a' |
5848 | 5364 |
|
5365 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5366 |
'uboot' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5367 |
'xmas' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5368 |
'alarm' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5369 |
'baby' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5370 |
'sql' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5371 |
'scr' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5372 |
'screen' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5373 |
'scrollbar' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5374 |
'scrs' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5375 |
'cvs' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5376 |
'cvssource' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5377 |
'symbol' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5378 |
'string' article. |
5848 | 5379 |
" |
608 | 5380 |
! |
5381 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5382 |
basicStoreString |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5383 |
"return a String for storing myself" |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5384 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5385 |
|s n index| |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5386 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5387 |
n := self occurrencesOf:$'. |
11320 | 5388 |
n ~~ 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5389 |
s := self species new:(n + 2 + self size). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5390 |
s at:1 put:$'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5391 |
index := 2. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5392 |
self do:[:thisChar | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5393 |
(thisChar == $') ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5394 |
s at:index put:thisChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5395 |
index := index + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5396 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5397 |
s at:index put:thisChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5398 |
index := index + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5399 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5400 |
s at:index put:$'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5401 |
^ s |
9192 | 5402 |
]. |
11320 | 5403 |
|
9192 | 5404 |
^ '''' , self , '''' |
15523 | 5405 |
|
5406 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5407 |
'''immutable'' string' asImmutableString basicStoreString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5408 |
'immutable string' asImmutableString basicStoreString |
15523 | 5409 |
" |
5410 |
||
5411 |
"Modified: / 14-07-2013 / 19:20:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
9192 | 5412 |
! |
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5413 |
|
11774
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5414 |
displayOn:aGCOrStream |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5415 |
"Compatibility |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5416 |
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
|
5417 |
OR: |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5418 |
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
|
5419 |
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
|
5420 |
(although the fallBack is to display its printString ...)" |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5421 |
|
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5422 |
"/ 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
|
5423 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
16738 | 5424 |
(aGCOrStream isStream) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5425 |
self storeOn:aGCOrStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5426 |
^ self |
11774
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5427 |
]. |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5428 |
^ super displayOn:aGCOrStream |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5429 |
! |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5430 |
|
608 | 5431 |
printOn:aStream |
5432 |
"print the receiver on aStream" |
|
5433 |
||
5434 |
aStream nextPutAll:self |
|
5435 |
! |
|
5436 |
||
5437 |
printString |
|
13079
111e7e456648
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
13073
diff
changeset
|
5438 |
"return a string for printing - that's myself" |
608 | 5439 |
|
5440 |
^ self |
|
3578 | 5441 |
! |
5442 |
||
5443 |
printWithQuotesDoubledOn:aStream |
|
5444 |
"put the raw storeString of myself on aStream" |
|
5445 |
||
5446 |
self do:[:thisChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5447 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5448 |
aStream nextPut:thisChar |
3578 | 5449 |
] |
5450 |
||
5451 |
"Modified: / 15.6.1998 / 17:21:17 / cg" |
|
5452 |
"Created: / 15.6.1998 / 17:22:13 / cg" |
|
12171 | 5453 |
! |
5454 |
||
15788 | 5455 |
printXmlQuotedOn:aStream |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5456 |
"convert aString to a valid XML string |
15788 | 5457 |
that can be used for attributes, text, comments an PIs |
5458 |
TODO: care for 16bit UNICODE string and escape chars ..." |
|
5459 |
||
5460 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5461 |
eachChar == $< ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5462 |
aStream nextPutAll:'<' "mapping needed for xml text" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5463 |
] ifFalse:[ eachChar == $& ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5464 |
aStream nextPutAll:'&' "mapping needed for all" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5465 |
] ifFalse:[ eachChar == $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5466 |
aStream nextPutAll:'>' "mapping needed for comments" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5467 |
] ifFalse:[ eachChar == $' ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5468 |
aStream nextPutAll:''' "mapping needed for attributes" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5469 |
] ifFalse:[ eachChar == $" ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5470 |
aStream nextPutAll:'"' "mapping needed for attributes" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5471 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5472 |
|codePoint| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5473 |
codePoint := eachChar codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5474 |
(codePoint < 16r20 or:[codePoint >= 16r7F]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5475 |
aStream nextPutAll:'&#'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5476 |
codePoint printOn:aStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5477 |
aStream nextPut:$;. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5478 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5479 |
aStream nextPut:eachChar |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5480 |
]]]]]] |
15788 | 5481 |
]. |
5482 |
! |
|
5483 |
||
5484 |
printXmlTextQuotedOn:aStream |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5485 |
"convert aString to a valid XML string |
15788 | 5486 |
that can be used for XML text. |
5487 |
Here line formatting characters are not escaped. |
|
5488 |
TODO: care for 16bit UNICODE string and escape chars ..." |
|
5489 |
||
5490 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5491 |
eachChar == $< ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5492 |
aStream nextPutAll:'<' "mapping needed for xml text" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5493 |
] ifFalse:[ eachChar == $& ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5494 |
aStream nextPutAll:'&' "mapping needed for all" |
15788 | 5495 |
"/ ] ifFalse:[ eachChar == $> ifTrue:[ |
5496 |
"/ aStream nextPutAll:'>' "mapping needed for comments" |
|
5497 |
"/ ] ifFalse:[ eachChar == $' ifTrue:[ |
|
5498 |
"/ aStream nextPutAll:''' "mapping needed for attributes" |
|
5499 |
"/ ] ifFalse:[ eachChar == $" ifTrue:[ |
|
5500 |
"/ aStream nextPutAll:'"' "mapping needed for attributes" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5501 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5502 |
|codePoint| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5503 |
codePoint := eachChar codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5504 |
((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
|
5505 |
or:[codePoint >= 16r7F]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5506 |
aStream nextPutAll:'&#'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5507 |
codePoint printOn:aStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5508 |
aStream nextPut:$;. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5509 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5510 |
aStream nextPut:eachChar |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5511 |
]]]"/]]] |
15788 | 5512 |
]. |
5513 |
! |
|
5514 |
||
12171 | 5515 |
printfWith:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
12177 | 5516 |
"Format and print the receiver with <argI> formatted in C style, |
12171 | 5517 |
as specified in the Unix C-language manual page for printf(3). |
15712 | 5518 |
Return the resulting string (i.e actually, this is more like an sprintf)." |
12177 | 5519 |
|
12171 | 5520 |
^ self printf:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
5521 |
||
5522 |
" |
|
12177 | 5523 |
Transcript showCR:('%d %05x %08o %b' printfWith:123 with:234 with:345 with:123) |
12171 | 5524 |
" |
15788 | 5525 |
! |
5526 |
||
5527 |
xmlQuotedPrintString |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5528 |
"convert aString to a valid XML string |
15788 | 5529 |
that can be used for attributes, text, comments an PIs |
5530 |
TODO: care for 16bit UNICODE string and escape chars ..." |
|
5531 |
||
5532 |
^ String streamContents:[:s| |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5533 |
self printXmlQuotedOn:s |
15788 | 5534 |
]. |
9192 | 5535 |
! ! |
5536 |
||
11955 | 5537 |
|
9192 | 5538 |
!CharacterArray methodsFor:'queries'! |
608 | 5539 |
|
4429 | 5540 |
bitsPerCharacter |
18662 | 5541 |
"return the underlying string's bitsPerCharacter |
4429 | 5542 |
(i.e. is it a regular String or a TwoByteString)" |
5543 |
||
8457 | 5544 |
|string max| |
5545 |
||
5546 |
(string := self string) ~~ self ifTrue:[ |
|
18662 | 5547 |
^ string bitsPerCharacter |
8457 | 5548 |
]. |
5549 |
||
5550 |
max := 8. |
|
5551 |
self do:[:eachCharacter | |
|
18662 | 5552 |
max := max max:(eachCharacter bitsPerCharacter) |
9192 | 5553 |
]. |
5554 |
^ max |
|
5555 |
||
5556 |
" |
|
5557 |
'hello' bitsPerCharacter |
|
5558 |
'hello' asText allBold bitsPerCharacter |
|
5559 |
" |
|
5560 |
! |
|
8457 | 5561 |
|
18967 | 5562 |
containsNon8BitElements |
5563 |
"return true, if the underlying string contains elements larger than a single byte" |
|
5564 |
||
5565 |
|sz "{ Class:SmallInteger }"| |
|
5566 |
||
5567 |
sz := self size. |
|
5568 |
1 to:sz do:[:idx| |
|
5569 |
(self at:idx) codePoint > 16rFF ifTrue:[ |
|
5570 |
^ true. |
|
5571 |
]. |
|
5572 |
]. |
|
5573 |
^ false. |
|
5574 |
! |
|
5575 |
||
10903 | 5576 |
continuesWith:aString startingAt:startIndex |
5577 |
"return true, if the receiver beginning at startIndex |
|
5578 |
contains the characters in aString." |
|
5579 |
||
5580 |
|sz "{Class: SmallInteger }" |
|
5581 |
idx "{Class: SmallInteger }"| |
|
5582 |
||
5583 |
sz := aString size. |
|
5584 |
idx := startIndex. |
|
5585 |
||
5586 |
1 to:sz do:[:i | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5587 |
(self at:idx) ~~ (aString at:i) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5588 |
idx := idx + 1 |
10903 | 5589 |
]. |
5590 |
^ true |
|
5591 |
||
5592 |
" |
|
5593 |
'hello world' continuesWith:'world' startingAt:6 |
|
5594 |
'hello world' continuesWith:'world' startingAt:7 |
|
5595 |
" |
|
5596 |
||
5597 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
5598 |
"Modified: 26.7.1996 / 19:08:36 / cg" |
|
5599 |
! |
|
5600 |
||
5601 |
countWords |
|
5602 |
"return the number of words, which are separated by separators" |
|
5603 |
||
5604 |
|tally "{ Class: SmallInteger }" |
|
5605 |
start "{ Class: SmallInteger }" |
|
5606 |
mySize "{ Class: SmallInteger }" |
|
5607 |
stop ch| |
|
5608 |
||
5609 |
tally := 0. |
|
5610 |
start := 1. |
|
5611 |
mySize := self size. |
|
5612 |
[start <= mySize] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5613 |
ch := self at:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5614 |
ch isSeparator ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5615 |
start := start + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5616 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5617 |
stop := self indexOfSeparatorStartingAt:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5618 |
(stop == 0) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5619 |
stop := mySize + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5620 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5621 |
tally := tally + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5622 |
start := stop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5623 |
] |
10903 | 5624 |
]. |
5625 |
^ tally |
|
5626 |
||
5627 |
" |
|
5628 |
'hello world isnt this nice' countWords' |
|
5629 |
" |
|
5630 |
! |
|
5631 |
||
11788 | 5632 |
defaultElement |
5633 |
^ Character space |
|
5634 |
! |
|
5635 |
||
608 | 5636 |
encoding |
1311 | 5637 |
"return the strings encoding, as a symbol. |
7982 | 5638 |
Here, by default, we assume unicode-encoding. |
5639 |
Notice, that iso8859-1 is a true subset of unicode, |
|
8874 | 5640 |
and that singleByteStrings are therefore both unicode AND |
7982 | 5641 |
8859-1 encoded." |
5642 |
||
14168 | 5643 |
^ #unicode |
608 | 5644 |
! |
5645 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5646 |
hasChangeOfEmphasis |
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
5647 |
"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
|
5648 |
i.e. any non-normal (=emphasized) characters" |
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
5649 |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5650 |
^ false |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5651 |
|
1381 | 5652 |
"Created: 12.5.1996 / 12:31:39 / cg" |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5653 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5654 |
|
7995
8ddbb403d67b
+hasIcon and hasImage for LabelAndIcon compatibility
Claus Gittinger <cg@exept.de>
parents:
7991
diff
changeset
|
5655 |
hasIcon |
9191 | 5656 |
"for LabelAndIcon compatibility" |
5657 |
||
9192 | 5658 |
^ false |
5659 |
! |
|
5660 |
||
5661 |
hasImage |
|
5662 |
"for LabelAndIcon compatibility" |
|
5663 |
||
5664 |
^ false |
|
5665 |
! |
|
7995
8ddbb403d67b
+hasIcon and hasImage for LabelAndIcon compatibility
Claus Gittinger <cg@exept.de>
parents:
7991
diff
changeset
|
5666 |
|
1388 | 5667 |
heightOn:aGC |
19464 | 5668 |
"return the size of the receiver in device units if displayed on aGC" |
1388 | 5669 |
|
6528 | 5670 |
^ (aGC font onDevice:aGC device) heightOf:self |
1388 | 5671 |
|
5672 |
" |
|
8874 | 5673 |
'hello world' heightOn:(View new) |
1388 | 5674 |
" |
5675 |
||
5676 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
5677 |
"Modified: 12.5.1996 / 20:32:05 / cg" |
|
5678 |
! |
|
5679 |
||
15773 | 5680 |
isKeyword |
5681 |
"return true, if the receiver is a keyword message selector" |
|
5682 |
||
5683 |
^ self includes:$: |
|
5684 |
||
5685 |
" |
|
5686 |
#at:put: isKeyword |
|
5687 |
#at: isKeyword |
|
5688 |
#+ isKeyword |
|
5689 |
#size isKeyword |
|
5690 |
" |
|
5691 |
||
5692 |
"Created: / 1.11.1997 / 12:34:55 / cg" |
|
5693 |
"Modified: / 1.11.1997 / 12:36:37 / cg" |
|
5694 |
! |
|
5695 |
||
11828 | 5696 |
isLowercaseFirst |
5697 |
"return true, if the first character is a lowercase character." |
|
5698 |
||
5699 |
^ self size ~~ 0 and:[ self first isLowercase ] |
|
5700 |
||
5701 |
" |
|
12177 | 5702 |
'helloWorld' isLowercaseFirst |
5703 |
'HelloWorld' isLowercaseFirst |
|
11828 | 5704 |
" |
5705 |
! |
|
5706 |
||
5707 |
isUppercaseFirst |
|
5708 |
"return true, if the first character is an uppercase character." |
|
5709 |
||
5710 |
^ self size ~~ 0 and:[ self first isUppercase ] |
|
5711 |
||
5712 |
" |
|
12177 | 5713 |
'helloWorld' isUppercaseFirst |
5714 |
'HelloWorld' isUppercaseFirst |
|
11828 | 5715 |
" |
5716 |
! |
|
5717 |
||
15773 | 5718 |
keywords |
5719 |
"assuming the receiver is a keyword message selector, |
|
5720 |
return the individual keywords (i.e. break it up at colons) |
|
5721 |
and return these as a collection. |
|
5722 |
For binary and unary selectors, the result may be nonsense (an array containing the receiver)." |
|
5723 |
||
5724 |
|coll s part| |
|
5725 |
||
5726 |
coll := OrderedCollection new. |
|
5727 |
s := ReadStream on:self. |
|
5728 |
[s atEnd] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5729 |
part := s through:$:. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5730 |
coll add:part |
15773 | 5731 |
]. |
5732 |
^ coll asArray |
|
5733 |
||
5734 |
" |
|
5735 |
#at:put: keywords |
|
5736 |
#at: keywords |
|
5737 |
#+ keywords |
|
5738 |
#size keywords |
|
5739 |
" |
|
5740 |
||
5741 |
"Modified (Comment): / 30-06-2011 / 17:46:21 / cg" |
|
5742 |
! |
|
5743 |
||
9190 | 5744 |
knownAsSymbol |
5745 |
"for now, only single character strings are allowed as symbols. |
|
5746 |
This method is redefined in String." |
|
5747 |
||
5748 |
^ false |
|
5749 |
! |
|
5750 |
||
5751 |
leftIndent |
|
5752 |
"if the receiver starts with spaces, return the number of spaces |
|
5753 |
at the left - otherwise, return 0. |
|
19464 | 5754 |
If the receiver consists of spaces only, return the receiver's size." |
9192 | 5755 |
|
5756 |
|index "{Class: SmallInteger }" |
|
5757 |
end "{Class: SmallInteger }"| |
|
5758 |
||
5759 |
index := 1. |
|
5760 |
end := self size. |
|
5761 |
[index <= end] whileTrue:[ |
|
19464 | 5762 |
(self at:index) isSeparator ifFalse:[^ index - 1]. |
5763 |
index := index + 1 |
|
8350 | 5764 |
]. |
9192 | 5765 |
^ end |
5766 |
||
5767 |
" |
|
5768 |
' hello' leftIndent |
|
5769 |
'foo ' leftIndent |
|
9190 | 5770 |
' ' leftIndent |
5771 |
" |
|
5772 |
||
5773 |
"Modified: 20.4.1996 / 19:28:43 / cg" |
|
8350 | 5774 |
! |
5775 |
||
10437 | 5776 |
nameSpaceSelectorParts |
5777 |
"Answer the namespace and baseSelector parts of a namespace selector. |
|
5778 |
Namespace selectors are those generated by sends from a method in a different |
|
5779 |
namespace; they are prefixed by ':'<ns>'::'. |
|
5780 |
You cannot easily change this algorithm here, as it is also known by the VM's lookup function. |
|
5781 |
Experimental" |
|
5782 |
||
5783 |
|nsPart selPart idx| |
|
5784 |
||
5785 |
(self at:1) == $: ifFalse:[^ Array with:'' with:self]. |
|
5786 |
idx := self indexOf:$: startingAt:3. |
|
5787 |
idx == 0 ifTrue:[^ Array with:'' with:self]. |
|
5788 |
||
5789 |
(idx+2 > self size) ifTrue:[^ Array with:'' with:self]. |
|
5790 |
(self at:idx+1) == $: ifFalse:[^ Array with:'' with:self]. |
|
5791 |
nsPart := self copyFrom:2 to:idx-1. |
|
5792 |
selPart := self copyFrom:idx+2. |
|
5793 |
^ Array with:nsPart with:selPart |
|
5794 |
||
5795 |
"test: |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5796 |
self assert:('+' nameSpaceSelectorParts) = #('' '+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5797 |
self assert:(':+' nameSpaceSelectorParts) = #('' ':+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5798 |
self assert:(':Foo:+' nameSpaceSelectorParts) = #('' ':Foo:+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5799 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5800 |
self assert:(':Foo::+' nameSpaceSelectorParts) = #('Foo' '+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5801 |
self assert:(':Foo::bar:baz:' nameSpaceSelectorParts) = #('Foo' 'bar:baz:'). |
10437 | 5802 |
" |
5803 |
||
5804 |
"Created: / 05-03-2007 / 17:16:58 / cg" |
|
5805 |
"Modified: / 06-03-2007 / 11:51:15 / cg" |
|
5806 |
! |
|
5807 |
||
9190 | 5808 |
stringSpecies |
8874 | 5809 |
"return the underlying strings bitsPerCharacter |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5810 |
(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
|
5811 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5812 |
|string| |
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5813 |
|
15523 | 5814 |
string := self string. |
5815 |
string == self ifTrue:[^ self species]. |
|
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5816 |
^ string stringSpecies |
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5817 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5818 |
" |
8874 | 5819 |
'hello' stringSpecies |
9192 | 5820 |
'hello' asText allBold stringSpecies |
5821 |
" |
|
5822 |
! |
|
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5823 |
|
6653 | 5824 |
widthFrom:startIndex to:endIndex on:aGC |
19464 | 5825 |
"return ths size of part of the receiver in device units if displayed on aGC" |
6653 | 5826 |
|
5827 |
^ (aGC font onDevice:aGC device) widthOf:self from:startIndex to:endIndex |
|
5828 |
||
5829 |
" |
|
8874 | 5830 |
'hello world' widthFrom:1 to:5 on:(View new) |
5831 |
'hello' widthOn:(View new) |
|
6653 | 5832 |
" |
9192 | 5833 |
! |
6653 | 5834 |
|
1388 | 5835 |
widthOn:aGC |
19464 | 5836 |
"return ths size of the receiver in device units if displayed on aGC" |
1388 | 5837 |
|
6528 | 5838 |
^ (aGC font onDevice:aGC device) widthOf:self |
1388 | 5839 |
|
5840 |
" |
|
8874 | 5841 |
'hello world' widthOn:(View new) |
1388 | 5842 |
" |
5843 |
||
5844 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
2554 | 5845 |
"Modified: 17.4.1997 / 12:50:23 / cg" |
608 | 5846 |
! ! |
5847 |
||
19580 | 5848 |
|
608 | 5849 |
!CharacterArray methodsFor:'special string converting'! |
5850 |
||
16759 | 5851 |
asUnixFilenameString |
5852 |
"return a new string consisting of receiver's characters |
|
5853 |
with all \-characters replaced by /-characters. |
|
5854 |
If there are no backslashes, return the original" |
|
5855 |
||
5856 |
^ self copyReplaceAll:$\ with:$/ ifNone:self |
|
5857 |
||
5858 |
" |
|
5859 |
'hello\world' asUnixFilenameString |
|
5860 |
" |
|
5861 |
||
5862 |
"Modified: / 18.7.1998 / 22:53:02 / cg" |
|
5863 |
! |
|
5864 |
||
14768 | 5865 |
expandPlaceholders:escapeCharacter with:argArrayOrDictionary |
5866 |
"this is the generic version of the old %-escaping method, allowing for an arbitrary |
|
5867 |
escape character to be used (typically $$ or $% are effectively used). |
|
5868 |
Return a copy of the receiver, where all %i escapes are |
|
5869 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
|
5870 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
|
5871 |
in the new string 'hello world; how is this'. |
|
5872 |
As an extension, the argument may also be a dictionary, providing |
|
5873 |
values for symbolic keys. |
|
5874 |
In this case, %a .. %z and %(...) are also allowed. |
|
5875 |
(%1..%9 require a numeric key in the dictionary, however) |
|
5876 |
To get a '%' character, use a '%%'-escape. |
|
5877 |
To get an integer-indexed placeHolder followed by another digit, |
|
5878 |
or an index > 9, you must use %(digit). |
|
5879 |
See also bindWith:... for VisualAge compatibility." |
|
5880 |
||
5881 |
|stream| |
|
5882 |
||
18269 | 5883 |
stream := (TextStream ? CharacterWriteStream) on:(self species uninitializedNew:self size + 20). |
14768 | 5884 |
self expandPlaceholders:escapeCharacter with:argArrayOrDictionary on:stream. |
5885 |
^ stream contents. |
|
5886 |
||
5887 |
||
5888 |
" |
|
5889 |
'hello %1' expandPlaceholdersWith:#('world') |
|
5890 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
5891 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
5892 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
|
5893 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) |
|
5894 |
'%%10 gives %10' expandPlaceholdersWith:#(123) |
|
5895 |
'%%(10) gives %(10)' expandPlaceholdersWith:#(123) |
|
5896 |
'%test gives %1' expandPlaceholdersWith:#(123) |
|
5897 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' allBold } |
|
5898 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' } |
|
5899 |
" |
|
5900 |
||
5901 |
" |
|
5902 |
|dict| |
|
5903 |
||
5904 |
dict := Dictionary new. |
|
5905 |
dict at:1 put:'one'. |
|
5906 |
dict at:$a put:'AAAAA'. |
|
5907 |
dict at:$b put:[ Time now ]. |
|
5908 |
dict at:'foo' put:[ Date today ]. |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5909 |
'hello $1 %a $b %(foo) $foo ' expandPlaceholders:$$ with:dict. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5910 |
'hello $1 %a $b %(foo) $foo ' expandPlaceholders:$% with:dict. |
14768 | 5911 |
" |
5912 |
||
5913 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
|
5914 |
! |
|
5915 |
||
14765 | 5916 |
expandPlaceholders:escapeCharacter with:argArrayOrDictionary on:aStream |
5917 |
"this is the generic version of the old %-escaping method, allowing for an arbitrary |
|
5918 |
escape character to be used (typically $$ or $% are effectively used). |
|
18425 | 5919 |
|
14765 | 5920 |
Write the receiver to aStream, where all %i escapes are |
5921 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
|
5922 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
|
5923 |
in the new string 'hello world; how is this'. |
|
18425 | 5924 |
|
17192 | 5925 |
As an extension, the argument may also be a dictionary, providing values for symbolic keys. |
14765 | 5926 |
In this case, %a .. %z and %(...) are also allowed. |
5927 |
(%1..%9 require a numeric key in the dictionary, however) |
|
17192 | 5928 |
Also, the values in argArrayOrDictionary may be blocks. |
18425 | 5929 |
|
14765 | 5930 |
To get a '%' character, use a '%%'-escape. |
5931 |
To get an integer-indexed placeHolder followed by another digit, |
|
5932 |
or an index > 9, you must use %(digit). |
|
18425 | 5933 |
|
14765 | 5934 |
See also bindWith:... for VisualAge compatibility. |
5935 |
Use %<cr> to insert a CR and %<tab> to insert a TAB." |
|
5936 |
||
5937 |
|next v key |
|
5938 |
idx "{ SmallInteger }" |
|
5939 |
idx2 "{ SmallInteger }" |
|
5940 |
start "{ SmallInteger }" |
|
5941 |
stop "{ SmallInteger }"| |
|
5942 |
||
5943 |
stop := self size. |
|
5944 |
start := 1. |
|
5945 |
[start <= stop] whileTrue:[ |
|
18425 | 5946 |
idx := self indexOf:escapeCharacter startingAt:start. |
5947 |
(idx == 0 or:[idx == stop]) ifTrue:[ |
|
5948 |
aStream nextPutAll:self startingAt:start to:stop. |
|
5949 |
^ self. |
|
5950 |
]. |
|
5951 |
"found an escapeCharacter" |
|
5952 |
aStream nextPutAll:self startingAt:start to:(idx - 1). |
|
5953 |
next := self at:(idx + 1). |
|
5954 |
(next == escapeCharacter) ifTrue:[ |
|
5955 |
aStream nextPut:escapeCharacter. |
|
5956 |
] ifFalse:[ |
|
5957 |
next == $< ifTrue:[ |
|
5958 |
idx2 := self indexOf:$> startingAt:idx+2. |
|
5959 |
key := self copyFrom:idx+2 to:idx2-1. |
|
5960 |
idx := idx2 - 1. |
|
5961 |
key := key asSymbolIfInterned. |
|
5962 |
(#(cr tab nl return lf ff null) includesIdentical:key) ifTrue:[ |
|
5963 |
aStream nextPut:(Character perform:key). |
|
5964 |
]. |
|
5965 |
] ifFalse:[ |
|
5966 |
next isDigit ifTrue:[ |
|
5967 |
v := argArrayOrDictionary at:(next digitValue) ifAbsent:'' |
|
5968 |
] ifFalse:[ |
|
5969 |
next == $( ifTrue:[ |
|
5970 |
idx2 := self indexOf:$) startingAt:idx+2. |
|
5971 |
key := self copyFrom:idx+2 to:idx2-1. |
|
5972 |
idx := idx2 - 1. |
|
5973 |
(argArrayOrDictionary includesKey:key) ifTrue:[ |
|
5974 |
v := argArrayOrDictionary at:key |
|
5975 |
] ifFalse:[ |
|
5976 |
key := key asSymbolIfInterned ? key. |
|
5977 |
(argArrayOrDictionary includesKey:key) ifTrue:[ |
|
5978 |
v := argArrayOrDictionary at:key |
|
5979 |
] ifFalse:[ |
|
5980 |
(key size == 1 and:[ argArrayOrDictionary includesKey:(key at:1)]) ifTrue:[ |
|
5981 |
v := argArrayOrDictionary at:(key at:1) |
|
5982 |
] ifFalse:[ |
|
5983 |
key isNumeric ifTrue:[ |
|
5984 |
key := Integer readFrom:key onError:nil. |
|
5985 |
]. |
|
5986 |
v := argArrayOrDictionary at:key ifAbsent:'' |
|
5987 |
] |
|
5988 |
]. |
|
5989 |
]. |
|
5990 |
] ifFalse:[ |
|
5991 |
(next isLetter and:[argArrayOrDictionary isSequenceable not "is a Dictionary"]) ifTrue:[ |
|
5992 |
"so next is a non-numeric single character." |
|
5993 |
v := argArrayOrDictionary |
|
5994 |
at:next |
|
5995 |
ifAbsent:[ |
|
5996 |
"try symbol instead of character" |
|
5997 |
argArrayOrDictionary |
|
5998 |
at:next asSymbol |
|
5999 |
ifAbsent:[String with:escapeCharacter with:next]. |
|
6000 |
]. |
|
6001 |
] ifFalse:[ |
|
6002 |
v := String with:$% with:next. |
|
6003 |
]. |
|
6004 |
] |
|
6005 |
]. |
|
6006 |
"/ v notNil ifTrue:[ |
|
6007 |
v isBlock ifTrue:[ |
|
6008 |
v := v value |
|
6009 |
]. |
|
6010 |
||
6011 |
v printOn:aStream. |
|
6012 |
"/ ]. |
|
6013 |
] |
|
6014 |
]. |
|
6015 |
start := idx + 2 |
|
14765 | 6016 |
]. |
6017 |
||
6018 |
" |
|
6019 |
String streamContents:[:s| |
|
18425 | 6020 |
'hello %1' expandPlaceholders:$% with:#('world') on:s. |
6021 |
s cr. |
|
6022 |
'hello $1; how is $2' expandPlaceholders:$$ with:#('world' 'this') on:s. |
|
6023 |
s cr. |
|
6024 |
'hello %2; how is %1' expandPlaceholders:$% with:#('world' 'this') on:s. |
|
6025 |
s cr. |
|
6026 |
'%1 plus %2 gives %3 ' expandPlaceholders:$% with:#(4 5 9) on:s. |
|
6027 |
s cr. |
|
6028 |
'%%(1)0 gives %(1)0' expandPlaceholders:$% with:#(123) on:s. |
|
6029 |
s cr. |
|
6030 |
'%%10 gives %10' expandPlaceholders:$% with:#(123) on:s. |
|
6031 |
s cr. |
|
6032 |
'%%(10) gives %(10) %<cr>%<tab>next line' expandPlaceholders:$% with:#(123) on:s. |
|
6033 |
s cr. |
|
6034 |
'%%test gives %test' expandPlaceholders:$% with:#(123) on:s. |
|
6035 |
s cr. |
|
6036 |
'|%%<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
|
6037 |
] |
14765 | 6038 |
" |
6039 |
||
6040 |
" |
|
6041 |
|dict| |
|
6042 |
||
6043 |
dict := Dictionary new. |
|
6044 |
dict at:1 put:'one'. |
|
6045 |
dict at:$a put:'AAAAA'. |
|
6046 |
dict at:$b put:[ Time now ]. |
|
6047 |
String streamContents:[:s| |
|
18425 | 6048 |
'hello $1 $a $b' expandPlaceholders:$$ with:dict on:s. |
14765 | 6049 |
]. |
6050 |
" |
|
6051 |
||
18425 | 6052 |
"using blocks: |
6053 |
|dict| |
|
6054 |
||
6055 |
dict := Dictionary new. |
|
6056 |
dict at:'time' put:[Time now printString]. |
|
6057 |
dict at:'date' put:[Date today printString]. |
|
6058 |
String streamContents:[:s| |
|
6059 |
'it is $(time) $(date)' expandPlaceholders:$$ with:dict on:s. |
|
6060 |
]. |
|
6061 |
" |
|
6062 |
||
14765 | 6063 |
"Modified: / 18-11-2010 / 15:43:28 / cg" |
6064 |
! |
|
6065 |
||
9192 | 6066 |
expandPlaceholdersWith:argArrayOrDictionary |
608 | 6067 |
"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
|
6068 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
608 | 6069 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
6070 |
in the new string 'hello world; how is this'. |
|
18425 | 6071 |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6072 |
As an extension, the argument may also be a dictionary, providing |
7313 | 6073 |
values for symbolic keys. |
4842 | 6074 |
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
|
6075 |
(%1..%9 require a numeric key in the dictionary, however) |
18425 | 6076 |
Also, the values in argArrayOrDictionary may be blocks. |
6077 |
||
608 | 6078 |
To get a '%' character, use a '%%'-escape. |
7313 | 6079 |
To get an integer-indexed placeHolder followed by another digit, |
6080 |
or an index > 9, you must use %(digit). |
|
608 | 6081 |
See also bindWith:... for VisualAge compatibility." |
6082 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6083 |
|stream| |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6084 |
|
18269 | 6085 |
stream := (TextStream ? CharacterWriteStream) on:(self species uninitializedNew:self size + 20). |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6086 |
self expandPlaceholdersWith:argArrayOrDictionary on:stream. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6087 |
^ stream contents. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6088 |
|
608 | 6089 |
|
6090 |
" |
|
8874 | 6091 |
'hello %1' expandPlaceholdersWith:#('world') |
6092 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
6093 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
6094 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
|
6095 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) |
|
6096 |
'%%10 gives %10' expandPlaceholdersWith:#(123) |
|
6097 |
'%%(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
|
6098 |
'%test gives %1' expandPlaceholdersWith:#(123) |
11028
cb1ee3ddd91a
expandPlaceHolders: care fr Text with emphasis
Claus Gittinger <cg@exept.de>
parents:
11018
diff
changeset
|
6099 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' allBold } |
cb1ee3ddd91a
expandPlaceHolders: care fr Text with emphasis
Claus Gittinger <cg@exept.de>
parents:
11018
diff
changeset
|
6100 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' } |
608 | 6101 |
" |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
6102 |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6103 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6104 |
|dict| |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6105 |
|
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6106 |
dict := Dictionary new. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6107 |
dict at:1 put:'one'. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6108 |
dict at:$a put:'AAAAA'. |
8794
a5df33935142
nindWith supports blocks in the value dictionary
Claus Gittinger <cg@exept.de>
parents:
8710
diff
changeset
|
6109 |
dict at:$b put:[ Time now ]. |
12316
3e78905d70a9
comment/format in: #expandPlaceholdersWith:
Claus Gittinger <cg@exept.de>
parents:
12196
diff
changeset
|
6110 |
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
|
6111 |
'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
|
6112 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6113 |
|
2737
9f29aecea39d
care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents:
2736
diff
changeset
|
6114 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
9192 | 6115 |
! |
6116 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6117 |
expandPlaceholdersWith:argArrayOrDictionary on:aStream |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6118 |
"write the receiver to aStream, where all %i escapes are |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6119 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6120 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6121 |
in the new string 'hello world; how is this'. |
18425 | 6122 |
|
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6123 |
As an extension, the argument may also be a dictionary, providing |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6124 |
values for symbolic keys. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6125 |
In this case, %a .. %z and %(...) are also allowed. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6126 |
(%1..%9 require a numeric key in the dictionary, however) |
18425 | 6127 |
Also, the values in argArrayOrDictionary may be blocks. |
6128 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6129 |
To get a '%' character, use a '%%'-escape. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6130 |
To get an integer-indexed placeHolder followed by another digit, |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6131 |
or an index > 9, you must use %(digit). |
18425 | 6132 |
|
10935 | 6133 |
See also bindWith:... for VisualAge compatibility. |
10939
d0ca31c1d1e9
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10935
diff
changeset
|
6134 |
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
|
6135 |
|
14765 | 6136 |
^ self expandPlaceholders:$% with:argArrayOrDictionary on:aStream |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6137 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6138 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6139 |
String streamContents:[:s| |
18425 | 6140 |
'hello %1' expandPlaceholdersWith:#('world') on:s. |
6141 |
s cr. |
|
6142 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') on:s. |
|
6143 |
s cr. |
|
6144 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') on:s. |
|
6145 |
s cr. |
|
6146 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) on:s. |
|
6147 |
s cr. |
|
6148 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) on:s. |
|
6149 |
s cr. |
|
6150 |
'%%10 gives %10' expandPlaceholdersWith:#(123) on:s. |
|
6151 |
s cr. |
|
6152 |
'%%(10) gives %(10) %<cr>%<tab>next line' expandPlaceholdersWith:#(123) on:s. |
|
6153 |
s cr. |
|
6154 |
'%test gives %1' expandPlaceholdersWith:#(123) on:s. |
|
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6155 |
] |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6156 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6157 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6158 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6159 |
|dict| |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6160 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6161 |
dict := Dictionary new. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6162 |
dict at:1 put:'one'. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6163 |
dict at:$a put:'AAAAA'. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6164 |
dict at:$b put:[ Time now ]. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6165 |
String streamContents:[:s| |
18425 | 6166 |
'hello %1 %a %b' expandPlaceholdersWith:dict on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6167 |
]. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6168 |
" |
13008
a27647c36b31
changed: #expandPlaceholdersWith:on:
Claus Gittinger <cg@exept.de>
parents:
12925
diff
changeset
|
6169 |
|
13138
d2eb0eba5907
changed: #expandPlaceholdersWith:on:
Claus Gittinger <cg@exept.de>
parents:
13137
diff
changeset
|
6170 |
"Modified: / 18-11-2010 / 15:43:28 / cg" |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6171 |
! |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6172 |
|
9230 | 6173 |
firstLine |
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6174 |
"return the first line of a multiline string" |
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6175 |
|
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6176 |
^ self asCollectionOfSubCollectionsSeparatedBy:(Character cr) do:[:line | ^ line]. |
9230 | 6177 |
|
6178 |
" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6179 |
'hello' firstLine |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6180 |
'1\2\3' withCRs firstLine |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6181 |
'\1\2\3' withCRs firstLine |
9230 | 6182 |
" |
6183 |
! |
|
6184 |
||
13987 | 6185 |
tokensBasedOn:aCharacter |
6186 |
"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
|
6187 |
asCollectionOfSubstringsSeparatedBy:" |
13987 | 6188 |
|
6189 |
^ self asCollectionOfSubstringsSeparatedBy:aCharacter |
|
6190 |
||
6191 |
" |
|
6192 |
'hello:world:isnt:this nice' tokensBasedOn:$: |
|
6193 |
'foo,bar,baz' tokensBasedOn:$, |
|
6194 |
'/etc/passwd' asFilename readStream nextLine tokensBasedOn:$: |
|
6195 |
" |
|
6196 |
! |
|
6197 |
||
6198 |
withCEscapes |
|
16863 | 6199 |
"return a new string consisting of receiver's characters |
13987 | 6200 |
with all special and unprintable characters replaced by \X-character escapes. |
6201 |
(similar to the way C-language literal Strings are represented). |
|
6202 |
The resulting string will contain only 7-bit ascii characters. |
|
6203 |
Emphasis is not supported. |
|
6204 |
The following escapes are generated: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6205 |
\' single quote character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6206 |
\dQuote double quote character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6207 |
\r return character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6208 |
\r return character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6209 |
\n newline character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6210 |
\t tab character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6211 |
\\ the \ character itself |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6212 |
\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
|
6213 |
\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
|
6214 |
\Unnnnnnnn eight digit hex number defining the characters ascii value |
16863 | 6215 |
This is the opposite of withoutCEscapes. |
17000 | 6216 |
|
6217 |
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
|
6218 |
but it cannot be changed easily, as these methods are already used heavily |
13987 | 6219 |
" |
6220 |
||
6221 |
|anyEscapeNeeded out seq| |
|
6222 |
||
6223 |
" |
|
6224 |
first, check if any escape is needed and return the receiver unchanged if not |
|
6225 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6226 |
anyEscapeNeeded := self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6227 |
contains:[:ch | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6228 |
((ch codePoint between:32 and:126) not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6229 |
or:[ch == $' or:[ch == $"]]) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6230 |
]. |
13987 | 6231 |
anyEscapeNeeded ifFalse:[ ^ self ]. |
6232 |
||
6233 |
self hasChangeOfEmphasis ifTrue:[ self error:'emphasis not supported' ]. |
|
6234 |
||
18269 | 6235 |
out := WriteStream on:(String uninitializedNew:self size-1). |
13987 | 6236 |
|
6237 |
self do:[:ch | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6238 |
|cp| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6239 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6240 |
(ch == $' or:[ch == $"]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6241 |
out nextPut:$\. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6242 |
out nextPut:ch. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6243 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6244 |
(ch codePoint between:32 and:126) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6245 |
out nextPut:ch |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6246 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6247 |
ch == Character return ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6248 |
seq := '\r' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6249 |
] ifFalse:[ ch == Character nl ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6250 |
seq := '\n' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6251 |
] ifFalse:[ ch == Character tab ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6252 |
seq := '\t' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6253 |
] ifFalse:[ ch == $\ ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6254 |
seq := '\\' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6255 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6256 |
cp := ch codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6257 |
cp <= 16rFF ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6258 |
seq := '\x' , (cp printStringRadix:16 padTo:2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6259 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6260 |
cp <= 16rFFFF ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6261 |
seq := '\u' , (cp printStringRadix:16 padTo:4) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6262 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6263 |
seq := '\U',(cp printStringRadix:16 padTo:8) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6264 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6265 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6266 |
]]]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6267 |
out nextPutAll:seq |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6268 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6269 |
]. |
13987 | 6270 |
]. |
6271 |
^ out contents |
|
6272 |
||
6273 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6274 |
'hello\n\tworld' withoutCEscapes. |
17000 | 6275 |
'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
|
6276 |
('hello ',(Character value:16r1234),' world') withCEscapes |
13987 | 6277 |
" |
6278 |
||
6279 |
"Created: / 25-01-2012 / 11:08:16 / cg" |
|
6280 |
! |
|
6281 |
||
9192 | 6282 |
withCRs |
17205 | 6283 |
"return a new string consisting of the receiver's characters |
16757 | 6284 |
with all \-characters replaced by cr-characters. |
6285 |
If there are no backslashes, return the original" |
|
6286 |
||
16759 | 6287 |
^ self copyReplaceAll:$\ with:(Character cr) ifNone:self |
9192 | 6288 |
|
6289 |
" |
|
6290 |
'hello\world' withCRs |
|
6291 |
" |
|
6292 |
||
6293 |
"Modified: / 18.7.1998 / 22:53:02 / cg" |
|
6294 |
! |
|
6295 |
||
6296 |
withEscapes |
|
15405 | 6297 |
<resource: #obsolete> |
13987 | 6298 |
"has been renamed; the name withEscapes is misleading" |
6299 |
||
6300 |
self obsoleteMethodWarning:'use withoutCEscapes'. |
|
6301 |
^ self withoutCEscapes. |
|
6302 |
||
6303 |
"Modified: / 25-01-2012 / 10:42:30 / cg" |
|
9192 | 6304 |
! |
6305 |
||
6306 |
withMatchEscapes |
|
4117 | 6307 |
"return a copy of the receiver with all match characters escaped |
6308 |
by $\ characters (to be usable as a match string). |
|
6309 |
Return the receiver, if there are none." |
|
6310 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6311 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6312 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6313 |
escape := self class matchEscapeCharacter. |
4117 | 6314 |
|
6315 |
in := self readStream. |
|
7986 | 6316 |
out := WriteStream on:(self species new:self size). |
4117 | 6317 |
[in atEnd] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6318 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6319 |
(c == escape or:['*[#' includes:c]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6320 |
out nextPut:$\. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6321 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6322 |
out nextPut:c. |
4117 | 6323 |
]. |
6324 |
^ out contents. |
|
6325 |
||
6326 |
" |
|
8874 | 6327 |
'*foo' withMatchEscapes |
6328 |
'\*foo' withMatchEscapes |
|
6329 |
'*foo' withMatchEscapes |
|
6330 |
'\\*foo' withMatchEscapes |
|
6331 |
'foo*' withMatchEscapes |
|
6332 |
'foo\*' withMatchEscapes |
|
6333 |
'foo\' withMatchEscapes |
|
6334 |
'f*o*o' withMatchEscapes |
|
4117 | 6335 |
" |
6336 |
||
6337 |
"Modified: 2.4.1997 / 18:13:04 / cg" |
|
9192 | 6338 |
! |
6339 |
||
14992 | 6340 |
withSeparatorsCompacted |
6341 |
"return a new string with each sequence of whiteSpace replaced by a single space character. |
|
6342 |
Preserves a leading/trailing space." |
|
6343 |
||
6344 |
^ self species streamContents:[:s | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6345 |
|skipping| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6346 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6347 |
skipping := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6348 |
1 to:self size do:[:idx | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6349 |
|char| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6350 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6351 |
char := self at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6352 |
char isSeparator ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6353 |
s nextPut:char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6354 |
skipping := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6355 |
] ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6356 |
skipping ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6357 |
s nextPut:(Character space). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6358 |
skipping := true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6359 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6360 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6361 |
] |
14992 | 6362 |
] |
6363 |
||
6364 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6365 |
'hello wwww' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6366 |
'hello wwww' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6367 |
' hello wwww' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6368 |
' hello wwww ' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6369 |
' hello wwww ' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6370 |
'hel lo www w' withSeparatorsCompacted |
14992 | 6371 |
" |
6372 |
! |
|
6373 |
||
18464 | 6374 |
withSeparatorsReplacedBy:replacementCharacter |
6375 |
"return a new string with each separator (whitespace) replaced by replacementCharacter. |
|
6376 |
Typically used with space as replacementCharacter" |
|
6377 |
||
6378 |
^ self species streamContents:[:s | |
|
6379 |
self do:[:ch | |
|
6380 |
ch isSeparator ifTrue:[ |
|
6381 |
s nextPut:replacementCharacter |
|
6382 |
] ifFalse:[ |
|
6383 |
s nextPut:ch. |
|
6384 |
] |
|
6385 |
] |
|
6386 |
] |
|
6387 |
||
6388 |
" |
|
6389 |
'hello wwww' withSeparatorsReplacedBy:$* |
|
6390 |
'hello ww ww' withSeparatorsReplacedBy:$* |
|
6391 |
' hello wwww' withSeparatorsReplacedBy:$* |
|
6392 |
'hel lo www w' withSeparatorsReplacedBy:$* |
|
6393 |
'hel |
|
6394 |
lo www |
|
6395 |
w' withSeparatorsReplacedBy:$* |
|
6396 |
" |
|
6397 |
! |
|
6398 |
||
9192 | 6399 |
withTabs |
19464 | 6400 |
"return a string consisting of the receiver's characters |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6401 |
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
|
6402 |
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
|
6403 |
otherwise a new string is returned. |
8874 | 6404 |
Limitation: only the very first spaces are replaced |
19464 | 6405 |
(i.e. if the receiver contains newLine characters, |
6406 |
no tabs are inserted after those lineBreaks)" |
|
8874 | 6407 |
|
6408 |
|idx "{ SmallInteger }" |
|
6409 |
nTabs "{ SmallInteger }" |
|
608 | 6410 |
newString| |
6411 |
||
6412 |
idx := self findFirst:[:c | (c ~~ Character space)]. |
|
6413 |
nTabs := (idx-1) // 8. |
|
5815
4acdd87a77d4
// can return negative numbers.
Stefan Vogel <sv@exept.de>
parents:
5795
diff
changeset
|
6414 |
nTabs <= 0 ifTrue:[^ self]. |
608 | 6415 |
|
6416 |
"any tabs" |
|
15523 | 6417 |
newString := self species new:(self size - (nTabs * 7)). |
608 | 6418 |
newString atAll:(1 to:nTabs) put:(Character tab). |
6419 |
newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1). |
|
6420 |
^ newString |
|
6421 |
||
6422 |
" |
|
8874 | 6423 |
'12345678901234567890' withTabs |
6424 |
' 8901234567890' withTabs |
|
6425 |
' 901234567890' withTabs |
|
608 | 6426 |
' 67890' withTabs |
6427 |
' 7890' withTabs |
|
6428 |
' 890' withTabs |
|
6429 |
" |
|
9192 | 6430 |
! |
6431 |
||
6432 |
withTabsExpanded |
|
19464 | 6433 |
"return a string consisting of the receiver's characters, |
8874 | 6434 |
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
|
6435 |
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
|
6436 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6437 |
This does handle multiline strings." |
608 | 6438 |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6439 |
^ self withTabsExpanded:8 |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6440 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6441 |
" |
8874 | 6442 |
('1' , Character tab asString , 'x') withTabsExpanded |
6443 |
('12345' , Character tab asString , 'x') withTabsExpanded |
|
6444 |
('123456' , Character tab asString , 'x') withTabsExpanded |
|
6445 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
|
6446 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
|
6447 |
('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
|
6448 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6449 |
(String with:Character tab |
19464 | 6450 |
with:Character tab |
6451 |
with:$1) withTabsExpanded |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6452 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6453 |
(String with:Character tab |
19464 | 6454 |
with:$1 |
6455 |
with:Character tab |
|
6456 |
with:$2) withTabsExpanded |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6457 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6458 |
(String with:Character tab |
19464 | 6459 |
with:$1 |
6460 |
with:Character cr |
|
6461 |
with:Character tab |
|
6462 |
with:$2) withTabsExpanded |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6463 |
" |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6464 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6465 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
9192 | 6466 |
! |
6467 |
||
6468 |
withTabsExpanded:numSpaces |
|
19464 | 6469 |
"return a string consisting of the receiver's characters, |
8874 | 6470 |
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
|
6471 |
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
|
6472 |
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
|
6473 |
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
|
6474 |
|
8874 | 6475 |
|col "{ SmallInteger }" |
1381 | 6476 |
str ch |
6477 |
dstIdx "{ SmallInteger }" |
|
6478 |
newSz "{ SmallInteger }" |
|
6479 |
sz "{ SmallInteger }" |
|
6480 |
hasEmphasis e| |
|
608 | 6481 |
|
6482 |
(self includes:(Character tab)) ifFalse:[^ self]. |
|
1381 | 6483 |
|
6484 |
sz := self size. |
|
6485 |
||
6486 |
"/ count the new size first, instead of |
|
6487 |
"/ multiple resizing (better for large strings) |
|
6488 |
||
6489 |
col := 1. newSz := 0. |
|
6490 |
1 to:sz do:[:srcIdx | |
|
19464 | 6491 |
ch := self at:srcIdx. |
6492 |
ch == Character tab ifFalse:[ |
|
6493 |
col := col + 1. |
|
6494 |
newSz := newSz + 1. |
|
6495 |
ch == Character cr ifTrue:[ |
|
6496 |
col := 1 |
|
6497 |
]. |
|
6498 |
] ifTrue:[ |
|
6499 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
|
6500 |
newSz := newSz + 1. |
|
6501 |
col := col + 1 |
|
6502 |
]. |
|
6503 |
] |
|
608 | 6504 |
]. |
1381 | 6505 |
|
6506 |
str := self species new:newSz. |
|
6507 |
||
6508 |
hasEmphasis := self hasChangeOfEmphasis. |
|
6509 |
||
6510 |
col := 1. dstIdx := 1. |
|
6511 |
1 to:sz do:[:srcIdx | |
|
19464 | 6512 |
ch := self at:srcIdx. |
6513 |
||
6514 |
ch == Character tab ifFalse:[ |
|
6515 |
col := col + 1. |
|
6516 |
ch == Character cr ifTrue:[ |
|
6517 |
col := 1 |
|
6518 |
]. |
|
6519 |
hasEmphasis ifTrue:[ |
|
6520 |
e := self emphasisAt:srcIdx. |
|
6521 |
str emphasisAt:dstIdx put:e |
|
6522 |
]. |
|
6523 |
str at:dstIdx put:ch. |
|
6524 |
dstIdx := dstIdx + 1 |
|
6525 |
] ifTrue:[ |
|
6526 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
|
6527 |
str at:dstIdx put:Character space. |
|
6528 |
dstIdx := dstIdx + 1. |
|
6529 |
col := col + 1 |
|
6530 |
]. |
|
6531 |
] |
|
1381 | 6532 |
]. |
6533 |
^ str |
|
608 | 6534 |
|
6535 |
" |
|
8874 | 6536 |
('1' , Character tab asString , 'x') withTabsExpanded |
6537 |
('1' , Character tab asString , 'x') withTabsExpanded:4 |
|
6538 |
('12345' , Character tab asString , 'x') withTabsExpanded |
|
6539 |
('123456' , Character tab asString , 'x') withTabsExpanded |
|
6540 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
|
6541 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
|
6542 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6543 |
|
608 | 6544 |
(String with:Character tab |
19464 | 6545 |
with:Character tab |
6546 |
with:$1) withTabsExpanded |
|
608 | 6547 |
|
6548 |
(String with:Character tab |
|
19464 | 6549 |
with:$1 |
6550 |
with:Character tab |
|
6551 |
with:$2) withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6552 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6553 |
(String with:Character tab |
19464 | 6554 |
with:$1 |
6555 |
with:Character cr |
|
6556 |
with:Character tab |
|
6557 |
with:$2) withTabsExpanded |
|
608 | 6558 |
" |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6559 |
|
1381 | 6560 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
9192 | 6561 |
! |
6562 |
||
13987 | 6563 |
withoutAllSpaces |
16855 | 6564 |
"return a copy of the receiver with all whitespace removed" |
6565 |
||
13987 | 6566 |
^ self asCollectionOfWords asStringWith:''. |
6567 |
"/ |col string| |
|
6568 |
"/ |
|
6569 |
"/ col := self asCollectionOfWords. |
|
6570 |
"/ string := String new. |
|
6571 |
"/ col do:[:el | |
|
6572 |
"/ string := string,el |
|
6573 |
"/ ]. |
|
6574 |
"/ ^string |
|
6575 |
||
6576 |
" |
|
6577 |
'hello wwww' withoutAllSpaces |
|
6578 |
'hel lo www w' withoutAllSpaces |
|
6579 |
" |
|
6580 |
||
6581 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
6582 |
! |
|
6583 |
||
6584 |
withoutCEscapes |
|
15628 | 6585 |
"return a new string consisting of receiver's characters |
13987 | 6586 |
with all \X-character escapes replaced by corresponding-characters. |
6587 |
(similar to the way C-language Strings are converted). |
|
6588 |
The following escapes are supported: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6589 |
\r return character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6590 |
\n newline character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6591 |
\b backspace character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6592 |
\f formfeed character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6593 |
\t tab character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6594 |
\e escape character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6595 |
\\ the \ character itself |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6596 |
\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
|
6597 |
\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
|
6598 |
\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
|
6599 |
\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
|
6600 |
\other other |
13987 | 6601 |
|
6602 |
Notice, that \' is NOT a valid escape, since the general syntax of |
|
6603 |
string constants is not affected by this method. |
|
6604 |
||
6605 |
Although easily implementable, this is NOT done automatically |
|
6606 |
by the compiler (due to a lack of a language standard for this). |
|
6607 |
However, the compiler may detect sends ot #withEscapes to string literals |
|
6608 |
and place a modified string constant into the binary/byte-code. |
|
6609 |
Therefore, no runtime penalty will be payed for using these escapes. |
|
6610 |
(not in pre 2.11 versions) |
|
16863 | 6611 |
|
6612 |
This is the opposite of withCEscapes. |
|
17000 | 6613 |
|
6614 |
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
|
6615 |
but it cannot be changed easily, as these methods are already used heavily |
13987 | 6616 |
" |
6617 |
||
6618 |
|val "{ SmallInteger }" |
|
6619 |
in out nextChar nDigits| |
|
6620 |
||
6621 |
" |
|
6622 |
first, see if there is any escape; if not, return the receiver unchanged |
|
6623 |
" |
|
6624 |
(self includes:$\) ifFalse:[^ self ]. |
|
6625 |
||
6626 |
self hasChangeOfEmphasis ifTrue:[ self error:'emphasis not supported' ]. |
|
6627 |
out := CharacterWriteStream on:(String new:self size - 1). |
|
6628 |
||
6629 |
in := ReadStream on:self. |
|
6630 |
[in atEnd] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6631 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6632 |
nextChar == $\ ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6633 |
in atEnd ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6634 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6635 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6636 |
nextChar == $r ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6637 |
nextChar := Character return |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6638 |
] ifFalse:[ nextChar == $n ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6639 |
nextChar := Character nl |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6640 |
] ifFalse:[ nextChar == $b ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6641 |
nextChar := Character backspace |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6642 |
] ifFalse:[ nextChar == $f ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6643 |
nextChar := Character newPage |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6644 |
] ifFalse:[ nextChar == $t ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6645 |
nextChar := Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6646 |
] ifFalse:[ nextChar == $e ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6647 |
nextChar := Character esc |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6648 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6649 |
nextChar == $0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6650 |
val := 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6651 |
nextChar := in peek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6652 |
nDigits := 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6653 |
[nextChar notNil and:[nextChar isDigit and:[nDigits <= 3]]] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6654 |
val := (val * 8) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6655 |
nextChar := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6656 |
nDigits := nDigits + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6657 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6658 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6659 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6660 |
val := 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6661 |
nextChar == $x ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6662 |
2 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6663 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6664 |
val := (val * 16) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6665 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6666 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6667 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6668 |
nextChar == $u ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6669 |
4 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6670 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6671 |
val := (val * 16) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6672 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6673 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6674 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6675 |
nextChar == $U ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6676 |
8 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6677 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6678 |
val := (val * 16) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6679 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6680 |
nextChar := Character value:val. |
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 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6683 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6684 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6685 |
]]]]]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6686 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6687 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6688 |
out nextPut:nextChar. |
13987 | 6689 |
]. |
6690 |
^ out contents |
|
6691 |
||
6692 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6693 |
'hello world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6694 |
'hello\world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6695 |
'hello\world\' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6696 |
'hello world\' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6697 |
'hello\tworld' withoutCEscapes |
13987 | 6698 |
'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
|
6699 |
'hello\tworld\n' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6700 |
'hello\010world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6701 |
'hello\r\nworld' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6702 |
'hello\r\n\x08world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6703 |
'0\x080' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6704 |
'0\u12340' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6705 |
'0\U123456780' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6706 |
'0\0a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6707 |
'0\00a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6708 |
'0\000a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6709 |
'0\0000a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6710 |
'0\00000a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6711 |
'0\03770' withoutCEscapes |
13987 | 6712 |
" |
6713 |
||
6714 |
"Created: / 25-01-2012 / 10:41:44 / cg" |
|
6715 |
! |
|
6716 |
||
9192 | 6717 |
withoutCRs |
19464 | 6718 |
"return a new collection consisting of receiver's elements |
9192 | 6719 |
with all cr-characters replaced by \-characters. |
6720 |
This is the reverse operation of withCRs." |
|
6721 |
||
16759 | 6722 |
^ self copyReplaceAll:(Character cr) with:$\ ifNone:self |
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
6723 |
|
9192 | 6724 |
" |
6725 |
'hello |
|
6726 |
world' withoutCRs |
|
6727 |
" |
|
6728 |
||
6729 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
6730 |
! |
|
6731 |
||
6732 |
withoutLeadingSeparators |
|
608 | 6733 |
"return a copy of myself without leading separators. |
6734 |
Notice: this does remove tabs, newline or any other whitespace. |
|
6735 |
Returns an empty string, if the receiver consist only of whitespace." |
|
6736 |
||
6737 |
|index| |
|
6738 |
||
6739 |
index := self indexOfNonSeparatorStartingAt:1. |
|
6740 |
index ~~ 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6741 |
index == 1 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6742 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6743 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6744 |
^ self copyFrom:index |
608 | 6745 |
]. |
6746 |
^ '' |
|
6747 |
||
6748 |
" |
|
8874 | 6749 |
' foo ' withoutLeadingSeparators |
6750 |
'foo ' withoutLeadingSeparators |
|
6751 |
' foo' withoutLeadingSeparators |
|
6752 |
' ' withoutLeadingSeparators |
|
6753 |
'foo' withoutLeadingSeparators |
|
6754 |
(' ' , Character tab asString , ' foo ') withoutLeadingSeparators inspect |
|
608 | 6755 |
" |
9192 | 6756 |
! |
6757 |
||
6758 |
withoutMatchEscapes |
|
4117 | 6759 |
"return a copy of the receiver with all $\ removed or |
6760 |
the receiver, if there are none." |
|
6761 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6762 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6763 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6764 |
escape := self class matchEscapeCharacter. |
4117 | 6765 |
|
6766 |
in := self readStream. |
|
8222
f2c454a9a038
replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents:
8124
diff
changeset
|
6767 |
out := self species writeStream. |
4117 | 6768 |
[in atEnd] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6769 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6770 |
c == escape ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6771 |
in atEnd ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6772 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6773 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6774 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6775 |
out nextPut:c. |
4117 | 6776 |
]. |
6777 |
^ out contents. |
|
6778 |
||
6779 |
" |
|
8874 | 6780 |
'*foo' withoutMatchEscapes |
6781 |
'\*foo' withoutMatchEscapes |
|
6782 |
'*foo' withoutMatchEscapes |
|
6783 |
'\\*foo' withoutMatchEscapes |
|
6784 |
'foo*' withoutMatchEscapes |
|
6785 |
'foo\*' withoutMatchEscapes |
|
6786 |
'foo\' withoutMatchEscapes |
|
6787 |
'f\*o\*o' withoutMatchEscapes |
|
4117 | 6788 |
" |
6789 |
||
6790 |
"Modified: 30.6.1997 / 13:40:23 / cg" |
|
9192 | 6791 |
! |
6792 |
||
6793 |
withoutPrefix:aString |
|
6794 |
"if the receiver startsWith aPrefix, return a copy without it. |
|
6795 |
Otherwise return the receiver" |
|
6796 |
||
6797 |
(self startsWith:aString) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6798 |
^ self copyFrom:aString size + 1 |
9192 | 6799 |
]. |
6800 |
^ self |
|
6801 |
||
6802 |
" |
|
6803 |
'helloworld' withoutPrefix:'hello' |
|
6804 |
'helloworld' withoutPrefix:'foo' |
|
6805 |
" |
|
6806 |
! |
|
6807 |
||
10671 | 6808 |
withoutQuotes |
17000 | 6809 |
"/ remove quotes ($" and $') from the front and end of myself (if matching)" |
6810 |
||
6811 |
|firstChar| |
|
6812 |
||
17024 | 6813 |
self isEmpty ifTrue:[^ self]. |
6814 |
||
17000 | 6815 |
firstChar := self first. |
6816 |
((firstChar == $") or:[firstChar == $']) ifFalse:[^ self]. |
|
6817 |
||
6818 |
self last == firstChar ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6819 |
^ self copyFrom:2 to:(self size-1) |
10671 | 6820 |
]. |
17000 | 6821 |
^ self |
6822 |
||
6823 |
"/ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6824 |
"/ '"hello"' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6825 |
"/ '''hello''' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6826 |
"/ 'hello' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6827 |
"/ '"hello' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6828 |
"/ 'hello"' withoutQuotes |
17000 | 6829 |
"/ |
10671 | 6830 |
! |
6831 |
||
9192 | 6832 |
withoutSeparators |
608 | 6833 |
"return a copy of myself without leading and trailing whitespace. |
4156 | 6834 |
(but whiteSpace in-between is preserved) |
608 | 6835 |
Whitespace is space, tab, newline, formfeed. |
6836 |
Use withoutSpaces, if you want to remove spaces only." |
|
6837 |
||
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
6838 |
^ self trimForWhich:[:ch | ch isSeparator] |
608 | 6839 |
|
6840 |
" |
|
8874 | 6841 |
' foo ' withoutSeparators |
6842 |
' foo' withoutSeparators |
|
6843 |
'foo ' withoutSeparators |
|
6844 |
' ' withoutSeparators |
|
6845 |
(' foo' , Character tab asString , ' ') withoutSeparators inspect |
|
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
6846 |
' foo ' asUnicode16String withoutSeparators |
608 | 6847 |
" |
9192 | 6848 |
! |
6849 |
||
6850 |
withoutSpaces |
|
608 | 6851 |
"return a copy of myself without leading and trailing spaces. |
4156 | 6852 |
(but spaces in-between are preserved) |
608 | 6853 |
Notice: this does NOT remove tabs, newline or any other whitespace. |
6854 |
Use withoutSeparators for this." |
|
6855 |
||
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
6856 |
^ self trimForWhich:[:ch | ch == Character space] |
608 | 6857 |
|
6858 |
" |
|
8874 | 6859 |
' foo ' withoutSpaces |
6860 |
'foo ' withoutSpaces |
|
6861 |
' foo' withoutSpaces |
|
6862 |
' ' withoutSpaces |
|
6863 |
'a b' withoutSpaces |
|
6864 |
(' foo' , Character tab asString , ' ') withoutSpaces inspect |
|
608 | 6865 |
" |
9192 | 6866 |
! |
6867 |
||
6868 |
withoutTrailingSeparators |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6869 |
"return a copy of myself without trailing separators. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6870 |
Notice: this does remove tabs, newline or any other whitespace. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6871 |
Returns an empty string, if the receiver consist only of whitespace." |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6872 |
|
12188 | 6873 |
^ self withoutTrailingForWhich:[:ch | ch isSeparator] |
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6874 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6875 |
" |
8874 | 6876 |
' foo ' withoutTrailingSeparators |
6877 |
'foo ' withoutTrailingSeparators |
|
6878 |
' foo' withoutTrailingSeparators |
|
6879 |
' ' withoutTrailingSeparators |
|
6880 |
'foo' withoutTrailingSeparators |
|
6881 |
(' ' , Character tab asString , ' foo ') withoutTrailingSeparators inspect |
|
6882 |
(' foo' , Character tab asString) withoutTrailingSeparators inspect |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6883 |
" |
9192 | 6884 |
! ! |
6885 |
||
6886 |
!CharacterArray methodsFor:'substring searching'! |
|
6887 |
||
15055 | 6888 |
findRangeOfString:subString |
6889 |
"find a substring. if found, return the start- and endIndex; |
|
6890 |
if not found, return an empty interval." |
|
6891 |
||
6892 |
^ self rangeOfSubCollection:subString startingAt:1 ifAbsent:[0 to:-1] caseSensitive:true |
|
6893 |
||
6894 |
" |
|
6895 |
'hello world' findRangeOfString:'llo' |
|
6896 |
'hello world' findRangeOfString:'ole' |
|
6897 |
" |
|
6898 |
! |
|
6899 |
||
9192 | 6900 |
findString:subString |
6901 |
"find a substring. if found, return the index; |
|
6902 |
if not found, return 0." |
|
6903 |
||
6904 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:true |
|
6905 |
||
6906 |
" |
|
6907 |
'hello world' findString:'llo' |
|
6908 |
'hello world' findString:'ole' |
|
6909 |
" |
|
6910 |
! |
|
608 | 6911 |
|
15734 | 6912 |
findString:subString caseSensitive:caseSensitive |
6913 |
"find a substring. if found, return the index; |
|
6914 |
if not found, return 0." |
|
6915 |
||
6916 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:caseSensitive |
|
6917 |
||
6918 |
" |
|
6919 |
'hello world' findString:'LLo' caseSensitive:true |
|
6920 |
'hello world' findString:'LLo' caseSensitive:false |
|
6921 |
" |
|
6922 |
! |
|
6923 |
||
608 | 6924 |
findString:subString ifAbsent:exceptionBlock |
6925 |
"find a substring. If found, return the index; |
|
6926 |
if not found, return the result of evaluating exceptionBlock." |
|
6927 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6928 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock caseSensitive:true |
608 | 6929 |
! |
6930 |
||
11018 | 6931 |
findString:subString ignoreCase:ignoreCase |
15734 | 6932 |
<resource: #obsolete> |
11018 | 6933 |
"find a substring. if found, return the index; |
6934 |
if not found, return 0." |
|
6935 |
||
6936 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:ignoreCase not |
|
6937 |
||
6938 |
" |
|
6939 |
'hello world' findString:'LLo' ignoreCase:false |
|
6940 |
'hello world' findString:'LLo' ignoreCase:true |
|
6941 |
" |
|
6942 |
! |
|
6943 |
||
608 | 6944 |
findString:subString startingAt:index |
6945 |
"find a substring, starting at index. if found, return the index; |
|
6946 |
if not found, return 0." |
|
6947 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6948 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:0 caseSensitive:true |
608 | 6949 |
|
6950 |
" |
|
9192 | 6951 |
'hello yello' findString:'llo' startingAt:1 |
6952 |
'hello yello' findString:'llo' startingAt:5 |
|
6953 |
'hello yello' findString:'llo' startingAt:15 |
|
6954 |
" |
|
6955 |
! |
|
608 | 6956 |
|
6957 |
findString:subString startingAt:index ifAbsent:exceptionBlock |
|
6958 |
"find a substring, starting at index. if found, return the index; |
|
6959 |
if not found, return the result of evaluating exceptionBlock." |
|
6960 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6961 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:true |
608 | 6962 |
! |
6963 |
||
12177 | 6964 |
findString:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
10929 | 6965 |
"find a substring, starting at index. if found, return the index; |
6966 |
if not found, return the result of evaluating exceptionBlock." |
|
6967 |
||
6968 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
|
6969 |
! |
|
6970 |
||
608 | 6971 |
includesString:aString |
6972 |
"return true, if a substring is contained in the receiver" |
|
6973 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6974 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0 caseSensitive:true) ~~ 0 |
608 | 6975 |
|
6976 |
" |
|
12177 | 6977 |
'hello world' includesString:'hel' |
8874 | 6978 |
'hello world' includesString:'rld' |
9192 | 6979 |
'hello world' includesString:'llo' |
6980 |
'hello world' includesString:'LLO' |
|
12177 | 6981 |
'hello world' includesString:'' |
9192 | 6982 |
" |
6983 |
! |
|
9191 | 6984 |
|
6985 |
includesString:aString caseSensitive:caseSensitive |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6986 |
"return true, if a substring is contained in the receiver" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6987 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6988 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0 caseSensitive:caseSensitive) ~~ 0 |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6989 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6990 |
" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6991 |
'hello world' includesString:'hel' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6992 |
'hello world' includesString:'HEL' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6993 |
'hello world' includesString:'HEL' caseSensitive:false |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6994 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6995 |
'hello world' includesString:'wor' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6996 |
'hello world' includesString:'WOR' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6997 |
'hello world' includesString:'WOR' caseSensitive:false |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6998 |
" |
9192 | 6999 |
! |
7000 |
||
17486 | 7001 |
indexOfString: aString |
7002 |
"VSE and V'age compatibility" |
|
7003 |
"find a substring. If found, return the index; if not found, return 0." |
|
7004 |
||
18939 | 7005 |
^ self indexOfSubCollection: aString startingAt:1 ifAbsent:[0] |
7006 |
! |
|
7007 |
||
7008 |
indexOfString:aString ifAbsent:exceptionValue |
|
7009 |
"VSE and V'age compatibility" |
|
7010 |
"find a substring. If found, return the index; if not found, return 0." |
|
7011 |
||
7012 |
^ self indexOfSubCollection: aString startingAt:1 ifAbsent:exceptionValue |
|
7013 |
||
7014 |
" |
|
7015 |
'abcdefabcdef' indexOfString:'fab' ifAbsent:[999] |
|
7016 |
'abcdefabcdef' indexOfString:'xxx' ifAbsent:[999] |
|
7017 |
" |
|
17486 | 7018 |
! |
7019 |
||
18721 | 7020 |
indexOfString:aString startingAt:startIndex |
7021 |
"VSE and V'age compatibility" |
|
7022 |
"find a substring. If found, return the index; if not found, return 0." |
|
7023 |
||
7024 |
^ self indexOfSubCollection:aString startingAt:startIndex ifAbsent:[0] |
|
7025 |
! |
|
7026 |
||
7027 |
indexOfString:aString startingAt:startIndex ifAbsent:exceptionalValue |
|
7028 |
"VSE and V'age compatibility" |
|
7029 |
"find a substring. |
|
7030 |
If found, return the index; if not found, the value from exceptionalValue." |
|
7031 |
||
7032 |
^ self indexOfSubCollection:aString startingAt:startIndex ifAbsent:exceptionalValue |
|
7033 |
! |
|
7034 |
||
18671 | 7035 |
indexOfSubCollection:subString caseSensitive:caseSensitive |
7036 |
"find a substring, starting at index. if found, return the index; |
|
7037 |
if not found, return the result of evaluating exceptionBlock. |
|
7038 |
This is a q&d hack - not very efficient" |
|
7039 |
||
7040 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:[0] caseSensitive:caseSensitive. |
|
7041 |
! |
|
7042 |
||
9192 | 7043 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
7044 |
"find a substring, starting at index. if found, return the index; |
|
7045 |
if not found, return the result of evaluating exceptionBlock. |
|
7046 |
This is a q&d hack - not very efficient" |
|
7047 |
||
7048 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:true. |
|
7049 |
! |
|
7050 |
||
7051 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7052 |
"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
|
7053 |
if not found, return the result of evaluating exceptionBlock. |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7054 |
This is a q&d hack - not very efficient" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7055 |
|
608 | 7056 |
|firstChar found |
7057 |
startIndex "{ Class: SmallInteger }" |
|
7058 |
subSize "{ Class: SmallInteger }" |
|
7059 |
mySize "{ Class: SmallInteger }" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7060 |
runIdx "{ Class: SmallInteger }" |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7061 |
tester| |
608 | 7062 |
|
7063 |
subSize := subString size. |
|
12177 | 7064 |
subSize == 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7065 |
subString isString ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7066 |
self error:'non string argument' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7067 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7068 |
"empty string does not match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7069 |
^ 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7070 |
"empty string matches" |
15433 | 7071 |
"/ ^ index |
6122
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
7072 |
]. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7073 |
|
608 | 7074 |
mySize := self size. |
7075 |
firstChar := subString at:1. |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7076 |
caseSensitive ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7077 |
tester := [:c1 :c2 | c1 = c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7078 |
startIndex := self indexOf:firstChar startingAt:index. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7079 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7080 |
tester := [:c1 :c2 | c1 sameAs: c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7081 |
startIndex := self findFirst:[:c | c sameAs:firstChar] startingAt:index. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7082 |
]. |
608 | 7083 |
[startIndex == 0] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7084 |
runIdx := startIndex. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7085 |
found := true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7086 |
1 to:subSize do:[:i | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7087 |
runIdx > mySize ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7088 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7089 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7090 |
(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
|
7091 |
found := false |
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 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7094 |
runIdx := runIdx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7095 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7096 |
found ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7097 |
^ startIndex |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7098 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7099 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7100 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7101 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7102 |
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
|
7103 |
]. |
608 | 7104 |
]. |
7105 |
^ exceptionBlock value |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7106 |
|
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7107 |
"Modified: 23.2.1996 / 15:35:15 / cg" |
9192 | 7108 |
! |
7109 |
||
17191 | 7110 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive ignoreDiacritics:ignoreDiacritics |
7111 |
"find a substring, starting at index. if found, return the index; |
|
7112 |
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
|
7113 |
This is a q&d hack - not very efficient |
17191 | 7114 |
(see implementation in string, for a much faster algorithm)" |
7115 |
||
7116 |
|firstChar found |
|
7117 |
startIndex "{ Class: SmallInteger }" |
|
7118 |
subSize "{ Class: SmallInteger }" |
|
7119 |
mySize "{ Class: SmallInteger }" |
|
7120 |
runIdx "{ Class: SmallInteger }" |
|
7121 |
tester charMap firstCharMapped findNextIndex| |
|
7122 |
||
7123 |
subSize := subString size. |
|
7124 |
subSize == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7125 |
subString isString ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7126 |
self error:'non string argument' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7127 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7128 |
"empty string does not match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7129 |
^ 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7130 |
"empty string matches" |
17191 | 7131 |
"/ ^ index |
7132 |
]. |
|
7133 |
||
7134 |
mySize := self size. |
|
7135 |
firstChar := subString at:1. |
|
7136 |
ignoreDiacritics ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7137 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7138 |
charMap := [:ch | ch asLowercase withoutDiacritics]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7139 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7140 |
charMap := [:ch | ch withoutDiacritics]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7141 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7142 |
tester := [:c1 :c2 | (charMap value:c1) = (charMap value:c2) ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7143 |
firstCharMapped := (charMap value:firstChar). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7144 |
findNextIndex := [:index | self findFirst:[:ch | (charMap value:ch) = firstCharMapped] startingAt:index]. |
17191 | 7145 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7146 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7147 |
tester := [:c1 :c2 | c1 = c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7148 |
findNextIndex := [:index | self indexOf:firstChar startingAt:index]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7149 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7150 |
tester := [:c1 :c2 | c1 sameAs: c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7151 |
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
|
7152 |
]. |
17191 | 7153 |
]. |
7154 |
startIndex := findNextIndex value:index. |
|
7155 |
[startIndex == 0] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7156 |
runIdx := startIndex. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7157 |
found := true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7158 |
1 to:subSize do:[:i | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7159 |
runIdx > mySize ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7160 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7161 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7162 |
(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
|
7163 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7164 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7165 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7166 |
runIdx := runIdx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7167 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7168 |
found ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7169 |
^ startIndex |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7170 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7171 |
startIndex := findNextIndex value:(startIndex + 1) |
17191 | 7172 |
]. |
7173 |
^ exceptionBlock value |
|
7174 |
||
7175 |
" |
|
17600 | 7176 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:1 ifAbsent:0 caseSensitive:false ignoreDiacritics:true. 5 |
7177 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:6 ifAbsent:0 caseSensitive:false ignoreDiacritics:true. 0 |
|
7178 |
||
7179 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:1 ifAbsent:0 caseSensitive:false ignoreDiacritics:false. 5 |
|
7180 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:6 ifAbsent:0 caseSensitive:false ignoreDiacritics:false. 0 |
|
17191 | 7181 |
" |
7182 |
! |
|
7183 |
||
18939 | 7184 |
lastIndexOfString:aString |
7185 |
"VSE and V'age compatibility" |
|
7186 |
"find the last occurrence of substring. |
|
7187 |
If found, return the index; if not found, return 0." |
|
7188 |
||
7189 |
^ self lastIndexOfSubCollection:aString startingAt:(self size-aString size+1) ifAbsent:[0] |
|
7190 |
||
7191 |
" 123456789012 |
|
7192 |
'abcdefabcdef' lastIndexOfString:'abc' |
|
7193 |
'abcdefabcdef' lastIndexOfString:'abc' startingAt:6 |
|
7194 |
'abcdefabcdef' lastIndexOfString:'xxx' startingAt:6 |
|
7195 |
" |
|
7196 |
! |
|
7197 |
||
7198 |
lastIndexOfString:aString ifAbsent:exceptionValue |
|
7199 |
"VSE and V'age compatibility" |
|
7200 |
"find the last occurrence of substring. |
|
7201 |
If found, return the index; if not found, return 0." |
|
7202 |
||
7203 |
^ self lastIndexOfSubCollection:aString startingAt:(self size-aString size+1) ifAbsent:exceptionValue |
|
7204 |
||
7205 |
" 123456789012 |
|
7206 |
'abcdefabcdef' lastIndexOfString:'abc' ifAbsent:[999] |
|
7207 |
'abcdefabcdef' lastIndexOfString:'xxx' ifAbsent:[999] |
|
7208 |
" |
|
7209 |
! |
|
7210 |
||
7211 |
lastIndexOfString:aString startingAt:startIndex |
|
7212 |
"VSE and V'age compatibility" |
|
7213 |
"find the last occurrence of a substring. |
|
7214 |
If found, return the index; if not found, return 0." |
|
7215 |
||
7216 |
^ self lastIndexOfSubCollection:aString startingAt:startIndex ifAbsent:[0] |
|
7217 |
||
7218 |
" 123456789012 |
|
7219 |
'abcdefabcdef' lastIndexOfString:'abc' |
|
7220 |
'abcdefabcdef' lastIndexOfString:'abc' startingAt:6 |
|
7221 |
" |
|
7222 |
! |
|
7223 |
||
7224 |
lastIndexOfString:aString startingAt:startIndex ifAbsent:exceptionValue |
|
7225 |
"VSE and V'age compatibility" |
|
7226 |
"find the last occurrence of a substring. |
|
7227 |
If found, return the index; if not found, return 0." |
|
7228 |
||
7229 |
^ self lastIndexOfSubCollection:aString startingAt:startIndex ifAbsent:exceptionValue |
|
7230 |
||
7231 |
" 123456789012 |
|
7232 |
'abcdefabcdef' lastIndexOfString:'abc' |
|
7233 |
'abcdefabcdef' lastIndexOfString:'abc' startingAt:6 |
|
7234 |
'abcdefabcdef' lastIndexOfString:'xxx' startingAt:6 ifAbsent:999 |
|
7235 |
" |
|
7236 |
! |
|
7237 |
||
15055 | 7238 |
rangeOfSubCollection:subString startingAt:start ifAbsent:exceptionValue caseSensitive:caseSensitive |
7239 |
"find a substring. if found, return the start- and endIndex; |
|
7240 |
if not found, return the value of exceptionValue." |
|
7241 |
||
7242 |
|i| |
|
7243 |
||
7244 |
i := self indexOfSubCollection:subString startingAt:start ifAbsent:0 caseSensitive:caseSensitive. |
|
7245 |
i == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7246 |
^ exceptionValue value |
15055 | 7247 |
]. |
7248 |
^ i to:(i + subString size - 1) |
|
7249 |
||
7250 |
" |
|
7251 |
'hello world' findRangeOfString:'llo' |
|
7252 |
'hello world' findRangeOfString:'ole' |
|
7253 |
" |
|
9192 | 7254 |
! ! |
7255 |
||
7256 |
!CharacterArray methodsFor:'testing'! |
|
7257 |
||
18463 | 7258 |
argumentCount |
7259 |
"treating the receiver as a message selector, return how many arguments would it take (ANSI)" |
|
7260 |
||
7261 |
|binopChars| |
|
7262 |
||
7263 |
(self size <= Method maxBinarySelectorSize) ifTrue:[ |
|
7264 |
binopChars := Method binarySelectorCharacters. |
|
7265 |
(self conform:[:eachChar | (binopChars includes:eachChar)]) ifTrue:[ |
|
7266 |
^ 1 |
|
7267 |
]. |
|
7268 |
]. |
|
7269 |
^ self occurrencesOf:$: |
|
7270 |
||
7271 |
" |
|
7272 |
'foo:bar:' argumentCount |
|
7273 |
#foo:bar: argumentCount |
|
7274 |
'hello' argumentCount |
|
7275 |
'+' argumentCount |
|
7276 |
'++' argumentCount |
|
7277 |
'+++' argumentCount |
|
7278 |
'|' argumentCount |
|
7279 |
'?' argumentCount |
|
7280 |
'_' argumentCount |
|
7281 |
'_:' argumentCount |
|
7282 |
'_:_:' argumentCount |
|
7283 |
'<->' argumentCount |
|
7284 |
" |
|
7285 |
! |
|
7286 |
||
18597 | 7287 |
characterSize |
7288 |
"answer the size in bits of my largest character (actually only 7, 8, 16 or 32)" |
|
7289 |
||
7290 |
|string max |
|
7291 |
sz "{ Class:SmallInteger}" | |
|
15829 | 7292 |
|
7293 |
(string := self string) ~~ self ifTrue:[ |
|
18597 | 7294 |
^ string characterSize. |
7295 |
]. |
|
7296 |
||
7297 |
sz := self size. |
|
7298 |
max := 7. |
|
7299 |
1 to:sz do:[:idx | |
|
7300 |
|thisSize| |
|
7301 |
||
7302 |
thisSize := (self at:idx) characterSize. |
|
7303 |
thisSize > max ifTrue:[ |
|
7304 |
max := thisSize. |
|
7305 |
max == 32 ifTrue:[ |
|
7306 |
"shortcut: we know, that max size is 32" |
|
7307 |
^ 32. |
|
7308 |
]. |
|
7309 |
]. |
|
15829 | 7310 |
]. |
18597 | 7311 |
|
7312 |
^ max. |
|
7313 |
||
7314 |
" |
|
7315 |
'hello' characterSize |
|
7316 |
'hello' asUnicode32String characterSize |
|
7317 |
'helloü' asUnicode32String characterSize |
|
7318 |
'hello' asText allBold characterSize |
|
7319 |
" |
|
7320 |
! |
|
7321 |
||
7322 |
contains8BitCharacters |
|
7323 |
<resource: #obsolete> |
|
7324 |
||
7325 |
^ self containsNon7BitAscii |
|
7326 |
! |
|
7327 |
||
7328 |
containsNon7BitAscii |
|
7329 |
"return true, if the underlying string contains 8BitCharacters (or widers) |
|
7330 |
(i.e. if it is non-ascii)" |
|
7331 |
||
7332 |
|string |
|
7333 |
sz "{ Class:SmallInteger }"| |
|
7334 |
||
7335 |
(string := self string) ~~ self ifTrue:[ |
|
7336 |
^ string containsNon7BitAscii |
|
7337 |
]. |
|
7338 |
sz := self size. |
|
7339 |
1 to:sz do:[:idx| |
|
7340 |
(self at:idx) codePoint > 16r7F ifTrue:[ |
|
7341 |
^ true. |
|
7342 |
]. |
|
7343 |
]. |
|
7344 |
^ false. |
|
7345 |
||
7346 |
" |
|
7347 |
'hello' asUnicode32String containsNon7BitAscii |
|
7348 |
'hello üöä' asUnicode32String containsNon7BitAscii |
|
7349 |
'hello' asUnicode32String asText allBold containsNon7BitAscii |
|
7350 |
'hello üö' asUnicode32String asText allBold containsNon7BitAscii |
|
15829 | 7351 |
" |
7352 |
! |
|
7353 |
||
9192 | 7354 |
isAlphaNumeric |
7355 |
"return true, if the receiver is some alphanumeric word; |
|
7356 |
i.e. consists of a letter followed by letters or digits." |
|
7357 |
||
7358 |
self size == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7359 |
"mhmh what is this ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7360 |
^ false |
9192 | 7361 |
]. |
7362 |
(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
|
7363 |
^ self conform:[:char | char isLetterOrDigit]. |
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7364 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7365 |
" |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7366 |
'helloWorld' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7367 |
'foo1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7368 |
'f1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7369 |
'1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7370 |
'+' isAlphaNumeric |
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7371 |
" |
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7372 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7373 |
"Modified: / 13-10-2006 / 12:53:49 / cg" |
9192 | 7374 |
! |
9190 | 7375 |
|
7376 |
isBinarySelector |
|
10903 | 7377 |
"treating the receiver as a message selector, return true if its a binary selector. |
7378 |
Notice, that st/x does not have a size <= 2 limit for unaries" |
|
9190 | 7379 |
|
7380 |
|binopChars| |
|
7381 |
||
18463 | 7382 |
(self size > Method maxBinarySelectorSize) ifTrue:[^ false]. |
7383 |
||
7384 |
binopChars := Method binarySelectorCharacters. |
|
9190 | 7385 |
^ (self conform:[:char | (binopChars includes:char)]) |
7386 |
||
7387 |
" |
|
7388 |
'foo:bar:' isBinarySelector |
|
7389 |
#foo:bar: isBinarySelector |
|
7390 |
'hello' isBinarySelector |
|
7391 |
'+' isBinarySelector |
|
7392 |
'|' isBinarySelector |
|
8874 | 7393 |
'?' isBinarySelector |
7394 |
':' isBinarySelector |
|
7395 |
'a:' isBinarySelector |
|
7396 |
'->' isBinarySelector |
|
7397 |
'<->' isBinarySelector |
|
7398 |
'::' isBinarySelector |
|
7482 | 7399 |
" |
7400 |
||
7401 |
"Modified: 4.1.1997 / 14:16:14 / cg" |
|
9192 | 7402 |
! |
7403 |
||
7404 |
isBlank |
|
7405 |
"return true, if the receiver contains spaces only" |
|
7406 |
||
9230 | 7407 |
^ (self contains:[:char | char ~~ Character space]) not |
7408 |
||
7409 |
" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7410 |
'' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7411 |
' a ' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7412 |
' ' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7413 |
' ' asUnicode16String isBlank |
9230 | 7414 |
" |
9192 | 7415 |
! |
7416 |
||
10903 | 7417 |
isKeywordSelector |
7418 |
"return true, iff there are only alphanumeric or underline characters separated by colons. |
|
7419 |
Must end with a colon." |
|
7420 |
||
7421 |
|state| |
|
7422 |
||
12177 | 7423 |
state := #initial. |
10903 | 7424 |
self do:[:char | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7425 |
(state == #initial or:[ state == #gotColon]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7426 |
(char isLetterOrUnderline) ifFalse:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7427 |
state := #gotCharacter. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7428 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7429 |
char == $: ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7430 |
state := #gotColon. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7431 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7432 |
(char isLetterOrDigit or:[char == $_]) ifFalse:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7433 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7434 |
]. |
10903 | 7435 |
]. |
7436 |
^ state == #gotColon. |
|
7437 |
||
7438 |
" |
|
12177 | 7439 |
self assert:(':' isKeywordSelector not). |
10903 | 7440 |
self assert:(':a' isKeywordSelector not). |
7441 |
self assert:('1:' isKeywordSelector not). |
|
7442 |
self assert:('a:' isKeywordSelector). |
|
7443 |
self assert:('_:' isKeywordSelector). |
|
7444 |
self assert:('_a:' isKeywordSelector). |
|
7445 |
self assert:('_1:' isKeywordSelector). |
|
7446 |
self assert:('_1::' isKeywordSelector not). |
|
7447 |
self assert:('_:_:' isKeywordSelector). |
|
7448 |
self assert:('a:b:' isKeywordSelector). |
|
7449 |
self assert:('aa:bb:' isKeywordSelector). |
|
7450 |
self assert:('aa:bb:a' isKeywordSelector not). |
|
7451 |
self assert:('1:2:' isKeywordSelector not). |
|
7452 |
" |
|
7453 |
! |
|
7454 |
||
10431 | 7455 |
isNameSpaceSelector |
7456 |
"Answer true if the receiver contains chars which form a nameSpace selector name. |
|
7457 |
These are of the form ':<ns>::<sel>', where ns is the NameSpace and sel is the regular selector. |
|
7458 |
For example, the #+ selector as seen by the Foo namespace would be actually #':Foo::+'. |
|
17511 | 7459 |
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
|
7460 |
is legal, and this can be checked quickly by just looking at the first character. |
10431 | 7461 |
You cannot easily change this algorithm here, as it is also known by the VM's lookup function." |
7462 |
||
7463 |
|i| |
|
7464 |
||
16733 | 7465 |
(self at:1) == $: ifFalse:[^ false]. |
17511 | 7466 |
|
10431 | 7467 |
i := self indexOf:$: startingAt:2. |
7468 |
i == 0 ifTrue:[^ false]. |
|
7469 |
self size <= (i+1) ifTrue:[^ false]. |
|
7470 |
(self at:i+1) == $: ifFalse:[^ false]. |
|
7471 |
(self at:i+2) == $: ifTrue:[^ false]. |
|
7472 |
"/ could check if the rest after the ns-prefix and colons is a valid selector... |
|
7473 |
^ true |
|
7474 |
||
7475 |
"test: |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7476 |
self assert:('+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7477 |
self assert:(':+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7478 |
self assert:(':Foo:+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7479 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7480 |
self assert:(':Foo::+' isNameSpaceSelector). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7481 |
self assert:(':Foo::bar:baz:' isNameSpaceSelector). |
10431 | 7482 |
" |
7483 |
||
7484 |
"Created: / 05-03-2007 / 11:35:31 / cg" |
|
7485 |
! |
|
7486 |
||
9192 | 7487 |
isNumeric |
7488 |
"return true, if the receiver is some numeric word; |
|
7489 |
i.e. consists only of digits." |
|
7490 |
||
7491 |
self size == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7492 |
^ false |
9192 | 7493 |
]. |
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7494 |
^ self conform:[:char | char isDigit] |
9192 | 7495 |
|
7496 |
" |
|
7497 |
'helloWorld' isNumeric |
|
7498 |
'foo1234' isNumeric |
|
7499 |
'f1234' isNumeric |
|
7500 |
'1234' isNumeric |
|
7501 |
'+' isNumeric |
|
7502 |
" |
|
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7503 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7504 |
"Modified: / 13-10-2006 / 12:54:12 / cg" |
9192 | 7505 |
! |
7506 |
||
18893 | 7507 |
isPlainString |
7508 |
"return true, if the receiver is a plain string (without attributes); |
|
7509 |
true is returned here - redefinition of Object>>isPlainString." |
|
7510 |
||
7511 |
^ true |
|
7512 |
! |
|
7513 |
||
9230 | 7514 |
isString |
7515 |
"return true, if the receiver is some kind of string; |
|
7516 |
true is returned here - redefinition of Object>>isString." |
|
7517 |
||
7518 |
^ true |
|
7519 |
! |
|
7520 |
||
7521 |
isUnarySelector |
|
7522 |
"Answer true if the receiver contains only chars in an ANSI unary method selector, false otherwise." |
|
7523 |
||
17442 | 7524 |
^ (self first isLetterOrUnderline) |
9845 | 7525 |
and:[ self conform: [ :chr | chr isLetterOrDigit or:[chr == $_] ]] |
7526 |
||
7527 |
"Modified: / 13-09-2006 / 11:35:15 / cg" |
|
9230 | 7528 |
! |
7529 |
||
14122 | 7530 |
isUnicode16String |
7531 |
^ false |
|
7532 |
! |
|
7533 |
||
7534 |
isUnicode32String |
|
7535 |
^ false |
|
7536 |
! |
|
7537 |
||
7538 |
isUnicodeString |
|
7539 |
^ false |
|
7540 |
! |
|
7541 |
||
9230 | 7542 |
isValidSmalltalkIdentifier |
19464 | 7543 |
"return true, if the receiver's characters make up a valid smalltalk identifier" |
9230 | 7544 |
|
7545 |
|scanner tok| |
|
7546 |
||
7547 |
scanner := Compiler new. |
|
7548 |
scanner source:(self readStream). |
|
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
7549 |
Parser parseErrorSignal handle:[:ex | |
19464 | 7550 |
tok := nil. |
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
7551 |
] do:[ |
19464 | 7552 |
tok := scanner nextToken. |
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
7553 |
]. |
9230 | 7554 |
tok ~~ #Identifier ifTrue:[ |
19464 | 7555 |
^ false |
9230 | 7556 |
]. |
7557 |
scanner tokenPosition == 1 ifFalse:[^ false]. |
|
7558 |
^ scanner sourceStream atEnd. |
|
7559 |
||
7560 |
" |
|
7561 |
'foo' isValidSmalltalkIdentifier |
|
7562 |
'1foo' isValidSmalltalkIdentifier |
|
7563 |
'_foo' isValidSmalltalkIdentifier |
|
7564 |
'_foo_bar_' isValidSmalltalkIdentifier |
|
7565 |
'foo ' isValidSmalltalkIdentifier |
|
7566 |
' foo' isValidSmalltalkIdentifier |
|
7567 |
" |
|
7568 |
! |
|
7569 |
||
14555 | 7570 |
isWideString |
19580 | 7571 |
"true if I require more than one byte per character" |
7572 |
||
15829 | 7573 |
|string| |
7574 |
||
7575 |
(string := self string) ~~ self ifTrue:[ |
|
19580 | 7576 |
^ string isWideString. |
15829 | 7577 |
]. |
7578 |
^ self contains:[:aCharacter | aCharacter codePoint > 16rFF]. |
|
14555 | 7579 |
! |
7580 |
||
9192 | 7581 |
numArgs |
18463 | 7582 |
<resource: #obsolete> |
608 | 7583 |
"treating the receiver as a message selector, return how many arguments would it take" |
7584 |
||
18463 | 7585 |
^ self argumentCount |
9192 | 7586 |
! |
7587 |
||
7588 |
partsIfSelector |
|
14629 | 7589 |
"treat the receiver as a message selector, return a collection of parts. |
7590 |
Notice: this is more tolerant than Smalltalk's syntax would suggest; |
|
7591 |
especially it allows for empty keyword parts between colons. |
|
7592 |
This is not (and should not be checked here), to allow parsing of |
|
7593 |
degenerate selectors as appearing with objectiveC." |
|
608 | 7594 |
|
9192 | 7595 |
|idx1 "{ Class: SmallInteger }" |
7596 |
coll idx2 sz| |
|
7597 |
||
7598 |
coll := OrderedCollection new. |
|
7599 |
idx1 := 1. |
|
7600 |
sz := self size. |
|
16245 | 7601 |
[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7602 |
idx2 := self indexOf:$: startingAt:idx1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7603 |
(idx2 == 0 or:[idx2 == sz]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7604 |
coll add:(self copyFrom:idx1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7605 |
^ coll |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7606 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7607 |
coll add:(self copyFrom:idx1 to:idx2). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7608 |
idx1 := idx2 + 1 |
16245 | 7609 |
] loop. |
9192 | 7610 |
|
7611 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7612 |
'foo:' partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7613 |
'foo:bar:' partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7614 |
'foo::::' partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7615 |
#foo:bar: partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7616 |
'hello' partsIfSelector |
9192 | 7617 |
'+' partsIfSelector |
7618 |
" |
|
64 | 7619 |
! ! |
7620 |
||
9192 | 7621 |
!CharacterArray methodsFor:'tracing'! |
7622 |
||
7623 |
traceInto:aRequestor level:level from:referrer |
|
7624 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
7625 |
||
7626 |
^ aRequestor traceCharacterArray:self level:level from:referrer |
|
7627 |
||
7628 |
||
7629 |
! ! |
|
7630 |
||
7631 |
!CharacterArray methodsFor:'visiting'! |
|
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7632 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7633 |
acceptVisitor:aVisitor with:aParameter |
16733 | 7634 |
"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
|
7635 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7636 |
^ aVisitor visitString:self with:aParameter |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7637 |
! ! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7638 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
7639 |
!CharacterArray class methodsFor:'documentation'! |
629 | 7640 |
|
7641 |
version |
|
18476 | 7642 |
^ '$Header$' |
12058 | 7643 |
! |
7644 |
||
7645 |
version_CVS |
|
18476 | 7646 |
^ '$Header$' |
629 | 7647 |
! ! |
6809 | 7648 |
|
14606 | 7649 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
7650 |
CharacterArray initialize! |