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