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