author | Claus Gittinger <cg@exept.de> |
Sat, 16 Jan 2016 20:38:41 +0100 | |
changeset 19039 | ef85a80a62ea |
parent 19033 | 64260c2d67b8 |
child 19042 | b81f2c85df7d |
child 19171 | b6405bcb8e75 |
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. |
|
758 |
Abstract subclasses must redefine again." |
|
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 |
|
899 |
replChar:oldChar with:newChar |
|
900 |
"return a copy of the receiver, with all oldChars replaced |
|
901 |
by newChar. |
|
902 |
This is an ST/V compatibility method." |
|
903 |
||
3656 | 904 |
^ self copyReplaceAll:oldChar with:newChar |
608 | 905 |
|
906 |
" |
|
8874 | 907 |
'12345678901234567890' replChar:$0 with:$* |
608 | 908 |
" |
3656 | 909 |
|
910 |
"Modified: / 18.7.1998 / 22:52:57 / cg" |
|
608 | 911 |
! |
912 |
||
913 |
replChar:oldChar withString:newString |
|
914 |
"return a copy of the receiver, with all oldChars replaced |
|
915 |
by newString (i.e. slice in the newString in place of the oldChar). |
|
916 |
This is an ST/V compatibility method." |
|
917 |
||
918 |
|tmpStream| |
|
919 |
||
15523 | 920 |
tmpStream := self species writeStream. |
608 | 921 |
self do:[:element | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
922 |
element = oldChar ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
923 |
tmpStream nextPutAll:newString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
924 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
925 |
tmpStream nextPut:element |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
926 |
]. |
608 | 927 |
]. |
928 |
^ tmpStream contents |
|
929 |
||
930 |
" |
|
8874 | 931 |
'12345678901234567890' replChar:$0 withString:'foo' |
932 |
'a string with spaces' replChar:$ withString:' foo ' |
|
608 | 933 |
" |
9192 | 934 |
! |
935 |
||
936 |
replString:subString withString:newString |
|
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
937 |
"return a copy of the receiver, with all sequences of subString replaced |
18390 | 938 |
by newString (i.e. slice in the newString in place of the oldString). |
939 |
This is an ST/V compatibility method." |
|
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
940 |
|
8347 | 941 |
^ self copyReplaceString:subString withString:newString |
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
942 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
943 |
" |
8874 | 944 |
'12345678901234567890' replString:'123' withString:'OneTwoThree' |
945 |
'12345678901234567890' replString:'123' withString:'*' |
|
946 |
'12345678901234567890' replString:'234' withString:'foo' |
|
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
947 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
948 |
('a string with spaces' replChar:$ withString:' foo ') |
18390 | 949 |
replString:'foo' withString:'bar' |
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
950 |
" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
951 |
|
8347 | 952 |
"Modified: / 12-05-2004 / 12:00:27 / cg" |
9192 | 953 |
! |
954 |
||
9275 | 955 |
subString:start to:end |
18390 | 956 |
"same as copyFrom:to: |
957 |
This is an ST/V compatibility method." |
|
958 |
||
9275 | 959 |
^ self copyFrom:start to:end |
960 |
||
961 |
" |
|
962 |
'12345678901234567890' subString:3 to:8 |
|
963 |
" |
|
964 |
! |
|
965 |
||
9192 | 966 |
trimBlanks |
14992 | 967 |
"return a copy of the receiver without leading and trailing spaces. |
18464 | 968 |
This is an ST/V compatibility method and an alias for withoutSpaces." |
9192 | 969 |
|
970 |
^ self withoutSpaces |
|
971 |
||
972 |
" |
|
973 |
' spaces at beginning' trimBlanks |
|
974 |
'spaces at end ' trimBlanks |
|
975 |
' spaces at beginning and end ' trimBlanks |
|
976 |
'no spaces' trimBlanks |
|
977 |
" |
|
978 |
! ! |
|
979 |
||
980 |
!CharacterArray methodsFor:'Compatibility-Squeak'! |
|
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
981 |
|
6148 | 982 |
asDate |
983 |
"Many allowed forms, see Date.readFrom:" |
|
984 |
||
985 |
^ Date readFrom: (ReadStream on: self) |
|
986 |
||
987 |
" |
|
8874 | 988 |
'30 Apr 1999' asDate dayName capitalized |
6148 | 989 |
" |
990 |
! |
|
991 |
||
16051 | 992 |
asOneByteString |
993 |
"return the receiver converted to a 'normal' string. |
|
18391 | 994 |
Same as asSingleByteString - for Squeak/Pharo compatibility." |
16051 | 995 |
|
996 |
^ self asSingleByteString |
|
997 |
! |
|
998 |
||
8971 | 999 |
asUrl |
18391 | 1000 |
"Same as asURL - for Squeak/Pharo compatibility." |
1001 |
||
8971 | 1002 |
^ self asURL |
1003 |
! |
|
1004 |
||
10840 | 1005 |
asWideString |
18391 | 1006 |
"return a two-byte string containing the same characters as the receiver. |
1007 |
Same as asTwoByteString - for Squeak/Pharo compatibility." |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1008 |
|
10840 | 1009 |
^ self asTwoByteString |
1010 |
||
1011 |
" |
|
1012 |
'abc' asWideString |
|
1013 |
" |
|
1014 |
! |
|
1015 |
||
4989 | 1016 |
capitalized |
18391 | 1017 |
"same as asUppercaseFirst for Squeak/Pharo compatibility" |
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1018 |
|
4989 | 1019 |
^ self asUppercaseFirst |
1020 |
||
1021 |
" |
|
1022 |
'hello' capitalized |
|
1023 |
" |
|
1024 |
! |
|
1025 |
||
10841 | 1026 |
caseInsensitiveLessOrEqual:aString |
18391 | 1027 |
"compare the receiver against the argument ignoring case differences |
1028 |
For Squeak/Pharo compatibility" |
|
1029 |
||
10841 | 1030 |
^ (self compareCaselessWith:aString) <= 0 |
1031 |
! |
|
1032 |
||
1033 |
caseSensitiveLessOrEqual:aString |
|
18391 | 1034 |
"compare the receiver against the argument caring for case differences |
1035 |
For Squeak/Pharo compatibility" |
|
1036 |
||
10841 | 1037 |
^ self <= aString |
1038 |
! |
|
1039 |
||
1040 |
charactersExactlyMatching:aString |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1041 |
"return the number of characters I share as a prefix with the argument, aString" |
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1042 |
|
10841 | 1043 |
|idx nMax| |
1044 |
||
1045 |
nMax :=(self size) min:(aString size). |
|
1046 |
idx := 1. |
|
1047 |
[idx <= nMax] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1048 |
(self at:idx) = (aString at:idx) ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1049 |
^ idx - 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1050 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1051 |
idx := idx + 1. |
10841 | 1052 |
]. |
1053 |
^ nMax |
|
1054 |
||
1055 |
" |
|
12177 | 1056 |
'abc' charactersExactlyMatching:'abc' |
1057 |
'abc' charactersExactlyMatching:'abcd' |
|
1058 |
'abcd' charactersExactlyMatching:'abc' |
|
1059 |
'abc' charactersExactlyMatching:'abd' |
|
1060 |
'abc' charactersExactlyMatching:'xxx' |
|
10841 | 1061 |
" |
1062 |
! |
|
1063 |
||
9192 | 1064 |
endsWithDigit |
1065 |
"Answer whether the receiver's final character represents a digit. 3/11/96 sw" |
|
1066 |
||
18391 | 1067 |
|len| |
1068 |
||
1069 |
^ (len := self size) > 0 and: [(self at:len) isDigit] |
|
9192 | 1070 |
! |
1071 |
||
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
1072 |
findDelimiters:delimiters startingAt:start |
18391 | 1073 |
"Answer the index of the character within the receiver, starting at start, |
1074 |
that matches one of the delimiters. |
|
1075 |
If the receiver does not contain any of the delimiters, answer size + 1." |
|
9192 | 1076 |
|
1077 |
|idx| |
|
1078 |
||
1079 |
idx := self indexOfAny:delimiters startingAt:start. |
|
1080 |
idx == 0 ifTrue:[^ self size + 1]. |
|
1081 |
^ idx. |
|
1082 |
"/start to: self size do: [:i | |
|
1083 |
"/ |char| |
|
1084 |
"/ |
|
1085 |
"/ char := self at: i. |
|
1086 |
"/ delimiters do: [:delim | delim = char ifTrue: [^ i]] |
|
8971 | 1087 |
"/ ]. |
1088 |
"/ ^ self size + 1 |
|
1089 |
! |
|
1090 |
||
13624 | 1091 |
findTokens:delimiterOrDelimiters |
7270 | 1092 |
"cg: I am not sure, if this is really the squeak semantics (w.r.t. empty fields)" |
1093 |
||
13624 | 1094 |
delimiterOrDelimiters size == 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1095 |
^ self asCollectionOfSubstringsSeparatedBy:delimiterOrDelimiters |
13624 | 1096 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1097 |
^ self asCollectionOfSubstringsSeparatedByAny:delimiterOrDelimiters |
13624 | 1098 |
]. |
7270 | 1099 |
|
1100 |
" |
|
8874 | 1101 |
'a|b#c||e' findTokens:#($# $|) |
13624 | 1102 |
'a|b#c||e' findTokens:$| |
1103 |
" |
|
1104 |
||
1105 |
"Modified: / 04-09-2011 / 20:31:21 / cg" |
|
1106 |
"Modified (comment): / 05-09-2011 / 04:25:28 / cg" |
|
4981 | 1107 |
! |
1108 |
||
4974 | 1109 |
includesSubString:aString |
1110 |
"return true, if a substring is contained in the receiver. |
|
1111 |
The compare is case sensitive." |
|
1112 |
||
1113 |
^ self includesString:aString |
|
1114 |
||
1115 |
" |
|
8874 | 1116 |
'hello world' includesSubString:'Hel' |
9192 | 1117 |
'hello world' includesSubString:'hel' |
1118 |
'hello world' includesSubString:'llo' |
|
1119 |
" |
|
1120 |
||
1121 |
||
1122 |
||
1123 |
! |
|
1124 |
||
11178 | 1125 |
includesSubString:aString caseSensitive:caseSensitive |
18391 | 1126 |
"sigh - an alias; added for Squeak/Pharo compatibility" |
1127 |
||
11179 | 1128 |
^ self includesSubstring:aString caseSensitive:caseSensitive |
11178 | 1129 |
! |
1130 |
||
16875
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1131 |
includesSubstring: aString |
18391 | 1132 |
"sigh - an alias; added for Squeak/Pharo compatibility" |
1133 |
||
16875
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1134 |
^ self includesSubString: aString |
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1135 |
|
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1136 |
"Created: / 03-10-2014 / 02:47:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1137 |
! |
32e61bb3a742
class: CharacterArray>>#includesSubstring: (for Squeak compatibility)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16863
diff
changeset
|
1138 |
|
9192 | 1139 |
includesSubstring:aString caseSensitive:caseSensitive |
9190 | 1140 |
"return true, if a substring is contained in the receiver. |
9192 | 1141 |
The argument, caseSensitive controls if case is ignored in the compare." |
1142 |
||
1143 |
"/ for now, a q&d hack ... |
|
1144 |
||
1145 |
caseSensitive ifFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1146 |
^ self asLowercase includesString:aString asLowercase |
9192 | 1147 |
]. |
9190 | 1148 |
^ self includesString:aString |
1149 |
||
1150 |
" |
|
9192 | 1151 |
'hello world' includesSubstring:'Hel' caseSensitive:true |
1152 |
'hello world' includesSubstring:'Hel' caseSensitive:false |
|
1153 |
" |
|
1154 |
||
1155 |
||
1156 |
||
1157 |
! |
|
9190 | 1158 |
|
6979 | 1159 |
isAllDigits |
1160 |
"Answer whether the receiver's characters are all digits" |
|
1161 |
||
1162 |
^ self conform:[:eachChar | eachChar isDigit] |
|
1163 |
||
1164 |
" |
|
1165 |
'hello world' isAllDigits |
|
1166 |
'12344' isAllDigits |
|
1167 |
" |
|
1168 |
! |
|
1169 |
||
4890 | 1170 |
lastSpacePosition |
18391 | 1171 |
"return the index of the last space character; 0 if there is none. |
1172 |
Added for Squeak/Pharo compatibility" |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
1173 |
|
4890 | 1174 |
^ self lastIndexOfSeparator |
1175 |
! |
|
1176 |
||
7022 | 1177 |
padded:leftOrRight to:paddedSize with:padCharacter |
14053
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1178 |
"pad left (leftOrRight==#left) or right" |
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1179 |
|
7022 | 1180 |
leftOrRight == #left ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1181 |
^ self leftPaddedTo:paddedSize with:padCharacter |
9190 | 1182 |
]. |
1183 |
^ self paddedTo:paddedSize with:padCharacter |
|
1184 |
||
1185 |
" |
|
8874 | 1186 |
'hello' padded:#right to:10 with:$. |
9192 | 1187 |
'hello' padded:#left to:10 with:$. |
1188 |
" |
|
14053
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1189 |
|
acbb97913c30
comment/format in: #padded:to:with:
Claus Gittinger <cg@exept.de>
parents:
14050
diff
changeset
|
1190 |
"Modified (comment): / 07-03-2012 / 16:31:33 / cg" |
9192 | 1191 |
! |
1192 |
||
1193 |
skipDelimiters:delimiters startingAt:start |
|
1194 |
"Answer the index of the character within the receiver, starting at start, |
|
1195 |
that does NOT match one of the delimiters. |
|
1196 |
If the receiver does not contain any of the delimiters, answer size + 1. |
|
1197 |
Assumes the delimiters to be a non-empty string." |
|
1198 |
||
1199 |
start to:self size do:[:i | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1200 |
delimiters detect:[:delim | delim = (self at:i) ] ifNone:[ ^ i ] |
9192 | 1201 |
]. |
1202 |
^ self size + 1 |
|
1203 |
||
1204 |
" |
|
1205 |
'123***7890' skipDelimiters:'*' startingAt:4 |
|
1206 |
'123***7890' skipDelimiters:'*' startingAt:3 |
|
9190 | 1207 |
'123***7890' skipDelimiters:'*' startingAt:10 |
1208 |
'123*******' skipDelimiters:'*' startingAt:10 |
|
8874 | 1209 |
" |
1210 |
! |
|
1211 |
||
9190 | 1212 |
substrings |
18921 | 1213 |
"return a collection consisting of all words contained in the receiver. |
17517 | 1214 |
Words are separated by whitespace. |
1215 |
This has been added for Squeak compatibility. |
|
1216 |
(sigh: it is called #'subStrings' in V'Age, and #'asCollectionOfWords' in ST/X) " |
|
1217 |
||
9190 | 1218 |
^ self asCollectionOfWords |
1219 |
||
1220 |
" |
|
1221 |
'foo bar baz' substrings |
|
1222 |
" |
|
1223 |
! |
|
1224 |
||
12665
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1225 |
substringsSeparatedBy:separatorCharacter |
18921 | 1226 |
"return a collection consisting of all words contained in the receiver. |
1227 |
Words are separated by the given separator character. |
|
1228 |
This has been added for Squeak/Pharo compatibility. |
|
1229 |
(sigh: it is called #'subStrings:' in V'Age, |
|
1230 |
and #'asCollectionOfSubstringsSeparatedBy' in ST/X) " |
|
18391 | 1231 |
|
12665
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1232 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1233 |
|
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1234 |
" |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1235 |
'foo bar, baz' substringsSeparatedBy:$, |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1236 |
" |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1237 |
! |
b027fc5aec4e
added: #substringsSeparatedBy:
Claus Gittinger <cg@exept.de>
parents:
12664
diff
changeset
|
1238 |
|
9190 | 1239 |
truncateTo:smallSize |
9192 | 1240 |
"return myself or a copy shortened to smallSize. 1/18/96 sw" |
1241 |
||
1242 |
self size <= smallSize ifTrue:[^ self]. |
|
1243 |
^ self copyFrom: 1 to: smallSize |
|
1244 |
||
1245 |
" |
|
1246 |
'hello world' truncateTo:5 |
|
1247 |
'hello' truncateTo:10 |
|
1248 |
||
1249 |
'hello world' copyTo:5 |
|
1250 |
'hello' copyTo:10 |
|
1251 |
" |
|
1252 |
! |
|
5795 | 1253 |
|
4890 | 1254 |
withBlanksTrimmed |
18464 | 1255 |
"Return a copy of the receiver from which leading and trailing whitespace have been trimmed. |
1256 |
Notice the bad naming - it is trimming separators, not just blanks. |
|
1257 |
Added for Squeak compatibility and an alias for withoutSeparators" |
|
4890 | 1258 |
|
14865 | 1259 |
^ self withoutSeparators "withoutSpaces" "/ cg: it seems that squeak cares for any whitespace |
4890 | 1260 |
|
1261 |
" |
|
8874 | 1262 |
' hello world ' withBlanksTrimmed |
4890 | 1263 |
" |
1264 |
! |
|
1265 |
||
1266 |
withNoLineLongerThan: aNumber |
|
1267 |
"Answer a string with the same content as receiver, but rewrapped so that no line has more characters than the given number" |
|
1268 |
||
9192 | 1269 |
| listOfLines currentLast currentStart resultString putativeLast putativeLine crPosition | |
1270 |
||
14451
c06e7885b675
changed: #withNoLineLongerThan:
Claus Gittinger <cg@exept.de>
parents:
14420
diff
changeset
|
1271 |
(aNumber isNumber not or:[ aNumber < 1] ) ifTrue: [self error: 'too narrow']. |
9192 | 1272 |
listOfLines _ OrderedCollection new. |
1273 |
currentLast _ 0. |
|
1274 |
[currentLast < self size] whileTrue: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1275 |
[currentStart _ currentLast + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1276 |
putativeLast _ (currentStart + aNumber - 1) min: self size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1277 |
putativeLine _ self copyFrom: currentStart to: putativeLast. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1278 |
(crPosition _ putativeLine indexOf: Character cr) > 0 ifTrue: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1279 |
[putativeLast _ currentStart + crPosition - 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1280 |
putativeLine _ self copyFrom: currentStart to: putativeLast]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1281 |
currentLast _ putativeLast == self size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1282 |
ifTrue: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1283 |
[putativeLast] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1284 |
ifFalse: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1285 |
[currentStart + putativeLine lastSpacePosition - 1]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1286 |
currentLast <= currentStart ifTrue: |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1287 |
["line has NO spaces; baleout!!" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1288 |
currentLast _ putativeLast]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1289 |
listOfLines add: (self copyFrom: currentStart to: currentLast) withBlanksTrimmed]. |
9192 | 1290 |
|
1291 |
listOfLines size > 0 ifFalse: [^ '']. |
|
1292 |
resultString _ listOfLines first. |
|
1293 |
2 to: listOfLines size do: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1294 |
[:i | resultString _ resultString, Character cr asString, (listOfLines at: i)]. |
9192 | 1295 |
^ resultString |
1296 |
||
1297 |
" |
|
1298 |
#(5 7 20) collect: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1299 |
[: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
|
1300 |
" |
10883 | 1301 |
! |
1302 |
||
12343
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1303 |
withSqueakLineEndings |
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1304 |
"assume the string is textual, and that CR, LF, and CRLF are all |
18391 | 1305 |
valid line endings. Replace each occurence with a single CR" |
12343
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1306 |
|
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1307 |
^ self asStringCollection asStringWith:Character cr. |
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1308 |
! |
0a93eee37d65
added: #withSqueakLineEndings
Claus Gittinger <cg@exept.de>
parents:
12330
diff
changeset
|
1309 |
|
12188 | 1310 |
withoutLeading: char |
1311 |
"return a copy of myself without leading a char. |
|
1312 |
Returns an empty string, if the receiver consist only of a char." |
|
1313 |
||
1314 |
^ self withoutLeadingForWhich:[:ch | ch = char] |
|
1315 |
||
1316 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1317 |
'****foo****' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1318 |
'foo****' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1319 |
'*' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1320 |
'' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1321 |
'****foo' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1322 |
'*******' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1323 |
'foo' withoutLeading: $* |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1324 |
'f***o***o' withoutLeading: $* |
12188 | 1325 |
('**' , Character tab asString , '*foo***') withoutLeading: $* inspect |
1326 |
" |
|
1327 |
! |
|
1328 |
||
11565 | 1329 |
withoutTrailing:char |
1330 |
"return a copy of myself without trailing char. |
|
1331 |
Returns an empty string, if the receiver consist only of char." |
|
1332 |
||
12188 | 1333 |
^ self withoutTrailingForWhich:[:ch | ch = char] |
1334 |
||
1335 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1336 |
' foo....' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1337 |
'foo....' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1338 |
' foo' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1339 |
'.......' withoutTrailing:$. |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
1340 |
'foo' withoutTrailing:$. |
11565 | 1341 |
" |
9190 | 1342 |
! ! |
1343 |
||
1344 |
!CharacterArray methodsFor:'Compatibility-V''Age'! |
|
1345 |
||
1346 |
addLineDelimiter |
|
1347 |
"replace all '\'-characters by line delimiter (cr) - characters. |
|
9192 | 1348 |
This has been added for VisualAge compatibility." |
1349 |
||
1350 |
^ self withCRs |
|
1351 |
! |
|
1352 |
||
1353 |
bindWith:aString |
|
1354 |
"return a copy of the receiver, where a '%1' escape is |
|
1355 |
replaced by aString. |
|
1356 |
This has been added for VisualAge compatibility." |
|
1357 |
||
1358 |
^ self expandPlaceholdersWith:(Array with:aString) |
|
1359 |
||
1360 |
" |
|
1361 |
'do you like %1 ?' bindWith:'smalltalk' |
|
1362 |
" |
|
1363 |
! |
|
608 | 1364 |
|
1365 |
bindWith:string1 with:string2 |
|
1366 |
"return a copy of the receiver, where a '%1' escape is |
|
1367 |
replaced by string1 and '%2' is replaced by string2. |
|
1368 |
This has been added for VisualAge compatibility." |
|
1369 |
||
1370 |
^ self expandPlaceholdersWith:(Array with:string1 with:string2) |
|
1371 |
||
1372 |
" |
|
1373 |
'do you prefer %1 or rather %2 ?' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1374 |
bindWith:'smalltalk' with:'c++' |
9192 | 1375 |
" |
1376 |
! |
|
9190 | 1377 |
|
1378 |
bindWith:str1 with:str2 with:str3 |
|
608 | 1379 |
"return a copy of the receiver, where a '%1', '%2' and '%3' escapes |
1380 |
are replaced by str1, str2 and str3 respectively. |
|
1381 |
This has been added for VisualAge compatibility." |
|
1382 |
||
1383 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3) |
|
1384 |
||
1385 |
" |
|
9192 | 1386 |
'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
|
1387 |
bindWith:'smalltalk' with:'c++' with:'c' |
9192 | 1388 |
" |
1389 |
! |
|
608 | 1390 |
|
1391 |
bindWith:str1 with:str2 with:str3 with:str4 |
|
1392 |
"return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes |
|
1393 |
are replaced by str1, str2, str3 and str4 respectively. |
|
1394 |
This has been added for VisualAge compatibility." |
|
1395 |
||
1396 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4) |
|
1397 |
||
1398 |
" |
|
9192 | 1399 |
'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
|
1400 |
bindWith:'smalltalk' with:'c++' with:'c' with:'assembler' |
9192 | 1401 |
" |
1402 |
! |
|
608 | 1403 |
|
2344 | 1404 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 |
1405 |
"return a copy of the receiver, where a '%1' .. '%5' escapes |
|
1406 |
are replaced by str1 .. str5 respectively. |
|
1407 |
This has been added for VisualAge compatibility." |
|
1408 |
||
1409 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5) |
|
1410 |
||
1411 |
"Created: 31.1.1997 / 16:25:42 / cg" |
|
1412 |
! |
|
1413 |
||
5343 | 1414 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 |
1415 |
"return a copy of the receiver, where a '%1' .. '%6' escapes |
|
11524 | 1416 |
are replaced by str1 .. str6 respectively. |
5343 | 1417 |
This has been added for VisualAge compatibility." |
1418 |
||
8874 | 1419 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1420 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1421 |
with:str5 with:str6) |
11524 | 1422 |
! |
1423 |
||
1424 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 with:str7 |
|
1425 |
"return a copy of the receiver, where a '%1' .. '%7' escapes |
|
1426 |
are replaced by str1 .. str7 respectively. |
|
1427 |
This has been added for VisualAge compatibility." |
|
1428 |
||
1429 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1430 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1431 |
with:str5 with:str6 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1432 |
with:str7) |
5343 | 1433 |
! |
1434 |
||
13996
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1435 |
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
|
1436 |
"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
|
1437 |
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
|
1438 |
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
|
1439 |
|
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1440 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1441 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1442 |
with:str5 with:str6 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1443 |
with:str7 with:str8) |
13996
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1444 |
|
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1445 |
"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
|
1446 |
! |
a86faa4f17b8
added: #bindWith:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13987
diff
changeset
|
1447 |
|
14014
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1448 |
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
|
1449 |
"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
|
1450 |
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
|
1451 |
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
|
1452 |
|
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1453 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1454 |
with:str3 with:str4 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1455 |
with:str5 with:str6 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1456 |
with:str7 with:str8 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1457 |
with:str9) |
14014
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1458 |
|
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1459 |
"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
|
1460 |
! |
3aff2d7c41c8
added: #bindWith:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
13996
diff
changeset
|
1461 |
|
608 | 1462 |
bindWithArguments:anArrayOfStrings |
1463 |
"return a copy of the receiver, where a '%i' escape |
|
1464 |
is replaced by the coresponding string from the argument array. |
|
1465 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
1466 |
This has been added for VisualAge compatibility." |
|
1467 |
||
9192 | 1468 |
^ self expandPlaceholdersWith:anArrayOfStrings |
1469 |
||
1470 |
" |
|
1471 |
'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
|
1472 |
bindWithArguments:#('smalltalk' 'c++' 'c') |
12196 | 1473 |
|
1474 |
'do you %(what) ?' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1475 |
bindWithArguments:(Dictionary new at:#'what' put:'understand'; yourself) |
9192 | 1476 |
" |
1477 |
! |
|
608 | 1478 |
|
1479 |
subStrings |
|
18921 | 1480 |
"return a collection consisting of all words contained in the receiver. |
608 | 1481 |
Words are separated by whitespace. |
17517 | 1482 |
This has been added for VisualAge compatibility. |
1483 |
(sigh: it is called #'subbtrings' in Squeak, and #'asCollectionOfWords' in ST/X) " |
|
608 | 1484 |
|
1485 |
^ self asCollectionOfWords |
|
1486 |
||
1487 |
" |
|
1488 |
'hello world, this is smalltalk' subStrings |
|
1489 |
" |
|
1490 |
! |
|
1491 |
||
16181 | 1492 |
subStrings:separatorCharacterOrString |
18921 | 1493 |
"return a collection consisting of all words contained in the receiver. |
608 | 1494 |
Words are separated by separatorCharacter. |
18921 | 1495 |
This is similar to split: (squeak) and asCollectionOfSubstringsSeparatedBy: (st/x) |
1496 |
and has been added for VisualAge compatibility." |
|
608 | 1497 |
|
16181 | 1498 |
separatorCharacterOrString isCharacter ifTrue:[ |
18921 | 1499 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacterOrString |
16181 | 1500 |
]. |
1501 |
^ self asCollectionOfSubstringsSeparatedByAny:separatorCharacterOrString |
|
1502 |
||
1503 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1504 |
'foo:bar:baz:smalltalk' subStrings:$: |
16181 | 1505 |
'foo:bar:baz:smalltalk' subStrings:':' |
1506 |
'foo.bar,baz-smalltalk' subStrings:'.,-' |
|
9192 | 1507 |
" |
1508 |
! |
|
1509 |
||
1510 |
trimSeparators |
|
18392 | 1511 |
"return a copy of the receiver without leading and trailing whiteSpace. |
18921 | 1512 |
Added for VisualAge compatibility (an alias for withoutSeparators)" |
9192 | 1513 |
|
1514 |
^ self withoutSeparators |
|
1515 |
! ! |
|
1516 |
||
1517 |
!CharacterArray methodsFor:'Compatibility-VW'! |
|
5964 | 1518 |
|
6139 | 1519 |
asLogicalFileSpecification |
1520 |
^ self asFilename |
|
1521 |
||
1522 |
"Created: / 30.10.2001 / 17:29:53 / cg" |
|
1523 |
! |
|
1524 |
||
5964 | 1525 |
expandMacros |
1526 |
"ST80 compatibility - expand '<..>' macros with |
|
1527 |
argument strings. Similar to #bindWith:. |
|
1528 |
Read the comment in #expandMacrosWithArguments: about |
|
1529 |
limited compatibility issues." |
|
1530 |
||
1531 |
^ self expandMacrosWithArguments:#() |
|
1532 |
||
1533 |
" |
|
1534 |
'hello<n>foo' expandMacros |
|
1535 |
" |
|
1536 |
||
9192 | 1537 |
"Modified: / 18.6.1998 / 16:03:02 / cg" |
1538 |
! |
|
1539 |
||
1540 |
expandMacrosWith:arg |
|
5964 | 1541 |
"ST80 compatibility - expand '<..>' macros with |
1542 |
argument strings. Similar to #bindWith:. |
|
1543 |
Read the comment in #expandMacrosWithArguments: about |
|
1544 |
limited compatibility issues." |
|
1545 |
||
9192 | 1546 |
^ self expandMacrosWithArguments:(Array with:arg) |
1547 |
||
1548 |
"Created: / 1.11.1997 / 13:01:28 / cg" |
|
1549 |
"Modified: / 1.11.1997 / 13:30:50 / cg" |
|
1550 |
! |
|
5964 | 1551 |
|
1552 |
expandMacrosWith:arg1 with:arg2 |
|
1553 |
"ST80 compatibility - expand '<..>' macros with |
|
1554 |
argument strings. Similar to #bindWith:. |
|
1555 |
Read the comment in #expandMacrosWithArguments: about |
|
1556 |
limited compatibility issues." |
|
1557 |
||
1558 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2) |
|
1559 |
||
1560 |
"Modified: / 6.7.1998 / 21:58:14 / cg" |
|
1561 |
! |
|
1562 |
||
1563 |
expandMacrosWith:arg1 with:arg2 with:arg3 |
|
1564 |
"ST80 compatibility - expand '<..>' macros with |
|
1565 |
argument strings. Similar to #bindWith:. |
|
1566 |
Read the comment in #expandMacrosWithArguments: about |
|
1567 |
limited compatibility issues." |
|
1568 |
||
1569 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2 with:arg3) |
|
1570 |
! |
|
1571 |
||
10353
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1572 |
expandMacrosWith:arg1 with:arg2 with:arg3 with:arg4 |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1573 |
"ST80 compatibility - expand '<..>' macros with |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1574 |
argument strings. Similar to #bindWith:. |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1575 |
Read the comment in #expandMacrosWithArguments: about |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1576 |
limited compatibility issues." |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1577 |
|
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1578 |
^ 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
|
1579 |
! |
65fb7aa2c6c2
added #expandMacrosWith:with:with:with:
Stefan Vogel <sv@exept.de>
parents:
10134
diff
changeset
|
1580 |
|
9192 | 1581 |
expandMacrosWithArguments:argArray |
5964 | 1582 |
"ST80 compatibility - expand '<..>' macros with |
1583 |
argument strings. Similar to #bindWith:. |
|
1584 |
WARNING: possibly not all ST80 expansions are supported here." |
|
1585 |
||
1586 |
"/ supported expansions: |
|
1587 |
"/ |
|
1588 |
"/ <#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
|
1589 |
"/ <#s> # is arg Number; slice in the arg itself (must know asString) |
5964 | 1590 |
"/ <#?s1:s2> # is arg Number; slice in s1 if the arg is true, s2 otherwise |
7643 | 1591 |
"/ use first arg if # is not given (i.e. no number before s,p ...) |
5964 | 1592 |
"/ <n> replace by a newLine character |
1593 |
"/ <t> replace by a tab character |
|
6834
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
1594 |
"/ %X the X character itself |
5964 | 1595 |
|
8999
f3fda66ea51e
#expandMacrosWithArguments: - be mor friendly to xml strings.
Stefan Vogel <sv@exept.de>
parents:
8971
diff
changeset
|
1596 |
|in out c fmt nr arg s1 s2 peekc| |
5964 | 1597 |
|
1598 |
in := self readStream. |
|
10721
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1599 |
out := CharacterWriteStream on:(self species uninitializedNew:self size). |
5964 | 1600 |
|
1601 |
[in atEnd] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1602 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1603 |
c == $% ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1604 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1605 |
out nextPut:c |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1606 |
] ifFalse:[c ~~ $< ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1607 |
out nextPut:c. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1608 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1609 |
peekc := in peek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1610 |
[peekc == $<] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1611 |
out nextPut:$<. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1612 |
peekc := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1613 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1614 |
peekc == $n ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1615 |
peekc := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1616 |
peekc == $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1617 |
in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1618 |
out cr. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1619 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1620 |
out nextPutAll:'<n'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1621 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1622 |
] ifFalse:[peekc == $t ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1623 |
peekc := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1624 |
peekc == $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1625 |
in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1626 |
out tab. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1627 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1628 |
out nextPutAll:'<t'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1629 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1630 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1631 |
peekc isDigit ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1632 |
"start an argument expansion ..." |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1633 |
nr := Integer readFrom:in onError:nil. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1634 |
nr isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1635 |
"this cannot happen (there is at least one digit)" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1636 |
self error:'invalid format' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1637 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1638 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1639 |
fmt := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1640 |
(fmt ~~ $? and:[in peek ~~ $>]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1641 |
out nextPut:$<. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1642 |
nr printOn:out. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1643 |
out nextPut:fmt. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1644 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1645 |
(nr between:1 and:argArray size) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1646 |
arg := argArray at:nr. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1647 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1648 |
arg := '' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1649 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1650 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1651 |
fmt == $p ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1652 |
"expand with args printString" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1653 |
arg printOn:out. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1654 |
] ifFalse:[fmt == $s ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1655 |
"expand with arg itself" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1656 |
arg isText ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1657 |
out contentsSpecies isText ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1658 |
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
|
1659 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1660 |
out nextPutAll:arg. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1661 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1662 |
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
|
1663 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1664 |
] ifFalse:[fmt == $? ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1665 |
s1 := in upTo:$:. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1666 |
s2 := in nextUpTo:$>. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1667 |
arg == true ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1668 |
out nextPutAll:s1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1669 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1670 |
out nextPutAll:s2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1671 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1672 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1673 |
"what does VW do here ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1674 |
self error:'invalid format' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1675 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1676 |
]]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1677 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1678 |
c ~~ $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1679 |
"what does VW do here ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1680 |
self error:'invalid format' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1681 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1682 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1683 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1684 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1685 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1686 |
out nextPut:$<. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1687 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1688 |
]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1689 |
]]. |
5964 | 1690 |
]. |
1691 |
^ out contents |
|
1692 |
||
1693 |
" |
|
8874 | 1694 |
'hello <1s> how are you' expandMacrosWith:(OperatingSystem getLoginName) |
1695 |
'one plus one is <1p>' expandMacrosWith:2 |
|
5964 | 1696 |
" |
1697 |
||
10721
58e6950264cb
care for bitsPerCharacter when expanding macros
Claus Gittinger <cg@exept.de>
parents:
10703
diff
changeset
|
1698 |
"Modified: / 18-09-2007 / 22:50:43 / cg" |
9192 | 1699 |
! |
1700 |
||
1701 |
isCharacters |
|
1702 |
"added for visual works compatibility" |
|
1703 |
^ true |
|
1704 |
! ! |
|
1705 |
||
16295 | 1706 |
!CharacterArray methodsFor:'JavaScript support'! |
1707 |
||
1708 |
unquote |
|
17000 | 1709 |
"removes double quotes from the receiver. |
1710 |
This is the JavaSccript standard unquote function." |
|
1711 |
||
1712 |
|mySize| |
|
1713 |
||
1714 |
(mySize := self size) >= 2 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1715 |
((self first == $") and:[self last == $"]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1716 |
^ self copyFrom:2 to:mySize-1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1717 |
]. |
16295 | 1718 |
]. |
1719 |
^ self |
|
1720 |
||
1721 |
" |
|
17000 | 1722 |
'hello' quote unquote |
1723 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1724 |
JavaScriptParser evaluate:'''hello''.quote.unquote' |
16295 | 1725 |
" |
1726 |
! ! |
|
13510 | 1727 |
|
16175 | 1728 |
|
9192 | 1729 |
!CharacterArray methodsFor:'character searching'! |
1730 |
||
1731 |
includesMatchCharacters |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
1732 |
"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
|
1733 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1734 |
Here, do not care for $\ escapes" |
608 | 1735 |
|
1736 |
^ self includesAny:'*#[' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1737 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1738 |
" |
8874 | 1739 |
'*foo' includesMatchCharacters |
1740 |
'\*foo' includesMatchCharacters |
|
1741 |
'\*foo' includesUnescapedMatchCharacters |
|
1742 |
'*foo' includesMatchCharacters |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1743 |
'\\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1744 |
'foo*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1745 |
'foo\*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1746 |
'foo\' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1747 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1748 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1749 |
"Modified: 2.4.1997 / 18:12:34 / cg" |
9192 | 1750 |
! |
1751 |
||
1752 |
includesSeparator |
|
1753 |
"return true, if the receiver contains any whitespace characters" |
|
1754 |
||
1755 |
^ (self indexOfSeparator ~~ 0) |
|
1756 |
||
1757 |
" |
|
1758 |
'hello world' includesSeparator |
|
1759 |
'helloworld' includesSeparator |
|
1760 |
" |
|
1761 |
! |
|
1762 |
||
1763 |
includesUnescapedMatchCharacters |
|
8874 | 1764 |
"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
|
1765 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1766 |
Here, care for $\ escapes" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1767 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1768 |
|idx sz specialChars escape| |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1769 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1770 |
idx := 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1771 |
sz := self size. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1772 |
specialChars := '*#[\'. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1773 |
(escape := self class matchEscapeCharacter) ~~ $\ ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1774 |
specialChars := specialChars copy. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1775 |
specialChars at:specialChars size put:escape |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1776 |
]. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1777 |
|
16245 | 1778 |
[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1779 |
idx := self indexOfAny:specialChars startingAt:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1780 |
idx == 0 ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1781 |
(self at:idx) == escape ifFalse:[^ true]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1782 |
idx := idx + 2. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1783 |
idx > sz ifTrue:[^ false]. |
16245 | 1784 |
] loop. |
8874 | 1785 |
|
1786 |
" |
|
1787 |
'*foo' includesUnescapedMatchCharacters |
|
1788 |
'\*foo' includesUnescapedMatchCharacters |
|
1789 |
'\\foo' includesUnescapedMatchCharacters |
|
1790 |
'\\\$foo' includesUnescapedMatchCharacters |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1791 |
'*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1792 |
'\\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1793 |
'foo*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1794 |
'foo\*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1795 |
'foo\' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1796 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1797 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1798 |
"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
|
1799 |
"Created: 2.4.1997 / 17:23:26 / cg" |
9192 | 1800 |
! |
1801 |
||
1802 |
indexOfControlCharacterStartingAt:startIndex |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1803 |
"return the index of the next control character; |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1804 |
that is a character with asciiValue < 32. |
15605 | 1805 |
Start the search at startIndex, searching forward. |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1806 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1807 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1808 |
|start "{ Class: SmallInteger }" |
9192 | 1809 |
mySize "{ Class: SmallInteger }"| |
1810 |
||
1811 |
start := startIndex. |
|
1812 |
mySize := self size. |
|
1813 |
||
1814 |
start to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1815 |
(self at:index) isControlCharacter ifTrue:[^ index] |
9192 | 1816 |
]. |
1817 |
^ 0 |
|
1818 |
||
1819 |
" |
|
1820 |
'hello world' asTwoByteString indexOfControlCharacterStartingAt:1 |
|
1821 |
'hello world\foo' withCRsasTwoByteString indexOfControlCharacterStartingAt:1 |
|
1822 |
" |
|
1823 |
||
1824 |
"Modified: / 21.7.1998 / 17:25:07 / cg" |
|
1825 |
! |
|
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
1826 |
|
8541 | 1827 |
indexOfNonSeparator |
1828 |
"return the index of the first non-whitespace character. |
|
1829 |
return 0 if no non-separator was found" |
|
1830 |
||
1831 |
^ self indexOfNonSeparatorStartingAt:1. |
|
1832 |
||
1833 |
" |
|
8874 | 1834 |
' hello world' indexOfNonSeparator |
1835 |
' ' indexOfNonSeparator |
|
1836 |
'a ' indexOfNonSeparator |
|
1837 |
'abc' indexOfNonSeparator |
|
1838 |
' ' indexOfNonSeparator |
|
9192 | 1839 |
'' indexOfNonSeparator |
1840 |
" |
|
1841 |
! |
|
1842 |
||
1843 |
indexOfNonSeparatorStartingAt:startIndex |
|
4117 | 1844 |
"return the index of the next non-whitespace character, |
1845 |
starting the search at startIndex, searching forward; |
|
1846 |
return 0 if no non-separator was found" |
|
608 | 1847 |
|
1848 |
|start "{ Class: SmallInteger }" |
|
1849 |
mySize "{ Class: SmallInteger }"| |
|
1850 |
||
1851 |
start := startIndex. |
|
1852 |
mySize := self size. |
|
1853 |
||
1854 |
start to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1855 |
(self at:index) isSeparator ifFalse:[^ index] |
608 | 1856 |
]. |
1857 |
^ 0 |
|
1858 |
||
1859 |
" |
|
8874 | 1860 |
' hello world' indexOfNonSeparatorStartingAt:1 |
1861 |
' ' indexOfNonSeparatorStartingAt:1 |
|
1862 |
'a ' indexOfNonSeparatorStartingAt:2 |
|
4117 | 1863 |
" |
1864 |
||
608 | 1865 |
" |
1866 |
|s index1 index2| |
|
1867 |
s := ' foo bar baz'. |
|
1868 |
index1 := s indexOfNonSeparatorStartingAt:1. |
|
1869 |
index2 := s indexOfSeparatorStartingAt:index1. |
|
1870 |
s copyFrom:index1 to:index2 - 1 |
|
1871 |
" |
|
9192 | 1872 |
! |
1873 |
||
1874 |
indexOfSeparator |
|
1875 |
"return the index of the first whitespace character; |
|
1876 |
starting the search at the beginning, searching forward; |
|
1877 |
return 0 if no separator was found" |
|
1878 |
||
1879 |
^ self indexOfSeparatorStartingAt:1 |
|
1880 |
||
1881 |
" |
|
1882 |
'hello world' indexOfSeparator |
|
1883 |
'helloworld' indexOfSeparator |
|
1884 |
'hello ' indexOfSeparator |
|
1885 |
' hello' indexOfSeparator |
|
1886 |
" |
|
1887 |
! |
|
1888 |
||
15912 | 1889 |
indexOfSeparatorOrEndStartingAt:startIndex |
1890 |
"return the index of the next whitespace character, |
|
1891 |
starting the search at startIndex, searching forward; |
|
1892 |
return the index of one behond the end of the receiver if no separator was found. |
|
1893 |
To extract the word, copy from startIndex to the returned index-1" |
|
1894 |
||
1895 |
|idx| |
|
1896 |
||
1897 |
idx := self indexOfSeparatorStartingAt:startIndex. |
|
1898 |
idx == 0 ifTrue:[^ self size + 1]. |
|
1899 |
^ idx. |
|
1900 |
||
1901 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1902 |
'hello world' indexOfSeparatorOrEndStartingAt:3 |
15912 | 1903 |
' hello world' indexOfSeparatorOrEndStartingAt:3 |
1904 |
'hello world ' indexOfSeparatorOrEndStartingAt:3 |
|
1905 |
'hello world ' indexOfSeparatorOrEndStartingAt:6 |
|
1906 |
'hello world ' indexOfSeparatorOrEndStartingAt:7 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1907 |
'helloworld ' indexOfSeparatorOrEndStartingAt:7 |
15912 | 1908 |
'helloworld' indexOfSeparatorOrEndStartingAt:7 |
1909 |
" |
|
1910 |
! |
|
1911 |
||
9192 | 1912 |
indexOfSeparatorStartingAt:startIndex |
1913 |
"return the index of the next whitespace character, |
|
1914 |
starting the search at startIndex, searching forward; |
|
1915 |
return 0 if no separator was found" |
|
1916 |
||
1917 |
|start "{ Class: SmallInteger }" |
|
1918 |
mySize "{ Class: SmallInteger }"| |
|
1919 |
||
1920 |
start := startIndex. |
|
1921 |
mySize := self size. |
|
1922 |
||
1923 |
start to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1924 |
(self at:index) isSeparator ifTrue:[^ index] |
9192 | 1925 |
]. |
1926 |
^ 0 |
|
1927 |
||
1928 |
" |
|
1929 |
'hello world' indexOfSeparatorStartingAt:3 |
|
1930 |
' hello world' indexOfSeparatorStartingAt:3 |
|
8874 | 1931 |
'hello world ' indexOfSeparatorStartingAt:3 |
1932 |
'hello world ' indexOfSeparatorStartingAt:6 |
|
1933 |
'hello world ' indexOfSeparatorStartingAt:7 |
|
1934 |
'helloworld ' indexOfSeparatorStartingAt:7 |
|
1935 |
'helloworld' indexOfSeparatorStartingAt:7 |
|
4117 | 1936 |
" |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1937 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1938 |
|
4117 | 1939 |
lastIndexOfSeparator |
14150
e13160aa321a
comment/format in: #lastIndexOfSeparator
Claus Gittinger <cg@exept.de>
parents:
14141
diff
changeset
|
1940 |
"return the last index of a whitespace character (space or tab). |
4117 | 1941 |
(i.e. start the search at the end and search backwards); |
1942 |
Returns 0 if no separator is found." |
|
1943 |
||
1944 |
^ self lastIndexOfSeparatorStartingAt:(self size) |
|
1945 |
||
1946 |
" |
|
8874 | 1947 |
'hello world' lastIndexOfSeparator |
1948 |
'helloworld' lastIndexOfSeparator |
|
1949 |
'hel lo wor ld' lastIndexOfSeparator |
|
1950 |
'hel ' lastIndexOfSeparator 6 |
|
4117 | 1951 |
" |
14150
e13160aa321a
comment/format in: #lastIndexOfSeparator
Claus Gittinger <cg@exept.de>
parents:
14141
diff
changeset
|
1952 |
|
e13160aa321a
comment/format in: #lastIndexOfSeparator
Claus Gittinger <cg@exept.de>
parents:
14141
diff
changeset
|
1953 |
"Modified (comment): / 01-06-2012 / 13:10:30 / cg" |
4117 | 1954 |
! |
1955 |
||
1956 |
lastIndexOfSeparatorStartingAt:startIndex |
|
9192 | 1957 |
"return the index of the previous whitespace character, |
1958 |
starting the search at startIndex (and searching backwards); |
|
1959 |
returns 0 if no separator was found" |
|
1960 |
||
1961 |
|start "{ Class: SmallInteger }"| |
|
1962 |
||
1963 |
start := startIndex. |
|
1964 |
||
1965 |
start to:1 by:-1 do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1966 |
(self at:index) isSeparator ifTrue:[^ index] |
9192 | 1967 |
]. |
1968 |
^ 0 |
|
1969 |
||
1970 |
" |
|
1971 |
'hello world' lastIndexOfSeparatorStartingAt:3 |
|
1972 |
'hello world' lastIndexOfSeparatorStartingAt:7 |
|
1973 |
'helloworld' lastIndexOfSeparatorStartingAt:7 |
|
8874 | 1974 |
' helloworld' lastIndexOfSeparatorStartingAt:7 |
4117 | 1975 |
" |
608 | 1976 |
! ! |
1977 |
||
1978 |
!CharacterArray methodsFor:'comparing'! |
|
1979 |
||
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1980 |
< aString |
608 | 1981 |
"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
|
1982 |
receiver is greater than the argument. Otherwise return false. |
8874 | 1983 |
This comparison is based on the elements ascii code - |
9192 | 1984 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
1985 |
||
1986 |
|mySize "{ Class: SmallInteger }" |
|
1987 |
otherSize "{ Class: SmallInteger }" |
|
1988 |
n "{ Class: SmallInteger }" |
|
1989 |
c1 c2| |
|
1990 |
||
1991 |
mySize := self size. |
|
1992 |
otherSize := aString string size. |
|
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1993 |
n := mySize min:otherSize. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1994 |
|
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
1995 |
1 to:n do:[:index | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1996 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1997 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
1998 |
(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
|
1999 |
]. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
2000 |
^ mySize < otherSize |
608 | 2001 |
! |
2002 |
||
2003 |
= aString |
|
2004 |
"Compare the receiver with the argument and return true if the |
|
2005 |
receiver is equal to the argument. Otherwise return false. |
|
1252 | 2006 |
|
9191 | 2007 |
This compare does NOT ignore case differences, |
608 | 2008 |
therefore 'foo' = 'Foo' will return false. |
2009 |
Since this is incompatible to ST-80 (at least, V2.x) , this may change." |
|
2010 |
||
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
2011 |
|mySize "{ Class: SmallInteger }"| |
608 | 2012 |
|
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2013 |
(aString isString or:[aString species == self species]) ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2014 |
^ false |
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2015 |
]. |
608 | 2016 |
mySize := self size. |
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
2017 |
mySize ~~ (aString size) ifTrue:[^ false]. |
608 | 2018 |
|
2019 |
1 to:mySize do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2020 |
(self at:index) = (aString at:index) ifFalse:[^ false]. |
608 | 2021 |
]. |
2022 |
^ true |
|
2023 |
||
2024 |
" |
|
8874 | 2025 |
'foo' = 'Foo' |
2026 |
'foo' = 'bar' |
|
2027 |
'foo' = 'foo' |
|
2028 |
'foo' = 'foo' asText |
|
2029 |
'foo' asText = 'foo' |
|
2030 |
'foo' asText = 'foo' asText |
|
608 | 2031 |
" |
1252 | 2032 |
|
2033 |
"Modified: 22.4.1996 / 15:53:58 / cg" |
|
608 | 2034 |
! |
9192 | 2035 |
|
9191 | 2036 |
> aString |
608 | 2037 |
"Compare the receiver with the argument and return true if the |
2038 |
receiver is greater than the argument. Otherwise return false. |
|
8874 | 2039 |
This comparison is based on the elements ascii code - |
1252 | 2040 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
608 | 2041 |
|
2042 |
|mySize "{ Class: SmallInteger }" |
|
8874 | 2043 |
otherSize "{ Class: SmallInteger }" |
9192 | 2044 |
n "{ Class: SmallInteger }" |
2045 |
c1 c2| |
|
2046 |
||
2047 |
mySize := self size. |
|
5929 | 2048 |
otherSize := aString string size. |
2049 |
n := mySize min:otherSize. |
|
2050 |
||
2051 |
1 to:n do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2052 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2053 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2054 |
(c1 == c2 or:[c1 = c2]) ifFalse:[^ c1 > c2]. |
5929 | 2055 |
]. |
9192 | 2056 |
^ mySize > otherSize |
2057 |
||
2058 |
"Modified: 22.4.1996 / 15:55:00 / cg" |
|
2059 |
! |
|
2060 |
||
14660 | 2061 |
after:aString |
2062 |
"Compare the receiver with the argument and return true if the |
|
2063 |
receiver should come after the argument in a sorted list. |
|
2064 |
Otherwise return false. |
|
2065 |
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
|
2066 |
LC_COLLATE, which is initialized from the environment. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2067 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2068 |
Currently it is for Strings, but not for UnicodeStrings... |
14660 | 2069 |
|
2070 |
STUPID: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2071 |
#after has a completely different meaning in SeqColl ..." |
14660 | 2072 |
|
2073 |
^ (self compareCollatingWith:aString) > 0 |
|
2074 |
! |
|
2075 |
||
15814 | 2076 |
compareAsVersionNumberWith:aStringOrCollection |
2077 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2078 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
2079 |
Compare as version numbers in the form a.b.c... ." |
|
2080 |
||
2081 |
|rev1 rev2| |
|
2082 |
||
2083 |
rev1 := self asCollectionOfSubstringsSeparatedBy:$.. |
|
2084 |
aStringOrCollection isString ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2085 |
rev2 := aStringOrCollection asCollectionOfSubstringsSeparatedBy:$.. |
15814 | 2086 |
]. |
2087 |
rev1 := rev1 collect:[:each| each asInteger]. |
|
2088 |
rev2 := rev2 collect:[:each| each asInteger]. |
|
2089 |
||
2090 |
^ rev1 compareWith:rev2 |
|
2091 |
||
2092 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2093 |
self assert:('1' compareAsVersionNumberWith:'2') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2094 |
self assert:('2' compareAsVersionNumberWith:'1') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2095 |
self assert:('1.1' compareAsVersionNumberWith:'2.1.2') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2096 |
self assert:('2.1' compareAsVersionNumberWith:'1.2.3') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2097 |
self assert:('1' compareAsVersionNumberWith:'1.1') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2098 |
self assert:('1.1' compareAsVersionNumberWith:'1') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2099 |
self assert:('1.1' compareAsVersionNumberWith:'1.2') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2100 |
self assert:('1.10' compareAsVersionNumberWith:'1.2') > 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2101 |
self assert:('1.2.3.4' compareAsVersionNumberWith:'1.2.3.5') < 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2102 |
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
|
2103 |
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
|
2104 |
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
|
2105 |
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
|
2106 |
self assert:('1.2.3.4' compareAsVersionNumberWith:#(1 2 3 4)) = 0. |
15814 | 2107 |
" |
2108 |
! |
|
2109 |
||
9192 | 2110 |
compareCaselessWith:aString |
9190 | 2111 |
"Compare the receiver against the argument, ignoreing case. |
2112 |
Return 1 if the receiver is greater, 0 if equal and -1 if less than the argument. |
|
2113 |
||
8874 | 2114 |
This comparison is based on the elements ascii code - |
9190 | 2115 |
i.e. national characters are NOT treated specially. |
2116 |
'foo' compareWith: 'Foo' will return 0" |
|
608 | 2117 |
|
2118 |
|mySize "{ Class: SmallInteger }" |
|
8874 | 2119 |
otherSize "{ Class: SmallInteger }" |
9192 | 2120 |
n "{ Class: SmallInteger }" |
608 | 2121 |
c1 c2| |
2122 |
||
2123 |
mySize := self size. |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
2124 |
otherSize := aString string size. |
608 | 2125 |
n := mySize min:otherSize. |
2126 |
||
2127 |
1 to:n do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2128 |
c1 := (self at:index) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2129 |
c2 := (aString at:index) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2130 |
c1 > c2 ifTrue:[^ 1]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2131 |
c1 < c2 ifTrue:[^ -1]. |
608 | 2132 |
]. |
2133 |
mySize > otherSize ifTrue:[^ 1]. |
|
2134 |
mySize < otherSize ifTrue:[^ -1]. |
|
2135 |
^ 0 |
|
1252 | 2136 |
|
2137 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
608 | 2138 |
! |
2139 |
||
14660 | 2140 |
compareCollatingWith:aString |
2141 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2142 |
greater, 0 if equal and -1 if less than the argument in a sorted list. |
|
2143 |
The comparison is language specific, depending on the value of |
|
2144 |
LC_COLLATE, which is in the shell environment." |
|
2145 |
||
2146 |
"TODO not yet defined for unicode" |
|
2147 |
<resource: #todo> |
|
2148 |
||
2149 |
|s| |
|
2150 |
||
2151 |
(s := self string) ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2152 |
^ s compareCollatingWith:aString |
14660 | 2153 |
]. |
2154 |
^ self compareWith:aString |
|
2155 |
! |
|
2156 |
||
9192 | 2157 |
compareWith:aString |
9190 | 2158 |
"Compare the receiver with the argument and return 1 if the receiver is |
2159 |
greater, 0 if equal and -1 if less than the argument. |
|
11861 | 2160 |
This comparison is based on the elements' codepoints - |
9190 | 2161 |
i.e. upper/lowercase & national characters are NOT treated specially. |
2162 |
'foo' compareWith: 'Foo' will return 1. |
|
2163 |
while 'foo' sameAs:'Foo' will return true" |
|
2164 |
||
15814 | 2165 |
|s| |
2166 |
||
2167 |
s := self string. |
|
2168 |
s ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2169 |
^ s compareWith:aString string. |
9192 | 2170 |
]. |
15814 | 2171 |
^ super compareWith:aString string. |
9192 | 2172 |
! |
2173 |
||
11861 | 2174 |
endsWith:aStringOrCharacter |
16175 | 2175 |
"return true, if the receiver ends with something, aStringOrCharacter. |
2176 |
If aStringOrCharacter is empty, true is returned" |
|
11861 | 2177 |
|
2178 |
|s| |
|
2179 |
||
2180 |
(s := self string) ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2181 |
^ s endsWith:aStringOrCharacter |
11861 | 2182 |
]. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2183 |
(self size > 0 and:[aStringOrCharacter isCharacter]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2184 |
^ self last = aStringOrCharacter |
11861 | 2185 |
]. |
2186 |
^ super endsWith:aStringOrCharacter |
|
2187 |
||
2188 |
" |
|
2189 |
'hello world' endsWith:'world' |
|
2190 |
'hello world' asText allBold endsWith:'world' |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2191 |
'hello world' endsWith:'' |
16175 | 2192 |
'hello world' asText allBold endsWith:'' |
11861 | 2193 |
" |
2194 |
||
2195 |
"Modified: 12.5.1996 / 15:49:18 / cg" |
|
2196 |
! |
|
2197 |
||
11838 | 2198 |
hammingDistanceTo:aString |
2199 |
"return the hamming distance (the number of characters which are different). |
|
12177 | 2200 |
In information theory, the Hamming distance between two strings of equal length |
2201 |
is the number of positions for which the corresponding symbols are different. |
|
2202 |
Put another way, it measures the minimum number of substitutions required to change |
|
11838 | 2203 |
one into the other, or the number of errors that transformed one string into the other." |
2204 |
||
2205 |
self assert:(aString size == self size). |
|
2206 |
^ 1 to:self size count:[:idx | (self at:idx) ~= (aString at:idx)] |
|
2207 |
||
2208 |
" |
|
2209 |
'roses' hammingDistanceTo:'toned' |
|
2210 |
" |
|
2211 |
! |
|
2212 |
||
9192 | 2213 |
hash |
2214 |
"return an integer useful as a hash-key" |
|
2215 |
||
16898 | 2216 |
"/ whenever changing, also care for String>>hash. |
13879 | 2217 |
"/ immediately after any change, execute (maybe in a debugger): |
2218 |
"/ Set allSubInstancesDo:[:s | s rehash] |
|
16898 | 2219 |
^ self hash_fnv1a |
2220 |
||
2221 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2222 |
'a' hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2223 |
'a' asUnicode16String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2224 |
'a' asUnicode32String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2225 |
'aa' hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2226 |
'aa' asUnicode16String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2227 |
'aa' asUnicode32String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2228 |
'ab' hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2229 |
'ab' asUnicode16String hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2230 |
'ab' asUnicode32String hash |
13879 | 2231 |
'ab' hash |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2232 |
'ab' asArray hash |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2233 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2234 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2235 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2236 |
|syms ms| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2237 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2238 |
syms := Symbol allInstances. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2239 |
Transcript show:'syms: '; showCR:syms size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2240 |
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
|
2241 |
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
|
2242 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2243 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2244 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2245 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2246 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2247 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2248 |
Transcript show:'sdbm hash: '; showCR:ms. |
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 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2251 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2252 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2253 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2254 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2255 |
Transcript show:'dragonBook: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2256 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2257 |
syms := syms collect:[:each| each asUnicode16String]. |
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:'unicode 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:'unicode dragonBook:'; showCR:ms. |
14641 | 2271 |
" |
2272 |
||
13879 | 2273 |
"Modified: / 26-12-2011 / 14:09:07 / cg" |
2274 |
! |
|
2275 |
||
2276 |
hash_dragonBook |
|
2277 |
"return an integer useful as a hash-key" |
|
2278 |
||
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2279 |
|h g| |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2280 |
|
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2281 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2282 |
"/ this is the dragon-book algorithm |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2283 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2284 |
h := 0. |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2285 |
self reverseDo:[:char | |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2286 |
"/ 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
|
2287 |
"/ h := (h bitShift:4) + char asciiValue. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2288 |
h := (h bitShift:4). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2289 |
h := h + char codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2290 |
h := h bitAnd:16rFFFFFFFF. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2291 |
g := (h bitAnd: 16rF0000000). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2292 |
g ~~ 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2293 |
h := h bitXor:(g bitShift:-24). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2294 |
h := h bitXor:g. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2295 |
]. |
10698
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 |
"/ |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2298 |
"/ multiply by large prime to spread values |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2299 |
"/ This speeds up Set and Dictionary by a factor of 10!! |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2300 |
"/ |
14137
1eb1b4a3f364
Inherit from UninterpretedBytes instead of ByteArray
Stefan Vogel <sv@exept.de>
parents:
14122
diff
changeset
|
2301 |
h := h times:31415821. |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2302 |
^ h |
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2303 |
|
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2304 |
" |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2305 |
'a' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2306 |
'a' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2307 |
'aa' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2308 |
'aa' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2309 |
'ab' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2310 |
'ab' asUnicode16String hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2311 |
'ab' hash |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
2312 |
'ab' asArray hash |
10698
08bfe7364c0f
oops: Unicode16String-hash returned different value from
sr
parents:
10671
diff
changeset
|
2313 |
" |
13879 | 2314 |
|
2315 |
"Created: / 26-12-2011 / 13:46:06 / cg" |
|
2316 |
! |
|
2317 |
||
16887 | 2318 |
hash_fnv1a |
2319 |
"return an integer useful as a hash-key. |
|
2320 |
This method uses the fnv-1a algorithm |
|
2321 |
(which is actually a very good one)" |
|
2322 |
||
2323 |
|h| |
|
2324 |
||
2325 |
h := 2166136261. |
|
2326 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2327 |
h := h bitXor:(eachChar codePoint). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2328 |
h := (h * 16777619) bitAnd:16rFFFFFFFF. |
16887 | 2329 |
]. |
16898 | 2330 |
"/ make sure, it fits into a smallInt |
2331 |
h := (h bitXor: (h >> 30)) bitAnd: 16r3FFFFFFF. |
|
16887 | 2332 |
^ h |
2333 |
||
2334 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2335 |
'abc' hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2336 |
'abc' asUnicode16String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2337 |
'abc' asUnicode32String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2338 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2339 |
'foofooHelloWorld' hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2340 |
'foofooHelloWorld' asUnicode16String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2341 |
'foofooHelloWorld' asUnicode32String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2342 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2343 |
'blablaHelloWorld' hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2344 |
'blablaHelloWorld' asUnicode16String hash_fnv1a |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2345 |
'blablaHelloWorld' asUnicode32String hash_fnv1a |
16887 | 2346 |
" |
2347 |
! |
|
2348 |
||
2349 |
hash_java |
|
2350 |
"return an integer useful as a hash-key. |
|
2351 |
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
|
2352 |
the java virtual machine |
16887 | 2353 |
(which is actually not a very good one)." |
2354 |
||
2355 |
|h| |
|
2356 |
||
2357 |
h := 0. |
|
2358 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2359 |
h := (h * 31) + (eachChar codePoint). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2360 |
h := h bitAnd:16rFFFFFFFF. |
16887 | 2361 |
]. |
2362 |
^ h |
|
2363 |
||
2364 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2365 |
'abc' hash_java |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2366 |
'foofooHelloWorld' hash_java |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2367 |
'blablaHelloWorld' hash_java |
16887 | 2368 |
" |
2369 |
! |
|
2370 |
||
16898 | 2371 |
hash_sdbm |
2372 |
"return an integer useful as a hash-key. |
|
2373 |
This method implements the sdbm algorithm." |
|
2374 |
||
2375 |
|h| |
|
2376 |
||
2377 |
"/ |
|
2378 |
"/ this is the sdbm algorithm |
|
2379 |
"/ |
|
2380 |
h := 0. |
|
2381 |
self do:[:char | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2382 |
h := (65599 times:h) plus:char codePoint. |
16898 | 2383 |
]. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2384 |
^ h |
16898 | 2385 |
|
2386 |
" |
|
2387 |
'a' hash |
|
2388 |
'a' asUnicode16String hash |
|
2389 |
'aa' hash |
|
2390 |
'aa' asUnicode16String hash |
|
2391 |
'ab' hash |
|
2392 |
'ab' asUnicode16String hash |
|
2393 |
'ab' hash |
|
2394 |
'ab' asArray hash |
|
2395 |
" |
|
2396 |
||
2397 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2398 |
|syms ms| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2399 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2400 |
syms := Symbol allInstances. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2401 |
Transcript show:'syms: '; showCR:syms size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2402 |
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
|
2403 |
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
|
2404 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2405 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2406 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2407 |
syms do:[:each| each hash]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2408 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2409 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2410 |
Transcript show:'sdbm hash: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2411 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2412 |
ms := Time millisecondsToRun:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2413 |
10 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2414 |
syms do:[:each| each hash_dragonBook]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2415 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2416 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2417 |
Transcript show:'dragonBook: '; showCR:ms. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2418 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2419 |
syms := syms collect:[:each| each asUnicode16String]. |
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:'unicode 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:'unicode dragonBook:'; showCR:ms. |
16898 | 2433 |
" |
2434 |
||
2435 |
"Modified: / 26-12-2011 / 14:09:07 / cg" |
|
2436 |
! |
|
2437 |
||
11861 | 2438 |
levenshteinTo:aString |
2439 |
"return the levenshtein distance to the argument, aString; |
|
2440 |
this value corresponds to the number of replacements that have to be |
|
2441 |
made to get aString from the receiver. |
|
2442 |
See IEEE transactions on Computers 1976 Pg 172 ff." |
|
2443 |
||
2444 |
" |
|
2445 |
in the following, we assume that ommiting a character |
|
2446 |
is less of an error than inserting an extra character. |
|
2447 |
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
|
2448 |
s: substitution weight (4) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2449 |
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
|
2450 |
c: case weight (4) - or nil (then use s) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2451 |
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
|
2452 |
i: insertion of extra character weight (2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2453 |
d: delete of a character weight (6) |
11861 | 2454 |
" |
2455 |
||
2456 |
^ StringUtilities |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2457 |
levenshteinDistanceFrom:self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2458 |
to:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2459 |
s:4 k:4 c:4 e:nil i:2 d:6 |
12177 | 2460 |
|
2461 |
" |
|
2462 |
'computer' levenshteinTo:'computer' |
|
11861 | 2463 |
'cOmputer' levenshteinTo:'computer' |
12177 | 2464 |
'cOmpuTer' levenshteinTo:'computer' |
11861 | 2465 |
'cimputer' levenshteinTo:'computer' |
2466 |
'cumputer' levenshteinTo:'computer' |
|
2467 |
||
2468 |
'cmputer' levenshteinTo:'computer' |
|
2469 |
'coomputer' levenshteinTo:'computer' |
|
2470 |
||
2471 |
'ocmprt' levenshteinTo:'computer' |
|
2472 |
'computer' levenshteinTo:'computer' |
|
2473 |
'ocmputer' levenshteinTo:'computer' |
|
2474 |
'cmputer' levenshteinTo:'computer' |
|
2475 |
'computer' levenshteinTo:'cmputer' |
|
2476 |
'Computer' levenshteinTo:'computer' |
|
2477 |
||
12177 | 2478 |
'compiter' levenshteinTo:'computer' |
2479 |
'compoter' levenshteinTo:'computer' |
|
2480 |
||
2481 |
'comptuer' levenshteinTo:'computer' |
|
11861 | 2482 |
" |
2483 |
! |
|
2484 |
||
2485 |
levenshteinTo:aString s:substWeight k:kbdTypoWeight c:caseWeight i:insrtWeight d:deleteWeight |
|
2486 |
"parametrized levenshtein. |
|
2487 |
return the levenshtein distance to the argument, aString; |
|
2488 |
this value corrensponds to the number of replacements that have to be |
|
2489 |
made to get aString from the receiver. |
|
2490 |
The arguments are the costs for |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2491 |
s:substitution, |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2492 |
k:keyboard type (substitution), |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2493 |
c:case-change, |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2494 |
i:insertion |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2495 |
d:deletion |
11861 | 2496 |
of a character. |
2497 |
See IEEE transactions on Computers 1976 Pg 172 ff" |
|
2498 |
||
2499 |
^ StringUtilities |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2500 |
levenshteinDistanceFrom:self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2501 |
to:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2502 |
s:substWeight k:kbdTypoWeight c:caseWeight e:nil i:insrtWeight d:deleteWeight |
11861 | 2503 |
! |
2504 |
||
9190 | 2505 |
sameAs:aString |
2506 |
"Compare the receiver with the argument like =, but ignore case differences. |
|
2507 |
Return true or false." |
|
2508 |
||
2509 |
|mySize "{ Class: SmallInteger }" |
|
2510 |
otherSize c1 c2| |
|
2511 |
||
9192 | 2512 |
self == aString ifTrue:[^ true]. |
2513 |
||
2514 |
mySize := self size. |
|
2515 |
otherSize := aString string size. |
|
18884 | 2516 |
mySize ~~ otherSize ifTrue:[^ false]. |
9192 | 2517 |
|
2518 |
1 to:mySize do:[:index | |
|
18884 | 2519 |
c1 := self at:index. |
2520 |
c2 := aString at:index. |
|
2521 |
c1 ~~ c2 ifTrue:[ |
|
2522 |
(c1 sameAs:c2) ifFalse:[^ false]. |
|
2523 |
] |
|
9192 | 2524 |
]. |
2525 |
^ true |
|
2526 |
||
608 | 2527 |
" |
8874 | 2528 |
'foo' sameAs: 'Foo' |
2529 |
'foo' sameAs: 'bar' |
|
2530 |
'foo' sameAs: 'foo' |
|
9192 | 2531 |
" |
2532 |
||
2533 |
"Modified: 22.4.1996 / 15:56:17 / cg" |
|
2534 |
! |
|
608 | 2535 |
|
15734 | 2536 |
sameAs:aString caseSensitive:caseSensitive |
2537 |
"Compare the receiver with the argument. |
|
2538 |
If caseSensitive is false, this is the same as #sameAs:, |
|
2539 |
if false, this is the same as #=." |
|
2540 |
||
2541 |
caseSensitive ifFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2542 |
^ self sameAs:aString |
15734 | 2543 |
]. |
2544 |
^ self = aString |
|
2545 |
||
2546 |
" |
|
2547 |
'foo' sameAs:'Foo' caseSensitive:false |
|
2548 |
'foo' sameAs:'foo' caseSensitive:true |
|
2549 |
" |
|
2550 |
! |
|
2551 |
||
5242 | 2552 |
sameAs:aString ignoreCase:ignoreCase |
15734 | 2553 |
<resource: #obsolete> |
5242 | 2554 |
"Compare the receiver with the argument. |
2555 |
If ignoreCase is true, this is the same as #sameAs:, |
|
2556 |
if false, this is the same as #=." |
|
2557 |
||
2558 |
ignoreCase ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2559 |
^ self sameAs:aString |
5242 | 2560 |
]. |
2561 |
^ self = aString |
|
2562 |
||
2563 |
" |
|
8874 | 2564 |
'foo' sameAs:'Foo' ignoreCase:false |
2565 |
'foo' sameAs:'foo' ignoreCase:true |
|
5242 | 2566 |
" |
2567 |
||
2568 |
! |
|
2569 |
||
608 | 2570 |
sameCharacters:aString |
9192 | 2571 |
"count & return the number of characters which are the same |
2572 |
(ignoring case and emphasis) in the receiver and the argument, aString." |
|
2573 |
||
2574 |
|n "{ Class: SmallInteger }" |
|
2575 |
c1 c2 cnt| |
|
2576 |
||
2577 |
n := self size. |
|
2578 |
n := n min:(aString string size). |
|
2579 |
||
2580 |
cnt := 0. |
|
2581 |
1 to:n do:[:index | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2582 |
c1 := self at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2583 |
c2 := aString at:index. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2584 |
((c1 == c2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2585 |
or:[c1 asLowercase = c2 asLowercase]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2586 |
cnt := cnt + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2587 |
] |
9192 | 2588 |
]. |
2589 |
^ cnt |
|
2590 |
||
2591 |
" |
|
2592 |
'foobarbaz' sameCharacters: 'foo' |
|
8874 | 2593 |
'foobarbaz' sameCharacters: 'Foo' |
2594 |
'foobarbaz' sameCharacters: 'baz' |
|
608 | 2595 |
" |
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2596 |
! |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2597 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2598 |
sameEmphasisAs:aStringOrText |
17215 | 2599 |
"compare the receiver's and the argument's emphasis" |
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2600 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2601 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2602 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2603 |
" |
8874 | 2604 |
'hello' asText sameEmphasisAs: 'hello' |
2605 |
'hello' asText sameEmphasisAs: 'hello' asText |
|
2606 |
'hello' asText allBold sameEmphasisAs: 'hello' |
|
2607 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
|
9192 | 2608 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
2609 |
" |
|
2610 |
! |
|
2611 |
||
9191 | 2612 |
sameStringAndEmphasisAs:aStringOrText |
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
2613 |
"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
|
2614 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2615 |
aStringOrText isString ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2616 |
(self string = aStringOrText string) ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2617 |
self hasChangeOfEmphasis = aStringOrText hasChangeOfEmphasis ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2618 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2619 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2620 |
" |
8874 | 2621 |
'hello' asText sameEmphasisAs: 'hello' |
2622 |
'hello' asText sameEmphasisAs: 'hello' asText |
|
2623 |
'hello' asText allBold sameEmphasisAs: 'hello' |
|
2624 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
|
2625 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
|
2626 |
||
2627 |
'hello' sameEmphasisAs: 'hello' asText |
|
2628 |
'hello' sameEmphasisAs: 'hello' asText allBold |
|
2629 |
'hello' sameEmphasisAs: 'fooba' |
|
2630 |
'hello' sameEmphasisAs: 'fooba' asText |
|
2631 |
'hello' sameEmphasisAs: 'fooba' asText allBold |
|
2632 |
'hello' sameEmphasisAs: 'fooba' asText allItalic |
|
2633 |
||
2634 |
'hello' asText sameStringAndEmphasisAs: 'hello' |
|
2635 |
'hello' asText sameStringAndEmphasisAs: 'hello' asText |
|
2636 |
'hello' asText allBold sameStringAndEmphasisAs: 'hello' |
|
2637 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allBold |
|
2638 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allItalic |
|
2639 |
||
2640 |
'hello' sameStringAndEmphasisAs: 'hello' asText |
|
2641 |
'hello' sameStringAndEmphasisAs: 'hello' asText allBold |
|
2642 |
'hello' sameStringAndEmphasisAs: 'fooba' |
|
2643 |
'hello' sameStringAndEmphasisAs: 'fooba' asText |
|
2644 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allBold |
|
2645 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allItalic |
|
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2646 |
" |
11861 | 2647 |
! |
2648 |
||
2649 |
spellAgainst: aString |
|
2650 |
"return an integer between 0 and 100 indicating how similar |
|
2651 |
the argument is to the receiver. No case conversion is done. |
|
2652 |
This algorithm is much simpler (but also less exact) than the |
|
2653 |
levenshtein distance. Experiment which is better for your |
|
2654 |
application." |
|
2655 |
||
2656 |
| i1 "{ Class: SmallInteger }" |
|
2657 |
i2 "{ Class: SmallInteger }" |
|
2658 |
next1 "{ Class: SmallInteger }" |
|
2659 |
next2 "{ Class: SmallInteger }" |
|
2660 |
size1 "{ Class: SmallInteger }" |
|
2661 |
size2 "{ Class: SmallInteger }" |
|
2662 |
score "{ Class: SmallInteger }" |
|
2663 |
maxLen "{ Class: SmallInteger }" | |
|
2664 |
||
2665 |
size1 := self size. |
|
2666 |
size2 := aString size. |
|
2667 |
maxLen := size1 max:size2. |
|
2668 |
score := 0. |
|
2669 |
i1 := i2 := 1. |
|
2670 |
[i1 <= size1 and: [i2 <= size2]] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2671 |
next1 := i1 + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2672 |
next2 := i2 + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2673 |
(self at:i1) == (aString at:i2) ifTrue: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2674 |
score := score+1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2675 |
i1 := next1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2676 |
i2 := next2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2677 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2678 |
(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
|
2679 |
i2 := next2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2680 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2681 |
(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
|
2682 |
i1 := next1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2683 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2684 |
i1 := next1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2685 |
i2 := next2 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2686 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2687 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2688 |
] |
11861 | 2689 |
]. |
2690 |
||
2691 |
score == maxLen ifTrue: [^ 100]. |
|
2692 |
^ 100 * score // maxLen |
|
2693 |
||
2694 |
" |
|
2695 |
'Smalltalk' spellAgainst: 'Smalltlak' |
|
2696 |
'Smalltalk' spellAgainst: 'smalltlak' |
|
2697 |
'Smalltalk' spellAgainst: 'smalltalk' |
|
2698 |
'Smalltalk' spellAgainst: 'smalltlk' |
|
2699 |
'Smalltalk' spellAgainst: 'Smalltolk' |
|
2700 |
" |
|
2701 |
! |
|
2702 |
||
16553 | 2703 |
startsWith:aStringOrCharacter |
2704 |
"return true, if the receiver starts with something, aStringOrCharacter. |
|
17371 | 2705 |
If the argument is empty, true is returned. |
2706 |
Notice, that this is similar to, but slightly different from VW's and Squeak's beginsWith:, |
|
2707 |
which are both inconsistent w.r.t. an empty argument." |
|
11861 | 2708 |
|
2709 |
|s| |
|
2710 |
||
16553 | 2711 |
aStringOrCharacter isCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2712 |
^ (self size > 0) and:[ (self at:1) == aStringOrCharacter ] |
16553 | 2713 |
]. |
11861 | 2714 |
(s := self string) ~~ self ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2715 |
^ s startsWith:aStringOrCharacter |
11861 | 2716 |
]. |
16553 | 2717 |
^ super startsWith:aStringOrCharacter |
11861 | 2718 |
|
2719 |
" |
|
17364 | 2720 |
'abcde' startsWith:#($a $b $c) |
2721 |
'abcde' startsWith:'abc' |
|
2722 |
'abcd' startsWith:'abcde' |
|
2723 |
'abcde' startsWith:'abd' |
|
11861 | 2724 |
'hello world' startsWith:'hello' |
2725 |
'hello world' asText allBold startsWith:'hello' |
|
2726 |
'hello world' asText allBold startsWith:'' |
|
2727 |
" |
|
2728 |
||
2729 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
2730 |
"Modified: 12.5.1996 / 15:49:24 / cg" |
|
9192 | 2731 |
! ! |
2732 |
||
2733 |
!CharacterArray methodsFor:'converting'! |
|
2734 |
||
11881 | 2735 |
asAsciiZ |
2736 |
"if the receiver does not end with a 0-valued character, return a copy of it, |
|
2737 |
with an additional 0-character. Otherwise return the receiver. This is sometimes |
|
2738 |
needed when a string has to be passed to C, which needs 0-terminated strings. |
|
2739 |
Notice, that all singleByte strings are already 0-terminated in ST/X, whereas wide |
|
2740 |
strings are not." |
|
2741 |
||
12658 | 2742 |
(self notEmpty and:[self last codePoint == 0]) ifTrue:[^ self ]. |
11881 | 2743 |
^ self copyWith:(Character value:0). |
2744 |
||
2745 |
" |
|
2746 |
'abc' asAsciiZ |
|
2747 |
'abc' asWideString asAsciiZ |
|
2748 |
" |
|
2749 |
! |
|
2750 |
||
13524 | 2751 |
asByteArray |
15936 | 2752 |
"depending on the size of the characters in the receiver, |
2753 |
return a byteArray containing single-, double- or even 4-bytewise values. |
|
2754 |
The size of the returned byteArray will be the strings size multiplied by the |
|
2755 |
size required for the largest character. |
|
2756 |
Caveat: better use utf8Encoded, to get reproducable results" |
|
2757 |
||
14555 | 2758 |
|bytes sz bytesPerCharacter idx str| |
2759 |
||
2760 |
str := self string. |
|
2761 |
str ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2762 |
"/ for text and other wrappers |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2763 |
^ str asByteArray |
13611
ba8c7372218a
variable renamed in: #inspector2TabBytes
Claus Gittinger <cg@exept.de>
parents:
13524
diff
changeset
|
2764 |
]. |
ba8c7372218a
variable renamed in: #inspector2TabBytes
Claus Gittinger <cg@exept.de>
parents:
13524
diff
changeset
|
2765 |
|
ba8c7372218a
variable renamed in: #inspector2TabBytes
Claus Gittinger <cg@exept.de>
parents:
13524
diff
changeset
|
2766 |
"/ for real strings, a fallback |
13524 | 2767 |
sz := self size. |
2768 |
bytesPerCharacter := self bitsPerCharacter // 8. |
|
2769 |
bytes := ByteArray new:(sz * bytesPerCharacter). |
|
2770 |
idx := 1. |
|
2771 |
self do:[:char | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2772 |
|code| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2773 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2774 |
code := char codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2775 |
bytesPerCharacter == 2 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2776 |
bytes unsignedShortAt:idx put:code |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2777 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2778 |
bytesPerCharacter == 4 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2779 |
bytes unsignedLongAt:idx put:code |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2780 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2781 |
bytes at:idx put:code |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2782 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2783 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2784 |
idx := idx + bytesPerCharacter. |
13524 | 2785 |
]. |
2786 |
^ bytes |
|
2787 |
||
2788 |
"Created: / 27-07-2011 / 00:56:17 / cg" |
|
2789 |
! |
|
2790 |
||
608 | 2791 |
asCollectionOfLines |
8874 | 2792 |
"return a collection containing the lines (separated by cr) |
608 | 2793 |
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
|
2794 |
contain empty strings. |
14456
d7c3e67647f1
comment/format in: #asCollectionOfLines
Claus Gittinger <cg@exept.de>
parents:
14455
diff
changeset
|
2795 |
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
|
2796 |
See also #asCollectionOfLinesWithReturn |
d7c3e67647f1
comment/format in: #asCollectionOfLines
Claus Gittinger <cg@exept.de>
parents:
14455
diff
changeset
|
2797 |
(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
|
2798 |
this method and we did not want to risk any incompatibilities)" |
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2799 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2800 |
^ self asCollectionOfSubstringsSeparatedBy:Character cr. |
608 | 2801 |
|
2802 |
" |
|
2803 |
'1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines |
|
8874 | 2804 |
'1 one\\\\2 two\3 three' withCRs asCollectionOfLines |
608 | 2805 |
" |
2806 |
! |
|
2807 |
||
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2808 |
asCollectionOfLinesWithReturn |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2809 |
"return a collection containing the lines (separated by cr) |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2810 |
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
|
2811 |
contain empty strings." |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2812 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2813 |
|lines| |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2814 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2815 |
lines := self asCollectionOfSubstringsSeparatedBy:Character cr. |
18194 | 2816 |
(lines notEmpty and:[lines last isEmpty]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2817 |
^ lines copyButLast:1 |
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2818 |
]. |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2819 |
^ lines |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2820 |
|
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2821 |
" |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2822 |
'1\2\3' withCRs asCollectionOfLines |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2823 |
'1\2\3\' withCRs asCollectionOfLines |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2824 |
'1\2\3' withCRs asCollectionOfLinesWithReturn |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2825 |
'1\2\3\' withCRs asCollectionOfLinesWithReturn |
18194 | 2826 |
'' withCRs asCollectionOfLinesWithReturn |
14455
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2827 |
" |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2828 |
! |
ee8809bade6b
added: #asCollectionOfLinesWithReturn
Claus Gittinger <cg@exept.de>
parents:
14452
diff
changeset
|
2829 |
|
608 | 2830 |
asCollectionOfSubstringsSeparatedBy:aCharacter |
15740 | 2831 |
"return a collection containing substrings (separated by aCharacter) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2832 |
of the receiver. |
15740 | 2833 |
If aCharacter occurs multiple times in a row, the result will contain empty strings. |
2834 |
If the receiver ends with aCharacter, an empty string with be the last result element." |
|
608 | 2835 |
|
9192 | 2836 |
^ self asCollectionOfSubCollectionsSeparatedBy:aCharacter |
2837 |
||
2838 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2839 |
'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
|
2840 |
'1 one:2 two:3 three:4 four:5 five:' asCollectionOfSubstringsSeparatedBy:$: |
15740 | 2841 |
'1 one 2 two 3 three 4 four 5 five' asCollectionOfSubstringsSeparatedBy:Character space |
9192 | 2842 |
" |
2843 |
! |
|
608 | 2844 |
|
11828 | 2845 |
asCollectionOfSubstringsSeparatedBy:aCharacter exceptIn:ch |
15740 | 2846 |
"return a collection containing the substrings (separated by aCharacter) |
12177 | 2847 |
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
|
2848 |
the result will contain empty strings. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2849 |
The separation is not done, inside a matching pair of ch-substrings. |
15740 | 2850 |
Can be used to tokenize csv-like strings, which may or may not be enclosed in quotes." |
11828 | 2851 |
|
2852 |
|lines myClass except i c |
|
2853 |
startIndex "{ Class:SmallInteger }" |
|
2854 |
stopIndex "{ Class:SmallInteger }" | |
|
2855 |
||
11905
cbc2191cfe2d
return stringCollections from asCollectionOfXXX
Claus Gittinger <cg@exept.de>
parents:
11904
diff
changeset
|
2856 |
lines := StringCollection new. |
11828 | 2857 |
myClass := self species. |
2858 |
||
2859 |
startIndex := 1. |
|
2860 |
except := false. |
|
2861 |
[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2862 |
i := startIndex-1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2863 |
[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2864 |
i := i+1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2865 |
c := self at:i. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2866 |
c = ch ifTrue:[ except := except not. ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2867 |
i < self size and:[except or:[c ~= aCharacter]] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2868 |
] whileTrue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2869 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2870 |
c = aCharacter ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2871 |
stopIndex := i -1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2872 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2873 |
stopIndex := i. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2874 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2875 |
(stopIndex < startIndex) ifTrue: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2876 |
lines add:(myClass new:0) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2877 |
] ifFalse: [ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2878 |
lines add:(self copyFrom:startIndex to:stopIndex) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2879 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2880 |
startIndex := stopIndex + 2. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2881 |
startIndex <= self size |
11828 | 2882 |
] whileTrue. |
2883 |
^ lines |
|
2884 |
||
2885 |
" |
|
12177 | 2886 |
'asd''f;d''dd;s' asCollectionOfSubstringsSeparatedBy:$; exceptIn:$' |
2887 |
" |
|
2888 |
"/ 'asd "hello bla" foo "bla bla" bar' asCollectionOfSubstringsSeparatedBy:$ exceptIn:$" |
|
11828 | 2889 |
! |
2890 |
||
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2891 |
asCollectionOfSubstringsSeparatedBy:aFieldSeparatorString textSeparator:aTextSeparatorOrNil |
13343
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
2892 |
"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
|
2893 |
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
|
2894 |
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
|
2895 |
|
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2896 |
|aTextSeparatorChar items scanningWord inStream element lastIsFieldSeparator sz| |
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2897 |
|
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2898 |
aTextSeparatorOrNil isNil ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2899 |
^ self asCollectionOfSubstringsSeparatedByAll: aFieldSeparatorString |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2900 |
]. |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2901 |
sz := aTextSeparatorOrNil size. |
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2902 |
sz = 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2903 |
aTextSeparatorChar := aTextSeparatorOrNil |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2904 |
] ifFalse:[sz = 1 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2905 |
"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
|
2906 |
aTextSeparatorChar := aTextSeparatorOrNil first. |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2907 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2908 |
self error:'textSeparatoSize > 1'. |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2909 |
]]. |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2910 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2911 |
items := OrderedCollection new. |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2912 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2913 |
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
|
2914 |
[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2915 |
inStream skipSeparators. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2916 |
inStream atEnd |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2917 |
] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2918 |
lastIsFieldSeparator := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2919 |
inStream peek == aTextSeparatorChar ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2920 |
inStream next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2921 |
element := ''. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2922 |
scanningWord := true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2923 |
[ scanningWord and:[inStream atEnd not] ] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2924 |
element := element , (inStream upTo:aTextSeparatorChar). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2925 |
(inStream peek == aTextSeparatorChar) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2926 |
element := element , aTextSeparatorChar . |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2927 |
inStream next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2928 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2929 |
scanningWord := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2930 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2931 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2932 |
inStream upToAll_positionBefore:aFieldSeparatorString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2933 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2934 |
element := inStream upToAll_positionBefore:aFieldSeparatorString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2935 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2936 |
items add:element. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2937 |
lastIsFieldSeparator := (inStream skipThroughAll:aFieldSeparatorString) notNil. |
13343
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
2938 |
]. |
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
2939 |
lastIsFieldSeparator ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2940 |
"empty element at the end of the line" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2941 |
items add:''. |
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 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2944 |
^ items |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2945 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2946 |
" |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2947 |
self assert:(('#First#, #Second,SecondAdd#, #Third#' asCollectionOfSubstringsSeparatedBy:',' textSeparator: $#) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2948 |
sameContentsAs:#('First' 'Second,SecondAdd' 'Third')). |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2949 |
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
|
2950 |
sameContentsAs:#('Fir#st' 'Second,SecondAdd' 'Third')). |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2951 |
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
|
2952 |
sameContentsAs:#('Fir#st' 'Second' 'SecondAdd' 'Third')). |
13343
3f058ad0d2f1
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13332
diff
changeset
|
2953 |
self assert:(('First,Second,Third,,' asCollectionOfSubstringsSeparatedBy:',' textSeparator:nil) |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2954 |
sameContentsAs:#('First' 'Second' 'Third' '' '')). |
13344
ec6860c49990
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Stefan Vogel <sv@exept.de>
parents:
13343
diff
changeset
|
2955 |
self assert:(('First,Second,Third,,' asCollectionOfSubstringsSeparatedBy:',' textSeparator:'#') |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
2956 |
sameContentsAs:#('First' 'Second' 'Third' '' '')). |
13327
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2957 |
" |
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2958 |
|
9bfd3ddd5110
changed: #asCollectionOfSubstringsSeparatedBy:textSeparator:
Claus Gittinger <cg@exept.de>
parents:
13310
diff
changeset
|
2959 |
"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
|
2960 |
! |
999589445aa7
add new method for splitting a csv string into csv elements
ab
parents:
10437
diff
changeset
|
2961 |
|
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2962 |
asCollectionOfSubstringsSeparatedByAll:aSeparatorString |
8874 | 2963 |
"return a collection containing the lines (separated by aSeparatorString) |
2964 |
of the receiver. If aSeparatorString occurs multiple times in a row, |
|
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2965 |
the result will contain empty strings." |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2966 |
|
8852
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2967 |
^ self asCollectionOfSubCollectionsSeparatedByAll:aSeparatorString |
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2968 |
|
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2969 |
" |
8874 | 2970 |
'1::2::3::4::5::' asCollectionOfSubstringsSeparatedByAll:'::' |
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2971 |
" |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2972 |
! |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
2973 |
|
608 | 2974 |
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators |
2975 |
"return a collection containing the words (separated by any character |
|
2976 |
from aCollectionOfSeparators) of the receiver. |
|
2977 |
This allows breaking up strings using any character as separator." |
|
2978 |
||
8852
9f5984eff2c2
use asCollectionOfSubCollectionsSeparatedBy*
Claus Gittinger <cg@exept.de>
parents:
8794
diff
changeset
|
2979 |
^ self asCollectionOfSubCollectionsSeparatedByAny:aCollectionOfSeparators |
608 | 2980 |
|
2981 |
" |
|
2982 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:) |
|
8874 | 2983 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' |
2984 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) |
|
2985 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' |
|
2986 |
'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) |
|
608 | 2987 |
" |
2988 |
! |
|
2989 |
||
2990 |
asCollectionOfWords |
|
8874 | 2991 |
"return a collection containing the words (separated by whitespace) |
2992 |
of the receiver. Multiple occurrences of whitespace characters will |
|
17517 | 2993 |
be treated like one - i.e. whitespace is skipped. |
2994 |
(sigh: it is called #'subStrings' in V'Age, and #'substrings' in Squeak) " |
|
608 | 2995 |
|
7797 | 2996 |
|words| |
608 | 2997 |
|
11905
cbc2191cfe2d
return stringCollections from asCollectionOfXXX
Claus Gittinger <cg@exept.de>
parents:
11904
diff
changeset
|
2998 |
words := StringCollection new. |
7797 | 2999 |
self asCollectionOfWordsDo:[:w | words add:w]. |
608 | 3000 |
^ words |
3001 |
||
3002 |
" |
|
3003 |
'hello world isnt this nice' asCollectionOfWords |
|
3004 |
' hello world isnt this nice ' asCollectionOfWords |
|
3005 |
'hello' asCollectionOfWords |
|
3006 |
'' asCollectionOfWords |
|
3007 |
' ' asCollectionOfWords |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
3008 |
' foo bar__baz__bla__ bar ' asCollectionOfWords |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
3009 |
' foo __bar__baz__bla__ bar ' asCollectionOfWords |
608 | 3010 |
" |
9192 | 3011 |
! |
3012 |
||
3013 |
asCollectionOfWordsDo:aBlock |
|
8874 | 3014 |
"evaluate aBlock for each word (separated by whitespace) of the receiver. |
3015 |
Multiple occurrences of whitespace characters will be treated like one |
|
7797 | 3016 |
- i.e. whitespace is skipped. |
3017 |
Returns the number of words (i.e. the number of invocations of aBlock)." |
|
3018 |
||
3019 |
|count "{ Class:SmallInteger }" |
|
8874 | 3020 |
start "{ Class:SmallInteger }" |
3021 |
stop "{ Class:SmallInteger }" |
|
7797 | 3022 |
mySize "{ Class:SmallInteger }"| |
3023 |
||
3024 |
count := 0. |
|
3025 |
start := 1. |
|
3026 |
mySize := self size. |
|
3027 |
[start <= mySize] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3028 |
start := self indexOfNonSeparatorStartingAt:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3029 |
start == 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3030 |
^ count |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3031 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3032 |
stop := self indexOfSeparatorStartingAt:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3033 |
stop == 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3034 |
aBlock value:(self copyFrom:start to:mySize). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3035 |
^ count + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3036 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3037 |
aBlock value:(self copyFrom:start to:(stop - 1)). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3038 |
start := stop. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3039 |
count := count + 1 |
7797 | 3040 |
]. |
3041 |
^ count |
|
3042 |
||
3043 |
" |
|
3044 |
'hello world isnt this nice' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3045 |
' hello world isnt this nice ' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3046 |
'hello' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3047 |
'' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3048 |
' ' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3049 |
" |
|
9192 | 3050 |
! |
3051 |
||
3052 |
asFilename |
|
3053 |
"return a Filename with pathname taken from the receiver" |
|
3054 |
||
3055 |
^ Filename named:self "(self asSingleByteStringReplaceInvalidWith:$?)" |
|
3056 |
||
3057 |
"Modified: 20.5.1996 / 09:38:15 / cg" |
|
3058 |
! |
|
608 | 3059 |
|
3060 | 3060 |
asFixedPoint |
3061 |
"read a fixedPoint number from the receiver. |
|
8874 | 3062 |
Notice, that errors may occur during the read, |
7423 | 3063 |
so you better setup some signal handler when using this method." |
3060 | 3064 |
|
3065 |
^ FixedPoint readFromString:self |
|
3066 |
||
3067 |
" |
|
8874 | 3068 |
'0.123' asFixedPoint |
3069 |
'12345' asFixedPoint |
|
3060 | 3070 |
'(1/5)' asFixedPoint |
3071 |
'foo' asFixedPoint |
|
9192 | 3072 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asFixedPoint] |
3073 |
" |
|
3074 |
||
3075 |
"Modified: / 25.10.1997 / 15:19:00 / cg" |
|
3076 |
! |
|
3077 |
||
3078 |
asFixedPoint:scale |
|
3060 | 3079 |
"read a fixedPoint number with scale number of post-decimal digits |
3080 |
from the receiver. Scale controls the number of displayed digits, |
|
3081 |
not the number of actually valid digits. |
|
8874 | 3082 |
Notice, that errors may occur during the read, |
7423 | 3083 |
so you better setup some signal handler when using this method." |
3060 | 3084 |
|
3085 |
^ (FixedPoint readFromString:self) scale:scale |
|
3086 |
||
3087 |
" |
|
8874 | 3088 |
'0.123' asFixedPoint:2 |
3089 |
'123456' asFixedPoint:2 |
|
3090 |
('3.14157' asFixedPoint:1) asFixedPoint:5 |
|
3091 |
'3.14157' asFixedPoint:2 |
|
3092 |
'foo' asFixedPoint:2 |
|
3060 | 3093 |
" |
3094 |
||
3095 |
"Modified: / 25.10.1997 / 15:21:57 / cg" |
|
9192 | 3096 |
! |
3097 |
||
3098 |
asFloat |
|
608 | 3099 |
"read a float number from the receiver. |
8874 | 3100 |
Notice, that errors may occur during the read, |
7422 | 3101 |
so you better setup some exception handler when using this method." |
608 | 3102 |
|
3103 |
^ (Number readFromString:self) asFloat |
|
3104 |
||
3105 |
" |
|
8874 | 3106 |
'0.123' asFloat |
608 | 3107 |
'12345' asFloat |
3108 |
'(1/5)' asFloat |
|
8874 | 3109 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asFloat] |
608 | 3110 |
" |
3111 |
! |
|
3112 |
||
3113 |
asInteger |
|
9190 | 3114 |
"convert the receiver into an integer. |
8874 | 3115 |
Notice, that errors may occur during the read, |
9190 | 3116 |
so you better setup some exception handler when using this method. |
3117 |
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
|
3118 |
in other smalltalks. |
9190 | 3119 |
For less strict integer reading, use Integer readFrom:aString" |
608 | 3120 |
|
3121 |
^ Integer readFromString:self |
|
3122 |
||
3123 |
" |
|
3124 |
'12345678901234567890' asInteger |
|
3125 |
'-1234' asInteger |
|
9190 | 3126 |
|
3127 |
The following raises an error: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3128 |
'0.123' asInteger <- reader finds more after reading 0 |
9190 | 3129 |
|
3130 |
whereas the less strict readFrom does not: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3131 |
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
|
3132 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
3133 |
'0.123' asInteger |
608 | 3134 |
'0.123' asNumber <- returns what you expect |
8874 | 3135 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asInteger] |
9190 | 3136 |
|
3137 |
" |
|
9192 | 3138 |
! |
3139 |
||
3140 |
asLowercase |
|
608 | 3141 |
"return a copy of myself in lowercase letters" |
3142 |
||
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3143 |
|newStr c bitsPerCharacter |
9192 | 3144 |
mySize "{ Class: SmallInteger }" | |
3145 |
||
3146 |
mySize := self size. |
|
3147 |
mySize == 0 ifTrue:[^ self]. |
|
18657 | 3148 |
|
9192 | 3149 |
newStr := self species new:mySize. |
3150 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
3151 |
||
18657 | 3152 |
"/ handle the very seldom case of an uppercase char which needs |
3153 |
"/ more bits in its lowercase variant |
|
3154 |
"/ (there are only a few of them) |
|
3155 |
||
9192 | 3156 |
1 to:mySize do:[:i | |
18657 | 3157 |
c := (self at:i) asLowercase. |
3158 |
(c bitsPerCharacter > bitsPerCharacter |
|
3159 |
and:[c stringSpecies ~= newStr stringSpecies]) ifTrue:[ |
|
3160 |
newStr := c stringSpecies fromString:newStr. |
|
18662 | 3161 |
bitsPerCharacter := newStr bitsPerCharacter. |
18657 | 3162 |
]. |
3163 |
newStr at:i put:c |
|
9192 | 3164 |
]. |
3165 |
^ newStr |
|
3166 |
||
3167 |
" |
|
3168 |
'HelloWorld' asLowercase |
|
18662 | 3169 |
'HelloWorld' asUnicode16String asLowercase |
9192 | 3170 |
'HelloWorld' asLowercaseFirst |
18657 | 3171 |
'HelloWorld' asUppercase |
9192 | 3172 |
" |
3173 |
! |
|
3174 |
||
3175 |
asLowercaseFirst |
|
17508 | 3176 |
"return a copy of myself where the first character is converted to lowercase. |
3177 |
If the first character is already lowercase, or there is no uppercase for it, return the |
|
3178 |
receiver." |
|
9192 | 3179 |
|
3180 |
|newString firstChar firstCharAsLowercase| |
|
3181 |
||
11525 | 3182 |
self isEmpty ifTrue:[^ self]. |
9192 | 3183 |
firstChar := (self at:1). |
3184 |
firstCharAsLowercase := firstChar asLowercase. |
|
3185 |
firstChar == firstCharAsLowercase ifTrue:[ ^ self]. |
|
3186 |
||
3187 |
firstCharAsLowercase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3188 |
newString := firstCharAsLowercase stringSpecies fromString:self. |
9192 | 3189 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3190 |
newString := self stringSpecies fromString:self. |
9192 | 3191 |
]. |
9190 | 3192 |
newString at:1 put:firstCharAsLowercase. |
3193 |
^ newString |
|
608 | 3194 |
|
3195 |
" |
|
8874 | 3196 |
'HelloWorld' asLowercase |
3197 |
'HelloWorld' asLowercaseFirst |
|
608 | 3198 |
" |
3199 |
! |
|
3200 |
||
11828 | 3201 |
asLowercaseLast |
3202 |
"return a copy of myself where the last character is |
|
3203 |
converted to lowercase." |
|
3204 |
||
3205 |
|newString sz| |
|
3206 |
||
3207 |
sz := self size. |
|
3208 |
newString := self copyFrom:1 to:sz. |
|
3209 |
sz > 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3210 |
newString at:sz put:(newString at:sz) asLowercase |
11828 | 3211 |
]. |
3212 |
^ newString |
|
3213 |
||
3214 |
" |
|
12177 | 3215 |
'HelloWorld' asLowercase |
3216 |
'HelloWorlD' asLowercaseLast |
|
11828 | 3217 |
" |
3218 |
! |
|
3219 |
||
17644 | 3220 |
asMutator |
3221 |
"return a corresponding setter method's selector" |
|
3222 |
||
3223 |
^ (self asOneByteString,':') asSymbol |
|
3224 |
! |
|
3225 |
||
9190 | 3226 |
asNumber |
3227 |
"read a number from the receiver. |
|
3228 |
Notice, that (in contrast to ST-80) errors may occur during the read, |
|
3229 |
so you better setup some signal handler when using this method. |
|
3230 |
Also notice, that this is meant to read end-user numbers from a string; |
|
9135 | 3231 |
it does not handle smalltalk numbers (i.e. radix). |
3232 |
To read a smalltalk number, use Number >> readSmalltalkFrom:. |
|
608 | 3233 |
This may change if ANSI specifies it." |
3234 |
||
3235 |
"/ ST-80 behavior: |
|
3236 |
"/ ^ Number readFromString:self onError:0 |
|
3237 |
||
17061 | 3238 |
^ Number fromString:self |
3239 |
||
3240 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3241 |
'123' asNumber |
608 | 3242 |
'123.567' asNumber |
3243 |
'(5/6)' asNumber |
|
3244 |
'foo' asNumber |
|
17061 | 3245 |
'123a' asNumber |
8874 | 3246 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] |
608 | 3247 |
" |
9192 | 3248 |
! |
3249 |
||
3250 |
asNumberFromFormatString:ignored |
|
608 | 3251 |
"read a number from the receiver, ignoring any nonDigit characters. |
3252 |
This is typically used to convert from strings which include |
|
3253 |
dollar-signs or millenium digits. However, this method also ignores |
|
3254 |
the decimal point (if any) and therefore should be used with care." |
|
3255 |
||
3256 |
|tempString| |
|
3257 |
||
3258 |
tempString := self collect:[:char | char isDigit]. |
|
3259 |
^ Number readFromString:tempString onError:0 |
|
3260 |
||
3261 |
" |
|
3262 |
'USD 123' asNumberFromFormatString:'foo' |
|
3263 |
'DM 123' asNumberFromFormatString:'foo' |
|
3264 |
'123' asNumberFromFormatString:'foo' |
|
3265 |
'123.567' asNumberFromFormatString:'foo' |
|
3266 |
'(5/6)' asNumberFromFormatString:'foo' |
|
3267 |
'foo' asNumberFromFormatString:'foo' |
|
3268 |
" |
|
9192 | 3269 |
! |
3270 |
||
7977 | 3271 |
asSingleByteStringIfPossible |
3272 |
"if possible, return the receiver converted to a 'normal' string. |
|
18181 | 3273 |
It is only possible, if there are no characters with codePoints above 255 in the receiver. |
3274 |
If not possible, the (wideString) receiver is returned." |
|
7977 | 3275 |
|
14555 | 3276 |
self isWideString ifFalse:[^ self]. |
18967 | 3277 |
self containsNon8BitElements ifTrue:[^ self]. |
3278 |
^ self asSingleByteString |
|
9192 | 3279 |
|
3280 |
" |
|
3281 |
'hello' asSingleByteStringIfPossible |
|
18967 | 3282 |
'hello' asText asSingleByteStringIfPossible |
3283 |
'hello' asUnicodeString asText asSingleByteStringIfPossible |
|
9192 | 3284 |
'hello' asUnicodeString asSingleByteStringIfPossible |
3285 |
" |
|
3286 |
! |
|
3287 |
||
3288 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
|
3289 |
"return the receiver converted to a 'normal' string, |
|
3290 |
with invalid characters replaced by replacementCharacter. |
|
3291 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
3292 |
and replace characters above code-255 with some replacement." |
|
3293 |
||
3294 |
|newString| |
|
3295 |
||
3296 |
newString := String new:(self size). |
|
3297 |
1 to:self size do:[:idx | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3298 |
|char| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3299 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3300 |
char := self at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3301 |
char codePoint <= 16rFF ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3302 |
newString at:idx put:char |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3303 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3304 |
newString at:idx put:replacementCharacter |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3305 |
]. |
9190 | 3306 |
]. |
3307 |
^ newString |
|
3308 |
||
3309 |
"Created: 30.6.1997 / 13:02:14 / cg" |
|
7977 | 3310 |
! |
3311 |
||
9192 | 3312 |
asString |
3313 |
"return myself - I am a string" |
|
3314 |
||
3315 |
^ self |
|
3316 |
! |
|
3317 |
||
3318 |
asStringCollection |
|
3319 |
"return a collection of lines from myself." |
|
3320 |
||
3321 |
^ StringCollection fromString:self "string" |
|
3322 |
||
3323 |
"Modified: 13.5.1996 / 20:36:59 / cg" |
|
3324 |
! |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3325 |
|
1434 | 3326 |
asSymbol |
19039 | 3327 |
"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
|
3328 |
The receiver must be a singleByte-String. |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3329 |
TwoByte- and FourByteSymbols are (currently ?) not allowed." |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3330 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3331 |
|str| |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3332 |
|
9192 | 3333 |
str := self string. |
3334 |
str ~~ self ifTrue:[ ^ str asSymbol ]. |
|
3335 |
^ self asSingleByteString asSymbol |
|
3336 |
! |
|
3337 |
||
3338 |
asSymbolIfInterned |
|
17183 | 3339 |
"If a symbol with the receiver's characters is already known, return it. Otherwise, return nil. |
9230 | 3340 |
This can be used to query for an existing symbol and is the same as: |
18967 | 3341 |
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
|
3342 |
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
|
3343 |
The receiver must be a singleByte-String. |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
3344 |
TwoByte- and FourByteSymbols are (currently ?) not allowed." |
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3345 |
|
18967 | 3346 |
|str| |
3347 |
||
3348 |
str := self string. |
|
3349 |
str == self ifTrue:[ |
|
3350 |
"must be some kind of N-ByteString" |
|
3351 |
str := self asSingleByteStringIfPossible. |
|
3352 |
str == self ifTrue:[ |
|
3353 |
"single byte string conversion is not possible" |
|
3354 |
^ nil. |
|
3355 |
]. |
|
6642 | 3356 |
]. |
18967 | 3357 |
^ str asSymbolIfInterned |
3358 |
||
3359 |
" |
|
3360 |
(Unicode16String with:(Character value:16rFFFF)) asSymbolIfInterned |
|
3361 |
'new' asUnicodeString asSymbolIfInterned |
|
3362 |
'new' asText asSymbolIfInterned |
|
3363 |
'new' asUnicodeString asText asSymbolIfInterned |
|
3364 |
" |
|
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3365 |
|
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3366 |
"Created: 22.5.1996 / 16:37:04 / cg" |
9192 | 3367 |
! |
3368 |
||
3369 |
asText |
|
9403 | 3370 |
"return a Text-object (string with emphasis) from myself." |
9192 | 3371 |
|
3372 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
3373 |
Text isNil ifTrue:[^ self]. |
|
17065 | 3374 |
^ Text string:self |
9192 | 3375 |
|
3376 |
"Created: 12.5.1996 / 10:41:14 / cg" |
|
3377 |
! |
|
3378 |
||
17021 | 3379 |
asTimestamp |
3380 |
"convert the receiver into an Timestamp. |
|
3381 |
Notice, that errors may occur during the read, |
|
3382 |
so you better setup some exception handler when using this method." |
|
3383 |
||
3384 |
^ Timestamp readFromString:self |
|
3385 |
||
3386 |
" |
|
3387 |
'2014-11-10 21:30:22.444' asTimestamp |
|
3388 |
'2014-11-10 21:30:22.444Z' asTimestamp |
|
3389 |
'2014-11-10 21:30:22.444+0200' asTimestamp |
|
3390 |
" |
|
3391 |
! |
|
3392 |
||
9192 | 3393 |
asTitlecase |
8027 | 3394 |
"return a version of the receiver, where the first character is converted to titlecase, |
3395 |
and everything else to lowercase. |
|
3396 |
See the comment in Character on what titlecase is." |
|
3397 |
||
3398 |
|newStr c bitsPerCharacter |
|
3399 |
mySize "{ Class: SmallInteger }" | |
|
3400 |
||
3401 |
mySize := self size. |
|
3402 |
newStr := self species new:mySize. |
|
3403 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
3404 |
||
3405 |
1 to:mySize do:[:i | |
|
18662 | 3406 |
i == 1 ifTrue:[ |
3407 |
c := (self at:i) asTitlecase. |
|
3408 |
] ifFalse:[ |
|
3409 |
c := (self at:i) asLowercase. |
|
3410 |
]. |
|
3411 |
c bitsPerCharacter > bitsPerCharacter ifTrue:[ |
|
3412 |
newStr := c stringSpecies fromString:newStr. |
|
3413 |
bitsPerCharacter := newStr bitsPerCharacter. |
|
3414 |
]. |
|
3415 |
newStr at:i put:c |
|
8027 | 3416 |
]. |
3417 |
^ newStr |
|
3418 |
||
3419 |
" |
|
8874 | 3420 |
'helloWorld' asTitlecase |
3421 |
'HelloWorld' asTitlecase |
|
3422 |
'HELLOWORLD' asTitlecase |
|
3423 |
'helloworld' asTitlecase |
|
8027 | 3424 |
" |
9192 | 3425 |
! |
3426 |
||
3427 |
asTitlecaseFirst |
|
8023 | 3428 |
"return a version of the receiver, where the first character is converted to titlecase. |
8024 | 3429 |
Titlecase is much like uppercase for most characters, with the exception of some combined |
3430 |
(2-character glyphs), which consist of an upper- and lower-case characters. |
|
3431 |
If the first character is already titlecase, or there is no titlecasepercase for it, return the |
|
8023 | 3432 |
receiver." |
3433 |
||
8026 | 3434 |
" |
8874 | 3435 |
For example, in Unicode, character U+01F3 is LATIN SMALL LETTER DZ. |
3436 |
(Let us write this compound character using ASCII as 'dz'.) |
|
3437 |
This character uppercases to character U+01F1, LATIN CAPITAL LETTER DZ. |
|
3438 |
(Which is basically 'DZ'.) |
|
3439 |
But it titlecases to to character U+01F2, LATIN CAPITAL LETTER D WITH SMALL LETTER Z. |
|
8026 | 3440 |
(Which we can write 'Dz'.) |
3441 |
||
3442 |
character uppercase titlecase |
|
3443 |
--------- --------- --------- |
|
3444 |
dz DZ Dz |
|
3445 |
" |
|
3446 |
||
8023 | 3447 |
|newString firstChar firstCharAsTitlecase| |
3448 |
||
3449 |
firstChar := (self at:1). |
|
8025 | 3450 |
firstCharAsTitlecase := firstChar asTitlecase. |
8023 | 3451 |
firstChar == firstCharAsTitlecase ifTrue:[ ^ self]. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3452 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3453 |
firstCharAsTitlecase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3454 |
newString := firstCharAsTitlecase stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3455 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3456 |
newString := self stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3457 |
]. |
8023 | 3458 |
newString at:1 put:firstCharAsTitlecase. |
3459 |
^ newString |
|
3460 |
||
3461 |
" |
|
8874 | 3462 |
'helloWorld' asTitlecaseFirst |
3463 |
'HelloWorld' asTitlecaseFirst |
|
8023 | 3464 |
" |
9192 | 3465 |
! |
3466 |
||
3467 |
asTwoByteString |
|
3468 |
"return the receiver converted to a two-byte string. |
|
16051 | 3469 |
Will be obsolete soon - use asUnicode16String." |
9192 | 3470 |
|
3471 |
^ TwoByteString fromString:self |
|
3472 |
! |
|
3473 |
||
3474 |
asURI |
|
3475 |
"return an URI with string taken from the receiver" |
|
3476 |
||
3477 |
^ URI fromString:self |
|
3478 |
! |
|
8710 | 3479 |
|
5776 | 3480 |
asURL |
3481 |
"return an URL-object from myself." |
|
3482 |
||
3483 |
^ URL fromString:self |
|
3484 |
||
3485 |
" |
|
8874 | 3486 |
'http://www.exept.de:80/index.html' asURL host |
3487 |
'http://www.exept.de:80/index.html' asURL port |
|
9192 | 3488 |
'http://www.exept.de:80/index.html' asURL method |
3489 |
'http://www.exept.de:80/index.html' asURL path |
|
3490 |
" |
|
3491 |
! |
|
3492 |
||
18901 | 3493 |
asUUID |
3494 |
"return self as a UUID" |
|
3495 |
||
3496 |
^ UUID fromString:self |
|
3497 |
||
3498 |
" |
|
3499 |
UUID genUUID asString asUUID |
|
3500 |
'{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' asUUID |
|
3501 |
'{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' asUnicodeString asUUID |
|
3502 |
'EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B' asUUID |
|
3503 |
'EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B quatsch' asUUID |
|
3504 |
'quark EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B' asUUID |
|
3505 |
" |
|
3506 |
||
3507 |
"Modified: / 02-08-2007 / 16:43:29 / cg" |
|
3508 |
! |
|
3509 |
||
9192 | 3510 |
asUnicode16String |
15035 | 3511 |
"return the receiver in a two-byte per character representation. |
3512 |
Normally, the internal ST/X representation should be transparent and not |
|
3513 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3514 |
such as wide-string ffi calls or file contents." |
|
3515 |
||
17600 | 3516 |
|sz| |
3517 |
||
3518 |
sz := self size. |
|
3519 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3520 |
^ (Unicode16String new:sz) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3521 |
replaceFrom:1 to:sz with:self startingAt:1; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3522 |
yourself. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3523 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3524 |
" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3525 |
'abc' asUnicode16String |
17600 | 3526 |
" |
3527 |
! |
|
3528 |
||
3529 |
asUnicode16StringZ |
|
3530 |
"return the receiver in a two-byte per character representation. |
|
17625 | 3531 |
Make sure that is zero terminated (last char is 16r0000). |
17600 | 3532 |
Normally, the internal ST/X representation should be transparent and not |
3533 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3534 |
such as wide-string ffi calls or file contents." |
|
3535 |
||
3536 |
|sz| |
|
3537 |
||
3538 |
sz := self size. |
|
3539 |
(self at:sz) == (Character codePoint:0) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3540 |
^ self asUnicode16String. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3541 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3542 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3543 |
^ (Unicode16String new:sz+1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3544 |
replaceFrom:1 to:sz with:self startingAt:1; |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3545 |
at:sz+1 put:(Character codePoint:0); |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3546 |
yourself. |
17600 | 3547 |
|
3548 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3549 |
'abc' asUnicode16StringZ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3550 |
'abc' asUnicode16String asUnicode16StringZ |
17600 | 3551 |
" |
9192 | 3552 |
! |
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3553 |
|
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3554 |
asUnicode32String |
16051 | 3555 |
"return the receiver in a four-byte per character representation. |
3556 |
Normally, the internal ST/X representation should be transparent and not |
|
3557 |
of the programmer's concern; except when strings are passed to the outside world, |
|
3558 |
such as wide-string ffi calls or file contents." |
|
3559 |
||
3560 |
^ self as:Unicode32String |
|
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3561 |
! |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3562 |
|
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3563 |
asUnicodeString |
16051 | 3564 |
"return the receiver in a two-byte per character representation. |
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 |
^ self asUnicode16String |
|
3570 |
" |
|
3571 |
'Hello World' asUnicodeString |
|
14141
e86d245213b0
comment/format in: #asUnicodeString
Stefan Vogel <sv@exept.de>
parents:
14137
diff
changeset
|
3572 |
" |
8295
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3573 |
! |
8433d819226b
Define #asUnicode16String and #asUnicode32String in CharacterArray
Stefan Vogel <sv@exept.de>
parents:
8222
diff
changeset
|
3574 |
|
13073 | 3575 |
asUnixFilename |
3576 |
"return a UnixFilename with pathname taken from the receiver" |
|
3577 |
||
3578 |
^ UnixFilename named:self |
|
3579 |
||
3580 |
"Created: / 20-09-2010 / 21:42:55 / cg" |
|
3581 |
! |
|
3582 |
||
608 | 3583 |
asUppercase |
3584 |
"return a copy of myself in uppercase letters" |
|
3585 |
||
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3586 |
|newStr c bitsPerCharacter |
608 | 3587 |
mySize "{ Class: SmallInteger }" | |
3588 |
||
3589 |
mySize := self size. |
|
8954
12e701d7b5ac
allow for receiver to be empty in asLowercase and asUppercase.
Claus Gittinger <cg@exept.de>
parents:
8938
diff
changeset
|
3590 |
mySize == 0 ifTrue:[^ self]. |
608 | 3591 |
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
|
3592 |
bitsPerCharacter := newStr bitsPerCharacter. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3593 |
|
18657 | 3594 |
"/ handle the very seldom case of a lowercase char which needs |
3595 |
"/ more bits in its uppercase variant |
|
3596 |
"/ (there are only a few of them) |
|
3597 |
||
608 | 3598 |
1 to:mySize do:[:i | |
18657 | 3599 |
c := (self at:i) asUppercase. |
3600 |
c bitsPerCharacter > bitsPerCharacter ifTrue:[ |
|
3601 |
newStr := c stringSpecies fromString:newStr. |
|
18662 | 3602 |
bitsPerCharacter := newStr bitsPerCharacter. |
18657 | 3603 |
]. |
3604 |
newStr at:i put:c |
|
608 | 3605 |
]. |
3606 |
^ newStr |
|
3607 |
||
3608 |
" |
|
8874 | 3609 |
'helloWorld' asUppercase |
3610 |
'helloWorld' asUppercaseFirst |
|
9192 | 3611 |
(Character value:16rB5) asString asUppercase -- needs 16 bits !! |
18657 | 3612 |
(Character value:16rFF) asString asUppercase -- needs 16 bits !! |
9192 | 3613 |
" |
3614 |
! |
|
3615 |
||
3616 |
asUppercaseFirst |
|
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3617 |
"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
|
3618 |
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
|
3619 |
receiver." |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3620 |
|
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3621 |
|newString firstChar firstCharAsUppercase| |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3622 |
|
12679 | 3623 |
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
|
3624 |
firstChar := self at:1. |
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3625 |
firstCharAsUppercase := firstChar asUppercase. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3626 |
firstChar == firstCharAsUppercase ifTrue:[ ^ self]. |
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3627 |
|
12679 | 3628 |
"/ 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
|
3629 |
firstCharAsUppercase bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3630 |
newString := firstCharAsUppercase stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3631 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3632 |
newString := self stringSpecies fromString:self. |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
3633 |
]. |
8003
6e690f4b79f1
asLowercase/asUppercase and friends care for 16-bit chars
Claus Gittinger <cg@exept.de>
parents:
7995
diff
changeset
|
3634 |
newString at:1 put:firstCharAsUppercase. |
608 | 3635 |
^ newString |
3636 |
||
3637 |
" |
|
8874 | 3638 |
'helloWorld' asUppercase |
3639 |
'helloWorld' asUppercaseFirst |
|
3640 |
'HelloWorld' asUppercaseFirst |
|
608 | 3641 |
" |
9192 | 3642 |
! |
3643 |
||
11828 | 3644 |
asUppercaseLast |
3645 |
"return a copy of myself where the last character is |
|
3646 |
converted to uppercase." |
|
3647 |
||
3648 |
|newString sz| |
|
3649 |
||
3650 |
sz := self size. |
|
3651 |
newString := self copyFrom:1 to:sz. |
|
3652 |
sz > 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3653 |
newString at:sz put:(newString at:sz) asUppercase |
11828 | 3654 |
]. |
3655 |
^ newString |
|
3656 |
||
3657 |
" |
|
12177 | 3658 |
'HelloWorld' asUppercase |
3659 |
'HelloWorld' asUppercaseLast |
|
11828 | 3660 |
" |
3661 |
! |
|
3662 |
||
17021 | 3663 |
asUtcTimestamp |
3664 |
"convert the receiver into an UtcTimestamp (Time is interpreted in the UTC timezone). |
|
3665 |
Notice, that errors may occur during the read, |
|
3666 |
so you better setup some exception handler when using this method." |
|
3667 |
||
3668 |
^ UtcTimestamp readFromString:self |
|
3669 |
||
3670 |
" |
|
3671 |
'2014-11-10 21:30:22.444' asUtcTimestamp |
|
3672 |
" |
|
3673 |
! |
|
3674 |
||
11062 | 3675 |
literalArrayEncoding |
3676 |
"encode myself as an array literal, from which a copy of the receiver |
|
3677 |
can be reconstructed with #decodeAsLiteralArray." |
|
3678 |
||
3679 |
^ self |
|
3680 |
||
3681 |
"Modified: 1.9.1995 / 02:25:45 / claus" |
|
3682 |
"Modified: 22.4.1996 / 13:00:50 / cg" |
|
3683 |
! |
|
3684 |
||
9192 | 3685 |
string |
3686 |
"return the receiver - for ST-80 compatibility" |
|
3687 |
||
3688 |
^ self |
|
3689 |
||
3690 |
"Modified: 27.4.1996 / 13:29:30 / cg" |
|
3691 |
! ! |
|
3692 |
||
3693 |
!CharacterArray methodsFor:'copying'! |
|
3694 |
||
3695 |
, aStringOrCharacter |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3696 |
"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
|
3697 |
This is nonStandard, but convenient" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3698 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3699 |
|myWidth otherWidth| |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3700 |
|
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3701 |
aStringOrCharacter isCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3702 |
^ self copyWith:aStringOrCharacter |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3703 |
]. |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3704 |
aStringOrCharacter isText ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3705 |
^ aStringOrCharacter concatenateFromString:self |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3706 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3707 |
aStringOrCharacter isString ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3708 |
(otherWidth := aStringOrCharacter bitsPerCharacter) ~~ (myWidth := self bitsPerCharacter) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3709 |
otherWidth > myWidth ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3710 |
^ (aStringOrCharacter species fromString:self) , aStringOrCharacter |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3711 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3712 |
^ self , (self species fromString:aStringOrCharacter) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3713 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3714 |
]. |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3715 |
^ super , aStringOrCharacter |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3716 |
|
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3717 |
" |
8874 | 3718 |
'hello' , $1 |
3719 |
'hello' , '1' |
|
3720 |
'hello' , (' world' asText allBold) |
|
3721 |
'hello' , (JISEncodedString fromString:' world') |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3722 |
(JISEncodedString fromString:'hello') , ' world' |
1411 | 3723 |
|
1422 | 3724 |
Transcript showCR: |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3725 |
(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
|
3726 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3727 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3728 |
"Modified: 28.6.1997 / 00:13:17 / cg" |
9192 | 3729 |
! |
3730 |
||
3731 |
,, aString |
|
7020 | 3732 |
"concatenate with a newLine in between" |
6965 | 3733 |
|
3734 |
^ (self copyWith:Character cr) , aString |
|
3735 |
||
3736 |
" |
|
3737 |
hello ,, world |
|
7020 | 3738 |
'hello' ,, 'world' |
6965 | 3739 |
" |
3740 |
! |
|
3741 |
||
11329 | 3742 |
chopTo:maxLen |
3743 |
"if the receivers size is less or equal to maxLen, return it. |
|
3744 |
Otherwise, return a copy of the receiver, where some characters |
|
3745 |
in the middle have been removed for a total string length |
|
3746 |
of maxLen." |
|
3747 |
||
3748 |
|sz n1 n2| |
|
3749 |
||
3750 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3751 |
||
3752 |
n1 := n2 := maxLen // 2. |
|
3753 |
maxLen odd ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3754 |
n2 := n1 + 1 |
11329 | 3755 |
]. |
3756 |
^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1) |
|
3757 |
||
3758 |
" |
|
3759 |
'12345678901234' chopTo:15 |
|
3760 |
'123456789012345' chopTo:15 |
|
3761 |
'1234567890123456' chopTo:15 |
|
3762 |
'aShortString' chopTo:15 |
|
3763 |
'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 |
|
3764 |
" |
|
3765 |
||
3766 |
"Modified: / 24-10-2006 / 12:32:01 / cg" |
|
3767 |
! |
|
3768 |
||
3769 |
contractAtBeginningTo:maxLen |
|
3770 |
"if the receivers size is less or equal to maxLen, return it. |
|
3771 |
Otherwise, return a copy of the receiver, where some characters |
|
3772 |
at the beginning have been replaced by '...' for a total string length |
|
3773 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
3774 |
||
3775 |
|sz| |
|
3776 |
||
3777 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3778 |
||
3779 |
^ '...' , (self copyFrom:(sz - (maxLen - 4))) |
|
3780 |
||
3781 |
" |
|
3782 |
'12345678901234' contractAtBeginningTo:15 |
|
3783 |
'123456789012345' contractAtBeginningTo:15 |
|
3784 |
'1234567890123456' contractAtBeginningTo:15 |
|
3785 |
'aShortString' contractAtBeginningTo:15 |
|
3786 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15 |
|
3787 |
" |
|
3788 |
||
3789 |
"Modified: / 24-10-2006 / 12:32:13 / cg" |
|
3790 |
! |
|
3791 |
||
3792 |
contractAtEndTo:maxLen |
|
3793 |
"if the receivers size is less or equal to maxLen, return it. |
|
3794 |
Otherwise, return a copy of the receiver, where some characters |
|
3795 |
at the end have been replaced by '...' for a total string length |
|
3796 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
3797 |
||
3798 |
|sz| |
|
3799 |
||
3800 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3801 |
||
3802 |
^ (self copyTo:maxLen-3),'...' |
|
3803 |
||
3804 |
" |
|
3805 |
'12345678901234' contractAtEndTo:15 |
|
3806 |
'123456789012345' contractAtEndTo:15 |
|
3807 |
'1234567890123456' contractAtEndTo:15 |
|
3808 |
'aShortString' contractAtEndTo:15 |
|
3809 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 |
|
3810 |
" |
|
3811 |
||
3812 |
"Modified: / 24-10-2006 / 12:32:26 / cg" |
|
3813 |
! |
|
3814 |
||
3815 |
contractLeftTo:maxLen |
|
3816 |
"if the receivers size is less or equal to maxLen, return it. |
|
3817 |
Otherwise, return a copy of the receiver, where some characters |
|
3818 |
near the first quarter have been replaced by '...' for a total string length |
|
12177 | 3819 |
of maxLen. |
3820 |
Very similar to contractTo:, but better to abbreviate long filename entries, |
|
11329 | 3821 |
where the right part is of more use than the left." |
3822 |
||
3823 |
|sz "{ SmallInteger }" |
|
3824 |
halfSize quarterSize "{ SmallInteger }" |
|
3825 |
leftEnd rightEnd rightStart| |
|
3826 |
||
3827 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3828 |
||
3829 |
halfSize := maxLen // 2. |
|
3830 |
quarterSize := maxLen // 4. |
|
3831 |
leftEnd := quarterSize-1. |
|
3832 |
rightEnd := maxLen - leftEnd - 3. |
|
3833 |
rightStart := sz - rightEnd + 1. |
|
3834 |
^ (self copyTo:leftEnd),'...',(self copyFrom:rightStart) |
|
3835 |
||
3836 |
" |
|
12177 | 3837 |
'12345678901234' contractLeftTo:15 |
3838 |
'123456789012345' contractLeftTo:15 |
|
3839 |
'1234567890123456' contractLeftTo:15 |
|
3840 |
'aShortString' contractLeftTo:15 |
|
3841 |
'aVeryLongNameForAStringThatShouldBeShortened' contractLeftTo:15 |
|
11329 | 3842 |
'C:\Dokumente und Einstellungen\cg\work\bosch\dapas\hw_schnittstellen\DAPAS__HpibDLL.st' contractLeftTo:40 |
3843 |
" |
|
3844 |
! |
|
3845 |
||
3846 |
contractTo:maxLen |
|
3847 |
"if the receivers size is less or equal to maxLen, return it. |
|
3848 |
Otherwise, return a copy of the receiver, where some characters |
|
3849 |
in the middle have been replaced by '...' for a total string length |
|
3850 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
3851 |
||
13362 | 3852 |
|sz "{ SmallInteger }" leftSize rightSize| |
11329 | 3853 |
|
3854 |
(sz := self size) <= maxLen ifTrue:[ ^ self ]. |
|
3855 |
||
13362 | 3856 |
rightSize := maxLen // 2. |
3857 |
leftSize := maxLen - rightSize. |
|
13822 | 3858 |
leftSize := leftSize - 2. |
3859 |
rightSize := rightSize - 1. |
|
13362 | 3860 |
^ (self copyTo:leftSize),'...',(self copyFrom:(sz+1-rightSize)) |
3861 |
||
3862 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3863 |
'12345678901234' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3864 |
'123456789012345' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3865 |
'1234567890123456' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3866 |
'12345678901234567' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3867 |
'123456789012345678' contractTo:15 |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13879
diff
changeset
|
3868 |
'aShortString' contractTo:15 |
11329 | 3869 |
'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 |
3870 |
'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
|
3871 |
('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
|
3872 |
('1234567890123456789012345678901234567' contractTo:29) size |
13362 | 3873 |
" |
3874 |
||
13822 | 3875 |
"Modified (comment): / 24-11-2011 / 19:17:46 / cg" |
11329 | 3876 |
! |
3877 |
||
16202 | 3878 |
copyReplaceAll:oldElement with:newElement |
3879 |
"return a copy of the receiver as a string, where all elements equal to oldElement |
|
3880 |
have been replaced by newElement." |
|
3881 |
||
3882 |
"/ ANSI seems to allow a sequence to be replaced by another sequence, |
|
3883 |
"/ whereas the old ST80 meant replace all occurrences... - sigh. |
|
3884 |
oldElement isByteCollection ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3885 |
newElement isByteCollection ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3886 |
^ self copyReplaceString:oldElement withString:newElement. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3887 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3888 |
self halt:'check if this is legal'. |
16202 | 3889 |
]. |
3890 |
newElement isByteCollection ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3891 |
self halt:'check if this is legal'. |
16202 | 3892 |
]. |
16212 | 3893 |
^ super copyReplaceAll:oldElement with:newElement |
16202 | 3894 |
! |
3895 |
||
8347 | 3896 |
copyReplaceString:subString withString:newString |
3897 |
"return a copy of the receiver, with all sequences of subString replaced |
|
3898 |
by newString (i.e. slice in the newString in place of the oldString)." |
|
3899 |
||
3900 |
|tmpStream idx idx1| |
|
3901 |
||
15523 | 3902 |
tmpStream := self species writeStream. |
8347 | 3903 |
idx := 1. |
3904 |
[idx ~~ 0] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3905 |
idx1 := idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3906 |
idx := self indexOfSubCollection:subString startingAt:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3907 |
idx ~~ 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3908 |
tmpStream nextPutAll:(self copyFrom:idx1 to:idx-1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3909 |
tmpStream nextPutAll:newString. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3910 |
idx := idx + subString size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3911 |
] |
8347 | 3912 |
]. |
3913 |
tmpStream nextPutAll:(self copyFrom:idx1). |
|
3914 |
^ tmpStream contents |
|
3915 |
||
3916 |
" |
|
9306 | 3917 |
'12345678901234567890' copyReplaceString:'123' withString:'OneTwoThree' |
3918 |
'12345678901234567890' copyReplaceString:'123' withString:'*' |
|
3919 |
'12345678901234567890' copyReplaceString:'234' withString:'foo' |
|
3920 |
||
3921 |
('a string with spaces' copyReplaceAll:$ withAll:' foo ') |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3922 |
copyReplaceString:'foo' withString:'bar' |
8347 | 3923 |
" |
3924 |
||
3925 |
"Modified: / 31-05-1999 / 12:33:59 / cg" |
|
3926 |
"Created: / 12-05-2004 / 12:00:00 / cg" |
|
3927 |
! |
|
3928 |
||
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3929 |
copyWith:aCharacter |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3930 |
"return a new string containing the receivers characters |
8874 | 3931 |
and the single new character, aCharacter. |
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3932 |
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
|
3933 |
as argument, but equivalent to copy-and-addLast. |
8874 | 3934 |
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
|
3935 |
(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
|
3936 |
|
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3937 |
|sz newString| |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3938 |
|
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3939 |
aCharacter bitsPerCharacter > self bitsPerCharacter ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3940 |
sz := self size. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3941 |
newString := aCharacter stringSpecies new:sz + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3942 |
newString replaceFrom:1 to:sz with:self startingAt:1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3943 |
newString at:sz+1 put:aCharacter. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3944 |
^ newString. |
8040
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3945 |
]. |
f10cca439066
copyWith for mixed-width string/character
Claus Gittinger <cg@exept.de>
parents:
8037
diff
changeset
|
3946 |
^ super copyWith:aCharacter |
17241 | 3947 |
! |
3948 |
||
3949 |
restAfter:keyword withoutSeparators:strip |
|
3950 |
"compare the left of the receiver with keyword, |
|
3951 |
if it matches return the right. |
|
3952 |
Finally, if strip is true, remove whiteSpace. |
|
3953 |
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
|
3954 |
something: rest |
17241 | 3955 |
where we are interested in rest, but only if the receiver string |
3956 |
begins with something. |
|
3957 |
||
3958 |
You may wonder why such a specialized method exists here |
|
3959 |
- this is so common when processing mailboxes, |
|
3960 |
rcs files, nntp/pop3 responses, that is was considered worth |
|
3961 |
a special method here to avoid having the code below a hundred |
|
3962 |
times in variuos places." |
|
3963 |
||
3964 |
|rest| |
|
3965 |
||
3966 |
(self startsWith:keyword) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3967 |
rest := self copyFrom:(keyword size + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3968 |
strip ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3969 |
rest := rest withoutSeparators |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3970 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3971 |
^ rest |
17241 | 3972 |
]. |
3973 |
^ nil |
|
3974 |
||
3975 |
" |
|
3976 |
'foo: hello world' restAfter:'foo:' withoutSeparators:true |
|
3977 |
'funny: something' restAfter:'foo:' withoutSeparators:true |
|
3978 |
||
3979 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:true |
|
3980 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:false |
|
3981 |
" |
|
3982 |
||
3983 |
"Created: 25.11.1995 / 11:04:18 / cg" |
|
3984 |
! |
|
3985 |
||
3986 |
splitAtString:subString withoutSeparators:strip |
|
3987 |
"If the receiver is of the form: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3988 |
<left><subString><right> |
17241 | 3989 |
return a collection containing left and right only. |
3990 |
If strip is true, remove whiteSpace in the returned substrings." |
|
3991 |
||
3992 |
|idx left right| |
|
3993 |
||
3994 |
(idx := self indexOfSubCollection:subString) ~~ 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3995 |
left := self copyTo:(idx - 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3996 |
right := self copyFrom:(idx + subString size). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3997 |
strip ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3998 |
left := left withoutSeparators. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
3999 |
right := right withoutSeparators. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4000 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4001 |
^ StringCollection with:left with:right |
17241 | 4002 |
]. |
4003 |
self error:'substring not present in receiver' mayProceed:true. |
|
4004 |
^ self |
|
4005 |
||
4006 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4007 |
'hello -> world' splitAtString:'->' withoutSeparators:false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4008 |
'hello -> world' splitAtString:'->' withoutSeparators:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4009 |
'hello -> ' splitAtString:'->' withoutSeparators:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4010 |
'hello > error' splitAtString:'->' withoutSeparators:true |
17241 | 4011 |
" |
4012 |
||
4013 |
"Created: 25.11.1995 / 11:04:18 / cg" |
|
608 | 4014 |
! ! |
4015 |
||
4016 |
!CharacterArray methodsFor:'displaying'! |
|
4017 |
||
2762 | 4018 |
displayOn:aGC x:x y:y from:start to:stop |
4019 |
"display the receiver on a GC" |
|
4020 |
||
12171 | 4021 |
self displayOn:aGC x:x y:y from:start to:stop opaque:false |
4022 |
||
4023 |
"Modified: 12.5.1996 / 12:49:33 / cg" |
|
4024 |
! |
|
4025 |
||
4026 |
displayOn:aGC x:x y:y from:start to:stop opaque:opaque |
|
4027 |
"display the receiver on a GC" |
|
4028 |
||
2762 | 4029 |
"q&d hack" |
4030 |
||
12177 | 4031 |
(start == 1 and:[stop == self size]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4032 |
self displayOn:aGC x:x y:y opaque:opaque. |
12177 | 4033 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4034 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:opaque. |
12177 | 4035 |
]. |
2762 | 4036 |
! |
4037 |
||
7082 | 4038 |
displayOn:aGc x:x y:y opaque:opaque |
2762 | 4039 |
"display the receiver in a graphicsContext - this method allows |
4040 |
strings to be used like DisplayObjects." |
|
4041 |
||
4042 |
|s| |
|
4043 |
||
4044 |
s := self string. |
|
7082 | 4045 |
opaque ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4046 |
aGc displayOpaqueString:s x:x y:y. |
2762 | 4047 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4048 |
aGc displayString:s x:x y:y. |
2762 | 4049 |
]. |
1381 | 4050 |
|
4051 |
"Modified: 11.5.1996 / 14:42:48 / cg" |
|
4052 |
! |
|
4053 |
||
2762 | 4054 |
displayOpaqueOn:aGC x:x y:y from:start to:stop |
4055 |
"display the receiver on a GC" |
|
4056 |
||
12171 | 4057 |
self displayOn:aGC x:x y:y from:start to:stop opaque:true |
608 | 4058 |
! ! |
4059 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4060 |
!CharacterArray methodsFor:'emphasis'! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4061 |
|
11632
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4062 |
actionForAll:aBlock |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4063 |
"change the action block of all characters. |
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4064 |
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
|
4065 |
|
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4066 |
^ self asText actionForAll:aBlock |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4067 |
! |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4068 |
|
5732 | 4069 |
allBold |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4070 |
"return a text object representing the receiver, but all boldified" |
5732 | 4071 |
|
8874 | 4072 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
6187 | 4073 |
Text isNil ifTrue:[^ self]. |
5732 | 4074 |
^ self asText allBold |
4075 |
||
4076 |
" |
|
4077 |
Transcript showCR:'hello' asText allBold |
|
4078 |
Transcript showCR:'hello' allBold |
|
4079 |
" |
|
4080 |
! |
|
4081 |
||
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4082 |
allItalic |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4083 |
"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
|
4084 |
|
8874 | 4085 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
6187 | 4086 |
Text isNil ifTrue:[^ self]. |
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4087 |
^ self asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4088 |
|
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4089 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4090 |
Transcript showCR:'hello' asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4091 |
Transcript showCR:'hello' allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4092 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4093 |
! |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4094 |
|
11345 | 4095 |
allStrikedOut |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4096 |
"return a text object representing the receiver, but all in strikeout" |
11345 | 4097 |
|
4098 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
4099 |
Text isNil ifTrue:[^ self]. |
|
4100 |
^ self asText allStrikedOut |
|
4101 |
||
4102 |
" |
|
4103 |
Transcript showCR:'hello' asText allStrikedOut |
|
4104 |
Transcript showCR:'hello' allStrikedOut |
|
4105 |
" |
|
4106 |
! |
|
4107 |
||
10862 | 4108 |
allUnderlined |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4109 |
"return a text object representing the receiver, but all with underline" |
10862 | 4110 |
|
4111 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
|
4112 |
Text isNil ifTrue:[^ self]. |
|
4113 |
^ self asText allUnderlined |
|
4114 |
||
4115 |
" |
|
4116 |
Transcript showCR:'hello' asText allUnderlined |
|
4117 |
Transcript showCR:'hello' allUnderlined |
|
4118 |
" |
|
4119 |
! |
|
4120 |
||
6228 | 4121 |
colorizeAllWith:aColor |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4122 |
"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
|
4123 |
|
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4124 |
"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
|
4125 |
Text isNil ifTrue:[^ self]. |
6228 | 4126 |
^ self asText colorizeAllWith:aColor |
4127 |
||
4128 |
" |
|
4129 |
Transcript showCR:('hello' colorizeAllWith:Color red) |
|
4130 |
Transcript showCR:('world' colorizeAllWith:Color green darkened) |
|
4131 |
" |
|
4132 |
! |
|
4133 |
||
12330
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4134 |
colorizeAllWith:fgColor on:bgColor |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4135 |
"return a text object representing the receiver, but all colorized with |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4136 |
both fg and background color" |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4137 |
|
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4138 |
"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
|
4139 |
Text isNil ifTrue:[^ self]. |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4140 |
^ self asText colorizeAllWith:fgColor on:bgColor |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4141 |
|
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4142 |
" |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4143 |
Transcript showCR:('hello' colorizeAllWith:Color red on:Color yellow) |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4144 |
Transcript showCR:('world' colorizeAllWith:Color red) |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4145 |
" |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4146 |
! |
f9b57b0b8a8b
added: #colorizeAllWith:on:
Claus Gittinger <cg@exept.de>
parents:
12326
diff
changeset
|
4147 |
|
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4148 |
emphasis |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4149 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4150 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4151 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4152 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4153 |
^ RunArray new:self size withAll:nil |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4154 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4155 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4156 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4157 |
|
6655 | 4158 |
emphasis:emphasisCollection |
4159 |
^ self asText emphasis:emphasisCollection |
|
4160 |
||
4161 |
" |
|
4162 |
Transcript showCR:('hello' emphasis:#(bold bold bold bold bold)) |
|
4163 |
" |
|
4164 |
! |
|
4165 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4166 |
emphasisAt:characterIndex |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4167 |
"return the emphasis at some index. |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4168 |
Since characterArrays do not hold any emphasis information, |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4169 |
nil (no emphasis) is returned here." |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4170 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4171 |
^ nil |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4172 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4173 |
"Created: 11.5.1996 / 14:13:27 / cg" |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4174 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4175 |
|
11632
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4176 |
emphasisAtPoint:aPoint on:aGC |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4177 |
"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
|
4178 |
|
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4179 |
^ nil |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4180 |
! |
b82e9f3cabd1
new: #actionForAll: #emphasisAtPoint:on:
Stefan Vogel <sv@exept.de>
parents:
11630
diff
changeset
|
4181 |
|
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4182 |
emphasisCollection |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4183 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4184 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4185 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4186 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4187 |
^ RunArray new:(self size) |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4188 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4189 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4190 |
"Modified: 14.5.1996 / 15:02:29 / cg" |
3404 | 4191 |
! |
4192 |
||
11919 | 4193 |
emphasiseFrom:start to:stop with:newEmphasis |
4194 |
"set to the emphasis within some range. return the receiver" |
|
4195 |
||
4196 |
^ self asText emphasiseFrom:start to:stop with:newEmphasis |
|
4197 |
||
4198 |
" |
|
12177 | 4199 |
'hello' emphasiseFrom:2 with:#italic |
11919 | 4200 |
|
4201 |
Transcript showCR:('hello' emphasiseFrom:2 with:#italic) |
|
4202 |
" |
|
4203 |
! |
|
4204 |
||
4205 |
emphasiseFrom:start with:newEmphasis |
|
4206 |
"set to the emphasis within some range. return the receiver" |
|
4207 |
||
4208 |
^ self emphasiseFrom:start to:(self size) with:newEmphasis |
|
4209 |
||
4210 |
" |
|
12177 | 4211 |
'hello' emphasiseFrom:2 with:#italic |
11919 | 4212 |
|
4213 |
Transcript showCR:('hello' emphasiseFrom:2 with:#italic) |
|
4214 |
" |
|
4215 |
! |
|
4216 |
||
3404 | 4217 |
emphasizeAllWith:emphasis |
12326
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4218 |
"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
|
4219 |
|
c67f12213ddb
comment/format in:5 methods
Claus Gittinger <cg@exept.de>
parents:
12319
diff
changeset
|
4220 |
"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
|
4221 |
Text isNil ifTrue:[^ self]. |
3404 | 4222 |
^ self asText emphasizeAllWith:emphasis |
4223 |
||
4224 |
" |
|
4225 |
Transcript showCR:('hello' emphasizeAllWith:#bold) |
|
3599 | 4226 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
4227 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
|
4228 |
" |
|
4229 |
||
4230 |
"Modified: / 17.6.1998 / 12:51:44 / cg" |
|
5097 | 4231 |
! |
4232 |
||
4233 |
makeSelectorBoldIn:aClass |
|
14050 | 4234 |
"the receiver represents some source code for a method in aClass. |
5097 | 4235 |
Change myself to boldify the selector. |
14050 | 4236 |
Not yet implemented (could easily use the syntaxHighlighter for this ...). |
4237 |
For protocol compatibility with other smalltalks" |
|
5097 | 4238 |
|
4239 |
^ self |
|
4240 |
||
14050 | 4241 |
"Created: / 13-12-1999 / 21:49:24 / cg" |
4242 |
! |
|
4243 |
||
16697 | 4244 |
withColor:aColor |
4245 |
"return a text object representing the receiver, but all colorized" |
|
4246 |
||
4247 |
^ self colorizeAllWith:aColor |
|
4248 |
||
4249 |
" |
|
4250 |
Transcript showCR:('hello' withColor:Color red) |
|
4251 |
Transcript showCR:('world' withColor:Color green darkened) |
|
4252 |
" |
|
4253 |
! |
|
4254 |
||
14050 | 4255 |
withoutAnyColorEmphasis |
4256 |
"for protocol compatibility with Text" |
|
4257 |
||
4258 |
^ self |
|
4259 |
||
4260 |
"Created: / 06-03-2012 / 18:15:38 / cg" |
|
6653 | 4261 |
! |
4262 |
||
12396 | 4263 |
withoutBackgroundColorEmphasis |
14050 | 4264 |
"for protocol compatibility with Text" |
4265 |
||
12396 | 4266 |
^ self |
14050 | 4267 |
|
4268 |
"Modified (comment): / 06-03-2012 / 18:14:27 / cg" |
|
12396 | 4269 |
! |
4270 |
||
6653 | 4271 |
withoutEmphasis:emphasisToRemove |
14050 | 4272 |
"for protocol compatibility with Text" |
4273 |
||
6653 | 4274 |
^ self |
14050 | 4275 |
|
4276 |
"Modified (comment): / 06-03-2012 / 18:14:29 / cg" |
|
12396 | 4277 |
! |
4278 |
||
4279 |
withoutForegroundColorEmphasis |
|
14050 | 4280 |
"for protocol compatibility with Text" |
4281 |
||
12396 | 4282 |
^ self |
14050 | 4283 |
|
4284 |
"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
|
4285 |
! ! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4286 |
|
7265 | 4287 |
!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
|
4288 |
|
12767
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4289 |
decodeAsLiteralArray |
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4290 |
"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
|
4291 |
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
|
4292 |
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
|
4293 |
|
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4294 |
^ self |
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4295 |
! |
17d2c7268065
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12679
diff
changeset
|
4296 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4297 |
decodeFrom:encodingSymbol |
8874 | 4298 |
"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
|
4299 |
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
|
4300 |
|
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
4301 |
|myEncoding encoder| |
7950 | 4302 |
|
4303 |
encodingSymbol isNil ifTrue:[^ self]. |
|
4304 |
myEncoding := self encoding. |
|
4305 |
encodingSymbol == myEncoding ifTrue:[^ self]. |
|
4306 |
||
4307 |
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
|
4308 |
encoder isNil ifTrue:[^ self]. |
ca774158b317
code cleanup (removed old obsolete encoding stuff)
Claus Gittinger <cg@exept.de>
parents:
8102
diff
changeset
|
4309 |
^ 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
|
4310 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4311 |
|
9192 | 4312 |
encodeFrom:oldEncoding into:newEncoding |
4313 |
^ CharacterEncoder encodeString:self from:oldEncoding into:newEncoding |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
4314 |
|
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
4315 |
" |
17600 | 4316 |
'äüö' encodeFrom:#iso8859 into:#utf8 |
4317 |
('äüö' encodeFrom:#iso8859 into:#utf8) encodeFrom:#utf8 into:#unicode |
|
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
4318 |
" |
9192 | 4319 |
! |
4320 |
||
4321 |
rot13 |
|
8874 | 4322 |
"Usenet: from `rotate alphabet 13 places'] |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4323 |
The simple Caesar-cypher encryption that replaces each English |
8874 | 4324 |
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
|
4325 |
so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' |
8874 | 4326 |
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
|
4327 |
It is used to enclose the text in a sealed wrapper that the reader must choose |
8874 | 4328 |
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
|
4329 |
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
|
4330 |
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
|
4331 |
|
11865 | 4332 |
^ self rot:13 |
8874 | 4333 |
|
4334 |
" |
|
4335 |
'hello world' rot13 |
|
4336 |
'hello world' rot13 rot13 |
|
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4337 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4338 |
! |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4339 |
|
11865 | 4340 |
rot:n |
4341 |
"Usenet: from `rotate alphabet N places'] |
|
4342 |
The simple Caesar-cypher encryption that replaces each English |
|
4343 |
letter with the one N places forward or back along the alphabet, |
|
4344 |
so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' by rot 13 |
|
4345 |
Most Usenet news reading and posting programs include a rot13 feature. |
|
4346 |
It is used to enclose the text in a sealed wrapper that the reader must choose |
|
4347 |
to open -- e.g., for posting things that might offend some readers, or spoilers. |
|
4348 |
A major advantage of rot13 over rot(N) for other N is that it |
|
4349 |
is self-inverse, so the same code can be used for encoding and decoding." |
|
4350 |
||
4351 |
^ self species |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4352 |
streamContents:[:aStream | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4353 |
self do:[:char | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4354 |
aStream nextPut:(char rot:n) ]] |
11865 | 4355 |
|
4356 |
" |
|
4357 |
'hello world' rot:13 |
|
4358 |
('hello world' rot:13) rot:13 |
|
4359 |
" |
|
4360 |
! |
|
4361 |
||
15656 | 4362 |
utf16Encoded |
4363 |
"Return my UTF-16 representation as a new TwoByteString" |
|
4364 |
||
4365 |
|s| |
|
4366 |
||
4367 |
s := WriteStream on:(TwoByteString uninitializedNew:self size). |
|
4368 |
s nextPutAllUtf16:self. |
|
4369 |
^ s contents |
|
4370 |
||
4371 |
" |
|
4372 |
'abcde1234' utf16Encoded |
|
17600 | 4373 |
'abcdeäöüß' utf16Encoded |
15656 | 4374 |
" |
4375 |
||
4376 |
"Modified: / 11-05-2010 / 19:12:37 / cg" |
|
4377 |
! |
|
4378 |
||
9192 | 4379 |
utf8Encoded |
4380 |
"Return my UTF-8 representation as a new String" |
|
4381 |
||
17625 | 4382 |
|string| |
4383 |
||
4384 |
string := self string. |
|
4385 |
string ~~ self ifTrue:[ |
|
18597 | 4386 |
^ string utf8Encoded. |
17625 | 4387 |
]. |
14592 | 4388 |
|
18612 | 4389 |
^ CharacterEncoderImplementations::ISO10646_to_UTF8 new encodeString:self |
18597 | 4390 |
|
4391 |
" |
|
4392 |
'abcde1234' asUnicode32String utf8Encoded |
|
4393 |
'abcdeäöüß' asUnicode32String utf8Encoded |
|
12925
5c0a9a633ca1
comment/format in: #utf8Encoded
Claus Gittinger <cg@exept.de>
parents:
12912
diff
changeset
|
4394 |
" |
5c0a9a633ca1
comment/format in: #utf8Encoded
Claus Gittinger <cg@exept.de>
parents:
12912
diff
changeset
|
4395 |
|
5c0a9a633ca1
comment/format in: #utf8Encoded
Claus Gittinger <cg@exept.de>
parents:
12912
diff
changeset
|
4396 |
"Modified: / 11-05-2010 / 19:12:37 / cg" |
17625 | 4397 |
! |
4398 |
||
4399 |
utf8EncodedOn:aStream |
|
4400 |
"write to aStream in utf8 encoding" |
|
4401 |
||
4402 |
|string| |
|
4403 |
||
4404 |
string := self string. |
|
4405 |
string ~~ self ifTrue:[ |
|
18597 | 4406 |
^ string utf8EncodedOn:aStream. |
4407 |
]. |
|
4408 |
||
4409 |
self containsNon7BitAscii ifTrue:[ |
|
4410 |
aStream nextPutAllUtf8:self. |
|
4411 |
] ifFalse:[ |
|
4412 |
"speed up common case" |
|
4413 |
aStream nextPutAll:self. |
|
17625 | 4414 |
]. |
4415 |
||
18597 | 4416 |
" |
4417 |
String streamContents:[:w| |
|
4418 |
'abcde1234' asUnicode32String utf8EncodedOn:w |
|
4419 |
]. |
|
4420 |
String streamContents:[:w| |
|
4421 |
'abcde1234' asUnicode32String utf8EncodedOn:w |
|
4422 |
]. |
|
4423 |
String streamContents:[:w| |
|
4424 |
'abcdeäöüß' asUnicode32String utf8EncodedOn:w |
|
4425 |
]. |
|
17625 | 4426 |
" |
9192 | 4427 |
! ! |
4428 |
||
11345 | 4429 |
|
12111 | 4430 |
!CharacterArray methodsFor:'matching - glob expressions'! |
4431 |
||
4432 |
compoundMatch:aString |
|
4433 |
"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
|
4434 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
12111 | 4435 |
This is usable with fileName pattern fields. |
4436 |
||
4437 |
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
|
4438 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4439 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4440 |
NOTICE: the receiver is the match pattern" |
4441 |
||
15890 | 4442 |
^ self compoundMatch:aString caseSensitive:true withoutSeparators:false |
12111 | 4443 |
|
4444 |
" |
|
4445 |
'f*' match:'foo' |
|
4446 |
'b*' match:'foo' |
|
4447 |
'f*;b*' match:'foo' |
|
4448 |
'f*;b*' match:'bar' |
|
4449 |
'f*;b*' compoundMatch:'foo' |
|
4450 |
'f*;b*' compoundMatch:'bar' |
|
4451 |
" |
|
4452 |
||
4453 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4454 |
"Modified: / 16.12.1999 / 01:22:08 / cg" |
|
4455 |
! |
|
4456 |
||
15734 | 4457 |
compoundMatch:aString caseSensitive:caseSensitive |
12111 | 4458 |
"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
|
4459 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
12111 | 4460 |
This is usable with fileName pattern fields. |
4461 |
||
4462 |
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
|
4463 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4464 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4465 |
NOTICE: the receiver is the match pattern" |
4466 |
||
15890 | 4467 |
^self compoundMatch:aString caseSensitive:caseSensitive withoutSeparators:false |
4468 |
||
4469 |
" |
|
4470 |
'f*' match:'foo' |
|
4471 |
'b*' match:'foo' |
|
4472 |
'f*;b*' match:'foo' |
|
4473 |
'f*;b*' match:'bar' |
|
4474 |
'f*;b*' compoundMatch:'foo' |
|
4475 |
'f*;b*' compoundMatch:'bar' |
|
4476 |
'f*;b*' compoundMatch:'Foo' caseSensitive:false |
|
4477 |
'f*;b*' compoundMatch:'Bar' caseSensitive:false |
|
4478 |
'f*;b*' compoundMatch:'ccc' caseSensitive:false |
|
4479 |
" |
|
4480 |
||
4481 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
4482 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4483 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
4484 |
! |
|
4485 |
||
4486 |
compoundMatch:aString caseSensitive:caseSensitive withoutSeparators:withoutSeparators |
|
4487 |
"like match, but the receiver may be a compound match pattern, |
|
4488 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
|
4489 |
If withoutSeparators is true, spaces around individual patterns are stripped off. |
|
4490 |
This is usable with fileName pattern fields. |
|
4491 |
||
4492 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 4493 |
NOT the ST-80 meaning. |
15890 | 4494 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4495 |
NOTICE: the receiver is the match pattern" |
|
4496 |
||
12111 | 4497 |
|matchers| |
4498 |
||
4499 |
matchers := self asCollectionOfSubstringsSeparatedBy:$;. |
|
15890 | 4500 |
withoutSeparators ifTrue:[ matchers := matchers collect:[:each | each withoutSeparators] ]. |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4501 |
^ matchers |
19033 | 4502 |
contains:[:aPattern | |
4503 |
aPattern match:aString caseSensitive:caseSensitive escapeCharacter:nil |
|
4504 |
]. |
|
15734 | 4505 |
|
4506 |
" |
|
4507 |
'f*' match:'foo' |
|
4508 |
'b*' match:'foo' |
|
4509 |
'f*;b*' match:'foo' |
|
4510 |
'f*;b*' match:'bar' |
|
4511 |
'f*;b*' compoundMatch:'foo' |
|
4512 |
'f*;b*' compoundMatch:'bar' |
|
4513 |
'f*;b*' compoundMatch:'Foo' caseSensitive:false |
|
4514 |
'f*;b*' compoundMatch:'Bar' caseSensitive:false |
|
4515 |
'f*;b*' compoundMatch:'ccc' caseSensitive:false |
|
15890 | 4516 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4517 |
'f* ; b*' compoundMatch:'foo' |
15890 | 4518 |
'f* ; b*' compoundMatch:'foo' caseSensitive:true withoutSeparators:true |
15734 | 4519 |
" |
4520 |
||
4521 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
4522 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4523 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
4524 |
! |
|
4525 |
||
4526 |
compoundMatch:aString ignoreCase:ignoreCase |
|
4527 |
<resource: #obsolete> |
|
4528 |
||
4529 |
"like match, but the receiver may be a compound match pattern, |
|
4530 |
consisting of multiple simple GLOB patterns, separated by semicolons. |
|
4531 |
This is usable with fileName pattern fields. |
|
4532 |
||
4533 |
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
|
4534 |
NOT the ST-80 meaning. |
15734 | 4535 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4536 |
NOTICE: the receiver is the match pattern" |
|
4537 |
||
4538 |
^ self compoundMatch:aString caseSensitive:ignoreCase not |
|
12111 | 4539 |
|
4540 |
" |
|
4541 |
'f*' match:'foo' |
|
4542 |
'b*' match:'foo' |
|
4543 |
'f*;b*' match:'foo' |
|
4544 |
'f*;b*' match:'bar' |
|
4545 |
'f*;b*' compoundMatch:'foo' |
|
4546 |
'f*;b*' compoundMatch:'bar' |
|
4547 |
'f*;b*' compoundMatch:'Foo' ignoreCase:true |
|
4548 |
'f*;b*' compoundMatch:'Bar' ignoreCase:true |
|
4549 |
'f*;b*' compoundMatch:'ccc' ignoreCase:true |
|
4550 |
" |
|
4551 |
||
4552 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
|
4553 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
4554 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
|
4555 |
! |
|
4556 |
||
4557 |
findMatchString:matchString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4558 |
"like findString/indexOfSubCollection, but allowing GLOB match patterns. |
12111 | 4559 |
find matchstring; if found, return the index; |
4560 |
if not found, return 0. |
|
4561 |
||
4562 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
19033 | 4563 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4564 |
NOTICE: this GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4565 |
NOTICE: the argument is the match pattern" |
4566 |
||
19033 | 4567 |
^ self findMatchString:matchString startingAt:1 caseSensitive:true ifAbsent:0 |
4568 |
||
4569 |
" |
|
4570 |
1234567890123 |
|
4571 |
'hello world bla foo baz' findMatchString:'b* ' |
|
4572 |
" |
|
12111 | 4573 |
! |
4574 |
||
4575 |
findMatchString:matchString startingAt:index |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4576 |
"like findString, but allowing GLOB match patterns. |
12111 | 4577 |
find matchstring, starting at index. if found, return the index; |
4578 |
if not found, return 0. |
|
4579 |
||
4580 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 4581 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4582 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4583 |
NOTICE: the argument is the match pattern" |
4584 |
||
19033 | 4585 |
^ self findMatchString:matchString startingAt:index caseSensitive:true ifAbsent:0 |
12111 | 4586 |
! |
4587 |
||
15734 | 4588 |
findMatchString:matchString startingAt:index caseSensitive:caseSensitive ifAbsent:exceptionBlock |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4589 |
"like findString, but allowing GLOB match patterns. |
12111 | 4590 |
find matchstring, starting at index. if found, return the index; |
4591 |
if not found, return the result of evaluating exceptionBlock. |
|
4592 |
This is a q&d hack - not very efficient. |
|
4593 |
||
4594 |
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
|
4595 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4596 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4597 |
NOTICE: the argument is the match pattern" |
4598 |
||
4599 |
|firstChar firstSet |
|
4600 |
startIndex "{ Class: SmallInteger }" |
|
4601 |
matchSize "{ Class: SmallInteger }" |
|
4602 |
mySize "{ Class: SmallInteger }" |
|
4603 |
realMatchString lcChar ucChar| |
|
4604 |
||
4605 |
matchSize := matchString size. |
|
4606 |
matchSize == 0 ifTrue:[^ index]. "empty string matches" |
|
4607 |
||
4608 |
realMatchString := matchString. |
|
4609 |
(realMatchString endsWith:$*) ifFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4610 |
realMatchString := realMatchString , '*'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4611 |
matchSize := matchSize + 1 |
12111 | 4612 |
]. |
4613 |
||
4614 |
mySize := self size. |
|
4615 |
firstChar := realMatchString at:1. |
|
4616 |
firstChar == self class matchEscapeCharacter ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4617 |
firstChar := realMatchString at:2. |
12111 | 4618 |
]. |
4619 |
||
4620 |
firstChar asString includesMatchCharacters ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4621 |
index to:mySize do:[:col | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4622 |
(realMatchString match:self from:col to:mySize caseSensitive:caseSensitive) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4623 |
ifTrue:[^ col] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4624 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4625 |
^ exceptionBlock value. |
12111 | 4626 |
]. |
4627 |
||
4628 |
lcChar := firstChar asLowercase. |
|
4629 |
ucChar := firstChar asUppercase. |
|
15734 | 4630 |
(caseSensitive not and:[ lcChar ~= ucChar ]) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4631 |
firstSet := Array with:ucChar with:lcChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4632 |
startIndex := self indexOfAny:firstSet startingAt:index. |
12111 | 4633 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4634 |
startIndex := self indexOf:firstChar startingAt:index. |
12111 | 4635 |
]. |
4636 |
[startIndex == 0] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4637 |
(realMatchString match:self from:startIndex to:mySize caseSensitive:caseSensitive) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4638 |
ifTrue:[^ startIndex]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4639 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4640 |
firstSet notNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4641 |
startIndex := self indexOfAny:firstSet startingAt:(startIndex + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4642 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4643 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4644 |
]. |
12111 | 4645 |
]. |
4646 |
^ exceptionBlock value |
|
4647 |
||
4648 |
" |
|
4649 |
'one two three four' findMatchString:'o[nu]' |
|
4650 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
15734 | 4651 |
'one two three four one' findMatchString:'ONE' startingAt:3 caseSensitive:false ifAbsent:0 |
4652 |
'one two three four one' findMatchString:'ONE' startingAt:3 caseSensitive:true ifAbsent:0 |
|
4653 |
'one two three four ONE' findMatchString:'O#E' startingAt:1 caseSensitive:false ifAbsent:0 |
|
4654 |
'one two three four ONE' findMatchString:'O#E' startingAt:1 caseSensitive:true ifAbsent:0 |
|
4655 |
12345678901234567890 |
|
4656 |
" |
|
4657 |
||
4658 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
|
4659 |
! |
|
4660 |
||
4661 |
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock |
|
4662 |
<resource: #obsolete> |
|
4663 |
"like findString, but allowing GLOB match patterns. |
|
4664 |
find matchstring, starting at index. if found, return the index; |
|
4665 |
if not found, return the result of evaluating exceptionBlock. |
|
4666 |
This is a q&d hack - not very efficient. |
|
4667 |
||
4668 |
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
|
4669 |
NOT the ST-80 meaning. |
15734 | 4670 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4671 |
NOTICE: the argument is the match pattern" |
|
4672 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4673 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4674 |
findMatchString:matchString startingAt:index caseSensitive:ignoreCase not ifAbsent:exceptionBlock |
15734 | 4675 |
|
4676 |
" |
|
4677 |
'one two three four' findMatchString:'o[nu]' |
|
4678 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
12111 | 4679 |
'one two three four one' findMatchString:'ONE' startingAt:3 ignoreCase:true ifAbsent:0 |
4680 |
" |
|
4681 |
||
4682 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
|
4683 |
! |
|
4684 |
||
4685 |
includesMatchString:matchString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4686 |
"like includesString, but allowing GLOB match patterns. |
12111 | 4687 |
find matchstring; if found, return true, otherwise return false. |
4688 |
||
4689 |
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
|
4690 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4691 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4692 |
NOTICE: the argument is the match pattern" |
4693 |
||
4694 |
^ (self findMatchString:matchString) ~~ 0 |
|
4695 |
||
4696 |
" |
|
4697 |
'hello world' includesMatchString:'h*' |
|
4698 |
'hello world' includesMatchString:'h[aeiou]llo' |
|
4699 |
'hello world' includesMatchString:'wor*' |
|
4700 |
'hello world' includesMatchString:'woR*' |
|
4701 |
" |
|
4702 |
! |
|
4703 |
||
4704 |
includesMatchString:matchString caseSensitive:caseSensitive |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4705 |
"like includesString, but allowing GLOB match patterns. |
12111 | 4706 |
find matchstring; if found, return true, otherwise return false. |
4707 |
||
4708 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 4709 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4710 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4711 |
NOTICE: the argument is the match pattern" |
4712 |
||
19033 | 4713 |
^ (self findMatchString:matchString startingAt:1 caseSensitive:caseSensitive ifAbsent:0) ~~ 0 |
12111 | 4714 |
|
4715 |
" |
|
4716 |
'hello world' includesMatchString:'h*' caseSensitive:true |
|
4717 |
'hello world' includesMatchString:'h*' caseSensitive:false |
|
4718 |
'Hello world' includesMatchString:'h*' caseSensitive:true |
|
4719 |
'Hello world' includesMatchString:'h*' caseSensitive:false |
|
4720 |
||
4721 |
'hello world' includesMatchString:'h[aeiou]llo' caseSensitive:true |
|
4722 |
'hello world' includesMatchString:'h[aeiou]llo' caseSensitive:false |
|
4723 |
||
4724 |
'hello world' includesMatchString:'wor*' caseSensitive:true |
|
4725 |
'hello world' includesMatchString:'wor*' caseSensitive:false |
|
4726 |
||
4727 |
'hello world' includesMatchString:'woR*' caseSensitive:true |
|
4728 |
'hello world' includesMatchString:'woR*' caseSensitive:false |
|
4729 |
" |
|
4730 |
! |
|
4731 |
||
4732 |
match:aString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4733 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 4734 |
characters $* (to match any string) or $# (to match any character). |
4735 |
or [...] to match a set of characters. |
|
4736 |
Lower/uppercase are considered different. |
|
4737 |
The escape character is the backQuote. |
|
4738 |
||
4739 |
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
|
4740 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4741 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4742 |
NOTICE: the receiver is the match pattern" |
4743 |
||
15734 | 4744 |
^ self match:aString from:1 to:aString size caseSensitive:true |
12111 | 4745 |
|
4746 |
" |
|
4747 |
'\*f*' match:'f' |
|
4748 |
'\*f*' match:'*f' |
|
4749 |
'*\*f*' match:'*f' |
|
4750 |
'*f*' match:'*f' |
|
4751 |
'*ute*' match:'computer' |
|
4752 |
'*uter' match:'computer' |
|
4753 |
'uter*' match:'computer' |
|
4754 |
'*ute*' match:'' |
|
4755 |
'[abcd]*' match:'computer' |
|
4756 |
'[abcd]*' match:'komputer' |
|
4757 |
'*some*compl*ern*' match:'this is some more complicated pattern match' |
|
4758 |
'*some*compl*ern*' match:'this is another complicated pattern match' |
|
4759 |
'*-hh' match:'anton-h' |
|
4760 |
" |
|
4761 |
||
4762 |
"Modified: / 9.6.1998 / 18:50:00 / cg" |
|
4763 |
! |
|
4764 |
||
15734 | 4765 |
match:aString caseSensitive:caseSensitive |
4766 |
"return true if aString matches self, where self may contain GLOB meta-match |
|
4767 |
characters $* (to match any string) or $# (to match any character) |
|
4768 |
or [...] to match a set of characters. |
|
4769 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
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. |
15734 | 4774 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4775 |
NOTICE: the receiver is the match pattern" |
|
4776 |
||
4777 |
^ self match:aString from:1 to:aString size caseSensitive:caseSensitive |
|
4778 |
||
4779 |
" |
|
4780 |
'*ute*' match:'COMPUTER' caseSensitive:false |
|
4781 |
'*uter' match:'COMPUTER' caseSensitive:true |
|
4782 |
'[abcd]*' match:'computer' caseSensitive:true |
|
4783 |
'[abcd]*' match:'Computer' caseSensitive:true |
|
4784 |
'[a-k]*' match:'komputer' caseSensitive:true |
|
4785 |
'[a-k]*' match:'zomputer' caseSensitive:true |
|
4786 |
'[a-k]*' match:'Komputer' caseSensitive:true |
|
4787 |
'[a-k]*' match:'Komputer' caseSensitive:false |
|
4788 |
'*some*compl*ern*' match:'this is some more complicated pattern match' caseSensitive:false |
|
4789 |
'*some*compl*ern*' match:'this is another complicated pattern match' caseSensitive:false |
|
4790 |
||
4791 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4792 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4793 |
'[ab]*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4794 |
] |
15734 | 4795 |
]. |
4796 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4797 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4798 |
'*at:*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4799 |
] |
15734 | 4800 |
]. |
4801 |
" |
|
4802 |
||
4803 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
4804 |
! |
|
4805 |
||
4806 |
match:aString caseSensitive:caseSensitive escapeCharacter:escape |
|
4807 |
"return true if aString matches self, where self may contain GLOB meta-match |
|
4808 |
characters $* (to match any string) or $# (to match any character) |
|
4809 |
or [...] to match a set of characters. |
|
4810 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
4811 |
||
4812 |
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
|
4813 |
NOT the ST-80 meaning. |
15734 | 4814 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4815 |
NOTICE: the receiver is the match pattern" |
|
4816 |
||
4817 |
^ self match:aString from:1 to:aString size caseSensitive:caseSensitive escapeCharacter:escape |
|
4818 |
||
4819 |
" |
|
4820 |
'*ute*' match:'COMPUTER' caseSensitive:false |
|
4821 |
'*uter' match:'COMPUTER' caseSensitive:true |
|
4822 |
'[abcd]*' match:'computer' caseSensitive:true |
|
4823 |
'[abcd]*' match:'Computer' caseSensitive:true |
|
4824 |
'[a-k]*' match:'komputer' caseSensitive:true |
|
4825 |
'[a-k]*' match:'zomputer' caseSensitive:true |
|
4826 |
'[a-k]*' match:'Komputer' caseSensitive:true |
|
4827 |
'[a-k]*' match:'Komputer' caseSensitive:false |
|
4828 |
'*some*compl*ern*' match:'this is some more complicated pattern match' caseSensitive:false |
|
4829 |
'*some*compl*ern*' match:'this is another complicated pattern match' caseSensitive:false |
|
4830 |
||
4831 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4832 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4833 |
'[ab]*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4834 |
] |
15734 | 4835 |
]. |
4836 |
Time millisecondsToRun:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4837 |
Symbol allInstancesDo:[:sym | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4838 |
'*at:*' match:sym caseSensitive:true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4839 |
] |
15734 | 4840 |
]. |
4841 |
" |
|
4842 |
||
4843 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
4844 |
! |
|
4845 |
||
12111 | 4846 |
match:aString escapeCharacter:escape |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4847 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 4848 |
characters $* (to match any string) or $# (to match any character). |
4849 |
or [...] to match a set of characters. |
|
4850 |
Lower/uppercase are considered different. |
|
4851 |
||
4852 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 4853 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4854 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4855 |
NOTICE: the receiver is the match pattern" |
4856 |
||
19033 | 4857 |
^ self match:aString from:1 to:aString size caseSensitive:true escapeCharacter:escape |
12111 | 4858 |
|
4859 |
" |
|
4860 |
'a\b\c\*' match:'a\b\c\d' |
|
4861 |
'a\b\c\*' match:'a\b\c\d' escapeCharacter:nil |
|
4862 |
" |
|
4863 |
! |
|
4864 |
||
15734 | 4865 |
match:aString from:start to:stop caseSensitive:caseSensitive |
4866 |
"return true if part of aString matches myself, |
|
4867 |
where self may contain GLOB meta-match |
|
4868 |
characters $* (to match any string) or $# (to match any character) |
|
4869 |
or [...] to match a set of characters. |
|
4870 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
4871 |
The escape character is the backQuote. |
|
4872 |
||
4873 |
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
|
4874 |
NOT the ST-80 meaning. |
15734 | 4875 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4876 |
NOTICE: the receiver is the match pattern" |
|
4877 |
||
4878 |
^ self |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4879 |
match:aString from:start to:stop caseSensitive:caseSensitive |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4880 |
escapeCharacter:(self class matchEscapeCharacter) |
15734 | 4881 |
|
4882 |
" |
|
4883 |
'*ute*' match:'12345COMPUTER' from:1 to:5 caseSensitive:false |
|
4884 |
'*ute*' match:'12345COMPUTER' from:6 to:13 caseSensitive:false |
|
4885 |
" |
|
4886 |
||
4887 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
4888 |
! |
|
4889 |
||
4890 |
match:aString from:start to:stop caseSensitive:caseSensitive escapeCharacter:escape |
|
4891 |
"return true if part of aString matches myself, |
|
4892 |
where self may contain GLOB meta-match |
|
4893 |
characters $* (to match any string) or $# (to match any character) |
|
4894 |
or [...] to match a set of characters. |
|
4895 |
If caseSensitive is false, lower/uppercase are considered the same. |
|
4896 |
||
4897 |
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
|
4898 |
NOT the ST-80 meaning. |
15734 | 4899 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
4900 |
NOTICE: the receiver is the match pattern" |
|
4901 |
||
4902 |
|matchScanArray| |
|
4903 |
||
4904 |
" |
|
4905 |
keep the matchScanArray from the most recent match - |
|
4906 |
avoids parsing the pattern over-and over if multiple searches |
|
4907 |
are done with the same pattern. |
|
4908 |
" |
|
4909 |
(PreviousMatch notNil |
|
4910 |
and:[PreviousMatch key = self]) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4911 |
matchScanArray := PreviousMatch value |
15734 | 4912 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4913 |
matchScanArray := self class matchScanArrayFrom:self escapeCharacter:escape. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4914 |
matchScanArray isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4915 |
'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
|
4916 |
^ self = aString |
15734 | 4917 |
"/ ^ false |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4918 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4919 |
PreviousMatch := self -> matchScanArray. |
15734 | 4920 |
]. |
4921 |
||
4922 |
^ self class |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4923 |
matchScan:matchScanArray |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4924 |
from:1 to:matchScanArray size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4925 |
with:aString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4926 |
from:start to:stop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4927 |
caseSensitive:caseSensitive |
15734 | 4928 |
|
4929 |
" |
|
4930 |
'*ute*' match:'12345COMPUTER' from:1 to:5 caseSensitive:false |
|
4931 |
'*ute*' match:'12345COMPUTER' from:6 to:13 caseSensitive:false |
|
4932 |
" |
|
4933 |
||
4934 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
4935 |
! |
|
4936 |
||
12111 | 4937 |
match:aString from:start to:stop ignoreCase:ignoreCase |
15734 | 4938 |
<resource: #obsolete> |
12111 | 4939 |
"return true if part of aString matches myself, |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4940 |
where self may contain GLOB meta-match |
12111 | 4941 |
characters $* (to match any string) or $# (to match any character) |
4942 |
or [...] to match a set of characters. |
|
4943 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
4944 |
The escape character is the backQuote. |
|
4945 |
||
4946 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 4947 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4948 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4949 |
NOTICE: the receiver is the match pattern" |
4950 |
||
4951 |
^ self |
|
19033 | 4952 |
match:aString from:start to:stop caseSensitive:ignoreCase not |
4953 |
escapeCharacter:(self class matchEscapeCharacter) |
|
12111 | 4954 |
|
4955 |
" |
|
4956 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
4957 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
4958 |
" |
|
4959 |
||
4960 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
4961 |
! |
|
4962 |
||
4963 |
match:aString from:start to:stop ignoreCase:ignoreCase escapeCharacter:escape |
|
15734 | 4964 |
<resource: #obsolete> |
12111 | 4965 |
"return true if part of aString matches myself, |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4966 |
where self may contain GLOB meta-match |
12111 | 4967 |
characters $* (to match any string) or $# (to match any character) |
4968 |
or [...] to match a set of characters. |
|
4969 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
4970 |
||
4971 |
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
|
4972 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4973 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 4974 |
NOTICE: the receiver is the match pattern" |
4975 |
||
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4976 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4977 |
match:aString from:start to:stop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4978 |
caseSensitive:ignoreCase not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
4979 |
escapeCharacter:escape |
12111 | 4980 |
|
4981 |
" |
|
4982 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
4983 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
4984 |
" |
|
4985 |
||
4986 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
|
4987 |
! |
|
4988 |
||
4989 |
match:aString ignoreCase:ignoreCase |
|
15734 | 4990 |
<resource: #obsolete> |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4991 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 4992 |
characters $* (to match any string) or $# (to match any character) |
4993 |
or [...] to match a set of characters. |
|
4994 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
4995 |
The escape character is the backQuote. |
|
4996 |
||
4997 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 4998 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
4999 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5000 |
NOTICE: the receiver is the match pattern" |
5001 |
||
15734 | 5002 |
"/ leave it this way, in case a customer has redefined it for performance (for a while) |
19033 | 5003 |
^ self match:aString from:1 to:aString size caseSensitive:ignoreCase not |
12111 | 5004 |
|
5005 |
" |
|
5006 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
5007 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
5008 |
'[abcd]*' match:'computer' ignoreCase:false |
|
5009 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
5010 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
5011 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
5012 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
5013 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
5014 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
5015 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
5016 |
||
5017 |
Time millisecondsToRun:[ |
|
19033 | 5018 |
Symbol allInstancesDo:[:sym | |
5019 |
'[ab]*' match:sym ignoreCase:false |
|
5020 |
] |
|
12111 | 5021 |
]. |
5022 |
Time millisecondsToRun:[ |
|
19033 | 5023 |
Symbol allInstancesDo:[:sym | |
5024 |
'*at:*' match:sym ignoreCase:false |
|
5025 |
] |
|
12111 | 5026 |
]. |
5027 |
" |
|
5028 |
||
5029 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
5030 |
! |
|
5031 |
||
5032 |
match:aString ignoreCase:ignoreCase escapeCharacter:escape |
|
15734 | 5033 |
<resource: #obsolete> |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5034 |
"return true if aString matches self, where self may contain GLOB meta-match |
12111 | 5035 |
characters $* (to match any string) or $# (to match any character) |
5036 |
or [...] to match a set of characters. |
|
5037 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
5038 |
||
5039 |
NOTICE: match-meta character interpretation is like in unix-matching (glob), |
|
19033 | 5040 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5041 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5042 |
NOTICE: the receiver is the match pattern" |
5043 |
||
19033 | 5044 |
^ self match:aString from:1 to:aString size caseSensitive:ignoreCase not escapeCharacter:escape |
12111 | 5045 |
|
5046 |
" |
|
5047 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
5048 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
5049 |
'[abcd]*' match:'computer' ignoreCase:false |
|
5050 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
5051 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
5052 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
5053 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
5054 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
5055 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
5056 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
5057 |
||
5058 |
Time millisecondsToRun:[ |
|
19033 | 5059 |
Symbol allInstancesDo:[:sym | |
5060 |
'[ab]*' match:sym ignoreCase:false |
|
5061 |
] |
|
12111 | 5062 |
]. |
5063 |
Time millisecondsToRun:[ |
|
19033 | 5064 |
Symbol allInstancesDo:[:sym | |
5065 |
'*at:*' match:sym ignoreCase:false |
|
5066 |
] |
|
12111 | 5067 |
]. |
5068 |
" |
|
5069 |
||
5070 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
|
5071 |
! |
|
5072 |
||
5073 |
matches:aPatternString |
|
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5074 |
"return true if the receiver matches aString, where aPatternString may contain GLOB meta-match |
12111 | 5075 |
characters $* (to match any string) or $# (to match any character). |
5076 |
or [...] to match a set of characters. |
|
5077 |
Lower/uppercase are considered different. |
|
5078 |
||
5079 |
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
|
5080 |
NOT the ST-80 meaning. |
12518
bfdcbf713b43
comment/format in:16 methods
Claus Gittinger <cg@exept.de>
parents:
12396
diff
changeset
|
5081 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
12111 | 5082 |
NOTICE: the receiver is the match pattern" |
5083 |
||
5084 |
^ aPatternString match:self |
|
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5085 |
! |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5086 |
|
15734 | 5087 |
matches:aPatternString caseSensitive:caseSensitive |
5088 |
"return true if the receiver matches aString, where aPatternString may contain GLOB meta-match |
|
5089 |
characters $* (to match any string) or $# (to match any character). |
|
5090 |
or [...] to match a set of characters. |
|
5091 |
||
5092 |
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
|
5093 |
NOT the ST-80 meaning. |
15734 | 5094 |
NOTICE: this is GLOB, which is different from regex matching (see matchesRegex:) |
5095 |
NOTICE: the receiver is the match pattern" |
|
5096 |
||
5097 |
^ aPatternString match:self caseSensitive:caseSensitive |
|
5098 |
! |
|
5099 |
||
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5100 |
matches:aPatternString ignoreCase:ignoreCase |
15734 | 5101 |
<resource: #obsolete> |
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5102 |
"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
|
5103 |
characters $* (to match any string) or $# (to match any character). |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5104 |
or [...] to match a set of characters. |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5105 |
Lower/uppercase are considered different. |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5106 |
|
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5107 |
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
|
5108 |
NOT the ST-80 meaning. |
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5109 |
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
|
5110 |
NOTICE: the receiver is the match pattern" |
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5111 |
|
15734 | 5112 |
^ aPatternString match:self caseSensitive:ignoreCase not |
14054
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5113 |
|
48d3fab77bd9
added: #matches:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
14053
diff
changeset
|
5114 |
"Created: / 08-03-2012 / 03:11:11 / cg" |
12111 | 5115 |
! ! |
5116 |
||
5117 |
||
18722 | 5118 |
!CharacterArray methodsFor:'matching - regex'! |
5119 |
||
5120 |
matchesRegex:regexString caseSensitive:aBoolean |
|
5121 |
"Test if the receiver matches a regex. |
|
5122 |
May raise RxParser>>regexErrorSignal or child signals. |
|
5123 |
This is a part of the Regular Expression Matcher package, |
|
5124 |
(c) 1996, 1999 Vassili Bykov. |
|
5125 |
Refer to `documentation' protocol of RxParser class for details." |
|
5126 |
||
5127 |
aBoolean ifFalse:[ |
|
5128 |
^ self matchesRegexIgnoringCase:regexString |
|
5129 |
] ifTrue:[ |
|
5130 |
^ self matchesRegex:regexString |
|
5131 |
]. |
|
5132 |
||
5133 |
" |
|
5134 |
'hello world' matchesRegex:'h.*d'. |
|
5135 |
" |
|
5136 |
||
5137 |
"Created: / 13-12-2010 / 11:01:49 / cg" |
|
5138 |
! ! |
|
17625 | 5139 |
|
9192 | 5140 |
!CharacterArray methodsFor:'padded copying'! |
5141 |
||
5142 |
centerPaddedTo:newSize |
|
5143 |
"return a new string consisting of the receivers characters, |
|
5144 |
plus spaces up to length and center the receivers characters in |
|
5145 |
the resulting string. |
|
5146 |
If the receivers size is equal or greater than the length argument, |
|
5147 |
the original receiver is returned unchanged." |
|
5148 |
||
5149 |
^ self centerPaddedTo:newSize with:(Character space) |
|
5150 |
||
5151 |
" |
|
5152 |
'foo' centerPaddedTo:10 |
|
5153 |
123 printString centerPaddedTo:10 |
|
5154 |
" |
|
5155 |
||
5156 |
"Created: 25.11.1995 / 10:53:57 / cg" |
|
5157 |
! |
|
9190 | 5158 |
|
5159 |
centerPaddedTo:size with:padCharacter |
|
5160 |
"return a new string of length size, which contains the receiver |
|
5161 |
centered (i.e. padded on both sides). |
|
5162 |
Characters are filled with padCharacter. |
|
8874 | 5163 |
If the receivers size is equal or greater than the length argument, |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5164 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5165 |
|
9190 | 5166 |
|len s| |
5167 |
||
5168 |
len := self size. |
|
9192 | 5169 |
(len < size) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5170 |
s := self species new:size withAll:padCharacter. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5171 |
s replaceFrom:(size - len) // 2 + 1 with:self. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5172 |
^ s |
9192 | 5173 |
] |
5174 |
||
9190 | 5175 |
" |
5176 |
'foo' centerPaddedTo:11 with:$. |
|
5177 |
'fooBar' centerPaddedTo:5 with:$. |
|
5178 |
123 printString centerPaddedTo:10 with:$. |
|
5179 |
(' ' , 123 printString) centerPaddedTo:10 with:$. |
|
5180 |
(Float pi printString) centerPaddedTo:15 with:(Character space) |
|
5181 |
(Float pi printString) centerPaddedTo:15 with:$- |
|
5182 |
(' ' , Float pi class name) centerPaddedTo:15 with:$. |
|
5183 |
" |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5184 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5185 |
|
9190 | 5186 |
decimalPaddedTo:size and:afterPeriod at:decimalCharacter |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5187 |
"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
|
5188 |
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
|
5189 |
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
|
5190 |
to be padded). |
8874 | 5191 |
If the receivers size is equal or greater than the length argument, |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5192 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5193 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5194 |
|
8874 | 5195 |
^ self |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5196 |
decimalPaddedTo:size |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5197 |
and:afterPeriod |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5198 |
at:decimalCharacter |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5199 |
withLeft:(Character space) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5200 |
right:$0 |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5201 |
|
8874 | 5202 |
" |
5203 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123 ' |
|
5204 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
|
5205 |
'123.' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
|
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5206 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.100' |
8874 | 5207 |
'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
|
5208 |
'123.123' decimalPaddedTo:10 and:3 at:$. -> ' 123.123' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5209 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5210 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5211 |
"Created: 23.12.1995 / 13:11:52 / cg" |
9192 | 5212 |
! |
5213 |
||
5214 |
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
|
5215 |
"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
|
5216 |
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
|
5217 |
of the period. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5218 |
Characters on the left are filled with leftPadChar. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5219 |
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
|
5220 |
otherwise, if missing, a decimal point is added and right characters filled with this. |
8874 | 5221 |
If the receivers size is equal or greater than the length argument, |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5222 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5223 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5224 |
|
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
5225 |
|s idx n rest| |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5226 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5227 |
idx := self indexOf:decimalCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5228 |
idx == 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5229 |
"/ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5230 |
"/ no decimal point found; adjust string to the left of the period column |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5231 |
"/ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5232 |
rightPadChar isNil ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5233 |
s := self , (self species new:afterPeriod + 1 withAll:leftPadChar) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5234 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5235 |
s:= self , decimalCharacter asString , (self species new:afterPeriod withAll:rightPadChar). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5236 |
]. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5237 |
] ifFalse:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5238 |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5239 |
"/ the number of after-decimalPoint characters |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5240 |
n := self size - idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5241 |
rest := afterPeriod - n. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5242 |
rest > 0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5243 |
s := (self species new:rest withAll:(rightPadChar ? leftPadChar)). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5244 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5245 |
s := '' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5246 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5247 |
s := self , s. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5248 |
]. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5249 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5250 |
^ s leftPaddedTo:size with:leftPadChar |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5251 |
|
8874 | 5252 |
" |
5253 |
'123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:nil -> ' 123 ' |
|
5254 |
'123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.000' |
|
5255 |
'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
|
5256 |
'123.1' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.100' |
8874 | 5257 |
'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
|
5258 |
'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
|
5259 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5260 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
5261 |
"Modified: 23.12.1995 / 13:08:18 / cg" |
9192 | 5262 |
! |
5263 |
||
5264 |
leftPaddedTo:size |
|
5265 |
"return a new string of length size, which contains the receiver |
|
5266 |
right-adjusted (i.e. padded on the left). |
|
5267 |
Characters on the left are filled with spaces. |
|
5268 |
If the receivers size is equal or greater than the length argument, |
|
5269 |
the original receiver is returned unchanged." |
|
5270 |
||
5271 |
^ self leftPaddedTo:size with:(Character space) |
|
5272 |
||
5273 |
" |
|
5274 |
'foo' leftPaddedTo:10 |
|
5275 |
'fooBar' leftPaddedTo:5 |
|
5276 |
123 printString leftPaddedTo:10 |
|
5277 |
" |
|
5278 |
! |
|
608 | 5279 |
|
5280 |
paddedTo:newSize |
|
5281 |
"return a new string consisting of the receivers characters, |
|
5282 |
plus spaces up to length. |
|
8874 | 5283 |
If the receivers size is equal or greater than the length argument, |
608 | 5284 |
the original receiver is returned unchanged." |
5285 |
||
5286 |
^ self paddedTo:newSize with:(Character space) |
|
5287 |
||
5288 |
" |
|
8874 | 5289 |
'foo' paddedTo:10 |
5290 |
123 printString paddedTo:10 |
|
15734 | 5291 |
'12345678901234' paddedTo:10 |
608 | 5292 |
" |
64 | 5293 |
! ! |
5294 |
||
9192 | 5295 |
!CharacterArray methodsFor:'printing & storing'! |
608 | 5296 |
|
5297 |
article |
|
17137 | 5298 |
"return an article string for the receiver. |
5299 |
The original code only looked at the first character being a vowel; |
|
5300 |
this has been enhanced by some heuristics - not perfect, still." |
|
608 | 5301 |
|
17241 | 5302 |
|firstChar secondChar thirdChar| |
608 | 5303 |
|
8874 | 5304 |
firstChar := (self at:1) asLowercase. |
5848 | 5305 |
((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
|
5306 |
^ 'an' |
608 | 5307 |
]. |
17043 | 5308 |
|
5309 |
(self size >= 3) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5310 |
secondChar := (self at:2) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5311 |
thirdChar := (self at:3) asLowercase. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5312 |
(firstChar isVowel not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5313 |
and:[(secondChar isVowel or:[secondChar == $y]) not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5314 |
and:[thirdChar isVowel not ]]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5315 |
"/ 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
|
5316 |
(self size > 4) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5317 |
(firstChar == $s) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5318 |
((secondChar == $c and:[thirdChar == $r]) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5319 |
or:[ (secondChar == $t and:[thirdChar == $r]) ]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5320 |
(self at:4) isVowel ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5321 |
^ 'a' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5322 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5323 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5324 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5325 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5326 |
"/ an abbreviation; treat x, s as vowels |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5327 |
(firstChar == $x or:[ firstChar == $s ]) ifTrue:[^ 'an']. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5328 |
] |
17043 | 5329 |
]. |
608 | 5330 |
^ 'a' |
5848 | 5331 |
|
5332 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5333 |
'uboot' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5334 |
'xmas' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5335 |
'alarm' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5336 |
'baby' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5337 |
'sql' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5338 |
'scr' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5339 |
'screen' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5340 |
'scrollbar' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5341 |
'scrs' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5342 |
'cvs' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5343 |
'cvssource' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5344 |
'symbol' article. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5345 |
'string' article. |
5848 | 5346 |
" |
608 | 5347 |
! |
5348 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5349 |
basicStoreString |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5350 |
"return a String for storing myself" |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5351 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5352 |
|s n index| |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5353 |
|
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5354 |
n := self occurrencesOf:$'. |
11320 | 5355 |
n ~~ 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5356 |
s := self species new:(n + 2 + self size). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5357 |
s at:1 put:$'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5358 |
index := 2. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5359 |
self do:[:thisChar | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5360 |
(thisChar == $') ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5361 |
s at:index put:thisChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5362 |
index := index + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5363 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5364 |
s at:index put:thisChar. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5365 |
index := index + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5366 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5367 |
s at:index put:$'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5368 |
^ s |
9192 | 5369 |
]. |
11320 | 5370 |
|
9192 | 5371 |
^ '''' , self , '''' |
15523 | 5372 |
|
5373 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5374 |
'''immutable'' string' asImmutableString basicStoreString |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5375 |
'immutable string' asImmutableString basicStoreString |
15523 | 5376 |
" |
5377 |
||
5378 |
"Modified: / 14-07-2013 / 19:20:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
9192 | 5379 |
! |
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
8040
diff
changeset
|
5380 |
|
11774
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5381 |
displayOn:aGCOrStream |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5382 |
"Compatibility |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5383 |
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
|
5384 |
OR: |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5385 |
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
|
5386 |
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
|
5387 |
(although the fallBack is to display its printString ...)" |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5388 |
|
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5389 |
"/ 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
|
5390 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
16738 | 5391 |
(aGCOrStream isStream) ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5392 |
self storeOn:aGCOrStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5393 |
^ self |
11774
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5394 |
]. |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5395 |
^ super displayOn:aGCOrStream |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5396 |
! |
6f6e2b71b607
displayOn (inspector's interface) was broken
Claus Gittinger <cg@exept.de>
parents:
11754
diff
changeset
|
5397 |
|
608 | 5398 |
printOn:aStream |
5399 |
"print the receiver on aStream" |
|
5400 |
||
5401 |
aStream nextPutAll:self |
|
5402 |
! |
|
5403 |
||
5404 |
printString |
|
13079
111e7e456648
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
13073
diff
changeset
|
5405 |
"return a string for printing - that's myself" |
608 | 5406 |
|
5407 |
^ self |
|
3578 | 5408 |
! |
5409 |
||
5410 |
printWithQuotesDoubledOn:aStream |
|
5411 |
"put the raw storeString of myself on aStream" |
|
5412 |
||
5413 |
self do:[:thisChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5414 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5415 |
aStream nextPut:thisChar |
3578 | 5416 |
] |
5417 |
||
5418 |
"Modified: / 15.6.1998 / 17:21:17 / cg" |
|
5419 |
"Created: / 15.6.1998 / 17:22:13 / cg" |
|
12171 | 5420 |
! |
5421 |
||
15788 | 5422 |
printXmlQuotedOn:aStream |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5423 |
"convert aString to a valid XML string |
15788 | 5424 |
that can be used for attributes, text, comments an PIs |
5425 |
TODO: care for 16bit UNICODE string and escape chars ..." |
|
5426 |
||
5427 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5428 |
eachChar == $< ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5429 |
aStream nextPutAll:'<' "mapping needed for xml text" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5430 |
] ifFalse:[ eachChar == $& ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5431 |
aStream nextPutAll:'&' "mapping needed for all" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5432 |
] ifFalse:[ eachChar == $> ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5433 |
aStream nextPutAll:'>' "mapping needed for comments" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5434 |
] ifFalse:[ eachChar == $' ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5435 |
aStream nextPutAll:''' "mapping needed for attributes" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5436 |
] ifFalse:[ eachChar == $" ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5437 |
aStream nextPutAll:'"' "mapping needed for attributes" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5438 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5439 |
|codePoint| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5440 |
codePoint := eachChar codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5441 |
(codePoint < 16r20 or:[codePoint >= 16r7F]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5442 |
aStream nextPutAll:'&#'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5443 |
codePoint printOn:aStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5444 |
aStream nextPut:$;. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5445 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5446 |
aStream nextPut:eachChar |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5447 |
]]]]]] |
15788 | 5448 |
]. |
5449 |
! |
|
5450 |
||
5451 |
printXmlTextQuotedOn:aStream |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5452 |
"convert aString to a valid XML string |
15788 | 5453 |
that can be used for XML text. |
5454 |
Here line formatting characters are not escaped. |
|
5455 |
TODO: care for 16bit UNICODE string and escape chars ..." |
|
5456 |
||
5457 |
self do:[:eachChar | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5458 |
eachChar == $< ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5459 |
aStream nextPutAll:'<' "mapping needed for xml text" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5460 |
] ifFalse:[ eachChar == $& ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5461 |
aStream nextPutAll:'&' "mapping needed for all" |
15788 | 5462 |
"/ ] ifFalse:[ eachChar == $> ifTrue:[ |
5463 |
"/ aStream nextPutAll:'>' "mapping needed for comments" |
|
5464 |
"/ ] ifFalse:[ eachChar == $' ifTrue:[ |
|
5465 |
"/ aStream nextPutAll:''' "mapping needed for attributes" |
|
5466 |
"/ ] ifFalse:[ eachChar == $" ifTrue:[ |
|
5467 |
"/ aStream nextPutAll:'"' "mapping needed for attributes" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5468 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5469 |
|codePoint| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5470 |
codePoint := eachChar codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5471 |
((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
|
5472 |
or:[codePoint >= 16r7F]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5473 |
aStream nextPutAll:'&#'. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5474 |
codePoint printOn:aStream. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5475 |
aStream nextPut:$;. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5476 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5477 |
aStream nextPut:eachChar |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5478 |
]]]"/]]] |
15788 | 5479 |
]. |
5480 |
! |
|
5481 |
||
12171 | 5482 |
printfWith:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
12177 | 5483 |
"Format and print the receiver with <argI> formatted in C style, |
12171 | 5484 |
as specified in the Unix C-language manual page for printf(3). |
15712 | 5485 |
Return the resulting string (i.e actually, this is more like an sprintf)." |
12177 | 5486 |
|
12171 | 5487 |
^ self printf:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
5488 |
||
5489 |
" |
|
12177 | 5490 |
Transcript showCR:('%d %05x %08o %b' printfWith:123 with:234 with:345 with:123) |
12171 | 5491 |
" |
15788 | 5492 |
! |
5493 |
||
5494 |
xmlQuotedPrintString |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5495 |
"convert aString to a valid XML string |
15788 | 5496 |
that can be used for attributes, text, comments an PIs |
5497 |
TODO: care for 16bit UNICODE string and escape chars ..." |
|
5498 |
||
5499 |
^ String streamContents:[:s| |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5500 |
self printXmlQuotedOn:s |
15788 | 5501 |
]. |
9192 | 5502 |
! ! |
5503 |
||
11955 | 5504 |
|
9192 | 5505 |
!CharacterArray methodsFor:'queries'! |
608 | 5506 |
|
4429 | 5507 |
bitsPerCharacter |
18662 | 5508 |
"return the underlying string's bitsPerCharacter |
4429 | 5509 |
(i.e. is it a regular String or a TwoByteString)" |
5510 |
||
8457 | 5511 |
|string max| |
5512 |
||
5513 |
(string := self string) ~~ self ifTrue:[ |
|
18662 | 5514 |
^ string bitsPerCharacter |
8457 | 5515 |
]. |
5516 |
||
5517 |
max := 8. |
|
5518 |
self do:[:eachCharacter | |
|
18662 | 5519 |
max := max max:(eachCharacter bitsPerCharacter) |
9192 | 5520 |
]. |
5521 |
^ max |
|
5522 |
||
5523 |
" |
|
5524 |
'hello' bitsPerCharacter |
|
5525 |
'hello' asText allBold bitsPerCharacter |
|
5526 |
" |
|
5527 |
! |
|
8457 | 5528 |
|
18967 | 5529 |
containsNon8BitElements |
5530 |
"return true, if the underlying string contains elements larger than a single byte" |
|
5531 |
||
5532 |
|sz "{ Class:SmallInteger }"| |
|
5533 |
||
5534 |
sz := self size. |
|
5535 |
1 to:sz do:[:idx| |
|
5536 |
(self at:idx) codePoint > 16rFF ifTrue:[ |
|
5537 |
^ true. |
|
5538 |
]. |
|
5539 |
]. |
|
5540 |
^ false. |
|
5541 |
! |
|
5542 |
||
10903 | 5543 |
continuesWith:aString startingAt:startIndex |
5544 |
"return true, if the receiver beginning at startIndex |
|
5545 |
contains the characters in aString." |
|
5546 |
||
5547 |
|sz "{Class: SmallInteger }" |
|
5548 |
idx "{Class: SmallInteger }"| |
|
5549 |
||
5550 |
sz := aString size. |
|
5551 |
idx := startIndex. |
|
5552 |
||
5553 |
1 to:sz do:[:i | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5554 |
(self at:idx) ~~ (aString at:i) ifTrue:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5555 |
idx := idx + 1 |
10903 | 5556 |
]. |
5557 |
^ true |
|
5558 |
||
5559 |
" |
|
5560 |
'hello world' continuesWith:'world' startingAt:6 |
|
5561 |
'hello world' continuesWith:'world' startingAt:7 |
|
5562 |
" |
|
5563 |
||
5564 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
5565 |
"Modified: 26.7.1996 / 19:08:36 / cg" |
|
5566 |
! |
|
5567 |
||
5568 |
countWords |
|
5569 |
"return the number of words, which are separated by separators" |
|
5570 |
||
5571 |
|tally "{ Class: SmallInteger }" |
|
5572 |
start "{ Class: SmallInteger }" |
|
5573 |
mySize "{ Class: SmallInteger }" |
|
5574 |
stop ch| |
|
5575 |
||
5576 |
tally := 0. |
|
5577 |
start := 1. |
|
5578 |
mySize := self size. |
|
5579 |
[start <= mySize] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5580 |
ch := self at:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5581 |
ch isSeparator ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5582 |
start := start + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5583 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5584 |
stop := self indexOfSeparatorStartingAt:start. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5585 |
(stop == 0) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5586 |
stop := mySize + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5587 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5588 |
tally := tally + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5589 |
start := stop |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5590 |
] |
10903 | 5591 |
]. |
5592 |
^ tally |
|
5593 |
||
5594 |
" |
|
5595 |
'hello world isnt this nice' countWords' |
|
5596 |
" |
|
5597 |
! |
|
5598 |
||
11788 | 5599 |
defaultElement |
5600 |
^ Character space |
|
5601 |
! |
|
5602 |
||
608 | 5603 |
encoding |
1311 | 5604 |
"return the strings encoding, as a symbol. |
7982 | 5605 |
Here, by default, we assume unicode-encoding. |
5606 |
Notice, that iso8859-1 is a true subset of unicode, |
|
8874 | 5607 |
and that singleByteStrings are therefore both unicode AND |
7982 | 5608 |
8859-1 encoded." |
5609 |
||
14168 | 5610 |
^ #unicode |
608 | 5611 |
! |
5612 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5613 |
hasChangeOfEmphasis |
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
5614 |
"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
|
5615 |
i.e. any non-normal (=emphasized) characters" |
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
5616 |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5617 |
^ false |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5618 |
|
1381 | 5619 |
"Created: 12.5.1996 / 12:31:39 / cg" |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5620 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5621 |
|
7995
8ddbb403d67b
+hasIcon and hasImage for LabelAndIcon compatibility
Claus Gittinger <cg@exept.de>
parents:
7991
diff
changeset
|
5622 |
hasIcon |
9191 | 5623 |
"for LabelAndIcon compatibility" |
5624 |
||
9192 | 5625 |
^ false |
5626 |
! |
|
5627 |
||
5628 |
hasImage |
|
5629 |
"for LabelAndIcon compatibility" |
|
5630 |
||
5631 |
^ false |
|
5632 |
! |
|
7995
8ddbb403d67b
+hasIcon and hasImage for LabelAndIcon compatibility
Claus Gittinger <cg@exept.de>
parents:
7991
diff
changeset
|
5633 |
|
1388 | 5634 |
heightOn:aGC |
5635 |
"return the size of the recevier in device units if displayed on aGC" |
|
5636 |
||
6528 | 5637 |
^ (aGC font onDevice:aGC device) heightOf:self |
1388 | 5638 |
|
5639 |
" |
|
8874 | 5640 |
'hello world' heightOn:(View new) |
1388 | 5641 |
" |
5642 |
||
5643 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
5644 |
"Modified: 12.5.1996 / 20:32:05 / cg" |
|
5645 |
! |
|
5646 |
||
15773 | 5647 |
isKeyword |
5648 |
"return true, if the receiver is a keyword message selector" |
|
5649 |
||
5650 |
^ self includes:$: |
|
5651 |
||
5652 |
" |
|
5653 |
#at:put: isKeyword |
|
5654 |
#at: isKeyword |
|
5655 |
#+ isKeyword |
|
5656 |
#size isKeyword |
|
5657 |
" |
|
5658 |
||
5659 |
"Created: / 1.11.1997 / 12:34:55 / cg" |
|
5660 |
"Modified: / 1.11.1997 / 12:36:37 / cg" |
|
5661 |
! |
|
5662 |
||
11828 | 5663 |
isLowercaseFirst |
5664 |
"return true, if the first character is a lowercase character." |
|
5665 |
||
5666 |
^ self size ~~ 0 and:[ self first isLowercase ] |
|
5667 |
||
5668 |
" |
|
12177 | 5669 |
'helloWorld' isLowercaseFirst |
5670 |
'HelloWorld' isLowercaseFirst |
|
11828 | 5671 |
" |
5672 |
! |
|
5673 |
||
5674 |
isUppercaseFirst |
|
5675 |
"return true, if the first character is an uppercase character." |
|
5676 |
||
5677 |
^ self size ~~ 0 and:[ self first isUppercase ] |
|
5678 |
||
5679 |
" |
|
12177 | 5680 |
'helloWorld' isUppercaseFirst |
5681 |
'HelloWorld' isUppercaseFirst |
|
11828 | 5682 |
" |
5683 |
! |
|
5684 |
||
15773 | 5685 |
keywords |
5686 |
"assuming the receiver is a keyword message selector, |
|
5687 |
return the individual keywords (i.e. break it up at colons) |
|
5688 |
and return these as a collection. |
|
5689 |
For binary and unary selectors, the result may be nonsense (an array containing the receiver)." |
|
5690 |
||
5691 |
|coll s part| |
|
5692 |
||
5693 |
coll := OrderedCollection new. |
|
5694 |
s := ReadStream on:self. |
|
5695 |
[s atEnd] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5696 |
part := s through:$:. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5697 |
coll add:part |
15773 | 5698 |
]. |
5699 |
^ coll asArray |
|
5700 |
||
5701 |
" |
|
5702 |
#at:put: keywords |
|
5703 |
#at: keywords |
|
5704 |
#+ keywords |
|
5705 |
#size keywords |
|
5706 |
" |
|
5707 |
||
5708 |
"Modified (Comment): / 30-06-2011 / 17:46:21 / cg" |
|
5709 |
! |
|
5710 |
||
9190 | 5711 |
knownAsSymbol |
5712 |
"for now, only single character strings are allowed as symbols. |
|
5713 |
This method is redefined in String." |
|
5714 |
||
5715 |
^ false |
|
5716 |
! |
|
5717 |
||
5718 |
leftIndent |
|
5719 |
"if the receiver starts with spaces, return the number of spaces |
|
5720 |
at the left - otherwise, return 0. |
|
9192 | 5721 |
If the receiver consists of spaces only, return the receivers size." |
5722 |
||
5723 |
|index "{Class: SmallInteger }" |
|
5724 |
end "{Class: SmallInteger }"| |
|
5725 |
||
5726 |
index := 1. |
|
5727 |
end := self size. |
|
5728 |
[index <= end] whileTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5729 |
(self at:index) isSeparator ifFalse:[^ index - 1]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5730 |
index := index + 1 |
8350 | 5731 |
]. |
9192 | 5732 |
^ end |
5733 |
||
5734 |
" |
|
5735 |
' hello' leftIndent |
|
5736 |
'foo ' leftIndent |
|
9190 | 5737 |
' ' leftIndent |
5738 |
" |
|
5739 |
||
5740 |
"Modified: 20.4.1996 / 19:28:43 / cg" |
|
8350 | 5741 |
! |
5742 |
||
10437 | 5743 |
nameSpaceSelectorParts |
5744 |
"Answer the namespace and baseSelector parts of a namespace selector. |
|
5745 |
Namespace selectors are those generated by sends from a method in a different |
|
5746 |
namespace; they are prefixed by ':'<ns>'::'. |
|
5747 |
You cannot easily change this algorithm here, as it is also known by the VM's lookup function. |
|
5748 |
Experimental" |
|
5749 |
||
5750 |
|nsPart selPart idx| |
|
5751 |
||
5752 |
(self at:1) == $: ifFalse:[^ Array with:'' with:self]. |
|
5753 |
idx := self indexOf:$: startingAt:3. |
|
5754 |
idx == 0 ifTrue:[^ Array with:'' with:self]. |
|
5755 |
||
5756 |
(idx+2 > self size) ifTrue:[^ Array with:'' with:self]. |
|
5757 |
(self at:idx+1) == $: ifFalse:[^ Array with:'' with:self]. |
|
5758 |
nsPart := self copyFrom:2 to:idx-1. |
|
5759 |
selPart := self copyFrom:idx+2. |
|
5760 |
^ Array with:nsPart with:selPart |
|
5761 |
||
5762 |
"test: |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5763 |
self assert:('+' nameSpaceSelectorParts) = #('' '+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5764 |
self assert:(':+' nameSpaceSelectorParts) = #('' ':+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5765 |
self assert:(':Foo:+' nameSpaceSelectorParts) = #('' ':Foo:+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5766 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5767 |
self assert:(':Foo::+' nameSpaceSelectorParts) = #('Foo' '+'). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
5768 |
self assert:(':Foo::bar:baz:' nameSpaceSelectorParts) = #('Foo' 'bar:baz:'). |
10437 | 5769 |
" |
5770 |
||
5771 |
"Created: / 05-03-2007 / 17:16:58 / cg" |
|
5772 |
"Modified: / 06-03-2007 / 11:51:15 / cg" |
|
5773 |
! |
|
5774 |
||
9190 | 5775 |
stringSpecies |
8874 | 5776 |
"return the underlying strings bitsPerCharacter |
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5777 |
(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
|
5778 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5779 |
|string| |
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5780 |
|
15523 | 5781 |
string := self string. |
5782 |
string == self ifTrue:[^ self species]. |
|
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5783 |
^ string stringSpecies |
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5784 |
|
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5785 |
" |
8874 | 5786 |
'hello' stringSpecies |
9192 | 5787 |
'hello' asText allBold stringSpecies |
5788 |
" |
|
5789 |
! |
|
8037
8cce25b1059c
care for wide chars in asXXXFirst
Claus Gittinger <cg@exept.de>
parents:
8032
diff
changeset
|
5790 |
|
6653 | 5791 |
widthFrom:startIndex to:endIndex on:aGC |
5792 |
"return ths size of part of the recevier in device units if displayed on aGC" |
|
5793 |
||
5794 |
^ (aGC font onDevice:aGC device) widthOf:self from:startIndex to:endIndex |
|
5795 |
||
5796 |
" |
|
8874 | 5797 |
'hello world' widthFrom:1 to:5 on:(View new) |
5798 |
'hello' widthOn:(View new) |
|
6653 | 5799 |
" |
9192 | 5800 |
! |
6653 | 5801 |
|
1388 | 5802 |
widthOn:aGC |
5803 |
"return ths size of the recevier in device units if displayed on aGC" |
|
5804 |
||
6528 | 5805 |
^ (aGC font onDevice:aGC device) widthOf:self |
1388 | 5806 |
|
5807 |
" |
|
8874 | 5808 |
'hello world' widthOn:(View new) |
1388 | 5809 |
" |
5810 |
||
5811 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
2554 | 5812 |
"Modified: 17.4.1997 / 12:50:23 / cg" |
608 | 5813 |
! ! |
5814 |
||
5815 |
!CharacterArray methodsFor:'special string converting'! |
|
5816 |
||
16759 | 5817 |
asUnixFilenameString |
5818 |
"return a new string consisting of receiver's characters |
|
5819 |
with all \-characters replaced by /-characters. |
|
5820 |
If there are no backslashes, return the original" |
|
5821 |
||
5822 |
^ self copyReplaceAll:$\ with:$/ ifNone:self |
|
5823 |
||
5824 |
" |
|
5825 |
'hello\world' asUnixFilenameString |
|
5826 |
" |
|
5827 |
||
5828 |
"Modified: / 18.7.1998 / 22:53:02 / cg" |
|
5829 |
! |
|
5830 |
||
14768 | 5831 |
expandPlaceholders:escapeCharacter with:argArrayOrDictionary |
5832 |
"this is the generic version of the old %-escaping method, allowing for an arbitrary |
|
5833 |
escape character to be used (typically $$ or $% are effectively used). |
|
5834 |
Return a copy of the receiver, where all %i escapes are |
|
5835 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
|
5836 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
|
5837 |
in the new string 'hello world; how is this'. |
|
5838 |
As an extension, the argument may also be a dictionary, providing |
|
5839 |
values for symbolic keys. |
|
5840 |
In this case, %a .. %z and %(...) are also allowed. |
|
5841 |
(%1..%9 require a numeric key in the dictionary, however) |
|
5842 |
To get a '%' character, use a '%%'-escape. |
|
5843 |
To get an integer-indexed placeHolder followed by another digit, |
|
5844 |
or an index > 9, you must use %(digit). |
|
5845 |
See also bindWith:... for VisualAge compatibility." |
|
5846 |
||
5847 |
|stream| |
|
5848 |
||
18269 | 5849 |
stream := (TextStream ? CharacterWriteStream) on:(self species uninitializedNew:self size + 20). |
14768 | 5850 |
self expandPlaceholders:escapeCharacter with:argArrayOrDictionary on:stream. |
5851 |
^ stream contents. |
|
5852 |
||
5853 |
||
5854 |
" |
|
5855 |
'hello %1' expandPlaceholdersWith:#('world') |
|
5856 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
5857 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
5858 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
|
5859 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) |
|
5860 |
'%%10 gives %10' expandPlaceholdersWith:#(123) |
|
5861 |
'%%(10) gives %(10)' expandPlaceholdersWith:#(123) |
|
5862 |
'%test gives %1' expandPlaceholdersWith:#(123) |
|
5863 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' allBold } |
|
5864 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' } |
|
5865 |
" |
|
5866 |
||
5867 |
" |
|
5868 |
|dict| |
|
5869 |
||
5870 |
dict := Dictionary new. |
|
5871 |
dict at:1 put:'one'. |
|
5872 |
dict at:$a put:'AAAAA'. |
|
5873 |
dict at:$b put:[ Time now ]. |
|
5874 |
dict at:'foo' put:[ Date today ]. |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5875 |
'hello $1 %a $b %(foo) $foo ' expandPlaceholders:$$ with:dict. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
5876 |
'hello $1 %a $b %(foo) $foo ' expandPlaceholders:$% with:dict. |
14768 | 5877 |
" |
5878 |
||
5879 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
|
5880 |
! |
|
5881 |
||
14765 | 5882 |
expandPlaceholders:escapeCharacter with:argArrayOrDictionary on:aStream |
5883 |
"this is the generic version of the old %-escaping method, allowing for an arbitrary |
|
5884 |
escape character to be used (typically $$ or $% are effectively used). |
|
18425 | 5885 |
|
14765 | 5886 |
Write the receiver to aStream, where all %i escapes are |
5887 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
|
5888 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
|
5889 |
in the new string 'hello world; how is this'. |
|
18425 | 5890 |
|
17192 | 5891 |
As an extension, the argument may also be a dictionary, providing values for symbolic keys. |
14765 | 5892 |
In this case, %a .. %z and %(...) are also allowed. |
5893 |
(%1..%9 require a numeric key in the dictionary, however) |
|
17192 | 5894 |
Also, the values in argArrayOrDictionary may be blocks. |
18425 | 5895 |
|
14765 | 5896 |
To get a '%' character, use a '%%'-escape. |
5897 |
To get an integer-indexed placeHolder followed by another digit, |
|
5898 |
or an index > 9, you must use %(digit). |
|
18425 | 5899 |
|
14765 | 5900 |
See also bindWith:... for VisualAge compatibility. |
5901 |
Use %<cr> to insert a CR and %<tab> to insert a TAB." |
|
5902 |
||
5903 |
|next v key |
|
5904 |
idx "{ SmallInteger }" |
|
5905 |
idx2 "{ SmallInteger }" |
|
5906 |
start "{ SmallInteger }" |
|
5907 |
stop "{ SmallInteger }"| |
|
5908 |
||
5909 |
stop := self size. |
|
5910 |
start := 1. |
|
5911 |
[start <= stop] whileTrue:[ |
|
18425 | 5912 |
idx := self indexOf:escapeCharacter startingAt:start. |
5913 |
(idx == 0 or:[idx == stop]) ifTrue:[ |
|
5914 |
aStream nextPutAll:self startingAt:start to:stop. |
|
5915 |
^ self. |
|
5916 |
]. |
|
5917 |
"found an escapeCharacter" |
|
5918 |
aStream nextPutAll:self startingAt:start to:(idx - 1). |
|
5919 |
next := self at:(idx + 1). |
|
5920 |
(next == escapeCharacter) ifTrue:[ |
|
5921 |
aStream nextPut:escapeCharacter. |
|
5922 |
] ifFalse:[ |
|
5923 |
next == $< ifTrue:[ |
|
5924 |
idx2 := self indexOf:$> startingAt:idx+2. |
|
5925 |
key := self copyFrom:idx+2 to:idx2-1. |
|
5926 |
idx := idx2 - 1. |
|
5927 |
key := key asSymbolIfInterned. |
|
5928 |
(#(cr tab nl return lf ff null) includesIdentical:key) ifTrue:[ |
|
5929 |
aStream nextPut:(Character perform:key). |
|
5930 |
]. |
|
5931 |
] ifFalse:[ |
|
5932 |
next isDigit ifTrue:[ |
|
5933 |
v := argArrayOrDictionary at:(next digitValue) ifAbsent:'' |
|
5934 |
] ifFalse:[ |
|
5935 |
next == $( ifTrue:[ |
|
5936 |
idx2 := self indexOf:$) startingAt:idx+2. |
|
5937 |
key := self copyFrom:idx+2 to:idx2-1. |
|
5938 |
idx := idx2 - 1. |
|
5939 |
(argArrayOrDictionary includesKey:key) ifTrue:[ |
|
5940 |
v := argArrayOrDictionary at:key |
|
5941 |
] ifFalse:[ |
|
5942 |
key := key asSymbolIfInterned ? key. |
|
5943 |
(argArrayOrDictionary includesKey:key) ifTrue:[ |
|
5944 |
v := argArrayOrDictionary at:key |
|
5945 |
] ifFalse:[ |
|
5946 |
(key size == 1 and:[ argArrayOrDictionary includesKey:(key at:1)]) ifTrue:[ |
|
5947 |
v := argArrayOrDictionary at:(key at:1) |
|
5948 |
] ifFalse:[ |
|
5949 |
key isNumeric ifTrue:[ |
|
5950 |
key := Integer readFrom:key onError:nil. |
|
5951 |
]. |
|
5952 |
v := argArrayOrDictionary at:key ifAbsent:'' |
|
5953 |
] |
|
5954 |
]. |
|
5955 |
]. |
|
5956 |
] ifFalse:[ |
|
5957 |
(next isLetter and:[argArrayOrDictionary isSequenceable not "is a Dictionary"]) ifTrue:[ |
|
5958 |
"so next is a non-numeric single character." |
|
5959 |
v := argArrayOrDictionary |
|
5960 |
at:next |
|
5961 |
ifAbsent:[ |
|
5962 |
"try symbol instead of character" |
|
5963 |
argArrayOrDictionary |
|
5964 |
at:next asSymbol |
|
5965 |
ifAbsent:[String with:escapeCharacter with:next]. |
|
5966 |
]. |
|
5967 |
] ifFalse:[ |
|
5968 |
v := String with:$% with:next. |
|
5969 |
]. |
|
5970 |
] |
|
5971 |
]. |
|
5972 |
"/ v notNil ifTrue:[ |
|
5973 |
v isBlock ifTrue:[ |
|
5974 |
v := v value |
|
5975 |
]. |
|
5976 |
||
5977 |
v printOn:aStream. |
|
5978 |
"/ ]. |
|
5979 |
] |
|
5980 |
]. |
|
5981 |
start := idx + 2 |
|
14765 | 5982 |
]. |
5983 |
||
5984 |
" |
|
5985 |
String streamContents:[:s| |
|
18425 | 5986 |
'hello %1' expandPlaceholders:$% with:#('world') on:s. |
5987 |
s cr. |
|
5988 |
'hello $1; how is $2' expandPlaceholders:$$ with:#('world' 'this') on:s. |
|
5989 |
s cr. |
|
5990 |
'hello %2; how is %1' expandPlaceholders:$% with:#('world' 'this') on:s. |
|
5991 |
s cr. |
|
5992 |
'%1 plus %2 gives %3 ' expandPlaceholders:$% with:#(4 5 9) on:s. |
|
5993 |
s cr. |
|
5994 |
'%%(1)0 gives %(1)0' expandPlaceholders:$% with:#(123) on:s. |
|
5995 |
s cr. |
|
5996 |
'%%10 gives %10' expandPlaceholders:$% with:#(123) on:s. |
|
5997 |
s cr. |
|
5998 |
'%%(10) gives %(10) %<cr>%<tab>next line' expandPlaceholders:$% with:#(123) on:s. |
|
5999 |
s cr. |
|
6000 |
'%%test gives %test' expandPlaceholders:$% with:#(123) on:s. |
|
6001 |
s cr. |
|
6002 |
'|%%<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
|
6003 |
] |
14765 | 6004 |
" |
6005 |
||
6006 |
" |
|
6007 |
|dict| |
|
6008 |
||
6009 |
dict := Dictionary new. |
|
6010 |
dict at:1 put:'one'. |
|
6011 |
dict at:$a put:'AAAAA'. |
|
6012 |
dict at:$b put:[ Time now ]. |
|
6013 |
String streamContents:[:s| |
|
18425 | 6014 |
'hello $1 $a $b' expandPlaceholders:$$ with:dict on:s. |
14765 | 6015 |
]. |
6016 |
" |
|
6017 |
||
18425 | 6018 |
"using blocks: |
6019 |
|dict| |
|
6020 |
||
6021 |
dict := Dictionary new. |
|
6022 |
dict at:'time' put:[Time now printString]. |
|
6023 |
dict at:'date' put:[Date today printString]. |
|
6024 |
String streamContents:[:s| |
|
6025 |
'it is $(time) $(date)' expandPlaceholders:$$ with:dict on:s. |
|
6026 |
]. |
|
6027 |
" |
|
6028 |
||
14765 | 6029 |
"Modified: / 18-11-2010 / 15:43:28 / cg" |
6030 |
! |
|
6031 |
||
9192 | 6032 |
expandPlaceholdersWith:argArrayOrDictionary |
608 | 6033 |
"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
|
6034 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
608 | 6035 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
6036 |
in the new string 'hello world; how is this'. |
|
18425 | 6037 |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6038 |
As an extension, the argument may also be a dictionary, providing |
7313 | 6039 |
values for symbolic keys. |
4842 | 6040 |
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
|
6041 |
(%1..%9 require a numeric key in the dictionary, however) |
18425 | 6042 |
Also, the values in argArrayOrDictionary may be blocks. |
6043 |
||
608 | 6044 |
To get a '%' character, use a '%%'-escape. |
7313 | 6045 |
To get an integer-indexed placeHolder followed by another digit, |
6046 |
or an index > 9, you must use %(digit). |
|
608 | 6047 |
See also bindWith:... for VisualAge compatibility." |
6048 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6049 |
|stream| |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6050 |
|
18269 | 6051 |
stream := (TextStream ? CharacterWriteStream) on:(self species uninitializedNew:self size + 20). |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6052 |
self expandPlaceholdersWith:argArrayOrDictionary on:stream. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6053 |
^ stream contents. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6054 |
|
608 | 6055 |
|
6056 |
" |
|
8874 | 6057 |
'hello %1' expandPlaceholdersWith:#('world') |
6058 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
6059 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
6060 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
|
6061 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) |
|
6062 |
'%%10 gives %10' expandPlaceholdersWith:#(123) |
|
6063 |
'%%(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
|
6064 |
'%test gives %1' expandPlaceholdersWith:#(123) |
11028
cb1ee3ddd91a
expandPlaceHolders: care fr Text with emphasis
Claus Gittinger <cg@exept.de>
parents:
11018
diff
changeset
|
6065 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' allBold } |
cb1ee3ddd91a
expandPlaceHolders: care fr Text with emphasis
Claus Gittinger <cg@exept.de>
parents:
11018
diff
changeset
|
6066 |
'bla %1 bla' expandPlaceholdersWith:{ 'hello' } |
608 | 6067 |
" |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
6068 |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6069 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6070 |
|dict| |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6071 |
|
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6072 |
dict := Dictionary new. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6073 |
dict at:1 put:'one'. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6074 |
dict at:$a put:'AAAAA'. |
8794
a5df33935142
nindWith supports blocks in the value dictionary
Claus Gittinger <cg@exept.de>
parents:
8710
diff
changeset
|
6075 |
dict at:$b put:[ Time now ]. |
12316
3e78905d70a9
comment/format in: #expandPlaceholdersWith:
Claus Gittinger <cg@exept.de>
parents:
12196
diff
changeset
|
6076 |
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
|
6077 |
'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
|
6078 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
6079 |
|
2737
9f29aecea39d
care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents:
2736
diff
changeset
|
6080 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
9192 | 6081 |
! |
6082 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6083 |
expandPlaceholdersWith:argArrayOrDictionary on:aStream |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6084 |
"write the receiver to aStream, where all %i escapes are |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6085 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6086 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6087 |
in the new string 'hello world; how is this'. |
18425 | 6088 |
|
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6089 |
As an extension, the argument may also be a dictionary, providing |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6090 |
values for symbolic keys. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6091 |
In this case, %a .. %z and %(...) are also allowed. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6092 |
(%1..%9 require a numeric key in the dictionary, however) |
18425 | 6093 |
Also, the values in argArrayOrDictionary may be blocks. |
6094 |
||
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6095 |
To get a '%' character, use a '%%'-escape. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6096 |
To get an integer-indexed placeHolder followed by another digit, |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6097 |
or an index > 9, you must use %(digit). |
18425 | 6098 |
|
10935 | 6099 |
See also bindWith:... for VisualAge compatibility. |
10939
d0ca31c1d1e9
#expandPlaceHoldersWith: handle %<cr> %<tab> etc
Stefan Vogel <sv@exept.de>
parents:
10935
diff
changeset
|
6100 |
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
|
6101 |
|
14765 | 6102 |
^ self expandPlaceholders:$% with:argArrayOrDictionary on:aStream |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6103 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6104 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6105 |
String streamContents:[:s| |
18425 | 6106 |
'hello %1' expandPlaceholdersWith:#('world') on:s. |
6107 |
s cr. |
|
6108 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') on:s. |
|
6109 |
s cr. |
|
6110 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') on:s. |
|
6111 |
s cr. |
|
6112 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) on:s. |
|
6113 |
s cr. |
|
6114 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) on:s. |
|
6115 |
s cr. |
|
6116 |
'%%10 gives %10' expandPlaceholdersWith:#(123) on:s. |
|
6117 |
s cr. |
|
6118 |
'%%(10) gives %(10) %<cr>%<tab>next line' expandPlaceholdersWith:#(123) on:s. |
|
6119 |
s cr. |
|
6120 |
'%test gives %1' expandPlaceholdersWith:#(123) on:s. |
|
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6121 |
] |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6122 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6123 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6124 |
" |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6125 |
|dict| |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6126 |
|
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6127 |
dict := Dictionary new. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6128 |
dict at:1 put:'one'. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6129 |
dict at:$a put:'AAAAA'. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6130 |
dict at:$b put:[ Time now ]. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6131 |
String streamContents:[:s| |
18425 | 6132 |
'hello %1 %a %b' expandPlaceholdersWith:dict on:s. |
10906
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6133 |
]. |
6468fe197af0
CharacterArray>>#expandMacrosWith:on:
Stefan Vogel <sv@exept.de>
parents:
10903
diff
changeset
|
6134 |
" |
13008
a27647c36b31
changed: #expandPlaceholdersWith:on:
Claus Gittinger <cg@exept.de>
parents:
12925
diff
changeset
|
6135 |
|
13138
d2eb0eba5907
changed: #expandPlaceholdersWith:on:
Claus Gittinger <cg@exept.de>
parents:
13137
diff
changeset
|
6136 |
"Modified: / 18-11-2010 / 15:43:28 / cg" |
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 |
|
9230 | 6139 |
firstLine |
14405
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6140 |
"return the first line of a multiline string" |
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6141 |
|
1d0d99a95bba
comment/format in:7 methods
Claus Gittinger <cg@exept.de>
parents:
14168
diff
changeset
|
6142 |
^ self asCollectionOfSubCollectionsSeparatedBy:(Character cr) do:[:line | ^ line]. |
9230 | 6143 |
|
6144 |
" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6145 |
'hello' firstLine |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6146 |
'1\2\3' withCRs firstLine |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
6147 |
'\1\2\3' withCRs firstLine |
9230 | 6148 |
" |
6149 |
! |
|
6150 |
||
13987 | 6151 |
tokensBasedOn:aCharacter |
6152 |
"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
|
6153 |
asCollectionOfSubstringsSeparatedBy:" |
13987 | 6154 |
|
6155 |
^ self asCollectionOfSubstringsSeparatedBy:aCharacter |
|
6156 |
||
6157 |
" |
|
6158 |
'hello:world:isnt:this nice' tokensBasedOn:$: |
|
6159 |
'foo,bar,baz' tokensBasedOn:$, |
|
6160 |
'/etc/passwd' asFilename readStream nextLine tokensBasedOn:$: |
|
6161 |
" |
|
6162 |
! |
|
6163 |
||
6164 |
withCEscapes |
|
16863 | 6165 |
"return a new string consisting of receiver's characters |
13987 | 6166 |
with all special and unprintable characters replaced by \X-character escapes. |
6167 |
(similar to the way C-language literal Strings are represented). |
|
6168 |
The resulting string will contain only 7-bit ascii characters. |
|
6169 |
Emphasis is not supported. |
|
6170 |
The following escapes are generated: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6171 |
\' single quote character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6172 |
\dQuote double quote character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6173 |
\r return character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6174 |
\r return character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6175 |
\n newline character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6176 |
\t tab character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6177 |
\\ the \ character itself |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6178 |
\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
|
6179 |
\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
|
6180 |
\Unnnnnnnn eight digit hex number defining the characters ascii value |
16863 | 6181 |
This is the opposite of withoutCEscapes. |
17000 | 6182 |
|
6183 |
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
|
6184 |
but it cannot be changed easily, as these methods are already used heavily |
13987 | 6185 |
" |
6186 |
||
6187 |
|anyEscapeNeeded out seq| |
|
6188 |
||
6189 |
" |
|
6190 |
first, check if any escape is needed and return the receiver unchanged if not |
|
6191 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6192 |
anyEscapeNeeded := self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6193 |
contains:[:ch | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6194 |
((ch codePoint between:32 and:126) not |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6195 |
or:[ch == $' or:[ch == $"]]) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6196 |
]. |
13987 | 6197 |
anyEscapeNeeded ifFalse:[ ^ self ]. |
6198 |
||
6199 |
self hasChangeOfEmphasis ifTrue:[ self error:'emphasis not supported' ]. |
|
6200 |
||
18269 | 6201 |
out := WriteStream on:(String uninitializedNew:self size-1). |
13987 | 6202 |
|
6203 |
self do:[:ch | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6204 |
|cp| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6205 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6206 |
(ch == $' or:[ch == $"]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6207 |
out nextPut:$\. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6208 |
out nextPut:ch. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6209 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6210 |
(ch codePoint between:32 and:126) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6211 |
out nextPut:ch |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6212 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6213 |
ch == Character return ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6214 |
seq := '\r' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6215 |
] ifFalse:[ ch == Character nl ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6216 |
seq := '\n' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6217 |
] ifFalse:[ ch == Character tab ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6218 |
seq := '\t' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6219 |
] ifFalse:[ ch == $\ ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6220 |
seq := '\\' |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6221 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6222 |
cp := ch codePoint. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6223 |
cp <= 16rFF ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6224 |
seq := '\x' , (cp printStringRadix:16 padTo:2) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6225 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6226 |
cp <= 16rFFFF ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6227 |
seq := '\u' , (cp printStringRadix:16 padTo:4) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6228 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6229 |
seq := '\U',(cp printStringRadix:16 padTo:8) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6230 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6231 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6232 |
]]]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6233 |
out nextPutAll:seq |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6234 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6235 |
]. |
13987 | 6236 |
]. |
6237 |
^ out contents |
|
6238 |
||
6239 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6240 |
'hello\n\tworld' withoutCEscapes. |
17000 | 6241 |
'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
|
6242 |
('hello ',(Character value:16r1234),' world') withCEscapes |
13987 | 6243 |
" |
6244 |
||
6245 |
"Created: / 25-01-2012 / 11:08:16 / cg" |
|
6246 |
! |
|
6247 |
||
9192 | 6248 |
withCRs |
17205 | 6249 |
"return a new string consisting of the receiver's characters |
16757 | 6250 |
with all \-characters replaced by cr-characters. |
6251 |
If there are no backslashes, return the original" |
|
6252 |
||
16759 | 6253 |
^ self copyReplaceAll:$\ with:(Character cr) ifNone:self |
9192 | 6254 |
|
6255 |
" |
|
6256 |
'hello\world' withCRs |
|
6257 |
" |
|
6258 |
||
6259 |
"Modified: / 18.7.1998 / 22:53:02 / cg" |
|
6260 |
! |
|
6261 |
||
6262 |
withEscapes |
|
15405 | 6263 |
<resource: #obsolete> |
13987 | 6264 |
"has been renamed; the name withEscapes is misleading" |
6265 |
||
6266 |
self obsoleteMethodWarning:'use withoutCEscapes'. |
|
6267 |
^ self withoutCEscapes. |
|
6268 |
||
6269 |
"Modified: / 25-01-2012 / 10:42:30 / cg" |
|
9192 | 6270 |
! |
6271 |
||
6272 |
withMatchEscapes |
|
4117 | 6273 |
"return a copy of the receiver with all match characters escaped |
6274 |
by $\ characters (to be usable as a match string). |
|
6275 |
Return the receiver, if there are none." |
|
6276 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6277 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6278 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6279 |
escape := self class matchEscapeCharacter. |
4117 | 6280 |
|
6281 |
in := self readStream. |
|
7986 | 6282 |
out := WriteStream on:(self species new:self size). |
4117 | 6283 |
[in atEnd] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6284 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6285 |
(c == escape or:['*[#' includes:c]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6286 |
out nextPut:$\. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6287 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6288 |
out nextPut:c. |
4117 | 6289 |
]. |
6290 |
^ out contents. |
|
6291 |
||
6292 |
" |
|
8874 | 6293 |
'*foo' withMatchEscapes |
6294 |
'\*foo' withMatchEscapes |
|
6295 |
'*foo' withMatchEscapes |
|
6296 |
'\\*foo' withMatchEscapes |
|
6297 |
'foo*' withMatchEscapes |
|
6298 |
'foo\*' withMatchEscapes |
|
6299 |
'foo\' withMatchEscapes |
|
6300 |
'f*o*o' withMatchEscapes |
|
4117 | 6301 |
" |
6302 |
||
6303 |
"Modified: 2.4.1997 / 18:13:04 / cg" |
|
9192 | 6304 |
! |
6305 |
||
14992 | 6306 |
withSeparatorsCompacted |
6307 |
"return a new string with each sequence of whiteSpace replaced by a single space character. |
|
6308 |
Preserves a leading/trailing space." |
|
6309 |
||
6310 |
^ self species streamContents:[:s | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6311 |
|skipping| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6312 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6313 |
skipping := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6314 |
1 to:self size do:[:idx | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6315 |
|char| |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6316 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6317 |
char := self at:idx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6318 |
char isSeparator ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6319 |
s nextPut:char. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6320 |
skipping := false. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6321 |
] ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6322 |
skipping ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6323 |
s nextPut:(Character space). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6324 |
skipping := true |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6325 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6326 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6327 |
] |
14992 | 6328 |
] |
6329 |
||
6330 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6331 |
'hello wwww' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6332 |
'hello wwww' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6333 |
' hello wwww' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6334 |
' hello wwww ' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6335 |
' hello wwww ' withSeparatorsCompacted |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6336 |
'hel lo www w' withSeparatorsCompacted |
14992 | 6337 |
" |
6338 |
! |
|
6339 |
||
18464 | 6340 |
withSeparatorsReplacedBy:replacementCharacter |
6341 |
"return a new string with each separator (whitespace) replaced by replacementCharacter. |
|
6342 |
Typically used with space as replacementCharacter" |
|
6343 |
||
6344 |
^ self species streamContents:[:s | |
|
6345 |
self do:[:ch | |
|
6346 |
ch isSeparator ifTrue:[ |
|
6347 |
s nextPut:replacementCharacter |
|
6348 |
] ifFalse:[ |
|
6349 |
s nextPut:ch. |
|
6350 |
] |
|
6351 |
] |
|
6352 |
] |
|
6353 |
||
6354 |
" |
|
6355 |
'hello wwww' withSeparatorsReplacedBy:$* |
|
6356 |
'hello ww ww' withSeparatorsReplacedBy:$* |
|
6357 |
' hello wwww' withSeparatorsReplacedBy:$* |
|
6358 |
'hel lo www w' withSeparatorsReplacedBy:$* |
|
6359 |
'hel |
|
6360 |
lo www |
|
6361 |
w' withSeparatorsReplacedBy:$* |
|
6362 |
" |
|
6363 |
! |
|
6364 |
||
9192 | 6365 |
withTabs |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6366 |
"return a string consisting of the receivers characters |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6367 |
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
|
6368 |
Notice: if the receiver does not contain any tabs, it is returned unchanged; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6369 |
otherwise a new string is returned. |
8874 | 6370 |
Limitation: only the very first spaces are replaced |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6371 |
(i.e. if the receiver contains newLine characters, |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6372 |
no tabs are inserted after those lineBreaks)" |
8874 | 6373 |
|
6374 |
|idx "{ SmallInteger }" |
|
6375 |
nTabs "{ SmallInteger }" |
|
608 | 6376 |
newString| |
6377 |
||
6378 |
idx := self findFirst:[:c | (c ~~ Character space)]. |
|
6379 |
nTabs := (idx-1) // 8. |
|
5815
4acdd87a77d4
// can return negative numbers.
Stefan Vogel <sv@exept.de>
parents:
5795
diff
changeset
|
6380 |
nTabs <= 0 ifTrue:[^ self]. |
608 | 6381 |
|
6382 |
"any tabs" |
|
15523 | 6383 |
newString := self species new:(self size - (nTabs * 7)). |
608 | 6384 |
newString atAll:(1 to:nTabs) put:(Character tab). |
6385 |
newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1). |
|
6386 |
^ newString |
|
6387 |
||
6388 |
" |
|
8874 | 6389 |
'12345678901234567890' withTabs |
6390 |
' 8901234567890' withTabs |
|
6391 |
' 901234567890' withTabs |
|
608 | 6392 |
' 67890' withTabs |
6393 |
' 7890' withTabs |
|
6394 |
' 890' withTabs |
|
6395 |
" |
|
9192 | 6396 |
! |
6397 |
||
6398 |
withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6399 |
"return a string consisting of the receivers characters, |
8874 | 6400 |
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
|
6401 |
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
|
6402 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6403 |
This does handle multiline strings." |
608 | 6404 |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6405 |
^ self withTabsExpanded:8 |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6406 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6407 |
" |
8874 | 6408 |
('1' , Character tab asString , 'x') withTabsExpanded |
6409 |
('12345' , Character tab asString , 'x') withTabsExpanded |
|
6410 |
('123456' , Character tab asString , 'x') withTabsExpanded |
|
6411 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
|
6412 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
|
6413 |
('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
|
6414 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6415 |
(String with:Character tab |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6416 |
with:Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6417 |
with:$1) withTabsExpanded |
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6418 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6419 |
(String with:Character tab |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6420 |
with:$1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6421 |
with:Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6422 |
with:$2) withTabsExpanded |
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6423 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6424 |
(String with:Character tab |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6425 |
with:$1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6426 |
with:Character cr |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6427 |
with:Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6428 |
with:$2) withTabsExpanded |
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6429 |
" |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6430 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6431 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
9192 | 6432 |
! |
6433 |
||
6434 |
withTabsExpanded:numSpaces |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
6435 |
"return a string consisting of the receivers characters, |
8874 | 6436 |
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
|
6437 |
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
|
6438 |
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
|
6439 |
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
|
6440 |
|
8874 | 6441 |
|col "{ SmallInteger }" |
1381 | 6442 |
str ch |
6443 |
dstIdx "{ SmallInteger }" |
|
6444 |
newSz "{ SmallInteger }" |
|
6445 |
sz "{ SmallInteger }" |
|
6446 |
hasEmphasis e| |
|
608 | 6447 |
|
6448 |
(self includes:(Character tab)) ifFalse:[^ self]. |
|
1381 | 6449 |
|
6450 |
sz := self size. |
|
6451 |
||
6452 |
"/ count the new size first, instead of |
|
6453 |
"/ multiple resizing (better for large strings) |
|
6454 |
||
6455 |
col := 1. newSz := 0. |
|
6456 |
1 to:sz do:[:srcIdx | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6457 |
ch := self at:srcIdx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6458 |
ch == Character tab ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6459 |
col := col + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6460 |
newSz := newSz + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6461 |
ch == Character cr ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6462 |
col := 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6463 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6464 |
] ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6465 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6466 |
newSz := newSz + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6467 |
col := col + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6468 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6469 |
] |
608 | 6470 |
]. |
1381 | 6471 |
|
6472 |
str := self species new:newSz. |
|
6473 |
||
6474 |
hasEmphasis := self hasChangeOfEmphasis. |
|
6475 |
||
6476 |
col := 1. dstIdx := 1. |
|
6477 |
1 to:sz do:[:srcIdx | |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6478 |
ch := self at:srcIdx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6479 |
|
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6480 |
ch == Character tab ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6481 |
col := col + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6482 |
ch == Character cr ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6483 |
col := 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6484 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6485 |
hasEmphasis ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6486 |
e := self emphasisAt:srcIdx. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6487 |
str emphasisAt:dstIdx put:e |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6488 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6489 |
str at:dstIdx put:ch. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6490 |
dstIdx := dstIdx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6491 |
] ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6492 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6493 |
str at:dstIdx put:Character space. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6494 |
dstIdx := dstIdx + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6495 |
col := col + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6496 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6497 |
] |
1381 | 6498 |
]. |
6499 |
^ str |
|
608 | 6500 |
|
6501 |
" |
|
8874 | 6502 |
('1' , Character tab asString , 'x') withTabsExpanded |
6503 |
('1' , Character tab asString , 'x') withTabsExpanded:4 |
|
6504 |
('12345' , Character tab asString , 'x') withTabsExpanded |
|
6505 |
('123456' , Character tab asString , 'x') withTabsExpanded |
|
6506 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
|
6507 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
|
6508 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6509 |
|
608 | 6510 |
(String with:Character tab |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6511 |
with:Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6512 |
with:$1) withTabsExpanded |
608 | 6513 |
|
6514 |
(String with:Character tab |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6515 |
with:$1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6516 |
with:Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6517 |
with:$2) withTabsExpanded |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6518 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6519 |
(String with:Character tab |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6520 |
with:$1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6521 |
with:Character cr |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6522 |
with:Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6523 |
with:$2) withTabsExpanded |
608 | 6524 |
" |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
6525 |
|
1381 | 6526 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
9192 | 6527 |
! |
6528 |
||
13987 | 6529 |
withoutAllSpaces |
16855 | 6530 |
"return a copy of the receiver with all whitespace removed" |
6531 |
||
13987 | 6532 |
^ self asCollectionOfWords asStringWith:''. |
6533 |
"/ |col string| |
|
6534 |
"/ |
|
6535 |
"/ col := self asCollectionOfWords. |
|
6536 |
"/ string := String new. |
|
6537 |
"/ col do:[:el | |
|
6538 |
"/ string := string,el |
|
6539 |
"/ ]. |
|
6540 |
"/ ^string |
|
6541 |
||
6542 |
" |
|
6543 |
'hello wwww' withoutAllSpaces |
|
6544 |
'hel lo www w' withoutAllSpaces |
|
6545 |
" |
|
6546 |
||
6547 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
6548 |
! |
|
6549 |
||
6550 |
withoutCEscapes |
|
15628 | 6551 |
"return a new string consisting of receiver's characters |
13987 | 6552 |
with all \X-character escapes replaced by corresponding-characters. |
6553 |
(similar to the way C-language Strings are converted). |
|
6554 |
The following escapes are supported: |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6555 |
\r return character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6556 |
\n newline character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6557 |
\b backspace character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6558 |
\f formfeed character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6559 |
\t tab character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6560 |
\e escape character |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6561 |
\\ the \ character itself |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6562 |
\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
|
6563 |
\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
|
6564 |
\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
|
6565 |
\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
|
6566 |
\other other |
13987 | 6567 |
|
6568 |
Notice, that \' is NOT a valid escape, since the general syntax of |
|
6569 |
string constants is not affected by this method. |
|
6570 |
||
6571 |
Although easily implementable, this is NOT done automatically |
|
6572 |
by the compiler (due to a lack of a language standard for this). |
|
6573 |
However, the compiler may detect sends ot #withEscapes to string literals |
|
6574 |
and place a modified string constant into the binary/byte-code. |
|
6575 |
Therefore, no runtime penalty will be payed for using these escapes. |
|
6576 |
(not in pre 2.11 versions) |
|
16863 | 6577 |
|
6578 |
This is the opposite of withCEscapes. |
|
17000 | 6579 |
|
6580 |
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
|
6581 |
but it cannot be changed easily, as these methods are already used heavily |
13987 | 6582 |
" |
6583 |
||
6584 |
|val "{ SmallInteger }" |
|
6585 |
in out nextChar nDigits| |
|
6586 |
||
6587 |
" |
|
6588 |
first, see if there is any escape; if not, return the receiver unchanged |
|
6589 |
" |
|
6590 |
(self includes:$\) ifFalse:[^ self ]. |
|
6591 |
||
6592 |
self hasChangeOfEmphasis ifTrue:[ self error:'emphasis not supported' ]. |
|
6593 |
out := CharacterWriteStream on:(String new:self size - 1). |
|
6594 |
||
6595 |
in := ReadStream on:self. |
|
6596 |
[in atEnd] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6597 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6598 |
nextChar == $\ ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6599 |
in atEnd ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6600 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6601 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6602 |
nextChar == $r ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6603 |
nextChar := Character return |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6604 |
] ifFalse:[ nextChar == $n ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6605 |
nextChar := Character nl |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6606 |
] ifFalse:[ nextChar == $b ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6607 |
nextChar := Character backspace |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6608 |
] ifFalse:[ nextChar == $f ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6609 |
nextChar := Character newPage |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6610 |
] ifFalse:[ nextChar == $t ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6611 |
nextChar := Character tab |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6612 |
] ifFalse:[ nextChar == $e ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6613 |
nextChar := Character esc |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6614 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6615 |
nextChar == $0 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6616 |
val := 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6617 |
nextChar := in peek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6618 |
nDigits := 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6619 |
[nextChar notNil and:[nextChar isDigit and:[nDigits <= 3]]] whileTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6620 |
val := (val * 8) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6621 |
nextChar := in nextPeek. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6622 |
nDigits := nDigits + 1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6623 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6624 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6625 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6626 |
val := 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6627 |
nextChar == $x ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6628 |
2 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6629 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6630 |
val := (val * 16) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6631 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6632 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6633 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6634 |
nextChar == $u ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6635 |
4 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6636 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6637 |
val := (val * 16) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6638 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6639 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6640 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6641 |
nextChar == $U ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6642 |
8 timesRepeat:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6643 |
nextChar := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6644 |
val := (val * 16) + nextChar digitValue. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6645 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6646 |
nextChar := Character value:val. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6647 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6648 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6649 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6650 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6651 |
]]]]]]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6652 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6653 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6654 |
out nextPut:nextChar. |
13987 | 6655 |
]. |
6656 |
^ out contents |
|
6657 |
||
6658 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6659 |
'hello world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6660 |
'hello\world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6661 |
'hello\world\' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6662 |
'hello world\' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6663 |
'hello\tworld' withoutCEscapes |
13987 | 6664 |
'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
|
6665 |
'hello\tworld\n' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6666 |
'hello\010world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6667 |
'hello\r\nworld' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6668 |
'hello\r\n\x08world' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6669 |
'0\x080' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6670 |
'0\u12340' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6671 |
'0\U123456780' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6672 |
'0\0a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6673 |
'0\00a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6674 |
'0\000a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6675 |
'0\0000a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6676 |
'0\00000a' withoutCEscapes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6677 |
'0\03770' withoutCEscapes |
13987 | 6678 |
" |
6679 |
||
6680 |
"Created: / 25-01-2012 / 10:41:44 / cg" |
|
6681 |
! |
|
6682 |
||
9192 | 6683 |
withoutCRs |
6684 |
"return a new collection consisting of receivers elements |
|
6685 |
with all cr-characters replaced by \-characters. |
|
6686 |
This is the reverse operation of withCRs." |
|
6687 |
||
16759 | 6688 |
^ self copyReplaceAll:(Character cr) with:$\ ifNone:self |
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
6689 |
|
9192 | 6690 |
" |
6691 |
'hello |
|
6692 |
world' withoutCRs |
|
6693 |
" |
|
6694 |
||
6695 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
6696 |
! |
|
6697 |
||
6698 |
withoutLeadingSeparators |
|
608 | 6699 |
"return a copy of myself without leading separators. |
6700 |
Notice: this does remove tabs, newline or any other whitespace. |
|
6701 |
Returns an empty string, if the receiver consist only of whitespace." |
|
6702 |
||
6703 |
|index| |
|
6704 |
||
6705 |
index := self indexOfNonSeparatorStartingAt:1. |
|
6706 |
index ~~ 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6707 |
index == 1 ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6708 |
^ self |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6709 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6710 |
^ self copyFrom:index |
608 | 6711 |
]. |
6712 |
^ '' |
|
6713 |
||
6714 |
" |
|
8874 | 6715 |
' foo ' withoutLeadingSeparators |
6716 |
'foo ' withoutLeadingSeparators |
|
6717 |
' foo' withoutLeadingSeparators |
|
6718 |
' ' withoutLeadingSeparators |
|
6719 |
'foo' withoutLeadingSeparators |
|
6720 |
(' ' , Character tab asString , ' foo ') withoutLeadingSeparators inspect |
|
608 | 6721 |
" |
9192 | 6722 |
! |
6723 |
||
6724 |
withoutMatchEscapes |
|
4117 | 6725 |
"return a copy of the receiver with all $\ removed or |
6726 |
the receiver, if there are none." |
|
6727 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6728 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6729 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
6730 |
escape := self class matchEscapeCharacter. |
4117 | 6731 |
|
6732 |
in := self readStream. |
|
8222
f2c454a9a038
replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents:
8124
diff
changeset
|
6733 |
out := self species writeStream. |
4117 | 6734 |
[in atEnd] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6735 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6736 |
c == escape ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6737 |
in atEnd ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6738 |
c := in next. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6739 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6740 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6741 |
out nextPut:c. |
4117 | 6742 |
]. |
6743 |
^ out contents. |
|
6744 |
||
6745 |
" |
|
8874 | 6746 |
'*foo' withoutMatchEscapes |
6747 |
'\*foo' withoutMatchEscapes |
|
6748 |
'*foo' withoutMatchEscapes |
|
6749 |
'\\*foo' withoutMatchEscapes |
|
6750 |
'foo*' withoutMatchEscapes |
|
6751 |
'foo\*' withoutMatchEscapes |
|
6752 |
'foo\' withoutMatchEscapes |
|
6753 |
'f\*o\*o' withoutMatchEscapes |
|
4117 | 6754 |
" |
6755 |
||
6756 |
"Modified: 30.6.1997 / 13:40:23 / cg" |
|
9192 | 6757 |
! |
6758 |
||
6759 |
withoutPrefix:aString |
|
6760 |
"if the receiver startsWith aPrefix, return a copy without it. |
|
6761 |
Otherwise return the receiver" |
|
6762 |
||
6763 |
(self startsWith:aString) ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6764 |
^ self copyFrom:aString size + 1 |
9192 | 6765 |
]. |
6766 |
^ self |
|
6767 |
||
6768 |
" |
|
6769 |
'helloworld' withoutPrefix:'hello' |
|
6770 |
'helloworld' withoutPrefix:'foo' |
|
6771 |
" |
|
6772 |
! |
|
6773 |
||
10671 | 6774 |
withoutQuotes |
17000 | 6775 |
"/ remove quotes ($" and $') from the front and end of myself (if matching)" |
6776 |
||
6777 |
|firstChar| |
|
6778 |
||
17024 | 6779 |
self isEmpty ifTrue:[^ self]. |
6780 |
||
17000 | 6781 |
firstChar := self first. |
6782 |
((firstChar == $") or:[firstChar == $']) ifFalse:[^ self]. |
|
6783 |
||
6784 |
self last == firstChar ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6785 |
^ self copyFrom:2 to:(self size-1) |
10671 | 6786 |
]. |
17000 | 6787 |
^ self |
6788 |
||
6789 |
"/ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6790 |
"/ '"hello"' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6791 |
"/ '''hello''' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6792 |
"/ 'hello' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6793 |
"/ '"hello' withoutQuotes |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
6794 |
"/ 'hello"' withoutQuotes |
17000 | 6795 |
"/ |
10671 | 6796 |
! |
6797 |
||
9192 | 6798 |
withoutSeparators |
608 | 6799 |
"return a copy of myself without leading and trailing whitespace. |
4156 | 6800 |
(but whiteSpace in-between is preserved) |
608 | 6801 |
Whitespace is space, tab, newline, formfeed. |
6802 |
Use withoutSpaces, if you want to remove spaces only." |
|
6803 |
||
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
6804 |
^ self trimForWhich:[:ch | ch isSeparator] |
608 | 6805 |
|
6806 |
" |
|
8874 | 6807 |
' foo ' withoutSeparators |
6808 |
' foo' withoutSeparators |
|
6809 |
'foo ' withoutSeparators |
|
6810 |
' ' withoutSeparators |
|
6811 |
(' foo' , Character tab asString , ' ') withoutSeparators inspect |
|
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
6812 |
' foo ' asUnicode16String withoutSeparators |
608 | 6813 |
" |
9192 | 6814 |
! |
6815 |
||
6816 |
withoutSpaces |
|
608 | 6817 |
"return a copy of myself without leading and trailing spaces. |
4156 | 6818 |
(but spaces in-between are preserved) |
608 | 6819 |
Notice: this does NOT remove tabs, newline or any other whitespace. |
6820 |
Use withoutSeparators for this." |
|
6821 |
||
12319
18b80c2ce1e3
oops #withoutSeparators #withoutSpaces were noops
Claus Gittinger <cg@exept.de>
parents:
12317
diff
changeset
|
6822 |
^ self trimForWhich:[:ch | ch == Character space] |
608 | 6823 |
|
6824 |
" |
|
8874 | 6825 |
' foo ' withoutSpaces |
6826 |
'foo ' withoutSpaces |
|
6827 |
' foo' withoutSpaces |
|
6828 |
' ' withoutSpaces |
|
6829 |
'a b' withoutSpaces |
|
6830 |
(' foo' , Character tab asString , ' ') withoutSpaces inspect |
|
608 | 6831 |
" |
9192 | 6832 |
! |
6833 |
||
6834 |
withoutTrailingSeparators |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6835 |
"return a copy of myself without trailing separators. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6836 |
Notice: this does remove tabs, newline or any other whitespace. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6837 |
Returns an empty string, if the receiver consist only of whitespace." |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6838 |
|
12188 | 6839 |
^ self withoutTrailingForWhich:[:ch | ch isSeparator] |
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6840 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6841 |
" |
8874 | 6842 |
' foo ' withoutTrailingSeparators |
6843 |
'foo ' withoutTrailingSeparators |
|
6844 |
' foo' withoutTrailingSeparators |
|
6845 |
' ' withoutTrailingSeparators |
|
6846 |
'foo' withoutTrailingSeparators |
|
6847 |
(' ' , Character tab asString , ' foo ') withoutTrailingSeparators inspect |
|
6848 |
(' foo' , Character tab asString) withoutTrailingSeparators inspect |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6849 |
" |
9192 | 6850 |
! ! |
6851 |
||
6852 |
!CharacterArray methodsFor:'substring searching'! |
|
6853 |
||
15055 | 6854 |
findRangeOfString:subString |
6855 |
"find a substring. if found, return the start- and endIndex; |
|
6856 |
if not found, return an empty interval." |
|
6857 |
||
6858 |
^ self rangeOfSubCollection:subString startingAt:1 ifAbsent:[0 to:-1] caseSensitive:true |
|
6859 |
||
6860 |
" |
|
6861 |
'hello world' findRangeOfString:'llo' |
|
6862 |
'hello world' findRangeOfString:'ole' |
|
6863 |
" |
|
6864 |
! |
|
6865 |
||
9192 | 6866 |
findString:subString |
6867 |
"find a substring. if found, return the index; |
|
6868 |
if not found, return 0." |
|
6869 |
||
6870 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:true |
|
6871 |
||
6872 |
" |
|
6873 |
'hello world' findString:'llo' |
|
6874 |
'hello world' findString:'ole' |
|
6875 |
" |
|
6876 |
! |
|
608 | 6877 |
|
15734 | 6878 |
findString:subString caseSensitive:caseSensitive |
6879 |
"find a substring. if found, return the index; |
|
6880 |
if not found, return 0." |
|
6881 |
||
6882 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:caseSensitive |
|
6883 |
||
6884 |
" |
|
6885 |
'hello world' findString:'LLo' caseSensitive:true |
|
6886 |
'hello world' findString:'LLo' caseSensitive:false |
|
6887 |
" |
|
6888 |
! |
|
6889 |
||
608 | 6890 |
findString:subString ifAbsent:exceptionBlock |
6891 |
"find a substring. If found, return the index; |
|
6892 |
if not found, return the result of evaluating exceptionBlock." |
|
6893 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6894 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock caseSensitive:true |
608 | 6895 |
! |
6896 |
||
11018 | 6897 |
findString:subString ignoreCase:ignoreCase |
15734 | 6898 |
<resource: #obsolete> |
11018 | 6899 |
"find a substring. if found, return the index; |
6900 |
if not found, return 0." |
|
6901 |
||
6902 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 caseSensitive:ignoreCase not |
|
6903 |
||
6904 |
" |
|
6905 |
'hello world' findString:'LLo' ignoreCase:false |
|
6906 |
'hello world' findString:'LLo' ignoreCase:true |
|
6907 |
" |
|
6908 |
! |
|
6909 |
||
608 | 6910 |
findString:subString startingAt:index |
6911 |
"find a substring, starting at index. if found, return the index; |
|
6912 |
if not found, return 0." |
|
6913 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6914 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:0 caseSensitive:true |
608 | 6915 |
|
6916 |
" |
|
9192 | 6917 |
'hello yello' findString:'llo' startingAt:1 |
6918 |
'hello yello' findString:'llo' startingAt:5 |
|
6919 |
'hello yello' findString:'llo' startingAt:15 |
|
6920 |
" |
|
6921 |
! |
|
608 | 6922 |
|
6923 |
findString:subString startingAt:index ifAbsent:exceptionBlock |
|
6924 |
"find a substring, starting at index. if found, return the index; |
|
6925 |
if not found, return the result of evaluating exceptionBlock." |
|
6926 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6927 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:true |
608 | 6928 |
! |
6929 |
||
12177 | 6930 |
findString:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
10929 | 6931 |
"find a substring, starting at index. if found, return the index; |
6932 |
if not found, return the result of evaluating exceptionBlock." |
|
6933 |
||
6934 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
|
6935 |
! |
|
6936 |
||
608 | 6937 |
includesString:aString |
6938 |
"return true, if a substring is contained in the receiver" |
|
6939 |
||
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6940 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0 caseSensitive:true) ~~ 0 |
608 | 6941 |
|
6942 |
" |
|
12177 | 6943 |
'hello world' includesString:'hel' |
8874 | 6944 |
'hello world' includesString:'rld' |
9192 | 6945 |
'hello world' includesString:'llo' |
6946 |
'hello world' includesString:'LLO' |
|
12177 | 6947 |
'hello world' includesString:'' |
9192 | 6948 |
" |
6949 |
! |
|
9191 | 6950 |
|
6951 |
includesString:aString caseSensitive:caseSensitive |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6952 |
"return true, if a substring is contained in the receiver" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6953 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6954 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0 caseSensitive:caseSensitive) ~~ 0 |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6955 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6956 |
" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6957 |
'hello world' includesString:'hel' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6958 |
'hello world' includesString:'HEL' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6959 |
'hello world' includesString:'HEL' caseSensitive:false |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6960 |
|
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6961 |
'hello world' includesString:'wor' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6962 |
'hello world' includesString:'WOR' caseSensitive:true |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6963 |
'hello world' includesString:'WOR' caseSensitive:false |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
6964 |
" |
9192 | 6965 |
! |
6966 |
||
17486 | 6967 |
indexOfString: aString |
6968 |
"VSE and V'age compatibility" |
|
6969 |
"find a substring. If found, return the index; if not found, return 0." |
|
6970 |
||
18939 | 6971 |
^ self indexOfSubCollection: aString startingAt:1 ifAbsent:[0] |
6972 |
! |
|
6973 |
||
6974 |
indexOfString:aString ifAbsent:exceptionValue |
|
6975 |
"VSE and V'age compatibility" |
|
6976 |
"find a substring. If found, return the index; if not found, return 0." |
|
6977 |
||
6978 |
^ self indexOfSubCollection: aString startingAt:1 ifAbsent:exceptionValue |
|
6979 |
||
6980 |
" |
|
6981 |
'abcdefabcdef' indexOfString:'fab' ifAbsent:[999] |
|
6982 |
'abcdefabcdef' indexOfString:'xxx' ifAbsent:[999] |
|
6983 |
" |
|
17486 | 6984 |
! |
6985 |
||
18721 | 6986 |
indexOfString:aString startingAt:startIndex |
6987 |
"VSE and V'age compatibility" |
|
6988 |
"find a substring. If found, return the index; if not found, return 0." |
|
6989 |
||
6990 |
^ self indexOfSubCollection:aString startingAt:startIndex ifAbsent:[0] |
|
6991 |
! |
|
6992 |
||
6993 |
indexOfString:aString startingAt:startIndex ifAbsent:exceptionalValue |
|
6994 |
"VSE and V'age compatibility" |
|
6995 |
"find a substring. |
|
6996 |
If found, return the index; if not found, the value from exceptionalValue." |
|
6997 |
||
6998 |
^ self indexOfSubCollection:aString startingAt:startIndex ifAbsent:exceptionalValue |
|
6999 |
! |
|
7000 |
||
18671 | 7001 |
indexOfSubCollection:subString caseSensitive:caseSensitive |
7002 |
"find a substring, starting at index. if found, return the index; |
|
7003 |
if not found, return the result of evaluating exceptionBlock. |
|
7004 |
This is a q&d hack - not very efficient" |
|
7005 |
||
7006 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:[0] caseSensitive:caseSensitive. |
|
7007 |
! |
|
7008 |
||
9192 | 7009 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
7010 |
"find a substring, starting at index. if found, return the index; |
|
7011 |
if not found, return the result of evaluating exceptionBlock. |
|
7012 |
This is a q&d hack - not very efficient" |
|
7013 |
||
7014 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:true. |
|
7015 |
! |
|
7016 |
||
7017 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7018 |
"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
|
7019 |
if not found, return the result of evaluating exceptionBlock. |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7020 |
This is a q&d hack - not very efficient" |
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7021 |
|
608 | 7022 |
|firstChar found |
7023 |
startIndex "{ Class: SmallInteger }" |
|
7024 |
subSize "{ Class: SmallInteger }" |
|
7025 |
mySize "{ Class: SmallInteger }" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7026 |
runIdx "{ Class: SmallInteger }" |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7027 |
tester| |
608 | 7028 |
|
7029 |
subSize := subString size. |
|
12177 | 7030 |
subSize == 0 ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7031 |
subString isString ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7032 |
self error:'non string argument' mayProceed:true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7033 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7034 |
"empty string does not match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7035 |
^ 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7036 |
"empty string matches" |
15433 | 7037 |
"/ ^ index |
6122
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
7038 |
]. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7039 |
|
608 | 7040 |
mySize := self size. |
7041 |
firstChar := subString at:1. |
|
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7042 |
caseSensitive ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7043 |
tester := [:c1 :c2 | c1 = c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7044 |
startIndex := self indexOf:firstChar startingAt:index. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7045 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7046 |
tester := [:c1 :c2 | c1 sameAs: c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7047 |
startIndex := self findFirst:[:c | c sameAs:firstChar] startingAt:index. |
9087
9e28a6168468
case-insensitive search cleanup
Claus Gittinger <cg@exept.de>
parents:
9058
diff
changeset
|
7048 |
]. |
608 | 7049 |
[startIndex == 0] whileFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7050 |
runIdx := startIndex. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7051 |
found := true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7052 |
1 to:subSize do:[:i | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7053 |
runIdx > mySize ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7054 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7055 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7056 |
(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
|
7057 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7058 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7059 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7060 |
runIdx := runIdx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7061 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7062 |
found ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7063 |
^ startIndex |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7064 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7065 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7066 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1) |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7067 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7068 |
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
|
7069 |
]. |
608 | 7070 |
]. |
7071 |
^ exceptionBlock value |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7072 |
|
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7073 |
"Modified: 23.2.1996 / 15:35:15 / cg" |
9192 | 7074 |
! |
7075 |
||
17191 | 7076 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock caseSensitive:caseSensitive ignoreDiacritics:ignoreDiacritics |
7077 |
"find a substring, starting at index. if found, return the index; |
|
7078 |
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
|
7079 |
This is a q&d hack - not very efficient |
17191 | 7080 |
(see implementation in string, for a much faster algorithm)" |
7081 |
||
7082 |
|firstChar found |
|
7083 |
startIndex "{ Class: SmallInteger }" |
|
7084 |
subSize "{ Class: SmallInteger }" |
|
7085 |
mySize "{ Class: SmallInteger }" |
|
7086 |
runIdx "{ Class: SmallInteger }" |
|
7087 |
tester charMap firstCharMapped findNextIndex| |
|
7088 |
||
7089 |
subSize := subString size. |
|
7090 |
subSize == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7091 |
subString isString ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7092 |
self error:'non string argument' mayProceed:true. |
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 |
"empty string does not match" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7095 |
^ 0. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7096 |
"empty string matches" |
17191 | 7097 |
"/ ^ index |
7098 |
]. |
|
7099 |
||
7100 |
mySize := self size. |
|
7101 |
firstChar := subString at:1. |
|
7102 |
ignoreDiacritics ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7103 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7104 |
charMap := [:ch | ch asLowercase withoutDiacritics]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7105 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7106 |
charMap := [:ch | ch withoutDiacritics]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7107 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7108 |
tester := [:c1 :c2 | (charMap value:c1) = (charMap value:c2) ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7109 |
firstCharMapped := (charMap value:firstChar). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7110 |
findNextIndex := [:index | self findFirst:[:ch | (charMap value:ch) = firstCharMapped] startingAt:index]. |
17191 | 7111 |
] ifFalse:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7112 |
caseSensitive ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7113 |
tester := [:c1 :c2 | c1 = c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7114 |
findNextIndex := [:index | self indexOf:firstChar startingAt:index]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7115 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7116 |
tester := [:c1 :c2 | c1 sameAs: c2 ]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7117 |
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
|
7118 |
]. |
17191 | 7119 |
]. |
7120 |
startIndex := findNextIndex value:index. |
|
7121 |
[startIndex == 0] whileFalse:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7122 |
runIdx := startIndex. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7123 |
found := true. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7124 |
1 to:subSize do:[:i | |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7125 |
runIdx > mySize ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7126 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7127 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7128 |
(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
|
7129 |
found := false |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7130 |
] |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7131 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7132 |
runIdx := runIdx + 1 |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7133 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7134 |
found ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7135 |
^ startIndex |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7136 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7137 |
startIndex := findNextIndex value:(startIndex + 1) |
17191 | 7138 |
]. |
7139 |
^ exceptionBlock value |
|
7140 |
||
7141 |
" |
|
17600 | 7142 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:1 ifAbsent:0 caseSensitive:false ignoreDiacritics:true. 5 |
7143 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:6 ifAbsent:0 caseSensitive:false ignoreDiacritics:true. 0 |
|
7144 |
||
7145 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:1 ifAbsent:0 caseSensitive:false ignoreDiacritics:false. 5 |
|
7146 |
'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:6 ifAbsent:0 caseSensitive:false ignoreDiacritics:false. 0 |
|
17191 | 7147 |
" |
7148 |
! |
|
7149 |
||
18939 | 7150 |
lastIndexOfString:aString |
7151 |
"VSE and V'age compatibility" |
|
7152 |
"find the last occurrence of substring. |
|
7153 |
If found, return the index; if not found, return 0." |
|
7154 |
||
7155 |
^ self lastIndexOfSubCollection:aString startingAt:(self size-aString size+1) ifAbsent:[0] |
|
7156 |
||
7157 |
" 123456789012 |
|
7158 |
'abcdefabcdef' lastIndexOfString:'abc' |
|
7159 |
'abcdefabcdef' lastIndexOfString:'abc' startingAt:6 |
|
7160 |
'abcdefabcdef' lastIndexOfString:'xxx' startingAt:6 |
|
7161 |
" |
|
7162 |
! |
|
7163 |
||
7164 |
lastIndexOfString:aString ifAbsent:exceptionValue |
|
7165 |
"VSE and V'age compatibility" |
|
7166 |
"find the last occurrence of substring. |
|
7167 |
If found, return the index; if not found, return 0." |
|
7168 |
||
7169 |
^ self lastIndexOfSubCollection:aString startingAt:(self size-aString size+1) ifAbsent:exceptionValue |
|
7170 |
||
7171 |
" 123456789012 |
|
7172 |
'abcdefabcdef' lastIndexOfString:'abc' ifAbsent:[999] |
|
7173 |
'abcdefabcdef' lastIndexOfString:'xxx' ifAbsent:[999] |
|
7174 |
" |
|
7175 |
! |
|
7176 |
||
7177 |
lastIndexOfString:aString startingAt:startIndex |
|
7178 |
"VSE and V'age compatibility" |
|
7179 |
"find the last occurrence of a substring. |
|
7180 |
If found, return the index; if not found, return 0." |
|
7181 |
||
7182 |
^ self lastIndexOfSubCollection:aString startingAt:startIndex ifAbsent:[0] |
|
7183 |
||
7184 |
" 123456789012 |
|
7185 |
'abcdefabcdef' lastIndexOfString:'abc' |
|
7186 |
'abcdefabcdef' lastIndexOfString:'abc' startingAt:6 |
|
7187 |
" |
|
7188 |
! |
|
7189 |
||
7190 |
lastIndexOfString:aString startingAt:startIndex ifAbsent:exceptionValue |
|
7191 |
"VSE and V'age compatibility" |
|
7192 |
"find the last occurrence of a substring. |
|
7193 |
If found, return the index; if not found, return 0." |
|
7194 |
||
7195 |
^ self lastIndexOfSubCollection:aString startingAt:startIndex ifAbsent:exceptionValue |
|
7196 |
||
7197 |
" 123456789012 |
|
7198 |
'abcdefabcdef' lastIndexOfString:'abc' |
|
7199 |
'abcdefabcdef' lastIndexOfString:'abc' startingAt:6 |
|
7200 |
'abcdefabcdef' lastIndexOfString:'xxx' startingAt:6 ifAbsent:999 |
|
7201 |
" |
|
7202 |
! |
|
7203 |
||
15055 | 7204 |
rangeOfSubCollection:subString startingAt:start ifAbsent:exceptionValue caseSensitive:caseSensitive |
7205 |
"find a substring. if found, return the start- and endIndex; |
|
7206 |
if not found, return the value of exceptionValue." |
|
7207 |
||
7208 |
|i| |
|
7209 |
||
7210 |
i := self indexOfSubCollection:subString startingAt:start ifAbsent:0 caseSensitive:caseSensitive. |
|
7211 |
i == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7212 |
^ exceptionValue value |
15055 | 7213 |
]. |
7214 |
^ i to:(i + subString size - 1) |
|
7215 |
||
7216 |
" |
|
7217 |
'hello world' findRangeOfString:'llo' |
|
7218 |
'hello world' findRangeOfString:'ole' |
|
7219 |
" |
|
9192 | 7220 |
! ! |
7221 |
||
7222 |
!CharacterArray methodsFor:'testing'! |
|
7223 |
||
18463 | 7224 |
argumentCount |
7225 |
"treating the receiver as a message selector, return how many arguments would it take (ANSI)" |
|
7226 |
||
7227 |
|binopChars| |
|
7228 |
||
7229 |
(self size <= Method maxBinarySelectorSize) ifTrue:[ |
|
7230 |
binopChars := Method binarySelectorCharacters. |
|
7231 |
(self conform:[:eachChar | (binopChars includes:eachChar)]) ifTrue:[ |
|
7232 |
^ 1 |
|
7233 |
]. |
|
7234 |
]. |
|
7235 |
^ self occurrencesOf:$: |
|
7236 |
||
7237 |
" |
|
7238 |
'foo:bar:' argumentCount |
|
7239 |
#foo:bar: argumentCount |
|
7240 |
'hello' argumentCount |
|
7241 |
'+' argumentCount |
|
7242 |
'++' argumentCount |
|
7243 |
'+++' argumentCount |
|
7244 |
'|' argumentCount |
|
7245 |
'?' argumentCount |
|
7246 |
'_' argumentCount |
|
7247 |
'_:' argumentCount |
|
7248 |
'_:_:' argumentCount |
|
7249 |
'<->' argumentCount |
|
7250 |
" |
|
7251 |
! |
|
7252 |
||
18597 | 7253 |
characterSize |
7254 |
"answer the size in bits of my largest character (actually only 7, 8, 16 or 32)" |
|
7255 |
||
7256 |
|string max |
|
7257 |
sz "{ Class:SmallInteger}" | |
|
15829 | 7258 |
|
7259 |
(string := self string) ~~ self ifTrue:[ |
|
18597 | 7260 |
^ string characterSize. |
7261 |
]. |
|
7262 |
||
7263 |
sz := self size. |
|
7264 |
max := 7. |
|
7265 |
1 to:sz do:[:idx | |
|
7266 |
|thisSize| |
|
7267 |
||
7268 |
thisSize := (self at:idx) characterSize. |
|
7269 |
thisSize > max ifTrue:[ |
|
7270 |
max := thisSize. |
|
7271 |
max == 32 ifTrue:[ |
|
7272 |
"shortcut: we know, that max size is 32" |
|
7273 |
^ 32. |
|
7274 |
]. |
|
7275 |
]. |
|
15829 | 7276 |
]. |
18597 | 7277 |
|
7278 |
^ max. |
|
7279 |
||
7280 |
" |
|
7281 |
'hello' characterSize |
|
7282 |
'hello' asUnicode32String characterSize |
|
7283 |
'helloü' asUnicode32String characterSize |
|
7284 |
'hello' asText allBold characterSize |
|
7285 |
" |
|
7286 |
! |
|
7287 |
||
7288 |
contains8BitCharacters |
|
7289 |
<resource: #obsolete> |
|
7290 |
||
7291 |
^ self containsNon7BitAscii |
|
7292 |
! |
|
7293 |
||
7294 |
containsNon7BitAscii |
|
7295 |
"return true, if the underlying string contains 8BitCharacters (or widers) |
|
7296 |
(i.e. if it is non-ascii)" |
|
7297 |
||
7298 |
|string |
|
7299 |
sz "{ Class:SmallInteger }"| |
|
7300 |
||
7301 |
(string := self string) ~~ self ifTrue:[ |
|
7302 |
^ string containsNon7BitAscii |
|
7303 |
]. |
|
7304 |
sz := self size. |
|
7305 |
1 to:sz do:[:idx| |
|
7306 |
(self at:idx) codePoint > 16r7F ifTrue:[ |
|
7307 |
^ true. |
|
7308 |
]. |
|
7309 |
]. |
|
7310 |
^ false. |
|
7311 |
||
7312 |
" |
|
7313 |
'hello' asUnicode32String containsNon7BitAscii |
|
7314 |
'hello üöä' asUnicode32String containsNon7BitAscii |
|
7315 |
'hello' asUnicode32String asText allBold containsNon7BitAscii |
|
7316 |
'hello üö' asUnicode32String asText allBold containsNon7BitAscii |
|
15829 | 7317 |
" |
7318 |
! |
|
7319 |
||
9192 | 7320 |
isAlphaNumeric |
7321 |
"return true, if the receiver is some alphanumeric word; |
|
7322 |
i.e. consists of a letter followed by letters or digits." |
|
7323 |
||
7324 |
self size == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7325 |
"mhmh what is this ?" |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7326 |
^ false |
9192 | 7327 |
]. |
7328 |
(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
|
7329 |
^ self conform:[:char | char isLetterOrDigit]. |
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7330 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7331 |
" |
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7332 |
'helloWorld' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7333 |
'foo1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7334 |
'f1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7335 |
'1234' isAlphaNumeric |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7336 |
'+' isAlphaNumeric |
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7337 |
" |
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7338 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7339 |
"Modified: / 13-10-2006 / 12:53:49 / cg" |
9192 | 7340 |
! |
9190 | 7341 |
|
7342 |
isBinarySelector |
|
10903 | 7343 |
"treating the receiver as a message selector, return true if its a binary selector. |
7344 |
Notice, that st/x does not have a size <= 2 limit for unaries" |
|
9190 | 7345 |
|
7346 |
|binopChars| |
|
7347 |
||
18463 | 7348 |
(self size > Method maxBinarySelectorSize) ifTrue:[^ false]. |
7349 |
||
7350 |
binopChars := Method binarySelectorCharacters. |
|
9190 | 7351 |
^ (self conform:[:char | (binopChars includes:char)]) |
7352 |
||
7353 |
" |
|
7354 |
'foo:bar:' isBinarySelector |
|
7355 |
#foo:bar: isBinarySelector |
|
7356 |
'hello' isBinarySelector |
|
7357 |
'+' isBinarySelector |
|
7358 |
'|' isBinarySelector |
|
8874 | 7359 |
'?' isBinarySelector |
7360 |
':' isBinarySelector |
|
7361 |
'a:' isBinarySelector |
|
7362 |
'->' isBinarySelector |
|
7363 |
'<->' isBinarySelector |
|
7364 |
'::' isBinarySelector |
|
7482 | 7365 |
" |
7366 |
||
7367 |
"Modified: 4.1.1997 / 14:16:14 / cg" |
|
9192 | 7368 |
! |
7369 |
||
7370 |
isBlank |
|
7371 |
"return true, if the receiver contains spaces only" |
|
7372 |
||
9230 | 7373 |
^ (self contains:[:char | char ~~ Character space]) not |
7374 |
||
7375 |
" |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7376 |
'' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7377 |
' a ' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7378 |
' ' isBlank |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7379 |
' ' asUnicode16String isBlank |
9230 | 7380 |
" |
9192 | 7381 |
! |
7382 |
||
10903 | 7383 |
isKeywordSelector |
7384 |
"return true, iff there are only alphanumeric or underline characters separated by colons. |
|
7385 |
Must end with a colon." |
|
7386 |
||
7387 |
|state| |
|
7388 |
||
12177 | 7389 |
state := #initial. |
10903 | 7390 |
self do:[:char | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7391 |
(state == #initial or:[ state == #gotColon]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7392 |
(char isLetterOrUnderline) ifFalse:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7393 |
state := #gotCharacter. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7394 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7395 |
char == $: ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7396 |
state := #gotColon. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7397 |
] ifFalse:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7398 |
(char isLetterOrDigit or:[char == $_]) ifFalse:[^ false]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7399 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7400 |
]. |
10903 | 7401 |
]. |
7402 |
^ state == #gotColon. |
|
7403 |
||
7404 |
" |
|
12177 | 7405 |
self assert:(':' isKeywordSelector not). |
10903 | 7406 |
self assert:(':a' isKeywordSelector not). |
7407 |
self assert:('1:' isKeywordSelector not). |
|
7408 |
self assert:('a:' isKeywordSelector). |
|
7409 |
self assert:('_:' isKeywordSelector). |
|
7410 |
self assert:('_a:' isKeywordSelector). |
|
7411 |
self assert:('_1:' isKeywordSelector). |
|
7412 |
self assert:('_1::' isKeywordSelector not). |
|
7413 |
self assert:('_:_:' isKeywordSelector). |
|
7414 |
self assert:('a:b:' isKeywordSelector). |
|
7415 |
self assert:('aa:bb:' isKeywordSelector). |
|
7416 |
self assert:('aa:bb:a' isKeywordSelector not). |
|
7417 |
self assert:('1:2:' isKeywordSelector not). |
|
7418 |
" |
|
7419 |
! |
|
7420 |
||
10431 | 7421 |
isNameSpaceSelector |
7422 |
"Answer true if the receiver contains chars which form a nameSpace selector name. |
|
7423 |
These are of the form ':<ns>::<sel>', where ns is the NameSpace and sel is the regular selector. |
|
7424 |
For example, the #+ selector as seen by the Foo namespace would be actually #':Foo::+'. |
|
17511 | 7425 |
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
|
7426 |
is legal, and this can be checked quickly by just looking at the first character. |
10431 | 7427 |
You cannot easily change this algorithm here, as it is also known by the VM's lookup function." |
7428 |
||
7429 |
|i| |
|
7430 |
||
16733 | 7431 |
(self at:1) == $: ifFalse:[^ false]. |
17511 | 7432 |
|
10431 | 7433 |
i := self indexOf:$: startingAt:2. |
7434 |
i == 0 ifTrue:[^ false]. |
|
7435 |
self size <= (i+1) ifTrue:[^ false]. |
|
7436 |
(self at:i+1) == $: ifFalse:[^ false]. |
|
7437 |
(self at:i+2) == $: ifTrue:[^ false]. |
|
7438 |
"/ could check if the rest after the ns-prefix and colons is a valid selector... |
|
7439 |
^ true |
|
7440 |
||
7441 |
"test: |
|
10703
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7442 |
self assert:('+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7443 |
self assert:(':+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7444 |
self assert:(':Foo:+' isNameSpaceSelector) not. |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7445 |
|
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7446 |
self assert:(':Foo::+' isNameSpaceSelector). |
d1e981878c9c
Work around stx bug when compiling hash
Stefan Vogel <sv@exept.de>
parents:
10698
diff
changeset
|
7447 |
self assert:(':Foo::bar:baz:' isNameSpaceSelector). |
10431 | 7448 |
" |
7449 |
||
7450 |
"Created: / 05-03-2007 / 11:35:31 / cg" |
|
7451 |
! |
|
7452 |
||
9192 | 7453 |
isNumeric |
7454 |
"return true, if the receiver is some numeric word; |
|
7455 |
i.e. consists only of digits." |
|
7456 |
||
7457 |
self size == 0 ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7458 |
^ false |
9192 | 7459 |
]. |
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7460 |
^ self conform:[:char | char isDigit] |
9192 | 7461 |
|
7462 |
" |
|
7463 |
'helloWorld' isNumeric |
|
7464 |
'foo1234' isNumeric |
|
7465 |
'f1234' isNumeric |
|
7466 |
'1234' isNumeric |
|
7467 |
'+' isNumeric |
|
7468 |
" |
|
10093
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7469 |
|
8cff5eca1c6f
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
10088
diff
changeset
|
7470 |
"Modified: / 13-10-2006 / 12:54:12 / cg" |
9192 | 7471 |
! |
7472 |
||
18893 | 7473 |
isPlainString |
7474 |
"return true, if the receiver is a plain string (without attributes); |
|
7475 |
true is returned here - redefinition of Object>>isPlainString." |
|
7476 |
||
7477 |
^ true |
|
7478 |
! |
|
7479 |
||
9230 | 7480 |
isString |
7481 |
"return true, if the receiver is some kind of string; |
|
7482 |
true is returned here - redefinition of Object>>isString." |
|
7483 |
||
7484 |
^ true |
|
7485 |
! |
|
7486 |
||
7487 |
isUnarySelector |
|
7488 |
"Answer true if the receiver contains only chars in an ANSI unary method selector, false otherwise." |
|
7489 |
||
17442 | 7490 |
^ (self first isLetterOrUnderline) |
9845 | 7491 |
and:[ self conform: [ :chr | chr isLetterOrDigit or:[chr == $_] ]] |
7492 |
||
7493 |
"Modified: / 13-09-2006 / 11:35:15 / cg" |
|
9230 | 7494 |
! |
7495 |
||
14122 | 7496 |
isUnicode16String |
7497 |
^ false |
|
7498 |
! |
|
7499 |
||
7500 |
isUnicode32String |
|
7501 |
^ false |
|
7502 |
! |
|
7503 |
||
7504 |
isUnicodeString |
|
7505 |
^ false |
|
7506 |
! |
|
7507 |
||
9230 | 7508 |
isValidSmalltalkIdentifier |
7509 |
"return true, if the receivers characters make up a valid smalltalk identifier" |
|
7510 |
||
7511 |
|scanner tok| |
|
7512 |
||
7513 |
scanner := Compiler new. |
|
7514 |
scanner source:(self readStream). |
|
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
7515 |
Parser parseErrorSignal handle:[:ex | |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7516 |
tok := nil. |
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
7517 |
] do:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7518 |
tok := scanner nextToken. |
11630
6db5956f188f
isValidSmalltalkIdentifier: return true/false (catch parseError)
Claus Gittinger <cg@exept.de>
parents:
11565
diff
changeset
|
7519 |
]. |
9230 | 7520 |
tok ~~ #Identifier ifTrue:[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7521 |
^ false |
9230 | 7522 |
]. |
7523 |
scanner tokenPosition == 1 ifFalse:[^ false]. |
|
7524 |
^ scanner sourceStream atEnd. |
|
7525 |
||
7526 |
" |
|
7527 |
'foo' isValidSmalltalkIdentifier |
|
7528 |
'1foo' isValidSmalltalkIdentifier |
|
7529 |
'_foo' isValidSmalltalkIdentifier |
|
7530 |
'_foo_bar_' isValidSmalltalkIdentifier |
|
7531 |
'foo ' isValidSmalltalkIdentifier |
|
7532 |
' foo' isValidSmalltalkIdentifier |
|
7533 |
" |
|
7534 |
! |
|
7535 |
||
14555 | 7536 |
isWideString |
15829 | 7537 |
|string| |
7538 |
||
7539 |
(string := self string) ~~ self ifTrue:[ |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7540 |
^ string isWideString. |
15829 | 7541 |
]. |
7542 |
^ self contains:[:aCharacter | aCharacter codePoint > 16rFF]. |
|
14555 | 7543 |
! |
7544 |
||
9192 | 7545 |
numArgs |
18463 | 7546 |
<resource: #obsolete> |
608 | 7547 |
"treating the receiver as a message selector, return how many arguments would it take" |
7548 |
||
18463 | 7549 |
^ self argumentCount |
9192 | 7550 |
! |
7551 |
||
7552 |
partsIfSelector |
|
14629 | 7553 |
"treat the receiver as a message selector, return a collection of parts. |
7554 |
Notice: this is more tolerant than Smalltalk's syntax would suggest; |
|
7555 |
especially it allows for empty keyword parts between colons. |
|
7556 |
This is not (and should not be checked here), to allow parsing of |
|
7557 |
degenerate selectors as appearing with objectiveC." |
|
608 | 7558 |
|
9192 | 7559 |
|idx1 "{ Class: SmallInteger }" |
7560 |
coll idx2 sz| |
|
7561 |
||
7562 |
coll := OrderedCollection new. |
|
7563 |
idx1 := 1. |
|
7564 |
sz := self size. |
|
16245 | 7565 |
[ |
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7566 |
idx2 := self indexOf:$: startingAt:idx1. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7567 |
(idx2 == 0 or:[idx2 == sz]) ifTrue:[ |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7568 |
coll add:(self copyFrom:idx1). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7569 |
^ coll |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7570 |
]. |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7571 |
coll add:(self copyFrom:idx1 to:idx2). |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7572 |
idx1 := idx2 + 1 |
16245 | 7573 |
] loop. |
9192 | 7574 |
|
7575 |
" |
|
18350
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7576 |
'foo:' partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7577 |
'foo:bar:' partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7578 |
'foo::::' partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7579 |
#foo:bar: partsIfSelector |
8f0102bb84f5
a send avoided in endsWith:
Claus Gittinger <cg@exept.de>
parents:
18318
diff
changeset
|
7580 |
'hello' partsIfSelector |
9192 | 7581 |
'+' partsIfSelector |
7582 |
" |
|
64 | 7583 |
! ! |
7584 |
||
9192 | 7585 |
!CharacterArray methodsFor:'tracing'! |
7586 |
||
7587 |
traceInto:aRequestor level:level from:referrer |
|
7588 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
7589 |
||
7590 |
^ aRequestor traceCharacterArray:self level:level from:referrer |
|
7591 |
||
7592 |
||
7593 |
! ! |
|
7594 |
||
7595 |
!CharacterArray methodsFor:'visiting'! |
|
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7596 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7597 |
acceptVisitor:aVisitor with:aParameter |
16733 | 7598 |
"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
|
7599 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7600 |
^ aVisitor visitString:self with:aParameter |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7601 |
! ! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8376
diff
changeset
|
7602 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
7603 |
!CharacterArray class methodsFor:'documentation'! |
629 | 7604 |
|
7605 |
version |
|
18476 | 7606 |
^ '$Header$' |
12058 | 7607 |
! |
7608 |
||
7609 |
version_CVS |
|
18476 | 7610 |
^ '$Header$' |
629 | 7611 |
! ! |
6809 | 7612 |
|
14606 | 7613 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
7614 |
CharacterArray initialize! |