author | Stefan Vogel <sv@exept.de> |
Wed, 07 May 2014 16:48:48 +0200 | |
changeset 3274 | 66c78a994f69 |
parent 3231 | 94e60fc8bc0d |
child 3538 | d79ee26ed971 |
permissions | -rw-r--r-- |
2337
755696d72648
comment/format in: #asSoundexCode
Claus Gittinger <cg@exept.de>
parents:
2303
diff
changeset
|
1 |
"{ Package: 'stx:libbasic2' }"! |
1668 | 2 |
|
2288 | 3 |
!CharacterArray methodsFor:'matching - phonetic'! |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
4 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
5 |
asKoelnerPhoneticCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
6 |
"return a koelner phonetic code. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
7 |
The koelnerPhonetic code is for the german language what the soundex code is for english; |
2303 | 8 |
it returns simular strings for similar sounding words. |
9 |
There are some differences to soundex, though: |
|
10 |
its length is not limited to 4, but depends on the length of the original string; |
|
11 |
it does not start with the first character of the input. |
|
2288 | 12 |
|
13 |
Caveat: this phonetic code is especially suited for german words. |
|
2303 | 14 |
Please have a look at the other phonetic comparison operators found |
15 |
in PhoneticStringUtilities." |
|
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
16 |
|
2303 | 17 |
^ PhoneticStringUtilities koelnerPhoneticCodeOf:self |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
18 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
19 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
20 |
#( |
2303 | 21 |
'Müller' |
22 |
'Miller' |
|
23 |
'Mueller' |
|
24 |
'Mühler' |
|
25 |
'Mühlherr' |
|
26 |
'Mülherr' |
|
27 |
'Myler' |
|
28 |
'Millar' |
|
29 |
'Myller' |
|
30 |
'Müllar' |
|
31 |
'Müler' |
|
32 |
'Muehler' |
|
33 |
'Mülller' |
|
34 |
'Müllerr' |
|
35 |
'Muehlherr' |
|
36 |
'Muellar' |
|
37 |
'Mueler' |
|
38 |
'Mülleer' |
|
39 |
'Mueller' |
|
40 |
'Nüller' |
|
41 |
'Nyller' |
|
42 |
'Niler' |
|
43 |
'Czerny' |
|
44 |
'Tscherny' |
|
45 |
'Czernie' |
|
46 |
'Tschernie' |
|
47 |
'Schernie' |
|
48 |
'Scherny' |
|
49 |
'Scherno' |
|
50 |
'Czerne' |
|
51 |
'Zerny' |
|
52 |
'Tzernie' |
|
53 |
'Breschnew' |
|
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
54 |
) do:[:w | |
2303 | 55 |
Transcript show:w; show:'->'; showCR:(w asKoelnerPhoneticCode) |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
56 |
]. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
57 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
58 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
59 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
60 |
'Breschnew' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
61 |
'Breschnew' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
62 |
'Breschneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
63 |
'Braeschneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
64 |
'Braessneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
65 |
'Pressneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
66 |
'Presznäph' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
67 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
68 |
! ! |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
69 |
|
2288 | 70 |
!CharacterArray methodsFor:'matching - phonetic'! |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
71 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
72 |
asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
73 |
"return a soundex phonetic code or nil. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
74 |
Soundex returns similar codes for similar sounding words, making it a useful |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
75 |
tool when searching for words where the correct spelling is unknown. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
76 |
(read Knuth or search the web if you dont know what a soundex code is). |
2288 | 77 |
|
2337
755696d72648
comment/format in: #asSoundexCode
Claus Gittinger <cg@exept.de>
parents:
2303
diff
changeset
|
78 |
Caveat: 'similar sounding words' means: 'similar sounding in ENGLISH' |
2435 | 79 |
Please have a look at the other phonetic comparison operators found |
80 |
in PhoneticStringUtilities." |
|
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
81 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
82 |
^ PhoneticStringUtilities soundexCodeOf:self |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
83 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
84 |
" |
2303 | 85 |
'claus' asSoundexCode |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
86 |
'clause' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
87 |
'close' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
88 |
'smalltalk' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
89 |
'smaltalk' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
90 |
'smaltak' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
91 |
'smaltok' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
92 |
'smoltok' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
93 |
'aa' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
94 |
'by' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
95 |
'bab' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
96 |
'bob' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
97 |
'bop' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
98 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
99 |
! ! |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
100 |
|
2241 | 101 |
!CharacterArray methodsFor:'printing & storing'! |
102 |
||
2303 | 103 |
printf:args |
104 |
"Format and print the receiver with <args> formatted in C style, |
|
2295 | 105 |
as specified in the Unix C-language manual page for printf(3). |
3114 | 106 |
Return the resulting string (i.e actually, this is more like an sprintf). |
2241 | 107 |
|
108 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 109 |
|
2241 | 110 |
|aStream| |
111 |
||
112 |
aStream := WriteStream on:String new. |
|
2260 | 113 |
self printf:args on:aStream. |
2241 | 114 |
^ aStream contents |
115 |
||
116 |
" |
|
2303 | 117 |
Transcript showCR:('%05x %d %f %o' printf:{ 123. 234*5. 1.234. 8r377 } ) |
2256 | 118 |
" |
119 |
||
120 |
" |
|
2241 | 121 |
Transcript showCR: 'Some examples:'!! |
122 |
||
123 |
Transcript show:'''%#x %#X %03o%*.*s'' printf: #(16rABCD 16rEF 5 9 5 ''ghijklmn'') = .'. |
|
2303 | 124 |
Transcript show: ('%#x %#X %03o%*.*s' printf: #(16rABCD 16rEF 5 9 5 'ghijklmn')). |
2241 | 125 |
Transcript showCR: '.' |
126 |
||
127 |
Transcript show: '''%- 10.4s%.2e'' printf: (Array with: ''abcdefghijkl'' with: Float pi) = .'. |
|
2303 | 128 |
Transcript show: ('%- 10.4s%.2e' printf: (Array with: 'abcdefghijkl' with: Float pi)). |
2241 | 129 |
Transcript showCR: '.' |
130 |
||
131 |
Transcript show: '''%8.3f'' printf: (Array with: 200 sqrt negated) = .'. |
|
132 |
Transcript show: ('%8.3f' printf: (Array with: 200 sqrt negated)). |
|
133 |
Transcript showCR: '.' |
|
134 |
||
135 |
Transcript show: '''%c'' printf: #(16r41) = .'. |
|
136 |
Transcript show: ('%c' printf: #(16r41)). |
|
137 |
Transcript showCR: '.' |
|
138 |
||
139 |
Transcript show: '''%f%2s%s%s%s'' sscanf: ''237.0 this is a test'' = '. |
|
140 |
Transcript showCR: ('%f%2s%s%s%s' sscanf: '237.0 this is a test') printString. |
|
141 |
||
142 |
Transcript show: '''%d%f%s'' sscanf: ''25 54.32e-01 monday'' = '. |
|
143 |
Transcript showCR: ('%d%f%s' sscanf: '25 54.32e-01 monday') printString. |
|
144 |
||
145 |
Transcript show: '''%f%*f %8[A-F0-9]%c%d 0x%x%f'' sscanf: ''12.45 1048.73 AE40Z527 0x75BCD15 34'' = '. |
|
146 |
Transcript showCR: ('%f%*f %8[A-F0-9]%c%d 0x%x%f' sscanf: '12.45 1048.73 AE40Z527 0x75BCD15 34') printString. |
|
147 |
" |
|
148 |
! ! |
|
149 |
||
150 |
!CharacterArray methodsFor:'printing & storing'! |
|
151 |
||
2260 | 152 |
printf:args on:outStream |
153 |
"Format and print the receiver on <outStream> with <args> |
|
154 |
formatted in C style, as specified in the Unix C-language manual page for printf(3). |
|
155 |
||
156 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 157 |
|
2260 | 158 |
|argStream inStream char| |
159 |
||
160 |
argStream := ReadStream on:args. |
|
161 |
inStream := ReadStream on:self. |
|
162 |
[ inStream atEnd ] whileFalse:[ |
|
2303 | 163 |
(char := inStream next) == $% ifFalse:[ |
164 |
outStream nextPut:char |
|
165 |
] ifTrue:[ |
|
166 |
self |
|
167 |
printf_printArgFrom:inStream |
|
168 |
to:outStream |
|
169 |
withData:argStream |
|
170 |
] |
|
2260 | 171 |
] |
172 |
! ! |
|
173 |
||
174 |
!CharacterArray methodsFor:'printing & storing'! |
|
175 |
||
2303 | 176 |
printfWith:arg1 |
2295 | 177 |
"Format and print the receiver with <arg1> formatted in C style, |
178 |
as specified in the Unix C-language manual page for printf(3). |
|
3114 | 179 |
Return the resulting string (i.e actually, this is more like an sprintf)." |
2303 | 180 |
|
2256 | 181 |
^ self printf:(Array with:arg1) |
182 |
||
183 |
" |
|
2303 | 184 |
Transcript showCR:('%05x' printfWith:123) |
2256 | 185 |
" |
186 |
! ! |
|
187 |
||
188 |
!CharacterArray methodsFor:'printing & storing'! |
|
189 |
||
2303 | 190 |
printfWith:arg1 with:arg2 |
191 |
"Format and print the receiver with <argI> formatted in C style, |
|
2295 | 192 |
as specified in the Unix C-language manual page for printf(3). |
3114 | 193 |
Return the resulting string (i.e actually, this is more like an sprintf)." |
2303 | 194 |
|
2256 | 195 |
^ self printf:(Array with:arg1 with:arg2) |
196 |
||
197 |
" |
|
2303 | 198 |
Transcript showCR:('%d %05x' printfWith:123 with:234) |
2256 | 199 |
" |
200 |
! ! |
|
201 |
||
202 |
!CharacterArray methodsFor:'printing & storing'! |
|
203 |
||
204 |
printfWith:arg1 with:arg2 with:arg3 |
|
2303 | 205 |
"Format and print the receiver with <argI> formatted in C style, |
2295 | 206 |
as specified in the Unix C-language manual page for printf(3). |
3114 | 207 |
Return the resulting string (i.e actually, this is more like an sprintf)." |
2303 | 208 |
|
2256 | 209 |
^ self printf:(Array with:arg1 with:arg2 with:arg3) |
210 |
||
211 |
" |
|
2303 | 212 |
Transcript showCR:('%d %05x %08o' printfWith:123 with:234 with:345) |
2256 | 213 |
" |
214 |
! ! |
|
215 |
||
216 |
!CharacterArray methodsFor:'printing & storing'! |
|
217 |
||
218 |
printfWith:arg1 with:arg2 with:arg3 with:arg4 |
|
2303 | 219 |
"Format and print the receiver with <argI> formatted in C style, |
2295 | 220 |
as specified in the Unix C-language manual page for printf(3). |
3114 | 221 |
Return the resulting string (i.e actually, this is more like an sprintf)." |
2303 | 222 |
|
2256 | 223 |
^ self printf:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
224 |
||
225 |
" |
|
2303 | 226 |
Transcript showCR:('%d %05x %08o %b' printfWith:123 with:234 with:345 with:123) |
2256 | 227 |
" |
228 |
! ! |
|
229 |
||
230 |
!CharacterArray methodsFor:'printing & storing'! |
|
231 |
||
2241 | 232 |
printf_formatArgCount |
233 |
"Return the number of arguments required/produced if the receiver is interpreted |
|
234 |
as a printf/scanf format control string. |
|
235 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 236 |
|
2241 | 237 |
|nonConsecutive count| |
238 |
||
239 |
nonConsecutive := true. |
|
240 |
count := 0. |
|
2303 | 241 |
self do:[:c | |
242 |
c == $% ifTrue:[ |
|
243 |
nonConsecutive ifTrue:[ |
|
244 |
count := count + 1. |
|
245 |
nonConsecutive := false |
|
246 |
] ifFalse:[ |
|
247 |
count := count - 1. |
|
248 |
nonConsecutive := true |
|
249 |
] |
|
250 |
] ifFalse:[ |
|
251 |
nonConsecutive := true |
|
252 |
] |
|
2241 | 253 |
]. |
254 |
^ count |
|
255 |
! ! |
|
256 |
||
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
257 |
!CharacterArray methodsFor:'private'! |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
258 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
259 |
printf_printArgFrom:inStream to:outStream withData:argStream |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
260 |
"Interpret the required number of arguments from <argStream> |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
261 |
according to the formatting information in <inStream>. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
262 |
Place the interpretation on <outStream>. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
263 |
The interpretation is C printf(3) style, as |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
264 |
specified in the Unix C-language manual page for printf(3). |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
265 |
<inStream> is assumed to be positioned just past |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
266 |
$%, and a complete control string is assumed available. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
267 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
268 |
Return when the conversion control string is consumed. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
269 |
Leave <inStream> pointing past the last character in the conversion control string. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
270 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
271 |
This code assumes that <inStream> is formatted according to |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
272 |
specification, and error checking is minimal. Unexpected |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
273 |
results will be obtained by illegal control strings, or when |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
274 |
argument types do not match conversion codes, but it probably |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
275 |
won't dump core, like C does in such cases!! |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
276 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
277 |
For copyright information, see goodies/String-printf_scanf.chg" |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
278 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
279 |
|nextArg ljust plus pound width precision pad char arg argString| |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
280 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
281 |
nextArg := [ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
282 |
argStream atEnd ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
283 |
self error:'not enough arguments for format string' |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
284 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
285 |
argStream next |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
286 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
287 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
288 |
ljust := plus := pound := false. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
289 |
width := 0. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
290 |
precision := SmallInteger maxVal. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
291 |
pad := $ . |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
292 |
char := inStream peek. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
293 |
char == $% ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
294 |
^ outStream nextPut:inStream next |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
295 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
296 |
char == $- ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
297 |
ljust := true. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
298 |
inStream next. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
299 |
char := inStream peek |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
300 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
301 |
char == $ ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
302 |
outStream space. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
303 |
inStream next. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
304 |
char := inStream peek |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
305 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
306 |
char == $+ ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
307 |
plus := true. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
308 |
inStream next. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
309 |
char := inStream peek |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
310 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
311 |
char == $# ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
312 |
pound := true. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
313 |
inStream next. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
314 |
char := inStream peek |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
315 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
316 |
char == $* ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
317 |
width := nextArg value. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
318 |
inStream next. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
319 |
char := inStream peek |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
320 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
321 |
char isDigit ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
322 |
char == $0 ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
323 |
pad := $0 |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
324 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
325 |
width := Integer readFrom:inStream. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
326 |
char := inStream peek |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
327 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
328 |
char == $. ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
329 |
inStream next. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
330 |
char := inStream peek. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
331 |
char == $* ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
332 |
precision := nextArg value. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
333 |
inStream next. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
334 |
] ifFalse:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
335 |
precision := Integer readFrom:inStream. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
336 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
337 |
char := inStream peek |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
338 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
339 |
char == $l "Ignore long specifier." ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
340 |
inStream next. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
341 |
char := inStream peek |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
342 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
343 |
('feg' includes:char) ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
344 |
arg := nextArg value asFloat. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
345 |
precision := precision min:6. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
346 |
argString := WriteStream on:String new. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
347 |
char == $g ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
348 |
arg absPrintOn:argString digits:precision + 1 |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
349 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
350 |
char == $f ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
351 |
arg absDecimalPrintOn:argString digits:precision + arg abs log + 1 |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
352 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
353 |
char == $e ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
354 |
arg absScientificPrintOn:argString digits:precision + 1 |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
355 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
356 |
argString := argString contents. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
357 |
arg < 0 ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
358 |
argString := '-' , argString |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
359 |
] ifFalse:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
360 |
plus ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
361 |
argString := '+' , argString |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
362 |
] |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
363 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
364 |
(precision = 0 and:[ pound not ]) ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
365 |
(argString includes:$e) ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
366 |
"self halt" |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
367 |
] ifFalse:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
368 |
argString := arg truncated printString |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
369 |
] |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
370 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
371 |
pound ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
372 |
(argString includes:$e) ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
373 |
"self halt" |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
374 |
] ifFalse:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
375 |
precision - (argString size - (argString indexOf:$.)) timesRepeat:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
376 |
argString := argString , '0' |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
377 |
] |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
378 |
] |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
379 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
380 |
ljust ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
381 |
outStream nextPutAll:argString |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
382 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
383 |
width - argString size timesRepeat:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
384 |
outStream space |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
385 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
386 |
ljust ifFalse:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
387 |
outStream nextPutAll:argString |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
388 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
389 |
^ inStream next |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
390 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
391 |
char == $c ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
392 |
arg := String with:nextArg value asCharacter |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
393 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
394 |
char == $s "Assume the arg is a String or Symbol." ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
395 |
arg := nextArg value asString |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
396 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
397 |
char == $d ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
398 |
arg := nextArg value asInteger printString. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
399 |
plus ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
400 |
arg := '+' , arg |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
401 |
] |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
402 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
403 |
char == $u ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
404 |
arg := nextArg value asInteger abs printString |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
405 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
406 |
char == $o ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
407 |
arg := nextArg value asInteger abs printStringRadix:8. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
408 |
pound ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
409 |
arg := '0' , arg |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
410 |
] |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
411 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
412 |
char == $b ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
413 |
arg := nextArg value asInteger abs printStringRadix:2. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
414 |
pound ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
415 |
arg := '0' , arg |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
416 |
] |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
417 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
418 |
('xX' includes:char) ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
419 |
arg := nextArg value asInteger abs printStringRadix:16. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
420 |
pound ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
421 |
arg := '0x' , arg |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
422 |
] |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
423 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
424 |
char == $x ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
425 |
1 to:arg size do:[:i | |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
426 |
('ABCDEF' includes:(arg at:i)) ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
427 |
arg at:i put:((arg at:i) asciiValue + 16r20) asCharacter |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
428 |
] |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
429 |
] |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
430 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
431 |
precision := precision min:arg size. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
432 |
ljust ifTrue:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
433 |
outStream nextPutAll:(arg copyFrom:1 to:precision) |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
434 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
435 |
width - precision timesRepeat:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
436 |
outStream nextPut:pad |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
437 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
438 |
ljust ifFalse:[ |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
439 |
outStream nextPutAll:(arg copyFrom:1 to:precision) |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
440 |
]. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
441 |
^ inStream next |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
442 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
443 |
"Modified: / 24-07-2011 / 07:16:42 / cg" |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
444 |
! ! |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
445 |
|
2241 | 446 |
!CharacterArray methodsFor:'printing & storing'! |
447 |
||
2260 | 448 |
printf_printOn:outStream withData:args |
449 |
<resource: #obsolete> |
|
2303 | 450 |
|
2241 | 451 |
"Format and print the receiver on <outStream> with <args> |
452 |
formatted in C style, as specified in the Unix C-language manual page for printf(3). |
|
453 |
||
454 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
455 |
||
2260 | 456 |
self obsoleteMethodWarning:'use printf:on:'. |
457 |
self printf:args on:outStream |
|
2241 | 458 |
! ! |
459 |
||
460 |
!CharacterArray methodsFor:'converting'! |
|
461 |
||
2303 | 462 |
scanf:dataStream |
2241 | 463 |
"Return a Collection of objects found in the Character Stream |
2303 | 464 |
<dataStream> as interpreted according to the receiver. |
2241 | 465 |
The receiver is assumed to be a conversion control string as |
466 |
specified in the Unix C-language manual page for scanf(3). |
|
467 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 468 |
|
2241 | 469 |
|results format char| |
470 |
||
471 |
results := OrderedCollection new. |
|
472 |
format := ReadStream on:self. |
|
473 |
[ format atEnd ] whileFalse:[ |
|
2303 | 474 |
char := format next. |
475 |
(char == Character space or:[ char == Character tab ]) ifTrue:[ |
|
476 |
dataStream skipSeparators. |
|
477 |
format skipSeparators |
|
478 |
]. |
|
479 |
char == $% ifTrue:[ |
|
480 |
self |
|
481 |
scanf_scanArgFrom:dataStream |
|
482 |
to:results |
|
483 |
format:format |
|
484 |
] ifFalse:[ |
|
485 |
dataStream peekFor:char |
|
486 |
] |
|
2241 | 487 |
]. |
488 |
^ results |
|
489 |
||
490 |
" |
|
2303 | 491 |
'%d %x' scanf:(ReadStream on:'1234 ff00') |
2241 | 492 |
" |
493 |
! ! |
|
494 |
||
495 |
!CharacterArray methodsFor:'private'! |
|
496 |
||
2303 | 497 |
scanf_scanArgFrom:dataStream to:collection format:format |
2241 | 498 |
"Add to <collection> an object who's representation is found |
499 |
in <dataStream> interpreted according to the conversion |
|
2303 | 500 |
control string in the Stream <format>. |
501 |
<format> is assumed to be positioned just past a $%, and a complete control |
|
2241 | 502 |
string is assumed available. |
503 |
||
504 |
Return when the conversion control string is consumed. Leave |
|
505 |
<format> pointing past the last character in the conversion |
|
506 |
control string, leave <dataStream> pointing past any width |
|
507 |
specified in <format>, or at the first character that doesn't |
|
508 |
make sense for the <format>. |
|
509 |
||
510 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 511 |
|
2241 | 512 |
|final width char pos data scanset exclusive return last| |
513 |
||
2303 | 514 |
final := [:retval | |
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
515 |
collection add:retval. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
516 |
data == dataStream ifFalse:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
517 |
dataStream position:dataStream position + data position |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
518 |
]. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
519 |
^ self |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
520 |
]. |
2241 | 521 |
width := 0. |
522 |
char := format peek. |
|
523 |
char == $% ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
524 |
^ dataStream peekFor:char |
2241 | 525 |
]. |
526 |
char == $* ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
527 |
format next. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
528 |
char := format peek. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
529 |
final := [:retval | |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
530 |
data == dataStream ifFalse:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
531 |
dataStream position:dataStream position + data position |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
532 |
]. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
533 |
^ self |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
534 |
] |
2241 | 535 |
]. |
536 |
char isDigit ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
537 |
width := Integer readFrom:format. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
538 |
char := format peek |
2241 | 539 |
]. |
540 |
('slhduoxfeg' includes:char) ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
541 |
dataStream skipSeparators |
2241 | 542 |
]. |
543 |
width = 0 ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
544 |
data := dataStream |
2241 | 545 |
] ifFalse:[ |
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
546 |
pos := dataStream position. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
547 |
data := ReadStream on:(dataStream next:width). |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
548 |
dataStream position:pos |
2241 | 549 |
]. |
550 |
char == $s ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
551 |
final value:(data upToSeparator) |
2241 | 552 |
]. |
553 |
char == $c ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
554 |
width = 0 ifTrue:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
555 |
final value:(String with:data next) |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
556 |
] ifFalse:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
557 |
final value:data contents |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
558 |
] |
2241 | 559 |
]. |
560 |
char == $[ "What a mess!!" ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
561 |
return := WriteStream on:(String new:8). |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
562 |
scanset := IdentitySet new. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
563 |
format next. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
564 |
width = 0 ifTrue:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
565 |
width := SmallInteger maxVal |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
566 |
]. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
567 |
exclusive := format peekFor:$^. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
568 |
[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
569 |
last := char. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
570 |
char := format next. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
571 |
char == $] |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
572 |
] whileFalse:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
573 |
char == $- ifFalse:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
574 |
scanset add:char |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
575 |
] ifTrue:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
576 |
last to:format next do:[:c | |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
577 |
scanset add:c |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
578 |
] |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
579 |
] |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
580 |
]. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
581 |
[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
582 |
data atEnd not and:[ (scanset includes:data peek) xor:exclusive ] |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
583 |
] whileTrue:[ return nextPut:data next ]. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
584 |
final value:return contents |
2241 | 585 |
]. |
586 |
('lh' includes:char) ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
587 |
format next. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
588 |
char := format peek |
2241 | 589 |
]. |
590 |
('DUdu' includes:char) ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
591 |
final value:(Integer readFrom:data) |
2241 | 592 |
]. |
593 |
('FEGfeg' includes:char) ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
594 |
final value:(Float readFrom:data) |
2241 | 595 |
]. |
2256 | 596 |
('b' includes:char) ifTrue:[ |
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
597 |
final value:(Integer readFrom:data radix:2) |
2256 | 598 |
]. |
2241 | 599 |
('Oo' includes:char) ifTrue:[ |
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
600 |
final value:(Integer readFrom:data radix:8) |
2241 | 601 |
]. |
602 |
('Xx' includes:char) ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
603 |
final value:(Integer readFrom:data radix:16) |
2241 | 604 |
] |
2256 | 605 |
|
606 |
" |
|
2303 | 607 |
'%d %x' sscanf:'1234 ff00' |
608 |
'%d %x %b' sscanf:'1234 ff00 1001' |
|
2256 | 609 |
" |
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
610 |
|
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
611 |
"Modified: / 29-11-2011 / 11:55:39 / cg" |
2241 | 612 |
! ! |
613 |
||
614 |
!CharacterArray methodsFor:'converting'! |
|
615 |
||
2303 | 616 |
sscanf:string |
2241 | 617 |
"Return a Collection of objects found in <string> as |
2303 | 618 |
interpreted according to the receiver. |
2241 | 619 |
The receiver is assumed to be a conversion control string as |
620 |
specified in the Unix C-language manual page for scanf(3). |
|
621 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 622 |
|
2241 | 623 |
^ self scanf:(ReadStream on:string) |
624 |
||
625 |
" |
|
2303 | 626 |
'%d %x' sscanf:'1234 ff00' |
627 |
'%d %x %b' sscanf:'1234 ff00 1001' |
|
2241 | 628 |
" |
629 |
! ! |
|
630 |
||
2237 | 631 |
!Float methodsFor:'private'! |
632 |
||
2303 | 633 |
absDecimalPrintOn:aStream digits:digits |
2237 | 634 |
"Place a string representation of the receiver's abs value |
635 |
on <aStream> using <digits> significant digits, using decimal notation. |
|
636 |
This is a helper for printf." |
|
637 |
||
638 |
|exp x fuzz i| |
|
639 |
||
640 |
"x is myself normalized to (1.0, 10.0), exp is my exponent" |
|
2303 | 641 |
exp := self abs < 1.0 |
642 |
ifTrue:[ (10.0 / self abs) log floor negated ] |
|
643 |
ifFalse:[ self abs log floor ]. |
|
2237 | 644 |
x := self abs / (10.0 raisedTo:exp). |
645 |
fuzz := 10.0 raisedTo:1 - digits. |
|
646 |
"round the last digit to be printed" |
|
647 |
x := 0.5 * fuzz + x. |
|
648 |
x >= 10.0 "check if rounding has unnormalized x" ifTrue:[ |
|
2303 | 649 |
x := x / 10.0. |
650 |
exp := exp + 1 |
|
2237 | 651 |
]. |
652 |
exp < 0 ifTrue:[ |
|
2303 | 653 |
1 to:1 - exp do:[:j | |
654 |
aStream nextPut:('0.000000000000' at:j) |
|
655 |
] |
|
2237 | 656 |
]. |
657 |
[ x >= fuzz ] "use fuzz to track significance" whileTrue:[ |
|
2303 | 658 |
i := x truncated. |
659 |
aStream nextPut:(48 + i) asCharacter. |
|
660 |
x := (x - i) * 10.0. |
|
661 |
fuzz := fuzz * 10.0. |
|
662 |
exp := exp - 1. |
|
663 |
exp = -1 ifTrue:[ |
|
664 |
aStream nextPut:$. |
|
665 |
] |
|
2237 | 666 |
]. |
667 |
[ exp >= -1 ] whileTrue:[ |
|
2303 | 668 |
aStream nextPut:$0. |
669 |
exp := exp - 1. |
|
670 |
exp = -1 ifTrue:[ |
|
671 |
aStream nextPut:$. |
|
672 |
] |
|
2237 | 673 |
] |
674 |
! ! |
|
675 |
||
676 |
!Float methodsFor:'private'! |
|
677 |
||
2303 | 678 |
absPrintOn:aStream digits:digits |
679 |
"Place a string representation of the receiver's abs value on <aStream> using |
|
2237 | 680 |
<digits> significant digits. |
681 |
This is a helper for printf." |
|
2303 | 682 |
|
2237 | 683 |
(self < 1.0e6 and:[ self > 1.0e-4 ]) ifTrue:[ |
2303 | 684 |
self absDecimalPrintOn:aStream digits:digits |
2237 | 685 |
] ifFalse:[ |
2303 | 686 |
self absScientificPrintOn:aStream digits:digits |
2237 | 687 |
] |
688 |
! ! |
|
689 |
||
690 |
!Float methodsFor:'private'! |
|
691 |
||
2303 | 692 |
absScientificPrintOn:aStream digits:digits |
2237 | 693 |
"Place a string representation of the receiver's abs value on <aStream> using <digits> significant |
694 |
digits, using scientific notation. |
|
695 |
This is a helper for printf." |
|
2303 | 696 |
|
2237 | 697 |
|exp fuzz x q i| |
698 |
||
699 |
"x is myself normalized to [1.0, 10.0), exp is my exponent" |
|
2303 | 700 |
exp := self abs < 1.0 |
701 |
ifTrue:[ (10.0 / self abs) log floor negated ] |
|
702 |
ifFalse:[ self abs log floor ]. |
|
2237 | 703 |
x := self abs / (10.0 raisedTo:exp). |
704 |
fuzz := 10.0 raisedTo:1 - digits. |
|
705 |
"round the last digit to be printed" |
|
706 |
x := 0.5 * fuzz + x. |
|
707 |
x >= 10.0 "check if rounding has unnormalized x" ifTrue:[ |
|
2303 | 708 |
x := x / 10.0. |
709 |
exp := exp + 1 |
|
2237 | 710 |
]. |
711 |
q := exp. |
|
712 |
exp := 0. |
|
713 |
[ x >= fuzz ] "use fuzz to track significance" whileTrue:[ |
|
2303 | 714 |
i := x truncated. |
715 |
aStream nextPut:(48 + i) asCharacter. |
|
716 |
x := (x - i) * 10.0. |
|
717 |
fuzz := fuzz * 10.0. |
|
718 |
exp := exp - 1. |
|
719 |
exp = -1 ifTrue:[ |
|
720 |
aStream nextPut:$. |
|
721 |
] |
|
2237 | 722 |
]. |
723 |
[ exp >= -1 ] whileTrue:[ |
|
2303 | 724 |
aStream nextPut:$0. |
725 |
exp := exp - 1. |
|
726 |
exp = -1 ifTrue:[ |
|
727 |
aStream nextPut:$. |
|
728 |
] |
|
2237 | 729 |
]. |
730 |
aStream nextPut:$e. |
|
731 |
q printOn:aStream |
|
732 |
! ! |
|
733 |
||
1759 | 734 |
!Object methodsFor:'dependents-interests'! |
735 |
||
736 |
addInterest:anInterest |
|
737 |
"install an interest forwarder. |
|
738 |
Here, we use the nonWeakDependencies." |
|
739 |
||
740 |
self addNonWeakDependent:anInterest |
|
741 |
||
742 |
"Created: 14.10.1996 / 22:27:34 / stefan" |
|
743 |
! ! |
|
744 |
||
745 |
!Object methodsFor:'dependents-interests'! |
|
746 |
||
747 |
expressInterestIn:aspect for:anObject sendBack:aSelector |
|
748 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
749 |
changes aspect." |
|
750 |
||
751 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
752 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
753 |
||
2303 | 754 |
self addInterest:(InterestConverter |
755 |
destination:anObject |
|
756 |
selector:aSelector |
|
757 |
aspect:aspect) |
|
1759 | 758 |
|
759 |
" |
|
760 |
|p b| |
|
761 |
||
762 |
b := [Transcript showCR:' -> the point changed']. |
|
763 |
||
764 |
p := Point new. |
|
765 |
Transcript showCR:'interest in #foo:'. |
|
766 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
767 |
p x:1. |
|
768 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
769 |
p changed:#bar. |
|
770 |
Transcript cr. |
|
771 |
||
772 |
Delay waitForSeconds:1. |
|
773 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
774 |
p changed:#foo. |
|
775 |
Transcript cr. |
|
776 |
||
777 |
Delay waitForSeconds:1. |
|
778 |
Transcript showCR:'no more interest in #foo:'. |
|
779 |
p retractInterestIn:#foo for:b. |
|
780 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
781 |
p changed:#foo. |
|
782 |
Transcript cr. |
|
783 |
||
784 |
Delay waitForSeconds:1. |
|
785 |
Transcript showCR:'interest in #bar now:'. |
|
786 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
787 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
788 |
p changed:#foo. |
|
789 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
790 |
p changed:#bar. |
|
791 |
Transcript cr. |
|
792 |
||
793 |
Delay waitForSeconds:1. |
|
794 |
Transcript showCR:'interest in #foo now:'. |
|
795 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
796 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
797 |
p changed:#foo. |
|
798 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
799 |
p changed:#bar. |
|
800 |
Transcript cr. |
|
801 |
||
802 |
Delay waitForSeconds:1. |
|
803 |
Transcript showCR:'no more interests:'. |
|
804 |
p retractInterestsFor:b. |
|
805 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
806 |
p changed:#foo. |
|
807 |
Transcript showCR:'now changing #bar... (expect no notification)'. |
|
808 |
p changed:#bar. |
|
809 |
Transcript cr. |
|
810 |
||
811 |
p release. |
|
812 |
" |
|
1668 | 813 |
|
1759 | 814 |
"Created: 19.4.1996 / 10:26:22 / cg" |
815 |
"Modified: 19.4.1996 / 12:34:08 / cg" |
|
816 |
"Modified: 14.10.1996 / 22:28:20 / stefan" |
|
817 |
! ! |
|
818 |
||
819 |
!Object methodsFor:'dependents-interests'! |
|
820 |
||
821 |
interests |
|
822 |
"return a Collection of interests - empty if there is none. |
|
823 |
Here, we use the nonWeakDependents for interests." |
|
824 |
||
825 |
^ self nonWeakDependents |
|
826 |
||
827 |
"Created: / 14.10.1996 / 22:20:51 / stefan" |
|
828 |
"Modified: / 30.1.1998 / 14:07:35 / cg" |
|
829 |
! ! |
|
830 |
||
831 |
!Object methodsFor:'dependents-interests'! |
|
832 |
||
833 |
interestsFor:someOne |
|
834 |
"return a collection of interests of someOne - empty if there is none." |
|
835 |
||
836 |
|coll deps| |
|
837 |
||
838 |
deps := self interests. |
|
839 |
deps size == 0 ifTrue:[^ #()]. |
|
840 |
||
841 |
coll := IdentitySet new. |
|
842 |
||
843 |
deps do:[:dep | |
|
2303 | 844 |
(dep isInterestConverter) ifTrue:[ |
845 |
dep destination == someOne ifTrue:[ |
|
846 |
coll add:dep. |
|
847 |
] |
|
848 |
] |
|
1759 | 849 |
]. |
850 |
^ coll |
|
851 |
||
852 |
"Created: / 30.1.1998 / 14:02:26 / cg" |
|
853 |
"Modified: / 30.1.1998 / 14:08:24 / cg" |
|
854 |
! ! |
|
1668 | 855 |
|
1759 | 856 |
!Object methodsFor:'dependents-interests'! |
857 |
||
858 |
onChangeEvaluate:aBlock |
|
859 |
"arrange for aBlock to be evaluated whenever the receiver changes." |
|
860 |
||
2149
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
861 |
|na selector| |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
862 |
|
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
863 |
na := aBlock numArgs. |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
864 |
na == 0 ifTrue:[ |
2303 | 865 |
selector := #value |
2149
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
866 |
] ifFalse:[ |
2303 | 867 |
selector := #( #'value:' #'value:value:' #'value:value:value:') at:na |
2149
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
868 |
]. |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
869 |
^ self onChangeSend:selector to:aBlock |
1759 | 870 |
|
871 |
" |
|
872 |
|p b| |
|
873 |
||
874 |
b := [Transcript showCR:' -> the point changed']. |
|
875 |
||
876 |
p := Point new. |
|
877 |
Transcript showCR:'interest in #foo:'. |
|
878 |
p onChangeEvaluate:b. |
|
879 |
p x:1. |
|
880 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
881 |
p changed:#bar. |
|
882 |
||
883 |
p retractInterests. |
|
884 |
p changed:#bar. |
|
885 |
" |
|
886 |
! ! |
|
887 |
||
888 |
!Object methodsFor:'dependents-interests'! |
|
889 |
||
890 |
onChangeSend:aSelector to:anObject |
|
891 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
892 |
changes." |
|
893 |
||
894 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
895 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
896 |
||
897 |
((self interests ? #()) |
|
2303 | 898 |
contains:[:anInterest | |
899 |
(anInterest isInterestConverter) |
|
900 |
and:[ anInterest destination == anObject |
|
901 |
and:[ anInterest selector == aSelector]] |
|
902 |
]) |
|
903 |
ifTrue:[^ self]. |
|
1759 | 904 |
|
2303 | 905 |
self addInterest:(InterestConverter |
906 |
destination:anObject |
|
907 |
selector:aSelector) |
|
1668 | 908 |
|
909 |
" |
|
1759 | 910 |
|p b| |
911 |
||
912 |
b := [Transcript showCR:'the point changed']. |
|
913 |
||
914 |
p := Point new. |
|
915 |
p onChangeSend:#value to:b. |
|
916 |
p x:1. |
|
917 |
Transcript showCR:'now changing'. |
|
918 |
p changed. |
|
919 |
Transcript cr. |
|
920 |
||
921 |
Delay waitForSeconds:1. |
|
922 |
Transcript showCR:'now changing'. |
|
923 |
p changed. |
|
924 |
Transcript cr. |
|
925 |
||
926 |
Delay waitForSeconds:1. |
|
927 |
Transcript showCR:'no more interest'. |
|
928 |
p retractInterestsFor:b. |
|
929 |
Transcript showCR:'now changing again'. |
|
930 |
p changed. |
|
931 |
Transcript cr. |
|
932 |
||
933 |
Delay waitForSeconds:1. |
|
934 |
Transcript showCR:'interest again'. |
|
935 |
p onChangeSend:#value to:b. |
|
936 |
Transcript showCR:'now changing again'. |
|
937 |
p changed. |
|
938 |
Transcript cr. |
|
939 |
" |
|
940 |
||
941 |
"Created: 19.4.1996 / 10:26:38 / cg" |
|
942 |
"Modified: 19.4.1996 / 12:34:26 / cg" |
|
943 |
"Modified: 14.10.1996 / 22:28:27 / stefan" |
|
944 |
! ! |
|
945 |
||
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
946 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
947 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
948 |
removeActionsForEvent:eventSymbol |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
949 |
"remove ST/V-style event triggers." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
950 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
951 |
self retractInterestsIn:eventSymbol |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
952 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
953 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
954 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
955 |
|
2903 | 956 |
removeActionsWithReceiver:aReceiver |
957 |
"remove ST/V-style event triggers." |
|
958 |
||
959 |
self retractInterestsFor:aReceiver |
|
960 |
! ! |
|
961 |
||
962 |
!Object methodsFor:'dependents-st/v event simulation'! |
|
963 |
||
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
964 |
removeAllActionsWithReceiver:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
965 |
"remove ST/V-style event triggers." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
966 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
967 |
self retractInterestsFor:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
968 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
969 |
|
1759 | 970 |
!Object methodsFor:'dependents-interests'! |
971 |
||
972 |
removeInterest:anInterest |
|
973 |
"remove an interest forwarder. |
|
974 |
Here, we use the nonWeakDependencies." |
|
975 |
||
976 |
self removeNonWeakDependent:anInterest |
|
977 |
||
978 |
"Created: 14.10.1996 / 22:21:59 / stefan" |
|
979 |
! ! |
|
980 |
||
981 |
!Object methodsFor:'dependents-interests'! |
|
982 |
||
983 |
retractInterestIn:aspect for:someOne |
|
984 |
"remove the interest of someOne in the receiver changing aspect |
|
985 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
986 |
||
987 |
"/ for now, remove the interestConverter. |
|
988 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
989 |
||
990 |
self retractInterestsForWhich:[:i | (i aspect == aspect) and:[i destination == someOne]] |
|
991 |
||
1668 | 992 |
" |
1759 | 993 |
|p b| |
994 |
||
995 |
b := [Transcript showCR:'the point changed']. |
|
996 |
||
997 |
p := Point new. |
|
998 |
Transcript showCR:'interest in #foo'. |
|
999 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
1000 |
p x:1. |
|
1001 |
Transcript showCR:'now changing #bar'. |
|
1002 |
p changed:#bar. |
|
1003 |
Transcript cr. |
|
1004 |
||
1005 |
Delay waitForSeconds:1. |
|
1006 |
Transcript showCR:'now changing #foo'. |
|
1007 |
p changed:#foo. |
|
1008 |
Transcript cr. |
|
1009 |
||
1010 |
Delay waitForSeconds:1. |
|
1011 |
Transcript showCR:'no more interest in #foo'. |
|
1012 |
p retractInterestIn:#foo for:b. |
|
1013 |
Transcript showCR:'now changing #foo'. |
|
1014 |
p changed:#foo. |
|
1015 |
Transcript cr. |
|
1016 |
||
1017 |
Delay waitForSeconds:1. |
|
1018 |
Transcript showCR:'interest in #bar now'. |
|
1019 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
1020 |
Transcript showCR:'now changing #foo'. |
|
1021 |
p changed:#foo. |
|
1022 |
Transcript showCR:'now changing #bar'. |
|
1023 |
p changed:#bar. |
|
1024 |
Transcript cr. |
|
1025 |
||
1026 |
Delay waitForSeconds:1. |
|
1027 |
Transcript showCR:'interest in #foo now'. |
|
1028 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
1029 |
Transcript showCR:'now changing #foo'. |
|
1030 |
p changed:#foo. |
|
1031 |
Transcript showCR:'now changing #bar'. |
|
1032 |
p changed:#bar. |
|
1033 |
Transcript cr. |
|
1034 |
||
1035 |
Delay waitForSeconds:1. |
|
1036 |
Transcript showCR:'no more interests'. |
|
1037 |
p retractInterestsFor:b. |
|
1038 |
Transcript showCR:'now changing #foo'. |
|
1039 |
p changed:#foo. |
|
1040 |
Transcript showCR:'now changing #bar'. |
|
1041 |
p changed:#bar. |
|
1042 |
Transcript cr. |
|
1043 |
" |
|
1044 |
||
1045 |
"Created: / 19.4.1996 / 10:27:11 / cg" |
|
1046 |
"Modified: / 14.10.1996 / 22:21:19 / stefan" |
|
1047 |
"Modified: / 30.1.1998 / 14:05:34 / cg" |
|
1048 |
! ! |
|
1049 |
||
1050 |
!Object methodsFor:'dependents-interests'! |
|
1051 |
||
1052 |
retractInterests |
|
1053 |
"remove all interests in the receiver changing aspect |
|
1054 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
1055 |
||
1056 |
"/ for now, remove the interestConverter. |
|
1057 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1058 |
||
1059 |
self retractInterestsForWhich:[:i | true ] |
|
1060 |
! ! |
|
1061 |
||
1062 |
!Object methodsFor:'dependents-interests'! |
|
1063 |
||
1064 |
retractInterestsFor:someOne |
|
2303 | 1065 |
"remove the interest of someOne in the receiver |
1759 | 1066 |
(as installed with #onChangeSend:to:)." |
1067 |
||
1068 |
"/ for now, remove the interestConverter. |
|
1069 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1070 |
||
1071 |
self retractInterestsForWhich:[:i | i destination == someOne ] |
|
1072 |
||
1073 |
" |
|
1074 |
|p b| |
|
1075 |
||
1076 |
b := [Transcript showCR:'the point changed']. |
|
1077 |
||
1078 |
p := Point new. |
|
1079 |
p onChangeSend:#value to:b. |
|
1080 |
p x:1. |
|
1081 |
Transcript showCR:'now changing'. |
|
1082 |
p changed. |
|
1083 |
Transcript cr. |
|
1084 |
||
1085 |
Delay waitForSeconds:1. |
|
1086 |
Transcript showCR:'now changing'. |
|
1087 |
p changed. |
|
1088 |
Transcript cr. |
|
1089 |
||
1090 |
Delay waitForSeconds:1. |
|
1091 |
Transcript showCR:'no more interest'. |
|
1092 |
p retractInterestsFor:b. |
|
1093 |
Transcript showCR:'now changing again'. |
|
1094 |
p changed. |
|
1095 |
Transcript cr. |
|
1096 |
||
1097 |
Delay waitForSeconds:1. |
|
1098 |
Transcript showCR:'interest again'. |
|
1099 |
p onChangeSend:#value to:b. |
|
1100 |
Transcript showCR:'now changing again'. |
|
1101 |
p changed. |
|
1102 |
Transcript cr. |
|
1103 |
" |
|
1104 |
||
1105 |
"Created: / 19.4.1996 / 10:23:46 / cg" |
|
1106 |
"Modified: / 14.10.1996 / 22:21:25 / stefan" |
|
1107 |
"Modified: / 30.1.1998 / 14:04:52 / cg" |
|
1108 |
! ! |
|
1109 |
||
1110 |
!Object methodsFor:'dependents-interests'! |
|
1111 |
||
1112 |
retractInterestsForWhich:aBlock |
|
1113 |
"remove all interests in the receiver changing aspect |
|
1114 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
1115 |
||
1116 |
"/ for now, remove the interestConverter. |
|
1117 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1118 |
||
1119 |
|deps coll| |
|
1120 |
||
1121 |
deps := self interests. |
|
1122 |
deps size ~~ 0 ifTrue:[ |
|
2303 | 1123 |
"/ cannot removeDependent within the loop - the interests collection rehashes |
1124 |
coll := OrderedCollection new. |
|
1125 |
deps do:[:dep | |
|
1126 |
dep isInterestConverter ifTrue:[ |
|
1127 |
(aBlock value:dep) ifTrue:[coll add:dep]. |
|
1128 |
] |
|
1129 |
]. |
|
1130 |
coll do:[:dep | |
|
1131 |
self removeInterest:dep. |
|
1132 |
]. |
|
1759 | 1133 |
]. |
1134 |
! ! |
|
1135 |
||
1136 |
!Object methodsFor:'dependents-interests'! |
|
1137 |
||
1138 |
retractInterestsIn:aspect |
|
1139 |
"remove all interests in the receiver changing aspect |
|
1140 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
1141 |
||
1142 |
"/ for now, remove the interestConverter. |
|
1143 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1144 |
||
1145 |
self retractInterestsForWhich:[:i | i aspect == aspect ] |
|
1668 | 1146 |
! ! |
1147 |
||
2901 | 1148 |
!Object methodsFor:'Compatibility-Dolphin'! |
1149 |
||
1150 |
trigger:anAspect |
|
1151 |
self changed:anAspect |
|
1152 |
! ! |
|
1153 |
||
1154 |
!Object methodsFor:'Compatibility-Dolphin'! |
|
1155 |
||
1156 |
trigger:anAspect with:anArgument |
|
1157 |
self changed:anAspect with:anArgument |
|
1158 |
! ! |
|
1159 |
||
1160 |
!Object methodsFor:'dependents-st/v event simulation'! |
|
1161 |
||
1162 |
triggerEvent:aSymbol |
|
1163 |
self changed:aSymbol |
|
1164 |
! ! |
|
1165 |
||
1668 | 1166 |
!Object methodsFor:'dependents-st/v event simulation'! |
1167 |
||
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1168 |
triggerEvent:eventSymbol with:aParameter |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1169 |
"perform ST/V-style event triggering." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1170 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1171 |
self changed:eventSymbol with:(Array with:aParameter). |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1172 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1173 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1174 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1175 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1176 |
triggerEvent:eventSymbol withArguments:parameters |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1177 |
"perform ST/V-style event triggering." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1178 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1179 |
self changed:eventSymbol with:parameters. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1180 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1181 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1182 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1183 |
|
1668 | 1184 |
when:eventSymbol send:selector to:anObject |
1185 |
"install an ST/V-style interest forwarder. |
|
1186 |
Here, we use the nonWeakDependencies." |
|
1187 |
||
1188 |
self addInterest:(InterestConverterWithParameters |
|
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1189 |
destination:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1190 |
selector:selector |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1191 |
aspect:eventSymbol). |
1668 | 1192 |
|
1193 |
" |
|
1194 |
|p b| |
|
1195 |
||
1196 |
b := [Transcript showCR:'the point changed']. |
|
1197 |
||
1198 |
p := Point new. |
|
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1199 |
p when:#foo:bar: send:#value:value: to:[:a :b | Transcript show:'foo: '; show:a; show:' bar: '; showCR:b]. |
1668 | 1200 |
Transcript showCR:'now changing'. |
1201 |
p triggerEvent:#foo:bar: withArguments:#('fooArg' 'barArg'). |
|
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1202 |
p removeActionsForEvent:#foo:bar:. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1203 |
" |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1204 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1205 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1206 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1207 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1208 |
when:eventSymbol send:selector to:anObject with:aParameter |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1209 |
"install an ST/V-style interest forwarder. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1210 |
Here, we use the nonWeakDependencies." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1211 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1212 |
self addInterest:((InterestConverterWithParameters |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1213 |
destination:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1214 |
selector:selector |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1215 |
aspect:eventSymbol) |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1216 |
defaultParameters:(Array with:aParameter)). |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1217 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1218 |
" |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1219 |
|p b| |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1220 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1221 |
b := [Transcript showCR:'the point changed']. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1222 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1223 |
p := Point new. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1224 |
p |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1225 |
when:#foo: |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1226 |
send:#value: |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1227 |
to:[:a | Transcript show:'foo: '; showCR:a] |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1228 |
with:123. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1229 |
Transcript showCR:'now changing'. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1230 |
p triggerEvent:#foo:. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1231 |
p triggerEvent:#foo: with:987. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1232 |
p removeActionsForEvent:#foo:. |
1668 | 1233 |
" |
1234 |
! ! |
|
1235 |
||
2901 | 1236 |
!Object methodsFor:'Compatibility-Dolphin'! |
1237 |
||
1238 |
when:anAspect sendTo:anObject |
|
1239 |
self expressInterestIn:anAspect for:anObject sendBack:anAspect |
|
1240 |
! ! |
|
1241 |
||
2364 | 1242 |
!Stream methodsFor:'stacked computing streams'! |
1243 |
||
1244 |
collecting:aBlock |
|
1245 |
"return a stacked computing stream, which reads elements from the receiver, |
|
1246 |
applies aBlock to each read element, and provides the results as elements to its reader." |
|
1247 |
||
1248 |
^ CollectingReadStream on:self collecting:aBlock |
|
3094 | 1249 |
|
1250 |
" |
|
1251 |
|s s2| |
|
1252 |
||
1253 |
s := 'hello world' readStream. |
|
1254 |
s2 := s collecting:[:ch | ch asUppercase]. |
|
1255 |
s2 upToEnd. |
|
1256 |
" |
|
2364 | 1257 |
! ! |
1258 |
||
1259 |
!Stream methodsFor:'stacked computing streams'! |
|
1260 |
||
1261 |
selecting:aBlock |
|
1262 |
"return a stacked computing stream, which reads elements from the receiver, |
|
1263 |
but only provides elements for which aBlock returns true to its reader." |
|
1264 |
||
1265 |
^ SelectingReadStream on:self selecting:aBlock |
|
3094 | 1266 |
|
1267 |
" |
|
1268 |
|s s2| |
|
1269 |
||
1270 |
s := 'hello world' readStream. |
|
1271 |
s2 := s selecting:[:ch | ch isVowel]. |
|
1272 |
s2 upToEnd. |
|
1273 |
" |
|
2364 | 1274 |
! ! |
1275 |
||
2303 | 1276 |
!stx_libbasic2 class methodsFor:'documentation'! |
1277 |
||
1278 |
extensionsVersion_CVS |
|
3274 | 1279 |
^ '$Header: /cvs/stx/stx/libbasic2/extensions.st,v 1.29 2014-05-07 14:48:48 stefan Exp $' |
3005 | 1280 |
! ! |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
1281 |