author | Claus Gittinger <cg@exept.de> |
Thu, 16 Nov 2000 17:00:58 +0100 | |
changeset 5714 | df1aa9dff662 |
parent 5632 | e680dafe4b0d |
child 5732 | 7b5effa6816e |
permissions | -rw-r--r-- |
64 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
154 | 3 |
All Rights Reserved |
64 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
14 |
|
3926 | 15 |
ByteArray variableByteSubclass:#CharacterArray |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
16 |
instanceVariableNames:'' |
2734 | 17 |
classVariableNames:'PreviousMatch DecoderTables EncoderTables DecodingFailedSignal |
18 |
EncodingFailedSignal' |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
19 |
poolDictionaries:'' |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
20 |
category:'Collections-Text' |
64 | 21 |
! |
22 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
23 |
!CharacterArray class methodsFor:'documentation'! |
64 | 24 |
|
82 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
154 | 28 |
All Rights Reserved |
82 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
64 | 39 |
documentation |
40 |
" |
|
255 | 41 |
CharacterArray is a superclass for all kinds of Strings (i.e. |
68 | 42 |
(singleByte-)Strings, TwoByteStrings and whatever comes in the future. |
154 | 43 |
|
2537 | 44 |
This class is abstract, meaning that there are no instances of it. |
45 |
All this class does is provide common protocol for concrete subclasses. |
|
1290 | 46 |
|
47 |
[author:] |
|
48 |
Claus Gittinger |
|
49 |
||
50 |
[see also:] |
|
51 |
String TwoByteString |
|
52 |
StringCollection |
|
64 | 53 |
" |
54 |
! ! |
|
55 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
56 |
!CharacterArray class methodsFor:'initialization'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
57 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
58 |
initialize |
5440 | 59 |
DecodingFailedSignal isNil ifTrue:[ |
60 |
DecodingFailedSignal := Signal new mayProceed:true. |
|
61 |
DecodingFailedSignal notifierString:'decoding failure'. |
|
62 |
DecodingFailedSignal nameClass:self message:#decodingFailedSignal. |
|
63 |
||
64 |
EncodingFailedSignal := QuerySignal new mayProceed:true. |
|
65 |
EncodingFailedSignal notifierString:'encoding failure'. |
|
66 |
EncodingFailedSignal nameClass:self message:#encodingFailedSignal. |
|
67 |
] |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
68 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
69 |
" |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
70 |
CharacterArray initialize |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
71 |
" |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
72 |
|
2833 | 73 |
"Modified: 3.8.1997 / 18:15:59 / cg" |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
74 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
75 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
76 |
!CharacterArray class methodsFor:'instance creation'! |
64 | 77 |
|
78 |
basicNew |
|
79 |
"return a new empty string" |
|
80 |
||
81 |
^ self basicNew:0 |
|
82 |
! |
|
83 |
||
2734 | 84 |
fromBytes:aByteCollection |
85 |
"return an instance of the receiver class, |
|
86 |
taking untranslated bytes from the argument, aByteCollection. |
|
87 |
Only useful, when reading twoByteStrings from external sources." |
|
88 |
||
89 |
|mySize nBytes newString dstIdx| |
|
90 |
||
91 |
nBytes := aByteCollection size. |
|
92 |
mySize := self basicNew bitsPerCharacter. |
|
93 |
mySize == 16 ifTrue:[ |
|
94 |
newString := self basicNew:(nBytes // 2). |
|
95 |
dstIdx := 1. |
|
96 |
aByteCollection pairWiseDo:[:hi :lo | |
|
97 |
newString at:dstIdx put:(Character value:(hi bitShift:8)+lo). |
|
98 |
dstIdx := dstIdx + 1 |
|
99 |
]. |
|
100 |
^ newString. |
|
101 |
]. |
|
102 |
||
103 |
^ (self basicNew:nBytes) replaceFrom:1 with:aByteCollection |
|
104 |
||
105 |
" |
|
106 |
TwoByteString fromBytes:#[16r21 16r21] |
|
107 |
" |
|
108 |
||
109 |
"Modified: 30.6.1997 / 20:08:37 / cg" |
|
110 |
! |
|
111 |
||
64 | 112 |
fromString:aString |
113 |
"return a copy of the argument, aString" |
|
114 |
||
68 | 115 |
^ (self basicNew:(aString size)) replaceFrom:1 with:aString |
116 |
||
117 |
"TwoByteString fromString:'hello'" |
|
581 | 118 |
! |
119 |
||
120 |
fromStringCollection:aCollectionOfStrings |
|
121 |
"return new string formed by concatenating a copy of the argument, aString" |
|
122 |
||
123 |
^ self fromStringCollection:aCollectionOfStrings separatedBy:'' |
|
124 |
||
125 |
" |
|
126 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') |
|
127 |
" |
|
128 |
||
129 |
"Created: 20.11.1995 / 15:26:59 / cg" |
|
130 |
! |
|
131 |
||
132 |
fromStringCollection:aCollectionOfStrings separatedBy:aSeparatorString |
|
133 |
"return new string formed by concatenating a copy of the argument, aString" |
|
134 |
||
135 |
|newString first| |
|
136 |
||
137 |
newString := ''. |
|
138 |
first := true. |
|
139 |
aCollectionOfStrings do:[:s | |
|
140 |
first ifFalse:[ |
|
141 |
newString := newString , aSeparatorString |
|
142 |
] ifTrue:[ |
|
143 |
first := false |
|
144 |
]. |
|
145 |
newString := newString , s |
|
146 |
]. |
|
147 |
^ newString |
|
148 |
||
149 |
" |
|
150 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:' ' |
|
151 |
" |
|
152 |
||
153 |
"Created: 20.11.1995 / 15:32:17 / cg" |
|
608 | 154 |
! |
155 |
||
156 |
new |
|
157 |
"return a new empty string" |
|
158 |
||
159 |
^ self basicNew:0 |
|
64 | 160 |
! ! |
161 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
162 |
!CharacterArray class methodsFor:'Signal constants'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
163 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
164 |
decodingFailedSignal |
2833 | 165 |
"return the signal, raised when decoding of a string is not possible |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
166 |
due to invalid characters contained in the source. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
167 |
This may happen for example, if a non EUC coded 8-bit string |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
168 |
is attempted to be decoded into a JIS string." |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
169 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
170 |
^ DecodingFailedSignal |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
171 |
|
2833 | 172 |
"Created: 28.6.1997 / 20:09:55 / cg" |
173 |
"Modified: 3.8.1997 / 18:16:47 / cg" |
|
174 |
! |
|
175 |
||
176 |
encodingFailedSignal |
|
177 |
"return the (query-) signal, raised when encoding of a string is not possible |
|
178 |
due to invalid characters contained in the source." |
|
179 |
||
180 |
^ EncodingFailedSignal |
|
181 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
182 |
"Modified: 28.6.1997 / 20:09:35 / cg" |
2833 | 183 |
"Created: 3.8.1997 / 18:16:40 / cg" |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
184 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
185 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
186 |
!CharacterArray class methodsFor:'cleanup'! |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
187 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
188 |
lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
189 |
"cleanup in low-memory situations" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
190 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
191 |
DecoderTables := EncoderTables := nil |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
192 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
193 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
194 |
CharacterArray lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
195 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
196 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
197 |
"Created: 22.2.1996 / 16:30:30 / cg" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
198 |
"Modified: 22.2.1996 / 17:58:05 / cg" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
199 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
200 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
201 |
!CharacterArray class methodsFor:'code tables'! |
443 | 202 |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
203 |
classForEncoding:encodingSymbol |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
204 |
"return a class capable of representing text encoded |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
205 |
by encodingSymbol" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
206 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
207 |
encodingSymbol == #jis ifTrue:[^ JISEncodedString]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
208 |
encodingSymbol == #big5 ifTrue:[^ BIG5EncodedString]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
209 |
encodingSymbol == #gb ifTrue:[^ GBEncodedString]. |
2734 | 210 |
encodingSymbol == #ksc ifTrue:[^ KSCEncodedString]. |
211 |
encodingSymbol == #unicode ifTrue:[^ UnicodeString]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
212 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
213 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
214 |
"/ assume its an 8-bit code |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
215 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
216 |
^ String |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
217 |
|
2734 | 218 |
"Modified: 30.6.1997 / 19:48:05 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
219 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
220 |
|
443 | 221 |
decoderTableFor:encoding |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
222 |
"return a table to decode from an alien encoding into |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
223 |
the internal (iso8859, ansi) format. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
224 |
This is an experimental interface - unfinished" |
443 | 225 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
226 |
|table unrepresentableCharacterCode x80Table| |
443 | 227 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
228 |
DecoderTables notNil ifTrue:[ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
229 |
table := DecoderTables at:encoding ifAbsent:nil. |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
230 |
table notNil ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
231 |
table == #identity ifTrue:[^ nil]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
232 |
^ table |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
233 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
234 |
] ifFalse:[ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
235 |
DecoderTables := IdentityDictionary new |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
236 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
237 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
238 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
239 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
240 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
241 |
"/ setup as identityTranslation |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
242 |
"/ |
443 | 243 |
table := (0 to:255) asByteArray. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
244 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
245 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
246 |
"/ hp -> iso8859 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
247 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
248 |
"/ hp uses a funny encoding of the A1 .. FF characters |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
249 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
250 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
251 |
encoding == #hp ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
252 |
unrepresentableCharacterCode := 16rA0. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
253 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
254 |
x80Table := |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
255 |
#( |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
256 |
16r0080 16r0081 16r0082 16r0083 16r0084 16r0085 16r0086 16r0087 "/ 80 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
257 |
16r0088 16r0089 16r008a 16r008b 16r008c 16r008d 16r008e 16r008f |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
258 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
259 |
16r0090 16r0091 16r0092 16r0093 16r0094 16r0095 16r0096 16r0097 "/ 90 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
260 |
16r0098 16r0099 16r009a 16r009b 16r009c 16r009d 16r009e 16r009f |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
261 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
262 |
16r00a0 16r00c0 16r00c2 16r00c8 16r00c9 16r00cb 16r00ce 16r00cf "/ a0 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
263 |
16r00b4 16rFFFF 16rFFFF 16r00a8 16rFFFF 16r00d9 16r00da 16r00a3 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
264 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
265 |
16rFFFF 16r00dd 16r00fd 16r00b0 16r00c7 16r00e7 16r00d1 16r00f1 "/ b0 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
266 |
16r00a1 16r00bf 16r00a4 16r00a3 16r00a5 16r00a7 16rFFFF 16rFFFF |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
267 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
268 |
16r00e2 16r00ea 16r00f4 16r00fb 16r00e1 16r00e9 16r00f3 16r00fa "/ c0 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
269 |
16r00e0 16r00e8 16r00f2 16r00f9 16r00e4 16r00eb 16r00f6 16r00fc |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
270 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
271 |
16r00c5 16r00ee 16r00d8 16r00c6 16r00e5 16r00ed 16r00f8 16r00e6 "/ d0 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
272 |
16r00c4 16r00ec 16r00d6 16r00dc 16r00c9 16r00ef 16r00df 16r00d4 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
273 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
274 |
16r00c1 16r00c3 16r00e3 16r00d0 16r00f0 16r00cd 16r00cc 16r00d3 "/ e0 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
275 |
"/ S ? s ? Y ? |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
276 |
16r00d2 16r00d5 16r00f5 16rFFFF 16rFFFF 16r00da 16rFFFF 16r00ff |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
277 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
278 |
16r00de 16r00fe 16r00b7 16r00b5 16r00b6 16r00be 16r00ad 16r00bc "/ f0 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
279 |
16r00bd 16r00aa 16r00ba 16r00ab 16rFFFF 16r00bb 16r00b1 16rFFFF |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
280 |
). |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
281 |
]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
282 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
283 |
"/ |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
284 |
"/ mac -> iso8859 |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
285 |
"/ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
286 |
"/ You will loose the following characters: |
1440
7a38f09abf92
no 8-bit chars in comments (7-bit lexes dont like that)
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
287 |
"/ - all of them will be replaced by 8F |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
288 |
"/ |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
289 |
"/ A0 (dagger) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
290 |
"/ A5 (dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
291 |
"/ AA (tm - trademark) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
292 |
"/ AD (not equal) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
293 |
"/ B0 (infinity) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
294 |
"/ B3 (less-double-equal <=) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
295 |
"/ B4 (greater-equal >-) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
296 |
"/ B6 (math lowercase delta) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
297 |
"/ B7 (math sum) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
298 |
"/ B8 (math uppercase pi) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
299 |
"/ B9 (math lowercase pi) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
300 |
"/ BA (math integral) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
301 |
"/ BD (math omega) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
302 |
"/ C3 (math union) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
303 |
"/ C4 (ext latin f) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
304 |
"/ C5 (math almost equal) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
305 |
"/ C6 (math uppercase delta) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
306 |
"/ C9 (dot-dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
307 |
"/ CE (OE ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
308 |
"/ CF (oe ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
309 |
"/ D1 (hyphen) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
310 |
"/ D2 (opening top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
311 |
"/ D3 (closing top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
312 |
"/ D4 (opening top quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
313 |
"/ D5 (closing top quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
314 |
"/ D7 (geometric: ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
315 |
"/ D9 (uppercase Y diacrit ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
316 |
"/ DA (slash2 ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
317 |
"/ DC (single oldStyle opening quote (<) ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
318 |
"/ DD (single oldStyle closing quote (>) ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
319 |
"/ DE (? ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
320 |
"/ DF (? ) |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
321 |
"/ E0 (double dagger ) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
322 |
"/ E2 (opening bottom quote ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
323 |
"/ E3 (opening bottom dquote ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
324 |
"/ F0 (? ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
325 |
"/ F5 (latin l ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
326 |
"/ F6 (diacrit circumflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
327 |
"/ F7 (diacrit tilde) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
328 |
"/ F8 (diacrit top line) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
329 |
"/ F9 (diacrit inverse circumflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
330 |
"/ FA (diacrit dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
331 |
"/ FB (diacrit ring) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
332 |
"/ FC (diacrit cedille left) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
333 |
"/ FD (diacrit dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
334 |
"/ FE (diacrit cedille right) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
335 |
"/ FF (diacrit circumflex2 ?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
336 |
"/ |
443 | 337 |
encoding == #mac ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
338 |
x80Table := |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
339 |
#( 16r00c4 16r00c5 16r00c7 16r00c9 16r00d1 16r00d6 16r00dc 16r00e1 "/ 80 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
340 |
16r00e0 16r00e2 16r00e4 16r00e3 16r00e5 16r00e7 16r00e9 16r00e8 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
341 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
342 |
16r00ea 16r00eb 16r00ed 16r00ec 16r00ee 16r00ef 16r00f1 16r00f3 "/ 90 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
343 |
16r00f2 16r00f4 16r00f6 16r00f5 16r00fa 16r00f9 16r00fb 16r00fc |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
344 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
345 |
16rFFFF 16r00b0 16r00a2 16r00a3 16r00a7 16rFFFF 16r00b6 16r00df "/ a0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
346 |
16r00ae 16r00a9 16rFFFF 16r00b4 16r00a8 16rFFFF 16r00c6 16r00d8 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
347 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
348 |
16rFFFF 16r00b1 16rFFFF 16rFFFF 16r00a5 16r00b5 16rFFFF 16rFFFF "/ b0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
349 |
16rFFFF 16rFFFF 16rFFFF 16r00aa 16r00ba 16rFFFF 16r00e6 16r00f8 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
350 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
351 |
16r00bf 16r00a1 16r00ac 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00ab "/ c0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
352 |
16r00bb 16rFFFF 16r00a0 16r00c1 16r00c3 16r00d5 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
353 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
354 |
16r00ad 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00f7 16rFFFF "/ d0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
355 |
16rFFFF 16rFFFF 16rFFFF 16r00a4 16rFFFF 16rFFFF 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
356 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
357 |
16rFFFF 16r00b7 16rFFFF 16rFFFF 16rFFFF 16r00c2 16r00ca 16r00c1 "/ e0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
358 |
16r00cb 16r00c8 16r00cd 16r00ce 16r00cf 16r00cc 16r00d3 16r00d4 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
359 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
360 |
16rFFFF 16r00d2 16r00da 16r00db 16r00d9 16rFFFF 16rFFFF 16rFFFF "/ f0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
361 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
362 |
). |
657 | 363 |
]. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
364 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
365 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
366 |
"/ next -> iso8859 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
367 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
368 |
"/ You will loose the following characters: |
1440
7a38f09abf92
no 8-bit chars in comments (7-bit lexes dont like that)
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
369 |
"/ - all of them will be replaced by 8F |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
370 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
371 |
"/ A4 (diacrit /) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
372 |
"/ A9 (diacrit quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
373 |
"/ AA (top opening dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
374 |
"/ AC (single oldStyle opening quote (<)) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
375 |
"/ AD (single oldStyle closing quote (>)) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
376 |
"/ AE (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
377 |
"/ AF (?) |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
378 |
"/ B2 (dagger) |
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
379 |
"/ B3 (double dagger) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
380 |
"/ B7 (enter dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
381 |
"/ B8 (opening bottom quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
382 |
"/ B9 (opening bottom dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
383 |
"/ BA (closing top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
384 |
"/ BC (dot-dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
385 |
"/ BD (per-mille) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
386 |
"/ C0 (subscript 1) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
387 |
"/ C1 (accent grave) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
388 |
"/ C2 (accent degu) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
389 |
"/ C3 (accent circonflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
390 |
"/ C4 (accent tilde) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
391 |
"/ C5 (accent line) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
392 |
"/ C6 (accent circonflex reverse) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
393 |
"/ C7 (accent dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
394 |
"/ C8 (accent dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
395 |
"/ D0 (hline) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
396 |
"/ E8 (engl. pound upper case L) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
397 |
"/ EA (OE ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
398 |
"/ F5 (latin l) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
399 |
"/ F8 (engl. pound lower case l) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
400 |
"/ FE (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
401 |
"/ FF (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
402 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
403 |
encoding == #next ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
404 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
405 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
406 |
x80Table := |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
407 |
#( 16r0080 16r00c0 16r00c1 16r00c2 16r00c3 16r00c4 16r00c5 16r00c7 "/ 80 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
408 |
16r00c8 16r00c9 16r00ca 16r00cb 16r00cc 16r00cd 16r00ce 16r00cf |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
409 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
410 |
16r00d0 16r00d1 16r00d2 16r00d3 16r00d4 16r00d5 16r00d6 16r00d9 "/ 90 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
411 |
16r00da 16r00db 16r00dc 16r00dd 16r00de 16r00b5 16r00d7 16r00f7 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
412 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
413 |
16r00a9 16r00a1 16r00a2 16r00a3 16rFFFF 16r00a5 16rFFFF 16r00a7 "/ a0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
414 |
16r00a4 16rFFFF 16rFFFF 16r00ab 16rFFFF 16rFFFF 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
415 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
416 |
16r00ae 16r00ad 16rFFFF 16rFFFF 16r00b7 16r00a6 16r00b6 16rFFFF "/ b0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
417 |
16rFFFF 16rFFFF 16rFFFF 16r00bb 16rFFFF 16rFFFF 16r00ac 16r00bf |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
418 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
419 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF "/ c0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
420 |
16rFFFF 16r00b2 16r00b0 16r00b8 16r00b3 16rFFFF 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
421 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
422 |
16rFFFF 16r00b1 16r00bc 16r00bd 16r00be 16r00e0 16r00e1 16r00e2 "/ d0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
423 |
16r00e3 16r00e4 16r00e5 16r00e7 16r00e8 16r00e9 16r00ea 16r00eb |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
424 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
425 |
16r00ec 16r00c6 16r00ed 16r00aa 16r00ee 16r00ef 16r00f0 16r00f1 "/ e0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
426 |
16rFFFF 16r00d8 16rFFFF 16r00ba 16r00f2 16r00f3 16r00f4 16r00f5 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
427 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
428 |
16r00f6 16r00e6 16r00f9 16r00fa 16r00fb 16rFFFF 16r00fc 16r00fd "/ f0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
429 |
16rFFFF 16r00f8 16rFFFF 16r00df 16r00fe 16r00ff 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
430 |
). |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
431 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
432 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
433 |
"/ |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
434 |
"/ msdos (codePage 437 [=US]) -> iso8859 |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
435 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
436 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
437 |
"/ You will loose the following characters: |
1440
7a38f09abf92
no 8-bit chars in comments (7-bit lexes dont like that)
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
438 |
"/ - all of them will be replaced by 8F |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
439 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
440 |
"/ 9E (pesetas) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
441 |
"/ 9F (latin f) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
442 |
"/ A9 (technical not) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
443 |
"/ B0 - BF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
444 |
"/ C0 - CF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
445 |
"/ D0 - DF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
446 |
"/ E0 (greek alpha) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
447 |
"/ E2 - E5 (greek) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
448 |
"/ E7 - EC (greek & math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
449 |
"/ EE - EF (greek & math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
450 |
"/ F0 (math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
451 |
"/ F2 - F5 (math & technical) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
452 |
"/ F7 (math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
453 |
"/ F9 (center dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
454 |
"/ FB (math sqrt) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
455 |
"/ FC (super n) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
456 |
"/ FE (block) |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
457 |
"/ |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
458 |
encoding == #msdos437 ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
459 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
460 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
461 |
x80Table := |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
462 |
#( |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
463 |
"/ Ccedil uuml eacute acirc auml agrave aring ccedil |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
464 |
16r00c7 16r00fc 16r00e9 16r00e2 16r00e4 16r00e0 16r00e5 16r00e7 "/ 80 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
465 |
"/ ecirc euml egrave iuml icirc igrave Auml Aring |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
466 |
16r00ea 16r00eb 16r00e8 16r00ef 16r00ee 16r00ec 16r00c4 16r00c5 |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
467 |
"/ Eacute ae AE ocirc ouml ograve ucirc ugrave |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
468 |
16r00c9 16r00e6 16r00c6 16r00f4 16r00f6 16r00f2 16r00fb 16r00f9 "/ 90 |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
469 |
"/ yuml Ouml Uuml cent pound Yen psetas latin-f |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
470 |
16r00ff 16r00d6 16r00dc 16r00a2 16r00a3 16r00a5 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
471 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
472 |
"/ aacute iacute oacute uacute ntilde Ntilde asup 0sup |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
473 |
16r00e1 16r00ed 16r00f3 16r00fa 16r00f1 16r00d1 16r00aa 16r00b0 "/ a0 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
474 |
"/ iquest lognot 1/2 1/4 iexcla << >> |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
475 |
16r00bf 16rFFFF 16r00ac 16r00bd 16r00bc 16r00a1 16r00ab 16r00bb |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
476 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
477 |
"/ block graphics |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
478 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF "/ b0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
479 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
480 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
481 |
"/ block graphics |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
482 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF "/ c0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
483 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
484 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
485 |
"/ block graphics |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
486 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF "/ d0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
487 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
488 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
489 |
"/ alpha beta ... mu |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
490 |
16rFFFF 16r00df 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00b5 16rFFFF "/ e0 |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
491 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00f8 16rFFFF |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
492 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
493 |
"/ plusmin gr-eq lt-eq integr integr div |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
494 |
16rFFFF 16r00b1 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00f7 16rFFFF "/ f0 |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
495 |
"/ 0sup dot dot sqr sup2 space |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
496 |
16r00b0 16rFFFF 16r00b7 16rFFFF 16rFFFF 16r00b2 16rFFFF 16r00a0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
497 |
). |
443 | 498 |
]. |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
499 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
500 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
501 |
"/ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
502 |
"/ msdos (codePage 850 [=latin1]) -> iso8859 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
503 |
"/ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
504 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
505 |
(encoding == #msdos850 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
506 |
or:[encoding == #msdos]) ifTrue:[ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
507 |
unrepresentableCharacterCode := 16rBF. |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
508 |
x80Table := |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
509 |
#( |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
510 |
"/ Ccedil uuml eacute acirc auml agrave aring ccedil |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
511 |
16r00c7 16r00fc 16r00e9 16r00e2 16r00e4 16r00e0 16r00e5 16r00e7 "/ 80 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
512 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
513 |
"/ ecirc euml egrave iuml icirc igrave Auml Aring |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
514 |
16r00ea 16r00eb 16r00e8 16r00ef 16r00ee 16r00ec 16r00c4 16r00c5 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
515 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
516 |
"/ Eacute ae AE ocirc ouml ograve ucirc ugrave |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
517 |
16r00c9 16r00e6 16r00c6 16r00f4 16r00f6 16r00f2 16r00fb 16r00f9 "/ 90 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
518 |
"/ yuml Ouml Uuml oslash pound Oslash x latin-f |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
519 |
16r00ff 16r00d6 16r00dc 16r00f8 16r00a3 16r00d8 16rFFFF 16rFFFF |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
520 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
521 |
"/ aacute iacute oacute uacute ntilde Ntilde asup 0sup |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
522 |
16r00e1 16r00ed 16r00f3 16r00fa 16r00f1 16r00d1 16r00aa 16r00da "/ a0 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
523 |
"/ iquest reg lognot 1/2 1/4 iexcla << >> |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
524 |
16r00bf 16r00ae 16r00ac 16r00bd 16r00bc 16r00a1 16r00ab 16r00bb |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
525 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
526 |
"/ Aacute Acirc Agrave |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
527 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00c1 16r00c2 16r00c0 "/ b0 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
528 |
"/ cpyr cent Yen |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
529 |
16r00a9 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00a2 16r00a5 16rFFFF |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
530 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
531 |
"/ atilde Atilde |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
532 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00e3 16r00c3 "/ c0 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
533 |
"/ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
534 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
535 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
536 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
537 |
"/ Ecirc Euml Egrave Iacute Icirc |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
538 |
16rFFFF 16rFFFF 16r00ca 16r00cb 16r00c8 16rFFFF 16r00dc 16r00ce "/ d0 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
539 |
"/ Iuml Igrave |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
540 |
16r00cf 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r007c 16r00cc 16rFFFF |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
541 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
542 |
"/ Oacute sz Ocirc Ograve otilde Otilde mu |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
543 |
16r00d3 16r00df 16r00d4 16r00d2 16rFFFF 16r00f5 16r00b5 16rFFFF "/ e0 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
544 |
"/ Uacute Ucirc Ugrav yacute Yacute ' |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
545 |
16rFFFF 16r00da 16r00db 16r00d9 16r00fd 16r00dd 16rFFFF 16r0027 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
546 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
547 |
"/ plusmin = 3/4 para sect div "/ f0 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
548 |
16rFFFF 16r00b1 16r003d 16r00be 16r00b6 16r00a7 16r00f7 16rFFFF |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
549 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
550 |
"/ sup0 sup3 sup2 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
551 |
16r00b0 16rFFFF 16rFFFF 16rFFFF 16r00b3 16r00b2 16rFFFF 16r00a0 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
552 |
). |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
553 |
]. |
443 | 554 |
"/ more encodings needed here .... |
555 |
||
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
556 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
557 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
558 |
"/ x80Table should contain the translation for |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
559 |
"/ 0x80..0xFF characters |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
560 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
561 |
x80Table isNil ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
562 |
table := #identity. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
563 |
] ifFalse:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
564 |
x80Table keysAndValuesDo:[:idx :repl | |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
565 |
|ch| |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
566 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
567 |
repl == 16rFFFF ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
568 |
ch := unrepresentableCharacterCode |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
569 |
] ifFalse:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
570 |
ch := repl |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
571 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
572 |
table at:(16r80 + idx) put:ch |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
573 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
574 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
575 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
576 |
DecoderTables at:encoding put:table. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
577 |
^ table |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
578 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
579 |
" |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
580 |
EncoderTables := nil. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
581 |
DecoderTables := nil |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
582 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
583 |
|
443 | 584 |
"Created: 20.10.1995 / 23:04:43 / cg" |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
585 |
"Modified: 1.7.1997 / 17:24:49 / cg" |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
586 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
587 |
|
2734 | 588 |
defaultRomanCharacterValue |
589 |
"return the characterValue for unmappable roman characters |
|
590 |
(only applies to jis, gb, ksc etc.)" |
|
591 |
||
592 |
|romans| |
|
593 |
||
594 |
romans := self romanTable. |
|
595 |
romans isNil ifTrue:[^ 16r20]. |
|
596 |
^ romans at:1. "/ space characters xlation |
|
597 |
||
598 |
"Created: 30.6.1997 / 18:13:24 / cg" |
|
599 |
"Modified: 30.6.1997 / 18:19:26 / cg" |
|
600 |
! |
|
601 |
||
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
602 |
encoderTableFor:encoding |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
603 |
"return a table to encode from the internal (iso8859, ansi) format |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
604 |
into an alien encoding. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
605 |
This is an experimental interface - unfinished" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
606 |
|
2751 | 607 |
|table decoderTable unrepresentableCharacterCode| |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
608 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
609 |
EncoderTables notNil ifTrue:[ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
610 |
table := EncoderTables at:encoding ifAbsent:nil. |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
611 |
table notNil ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
612 |
table == #identity ifTrue:[^ nil]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
613 |
^ table |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
614 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
615 |
] ifFalse:[ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
616 |
EncoderTables := IdentityDictionary new |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
617 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
618 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
619 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
620 |
"/ iso8859 -> hp |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
621 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
622 |
encoding == #hp ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
623 |
decoderTable := self decoderTableFor:encoding. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
624 |
unrepresentableCharacterCode := 16rFF. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
625 |
]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
626 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
627 |
"/ |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
628 |
"/ iso8859 -> mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
629 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
630 |
encoding == #mac ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
631 |
decoderTable := self decoderTableFor:encoding. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
632 |
unrepresentableCharacterCode := 16rFF. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
633 |
]. |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
634 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
635 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
636 |
"/ iso8859 -> msdos |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
637 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
638 |
encoding == #msdos ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
639 |
decoderTable := self decoderTableFor:encoding. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
640 |
unrepresentableCharacterCode := 16rFF. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
641 |
]. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
642 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
643 |
"/ more encodings needed here .... |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
644 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
645 |
decoderTable notNil ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
646 |
table := Array new:256 withAll:unrepresentableCharacterCode. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
647 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
648 |
0 to:16rFF do:[:code | |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
649 |
|isoCode destIdex| |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
650 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
651 |
isoCode := decoderTable at:(code+1). |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
652 |
table at:isoCode+1 put:code. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
653 |
] |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
654 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
655 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
656 |
table isNil ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
657 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
658 |
"/ cannot put a nil into an Id-Dict; |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
659 |
"/ use special #identity |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
660 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
661 |
table := #identity. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
662 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
663 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
664 |
EncoderTables at:encoding put:table. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
665 |
^ table |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
666 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
667 |
" |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
668 |
EncoderTables := nil. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
669 |
DecoderTables := nil. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
670 |
CharacterArray decoderTableFor:#mac |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
671 |
CharacterArray encoderTableFor:#mac |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
672 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
673 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
674 |
"Created: 22.2.1996 / 16:17:58 / cg" |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
675 |
"Modified: 1.7.1997 / 17:26:28 / cg" |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
676 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
677 |
|
2733 | 678 |
romanTable |
679 |
^ nil |
|
680 |
||
681 |
"Created: 30.6.1997 / 15:13:52 / cg" |
|
682 |
! |
|
683 |
||
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
684 |
supportedEncodings |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
685 |
"return an array containing symbolic names of supported encodings. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
686 |
These are internally visible supported ones only" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
687 |
|
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
688 |
^ self supportedExternalEncodings at:2. |
2733 | 689 |
|
690 |
"Modified: 30.6.1997 / 14:38:25 / cg" |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
691 |
! |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
692 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
693 |
supportedExternalEncodings |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
694 |
"return an array of two arrays containing the names of supported |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
695 |
encodings which are supported for external resources (i.e. files). |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
696 |
The first array contains user-readable strings (descriptions), |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
697 |
the second contains the internally used symbolic names. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
698 |
More than one external name may be mapped onto the same symbolic." |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
699 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
700 |
^ #( |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
701 |
( |
2250 | 702 |
'iso8859 (ansi)' |
703 |
'iso8859-1 (latin1)' |
|
704 |
'iso8859-2 (latin2)' |
|
705 |
'iso8859-3 (latin3)' |
|
706 |
'iso8859-4 (latin4)' |
|
707 |
'iso8859-5 (cyrillic)' |
|
708 |
'iso8859-6 (arabic)' |
|
709 |
'iso8859-7 (greek)' |
|
710 |
'iso8859-8 (hebrew)' |
|
711 |
'msdos US (codepage 437)' |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
712 |
'msdos Latin1 (codepage 850)' |
2250 | 713 |
'macintosh (8 bit)' |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
714 |
'next (8 bit)' |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
715 |
'hp (8 bit)' |
2733 | 716 |
nil |
2250 | 717 |
'EUC (extended unix code japanese)' |
718 |
'JIS7 (jis 7bit escape codes japanese)' |
|
2759 | 719 |
'ISO-2022-JP (same as jis 7bit)' |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
720 |
'SJIS (shift jis 8bit codes japanese)' |
2733 | 721 |
nil |
2250 | 722 |
'GB (mainland china)' |
723 |
'BIG5 (taiwan)' |
|
2733 | 724 |
"/ 'KSC (korean)' |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
725 |
) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
726 |
( |
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
727 |
#'iso8859' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
728 |
#'iso8859-1' "/ latin1 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
729 |
#'iso8859-2' "/ latin2 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
730 |
#'iso8859-3' "/ latin3 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
731 |
#'iso8859-4' "/ latin4 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
732 |
#'iso8859-5' "/ cyrillic |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
733 |
#'iso8859-6' "/ arabic |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
734 |
#'iso8859-7' "/ greek |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
735 |
#'iso8859-8' "/ hebrew |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
736 |
#'msdos437' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
737 |
#'msdos850' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
738 |
#'mac' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
739 |
#'next' |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
740 |
#'hp' |
2733 | 741 |
nil |
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
742 |
#'euc' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
743 |
#'jis7' |
2759 | 744 |
#'iso-2022-jp' |
2721 | 745 |
#'sjis' |
2733 | 746 |
nil |
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
747 |
#'gb' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
748 |
#'big5' |
2733 | 749 |
"/ #'ksc' "/ korean |
2250 | 750 |
) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
751 |
) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
752 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
753 |
"Created: 22.4.1996 / 14:39:39 / cg" |
2759 | 754 |
"Modified: 16.7.1997 / 13:47:16 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
755 |
! ! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
756 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
757 |
!CharacterArray class methodsFor:'encoding / decoding'! |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
758 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
759 |
decodeFromBIG5:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
760 |
"return a new string containing the characters from aString, |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
761 |
which is interpreted as a BIG5 encoded singleByte string. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
762 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
763 |
The result is a Big5EncodedString (you need a BIG5 font to display that ...)." |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
764 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
765 |
|newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
766 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
767 |
newString := BIG5EncodedString new:aString size. |
1204 | 768 |
^ self decodeFromBIG5_or_GB:aString into:newString. |
769 |
||
770 |
"Modified: 17.4.1996 / 18:58:29 / cg" |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
771 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
772 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
773 |
decodeFromBIG5_or_GB:aString into:a16BitString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
774 |
"return a new string containing the characters from aString, |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
775 |
which is interpreted as a BIG5 encoded singleByte string. |
2748 | 776 |
The result is a Big5EncodedString (you need a BIG5 font to display that ...). |
777 |
||
778 |
This is a first-class candidate for a primitive" |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
779 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
780 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
781 |
dstIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
782 |
srcIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
783 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
784 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
785 |
val "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
786 |
c| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
787 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
788 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
789 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
790 |
dstIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
791 |
srcIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
792 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
793 |
[true] whileTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
794 |
c := aString at:srcIdx. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
795 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
796 |
"/ characters below 16rA1 are left untranslated |
2733 | 797 |
"/ (romans). |
798 |
"/ Translation into roman-row is done at display time. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
799 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
800 |
b1 := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
801 |
b1 >= 16rA1 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
802 |
srcIdx := srcIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
803 |
srcIdx <= sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
804 |
b2 := (aString at:srcIdx) asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
805 |
val := (b1 bitShift:8) bitOr:b2. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
806 |
c := Character value:val. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
807 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
808 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
809 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
810 |
a16BitString at:dstIdx put:c. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
811 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
812 |
srcIdx := srcIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
813 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
814 |
srcIdx > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
815 |
^ a16BitString copyFrom:1 to:dstIdx-1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
816 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
817 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
818 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
819 |
^ a16BitString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
820 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
821 |
"Created: 17.4.1996 / 16:55:54 / cg" |
2748 | 822 |
"Modified: 4.7.1997 / 11:01:38 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
823 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
824 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
825 |
decodeFromEUC:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
826 |
"return a new string containing the characters from aString, |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
827 |
which is interpreted as an EUC encoded singleByte string. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
828 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
829 |
There are various JIS encodings around (New-JIS, Old-JIS and NEC-JIS); |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
830 |
this one only understands New-JIS. |
2748 | 831 |
The result is a JISEncodedString (you need a JIS font to display that ...). |
832 |
||
833 |
This is a first-class candidate for a primitive" |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
834 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
835 |
|newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
836 |
sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
837 |
dstIdx "{ Class: SmallInteger }" |
2750 | 838 |
srcIdx "{ Class: SmallInteger }" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
839 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
840 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
841 |
val "{ Class: SmallInteger }" |
2733 | 842 |
c c2| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
843 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
844 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
845 |
newString := JISEncodedString new:sz. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
846 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
847 |
dstIdx := 1. |
2750 | 848 |
srcIdx := 1. |
849 |
||
850 |
%{ |
|
851 |
if (__isString(aString) |
|
852 |
&& (__Class(newString) == @global(JISEncodedString))) { |
|
853 |
int _dstIdx = 1, _srcIdx = 1; |
|
854 |
int _sz = __intVal(sz); |
|
855 |
unsigned char *_cp = __stringVal(aString); |
|
856 |
unsigned char _c1; |
|
857 |
unsigned short *_jcp = (unsigned short *)__stringVal(newString); |
|
858 |
||
859 |
while (_srcIdx <= _sz) { |
|
860 |
_c1 = _cp[_srcIdx-1]; |
|
861 |
if (_c1 < 161) { |
|
862 |
_jcp[_dstIdx-1] = _c1; |
|
863 |
} else { |
|
864 |
_srcIdx++; |
|
865 |
if (_srcIdx <= _sz) { |
|
866 |
unsigned char _c2; |
|
867 |
int _val; |
|
868 |
int _b1, _b2; |
|
869 |
||
870 |
_b1 = _c1 - 128; |
|
871 |
_c2 = _cp[_srcIdx-1]; |
|
872 |
_b2 = _c2 - 128; |
|
873 |
_val = (_b1<<8) + _b2; |
|
874 |
if (_val < 0) { |
|
875 |
/* decoder errors are handled in smalltalk */ |
|
876 |
_srcIdx--; |
|
877 |
goto getOutOfHere; |
|
878 |
} |
|
879 |
_jcp[_dstIdx-1] = _val; |
|
880 |
} else { |
|
881 |
_jcp[_dstIdx-1] = _c1; |
|
882 |
} |
|
883 |
} |
|
884 |
_dstIdx++; |
|
885 |
_srcIdx++; |
|
886 |
} |
|
887 |
getOutOfHere: |
|
888 |
srcIdx = __MKSMALLINT(_srcIdx); |
|
889 |
dstIdx = __MKSMALLINT(_dstIdx); |
|
890 |
} |
|
891 |
%}. |
|
892 |
||
893 |
[srcIdx <= sz] whileTrue:[ |
|
894 |
c := aString at:srcIdx. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
895 |
b1 := c asciiValue. |
2748 | 896 |
b1 < 161 ifTrue:[ |
897 |
"/ characters below 16rA1 are left untranslated |
|
898 |
"/ (control character or roman). |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
899 |
newString at:dstIdx put:c. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
900 |
] ifFalse:[ |
2750 | 901 |
srcIdx := srcIdx + 1. |
902 |
srcIdx <= sz ifTrue:[ |
|
2748 | 903 |
b1 := b1 - 128. |
2750 | 904 |
b2 := (c2 := aString at:srcIdx) asciiValue. |
2748 | 905 |
b2 := b2 - 128. |
906 |
val := (b1 bitShift:8) bitOr:b2. |
|
907 |
val <= 0 ifTrue:[ |
|
908 |
DecodingFailedSignal |
|
909 |
raiseWith:aString |
|
910 |
errorString:'EUC decoding failed (not EUC encoded ?)'. |
|
911 |
newString at:dstIdx put:c. |
|
912 |
dstIdx := dstIdx + 1. |
|
913 |
newString at:dstIdx put:c2. |
|
914 |
] ifFalse:[ |
|
915 |
newString at:dstIdx put:(Character value:val). |
|
916 |
]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
917 |
] ifFalse:[ |
2748 | 918 |
newString at:dstIdx put:c. |
919 |
]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
920 |
]. |
2748 | 921 |
dstIdx := dstIdx + 1. |
2750 | 922 |
srcIdx := srcIdx + 1. |
923 |
]. |
|
924 |
||
925 |
(dstIdx-1) ~~ sz ifTrue:[ |
|
926 |
newString := newString copyFrom:1 to:dstIdx-1. |
|
927 |
]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
928 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
929 |
^ newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
930 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
931 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
932 |
|
2733 | 933 |
'hello' decodeFrom:#euc |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
934 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
935 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
936 |
"Created: 17.4.1996 / 16:10:22 / cg" |
2748 | 937 |
"Modified: 4.7.1997 / 11:06:05 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
938 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
939 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
940 |
decodeFromGB:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
941 |
"return a new string containing the characters from aString, |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
942 |
which is interpreted as a GB encoded singleByte string. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
943 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
944 |
The result is a Big5EncodedString (you need a GB font to display that ...)." |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
945 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
946 |
|newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
947 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
948 |
newString := GBEncodedString new:aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
949 |
^ self decodeFromBIG5_or_GB:aString into:newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
950 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
951 |
"Created: 17.4.1996 / 16:56:33 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
952 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
953 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
954 |
decodeFromJIS7:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
955 |
"return a new string containing the aStrings characters, |
2758 | 956 |
which are interpreted as a JIS7 or ISO2022-JP encoded singleByte string. |
957 |
There are various JIS encodings around (New-JIS, Old-JIS, NEC-JIS and ISO2022); |
|
958 |
this one understands New-JIS, ISO2022 and treats Old-JIS just the same. |
|
2748 | 959 |
The result is a JISEncodedString (you need a JIS font to display that ...). |
960 |
||
961 |
This is a first-class candidate for a primitive" |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
962 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
963 |
|newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
964 |
sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
965 |
dstIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
966 |
start "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
967 |
stop "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
968 |
n1 n2 n3 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
969 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
970 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
971 |
val "{ Class: SmallInteger }" |
2734 | 972 |
singleBytes katakana c| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
973 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
974 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
975 |
newString := JISEncodedString new:sz. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
976 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
977 |
dstIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
978 |
start := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
979 |
singleBytes := true. |
2734 | 980 |
katakana := false. |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
981 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
982 |
[true] whileTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
983 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
984 |
"/ scan for next escape" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
985 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
986 |
stop := aString indexOf:(Character esc) startingAt:start. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
987 |
stop == 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
988 |
stop := sz + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
989 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
990 |
(stop + 2) > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
991 |
stop := sz + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
992 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
993 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
994 |
singleBytes ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
995 |
start to:(stop - 1) do:[:i | |
2758 | 996 |
c := aString at:i. |
2734 | 997 |
newString at:dstIdx put:c. |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
998 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
999 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1000 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1001 |
start to:(stop - 2) by:2 do:[:i | |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1002 |
b1 := (aString at:i) asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1003 |
b2 := (aString at:i+1) asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1004 |
val := (b1 bitShift:8) bitOr:b2. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1005 |
newString at:dstIdx put:(Character value:val). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1006 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1007 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1008 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1009 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1010 |
stop > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1011 |
^ newString copyFrom:1 to:dstIdx - 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1012 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1013 |
start := stop. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1014 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1015 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1016 |
"/ found an escape (at start) |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1017 |
"/ - check for KI (<ESC> '$' 'B') or OLD-JIS-KI (<ESC> '$' '@') |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1018 |
"/ and KO(ASCII) (<ESC> '(' 'B') or KO(ROMAN) (<ESC> '(' 'J') |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1019 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1020 |
n1 := aString at:start. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1021 |
n2 := aString at:(start + 1). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1022 |
n3 := aString at:(start + 2). |
2734 | 1023 |
katakana := false. |
1024 |
||
1025 |
(n2 == $$ and:[n3 == $B ]) ifTrue:[ |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1026 |
singleBytes := false. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1027 |
] ifFalse:[ |
2734 | 1028 |
(n2 == $$ and:[n3 == $@ ]) ifTrue:[ |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1029 |
singleBytes := false. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1030 |
] ifFalse:[ |
2734 | 1031 |
(n2 == $( and:[n3 == $B ]) ifTrue:[ |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1032 |
singleBytes := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1033 |
] ifFalse:[ |
2734 | 1034 |
(n2 == $( and:[n3 == $J ]) ifTrue:[ |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1035 |
singleBytes := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1036 |
] ifFalse:[ |
2734 | 1037 |
(n2 == $( and:[n3 == $I ]) ifTrue:[ |
1038 |
singleBytes := true. |
|
1039 |
katakana := true. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1040 |
] ifFalse:[ |
2734 | 1041 |
singleBytes ifTrue:[ |
1042 |
newString at:dstIdx put:n1. |
|
1043 |
newString at:(dstIdx + 1) put:n2. |
|
1044 |
newString at:(dstIdx + 2) put:n3. |
|
1045 |
dstIdx := dstIdx + 3. |
|
1046 |
] ifFalse:[ |
|
1047 |
DecodingFailedSignal |
|
1048 |
raiseWith:aString |
|
1049 |
errorString:'JIS7 decoding failed (not JIS7 encoded ?)'. |
|
1050 |
newString at:dstIdx put:n1. |
|
1051 |
newString at:(dstIdx + 1) put:n2. |
|
1052 |
newString at:(dstIdx + 2) put:n3. |
|
1053 |
dstIdx := dstIdx + 3. |
|
1054 |
] |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1055 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1056 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1057 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1058 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1059 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1060 |
start := start + 3. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1061 |
start > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1062 |
^ newString copyFrom:1 to:dstIdx-1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1063 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1064 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1065 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1066 |
^ newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1067 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1068 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1069 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1070 |
'hello' decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1071 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1072 |
ending with a crippled escape: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1073 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1074 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1075 |
s := 'hello' copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1076 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1077 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1078 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1079 |
s := 'hello' copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1080 |
s := s copyWith:$A. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1081 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1082 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1083 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1084 |
s := 'hello' copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1085 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1086 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1087 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1088 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1089 |
s := 'hello' copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1090 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1091 |
s := s copyWith:$A. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1092 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1093 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1094 |
ending with a KANJI-in, but no more chars: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1095 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1096 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1097 |
s := 'hello' copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1098 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1099 |
s := s copyWith:$B. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1100 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1101 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1102 |
ending with a KANJI-in, followed by $3 (KO): |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1103 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1104 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1105 |
s := 'hello' copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1106 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1107 |
s := s copyWith:$B. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1108 |
s := s , '$3'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1109 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1110 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1111 |
ending with a KANJI-in, followed by $3$l$OF| (KO RE HA NI): |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1112 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1113 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1114 |
s := 'hello' copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1115 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1116 |
s := s copyWith:$B. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1117 |
s := s , '$3$l$OF|'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1118 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1119 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1120 |
a KO in between: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1121 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1122 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1123 |
s := 'hello' copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1124 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1125 |
s := s copyWith:$B. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1126 |
s := s , '$3'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1127 |
s := s copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1128 |
s := s copyWith:$(. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1129 |
s := s copyWith:$B. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1130 |
s := s , 'hello'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1131 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1132 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1133 |
I dont know what that means ;-): |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1134 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1135 |
|s t l| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1136 |
s := 'kterm ' copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1137 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1138 |
s := s copyWith:$B. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1139 |
s := s , '$N4A;zC<Kv%(%_%e%l!!<%?'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1140 |
s := s copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1141 |
s := s copyWith:$(. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1142 |
s := s copyWith:$B. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1143 |
s := s , ' kterm'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1144 |
t := s decodeFromJIS7. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1145 |
l := Label new. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1146 |
l label:t. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1147 |
l font:(Font family:'k14' face:nil style:nil size:nil). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1148 |
l font:(Font family:'gothic' size:17). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1149 |
l font:(Font family:'mincho' size:23). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1150 |
l realize |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1151 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1152 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1153 |
"Created: 17.4.1996 / 16:11:57 / cg" |
2758 | 1154 |
"Modified: 16.7.1997 / 12:50:55 / cg" |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1155 |
! |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1156 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1157 |
decodeFromSJIS:aString |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1158 |
"return a new string containing the aStrings characters, |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1159 |
which are interpreted as a Shift-JIS encoded singleByte string. |
2748 | 1160 |
The result is a JISEncodedString (you need a JIS font to display that ...). |
1161 |
||
1162 |
This is a first-class candidate for a primitive" |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1163 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1164 |
|newString char1 char2 |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1165 |
sz "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1166 |
dstIdx "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1167 |
srcIdx "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1168 |
b1 "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1169 |
b2 "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1170 |
val "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1171 |
| |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1172 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1173 |
sz := aString size. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1174 |
newString := JISEncodedString new:sz. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1175 |
sz ~~ 0 ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1176 |
dstIdx := 1. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1177 |
srcIdx := 1. |
2749 | 1178 |
%{ |
2757 | 1179 |
if (1 && __isString(aString) |
2749 | 1180 |
&& (__Class(newString) == @global(JISEncodedString))) { |
1181 |
int _dstIdx = 1, _srcIdx = 1; |
|
1182 |
int _sz = __intVal(sz); |
|
1183 |
unsigned char *_cp = __stringVal(aString); |
|
1184 |
unsigned char _c1, _c2; |
|
1185 |
unsigned short *_jcp = (unsigned short *)__stringVal(newString); |
|
1186 |
||
1187 |
while (_srcIdx <= _sz) { |
|
1188 |
int _val; |
|
1189 |
||
1190 |
_c1 = _cp[_srcIdx-1]; |
|
1191 |
_srcIdx++; |
|
1192 |
||
1193 |
if ((_srcIdx <= _sz) |
|
1194 |
&& (((_c1 >= 129) && (_c1 <= 159)) |
|
1195 |
|| ((_c1 >= 224) && (_c1 <= 239)))) { |
|
1196 |
_c2 = _cp[_srcIdx-1]; |
|
1197 |
_srcIdx++; |
|
1198 |
if ((_c2 >= 64) && (_c2 <= 252)) { |
|
1199 |
int _adjust, _rowOffs, _cellOffs; |
|
1200 |
int _b1, _b2; |
|
1201 |
||
1202 |
_adjust = (_c2 < 159) ? 1 : 0; |
|
1203 |
_rowOffs = (_c1 < 160) ? 112 : 176; |
|
1204 |
if (_adjust) { |
|
1205 |
_cellOffs = 31 + ((_c2 > 127) ? 1 : 0); |
|
1206 |
} else { |
|
1207 |
_cellOffs = 126; |
|
1208 |
} |
|
1209 |
_b1 = ((_c1 - _rowOffs) << 1) - _adjust; |
|
1210 |
_b2 = (_c2 - _cellOffs); |
|
1211 |
_val = (_b1<<8) + _b2; |
|
1212 |
if (_val <= 0) { |
|
1213 |
/* decoder error - let smalltalk handle that */ |
|
1214 |
_srcIdx -= 2; |
|
1215 |
goto getOutOfHere; |
|
1216 |
} |
|
1217 |
_jcp[_dstIdx-1] = _val; |
|
1218 |
} else { |
|
1219 |
/* mhmh - append untranslated */ |
|
1220 |
||
1221 |
_jcp[_dstIdx-1] = _c1; |
|
1222 |
_dstIdx++; |
|
1223 |
_jcp[_dstIdx-1] = _c2; |
|
1224 |
} |
|
1225 |
} else { |
|
1226 |
if ((_c1 >= 0xA1 /* 161 */) && (_c1 <= 0xDF /* 223 */)) { |
|
1227 |
/* HALFWIDTH KATAKANA |
|
1228 |
* map half-width katakana to 8E:xx |
|
1229 |
*/ |
|
1230 |
_val = _c1 - 128; |
|
1231 |
_val = _val + 0x8E00; |
|
1232 |
_jcp[_dstIdx-1] = _val; |
|
1233 |
} else { |
|
1234 |
/* roman characters left untranslated */ |
|
1235 |
_jcp[_dstIdx-1] = _c1; |
|
1236 |
} |
|
1237 |
} |
|
1238 |
_dstIdx++; |
|
1239 |
} |
|
1240 |
getOutOfHere: ; |
|
1241 |
dstIdx = __MKSMALLINT(_dstIdx); |
|
1242 |
srcIdx = __MKSMALLINT(_srcIdx); |
|
1243 |
} |
|
1244 |
%}. |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1245 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1246 |
[srcIdx <= sz] whileTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1247 |
"/ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1248 |
"/ scan for next character in 129..159 or 224..239 |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1249 |
"/ |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1250 |
char1 := aString at:srcIdx. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1251 |
srcIdx := srcIdx + 1. |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1252 |
b1 := char1 asciiValue. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1253 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1254 |
((srcIdx <= sz) |
2757 | 1255 |
and:[(b1 >= 129 and:[b1 <= 159]) "/ SJIS1 81 .. 9F |
1256 |
or:[b1 >= 224 and:[b1 <= 239]]]) ifTrue:[ "/ E0 .. EF |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1257 |
char2 := aString at:srcIdx. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1258 |
srcIdx := srcIdx + 1. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1259 |
b2 := char2 asciiValue. |
2757 | 1260 |
(b2 >= 64 and:[b2 <= 252]) ifTrue:[ "/ SJIS2 40 .. FC |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1261 |
|adjust rowOffs cellOffs| |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1262 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1263 |
adjust := (b2 < 159) ifTrue:[1] ifFalse:[0]. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1264 |
rowOffs := b1 < 160 ifTrue:[112] ifFalse:[176]. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1265 |
adjust == 1 ifTrue:[ |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1266 |
cellOffs := 31 + (b2 > 127 ifTrue:[1] ifFalse:[0]). |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1267 |
] ifFalse:[ |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1268 |
cellOffs := 126. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1269 |
]. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1270 |
b1 := ((b1 - rowOffs) bitShift:1) - adjust. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1271 |
b2 := (b2 - cellOffs). |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1272 |
val := (b1 bitShift:8) + b2. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1273 |
val <= 0 ifTrue:[ |
2730
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1274 |
DecodingFailedSignal |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1275 |
raiseWith:aString |
2730
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1276 |
errorString:'SJIS decoding failed (not SJIS encoded ?)'. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1277 |
newString at:dstIdx put:char1. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1278 |
dstIdx := dstIdx + 1. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1279 |
newString at:dstIdx put:char2. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1280 |
] ifFalse:[ |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1281 |
newString at:dstIdx put:(Character value:val). |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1282 |
] |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1283 |
] ifFalse:[ |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1284 |
"/ mhmh - append untranslated |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1285 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1286 |
newString at:dstIdx put:char1. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1287 |
dstIdx := dstIdx + 1. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1288 |
newString at:dstIdx put:char2. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1289 |
] |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1290 |
] ifFalse:[ |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1291 |
(b1 >= 16rA1 "161" and:[b1 <= 16rDF "223"]) ifTrue:[ "/ HALFWIDTH KATAKANA |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1292 |
"/ map half-width katakan to 8E:xx |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1293 |
val := b1 - 128. |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1294 |
val := val + (16r8E bitShift:8). |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1295 |
newString at:dstIdx put:(Character value:val). |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1296 |
] ifFalse:[ |
2733 | 1297 |
"/ roman characters left untranslated |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1298 |
newString at:dstIdx put:char1 |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1299 |
] |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1300 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1301 |
dstIdx := dstIdx + 1. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1302 |
]. |
2749 | 1303 |
(dstIdx-1) ~~ sz ifTrue:[ |
1304 |
newString := newString copyTo:dstIdx - 1. |
|
1305 |
] |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1306 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1307 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1308 |
^ newString |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1309 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1310 |
"simple: |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1311 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1312 |
'hello' decodeFrom:#sjis |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1313 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1314 |
'../../doc/online/japanese/TOP.html' asFilename contents asString |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1315 |
decodeFrom:#sjis |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1316 |
" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1317 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1318 |
"Created: 28.6.1997 / 19:19:23 / cg" |
2748 | 1319 |
"Modified: 4.7.1997 / 11:01:22 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1320 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1321 |
|
2733 | 1322 |
encodeIntoBIG5:aBIG5String |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1323 |
"return a new string with aBIG5Strings characters as BIG5 encoded 16bit string, |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1324 |
The argument must be a BIG5String. |
2733 | 1325 |
This is used translate 16bit BIG5 strings into the external BIG5 encoded |
1326 |
representation. |
|
1327 |
The resulting string is only useful to be stored on some external file, |
|
2748 | 1328 |
not for being displayed in an ST/X view. |
1329 |
||
1330 |
This is a first-class candidate for a primitive" |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1331 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1332 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1333 |
b "{ Class: SmallInteger }" |
2733 | 1334 |
c out| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1335 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1336 |
sz := aBIG5String size. |
2733 | 1337 |
out := WriteStream on:(String new:(sz * 2)). |
1338 |
||
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1339 |
1 to:sz do:[:index | |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1340 |
c := aBIG5String at:index. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1341 |
b := c asciiValue. |
1203
a43528048cb8
code tables moved to BIG5/JISEncodedString classes
Claus Gittinger <cg@exept.de>
parents:
1202
diff
changeset
|
1342 |
|
2733 | 1343 |
b > 255 ifTrue:[ |
1344 |
"/ big5 character |
|
1345 |
||
1346 |
out nextPut:(Character value:(b bitShift:-8)). |
|
1347 |
out nextPut:(Character value:(b bitAnd:16rFF)). |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1348 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1349 |
"/ |
2733 | 1350 |
"/ control or roman character |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1351 |
"/ |
2733 | 1352 |
out nextPut:c |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1353 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1354 |
]. |
2733 | 1355 |
^ out contents |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1356 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1357 |
"Created: 17.4.1996 / 17:17:50 / cg" |
2748 | 1358 |
"Modified: 4.7.1997 / 11:01:57 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1359 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1360 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1361 |
encodeIntoEUC:aJISString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1362 |
"return a new string with aJISStrings characters as EUC encoded 8bit string. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1363 |
The argument must be a JIS 16 bit character string. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1364 |
The resulting string is only useful to be stored on some external file, |
2748 | 1365 |
not for being displayed in an ST/X view. |
1366 |
||
1367 |
This is a first-class candidate for a primitive" |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1368 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1369 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1370 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1371 |
val "{ Class: SmallInteger }" |
2733 | 1372 |
c romans out| |
1373 |
||
1374 |
romans := JISEncodedString romanTable. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1375 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1376 |
sz := aJISString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1377 |
sz == 0 ifTrue:[^ '']. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1378 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1379 |
out := WriteStream on:(String new:(sz * 2)). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1380 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1381 |
1 to:sz do:[:srcIndex | |
2733 | 1382 |
b1 := (c := aJISString at:srcIndex) asciiValue. |
2748 | 1383 |
b1 < 161 ifTrue:[ |
1384 |
"/ a control or roman character |
|
2733 | 1385 |
out nextPut:c. |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1386 |
] ifFalse:[ |
2748 | 1387 |
"/ |
1388 |
"/ check for a roman character |
|
1389 |
"/ the two numbers below are romanTable min and romanTable max |
|
1390 |
"/ |
|
1391 |
(b1 between:16r2121 and:16r2573) ifTrue:[ |
|
1392 |
val := romans indexOf:b1. |
|
1393 |
(val ~~ 0 and:[val <= 127]) ifTrue:[ |
|
1394 |
out nextPut:(Character value:(val - 1 + 32)) |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1395 |
] ifFalse:[ |
2747 | 1396 |
out nextPut:(Character value:(b1 bitShift:-8) + 128). |
1397 |
out nextPut:(Character value:(b1 bitAnd:16rFF) + 128). |
|
2748 | 1398 |
]. |
1399 |
] ifFalse:[ |
|
1400 |
out nextPut:(Character value:(b1 bitShift:-8) + 128). |
|
1401 |
out nextPut:(Character value:(b1 bitAnd:16rFF) + 128). |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1402 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1403 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1404 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1405 |
^ out contents |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1406 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1407 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1408 |
|
2733 | 1409 |
('hello' decodeFrom:#euc) encodeInto:#euc |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1410 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1411 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1412 |
"Created: 17.4.1996 / 16:13:33 / cg" |
2748 | 1413 |
"Modified: 4.7.1997 / 11:03:43 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1414 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1415 |
|
2733 | 1416 |
encodeIntoGB:aGBString |
1417 |
"return a new string with aGBStrings characters as GB encoded 8bit string. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1418 |
The argument must be a GBString. |
2733 | 1419 |
This is used translate 16bit GB strings into the external GB encoded |
1420 |
representation. |
|
1421 |
The resulting string is only useful to be stored on some external file, |
|
2748 | 1422 |
not for being displayed in an ST/X view. |
1423 |
||
1424 |
This is a first-class candidate for a primitive" |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1425 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1426 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1427 |
b "{ Class: SmallInteger }" |
2733 | 1428 |
c out| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1429 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1430 |
sz := aGBString size. |
2733 | 1431 |
out := WriteStream on:(String new:(sz * 2)). |
1432 |
||
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1433 |
1 to:sz do:[:index | |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1434 |
c := aGBString at:index. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1435 |
b := c asciiValue. |
2733 | 1436 |
b > 255 ifTrue:[ |
1437 |
"/ big5 character |
|
1438 |
||
1439 |
out nextPut:(Character value:(b bitShift:-8)). |
|
1440 |
out nextPut:(Character value:(b bitAnd:16rFF)). |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1441 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1442 |
"/ |
2733 | 1443 |
"/ control or roman character |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1444 |
"/ |
2733 | 1445 |
out nextPut:c |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1446 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1447 |
]. |
2733 | 1448 |
^ out contents |
1449 |
||
1450 |
"Created: 30.6.1997 / 15:48:35 / cg" |
|
2748 | 1451 |
"Modified: 4.7.1997 / 11:02:13 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1452 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1453 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1454 |
encodeIntoJIS7:aJISString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1455 |
"return a new string with aJISStrings characters as JIS7 encoded 7bit string, |
2733 | 1456 |
The receiver must be a JIS encoded character string. |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1457 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1458 |
The resulting string is only useful to be stored on some external file, |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1459 |
not for being displayed in an ST/X view." |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1460 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1461 |
|sz "{ Class:SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1462 |
b1 "{ Class:SmallInteger }" |
2757 | 1463 |
val romans out inSingleByteMode c kanji roman val2| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1464 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1465 |
inSingleByteMode := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1466 |
kanji := JISEncodedString jis7KanjiEscapeSequence. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1467 |
roman := JISEncodedString jis7RomanEscapeSequence. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1468 |
|
2733 | 1469 |
romans := JISEncodedString romanTable. |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1470 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1471 |
sz := aJISString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1472 |
sz == 0 ifTrue:[^ '']. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1473 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1474 |
out := WriteStream on:(String new:(sz * 2)). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1475 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1476 |
1 to:sz do:[:srcIndex | |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1477 |
c := aJISString at:srcIndex. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1478 |
b1 := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1479 |
b1 < 33 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1480 |
"/ a control character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1481 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1482 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1483 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1484 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1485 |
out nextPut:c. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1486 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1487 |
"/ check for a roman character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1488 |
"/ the two numbers below are romanTable min and romanTable max |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1489 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1490 |
(b1 between:16r2121 and:16r2573) ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1491 |
val := romans indexOf:b1. |
2757 | 1492 |
val2 := val - 1 + 32. |
1493 |
(val ~~ 0 and:[val2 <= 16r7F]) ifTrue:[ |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1494 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1495 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1496 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1497 |
]. |
2757 | 1498 |
out nextPut:(Character value:val2) |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1499 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1500 |
inSingleByteMode ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1501 |
out nextPutAll:kanji. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1502 |
inSingleByteMode := false |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1503 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1504 |
out nextPut:(Character value:(b1 bitShift:-8)). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1505 |
out nextPut:(Character value:(b1 bitAnd:16rFF)). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1506 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1507 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1508 |
b1 <= 255 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1509 |
"/ mhmh - unrepresentable roman (national chars) |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1510 |
"/ b1 >= 160 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1511 |
"/ ('no rep for ' , b1 printString) printNL. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1512 |
"/ ]. |
2734 | 1513 |
EncodingFailedSignal |
1514 |
raiseWith:aJISString |
|
1515 |
errorString:'JIS7 encoding failed (contains 8-bit characters ?)'. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1516 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1517 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1518 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1519 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1520 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1521 |
out nextPut:c |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1522 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1523 |
inSingleByteMode ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1524 |
out nextPutAll:kanji. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1525 |
inSingleByteMode := false |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1526 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1527 |
out nextPut:(Character value:(b1 bitShift:-8)). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1528 |
out nextPut:(Character value:(b1 bitAnd:16rFF)). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1529 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1530 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1531 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1532 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1533 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1534 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1535 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1536 |
^ out contents |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1537 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1538 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1539 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1540 |
'hello' decodeFromJIS7 encodeIntoJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1541 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1542 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1543 |
"Created: 17.4.1996 / 16:17:40 / cg" |
2757 | 1544 |
"Modified: 16.7.1997 / 11:30:07 / cg" |
2721 | 1545 |
! |
1546 |
||
2731 | 1547 |
encodeIntoSJIS:aJISString |
1548 |
"return a new string with aJISStrings characters as SJIS encoded 8bit string. |
|
2733 | 1549 |
The receiver must be a JIS encoded character string. |
2731 | 1550 |
|
1551 |
The resulting string is only useful to be stored on some external file, |
|
1552 |
not for being displayed in an ST/X view." |
|
1553 |
||
1554 |
|sz "{ Class: SmallInteger }" |
|
1555 |
rval "{ Class: SmallInteger }" |
|
1556 |
val "{ Class: SmallInteger }" |
|
1557 |
romans c out isSJIS| |
|
1558 |
||
2733 | 1559 |
romans := JISEncodedString romanTable. |
2731 | 1560 |
|
1561 |
sz := aJISString size. |
|
1562 |
sz == 0 ifTrue:[^ '']. |
|
1563 |
||
1564 |
out := WriteStream on:(String new:(sz * 2)). |
|
1565 |
||
1566 |
1 to:sz do:[:srcIndex | |
|
1567 |
val := (c := aJISString at:srcIndex) asciiValue. |
|
2748 | 1568 |
val <= 128 ifTrue:[ |
1569 |
"/ a control or ascii character |
|
2731 | 1570 |
out nextPut:c. |
1571 |
] ifFalse:[ |
|
2748 | 1572 |
(val > 150 and:[val < 224]) ifTrue:[ |
2731 | 1573 |
"/ ascii subset |
1574 |
out nextPut:c. |
|
1575 |
] ifFalse:[ |
|
2748 | 1576 |
"/ should not happen ... |
1577 |
val <= 255 ifTrue:[ |
|
2731 | 1578 |
out nextPut:c. |
1579 |
] ifFalse:[ |
|
2748 | 1580 |
isSJIS := true. |
1581 |
||
1582 |
"/ check for HALFWIDTH KATAKANA |
|
1583 |
"/ 8E:xx |
|
2757 | 1584 |
"/ NO: halfwidth katakana no longer generated |
1585 |
"/ remains there as full-width katakana |
|
1586 |
||
1587 |
"/ (val bitAnd:16rFF00) == 16r8E00 ifTrue:[ |
|
1588 |
"/ |b| |
|
1589 |
"/ |
|
1590 |
"/ b := (val bitAnd:16rFF) + 128. |
|
1591 |
"/ (b >= 16rA1 "161" and:[b <= 16rDF "223"]) ifTrue:[ |
|
1592 |
"/ out nextPut:(Character value:b). |
|
1593 |
"/ isSJIS := false. |
|
1594 |
"/ ]. |
|
1595 |
"/ ]. |
|
2748 | 1596 |
|
1597 |
isSJIS ifTrue:[ |
|
1598 |
||
1599 |
"/ check for a roman character |
|
1600 |
"/ the two numbers below are romanTable min and romanTable max |
|
1601 |
"/ |
|
1602 |
(val between:16r2121 and:16r2573) ifTrue:[ |
|
1603 |
rval := romans indexOf:val. |
|
1604 |
rval ~~ 0 ifTrue:[ |
|
2757 | 1605 |
rval := rval - 1 + 32. |
1606 |
rval <= 16r7F ifTrue:[ "/ do not translate halfwidth katakana |
|
1607 |
out nextPut:(Character value:rval). |
|
1608 |
isSJIS := false. |
|
1609 |
] |
|
2731 | 1610 |
]. |
1611 |
]. |
|
2748 | 1612 |
]. |
1613 |
||
1614 |
isSJIS ifTrue:[ |
|
1615 |
|b1 b2 rowOffset cellOffset| |
|
1616 |
||
1617 |
b1 := (val bitShift:-8). |
|
1618 |
b2 := (val bitAnd:16rFF). |
|
1619 |
rowOffset := (b1 < 95) ifTrue:[112] ifFalse:[176]. |
|
1620 |
cellOffset := b1 odd ifTrue:[(b2 > 95) ifTrue:[32] ifFalse:[31]] |
|
1621 |
ifFalse:[126]. |
|
1622 |
||
1623 |
out nextPut:(Character value:(((b1 + 1) bitShift:-1) + rowOffset)). |
|
1624 |
out nextPut:(Character value:b2 + cellOffset). |
|
2731 | 1625 |
] |
1626 |
] |
|
1627 |
] |
|
1628 |
]. |
|
1629 |
]. |
|
1630 |
^ out contents |
|
1631 |
||
1632 |
"simple: |
|
1633 |
||
1634 |
'hello' decodeFromEUC encodeIntoEUC |
|
1635 |
" |
|
1636 |
||
1637 |
"Created: 28.6.1997 / 21:13:27 / cg" |
|
2757 | 1638 |
"Modified: 16.7.1997 / 11:30:45 / cg" |
2733 | 1639 |
! |
1640 |
||
1641 |
encodeRomans:aTwoByteString |
|
1642 |
"return a new (usually 2-byte) string with roman characters |
|
1643 |
encoded. The position of roman characters are encoding specific. |
|
1644 |
(see romanTable of concrete 16-bit string classes). |
|
1645 |
Used when displaying strings." |
|
1646 |
||
1647 |
|sz "{ Class: SmallInteger }" |
|
1648 |
b "{ Class: SmallInteger }" |
|
4294 | 1649 |
c i nCode romans newString| |
2733 | 1650 |
|
1651 |
romans := self romanTable. |
|
1652 |
romans isNil ifTrue:[^ aTwoByteString]. |
|
1653 |
||
1654 |
sz := aTwoByteString size. |
|
2734 | 1655 |
newString := self fromString:aTwoByteString. |
2733 | 1656 |
|
1657 |
1 to:sz do:[:index | |
|
1658 |
c := aTwoByteString at:index. |
|
1659 |
b := c asciiValue. |
|
1660 |
||
2735 | 1661 |
(b > 32 and:[b <= 255]) ifTrue:[ |
4294 | 1662 |
(i := b - 32 + 1) <= romans size ifTrue:[ |
2734 | 1663 |
"/ |
1664 |
"/ a roman character |
|
1665 |
"/ map to corresponding row |
|
1666 |
"/ |
|
4294 | 1667 |
nCode := romans at:i. |
2734 | 1668 |
] ifFalse:[ |
4294 | 1669 |
nCode := self defaultRomanCharacterValue |
1670 |
]. |
|
1671 |
newString at:index put:(Character value:nCode). |
|
2733 | 1672 |
]. |
1673 |
]. |
|
1674 |
^ newString |
|
1675 |
||
1676 |
"Created: 30.6.1997 / 15:43:56 / cg" |
|
2735 | 1677 |
"Modified: 30.6.1997 / 21:16:20 / cg" |
2731 | 1678 |
! |
1679 |
||
2721 | 1680 |
guessEncodingFrom:aString |
1681 |
"try to guess some 8-bit strings encoding by |
|
1682 |
searching for certain escape sequences. |
|
1683 |
Returns a string or nil. |
|
1684 |
This may not find the strings real encoding." |
|
1685 |
||
2751 | 1686 |
|idx ascii| |
2721 | 1687 |
|
1688 |
"/ look for JIS7 / EUC encoding ... |
|
1689 |
||
2733 | 1690 |
(aString findString:(JISEncodedString jisISO2022EscapeSequence)) ~~ 0 ifTrue:[ |
2760 | 1691 |
^ #'iso2020-jp' |
2733 | 1692 |
]. |
2721 | 1693 |
(aString findString:(JISEncodedString jis7KanjiEscapeSequence)) ~~ 0 ifTrue:[ |
1694 |
^ #jis7 |
|
1695 |
]. |
|
1696 |
(aString findString:(JISEncodedString oldJis7KanjiEscapeSequence)) ~~ 0 ifTrue:[ |
|
1697 |
^ #jis7 |
|
1698 |
]. |
|
1699 |
||
1700 |
"/ TODO: |
|
1701 |
||
2735 | 1702 |
"/ "/ look for EUC |
1703 |
"/ idx := aString findFirst:[:char | |ascii| |
|
1704 |
"/ ((ascii := char asciiValue) >= 16rA1) |
|
1705 |
"/ and:[ascii <= 16rFE]]. |
|
1706 |
"/ idx ~~ 0 ifTrue:[ |
|
1707 |
"/ ascii := (aString at:(idx + 1)) asciiValue. |
|
1708 |
"/ (ascii >= 16rA1 and:[ascii <= 16rFE]) ifTrue:[ |
|
1709 |
"/ ^ #euc |
|
1710 |
"/ ] |
|
1711 |
"/ ]. |
|
1712 |
||
2721 | 1713 |
"/ look for SJIS ... |
1714 |
||
1715 |
"/ look for UTS ... |
|
1716 |
||
1717 |
^ nil |
|
1718 |
||
2760 | 1719 |
"Modified: 16.7.1997 / 13:54:59 / cg" |
443 | 1720 |
! ! |
1721 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
1722 |
!CharacterArray class methodsFor:'pattern matching'! |
64 | 1723 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1724 |
matchEscapeCharacter |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1725 |
"return the character used to escape a matchCharacter |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1726 |
(i.e. make it a regular character in a matchPattern)" |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1727 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1728 |
^ $\ |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1729 |
! |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1730 |
|
327 | 1731 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop ignoreCase:ignoreCase |
1732 |
"helper for match; return true if the characters from start to stop in |
|
1733 |
aString are matching the scan in matchScan from matchStart to matchStop. |
|
328 | 1734 |
The matchScan is as created by asMatchScanArray. |
327 | 1735 |
|
328 | 1736 |
This algorithm is not at all the most efficient; |
1737 |
for heavy duty pattern matching, an interface (primitive) to the regex |
|
1738 |
pattern matching package should be added." |
|
327 | 1739 |
|
1740 |
|matchEntry |
|
1741 |
mStart "{ Class: SmallInteger }" |
|
1742 |
mStop "{ Class: SmallInteger }" |
|
1743 |
sStart "{ Class: SmallInteger }" |
|
1744 |
sStop "{ Class: SmallInteger }" |
|
1745 |
mSize "{ Class: SmallInteger }" |
|
1746 |
sSize "{ Class: SmallInteger }" |
|
1747 |
index "{ Class: SmallInteger }" |
|
2561 | 1748 |
quickCheck matchLast nextMatchEntry |
986 | 1749 |
checkChar included| |
327 | 1750 |
|
1751 |
mStart := matchStart. |
|
1752 |
mStop := matchStop. |
|
1753 |
sStart := start. |
|
1754 |
sStop := stop. |
|
1755 |
||
1756 |
[true] whileTrue:[ |
|
3537 | 1757 |
"/ Transcript showCR:('match: ''' , (aString copyFrom:sStart to:sStop) , |
1758 |
"/ ''' against:' , (matchScanArray copyFrom:mStart to:mStop) printString). |
|
1759 |
||
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1760 |
mSize := mStop - mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1761 |
sSize := sStop - sStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1762 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1763 |
"empty strings match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1764 |
(mSize == 0) ifTrue:[^ (sSize == 0)]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1765 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1766 |
matchEntry := matchScanArray at:mStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1767 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1768 |
"/ the most common case first: |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1769 |
(sSize ~~ 0 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1770 |
and:[(checkChar := (aString at:sStart)) == matchEntry]) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1771 |
"advance by one and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1772 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1773 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1774 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1775 |
(matchEntry == #any) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1776 |
"restString empty -> no match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1777 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1778 |
"# matches single character" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1779 |
((sSize == 1) and:[mSize == 1]) ifTrue:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1780 |
"advance by one and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1781 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1782 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1783 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1784 |
(matchEntry == #anyString) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1785 |
"* alone matches anything" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1786 |
(mSize == 1) ifTrue:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1787 |
"restString empty & matchString not empty -> no match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1788 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1789 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1790 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1791 |
try to avoid some of the recursion by checking last |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1792 |
character and continue with shortened strings if possible |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1793 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1794 |
quickCheck := false. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1795 |
(mStop >= mStart) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1796 |
matchLast := matchScanArray at:mStop. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1797 |
(matchLast ~~ #anyString) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1798 |
(matchLast == #any) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1799 |
quickCheck := true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1800 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1801 |
matchLast == (aString at:sStop) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1802 |
quickCheck := true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1803 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1804 |
matchLast isString ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1805 |
quickCheck := matchLast includes:(aString at:sStop) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1806 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1807 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1808 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1809 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1810 |
]. |
3537 | 1811 |
quickCheck ifTrue:[ |
1812 |
" |
|
1813 |
quickCheck ok, advance from the right |
|
1814 |
" |
|
1815 |
mStop := mStop - 1. |
|
1816 |
sStop := sStop - 1 |
|
1817 |
] ifFalse:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1818 |
"/ no quick check; |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1819 |
"/ look for the next character(s) |
3537 | 1820 |
"/ and try matching there |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1821 |
"/ (to avoid recursion) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1822 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1823 |
mStart < mStop ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1824 |
nextMatchEntry := matchScanArray at:mStart+1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1825 |
nextMatchEntry isCharacter ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1826 |
sStart <= sStop ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1827 |
[true] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1828 |
ignoreCase ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1829 |
index := aString indexOf:nextMatchEntry startingAt:sStart |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1830 |
] ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1831 |
index := aString findFirst:[:c | c asLowercase == nextMatchEntry asLowercase] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1832 |
startingAt:sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1833 |
]. |
3879 | 1834 |
(index == 0 or:[index > sStop]) ifTrue:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1835 |
^ false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1836 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1837 |
(self matchScan:matchScanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1838 |
from:(mStart + 1) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1839 |
to:mStop |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1840 |
with:aString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1841 |
from:index |
3537 | 1842 |
to:sStop |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1843 |
ignoreCase:ignoreCase |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1844 |
) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1845 |
^ true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1846 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1847 |
sStart := index + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1848 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1849 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1850 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1851 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1852 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1853 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1854 |
no quick check possible; |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1855 |
loop over all possible substrings |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1856 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1857 |
index := sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1858 |
[index <= sStop] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1859 |
(self matchScan:matchScanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1860 |
from:(mStart + 1) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1861 |
to:mStop |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1862 |
with:aString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1863 |
from:index |
3537 | 1864 |
to:sStop |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1865 |
ignoreCase:ignoreCase |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1866 |
) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1867 |
^ true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1868 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1869 |
index := index + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1870 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1871 |
^ false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1872 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1873 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1874 |
(matchEntry isString) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1875 |
"testString empty -> no match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1876 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1877 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1878 |
included := false. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1879 |
"/ checkChar := aString at:sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1880 |
included := matchEntry includes:checkChar. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1881 |
included ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1882 |
ignoreCase ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1883 |
checkChar isUppercase ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1884 |
included := matchEntry includes:checkChar asLowercase. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1885 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1886 |
included := matchEntry includes:checkChar asUppercase. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1887 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1888 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1889 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1890 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1891 |
mSize := mSize - 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1892 |
included ifFalse:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1893 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1894 |
((sSize == 1) and:[mSize == 0]) ifTrue:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1895 |
"cut off 1st char and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1896 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1897 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1898 |
"/ must be single character |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1899 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1900 |
"testString empty ?" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1901 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1902 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1903 |
"first characters equal ?" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1904 |
"/ checkChar := aString at:sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1905 |
ignoreCase ifFalse:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1906 |
(checkChar asUppercase ~~ matchEntry asUppercase) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1907 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1908 |
"advance and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1909 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1910 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1911 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1912 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1913 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1914 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1915 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1916 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1917 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1918 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1919 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1920 |
scanArray := self matchScanArrayFrom:'*hello'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1921 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1922 |
CharacterArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1923 |
matchScan:scanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1924 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1925 |
to:scanArray size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1926 |
with:s |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1927 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1928 |
to:s size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1929 |
ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1930 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1931 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1932 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1933 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1934 |
scanArray := self matchScanArrayFrom:'*hello*'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1935 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1936 |
CharacterArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1937 |
matchScan:scanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1938 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1939 |
to:scanArray size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1940 |
with:s |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1941 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1942 |
to:s size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1943 |
ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1944 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1945 |
|
3879 | 1946 |
"Modified: / 15.10.1998 / 13:39:25 / cg" |
608 | 1947 |
! |
1948 |
||
1949 |
matchScanArrayFrom:aString |
|
1950 |
"scan a pattern string and decompose it into a scanArray. |
|
1951 |
This is processed faster (especially with character ranges), and |
|
1952 |
can also be reused later. (if the same pattern is to be searched again)" |
|
1953 |
||
1954 |
|coll |
|
1955 |
idx "{ Class: SmallInteger }" |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1956 |
end c1 c2 matchSet previous escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1957 |
|
5487 | 1958 |
previous := nil. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1959 |
escape := self matchEscapeCharacter. |
608 | 1960 |
|
1961 |
coll := OrderedCollection new. |
|
1962 |
idx := 1. end := aString size. |
|
1963 |
[idx <= end] whileTrue:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1964 |
|char this| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1965 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1966 |
char := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1967 |
char == $* ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1968 |
previous ~~ #anyString ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1969 |
this := #anyString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1970 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1971 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1972 |
char == $# ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1973 |
previous ~~ #anyString ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1974 |
this := #any |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1975 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1976 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1977 |
char == $[ ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1978 |
matchSet := IdentitySet new. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1979 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1980 |
idx > end ifTrue:[^ nil]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1981 |
char := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1982 |
c1 := nil. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1983 |
[char ~~ $]] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1984 |
((char == $-) and:[c1 notNil]) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1985 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1986 |
idx > end ifTrue:[^ nil]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1987 |
c2 := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1988 |
c1 to:c2 do:[:c | matchSet add:c]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1989 |
c1 := nil. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1990 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1991 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1992 |
(char ~~ $]) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1993 |
matchSet add:char. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1994 |
c1 := char. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1995 |
idx := idx + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1996 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1997 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1998 |
idx > end ifTrue:[^ nil]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1999 |
char := aString at:idx |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2000 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2001 |
this := matchSet asString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2002 |
] ifFalse:[ |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2003 |
char == escape ifTrue:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2004 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2005 |
idx > end ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2006 |
"/ mhmh - what should we do here ? |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2007 |
this := char |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2008 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2009 |
this := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2010 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2011 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2012 |
this := char |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2013 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2014 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2015 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2016 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2017 |
this notNil ifTrue:[coll add:this. previous := this]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2018 |
idx := idx + 1 |
608 | 2019 |
]. |
2020 |
||
2021 |
^ coll asArray |
|
2022 |
||
2023 |
" |
|
2024 |
String matchScanArrayFrom:'*ute*' |
|
2025 |
String matchScanArrayFrom:'**ute**' |
|
2026 |
String matchScanArrayFrom:'*uter' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2027 |
String matchScanArrayFrom:'\*uter' |
608 | 2028 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
2029 |
String matchScanArrayFrom:'[abcd]*' |
|
2030 |
String matchScanArrayFrom:'[a-k]*' |
|
2031 |
String matchScanArrayFrom:'*some*compl*ern*' |
|
2032 |
String matchScanArrayFrom:'[a-' |
|
2033 |
String matchScanArrayFrom:'[a-zA-Z]' |
|
2034 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
|
2035 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2036 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2037 |
"Modified: 2.4.1997 / 16:20:29 / cg" |
608 | 2038 |
! ! |
2039 |
||
5301
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2040 |
!CharacterArray methodsFor:'Compatibility - Ansi'! |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2041 |
|
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2042 |
addLineDelimiters |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2043 |
^ self withCRs |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2044 |
! ! |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2045 |
|
608 | 2046 |
!CharacterArray methodsFor:'Compatibility - ST/V'! |
2047 |
||
2048 |
byteAt:index put:aByte |
|
2049 |
"store a byte at given index. |
|
2050 |
This is an ST/V compatibility method." |
|
2051 |
||
1333
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2052 |
"/ (aByte == 0) ifTrue:[ |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2053 |
"/ "store a space instead" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2054 |
"/ ^ super basicAt:index put:(Character space) |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2055 |
"/ ]. |
608 | 2056 |
^ super at:index put:(Character value:aByte) |
1333
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2057 |
|
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2058 |
" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2059 |
'hello' copy at:1 put:$H asciiValue; yourself |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2060 |
'hello' copy byteAt:1 put:72; yourself |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2061 |
'hello' copy byteAt:1 put:0; yourself |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2062 |
" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2063 |
|
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2064 |
"Modified: 6.5.1996 / 10:35:26 / cg" |
608 | 2065 |
! |
2066 |
||
2067 |
replChar:oldChar with:newChar |
|
2068 |
"return a copy of the receiver, with all oldChars replaced |
|
2069 |
by newChar. |
|
2070 |
This is an ST/V compatibility method." |
|
2071 |
||
3656 | 2072 |
^ self copyReplaceAll:oldChar with:newChar |
608 | 2073 |
|
2074 |
" |
|
2075 |
'12345678901234567890' replChar:$0 with:$* |
|
2076 |
" |
|
3656 | 2077 |
|
2078 |
"Modified: / 18.7.1998 / 22:52:57 / cg" |
|
608 | 2079 |
! |
2080 |
||
2081 |
replChar:oldChar withString:newString |
|
2082 |
"return a copy of the receiver, with all oldChars replaced |
|
2083 |
by newString (i.e. slice in the newString in place of the oldChar). |
|
2084 |
This is an ST/V compatibility method." |
|
2085 |
||
2086 |
|tmpStream| |
|
2087 |
||
2088 |
tmpStream := WriteStream on:(self class new). |
|
2089 |
self do:[:element | |
|
2090 |
element = oldChar ifTrue:[ |
|
2091 |
tmpStream nextPutAll:newString |
|
2092 |
] ifFalse:[ |
|
2093 |
tmpStream nextPut:element |
|
2094 |
]. |
|
2095 |
]. |
|
2096 |
^ tmpStream contents |
|
2097 |
||
2098 |
" |
|
2099 |
'12345678901234567890' replChar:$0 withString:'foo' |
|
2100 |
'a string with spaces' replChar:$ withString:' foo ' |
|
2101 |
" |
|
2102 |
! |
|
2103 |
||
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2104 |
replString:subString withString:newString |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2105 |
"return a copy of the receiver, with all sequences of subString replaced |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2106 |
by newString (i.e. slice in the newString in place of the oldString)." |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2107 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2108 |
|tmpStream idx idx1| |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2109 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2110 |
tmpStream := WriteStream on:(self class new). |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2111 |
idx := 1. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2112 |
[idx ~~ 0] whileTrue:[ |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2113 |
idx1 := idx. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2114 |
idx := self indexOfSubCollection:subString startingAt:idx. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2115 |
idx ~~ 0 ifTrue:[ |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2116 |
tmpStream nextPutAll:(self copyFrom:idx1 to:idx-1). |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2117 |
tmpStream nextPutAll:newString. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2118 |
idx := idx + subString size |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2119 |
] |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2120 |
]. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2121 |
tmpStream nextPutAll:(self copyFrom:idx1). |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2122 |
^ tmpStream contents |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2123 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2124 |
" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2125 |
'12345678901234567890' replString:'123' withString:'OneTwoThree' |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2126 |
'12345678901234567890' replString:'123' withString:'*' |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2127 |
'12345678901234567890' replString:'234' withString:'foo' |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2128 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2129 |
('a string with spaces' replChar:$ withString:' foo ') |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2130 |
replString:'foo' withString:'bar' |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2131 |
" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2132 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2133 |
"Modified: / 31.5.1999 / 12:33:59 / cg" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2134 |
! |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2135 |
|
608 | 2136 |
trimBlanks |
2137 |
"return a copy of the receiver without leading |
|
2138 |
and trailing spaces. |
|
2139 |
This is an ST/V compatibility method." |
|
2140 |
||
2141 |
^ self withoutSpaces |
|
2142 |
||
2143 |
" |
|
2144 |
' spaces at beginning' trimBlanks |
|
2145 |
'spaces at end ' trimBlanks |
|
2146 |
' spaces at beginning and end ' trimBlanks |
|
2147 |
'no spaces' trimBlanks |
|
2148 |
" |
|
2149 |
! ! |
|
2150 |
||
3073 | 2151 |
!CharacterArray methodsFor:'Compatibility - ST80'! |
2152 |
||
3607 | 2153 |
expandMacros |
2154 |
"ST80 compatibility - expand '<..>' macros with |
|
2155 |
argument strings. Similar to #bindWith:. |
|
2156 |
Read the comment in #expandMacrosWithArguments: about |
|
2157 |
limited compatibility issues." |
|
2158 |
||
2159 |
^ self expandMacrosWithArguments:#() |
|
2160 |
||
2161 |
" |
|
2162 |
'hello<n>foo' expandMacros |
|
2163 |
" |
|
2164 |
||
2165 |
"Modified: / 18.6.1998 / 16:03:02 / cg" |
|
2166 |
! |
|
2167 |
||
3073 | 2168 |
expandMacrosWith:arg |
2169 |
"ST80 compatibility - expand '<..>' macros with |
|
2170 |
argument strings. Similar to #bindWith:. |
|
2171 |
Read the comment in #expandMacrosWithArguments: about |
|
2172 |
limited compatibility issues." |
|
2173 |
||
2174 |
^ self expandMacrosWithArguments:(Array with:arg) |
|
2175 |
||
2176 |
"Created: / 1.11.1997 / 13:01:28 / cg" |
|
2177 |
"Modified: / 1.11.1997 / 13:30:50 / cg" |
|
2178 |
! |
|
2179 |
||
3630
dd2f2db42638
added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents:
3608
diff
changeset
|
2180 |
expandMacrosWith:arg1 with:arg2 |
dd2f2db42638
added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents:
3608
diff
changeset
|
2181 |
"ST80 compatibility - expand '<..>' macros with |
dd2f2db42638
added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents:
3608
diff
changeset
|
2182 |
argument strings. Similar to #bindWith:. |
dd2f2db42638
added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents:
3608
diff
changeset
|
2183 |
Read the comment in #expandMacrosWithArguments: about |
dd2f2db42638
added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents:
3608
diff
changeset
|
2184 |
limited compatibility issues." |
dd2f2db42638
added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents:
3608
diff
changeset
|
2185 |
|
dd2f2db42638
added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents:
3608
diff
changeset
|
2186 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2) |
dd2f2db42638
added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents:
3608
diff
changeset
|
2187 |
|
dd2f2db42638
added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents:
3608
diff
changeset
|
2188 |
"Modified: / 6.7.1998 / 21:58:14 / cg" |
dd2f2db42638
added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents:
3608
diff
changeset
|
2189 |
! |
dd2f2db42638
added #expandMacrosWith:with:
Claus Gittinger <cg@exept.de>
parents:
3608
diff
changeset
|
2190 |
|
5629
4b506fb4b723
expandMacros with 3 arguments)
Claus Gittinger <cg@exept.de>
parents:
5609
diff
changeset
|
2191 |
expandMacrosWith:arg1 with:arg2 with:arg3 |
4b506fb4b723
expandMacros with 3 arguments)
Claus Gittinger <cg@exept.de>
parents:
5609
diff
changeset
|
2192 |
"ST80 compatibility - expand '<..>' macros with |
4b506fb4b723
expandMacros with 3 arguments)
Claus Gittinger <cg@exept.de>
parents:
5609
diff
changeset
|
2193 |
argument strings. Similar to #bindWith:. |
4b506fb4b723
expandMacros with 3 arguments)
Claus Gittinger <cg@exept.de>
parents:
5609
diff
changeset
|
2194 |
Read the comment in #expandMacrosWithArguments: about |
4b506fb4b723
expandMacros with 3 arguments)
Claus Gittinger <cg@exept.de>
parents:
5609
diff
changeset
|
2195 |
limited compatibility issues." |
4b506fb4b723
expandMacros with 3 arguments)
Claus Gittinger <cg@exept.de>
parents:
5609
diff
changeset
|
2196 |
|
4b506fb4b723
expandMacros with 3 arguments)
Claus Gittinger <cg@exept.de>
parents:
5609
diff
changeset
|
2197 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2 with:arg3) |
4b506fb4b723
expandMacros with 3 arguments)
Claus Gittinger <cg@exept.de>
parents:
5609
diff
changeset
|
2198 |
! |
4b506fb4b723
expandMacros with 3 arguments)
Claus Gittinger <cg@exept.de>
parents:
5609
diff
changeset
|
2199 |
|
3073 | 2200 |
expandMacrosWithArguments:argArray |
2201 |
"ST80 compatibility - expand '<..>' macros with |
|
2202 |
argument strings. Similar to #bindWith:. |
|
2203 |
WARNING: possibly not all ST80 expansions are supported here." |
|
2204 |
||
2205 |
"/ supported expansions: |
|
2206 |
"/ |
|
5221
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2207 |
"/ <#p> # is arg Number; slice in the args printString |
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2208 |
"/ <#s> # is arg Number; slice in the arg itself (must be a String) |
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2209 |
"/ <#?s1:s2> # is arg Number; slice in s1 if the arg is true, s2 otherwise |
5301
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2210 |
"/ <s> slice in the arg |
5221
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2211 |
"/ <n> replace by a newLine character |
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2212 |
"/ <t> replace by a tab character |
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2213 |
|
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2214 |
|in out c fmt nr arg s1 s2| |
3073 | 2215 |
|
2216 |
in := self readStream. |
|
2217 |
out := '' writeStream. |
|
2218 |
||
2219 |
[in atEnd] whileFalse:[ |
|
2220 |
c := in next. |
|
2221 |
c == $< ifTrue:[ |
|
5352
61dfc2af0ab4
Support extra $< chars in macros.
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
2222 |
[in peek == $<] whileTrue:[ |
61dfc2af0ab4
Support extra $< chars in macros.
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
2223 |
out nextPut:$<. |
61dfc2af0ab4
Support extra $< chars in macros.
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
2224 |
in next. |
61dfc2af0ab4
Support extra $< chars in macros.
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
2225 |
]. |
3073 | 2226 |
in peek == $n ifTrue:[ |
2227 |
out nextPut:Character cr. |
|
2228 |
in next |
|
3608
0eab11b4b351
support for <t> in expandMacros.
Claus Gittinger <cg@exept.de>
parents:
3607
diff
changeset
|
2229 |
] ifFalse:[in peek == $t ifTrue:[ |
0eab11b4b351
support for <t> in expandMacros.
Claus Gittinger <cg@exept.de>
parents:
3607
diff
changeset
|
2230 |
out nextPut:Character tab. |
0eab11b4b351
support for <t> in expandMacros.
Claus Gittinger <cg@exept.de>
parents:
3607
diff
changeset
|
2231 |
in next |
3073 | 2232 |
] ifFalse:[ |
5301
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2233 |
in peek isDigit ifFalse:[ |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2234 |
nr := 1 |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2235 |
] ifTrue:[ |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2236 |
"/ start an argument expansion ... |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2237 |
nr := Integer readFrom:in onError:nil. |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2238 |
nr isNil ifTrue:[ |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2239 |
"/ what does VW do here ? |
5714
df1aa9dff662
removed a few halts (which are really errors)
Claus Gittinger <cg@exept.de>
parents:
5632
diff
changeset
|
2240 |
self error:'invalid format' mayProceed:true. |
5301
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2241 |
^ self |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2242 |
]. |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2243 |
(nr between:1 and:argArray size) ifFalse:[ |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2244 |
"/ what does VW do here ? |
5714
df1aa9dff662
removed a few halts (which are really errors)
Claus Gittinger <cg@exept.de>
parents:
5632
diff
changeset
|
2245 |
self error:'invalid format - bad argNr' mayProceed:true. |
5301
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2246 |
^ self |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2247 |
]. |
5221
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2248 |
]. |
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2249 |
arg := argArray at:nr. |
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2250 |
|
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2251 |
fmt := in next. |
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2252 |
(fmt == $p) ifTrue:[ |
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2253 |
"/ expand with args printString |
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2254 |
out nextPutAll:arg printString. |
5316 | 2255 |
] ifFalse:[ (fmt == $s) ifTrue:[ |
2256 |
"/ expand with arg itself |
|
2257 |
out nextPutAll:arg asString. |
|
2258 |
] ifFalse:[ (fmt == $?) ifTrue:[ |
|
2259 |
s1 := in upTo:$:. |
|
2260 |
s2 := in nextUpTo:$>. |
|
2261 |
arg ifTrue:[ |
|
2262 |
out nextPutAll:s1 |
|
5221
ebdd9dee7c1f
expandMacros: added <?...:...> support.
Claus Gittinger <cg@exept.de>
parents:
5154
diff
changeset
|
2263 |
] ifFalse:[ |
5316 | 2264 |
out nextPutAll:s2 |
2265 |
]. |
|
2266 |
] ifFalse:[ |
|
2267 |
"/ what does VW do here ? |
|
5714
df1aa9dff662
removed a few halts (which are really errors)
Claus Gittinger <cg@exept.de>
parents:
5632
diff
changeset
|
2268 |
self error:'invalid format' mayProceed:true. |
5316 | 2269 |
^ self |
2270 |
]]]. |
|
3608
0eab11b4b351
support for <t> in expandMacros.
Claus Gittinger <cg@exept.de>
parents:
3607
diff
changeset
|
2271 |
]]. |
3073 | 2272 |
c := in next. |
2273 |
c ~~ $> ifTrue:[ |
|
2274 |
"/ what does VW do here ? |
|
5714
df1aa9dff662
removed a few halts (which are really errors)
Claus Gittinger <cg@exept.de>
parents:
5632
diff
changeset
|
2275 |
self error:'invalid format' mayProceed:true. |
3073 | 2276 |
^ self |
2277 |
] |
|
2278 |
] ifFalse:[ |
|
2279 |
out nextPut:c |
|
2280 |
]. |
|
2281 |
]. |
|
2282 |
^ out contents |
|
2283 |
||
2284 |
" |
|
2285 |
'hello <1p> how are you' expandMacrosWith:(OperatingSystem getLoginName) |
|
2286 |
" |
|
2287 |
||
3608
0eab11b4b351
support for <t> in expandMacros.
Claus Gittinger <cg@exept.de>
parents:
3607
diff
changeset
|
2288 |
"Modified: / 18.6.1998 / 16:04:46 / cg" |
3073 | 2289 |
! ! |
2290 |
||
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2291 |
!CharacterArray methodsFor:'Compatibility - Squeak'! |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2292 |
|
4989 | 2293 |
capitalized |
2294 |
^ self asUppercaseFirst |
|
2295 |
||
2296 |
" |
|
2297 |
'hello' capitalized |
|
2298 |
" |
|
2299 |
! |
|
2300 |
||
5632 | 2301 |
displayProgressAt:aPointOrNil from:start to:stop during:aBlock |
2302 |
ProgressIndicator |
|
2303 |
displayProgress:self |
|
2304 |
at:aPointOrNil |
|
2305 |
from:start |
|
2306 |
to:stop |
|
2307 |
during:aBlock. |
|
2308 |
||
2309 |
" |
|
2310 |
'dobedobedoobedoo' |
|
2311 |
displayProgressAt:(Screen current center) |
|
2312 |
from:0 to:100 |
|
2313 |
during:[:val | |
|
2314 |
0 to:100 do:[:i | |
|
2315 |
val value:i. |
|
2316 |
Delay waitForSeconds:0.05. |
|
2317 |
] |
|
2318 |
] |
|
2319 |
" |
|
2320 |
! |
|
2321 |
||
4981 | 2322 |
findTokens:delimiters |
2323 |
^ self asCollectionOfSubstringsSeparatedByAny:delimiters |
|
2324 |
! |
|
2325 |
||
4974 | 2326 |
includesSubString:aString |
2327 |
"return true, if a substring is contained in the receiver. |
|
2328 |
The compare is case sensitive." |
|
2329 |
||
2330 |
^ self includesString:aString |
|
2331 |
||
2332 |
" |
|
2333 |
'hello world' includesSubString:'Hel' |
|
2334 |
'hello world' includesSubString:'hel' |
|
2335 |
'hello world' includesSubString:'llo' |
|
2336 |
" |
|
2337 |
||
2338 |
||
2339 |
||
2340 |
! |
|
2341 |
||
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2342 |
includesSubstring:aString caseSensitive:caseSensitive |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2343 |
"return true, if a substring is contained in the receiver. |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2344 |
The argument, caseSensitive controls if case is ignored in the compare." |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2345 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2346 |
"/ for now, a q&d hack ... |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2347 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2348 |
caseSensitive ifFalse:[ |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2349 |
^ self asLowercase includesString:aString asLowercase |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2350 |
]. |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2351 |
^ self includesString:aString |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2352 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2353 |
" |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2354 |
'hello world' includesSubstring:'Hel' caseSensitive:true |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2355 |
'hello world' includesSubstring:'Hel' caseSensitive:false |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2356 |
" |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2357 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2358 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2359 |
|
4890 | 2360 |
! |
2361 |
||
2362 |
lastSpacePosition |
|
2363 |
^ self lastIndexOfSeparator |
|
2364 |
! |
|
2365 |
||
2366 |
withBlanksTrimmed |
|
2367 |
"Return a copy of the receiver from which leading and trailing blanks have been trimmed." |
|
2368 |
||
2369 |
^ self withoutSpaces |
|
2370 |
||
2371 |
" |
|
2372 |
' hello world ' withBlanksTrimmed |
|
2373 |
" |
|
2374 |
||
2375 |
||
2376 |
||
2377 |
! |
|
2378 |
||
2379 |
withNoLineLongerThan: aNumber |
|
2380 |
"Answer a string with the same content as receiver, but rewrapped so that no line has more characters than the given number" |
|
2381 |
||
2382 |
| listOfLines currentLast currentStart resultString putativeLast putativeLine crPosition | |
|
2383 |
||
2384 |
aNumber isNumber not | (aNumber < 1) ifTrue: [self error: 'too narrow']. |
|
2385 |
listOfLines _ OrderedCollection new. |
|
2386 |
currentLast _ 0. |
|
2387 |
[currentLast < self size] whileTrue: |
|
2388 |
[currentStart _ currentLast + 1. |
|
2389 |
putativeLast _ (currentStart + aNumber - 1) min: self size. |
|
2390 |
putativeLine _ self copyFrom: currentStart to: putativeLast. |
|
2391 |
(crPosition _ putativeLine indexOf: Character cr) > 0 ifTrue: |
|
2392 |
[putativeLast _ currentStart + crPosition - 1. |
|
2393 |
putativeLine _ self copyFrom: currentStart to: putativeLast]. |
|
2394 |
currentLast _ putativeLast == self size |
|
2395 |
ifTrue: |
|
2396 |
[putativeLast] |
|
2397 |
ifFalse: |
|
2398 |
[currentStart + putativeLine lastSpacePosition - 1]. |
|
2399 |
currentLast <= currentStart ifTrue: |
|
2400 |
["line has NO spaces; baleout!!" |
|
2401 |
currentLast _ putativeLast]. |
|
2402 |
listOfLines add: (self copyFrom: currentStart to: currentLast) withBlanksTrimmed]. |
|
2403 |
||
2404 |
listOfLines size > 0 ifFalse: [^ '']. |
|
2405 |
resultString _ listOfLines first. |
|
2406 |
2 to: listOfLines size do: |
|
2407 |
[:i | resultString _ resultString, Character cr asString, (listOfLines at: i)]. |
|
2408 |
^ resultString |
|
2409 |
||
2410 |
" |
|
2411 |
#(5 7 20) collect: |
|
2412 |
[:i | 'Fred the bear went down to the brook to read his book in silence' withNoLineLongerThan: i] |
|
2413 |
" |
|
2414 |
||
2415 |
||
2416 |
||
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2417 |
! ! |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2418 |
|
1978 | 2419 |
!CharacterArray methodsFor:'Compatibility - V''Age'! |
608 | 2420 |
|
2421 |
addLineDelimiter |
|
2422 |
"replace all '\'-characters by line delimiter (cr) - characters. |
|
2423 |
This has been added for VisualAge compatibility." |
|
2424 |
||
2425 |
^ self withCRs |
|
2426 |
! |
|
2427 |
||
2428 |
bindWith:aString |
|
2429 |
"return a copy of the receiver, where a '%1' escape is |
|
2430 |
replaced by aString. |
|
2431 |
This has been added for VisualAge compatibility." |
|
2432 |
||
2433 |
^ self expandPlaceholdersWith:(Array with:aString) |
|
2434 |
||
2435 |
" |
|
2436 |
'do you like %1 ?' bindWith:'smalltalk' |
|
2437 |
" |
|
2438 |
! |
|
2439 |
||
2440 |
bindWith:string1 with:string2 |
|
2441 |
"return a copy of the receiver, where a '%1' escape is |
|
2442 |
replaced by string1 and '%2' is replaced by string2. |
|
2443 |
This has been added for VisualAge compatibility." |
|
2444 |
||
2445 |
^ self expandPlaceholdersWith:(Array with:string1 with:string2) |
|
2446 |
||
2447 |
" |
|
2448 |
'do you prefer %1 or rather %2 ?' |
|
2449 |
bindWith:'smalltalk' with:'c++' |
|
2450 |
" |
|
2451 |
! |
|
2452 |
||
2453 |
bindWith:str1 with:str2 with:str3 |
|
2454 |
"return a copy of the receiver, where a '%1', '%2' and '%3' escapes |
|
2455 |
are replaced by str1, str2 and str3 respectively. |
|
2456 |
This has been added for VisualAge compatibility." |
|
2457 |
||
2458 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3) |
|
2459 |
||
2460 |
" |
|
2461 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
2462 |
bindWith:'smalltalk' with:'c++' with:'c' |
|
2463 |
" |
|
2464 |
! |
|
2465 |
||
2466 |
bindWith:str1 with:str2 with:str3 with:str4 |
|
2467 |
"return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes |
|
2468 |
are replaced by str1, str2, str3 and str4 respectively. |
|
2469 |
This has been added for VisualAge compatibility." |
|
2470 |
||
2471 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4) |
|
2472 |
||
2473 |
" |
|
2474 |
'do you prefer %1 or rather %2 (not talking about %3 or even %4) ?' |
|
2475 |
bindWith:'smalltalk' with:'c++' with:'c' with:'assembler' |
|
2476 |
" |
|
2477 |
! |
|
2478 |
||
2344 | 2479 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 |
2480 |
"return a copy of the receiver, where a '%1' .. '%5' escapes |
|
2481 |
are replaced by str1 .. str5 respectively. |
|
2482 |
This has been added for VisualAge compatibility." |
|
2483 |
||
2484 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5) |
|
2485 |
||
2486 |
"Created: 31.1.1997 / 16:25:42 / cg" |
|
2487 |
! |
|
2488 |
||
5343 | 2489 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 |
2490 |
"return a copy of the receiver, where a '%1' .. '%6' escapes |
|
2491 |
are replaced by str1 .. str5 respectively. |
|
2492 |
This has been added for VisualAge compatibility." |
|
2493 |
||
2494 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
|
2495 |
with:str3 with:str4 |
|
2496 |
with:str5 with:str6) |
|
2497 |
||
2498 |
! |
|
2499 |
||
608 | 2500 |
bindWithArguments:anArrayOfStrings |
2501 |
"return a copy of the receiver, where a '%i' escape |
|
2502 |
is replaced by the coresponding string from the argument array. |
|
2503 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
2504 |
This has been added for VisualAge compatibility." |
|
2505 |
||
2506 |
^ self expandPlaceholdersWith:anArrayOfStrings |
|
2507 |
||
2508 |
" |
|
2509 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
2510 |
bindWithArguments:#('smalltalk' 'c++' 'c') |
|
2511 |
" |
|
2512 |
! |
|
2513 |
||
2514 |
subStrings |
|
2515 |
"return an array consisting of all words contained in the receiver. |
|
2516 |
Words are separated by whitespace. |
|
2517 |
This has been added for VisualAge compatibility." |
|
2518 |
||
2519 |
^ self asCollectionOfWords |
|
2520 |
||
2521 |
" |
|
2522 |
'hello world, this is smalltalk' subStrings |
|
2523 |
" |
|
2524 |
! |
|
2525 |
||
2526 |
subStrings:separatorCharacter |
|
2527 |
"return an array consisting of all words contained in the receiver. |
|
2528 |
Words are separated by separatorCharacter. |
|
2529 |
This has been added for VisualAge compatibility." |
|
2530 |
||
2531 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter |
|
2532 |
||
2533 |
" |
|
2534 |
'foo:bar:baz:smalltalk' subStrings:$: |
|
2535 |
" |
|
2536 |
! |
|
2537 |
||
2538 |
trimSeparators |
|
2539 |
"return a copy of the receiver without leading and trailing whiteSpace" |
|
2540 |
||
2541 |
^ self withoutSeparators |
|
2542 |
! ! |
|
2543 |
||
2544 |
!CharacterArray methodsFor:'character searching'! |
|
2545 |
||
2546 |
includesMatchCharacters |
|
2547 |
"return true if the receiver includes any meta characters (i.e. $* or $#) |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2548 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2549 |
Here, do not care for $\ escapes" |
608 | 2550 |
|
2551 |
^ self includesAny:'*#[' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2552 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2553 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2554 |
'*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2555 |
'\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2556 |
'\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2557 |
'*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2558 |
'\\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2559 |
'foo*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2560 |
'foo\*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2561 |
'foo\' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2562 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2563 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2564 |
"Modified: 2.4.1997 / 18:12:34 / cg" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2565 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2566 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2567 |
includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2568 |
"return true if the receiver really includes any meta characters (i.e. $* or $#) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2569 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2570 |
Here, care for $\ escapes" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2571 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2572 |
|idx sz specialChars escape| |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2573 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2574 |
idx := 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2575 |
sz := self size. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2576 |
specialChars := '*#[\'. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2577 |
(escape := self class matchEscapeCharacter) ~~ $\ ifTrue:[ |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2578 |
specialChars := specialChars copy. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2579 |
specialChars at:specialChars size put:escape |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2580 |
]. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2581 |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2582 |
[true] whileTrue:[ |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2583 |
idx := self indexOfAny:specialChars startingAt:idx. |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2584 |
idx == 0 ifTrue:[^ false]. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2585 |
(self at:idx) == escape ifFalse:[^ true]. |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2586 |
idx := idx + 2. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2587 |
idx > sz ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2588 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2589 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2590 |
" |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2591 |
'*foo' includesUnescapedMatchCharacters |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2592 |
'\*foo' includesUnescapedMatchCharacters |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2593 |
'\\foo' includesUnescapedMatchCharacters |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2594 |
'\\\$foo' includesUnescapedMatchCharacters |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2595 |
'*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2596 |
'\\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2597 |
'foo*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2598 |
'foo\*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2599 |
'foo\' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2600 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2601 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2602 |
"Modified: 2.4.1997 / 17:08:52 / cg" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2603 |
"Created: 2.4.1997 / 17:23:26 / cg" |
608 | 2604 |
! |
2605 |
||
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2606 |
indexOfControlCharacterStartingAt:startIndex |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2607 |
"return the index of the next control character; |
4117 | 2608 |
starting the search at startIndex, searching forward; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2609 |
that is a character with asciiValue < 32. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2610 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2611 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2612 |
|start "{ Class: SmallInteger }" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2613 |
mySize "{ Class: SmallInteger }"| |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2614 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2615 |
start := startIndex. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2616 |
mySize := self size. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2617 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2618 |
start to:mySize do:[:index | |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2619 |
(self at:index) isControlCharacter ifTrue:[^ index] |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2620 |
]. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2621 |
^ 0 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2622 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2623 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2624 |
'hello world' asTwoByteString indexOfControlCharacterStartingAt:1 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2625 |
'hello world\foo' withCRsasTwoByteString indexOfControlCharacterStartingAt:1 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2626 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2627 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2628 |
"Modified: / 21.7.1998 / 17:25:07 / cg" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2629 |
! |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2630 |
|
608 | 2631 |
indexOfNonSeparatorStartingAt:startIndex |
4117 | 2632 |
"return the index of the next non-whitespace character, |
2633 |
starting the search at startIndex, searching forward; |
|
2634 |
return 0 if no non-separator was found" |
|
608 | 2635 |
|
2636 |
|start "{ Class: SmallInteger }" |
|
2637 |
mySize "{ Class: SmallInteger }"| |
|
2638 |
||
2639 |
start := startIndex. |
|
2640 |
mySize := self size. |
|
2641 |
||
2642 |
start to:mySize do:[:index | |
|
4117 | 2643 |
(self at:index) isSeparator ifFalse:[^ index] |
608 | 2644 |
]. |
2645 |
^ 0 |
|
2646 |
||
2647 |
" |
|
2648 |
' hello world' indexOfNonSeparatorStartingAt:1 |
|
4117 | 2649 |
' ' indexOfNonSeparatorStartingAt:1 |
2650 |
'a ' indexOfNonSeparatorStartingAt:2 |
|
2651 |
" |
|
2652 |
||
608 | 2653 |
" |
2654 |
|s index1 index2| |
|
2655 |
s := ' foo bar baz'. |
|
2656 |
index1 := s indexOfNonSeparatorStartingAt:1. |
|
2657 |
index2 := s indexOfSeparatorStartingAt:index1. |
|
2658 |
s copyFrom:index1 to:index2 - 1 |
|
2659 |
" |
|
2660 |
! |
|
2661 |
||
2662 |
indexOfSeparator |
|
4117 | 2663 |
"return the index of the first whitespace character; |
2664 |
starting the search at the beginning, searching forward; |
|
2665 |
return 0 if no separator was found" |
|
608 | 2666 |
|
2667 |
^ self indexOfSeparatorStartingAt:1 |
|
2668 |
||
4117 | 2669 |
" |
2670 |
'hello world' indexOfSeparator |
|
2671 |
'helloworld' indexOfSeparator |
|
2672 |
'hello ' indexOfSeparator |
|
2673 |
' hello' indexOfSeparator |
|
2674 |
" |
|
608 | 2675 |
! |
2676 |
||
2677 |
indexOfSeparatorStartingAt:startIndex |
|
4117 | 2678 |
"return the index of the next whitespace character, |
2679 |
starting the search at startIndex, searching forward; |
|
2680 |
return 0 if no separator was found" |
|
608 | 2681 |
|
2682 |
|start "{ Class: SmallInteger }" |
|
2683 |
mySize "{ Class: SmallInteger }"| |
|
2684 |
||
2685 |
start := startIndex. |
|
2686 |
mySize := self size. |
|
2687 |
||
2688 |
start to:mySize do:[:index | |
|
4117 | 2689 |
(self at:index) isSeparator ifTrue:[^ index] |
608 | 2690 |
]. |
2691 |
^ 0 |
|
2692 |
||
4117 | 2693 |
" |
2694 |
'hello world' indexOfSeparatorStartingAt:3 |
|
2695 |
' hello world' indexOfSeparatorStartingAt:3 |
|
2696 |
'hello world ' indexOfSeparatorStartingAt:3 |
|
2697 |
'hello world ' indexOfSeparatorStartingAt:6 |
|
2698 |
'hello world ' indexOfSeparatorStartingAt:7 |
|
2699 |
'helloworld ' indexOfSeparatorStartingAt:7 |
|
2700 |
'helloworld' indexOfSeparatorStartingAt:7 |
|
2701 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2702 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2703 |
|
4117 | 2704 |
lastIndexOfSeparator |
2705 |
"return the last index of the whitespace character. |
|
2706 |
(i.e. start the search at the end and search backwards); |
|
2707 |
Returns 0 if no separator is found." |
|
2708 |
||
2709 |
^ self lastIndexOfSeparatorStartingAt:(self size) |
|
2710 |
||
2711 |
" |
|
2712 |
'hello world' lastIndexOfSeparator |
|
2713 |
'helloworld' lastIndexOfSeparator |
|
2714 |
'hel lo wor ld' lastIndexOfSeparator |
|
2715 |
'hel ' lastIndexOfSeparator 6 |
|
2716 |
" |
|
2717 |
! |
|
2718 |
||
2719 |
lastIndexOfSeparatorStartingAt:startIndex |
|
2720 |
"return the index of the previous whitespace character, |
|
2721 |
starting the search at startIndex (and searching backwards); |
|
2722 |
returns 0 if no separator was found" |
|
2723 |
||
5487 | 2724 |
|start "{ Class: SmallInteger }"| |
4117 | 2725 |
|
2726 |
start := startIndex. |
|
2727 |
||
2728 |
start to:1 by:-1 do:[:index | |
|
2729 |
(self at:index) isSeparator ifTrue:[^ index] |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2730 |
]. |
4117 | 2731 |
^ 0 |
2732 |
||
2733 |
" |
|
2734 |
'hello world' lastIndexOfSeparatorStartingAt:3 |
|
2735 |
'hello world' lastIndexOfSeparatorStartingAt:7 |
|
2736 |
'helloworld' lastIndexOfSeparatorStartingAt:7 |
|
2737 |
' helloworld' lastIndexOfSeparatorStartingAt:7 |
|
2738 |
" |
|
608 | 2739 |
! ! |
2740 |
||
2741 |
!CharacterArray methodsFor:'comparing'! |
|
2742 |
||
2743 |
< something |
|
2744 |
"Compare the receiver with the argument and return true if the |
|
1252 | 2745 |
receiver is less than the argument. Otherwise return false. |
2746 |
This comparison is based on the elements ascii code - |
|
2747 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 2748 |
|
2749 |
^ (something > self) |
|
1252 | 2750 |
|
2751 |
"Modified: 22.4.1996 / 15:54:54 / cg" |
|
608 | 2752 |
! |
2753 |
||
2754 |
<= something |
|
2755 |
"Compare the receiver with the argument and return true if the |
|
1252 | 2756 |
receiver is less than or equal to the argument. Otherwise return false. |
2757 |
This comparison is based on the elements ascii code - |
|
2758 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 2759 |
|
2760 |
^ (self > something) not |
|
1252 | 2761 |
|
2762 |
"Modified: 22.4.1996 / 15:54:56 / cg" |
|
608 | 2763 |
! |
2764 |
||
2765 |
= aString |
|
2766 |
"Compare the receiver with the argument and return true if the |
|
2767 |
receiver is equal to the argument. Otherwise return false. |
|
1252 | 2768 |
|
608 | 2769 |
This compare does NOT ignore case differences, |
2770 |
therefore 'foo' = 'Foo' will return false. |
|
2771 |
Since this is incompatible to ST-80 (at least, V2.x) , this may change." |
|
2772 |
||
2773 |
|mySize "{ Class: SmallInteger }" |
|
2774 |
otherSize | |
|
2775 |
||
2776 |
aString species == self species ifFalse:[^ false]. |
|
2777 |
mySize := self size. |
|
2778 |
otherSize := aString size. |
|
2779 |
mySize == otherSize ifFalse:[^ false]. |
|
2780 |
||
2781 |
1 to:mySize do:[:index | |
|
1252 | 2782 |
(self at:index) = (aString at:index) ifFalse:[^ false]. |
608 | 2783 |
]. |
2784 |
^ true |
|
2785 |
||
2786 |
" |
|
2787 |
'foo' = 'Foo' |
|
2788 |
'foo' = 'bar' |
|
2789 |
'foo' = 'foo' |
|
2790 |
" |
|
1252 | 2791 |
|
2792 |
"Modified: 22.4.1996 / 15:53:58 / cg" |
|
608 | 2793 |
! |
2794 |
||
2795 |
> aString |
|
2796 |
"Compare the receiver with the argument and return true if the |
|
2797 |
receiver is greater than the argument. Otherwise return false. |
|
1252 | 2798 |
This comparison is based on the elements ascii code - |
2799 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
|
608 | 2800 |
|
2801 |
|mySize "{ Class: SmallInteger }" |
|
2802 |
otherSize "{ Class: SmallInteger }" |
|
2803 |
n "{ Class: SmallInteger }" |
|
2804 |
c1 c2| |
|
2805 |
||
2806 |
mySize := self size. |
|
2807 |
otherSize := aString size. |
|
2808 |
n := mySize min:otherSize. |
|
2809 |
||
2810 |
1 to:n do:[:index | |
|
1252 | 2811 |
c1 := self at:index. |
2812 |
c2 := aString at:index. |
|
2813 |
c1 > c2 ifTrue:[^ true]. |
|
2814 |
c1 < c2 ifTrue:[^ false]. |
|
608 | 2815 |
]. |
2816 |
^ mySize > otherSize |
|
1252 | 2817 |
|
2818 |
"Modified: 22.4.1996 / 15:55:00 / cg" |
|
608 | 2819 |
! |
2820 |
||
2821 |
>= something |
|
2822 |
"Compare the receiver with the argument and return true if the |
|
2823 |
receiver is greater than or equal to the argument. |
|
1252 | 2824 |
Otherwise return false. |
2825 |
This comparison is based on the elements ascii code - |
|
2826 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 2827 |
|
2828 |
^ (something > self) not |
|
1252 | 2829 |
|
2830 |
"Modified: 22.4.1996 / 15:55:03 / cg" |
|
608 | 2831 |
! |
2832 |
||
2833 |
compareWith:aString |
|
2834 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2835 |
greater, 0 if equal and -1 if less than the argument. |
|
1252 | 2836 |
This comparison is based on the elements ascii code - |
2837 |
i.e. upper/lowercase & national characters are NOT treated specially. |
|
2838 |
'foo' compareWith: 'Foo' will return 1. |
|
2839 |
while 'foo' sameAs:'Foo' will return true" |
|
608 | 2840 |
|
2841 |
|mySize "{ Class: SmallInteger }" |
|
2842 |
otherSize "{ Class: SmallInteger }" |
|
2843 |
n "{ Class: SmallInteger }" |
|
2844 |
c1 c2| |
|
2845 |
||
2846 |
mySize := self size. |
|
2847 |
otherSize := aString size. |
|
2848 |
n := mySize min:otherSize. |
|
2849 |
||
2850 |
1 to:n do:[:index | |
|
1252 | 2851 |
c1 := self at:index. |
2852 |
c2 := aString at:index. |
|
2853 |
c1 > c2 ifTrue:[^ 1]. |
|
2854 |
c1 < c2 ifTrue:[^ -1]. |
|
608 | 2855 |
]. |
2856 |
mySize > otherSize ifTrue:[^ 1]. |
|
2857 |
mySize < otherSize ifTrue:[^ -1]. |
|
2858 |
^ 0 |
|
1252 | 2859 |
|
2860 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
608 | 2861 |
! |
2862 |
||
2863 |
hash |
|
2864 |
"return an integer useful as a hash-key" |
|
2865 |
||
2866 |
%{ /* NOCONTEXT */ |
|
2867 |
||
3985 | 2868 |
REGISTER unsigned g, val; |
608 | 2869 |
REGISTER unsigned char *cp, *cp0; |
2870 |
int l; |
|
2871 |
||
1133 | 2872 |
cp = __stringVal(self); |
2873 |
l = __stringSize(self); |
|
3987 | 2874 |
if (__qClass(self) != @global(String)) { |
3985 | 2875 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
2876 |
||
2877 |
cp += n; |
|
2878 |
l -= n; |
|
608 | 2879 |
} |
2880 |
||
2881 |
/* |
|
3985 | 2882 |
* this is the dragon-book algorithm |
608 | 2883 |
*/ |
3985 | 2884 |
|
2885 |
val = 0; |
|
2886 |
switch (l) { |
|
2887 |
default: |
|
2888 |
for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) { |
|
2889 |
val = (val << 4) + *cp; |
|
2890 |
if (g = (val & 0xF0000000)) { |
|
2891 |
val ^= g >> 24; |
|
2892 |
val ^= g; |
|
2893 |
} |
|
2894 |
} |
|
2895 |
break; |
|
2896 |
case 7: |
|
2897 |
val = cp[6] << 4; |
|
2898 |
case 6: |
|
2899 |
val = (val + cp[5]) << 4; |
|
2900 |
case 5: |
|
2901 |
val = (val + cp[4]) << 4; |
|
2902 |
case 4: |
|
2903 |
val = (val + cp[3]) << 4; |
|
2904 |
case 3: |
|
2905 |
val = (val + cp[2]) << 4; |
|
2906 |
case 2: |
|
2907 |
val = (val + cp[1]) << 4; |
|
2908 |
case 1: |
|
2909 |
val = val + cp[0]; |
|
2910 |
case 0: |
|
2911 |
break; |
|
608 | 2912 |
} |
2913 |
||
3985 | 2914 |
/* |
2915 |
* multiply by large prime to spread values |
|
2916 |
* This speeds up Set and Dictionary by a factor of 10! |
|
2917 |
*/ |
|
2918 |
val *= 31415821; |
|
2919 |
RETURN ( __MKSMALLINT(val & 0x3fffffff)); |
|
608 | 2920 |
%} |
3985 | 2921 |
|
608 | 2922 |
! |
2923 |
||
2924 |
sameAs:aString |
|
2925 |
"Compare the receiver with the argument like =, but ignore |
|
1252 | 2926 |
case differences. |
2927 |
Return true or false." |
|
608 | 2928 |
|
2929 |
|mySize "{ Class: SmallInteger }" |
|
2930 |
otherSize c1 c2| |
|
2931 |
||
3195
0a1a7a4c6184
oops- sameAs returned self instead of true
Claus Gittinger <cg@exept.de>
parents:
3073
diff
changeset
|
2932 |
self == aString ifTrue:[^ true]. |
2581
d06e3bbfc294
faster #sameAs: if string is identical
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
2933 |
|
608 | 2934 |
mySize := self size. |
2935 |
otherSize := aString size. |
|
2936 |
mySize == otherSize ifFalse:[^ false]. |
|
2937 |
||
2938 |
1 to:mySize do:[:index | |
|
1252 | 2939 |
c1 := self at:index. |
2940 |
c2 := aString at:index. |
|
2941 |
c1 == c2 ifFalse:[ |
|
2942 |
c1 asLowercase = c2 asLowercase ifFalse:[^ false]. |
|
2943 |
] |
|
608 | 2944 |
]. |
2945 |
^ true |
|
2946 |
||
2947 |
" |
|
2948 |
'foo' sameAs: 'Foo' |
|
2949 |
'foo' sameAs: 'bar' |
|
2950 |
'foo' sameAs: 'foo' |
|
2951 |
" |
|
1252 | 2952 |
|
2953 |
"Modified: 22.4.1996 / 15:56:17 / cg" |
|
608 | 2954 |
! |
2955 |
||
5242 | 2956 |
sameAs:aString ignoreCase:ignoreCase |
2957 |
"Compare the receiver with the argument. |
|
2958 |
If ignoreCase is true, this is the same as #sameAs:, |
|
2959 |
if false, this is the same as #=." |
|
2960 |
||
2961 |
ignoreCase ifTrue:[ |
|
2962 |
^ self sameAs:aString |
|
2963 |
]. |
|
2964 |
^ self = aString |
|
2965 |
||
2966 |
" |
|
2967 |
'foo' sameAs:'Foo' ignoreCase:false |
|
2968 |
'foo' sameAs:'foo' ignoreCase:true |
|
2969 |
" |
|
2970 |
||
2971 |
! |
|
2972 |
||
608 | 2973 |
sameCharacters:aString |
2974 |
"count & return the number of characters which are the same |
|
2975 |
(ignoring case) in the receiver and the argument, aString." |
|
2976 |
||
2977 |
|n "{ Class: SmallInteger }" |
|
986 | 2978 |
c1 c2 cnt| |
608 | 2979 |
|
2980 |
n := self size. |
|
2981 |
n := n min:(aString size). |
|
2982 |
||
2983 |
cnt := 0. |
|
2984 |
1 to:n do:[:index | |
|
2985 |
c1 := self at:index. |
|
2986 |
c2 := aString at:index. |
|
2987 |
((c1 == c2) |
|
2988 |
or:[c1 asLowercase = c2 asLowercase]) ifTrue:[ |
|
2989 |
cnt := cnt + 1 |
|
2990 |
] |
|
2991 |
]. |
|
2992 |
^ cnt |
|
2993 |
||
2994 |
" |
|
2995 |
'foobarbaz' sameCharacters: 'foo' |
|
2996 |
'foobarbaz' sameCharacters: 'Foo' |
|
2997 |
'foobarbaz' sameCharacters: 'baz' |
|
2998 |
" |
|
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
2999 |
! |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3000 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3001 |
sameEmphasisAs:aStringOrText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3002 |
"compare the receivers and the arguments emphasis" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3003 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3004 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3005 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3006 |
" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3007 |
'hello' asText sameEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3008 |
'hello' asText sameEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3009 |
'hello' asText allBold sameEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3010 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3011 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3012 |
" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3013 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3014 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3015 |
! |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3016 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3017 |
sameStringAndEmphasisAs:aStringOrText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3018 |
"compare the receivers and the arguments emphasis and string" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3019 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3020 |
aStringOrText isString ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3021 |
(self string = aStringOrText string) ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3022 |
self hasChangeOfEmphasis = aStringOrText hasChangeOfEmphasis ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3023 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3024 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3025 |
" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3026 |
'hello' asText sameEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3027 |
'hello' asText sameEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3028 |
'hello' asText allBold sameEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3029 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3030 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3031 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3032 |
'hello' sameEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3033 |
'hello' sameEmphasisAs: 'hello' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3034 |
'hello' sameEmphasisAs: 'fooba' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3035 |
'hello' sameEmphasisAs: 'fooba' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3036 |
'hello' sameEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3037 |
'hello' sameEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3038 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3039 |
'hello' asText sameStringAndEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3040 |
'hello' asText sameStringAndEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3041 |
'hello' asText allBold sameStringAndEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3042 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3043 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3044 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3045 |
'hello' sameStringAndEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3046 |
'hello' sameStringAndEmphasisAs: 'hello' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3047 |
'hello' sameStringAndEmphasisAs: 'fooba' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3048 |
'hello' sameStringAndEmphasisAs: 'fooba' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3049 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3050 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3051 |
" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3052 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3053 |
|
608 | 3054 |
! ! |
3055 |
||
3056 |
!CharacterArray methodsFor:'converting'! |
|
3057 |
||
3058 |
asArrayOfSubstrings |
|
3059 |
"return an array of substrings from the receiver, interpreting |
|
3060 |
separators (i.e. spaces & newlines) as word-delimiters. |
|
3061 |
This is a compatibility method - the actual work is done in |
|
3062 |
asCollectionOfWords." |
|
3063 |
||
3064 |
^ self asCollectionOfWords asArray |
|
3065 |
||
3066 |
" |
|
3067 |
'1 one two three four 5 five' asArrayOfSubstrings |
|
3068 |
" |
|
3069 |
! |
|
3070 |
||
3071 |
asCollectionOfLines |
|
3072 |
"return a collection containing the lines (separated by cr) |
|
3073 |
of the receiver. If multiple cr's occur in a row, the result will |
|
3074 |
contain empty strings." |
|
3075 |
||
3076 |
^ self asCollectionOfSubstringsSeparatedBy:Character cr |
|
3077 |
||
3078 |
" |
|
3079 |
'1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines |
|
3080 |
'1 one\\\\2 two\3 three' withCRs asCollectionOfLines |
|
3081 |
" |
|
3082 |
! |
|
3083 |
||
3084 |
asCollectionOfSubstringsSeparatedBy:aCharacter |
|
3085 |
"return a collection containing the lines (separated by aCharacter) |
|
3086 |
of the receiver. If aCharacter occurs multiple times in a row, |
|
3087 |
the result will contain empty strings." |
|
3088 |
||
3089 |
|lines myClass |
|
3090 |
numberOfLines "{ Class:SmallInteger }" |
|
3091 |
startIndex "{ Class:SmallInteger }" |
|
3092 |
stopIndex "{ Class:SmallInteger }" | |
|
3093 |
||
3094 |
" |
|
3095 |
count first, to avoid regrowing of the OC |
|
3096 |
" |
|
3097 |
numberOfLines := (self occurrencesOf:aCharacter) + 1. |
|
3098 |
lines := OrderedCollection new:numberOfLines. |
|
3099 |
myClass := self species. |
|
3100 |
||
3101 |
startIndex := 1. |
|
3102 |
1 to:numberOfLines do:[:lineNr | |
|
3103 |
stopIndex := self indexOf:aCharacter startingAt:startIndex. |
|
3104 |
stopIndex == 0 ifTrue:[ |
|
3105 |
stopIndex := self size |
|
3106 |
] ifFalse: [ |
|
3107 |
stopIndex := stopIndex - 1. |
|
3108 |
]. |
|
3109 |
||
3110 |
(stopIndex < startIndex) ifTrue: [ |
|
3111 |
lines add:(myClass new:0) |
|
3112 |
] ifFalse: [ |
|
3113 |
lines add:(self copyFrom:startIndex to:stopIndex) |
|
3114 |
]. |
|
3115 |
startIndex := stopIndex + 2 |
|
3116 |
]. |
|
3117 |
^ lines |
|
3118 |
||
3119 |
" |
|
3120 |
'1 one:2 two:3 three:4 four:5 five' withCRs asCollectionOfSubstringsSeparatedBy:$: |
|
3121 |
'1 one 2 two 3 three 4 four 5 five' withCRs asCollectionOfSubstringsSeparatedBy:Character space |
|
3122 |
" |
|
3123 |
! |
|
3124 |
||
3125 |
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators |
|
3126 |
"return a collection containing the words (separated by any character |
|
3127 |
from aCollectionOfSeparators) of the receiver. |
|
3128 |
This allows breaking up strings using any character as separator." |
|
3129 |
||
3130 |
|words |
|
3131 |
start "{ Class:SmallInteger }" |
|
3132 |
stop "{ Class:SmallInteger }" |
|
3133 |
mySize "{ Class:SmallInteger }"| |
|
3134 |
||
3135 |
words := OrderedCollection new. |
|
3136 |
start := 1. |
|
3137 |
mySize := self size. |
|
3138 |
[start <= mySize] whileTrue:[ |
|
3139 |
"skip multiple separators" |
|
3140 |
[aCollectionOfSeparators includes:(self at:start)] whileTrue:[ |
|
3141 |
start := start + 1 . |
|
3142 |
start > mySize ifTrue:[ |
|
3143 |
^ words |
|
3144 |
]. |
|
3145 |
]. |
|
3146 |
||
3147 |
stop := self indexOfAny:aCollectionOfSeparators startingAt:start. |
|
3148 |
stop == 0 ifTrue:[ |
|
3149 |
words add:(self copyFrom:start to:mySize). |
|
3150 |
^ words |
|
3151 |
]. |
|
3152 |
words add:(self copyFrom:start to:(stop - 1)). |
|
3153 |
start := stop |
|
3154 |
]. |
|
3155 |
^ words |
|
3156 |
||
3157 |
" |
|
3158 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:) |
|
3159 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' |
|
3160 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) |
|
3161 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' |
|
3162 |
'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) |
|
3163 |
" |
|
3164 |
! |
|
3165 |
||
3166 |
asCollectionOfWords |
|
3167 |
"return a collection containing the words (separated by whitespace) |
|
3168 |
of the receiver. Multiple occurences of whitespace characters will |
|
3169 |
be treated like one - i.e. whitespace is skipped." |
|
3170 |
||
3171 |
|words |
|
3172 |
start "{ Class:SmallInteger }" |
|
3173 |
stop "{ Class:SmallInteger }" |
|
3174 |
mySize "{ Class:SmallInteger }"| |
|
3175 |
||
3176 |
words := OrderedCollection new. |
|
3177 |
start := 1. |
|
3178 |
mySize := self size. |
|
3179 |
[start <= mySize] whileTrue:[ |
|
3180 |
start := self indexOfNonSeparatorStartingAt:start. |
|
3181 |
start == 0 ifTrue:[ |
|
3182 |
^ words |
|
3183 |
]. |
|
3184 |
stop := self indexOfSeparatorStartingAt:start. |
|
3185 |
stop == 0 ifTrue:[ |
|
3186 |
words add:(self copyFrom:start to:mySize). |
|
3187 |
^ words |
|
3188 |
]. |
|
3189 |
words add:(self copyFrom:start to:(stop - 1)). |
|
3190 |
start := stop |
|
3191 |
]. |
|
3192 |
^ words |
|
3193 |
||
3194 |
" |
|
3195 |
'hello world isnt this nice' asCollectionOfWords |
|
3196 |
' hello world isnt this nice ' asCollectionOfWords |
|
3197 |
'hello' asCollectionOfWords |
|
3198 |
'' asCollectionOfWords |
|
3199 |
' ' asCollectionOfWords |
|
3200 |
" |
|
3201 |
! |
|
3202 |
||
3203 |
asComposedText |
|
1312 | 3204 |
"ST-80 compatibility |
3205 |
- ST/X does not (as today) support composedTexts." |
|
3206 |
||
608 | 3207 |
^ ComposedText fromString:self |
1312 | 3208 |
|
3209 |
"Modified: 27.4.1996 / 13:30:30 / cg" |
|
608 | 3210 |
! |
3211 |
||
3212 |
asFilename |
|
3213 |
"return a Filename with pathname taken from the receiver" |
|
3214 |
||
1423 | 3215 |
^ Filename named:self string |
3216 |
||
3217 |
"Modified: 20.5.1996 / 09:38:15 / cg" |
|
608 | 3218 |
! |
3219 |
||
3060 | 3220 |
asFixedPoint |
3221 |
"read a fixedPoint number from the receiver. |
|
3222 |
Notice, that errors may occur during the read, so you better |
|
3223 |
setup some signal handler when using this method." |
|
3224 |
||
3225 |
^ FixedPoint readFromString:self |
|
3226 |
||
3227 |
" |
|
3228 |
'0.123' asFixedPoint |
|
3229 |
'12345' asFixedPoint |
|
3230 |
'(1/5)' asFixedPoint |
|
3231 |
'foo' asFixedPoint |
|
3232 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asFixedPoint] |
|
3233 |
" |
|
3234 |
||
3235 |
"Modified: / 25.10.1997 / 15:19:00 / cg" |
|
3236 |
! |
|
3237 |
||
3238 |
asFixedPoint:scale |
|
3239 |
"read a fixedPoint number with scale number of post-decimal digits |
|
3240 |
from the receiver. Scale controls the number of displayed digits, |
|
3241 |
not the number of actually valid digits. |
|
3242 |
Notice, that errors may occur during the read, so you better |
|
3243 |
setup some signal handler when using this method." |
|
3244 |
||
3245 |
^ (FixedPoint readFromString:self) scale:scale |
|
3246 |
||
3247 |
" |
|
3248 |
'0.123' asFixedPoint:2 |
|
3249 |
'123456' asFixedPoint:2 |
|
3250 |
('3.14157' asFixedPoint:1) asFixedPoint:5 |
|
3251 |
" |
|
3252 |
||
3253 |
"Modified: / 25.10.1997 / 15:21:57 / cg" |
|
3254 |
! |
|
3255 |
||
608 | 3256 |
asFloat |
3257 |
"read a float number from the receiver. |
|
3258 |
Notice, that errors may occur during the read, so you better |
|
3259 |
setup some signal handler when using this method." |
|
3260 |
||
3261 |
^ (Number readFromString:self) asFloat |
|
3262 |
||
3263 |
" |
|
3264 |
'0.123' asFloat |
|
3265 |
'12345' asFloat |
|
3266 |
'(1/5)' asFloat |
|
3267 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asFloat] |
|
3268 |
" |
|
3269 |
! |
|
3270 |
||
3271 |
asInteger |
|
3272 |
"read an integer from the receiver. |
|
3273 |
Notice, that errors may occur during the read, so you better |
|
3274 |
setup some signal handler when using this method." |
|
3275 |
||
3276 |
^ Integer readFromString:self |
|
3277 |
||
3278 |
" |
|
3279 |
'12345678901234567890' asInteger |
|
3280 |
'-1234' asInteger |
|
3281 |
'0.123' asInteger <- reader stops at ., returning 0 here |
|
3282 |
'0.123' asNumber <- returns what you expect |
|
3283 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asInteger] |
|
3284 |
" |
|
3285 |
! |
|
3286 |
||
3287 |
asLowercase |
|
3288 |
"return a copy of myself in lowercase letters" |
|
3289 |
||
3290 |
|newStr |
|
3291 |
mySize "{ Class: SmallInteger }" | |
|
3292 |
||
3293 |
mySize := self size. |
|
3294 |
newStr := self species new:mySize. |
|
3295 |
1 to:mySize do:[:i | |
|
3296 |
newStr at:i put:(self at:i) asLowercase |
|
3297 |
]. |
|
3298 |
^ newStr |
|
3299 |
||
3300 |
" |
|
3301 |
'HelloWorld' asLowercase |
|
3302 |
'HelloWorld' asLowercaseFirst |
|
3303 |
" |
|
3304 |
! |
|
3305 |
||
3306 |
asLowercaseFirst |
|
3307 |
"return a copy of myself where the first character is |
|
3308 |
converted to lowercase." |
|
3309 |
||
3310 |
|newString sz| |
|
3311 |
||
3312 |
sz := self size. |
|
3313 |
newString := self copyFrom:1 to:sz. |
|
3314 |
sz > 0 ifTrue:[ |
|
3315 |
newString at:1 put:(newString at:1) asLowercase |
|
3316 |
]. |
|
3317 |
^ newString |
|
3318 |
||
3319 |
" |
|
3320 |
'HelloWorld' asLowercase |
|
3321 |
'HelloWorld' asLowercaseFirst |
|
3322 |
" |
|
3323 |
! |
|
3324 |
||
3325 |
asNumber |
|
3326 |
"read a number from the receiver. |
|
3327 |
Notice, that (in contrast to ST-80) errors may occur during the read, |
|
3328 |
so you better setup some signal handler when using this method. |
|
3329 |
This may change if ANSI specifies it." |
|
3330 |
||
3331 |
"/ ST-80 behavior: |
|
3332 |
"/ ^ Number readFromString:self onError:0 |
|
3333 |
||
3334 |
^ Number readFromString:self |
|
3335 |
||
3336 |
" |
|
3337 |
'123' asNumber |
|
3338 |
'123.567' asNumber |
|
3339 |
'(5/6)' asNumber |
|
3340 |
'foo' asNumber |
|
3341 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] |
|
3342 |
" |
|
3343 |
! |
|
3344 |
||
3345 |
asNumberFromFormatString:ignored |
|
3346 |
"read a number from the receiver, ignoring any nonDigit characters. |
|
3347 |
This is typically used to convert from strings which include |
|
3348 |
dollar-signs or millenium digits. However, this method also ignores |
|
3349 |
the decimal point (if any) and therefore should be used with care." |
|
3350 |
||
3351 |
|tempString| |
|
3352 |
||
3353 |
tempString := self collect:[:char | char isDigit]. |
|
3354 |
^ Number readFromString:tempString onError:0 |
|
3355 |
||
3356 |
" |
|
3357 |
'USD 123' asNumberFromFormatString:'foo' |
|
3358 |
'DM 123' asNumberFromFormatString:'foo' |
|
3359 |
'123' asNumberFromFormatString:'foo' |
|
3360 |
'123.567' asNumberFromFormatString:'foo' |
|
3361 |
'(5/6)' asNumberFromFormatString:'foo' |
|
3362 |
'foo' asNumberFromFormatString:'foo' |
|
3363 |
" |
|
3364 |
! |
|
3365 |
||
3366 |
asSingleByteString |
|
3367 |
"return the receiver converted to a 'normal' string" |
|
3368 |
||
3369 |
^ String fromString:self |
|
3370 |
! |
|
3371 |
||
2732 | 3372 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
3373 |
"return the receiver converted to a 'normal' string, |
|
3374 |
with invalid characters replaced by replacementCharacter. |
|
3375 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
3376 |
and replace characters above code-255 with some replacement." |
|
3377 |
||
3378 |
|newString| |
|
3379 |
||
3380 |
newString := String new:(self size). |
|
3381 |
1 to:self size do:[:idx | |
|
3382 |
|char| |
|
3383 |
||
3384 |
char := self at:idx. |
|
3385 |
char asciiValue <= 16rFF ifTrue:[ |
|
3386 |
newString at:idx put:char |
|
3387 |
] ifFalse:[ |
|
3388 |
newString at:idx put:replacementCharacter |
|
3389 |
]. |
|
3390 |
]. |
|
3391 |
^ newString |
|
3392 |
||
3393 |
"Created: 30.6.1997 / 13:02:14 / cg" |
|
3394 |
! |
|
3395 |
||
608 | 3396 |
asString |
3397 |
"return myself - I am a string" |
|
3398 |
||
3399 |
^ self |
|
3400 |
! |
|
3401 |
||
3402 |
asStringCollection |
|
3403 |
"return a collection of lines from myself." |
|
3404 |
||
1393 | 3405 |
^ StringCollection from:self "string" |
3406 |
||
3407 |
"Modified: 13.5.1996 / 20:36:59 / cg" |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3408 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3409 |
|
1434 | 3410 |
asSymbol |
3411 |
"return a unique symbol with the name taken from my characters. |
|
3412 |
The receiver must be a singleByte-String; twoByteSymbols are |
|
3413 |
(currently) not allowed." |
|
3414 |
||
3415 |
^ self string asSymbol |
|
3416 |
||
3417 |
"Created: 22.5.1996 / 15:56:11 / cg" |
|
3418 |
! |
|
3419 |
||
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3420 |
asSymbolIfInterned |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3421 |
"if a symbol with the receivers characters is already known, return it. |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3422 |
Otherwise, return nil. This can be used to query for an existing |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3423 |
symbol and is the same as |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3424 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3425 |
but slightly faster, since the symbol lookup operation is only |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3426 |
performed once. |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3427 |
The receiver must be a singleByte-String; twoByteSymbols are |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3428 |
(currently) not allowed." |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3429 |
|
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3430 |
^ self string asSymbolIfInterned |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3431 |
|
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3432 |
"Created: 22.5.1996 / 16:37:04 / cg" |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3433 |
! |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3434 |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3435 |
asText |
1381 | 3436 |
"return a Text-object (collection of lines) from myself." |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3437 |
|
4974 | 3438 |
Text isNil ifTrue:[^ self]. |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3439 |
^ Text fromString:self |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3440 |
|
1381 | 3441 |
"Created: 12.5.1996 / 10:41:14 / cg" |
608 | 3442 |
! |
3443 |
||
3444 |
asTwoByteString |
|
3445 |
"return the receiver converted to a two-byte string" |
|
3446 |
||
3447 |
^ TwoByteString fromString:self |
|
3448 |
! |
|
3449 |
||
3450 |
asUppercase |
|
3451 |
"return a copy of myself in uppercase letters" |
|
3452 |
||
3453 |
|newStr |
|
3454 |
mySize "{ Class: SmallInteger }" | |
|
3455 |
||
3456 |
mySize := self size. |
|
3457 |
newStr := self species new:mySize. |
|
3458 |
1 to:mySize do:[:i | |
|
3459 |
newStr at:i put:(self at:i) asUppercase |
|
3460 |
]. |
|
3461 |
^ newStr |
|
3462 |
||
3463 |
" |
|
3464 |
'helloWorld' asUppercase |
|
3465 |
'helloWorld' asUppercaseFirst |
|
3466 |
" |
|
3467 |
! |
|
3468 |
||
3469 |
asUppercaseFirst |
|
3470 |
"return a copy of myself where the first character is |
|
3471 |
converted to uppercase." |
|
3472 |
||
3473 |
|newString sz| |
|
3474 |
||
3475 |
sz := self size. |
|
3476 |
newString := self copyFrom:1 to:sz. |
|
3477 |
sz > 0 ifTrue:[ |
|
3478 |
newString at:1 put:(newString at:1) asUppercase |
|
3479 |
]. |
|
3480 |
^ newString |
|
3481 |
||
3482 |
" |
|
3483 |
'helloWorld' asUppercase |
|
3484 |
'helloWorld' asUppercaseFirst |
|
3485 |
'HelloWorld' asUppercaseFirst |
|
3486 |
" |
|
3487 |
! |
|
3488 |
||
3489 |
string |
|
1312 | 3490 |
"return the receiver - for ST-80 compatibility" |
3491 |
||
608 | 3492 |
^ self |
1312 | 3493 |
|
3494 |
"Modified: 27.4.1996 / 13:29:30 / cg" |
|
608 | 3495 |
! |
3496 |
||
3497 |
tokensBasedOn:aCharacter |
|
3498 |
"this is an ST-80 alias for the ST/X method |
|
3499 |
asCollectionOfSubstringsSeparatedBy:" |
|
3500 |
||
3501 |
^ self asCollectionOfSubstringsSeparatedBy:aCharacter |
|
3502 |
||
3503 |
" |
|
3504 |
'hello:world:isnt:this nice' tokensBasedOn:$: |
|
3505 |
'foo,bar,baz' tokensBasedOn:$, |
|
3506 |
'/etc/passwd' asFilename readStream nextLine tokensBasedOn:$: |
|
3507 |
" |
|
3508 |
! ! |
|
3509 |
||
3510 |
!CharacterArray methodsFor:'copying'! |
|
3511 |
||
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3512 |
, aStringOrCharacter |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3513 |
"redefined to allow characters and mixed strings to be appended. |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3514 |
This is nonStandard, but convenient" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3515 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3516 |
|myWidth otherWidth| |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3517 |
|
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3518 |
aStringOrCharacter isCharacter ifTrue:[ |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3519 |
^ self , aStringOrCharacter asString |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3520 |
]. |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3521 |
aStringOrCharacter isText ifTrue:[ |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3522 |
^ aStringOrCharacter concatenateFromString:self |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3523 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3524 |
aStringOrCharacter isString ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3525 |
(otherWidth := aStringOrCharacter bitsPerCharacter) ~~ (myWidth := self bitsPerCharacter) ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3526 |
otherWidth > myWidth ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3527 |
^ (aStringOrCharacter species fromString:self) , aStringOrCharacter |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3528 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3529 |
^ self , (self species fromString:aStringOrCharacter) |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3530 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3531 |
]. |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3532 |
^ super , aStringOrCharacter |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3533 |
|
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3534 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3535 |
'hello' , $1 |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3536 |
'hello' , '1' |
1411 | 3537 |
'hello' , (' world' asText allBold) |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3538 |
'hello' , (JISEncodedString fromString:' world') |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3539 |
(JISEncodedString fromString:'hello') , ' world' |
1411 | 3540 |
|
1422 | 3541 |
Transcript showCR: |
1411 | 3542 |
(Text string:'hello' emphasis:#italic) , (Text string:' world' emphasis:#bold) |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3543 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3544 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3545 |
"Modified: 28.6.1997 / 00:13:17 / cg" |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3546 |
! |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3547 |
|
608 | 3548 |
concatenate:string1 and:string2 |
3549 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
3550 |
This is equivalent to self , string1 , string2 |
|
3551 |
- generated by compiler when such a construct is detected and the receiver |
|
3552 |
is known to be a string." |
|
3553 |
||
3554 |
^ self , string1 , string2 |
|
3555 |
! |
|
3556 |
||
3557 |
concatenate:string1 and:string2 and:string3 |
|
3558 |
"return the concatenation of myself and the string arguments. |
|
3559 |
This is equivalent to self , string1 , string2 , string3 |
|
3560 |
- generated by compiler when such a construct is detected and the receiver |
|
3561 |
is known to be a string." |
|
3562 |
||
3563 |
^ self , string1 , string2 , string3 |
|
3564 |
! ! |
|
3565 |
||
3566 |
!CharacterArray methodsFor:'displaying'! |
|
3567 |
||
2762 | 3568 |
displayOn:aGC x:x y:y from:start to:stop |
3569 |
"display the receiver on a GC" |
|
3570 |
||
3571 |
"q&d hack" |
|
3572 |
||
3573 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:false |
|
3574 |
||
3575 |
"Modified: 12.5.1996 / 12:49:33 / cg" |
|
3576 |
! |
|
3577 |
||
3578 |
displayOn:aGc x:x y:y opaque:opq |
|
3579 |
"display the receiver in a graphicsContext - this method allows |
|
3580 |
strings to be used like DisplayObjects." |
|
3581 |
||
3582 |
|s| |
|
3583 |
||
3584 |
s := self string. |
|
3585 |
opq ifTrue:[ |
|
3586 |
aGc displayOpaqueString:s x:x y:y. |
|
3587 |
] ifFalse:[ |
|
3588 |
aGc displayString:s x:x y:y. |
|
3589 |
]. |
|
1381 | 3590 |
|
3591 |
"Modified: 11.5.1996 / 14:42:48 / cg" |
|
3592 |
! |
|
3593 |
||
2762 | 3594 |
displayOpaqueOn:aGC x:x y:y from:start to:stop |
3595 |
"display the receiver on a GC" |
|
3596 |
||
3597 |
"q&d hack" |
|
3598 |
||
3599 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:true |
|
3600 |
||
3601 |
"Created: 12.5.1996 / 12:29:37 / cg" |
|
3602 |
"Modified: 12.5.1996 / 12:49:19 / cg" |
|
608 | 3603 |
! ! |
3604 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3605 |
!CharacterArray methodsFor:'emphasis'! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3606 |
|
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3607 |
emphasis |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3608 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3609 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3610 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3611 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3612 |
^ RunArray new:self size withAll:nil |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3613 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3614 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3615 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3616 |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3617 |
emphasisAt:characterIndex |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3618 |
"return the emphasis at some index. |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3619 |
Since characterArrays do not hold any emphasis information, |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3620 |
nil (no emphasis) is returned here." |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3621 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3622 |
^ nil |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3623 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3624 |
"Created: 11.5.1996 / 14:13:27 / cg" |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3625 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3626 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3627 |
emphasisCollection |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3628 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3629 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3630 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3631 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3632 |
^ RunArray new:(self size) |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3633 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3634 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3635 |
"Modified: 14.5.1996 / 15:02:29 / cg" |
3404 | 3636 |
! |
3637 |
||
3638 |
emphasizeAllWith:emphasis |
|
3639 |
^ self asText emphasizeAllWith:emphasis |
|
3640 |
||
3641 |
" |
|
3642 |
Transcript showCR:('hello' emphasizeAllWith:#bold) |
|
3599 | 3643 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
3644 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
|
3645 |
" |
|
3646 |
||
3647 |
"Modified: / 17.6.1998 / 12:51:44 / cg" |
|
5097 | 3648 |
! |
3649 |
||
3650 |
makeSelectorBoldIn:aClass |
|
3651 |
"the receiver represents some source code for |
|
3652 |
a method in aClass. |
|
3653 |
Change myself to boldify the selector. |
|
3654 |
Not yet implemented (could easily use the syntaxHighlighter |
|
3655 |
for this ...)" |
|
3656 |
||
3657 |
^ self |
|
3658 |
||
3659 |
"Modified: / 13.12.1999 / 21:49:11 / cg" |
|
3660 |
"Created: / 13.12.1999 / 21:49:24 / cg" |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3661 |
! ! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3662 |
|
5469
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3663 |
!CharacterArray methodsFor:'encoding'! |
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3664 |
|
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3665 |
encodeOn:anEncoder with:aParameter |
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3666 |
|
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3667 |
anEncoder encodeString:self with:aParameter |
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3668 |
|
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3669 |
! ! |
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3670 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3671 |
!CharacterArray methodsFor:'encoding/decoding'! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3672 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3673 |
decodeFrom:encodingSymbol |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3674 |
"given the receiver encoded as described by encodingSymbol, |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3675 |
convert it into internal ST/X encoding and return a corresponding CharacterArray. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3676 |
Currently, only a few encodings are supported |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3677 |
(and those are untested/incomplete): |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3678 |
#euc |
997
6c7f1815ed02
more encoding & decoding support
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
3679 |
#jis7 |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
3680 |
#sjis |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3681 |
#mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3682 |
#msdos |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3683 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3684 |
|
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3685 |
|newString table| |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3686 |
|
2736 | 3687 |
encodingSymbol == #'x-jis7' ifTrue:[ |
2733 | 3688 |
^ JISEncodedString decodeFromJIS7:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3689 |
]. |
2758 | 3690 |
encodingSymbol == #'x-iso2022-jp' ifTrue:[ |
3691 |
^ JISEncodedString decodeFromJIS7:self |
|
3692 |
]. |
|
2759 | 3693 |
encodingSymbol == #'iso2022-jp' ifTrue:[ |
3694 |
^ JISEncodedString decodeFromJIS7:self |
|
3695 |
]. |
|
2736 | 3696 |
encodingSymbol == #'x-sjis' ifTrue:[ |
2733 | 3697 |
^ JISEncodedString decodeFromSJIS:self |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3698 |
]. |
2736 | 3699 |
encodingSymbol == #'x-shift-jis' ifTrue:[ |
3700 |
^ JISEncodedString decodeFromSJIS:self |
|
3701 |
]. |
|
3702 |
encodingSymbol == #'x-euc-jp' ifTrue:[ |
|
2733 | 3703 |
^ JISEncodedString decodeFromEUC:self |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3704 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3705 |
encodingSymbol == #big5 ifTrue:[ |
2733 | 3706 |
^ BIG5EncodedString decodeFromBIG5:self |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3707 |
]. |
2736 | 3708 |
encodingSymbol == #gb2312 ifTrue:[ |
2733 | 3709 |
^ GBEncodedString decodeFromGB:self |
3710 |
]. |
|
2736 | 3711 |
encodingSymbol == #'x-euc-gb' ifTrue:[ |
3712 |
^ GBEncodedString decodeFromEUC:self |
|
3713 |
]. |
|
3714 |
encodingSymbol == #'x-euc-kr' ifTrue:[ |
|
3715 |
^ KSCEncodedString decodeFromEUC:self |
|
2733 | 3716 |
]. |
3717 |
||
3718 |
encodingSymbol == #ucs2 ifTrue:[ |
|
3719 |
^ UnicodeString decodeFromUCS2:self |
|
3720 |
]. |
|
3721 |
encodingSymbol == #ucs4 ifTrue:[ |
|
3722 |
^ UnicodeString decodeFromUCS4:self |
|
3723 |
]. |
|
3724 |
encodingSymbol == #utf7 ifTrue:[ |
|
3725 |
^ UnicodeString decodeFromUTF7:self |
|
3726 |
]. |
|
3727 |
encodingSymbol == #utf8 ifTrue:[ |
|
3728 |
^ UnicodeString decodeFromUTF8:self |
|
3729 |
]. |
|
3730 |
encodingSymbol == #utf16 ifTrue:[ |
|
3731 |
^ UnicodeString decodeFromUTF16:self |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3732 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3733 |
|
2736 | 3734 |
|
3735 |
"/ soon obsolete ... |
|
3736 |
encodingSymbol == #jis7 ifTrue:[ |
|
3737 |
^ JISEncodedString decodeFromJIS7:self |
|
3738 |
]. |
|
3739 |
encodingSymbol == #sjis ifTrue:[ |
|
3740 |
^ JISEncodedString decodeFromSJIS:self |
|
3741 |
]. |
|
3742 |
encodingSymbol == #euc ifTrue:[ |
|
3743 |
^ JISEncodedString decodeFromEUC:self |
|
3744 |
]. |
|
3745 |
||
3746 |
encodingSymbol == #gb ifTrue:[ |
|
3747 |
^ GBEncodedString decodeFromGB:self |
|
3748 |
]. |
|
3749 |
encodingSymbol == #ksc ifTrue:[ |
|
3750 |
^ KSCEncodedString decodeFromKSC:self |
|
3751 |
]. |
|
3752 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3753 |
table := self class decoderTableFor:encodingSymbol. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3754 |
table isNil ifTrue:[^ self]. |
2736 | 3755 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3756 |
newString := self class new:self size. |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3757 |
newString replaceFrom:self translateBy:table. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3758 |
newString = self ifTrue:[^ self]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3759 |
^ newString |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3760 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3761 |
"Created: 22.2.1996 / 15:06:49 / cg" |
2759 | 3762 |
"Modified: 16.7.1997 / 13:45:33 / cg" |
2733 | 3763 |
! |
3764 |
||
3765 |
encodeForDisplayInto:encodingSymbol |
|
3766 |
"given the receiver in internal ST/X encoding, |
|
3767 |
convert it into the format as described by encodingSymbol |
|
3768 |
for display. |
|
3769 |
The receiver may contain roman characters in 0..255, which |
|
3770 |
are translated according to the encodings roman translation. |
|
3771 |
For example: in JIS, roman $a is found at 16r2361. |
|
3772 |
" |
|
3773 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3774 |
|newString table| |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3775 |
|
2733 | 3776 |
encodingSymbol isNil ifTrue:[^ self]. |
3777 |
||
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3778 |
"/ notice: this method may not be moved to |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3779 |
"/ concrete TwoByte classes; it is also invoked |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3780 |
"/ to convert singleByte strings ... |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3781 |
|
2733 | 3782 |
(encodingSymbol startsWith:'jis') ifTrue:[ |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3783 |
newString := JISEncodedString encodeRomans:self. |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3784 |
|
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3785 |
"/ jisx0208.1983 has no half-width katakana |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3786 |
(encodingSymbol startsWith:'jisx0208.1983') ifTrue:[ |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3787 |
newString := JISEncodedString encodeHalfWidthKatakana:newString. |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3788 |
]. |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3789 |
^ newString |
2733 | 3790 |
]. |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3791 |
|
2733 | 3792 |
(encodingSymbol startsWith:'big5') ifTrue:[ |
3793 |
^ BIG5EncodedString encodeRomans:self |
|
3794 |
]. |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3795 |
|
2733 | 3796 |
(encodingSymbol startsWith:'gb') ifTrue:[ |
3797 |
^ GBEncodedString encodeRomans:self |
|
3798 |
]. |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3799 |
|
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3800 |
(encodingSymbol startsWith:'ksc') ifTrue:[ |
2733 | 3801 |
^ KSCEncodedString encodeRomans:self |
3802 |
]. |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3803 |
|
2733 | 3804 |
(encodingSymbol startsWith:'uni') ifTrue:[ |
3805 |
^ UnicodeString encodeRomans:self |
|
3806 |
]. |
|
3807 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3808 |
table := self class encoderTableFor:encodingSymbol. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3809 |
table isNil ifTrue:[^ self]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3810 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3811 |
newString := self class new:self size. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3812 |
newString replaceFrom:self translateBy:table. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3813 |
newString = self ifTrue:[^ self]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3814 |
^ newString |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3815 |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3816 |
"Modified: 2.7.1997 / 15:02:56 / cg" |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3817 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3818 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3819 |
encodeInto:encodingSymbol |
2733 | 3820 |
"given the receiver in internal ST/X encoding, |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3821 |
convert it into the format as described by encodingSymbol |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3822 |
and return a corresponding CharacterArray. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3823 |
Currently, only a few encodings are supported |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3824 |
(and those are untested/incomplete): |
2736 | 3825 |
#x-euc-jp |
2760 | 3826 |
#x-jis7 (== iso2022-jp) |
2736 | 3827 |
#x-sjis |
3828 |
#x-shift-jis |
|
2733 | 3829 |
#big5 |
3830 |
#gb |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3831 |
#mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3832 |
#msdos |
2733 | 3833 |
#next |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3834 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3835 |
|
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3836 |
|newString table| |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3837 |
|
1204 | 3838 |
"/ self encoding storeString print. ' -> ' print. encodingSymbol storeString printNL. |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3839 |
|
1028 | 3840 |
encodingSymbol isNil ifTrue:[^ self]. |
3841 |
||
2736 | 3842 |
encodingSymbol == #'x-jis7' ifTrue:[ |
2733 | 3843 |
^ JISEncodedString encodeIntoJIS7:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3844 |
]. |
2759 | 3845 |
encodingSymbol == #'x-iso2022-jp' ifTrue:[ |
3846 |
^ JISEncodedString encodeIntoJIS7:self |
|
3847 |
]. |
|
3848 |
encodingSymbol == #'iso2022-jp' ifTrue:[ |
|
3849 |
^ JISEncodedString encodeIntoJIS7:self |
|
3850 |
]. |
|
2736 | 3851 |
encodingSymbol == #'x-sjis' ifTrue:[ |
2733 | 3852 |
^ JISEncodedString encodeIntoSJIS:self |
1013
0e54ddc990cb
more 16bit & encoding support
Claus Gittinger <cg@exept.de>
parents:
1012
diff
changeset
|
3853 |
]. |
2736 | 3854 |
encodingSymbol == #'x-shift-jis' ifTrue:[ |
3855 |
^ JISEncodedString encodeIntoSJIS:self |
|
3856 |
]. |
|
3857 |
encodingSymbol == #'x-euc-jp' ifTrue:[ |
|
2733 | 3858 |
^ JISEncodedString encodeIntoEUC:self |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3859 |
]. |
2733 | 3860 |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3861 |
encodingSymbol == #big5 ifTrue:[ |
2733 | 3862 |
^ BIG5EncodedString encodeIntoBIG5:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3863 |
]. |
2736 | 3864 |
|
3865 |
encodingSymbol == #gb2312 ifTrue:[ |
|
2733 | 3866 |
^ GBEncodedString encodeIntoGB:self |
3867 |
]. |
|
2736 | 3868 |
encodingSymbol == #'x-euc-gb' ifTrue:[ |
3869 |
^ GBEncodedString encodeIntoGB:self |
|
3870 |
]. |
|
3871 |
||
3872 |
encodingSymbol == #'x-euc-kr' ifTrue:[ |
|
2733 | 3873 |
^ KSCEncodedString encodeIntoKSC:self |
3874 |
]. |
|
3875 |
||
3876 |
encodingSymbol == #ucs2 ifTrue:[ |
|
3877 |
^ UnicodeString encodeIntoUCS2:self |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3878 |
]. |
2733 | 3879 |
encodingSymbol == #ucs4 ifTrue:[ |
3880 |
^ UnicodeString encodeIntoUCS4:self |
|
3881 |
]. |
|
3882 |
encodingSymbol == #utf7 ifTrue:[ |
|
3883 |
^ UnicodeString encodeIntoUTF7:self |
|
3884 |
]. |
|
3885 |
encodingSymbol == #utf8 ifTrue:[ |
|
3886 |
^ UnicodeString encodeIntoUTF8:self |
|
3887 |
]. |
|
3888 |
encodingSymbol == #utf16 ifTrue:[ |
|
3889 |
^ UnicodeString encodeIntoUTF16:self |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3890 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3891 |
|
2736 | 3892 |
|
3893 |
"/ to be obsoleted ... |
|
3894 |
encodingSymbol == #jis7 ifTrue:[ |
|
3895 |
^ JISEncodedString encodeIntoJIS7:self |
|
3896 |
]. |
|
3897 |
encodingSymbol == #sjis ifTrue:[ |
|
3898 |
^ JISEncodedString encodeIntoSJIS:self |
|
3899 |
]. |
|
3900 |
encodingSymbol == #euc ifTrue:[ |
|
3901 |
^ JISEncodedString encodeIntoEUC:self |
|
3902 |
]. |
|
3903 |
||
3904 |
encodingSymbol == #gb ifTrue:[ |
|
3905 |
^ GBEncodedString encodeIntoGB:self |
|
3906 |
]. |
|
3907 |
encodingSymbol == #ksc ifTrue:[ |
|
3908 |
^ KSCEncodedString encodeIntoKSC:self |
|
3909 |
]. |
|
3910 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3911 |
table := self class encoderTableFor:encodingSymbol. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3912 |
table isNil ifTrue:[^ self]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3913 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3914 |
newString := self class new:self size. |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3915 |
newString replaceFrom:self translateBy:table. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3916 |
newString = self ifTrue:[^ self]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3917 |
^ newString |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3918 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3919 |
"Created: 22.2.1996 / 15:07:31 / cg" |
2760 | 3920 |
"Modified: 16.7.1997 / 13:56:21 / cg" |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3921 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3922 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3923 |
replaceFrom:aString decode:encoding |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3924 |
"this is an experimental interface - unfinished" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3925 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3926 |
^ self replaceFrom:aString translateBy:(self class decoderTableFor:encoding) |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3927 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3928 |
"Created: 20.10.1995 / 23:00:09 / cg" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3929 |
"Modified: 22.2.1996 / 16:08:26 / cg" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3930 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3931 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3932 |
replaceFrom:aString encode:encoding |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3933 |
"this is an experimental interface - unfinished" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3934 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3935 |
^ self replaceFrom:aString translateBy:(self class encoderTableFor:encoding) |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3936 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3937 |
"Modified: 20.10.1995 / 23:08:16 / cg" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3938 |
"Created: 22.2.1996 / 16:08:34 / cg" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3939 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3940 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3941 |
replaceFrom:aString translateBy:encodingTable |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3942 |
"replace the receivers characters by translations coming from |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3943 |
an encoding table." |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3944 |
|
2520
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3945 |
|mySize "{ Class: SmallInteger }" |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3946 |
maxCode "{ Class: SmallInteger }" |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3947 |
char |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3948 |
oldCode "{ Class: SmallInteger }" |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3949 |
newCode| |
1023 | 3950 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3951 |
self replaceFrom:1 with:aString. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3952 |
encodingTable isNil ifTrue:[^ self]. |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3953 |
|
2520
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3954 |
maxCode := encodingTable size. |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3955 |
mySize := self size. |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3956 |
|
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3957 |
1 to:mySize do:[:index | |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3958 |
char := aString at:index. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3959 |
oldCode := char asciiValue. |
2520
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3960 |
oldCode >= maxCode ifFalse:[ |
1023 | 3961 |
newCode := encodingTable at:(oldCode + 1). |
3962 |
newCode ~~ oldCode ifTrue:[ |
|
3963 |
self at:index put:(Character value:newCode) |
|
3964 |
] |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3965 |
] |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3966 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3967 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3968 |
"Created: 22.2.1996 / 16:07:26 / cg" |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3969 |
"Modified: 1.7.1997 / 17:18:06 / cg" |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3970 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3971 |
|
608 | 3972 |
!CharacterArray methodsFor:'padded copying'! |
3973 |
||
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3974 |
centerPaddedTo:newSize |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3975 |
"return a new string consisting of the receivers characters, |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3976 |
plus spaces up to length and center the receivers characters in |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3977 |
the resulting string. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3978 |
If the receivers size is equal or greater than the length argument, |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3979 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3980 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3981 |
^ self centerPaddedTo:newSize with:(Character space) |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3982 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3983 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3984 |
'foo' centerPaddedTo:10 |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3985 |
123 printString centerPaddedTo:10 |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3986 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3987 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3988 |
"Created: 25.11.1995 / 10:53:57 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3989 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3990 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3991 |
centerPaddedTo:size with:padCharacter |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3992 |
"return a new string of length size, which contains the receiver |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3993 |
centered (i.e. padded on both sides). |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3994 |
Characters are filled with padCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3995 |
If the receivers size is equal or greater than the length argument, |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3996 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3997 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3998 |
|len s| |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3999 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4000 |
len := self size. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4001 |
(len < size) ifTrue:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4002 |
s := self species new:size withAll:padCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4003 |
s replaceFrom:(size - len) // 2 + 1 with:self. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4004 |
^ s |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4005 |
] |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4006 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4007 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4008 |
'foo' centerPaddedTo:11 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4009 |
'fooBar' centerPaddedTo:5 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4010 |
123 printString centerPaddedTo:10 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4011 |
(' ' , 123 printString) centerPaddedTo:10 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4012 |
(Float pi printString) centerPaddedTo:15 with:(Character space) |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4013 |
(Float pi printString) centerPaddedTo:15 with:$- |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4014 |
(' ' , Float pi class name) centerPaddedTo:15 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4015 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4016 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4017 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4018 |
decimalPaddedTo:size and:afterPeriod at:decimalCharacter |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4019 |
"return a new string of overall length size, which contains the receiver |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4020 |
aligned at the decimal-period column and afterPeriod characters to the right |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4021 |
of the period. The periodCharacter is passed as arguments (allowing for US and European formats |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4022 |
to be padded). |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4023 |
If the receivers size is equal or greater than the length argument, |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4024 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4025 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4026 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4027 |
^ self |
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4028 |
decimalPaddedTo:size |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4029 |
and:afterPeriod |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4030 |
at:decimalCharacter |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4031 |
withLeft:(Character space) |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4032 |
right:$0 |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4033 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4034 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4035 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123 ' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4036 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4037 |
'123.' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4038 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.100' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4039 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.1 ' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4040 |
'123.123' decimalPaddedTo:10 and:3 at:$. -> ' 123.123' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4041 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4042 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4043 |
"Created: 23.12.1995 / 13:11:52 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4044 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4045 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4046 |
decimalPaddedTo:size and:afterPeriod at:decimalCharacter withLeft:leftPadChar right:rightPadChar |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4047 |
"return a new string of overall length size, which contains the receiver |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4048 |
aligned at the decimal-period column and afterPeriod characters to the right |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4049 |
of the period. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4050 |
Characters on the left are filled with leftPadChar. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4051 |
If rightPadChar is nil, characters on the right are filled with leftPadCharacter too; |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4052 |
otherwise, if missing, a decimal point is added and right characters filled with this. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4053 |
If the receivers size is equal or greater than the length argument, |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4054 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4055 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4056 |
|
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4057 |
|s idx n rest| |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4058 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4059 |
idx := self indexOf:decimalCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4060 |
idx == 0 ifTrue:[ |
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4061 |
"/ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4062 |
"/ no decimal point found; adjust string to the left of the period column |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4063 |
"/ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4064 |
rightPadChar isNil ifTrue:[ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4065 |
s := self , (self species new:afterPeriod + 1 withAll:leftPadChar) |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4066 |
] ifFalse:[ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4067 |
s:= self , decimalCharacter asString , (self species new:afterPeriod withAll:rightPadChar). |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4068 |
]. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4069 |
] ifFalse:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4070 |
|
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4071 |
"/ the number of after-decimalPoint characters |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4072 |
n := self size - idx. |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4073 |
rest := afterPeriod - n. |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4074 |
rest > 0 ifTrue:[ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4075 |
s := (self species new:rest withAll:(rightPadChar ? leftPadChar)). |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4076 |
] ifFalse:[ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4077 |
s := '' |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4078 |
]. |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4079 |
s := self , s. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4080 |
]. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4081 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4082 |
^ s leftPaddedTo:size with:leftPadChar |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4083 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4084 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4085 |
'123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:nil -> ' 123 ' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4086 |
'123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.000' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4087 |
'123.' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.000' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4088 |
'123.1' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.100' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4089 |
'123.1' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:nil -> ' 123.1 ' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4090 |
'123.123' decimalPaddedTo:10 and:3 at:$. withLeft:(Character space) right:$0 -> ' 123.123' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4091 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4092 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4093 |
"Modified: 23.12.1995 / 13:08:18 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4094 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4095 |
|
608 | 4096 |
leftPaddedTo:size |
4097 |
"return a new string of length size, which contains the receiver |
|
4098 |
right-adjusted (i.e. padded on the left). |
|
4099 |
Characters on the left are filled with spaces. |
|
4100 |
If the receivers size is equal or greater than the length argument, |
|
4101 |
the original receiver is returned unchanged." |
|
4102 |
||
4103 |
^ self leftPaddedTo:size with:(Character space) |
|
4104 |
||
4105 |
" |
|
4106 |
'foo' leftPaddedTo:10 |
|
4107 |
'fooBar' leftPaddedTo:5 |
|
4108 |
123 printString leftPaddedTo:10 |
|
4109 |
" |
|
4110 |
! |
|
4111 |
||
4112 |
paddedTo:newSize |
|
4113 |
"return a new string consisting of the receivers characters, |
|
4114 |
plus spaces up to length. |
|
4115 |
If the receivers size is equal or greater than the length argument, |
|
4116 |
the original receiver is returned unchanged." |
|
4117 |
||
4118 |
^ self paddedTo:newSize with:(Character space) |
|
4119 |
||
4120 |
" |
|
4121 |
'foo' paddedTo:10 |
|
4122 |
123 printString paddedTo:10 |
|
4123 |
" |
|
64 | 4124 |
! ! |
4125 |
||
328 | 4126 |
!CharacterArray methodsFor:'pattern matching'! |
4127 |
||
2551 | 4128 |
compoundMatch:aString |
3253 | 4129 |
"like match, but the receiver may be a compound match pattern, |
2551 | 4130 |
consisting of multiple simple patterns, separated by semicolons. |
4131 |
This is usable with fileName pattern fields." |
|
4132 |
||
5124
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4133 |
^self compoundMatch:aString ignoreCase:false |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4134 |
|
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4135 |
" |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4136 |
'f*' match:'foo' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4137 |
'b*' match:'foo' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4138 |
'f*;b*' match:'foo' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4139 |
'f*;b*' match:'bar' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4140 |
'f*;b*' compoundMatch:'foo' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4141 |
'f*;b*' compoundMatch:'bar' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4142 |
" |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4143 |
|
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4144 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4145 |
"Modified: / 16.12.1999 / 01:22:08 / cg" |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4146 |
! |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4147 |
|
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4148 |
compoundMatch:aString ignoreCase:ignoreCase |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4149 |
"like match, but the receiver may be a compound match pattern, |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4150 |
consisting of multiple simple patterns, separated by semicolons. |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4151 |
This is usable with fileName pattern fields." |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4152 |
|
2551 | 4153 |
|matchers| |
4154 |
||
4155 |
matchers := self asCollectionOfSubstringsSeparatedBy:$;. |
|
4156 |
matchers do:[:aPattern | |
|
5124
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4157 |
(aPattern match:aString ignoreCase:ignoreCase) ifTrue:[^ true]. |
2551 | 4158 |
]. |
4159 |
^ false. |
|
4160 |
||
4161 |
" |
|
4162 |
'f*' match:'foo' |
|
4163 |
'b*' match:'foo' |
|
4164 |
'f*;b*' match:'foo' |
|
4165 |
'f*;b*' match:'bar' |
|
4166 |
'f*;b*' compoundMatch:'foo' |
|
4167 |
'f*;b*' compoundMatch:'bar' |
|
5124
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4168 |
'f*;b*' compoundMatch:'Foo' ignoreCase:true |
2551 | 4169 |
" |
4170 |
||
3253 | 4171 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
4172 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
5124
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4173 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
2551 | 4174 |
! |
4175 |
||
328 | 4176 |
findMatchString:matchString |
368 | 4177 |
"like findString/indexOfSubCollection, but allowing match patterns. |
328 | 4178 |
find matchstring; if found, return the index; |
4179 |
if not found, return 0." |
|
4180 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
4181 |
^ self findMatchString:matchString startingAt:1 ignoreCase:false ifAbsent:0 |
328 | 4182 |
! |
4183 |
||
4184 |
findMatchString:matchString startingAt:index |
|
4185 |
"like findString, but allowing match patterns. |
|
4186 |
find matchstring, starting at index. if found, return the index; |
|
4187 |
if not found, return 0." |
|
4188 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
4189 |
^ self findMatchString:matchString startingAt:index ignoreCase:false ifAbsent:0 |
328 | 4190 |
! |
4191 |
||
4192 |
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock |
|
4193 |
"like findString, but allowing match patterns. |
|
4194 |
find matchstring, starting at index. if found, return the index; |
|
4195 |
if not found, return the result of evaluating exceptionBlock. |
|
4196 |
This is a q&d hack - not very efficient" |
|
4197 |
||
2916 | 4198 |
|firstChar firstSet |
328 | 4199 |
startIndex "{ Class: SmallInteger }" |
4200 |
matchSize "{ Class: SmallInteger }" |
|
4201 |
mySize "{ Class: SmallInteger }" |
|
4202 |
realMatchString| |
|
4203 |
||
4204 |
matchSize := matchString size. |
|
4205 |
matchSize == 0 ifTrue:[^ index]. "empty string matches" |
|
4206 |
||
4207 |
realMatchString := matchString. |
|
4208 |
(realMatchString endsWith:$*) ifFalse:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4209 |
realMatchString := realMatchString , '*'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4210 |
matchSize := matchSize + 1 |
328 | 4211 |
]. |
4212 |
||
4213 |
mySize := self size. |
|
4214 |
firstChar := realMatchString at:1. |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
4215 |
firstChar == self class matchEscapeCharacter ifTrue:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4216 |
firstChar := realMatchString at:2. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4217 |
]. |
328 | 4218 |
|
4219 |
firstChar asString includesMatchCharacters ifTrue:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4220 |
index to:mySize do:[:col | |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4221 |
(realMatchString match:self from:col to:mySize ignoreCase:ignoreCase) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4222 |
ifTrue:[^ col] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4223 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4224 |
^ exceptionBlock value. |
328 | 4225 |
]. |
2916 | 4226 |
ignoreCase ifTrue:[ |
4227 |
firstSet := String with:(firstChar asUppercase) with:(firstChar asLowercase). |
|
4228 |
startIndex := self indexOfAny:firstSet startingAt:index. |
|
4229 |
] ifFalse:[ |
|
4230 |
startIndex := self indexOf:firstChar startingAt:index. |
|
4231 |
]. |
|
328 | 4232 |
[startIndex == 0] whileFalse:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4233 |
(realMatchString match:self from:startIndex to:mySize ignoreCase:ignoreCase) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4234 |
ifTrue:[^ startIndex]. |
2916 | 4235 |
ignoreCase ifTrue:[ |
4236 |
startIndex := self indexOfAny:firstSet startingAt:(startIndex + 1). |
|
4237 |
] ifFalse:[ |
|
4238 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1). |
|
4239 |
]. |
|
328 | 4240 |
]. |
4241 |
^ exceptionBlock value |
|
4242 |
||
4243 |
" |
|
4244 |
'one two three four' findMatchString:'o[nu]' |
|
4245 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
2916 | 4246 |
'one two three four one' findMatchString:'ONE' startingAt:3 ignoreCase:true ifAbsent:0 |
328 | 4247 |
" |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4248 |
|
2916 | 4249 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
328 | 4250 |
! |
4251 |
||
608 | 4252 |
includesMatchString:matchString |
4253 |
"like includesString, but allowing match patterns. |
|
4254 |
find matchstring; if found, return true, otherwise return false" |
|
4255 |
||
4256 |
^ (self findMatchString:matchString) ~~ 0 |
|
4257 |
||
4258 |
" |
|
4259 |
'hello world' includesMatchString:'h*' |
|
4260 |
'hello world' includesMatchString:'h[aeiou]llo' |
|
4261 |
'hello world' includesMatchString:'wor*' |
|
4262 |
'hello world' includesMatchString:'woR*' |
|
4263 |
" |
|
4264 |
! |
|
4265 |
||
328 | 4266 |
match:aString |
4267 |
"return true if aString matches self, where self may contain meta-match |
|
4268 |
characters $* (to match any string) or $# (to match any character). |
|
4269 |
or [...] to match a set of characters. |
|
345 | 4270 |
Lower/uppercase are considered different. |
4271 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4272 |
NOT the ST-80 meaning." |
328 | 4273 |
|
4274 |
^ self match:aString from:1 to:aString size ignoreCase:false |
|
4275 |
||
4276 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4277 |
'\*f*' match:'f' |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4278 |
'\*f*' match:'*f' |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4279 |
'*\*f*' match:'*f' |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4280 |
'*f*' match:'*f' |
328 | 4281 |
'*ute*' match:'computer' |
4282 |
'*uter' match:'computer' |
|
4283 |
'uter*' match:'computer' |
|
4284 |
'*ute*' match:'' |
|
4285 |
'[abcd]*' match:'computer' |
|
4286 |
'[abcd]*' match:'komputer' |
|
4287 |
'*some*compl*ern*' match:'this is some more complicated pattern match' |
|
4288 |
'*some*compl*ern*' match:'this is another complicated pattern match' |
|
3537 | 4289 |
'*-hh' match:'anton-h' |
4290 |
" |
|
4291 |
||
4292 |
"Modified: / 9.6.1998 / 18:50:00 / cg" |
|
328 | 4293 |
! |
4294 |
||
4295 |
match:aString from:start to:stop ignoreCase:ignoreCase |
|
4296 |
"return true if part of aString matches myself, |
|
4297 |
where self may contain meta-match |
|
4298 |
characters $* (to match any string) or $# (to match any character) |
|
4299 |
or [...] to match a set of characters. |
|
345 | 4300 |
If ignoreCase is true, lower/uppercase are considered the same. |
4301 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
1429 | 4302 |
NOT the ST-80 meaning." |
328 | 4303 |
|
4304 |
|matchScanArray| |
|
4305 |
||
4306 |
" |
|
4307 |
keep the matchScanArray from the most recent match - |
|
4308 |
avoids parsing the pattern over-and over if multiple searches |
|
4309 |
are done with the same pattern. |
|
4310 |
" |
|
4311 |
(PreviousMatch notNil |
|
4312 |
and:[PreviousMatch key = self]) ifTrue:[ |
|
1429 | 4313 |
matchScanArray := PreviousMatch value |
328 | 4314 |
] ifFalse:[ |
1429 | 4315 |
matchScanArray := self class matchScanArrayFrom:self. |
4316 |
matchScanArray isNil ifTrue:[ |
|
3926 | 4317 |
'CharacterArray [info]: invalid matchpattern:''' infoPrint. self infoPrint. ''' comparing for equality.' infoPrintCR. |
4318 |
^ self = aString |
|
4319 |
"/ ^ false |
|
1429 | 4320 |
]. |
4321 |
PreviousMatch := self -> matchScanArray. |
|
328 | 4322 |
]. |
4323 |
||
4324 |
^ self class |
|
1429 | 4325 |
matchScan:matchScanArray |
4326 |
from:1 to:matchScanArray size |
|
4327 |
with:aString |
|
4328 |
from:start to:stop |
|
4329 |
ignoreCase:ignoreCase |
|
328 | 4330 |
|
4331 |
" |
|
4332 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
4333 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
4334 |
" |
|
1429 | 4335 |
|
3926 | 4336 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
359 | 4337 |
! |
4338 |
||
608 | 4339 |
match:aString ignoreCase:ignoreCase |
4340 |
"return true if aString matches self, where self may contain meta-match |
|
4341 |
characters $* (to match any string) or $# (to match any character) |
|
4342 |
or [...] to match a set of characters. |
|
4343 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
4344 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4345 |
NOT the ST-80 meaning." |
608 | 4346 |
|
4347 |
^ self match:aString from:1 to:aString size ignoreCase:ignoreCase |
|
4348 |
||
4349 |
" |
|
4350 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
4351 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
4352 |
'[abcd]*' match:'computer' ignoreCase:false |
|
4353 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
4354 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
4355 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
4356 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
4357 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
4358 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
4359 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
4360 |
||
4361 |
Time millisecondsToRun:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4362 |
Symbol allInstancesDo:[:sym | |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4363 |
'[ab]*' match:sym ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4364 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4365 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4366 |
Time millisecondsToRun:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4367 |
Symbol allInstancesDo:[:sym | |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4368 |
'*at:*' match:sym ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4369 |
] |
608 | 4370 |
]. |
4371 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4372 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4373 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
5609 | 4374 |
! |
4375 |
||
4376 |
matches:aPatternString |
|
4377 |
"return true if the receiver matches aString, where aPatternString may contain meta-match |
|
4378 |
characters $* (to match any string) or $# (to match any character). |
|
4379 |
or [...] to match a set of characters. |
|
4380 |
Lower/uppercase are considered different. |
|
4381 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
4382 |
NOT the ST-80 meaning." |
|
4383 |
||
4384 |
^ aPatternString match:self |
|
4385 |
||
4386 |
||
608 | 4387 |
! ! |
4388 |
||
4389 |
!CharacterArray methodsFor:'printing & storing'! |
|
4390 |
||
4391 |
article |
|
4392 |
"return an article string for the receiver." |
|
4393 |
||
4394 |
|firstChar| |
|
4395 |
||
4396 |
firstChar := (self at:1) asLowercase. |
|
4397 |
(firstChar isVowel or:[firstChar == $x]) ifTrue:[ |
|
4398 |
firstChar ~~ $u ifTrue:[ |
|
4399 |
^ 'an' |
|
4400 |
] |
|
4401 |
]. |
|
4402 |
^ 'a' |
|
4403 |
! |
|
4404 |
||
4405 |
displayString |
|
4406 |
"return a string to display the receiver - use storeString to have |
|
4407 |
quotes around." |
|
4408 |
||
4409 |
^ self storeString |
|
4410 |
! |
|
4411 |
||
4412 |
printOn:aStream |
|
4413 |
"print the receiver on aStream" |
|
4414 |
||
4415 |
aStream nextPutAll:self |
|
4416 |
! |
|
4417 |
||
4418 |
printString |
|
4419 |
"return a string for printing - thats myself" |
|
4420 |
||
4421 |
^ self |
|
3578 | 4422 |
! |
4423 |
||
4424 |
printWithQuotesDoubledOn:aStream |
|
4425 |
"put the raw storeString of myself on aStream" |
|
4426 |
||
4427 |
self do:[:thisChar | |
|
4428 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
4429 |
aStream nextPut:thisChar |
|
4430 |
] |
|
4431 |
||
4432 |
"Modified: / 15.6.1998 / 17:21:17 / cg" |
|
4433 |
"Created: / 15.6.1998 / 17:22:13 / cg" |
|
608 | 4434 |
! ! |
4435 |
||
4436 |
!CharacterArray methodsFor:'queries'! |
|
4437 |
||
4429 | 4438 |
bitsPerCharacter |
4439 |
"return the underlying strings bitsPerCharacter |
|
4440 |
(i.e. is it a regular String or a TwoByteString)" |
|
4441 |
||
4442 |
^ self string bitsPerCharacter |
|
4443 |
||
4444 |
" |
|
4445 |
'hello' bitsPerCharacter |
|
4446 |
'hello' asText allBold bitsPerCharacter |
|
4447 |
" |
|
4448 |
! |
|
4449 |
||
608 | 4450 |
encoding |
1311 | 4451 |
"return the strings encoding, as a symbol. |
4452 |
Here, by default, we assume #iso8859 encoding. |
|
1241 | 4453 |
This has to be redefined in XXXEncodedString subclasses." |
1012
19fd2f72269f
keep track of encoding of 16bit strings
Claus Gittinger <cg@exept.de>
parents:
1008
diff
changeset
|
4454 |
|
1311 | 4455 |
^ #iso8859 |
4456 |
||
4457 |
"Modified: 27.4.1996 / 13:23:49 / cg" |
|
608 | 4458 |
! |
4459 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4460 |
hasChangeOfEmphasis |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4461 |
^ false |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4462 |
|
1381 | 4463 |
"Created: 12.5.1996 / 12:31:39 / cg" |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4464 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4465 |
|
1388 | 4466 |
heightOn:aGC |
4467 |
"return the size of the recevier in device units if displayed on aGC" |
|
4468 |
||
3337 | 4469 |
^ (aGC font on:aGC device) heightOf:self |
1388 | 4470 |
|
4471 |
" |
|
4472 |
'hello world' heightOn:(View new) |
|
4473 |
" |
|
4474 |
||
4475 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
4476 |
"Modified: 12.5.1996 / 20:32:05 / cg" |
|
4477 |
! |
|
4478 |
||
608 | 4479 |
isString |
4480 |
"return true, if the receiver is some kind of string; |
|
4481 |
true is returned here - redefinition of Object>>isString." |
|
4482 |
||
4483 |
^ true |
|
1235 | 4484 |
! |
4485 |
||
4486 |
leftIndent |
|
4487 |
"if the receiver starts with spaces, return the number of spaces |
|
4488 |
at the left - otherwise, return 0. |
|
4489 |
If the receiver consists of spaces only, return the receivers size." |
|
4490 |
||
4491 |
|index "{Class: SmallInteger }" |
|
4492 |
end "{Class: SmallInteger }"| |
|
4493 |
||
4494 |
index := 1. |
|
4495 |
end := self size. |
|
4496 |
[index <= end] whileTrue:[ |
|
4497 |
(self at:index) isSeparator ifFalse:[^ index - 1]. |
|
4498 |
index := index + 1 |
|
4499 |
]. |
|
4500 |
^ end |
|
4501 |
||
4502 |
" |
|
4503 |
' hello' leftIndent |
|
4504 |
'foo ' leftIndent |
|
4505 |
' ' leftIndent |
|
4506 |
" |
|
4507 |
||
4508 |
"Modified: 20.4.1996 / 19:28:43 / cg" |
|
1388 | 4509 |
! |
4510 |
||
4511 |
widthOn:aGC |
|
4512 |
"return ths size of the recevier in device units if displayed on aGC" |
|
4513 |
||
2554 | 4514 |
^ (aGC font on:aGC device) widthOf:self |
1388 | 4515 |
|
4516 |
" |
|
4517 |
'hello world' widthOn:(View new) |
|
4518 |
" |
|
4519 |
||
4520 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
2554 | 4521 |
"Modified: 17.4.1997 / 12:50:23 / cg" |
608 | 4522 |
! ! |
4523 |
||
4524 |
!CharacterArray methodsFor:'special string converting'! |
|
4525 |
||
4526 |
chopTo:maxLen |
|
4527 |
"if the receivers size is less or equal to maxLen, return it. |
|
4528 |
Otherwise, return a copy of the receiver, where some characters |
|
4529 |
in the middle have been removed for a total string length |
|
4530 |
of maxLen." |
|
4531 |
||
4532 |
|sz n1 n2| |
|
4533 |
||
4534 |
(sz := self size) > maxLen ifTrue:[ |
|
4535 |
n1 := n2 := maxLen // 2. |
|
4536 |
maxLen odd ifTrue:[ |
|
4537 |
n2 := n1 + 1 |
|
4538 |
]. |
|
4539 |
^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1) |
|
4540 |
] |
|
4541 |
||
4542 |
" |
|
4543 |
'12345678901234' chopTo:15 |
|
4544 |
'123456789012345' chopTo:15 |
|
4545 |
'1234567890123456' chopTo:15 |
|
4546 |
'aShortString' chopTo:15 |
|
4547 |
'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 |
|
4548 |
" |
|
4549 |
! |
|
4550 |
||
4551 |
contractAtBeginningTo:maxLen |
|
4552 |
"if the receivers size is less or equal to maxLen, return it. |
|
4553 |
Otherwise, return a copy of the receiver, where some characters |
|
4554 |
at the beginning have been replaced by '...' for a total string length |
|
4555 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
4556 |
||
4557 |
|sz| |
|
4558 |
||
4559 |
(sz := self size) > maxLen ifTrue:[ |
|
4560 |
^ '...' , (self copyFrom:(sz - (maxLen - 4))) |
|
4561 |
] |
|
4562 |
||
4563 |
" |
|
4564 |
'12345678901234' contractAtBeginningTo:15 |
|
4565 |
'123456789012345' contractAtBeginningTo:15 |
|
4566 |
'1234567890123456' contractAtBeginningTo:15 |
|
4567 |
'aShortString' contractAtBeginningTo:15 |
|
4568 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15 |
|
4569 |
" |
|
4570 |
! |
|
359 | 4571 |
|
608 | 4572 |
contractAtEndTo:maxLen |
4573 |
"if the receivers size is less or equal to maxLen, return it. |
|
4574 |
Otherwise, return a copy of the receiver, where some characters |
|
4575 |
at the end have been replaced by '...' for a total string length |
|
4576 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
4577 |
||
4578 |
|sz| |
|
4579 |
||
4580 |
(sz := self size) > maxLen ifTrue:[ |
|
4581 |
^ self copyReplaceFrom:maxLen - 3 |
|
4582 |
with:'...' |
|
4583 |
] |
|
4584 |
||
4585 |
" |
|
4586 |
'12345678901234' contractAtEndTo:15 |
|
4587 |
'123456789012345' contractAtEndTo:15 |
|
4588 |
'1234567890123456' contractAtEndTo:15 |
|
4589 |
'aShortString' contractAtEndTo:15 |
|
4590 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 |
|
4591 |
" |
|
4592 |
! |
|
4593 |
||
4594 |
contractTo:maxLen |
|
4595 |
"if the receivers size is less or equal to maxLen, return it. |
|
4596 |
Otherwise, return a copy of the receiver, where some characters |
|
4597 |
in the middle have been replaced by '...' for a total string length |
|
4598 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
4599 |
||
4600 |
|sz "{ SmallInteger }" |
|
4601 |
halfSize "{ SmallInteger }"| |
|
4602 |
||
4603 |
(sz := self size) > maxLen ifTrue:[ |
|
4604 |
halfSize := maxLen // 2. |
|
4605 |
^ self copyReplaceFrom:halfSize - 1 |
|
4606 |
to:sz - maxLen + halfSize + 1 |
|
4607 |
with:'...' |
|
4608 |
] |
|
4609 |
||
4610 |
" |
|
4611 |
'12345678901234' contractTo:15 |
|
4612 |
'123456789012345' contractTo:15 |
|
4613 |
'1234567890123456' contractTo:15 |
|
4614 |
'aShortString' contractTo:15 |
|
4615 |
'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 |
|
4616 |
" |
|
4617 |
! |
|
4618 |
||
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4619 |
expandPlaceholdersWith:argArrayOrDictionary |
608 | 4620 |
"return a copy of the receiver, where all %i escapes are |
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4621 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
608 | 4622 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
4623 |
in the new string 'hello world; how is this'. |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4624 |
As an extension, the argument may also be a dictionary, providing |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4625 |
values for character keys. |
4842 | 4626 |
In this case, %a .. %z and %(...) are also allowed. |
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4627 |
(%1..%9 require a numeric key in the dictionary, however) |
608 | 4628 |
To get a '%' character, use a '%%'-escape. |
4629 |
See also bindWith:... for VisualAge compatibility." |
|
4630 |
||
4842 | 4631 |
|expandedString next v key |
608 | 4632 |
idx "{ SmallInteger }" |
4842 | 4633 |
idx2 "{ SmallInteger }" |
608 | 4634 |
start "{ SmallInteger }" |
4635 |
stop "{ SmallInteger }"| |
|
4636 |
||
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4637 |
expandedString := self species new:0. |
608 | 4638 |
stop := self size. |
4639 |
start := 1. |
|
4640 |
[start <= stop] whileTrue:[ |
|
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4641 |
idx := self indexOf:$% startingAt:start. |
2737
9f29aecea39d
care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents:
2736
diff
changeset
|
4642 |
(idx == 0 or:[idx == stop]) ifTrue:[ |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4643 |
^ expandedString , (self copyFrom:start to:stop) |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4644 |
]. |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4645 |
"found a %" |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4646 |
expandedString := expandedString , (self copyFrom:start to:(idx - 1)). |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4647 |
next := self at:(idx + 1). |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4648 |
(next == $%) ifTrue:[ |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4649 |
expandedString := expandedString , '%' |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4650 |
] ifFalse:[ |
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4651 |
(next between:$1 and:$9) ifTrue:[ |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4652 |
v := argArrayOrDictionary at:(next digitValue) |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4653 |
] ifFalse:[ |
4842 | 4654 |
next == $( ifTrue:[ |
4655 |
idx2 := self indexOf:$) startingAt:idx+2. |
|
4656 |
key := self copyFrom:idx+2 to:idx2-1. |
|
4657 |
idx := idx2 - 1. |
|
4658 |
v := argArrayOrDictionary at:key asSymbol |
|
4659 |
] ifFalse:[ |
|
4660 |
v := argArrayOrDictionary at:next |
|
4661 |
] |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4662 |
]. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4663 |
expandedString := expandedString , v printString |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4664 |
]. |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4665 |
start := idx + 2 |
608 | 4666 |
]. |
4667 |
^ expandedString |
|
4668 |
||
4669 |
" |
|
4670 |
'hello %1' expandPlaceholdersWith:#('world') |
|
4671 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
4672 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
1308 | 4673 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
608 | 4674 |
" |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4675 |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4676 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4677 |
|dict| |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4678 |
|
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4679 |
dict := Dictionary new. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4680 |
dict at:1 put:'one'. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4681 |
dict at:$a put:'AAAAA'. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4682 |
'hello %1 %a' expandPlaceholdersWith:dict |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4683 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4684 |
|
2737
9f29aecea39d
care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents:
2736
diff
changeset
|
4685 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
608 | 4686 |
! |
4687 |
||
4688 |
withCRs |
|
4689 |
"return a new string consisting of receivers characters |
|
4690 |
with all \-characters replaced by cr-characters." |
|
4691 |
||
3656 | 4692 |
^ self copyReplaceAll:$\ with:(Character cr) |
608 | 4693 |
|
4694 |
" |
|
4695 |
'hello\world' withCRs |
|
4696 |
" |
|
3656 | 4697 |
|
4698 |
"Modified: / 18.7.1998 / 22:53:02 / cg" |
|
608 | 4699 |
! |
4700 |
||
4701 |
withEscapes |
|
4702 |
"return a new string consisting of receivers characters |
|
4703 |
with all \X-character escapes replaced by corresponding-characters. |
|
4704 |
(similar to the way C-language Strings are converted). |
|
4705 |
The following escapes are supported: |
|
1008 | 4706 |
\r return character |
4707 |
\n newline character |
|
4708 |
\b backspace character |
|
4709 |
\f formfeed character |
|
4710 |
\t tab character |
|
4711 |
\e escape character |
|
4712 |
\\ the \ character itself |
|
4713 |
\nnn three digit octal number defining the characters ascii value |
|
4714 |
\other other |
|
608 | 4715 |
|
4716 |
Notice, that \' is NOT a valid escape, since the general syntax of |
|
4717 |
string constants is not affected by this method. |
|
4718 |
||
4719 |
Although easily implementable, this is NOT done automatically |
|
4720 |
by the compiler (due to a lack of a language standard for this). |
|
4721 |
However, the compiler may detect sends ot #withEscapes to string literals |
|
4722 |
and place a modified string constant into the binary/byte-code. |
|
4723 |
Therefore, no runtime penalty will be payed for using these escapes. |
|
4724 |
(not in pre 2.11 versions) |
|
4725 |
" |
|
4726 |
||
4727 |
|sz "{ SmallInteger }" |
|
4728 |
newSize "{ SmallInteger }" |
|
4729 |
srcIdx "{ SmallInteger }" |
|
4730 |
dstIdx "{ SmallInteger }" |
|
4731 |
val "{ SmallInteger }" |
|
1381 | 4732 |
newString next hasEmphasis e| |
359 | 4733 |
|
4734 |
" |
|
608 | 4735 |
first, count the number of escapes, to allow preallocation |
4736 |
of the new string ... |
|
4737 |
(it is faster to scan the string twice than to reallocate it multiple |
|
4738 |
times in a WriteStream) |
|
4739 |
" |
|
4740 |
sz := newSize := self size. |
|
4741 |
srcIdx := 1. |
|
4742 |
[(srcIdx := self indexOf:$\ startingAt:srcIdx) ~~ 0] whileTrue:[ |
|
1008 | 4743 |
srcIdx == sz ifFalse:[ |
4744 |
newSize := newSize - 1. |
|
4745 |
srcIdx := srcIdx + 1. |
|
4746 |
next := self at:srcIdx. |
|
4747 |
next == $0 ifTrue:[ |
|
3527
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4748 |
[srcIdx < sz and:[next isDigit]] whileTrue:[ |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4749 |
newSize := newSize - 1. srcIdx := srcIdx + 1. next := self at:srcIdx. |
1008 | 4750 |
] |
4751 |
]. |
|
4752 |
]. |
|
4753 |
srcIdx := srcIdx + 1. |
|
608 | 4754 |
]. |
4755 |
||
4756 |
newSize == sz ifTrue:[ |
|
1008 | 4757 |
^ self |
608 | 4758 |
]. |
4759 |
||
4760 |
newString := self species new:newSize. |
|
1381 | 4761 |
|
4762 |
hasEmphasis := self hasChangeOfEmphasis. |
|
4763 |
||
608 | 4764 |
" |
4765 |
copy over, replace escapes |
|
4766 |
" |
|
4767 |
srcIdx := dstIdx := 1. |
|
4768 |
[srcIdx <= sz] whileTrue:[ |
|
1008 | 4769 |
next := self at:srcIdx. |
1381 | 4770 |
hasEmphasis ifTrue:[ |
4771 |
e := self emphasisAt:srcIdx |
|
4772 |
]. |
|
1008 | 4773 |
srcIdx := srcIdx + 1. |
4774 |
next == $\ ifTrue:[ |
|
4775 |
srcIdx <= sz ifTrue:[ |
|
4776 |
next := self at:srcIdx. |
|
4777 |
srcIdx := srcIdx + 1. |
|
4778 |
next == $r ifTrue:[ |
|
4779 |
next := Character return |
|
4780 |
] ifFalse:[ |
|
4781 |
next == $n ifTrue:[ |
|
4782 |
next := Character nl |
|
4783 |
] ifFalse:[ |
|
4784 |
next == $b ifTrue:[ |
|
4785 |
next := Character backspace |
|
4786 |
] ifFalse:[ |
|
4787 |
next == $f ifTrue:[ |
|
4788 |
next := Character newPage |
|
4789 |
] ifFalse:[ |
|
4790 |
next == $t ifTrue:[ |
|
4791 |
next := Character tab |
|
4792 |
] ifFalse:[ |
|
4793 |
next == $e ifTrue:[ |
|
4794 |
next := Character esc |
|
4795 |
] ifFalse:[ |
|
4796 |
next == $0 ifTrue:[ |
|
4797 |
val := 0. |
|
3527
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4798 |
[next notNil and:[next isDigit]] whileTrue:[ |
1008 | 4799 |
val := val * 8 + next digitValue. |
3527
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4800 |
srcIdx <= sz ifTrue:[ |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4801 |
next := self at:srcIdx. |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4802 |
srcIdx := srcIdx + 1. |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4803 |
] ifFalse:[ |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4804 |
next := nil |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4805 |
] |
1008 | 4806 |
]. |
4807 |
next := Character value:val. |
|
4808 |
] |
|
4809 |
] |
|
4810 |
] |
|
4811 |
] |
|
4812 |
] |
|
4813 |
] |
|
4814 |
]. |
|
4815 |
]. |
|
4816 |
]. |
|
4817 |
newString at:dstIdx put:next. |
|
1381 | 4818 |
hasEmphasis ifTrue:[ |
4819 |
newString emphasisAt:dstIdx put:e |
|
4820 |
]. |
|
1008 | 4821 |
dstIdx := dstIdx + 1. |
608 | 4822 |
]. |
4823 |
^ newString |
|
4824 |
||
4825 |
" |
|
4826 |
'hello world' withEscapes |
|
4827 |
'hello\world' withEscapes |
|
4828 |
'hello\world\' withEscapes |
|
4829 |
'hello world\' withEscapes |
|
4830 |
'hello\tworld' withEscapes |
|
4831 |
'hello\nworld\na\n\tnice\n\t\tstring' withEscapes |
|
4832 |
'hello\tworld\n' withEscapes |
|
4833 |
'hello\010world' withEscapes |
|
4834 |
'hello\r\nworld' withEscapes |
|
4835 |
" |
|
1008 | 4836 |
|
1381 | 4837 |
"Modified: 12.5.1996 / 12:53:34 / cg" |
608 | 4838 |
! |
4839 |
||
4117 | 4840 |
withMatchEscapes |
4841 |
"return a copy of the receiver with all match characters escaped |
|
4842 |
by $\ characters (to be usable as a match string). |
|
4843 |
Return the receiver, if there are none." |
|
4844 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
4845 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
4846 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
4847 |
escape := self class matchEscapeCharacter. |
4117 | 4848 |
|
4849 |
in := self readStream. |
|
4850 |
out := '' writeStream. |
|
4851 |
[in atEnd] whileFalse:[ |
|
4852 |
c := in next. |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
4853 |
(c == escape or:['*[#' includes:c]) ifTrue:[ |
4117 | 4854 |
out nextPut:$\. |
4855 |
]. |
|
4856 |
out nextPut:c. |
|
4857 |
]. |
|
4858 |
^ out contents. |
|
4859 |
||
4860 |
" |
|
4861 |
'*foo' withMatchEscapes |
|
4862 |
'\*foo' withMatchEscapes |
|
4863 |
'*foo' withMatchEscapes |
|
4864 |
'\\*foo' withMatchEscapes |
|
4865 |
'foo*' withMatchEscapes |
|
4866 |
'foo\*' withMatchEscapes |
|
4867 |
'foo\' withMatchEscapes |
|
4868 |
'f*o*o' withMatchEscapes |
|
4869 |
" |
|
4870 |
||
4871 |
"Modified: 2.4.1997 / 18:13:04 / cg" |
|
4872 |
! |
|
4873 |
||
608 | 4874 |
withTabs |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4875 |
"return a string consisting of the receivers characters |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4876 |
where leading spaces are replaced by tabulator characters (assuming 8-col tabs). |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4877 |
Notice: if the receiver does not contain any tabs, it is returned unchanged; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4878 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4879 |
Limitation: only the very first spaces are replaced |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4880 |
(i.e. if the receiver contains newLine characters, |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4881 |
no tabs are inserted after those lineBreaks)" |
608 | 4882 |
|
4883 |
|idx "{ SmallInteger }" |
|
4884 |
nTabs "{ SmallInteger }" |
|
4885 |
newString| |
|
4886 |
||
4887 |
idx := self findFirst:[:c | (c ~~ Character space)]. |
|
4888 |
nTabs := (idx-1) // 8. |
|
4889 |
nTabs == 0 ifTrue:[^ self]. |
|
4890 |
||
4891 |
"any tabs" |
|
4892 |
newString := self class new:(self size - (nTabs * 7)). |
|
4893 |
newString atAll:(1 to:nTabs) put:(Character tab). |
|
4894 |
newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1). |
|
4895 |
^ newString |
|
4896 |
||
4897 |
" |
|
4898 |
'12345678901234567890' withTabs |
|
4899 |
' 8901234567890' withTabs |
|
4900 |
' 901234567890' withTabs |
|
4901 |
' 67890' withTabs |
|
4902 |
' 7890' withTabs |
|
4903 |
' 890' withTabs |
|
4904 |
" |
|
4905 |
! |
|
4906 |
||
4907 |
withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4908 |
"return a string consisting of the receivers characters, |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4909 |
where all tabulator characters are expanded into spaces (assuming 8-col tabs). |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4910 |
Notice: if the receiver does not contain any tabs, it is returned unchanged; |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4911 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4912 |
This does handle multiline strings." |
608 | 4913 |
|
1381 | 4914 |
|col "{ SmallInteger }" |
4915 |
str ch |
|
4916 |
dstIdx "{ SmallInteger }" |
|
4917 |
newSz "{ SmallInteger }" |
|
4918 |
sz "{ SmallInteger }" |
|
4919 |
hasEmphasis e| |
|
608 | 4920 |
|
4921 |
(self includes:(Character tab)) ifFalse:[^ self]. |
|
1381 | 4922 |
|
4923 |
sz := self size. |
|
4924 |
||
4925 |
"/ count the new size first, instead of |
|
4926 |
"/ multiple resizing (better for large strings) |
|
4927 |
||
4928 |
col := 1. newSz := 0. |
|
4929 |
1 to:sz do:[:srcIdx | |
|
4930 |
ch := self at:srcIdx. |
|
4931 |
ch == Character tab ifFalse:[ |
|
4932 |
col := col + 1. |
|
4933 |
newSz := newSz + 1. |
|
4934 |
ch == Character cr ifTrue:[ |
|
4935 |
col := 1 |
|
4936 |
]. |
|
4937 |
] ifTrue:[ |
|
4938 |
(col \\ 8) to:8 do:[:ii | |
|
4939 |
newSz := newSz + 1. |
|
4940 |
col := col + 1 |
|
4941 |
]. |
|
4942 |
] |
|
608 | 4943 |
]. |
1381 | 4944 |
|
4945 |
str := self species new:newSz. |
|
4946 |
||
4947 |
hasEmphasis := self hasChangeOfEmphasis. |
|
4948 |
||
4949 |
col := 1. dstIdx := 1. |
|
4950 |
1 to:sz do:[:srcIdx | |
|
4951 |
ch := self at:srcIdx. |
|
4952 |
||
4953 |
ch == Character tab ifFalse:[ |
|
4954 |
col := col + 1. |
|
4955 |
ch == Character cr ifTrue:[ |
|
4956 |
col := 1 |
|
4957 |
]. |
|
4958 |
hasEmphasis ifTrue:[ |
|
4959 |
e := self emphasisAt:srcIdx. |
|
4960 |
str emphasisAt:dstIdx put:e |
|
4961 |
]. |
|
4962 |
str at:dstIdx put:ch. |
|
4963 |
dstIdx := dstIdx + 1 |
|
4964 |
] ifTrue:[ |
|
4965 |
(col \\ 8) to:8 do:[:ii | |
|
4966 |
str at:dstIdx put:Character space. |
|
4967 |
dstIdx := dstIdx + 1. |
|
4968 |
col := col + 1 |
|
4969 |
]. |
|
4970 |
] |
|
4971 |
]. |
|
4972 |
^ str |
|
608 | 4973 |
|
4974 |
" |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4975 |
('1' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4976 |
('12345' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4977 |
('123456' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4978 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4979 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4980 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4981 |
|
608 | 4982 |
(String with:Character tab |
1381 | 4983 |
with:Character tab |
4984 |
with:$1) withTabsExpanded |
|
608 | 4985 |
|
4986 |
(String with:Character tab |
|
1381 | 4987 |
with:$1 |
4988 |
with:Character tab |
|
4989 |
with:$2) withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4990 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4991 |
(String with:Character tab |
1381 | 4992 |
with:$1 |
4993 |
with:Character cr |
|
4994 |
with:Character tab |
|
4995 |
with:$2) withTabsExpanded |
|
608 | 4996 |
" |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4997 |
|
1381 | 4998 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
608 | 4999 |
! |
5000 |
||
5001 |
withoutCRs |
|
5002 |
"return a new collection consisting of receivers elements |
|
5003 |
with all cr-characters replaced by \-characters. |
|
5004 |
This is the reverse operation of withCRs." |
|
5005 |
||
3656 | 5006 |
^ self copyReplaceAll:(Character cr) with:$\ |
608 | 5007 |
" |
5008 |
'hello |
|
5009 |
world' withoutCRs |
|
359 | 5010 |
" |
3656 | 5011 |
|
5012 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
608 | 5013 |
! |
5014 |
||
5015 |
withoutLeadingSeparators |
|
5016 |
"return a copy of myself without leading separators. |
|
5017 |
Notice: this does remove tabs, newline or any other whitespace. |
|
5018 |
Returns an empty string, if the receiver consist only of whitespace." |
|
5019 |
||
5020 |
|index| |
|
5021 |
||
5022 |
index := self indexOfNonSeparatorStartingAt:1. |
|
5023 |
index ~~ 0 ifTrue:[ |
|
5024 |
index == 1 ifTrue:[ |
|
5025 |
^ self |
|
5026 |
]. |
|
5027 |
^ self copyFrom:index |
|
5028 |
]. |
|
5029 |
^ '' |
|
5030 |
||
5031 |
" |
|
5032 |
' foo ' withoutLeadingSeparators |
|
5033 |
'foo ' withoutLeadingSeparators |
|
5034 |
' foo' withoutLeadingSeparators |
|
5035 |
' ' withoutLeadingSeparators |
|
5036 |
'foo' withoutLeadingSeparators |
|
5037 |
(' ' , Character tab asString , ' foo ') withoutLeadingSeparators inspect |
|
5038 |
" |
|
5039 |
! |
|
5040 |
||
4117 | 5041 |
withoutMatchEscapes |
5042 |
"return a copy of the receiver with all $\ removed or |
|
5043 |
the receiver, if there are none." |
|
5044 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5045 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5046 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5047 |
escape := self class matchEscapeCharacter. |
4117 | 5048 |
|
5049 |
in := self readStream. |
|
5050 |
out := self species new writeStream. |
|
5051 |
[in atEnd] whileFalse:[ |
|
5052 |
c := in next. |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5053 |
c == escape ifTrue:[ |
4117 | 5054 |
in atEnd ifFalse:[ |
5055 |
c := in next. |
|
5056 |
] |
|
5057 |
]. |
|
5058 |
out nextPut:c. |
|
5059 |
]. |
|
5060 |
^ out contents. |
|
5061 |
||
5062 |
" |
|
5063 |
'*foo' withoutMatchEscapes |
|
5064 |
'\*foo' withoutMatchEscapes |
|
5065 |
'*foo' withoutMatchEscapes |
|
5066 |
'\\*foo' withoutMatchEscapes |
|
5067 |
'foo*' withoutMatchEscapes |
|
5068 |
'foo\*' withoutMatchEscapes |
|
5069 |
'foo\' withoutMatchEscapes |
|
5070 |
'f\*o\*o' withoutMatchEscapes |
|
5071 |
" |
|
5072 |
||
5073 |
"Modified: 30.6.1997 / 13:40:23 / cg" |
|
5074 |
! |
|
5075 |
||
608 | 5076 |
withoutSeparators |
5077 |
"return a copy of myself without leading and trailing whitespace. |
|
4156 | 5078 |
(but whiteSpace in-between is preserved) |
608 | 5079 |
Whitespace is space, tab, newline, formfeed. |
5080 |
Use withoutSpaces, if you want to remove spaces only." |
|
5081 |
||
5082 |
|startIndex "{ Class: SmallInteger }" |
|
5083 |
endIndex "{ Class: SmallInteger }" |
|
5084 |
sz| |
|
5085 |
||
5086 |
sz := self size. |
|
5087 |
startIndex := 1. |
|
5088 |
endIndex := sz. |
|
5089 |
||
5090 |
[(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[ |
|
4156 | 5091 |
startIndex := startIndex + 1 |
608 | 5092 |
]. |
5093 |
[(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[ |
|
4156 | 5094 |
endIndex := endIndex - 1 |
608 | 5095 |
]. |
5096 |
startIndex > endIndex ifTrue:[ |
|
4156 | 5097 |
^ '' |
608 | 5098 |
]. |
5099 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
|
4156 | 5100 |
^ self |
608 | 5101 |
]. |
5102 |
^ self copyFrom:startIndex to:endIndex |
|
5103 |
||
5104 |
" |
|
5105 |
' foo ' withoutSeparators |
|
5106 |
' foo' withoutSeparators |
|
5107 |
'foo ' withoutSeparators |
|
5108 |
' ' withoutSeparators |
|
5109 |
(' foo' , Character tab asString , ' ') withoutSeparators inspect |
|
5110 |
" |
|
5111 |
! |
|
5112 |
||
5113 |
withoutSpaces |
|
5114 |
"return a copy of myself without leading and trailing spaces. |
|
4156 | 5115 |
(but spaces in-between are preserved) |
608 | 5116 |
Notice: this does NOT remove tabs, newline or any other whitespace. |
5117 |
Use withoutSeparators for this." |
|
5118 |
||
5119 |
|startIndex "{ Class: SmallInteger }" |
|
5120 |
endIndex "{ Class: SmallInteger }" |
|
5121 |
sz| |
|
5122 |
||
5123 |
sz := self size. |
|
5124 |
startIndex := 1. |
|
5125 |
endIndex := sz. |
|
5126 |
||
5127 |
[(startIndex < endIndex) and:[(self at:startIndex) == Character space]] whileTrue:[ |
|
4156 | 5128 |
startIndex := startIndex + 1 |
608 | 5129 |
]. |
5130 |
[(endIndex > 1) and:[(self at:endIndex) == Character space]] whileTrue:[ |
|
4156 | 5131 |
endIndex := endIndex - 1 |
608 | 5132 |
]. |
5133 |
startIndex > endIndex ifTrue:[ |
|
4156 | 5134 |
^ '' |
608 | 5135 |
]. |
5136 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
|
4156 | 5137 |
^ self |
608 | 5138 |
]. |
5139 |
^ self copyFrom:startIndex to:endIndex |
|
5140 |
||
5141 |
" |
|
5142 |
' foo ' withoutSpaces |
|
5143 |
'foo ' withoutSpaces |
|
5144 |
' foo' withoutSpaces |
|
5145 |
' ' withoutSpaces |
|
4156 | 5146 |
'a b' withoutSpaces |
608 | 5147 |
(' foo' , Character tab asString , ' ') withoutSpaces inspect |
5148 |
" |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5149 |
! |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5150 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5151 |
withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5152 |
"return a copy of myself without trailing separators. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5153 |
Notice: this does remove tabs, newline or any other whitespace. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5154 |
Returns an empty string, if the receiver consist only of whitespace." |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5155 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5156 |
|index| |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5157 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5158 |
index := self size. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5159 |
[index ~~ 0] whileTrue:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5160 |
(self at:index) isSeparator ifFalse:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5161 |
^ self copyTo:index |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5162 |
]. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5163 |
index := index - 1 |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5164 |
]. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5165 |
^ '' |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5166 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5167 |
" |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5168 |
' foo ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5169 |
'foo ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5170 |
' foo' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5171 |
' ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5172 |
'foo' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5173 |
(' ' , Character tab asString , ' foo ') withoutTrailingSeparators inspect |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5174 |
(' foo' , Character tab asString) withoutTrailingSeparators inspect |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5175 |
" |
608 | 5176 |
! ! |
5177 |
||
5178 |
!CharacterArray methodsFor:'substring searching'! |
|
5179 |
||
5180 |
findString:subString |
|
5181 |
"find a substring. if found, return the index; |
|
5182 |
if not found, return 0." |
|
5183 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
5184 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 |
608 | 5185 |
|
5186 |
" |
|
5187 |
'hello world' findString:'llo' |
|
5188 |
'hello world' findString:'ole' |
|
5189 |
" |
|
5190 |
! |
|
5191 |
||
5192 |
findString:subString ifAbsent:exceptionBlock |
|
5193 |
"find a substring. If found, return the index; |
|
5194 |
if not found, return the result of evaluating exceptionBlock." |
|
5195 |
||
5196 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock |
|
5197 |
! |
|
5198 |
||
5199 |
findString:subString startingAt:index |
|
5200 |
"find a substring, starting at index. if found, return the index; |
|
5201 |
if not found, return 0." |
|
5202 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
5203 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:0 |
608 | 5204 |
|
5205 |
" |
|
5206 |
'hello yello' findString:'llo' startingAt:1 |
|
5207 |
'hello yello' findString:'llo' startingAt:5 |
|
5208 |
'hello yello' findString:'llo' startingAt:15 |
|
5209 |
" |
|
5210 |
! |
|
5211 |
||
5212 |
findString:subString startingAt:index ifAbsent:exceptionBlock |
|
5213 |
"find a substring, starting at index. if found, return the index; |
|
5214 |
if not found, return the result of evaluating exceptionBlock." |
|
5215 |
||
5216 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
|
5217 |
! |
|
5218 |
||
5219 |
includesString:aString |
|
5220 |
"return true, if a substring is contained in the receiver" |
|
5221 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
5222 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0) ~~ 0 |
608 | 5223 |
|
5224 |
" |
|
5225 |
'hello world' includesString:'hel' |
|
5226 |
'hello world' includesString:'rld' |
|
5227 |
'hello world' includesString:'llo' |
|
5228 |
'hello world' includesString:'LLO' |
|
5229 |
" |
|
5230 |
! |
|
5231 |
||
5232 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
|
5233 |
"find a substring, starting at index. if found, return the index; |
|
5234 |
if not found, return the result of evaluating exceptionBlock. |
|
5235 |
This is a q&d hack - not very efficient" |
|
5236 |
||
5237 |
|firstChar found |
|
5238 |
startIndex "{ Class: SmallInteger }" |
|
5239 |
subSize "{ Class: SmallInteger }" |
|
5240 |
mySize "{ Class: SmallInteger }" |
|
5241 |
runIdx "{ Class: SmallInteger }" | |
|
5242 |
||
5243 |
subSize := subString size. |
|
5244 |
subSize == 0 ifTrue:[^ index]. "empty string matches" |
|
5245 |
mySize := self size. |
|
5246 |
firstChar := subString at:1. |
|
5247 |
startIndex := self indexOf:firstChar startingAt:index. |
|
5248 |
[startIndex == 0] whileFalse:[ |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5249 |
runIdx := startIndex. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5250 |
found := true. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5251 |
1 to:subSize do:[:i | |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5252 |
runIdx > mySize ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5253 |
found := false |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5254 |
] ifFalse:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5255 |
(subString at:i) ~= (self at:runIdx) ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5256 |
found := false |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5257 |
] |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5258 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5259 |
runIdx := runIdx + 1 |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5260 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5261 |
found ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5262 |
^ startIndex |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5263 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5264 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1) |
608 | 5265 |
]. |
5266 |
^ exceptionBlock value |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5267 |
|
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5268 |
"Modified: 23.2.1996 / 15:35:15 / cg" |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5269 |
! |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5270 |
|
652 | 5271 |
restAfter:keyword withoutSeparators:strip |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5272 |
"compare the left of the receiver with keyword, |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5273 |
if it matches return the right. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5274 |
Finally, if strip is true, remove whiteSpace. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5275 |
This method is used to match and extract lines of the form: |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5276 |
something: rest |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
5277 |
where we are interested in rest, but only if the receiver string |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5278 |
begins with something. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5279 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5280 |
You may wonder why such a specialized method exists here |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5281 |
- this is so common when processing mailboxes, |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5282 |
rcs files, nntp/pop3 responses, that is was considered worth |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5283 |
a special method here to avoid having the code below a hundred |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5284 |
times in variuos places." |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5285 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5286 |
|rest| |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5287 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5288 |
(self startsWith:keyword) ifTrue:[ |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5289 |
rest := self copyFrom:(keyword size + 1). |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5290 |
strip ifTrue:[ |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5291 |
rest := rest withoutSeparators |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5292 |
]. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5293 |
^ rest |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5294 |
]. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5295 |
^ nil |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5296 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5297 |
" |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5298 |
'foo: hello world' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5299 |
'funny: something' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5300 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5301 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5302 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:false |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5303 |
" |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5304 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5305 |
"Created: 25.11.1995 / 11:04:18 / cg" |
328 | 5306 |
! ! |
5307 |
||
255 | 5308 |
!CharacterArray methodsFor:'testing'! |
64 | 5309 |
|
1613 | 5310 |
continuesWith:aString startingAt:startIndex |
5311 |
"return true, if the receiver beginning at startIndex |
|
5312 |
contains the characters in aString." |
|
5313 |
||
5314 |
|sz "{Class: SmallInteger }" |
|
5315 |
idx "{Class: SmallInteger }"| |
|
5316 |
||
5317 |
sz := aString size. |
|
5318 |
idx := startIndex. |
|
5319 |
||
5320 |
1 to:sz do:[:i | |
|
5321 |
(self at:idx) ~~ (aString at:i) ifTrue:[^ false]. |
|
5322 |
idx := idx + 1 |
|
5323 |
]. |
|
5324 |
^ true |
|
5325 |
||
5326 |
" |
|
5327 |
'hello world' continuesWith:'world' startingAt:6 |
|
5328 |
'hello world' continuesWith:'world' startingAt:7 |
|
5329 |
" |
|
5330 |
||
5331 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
5332 |
"Modified: 26.7.1996 / 19:08:36 / cg" |
|
5333 |
! |
|
5334 |
||
64 | 5335 |
countWords |
5336 |
"return the number of words, which are separated by separators" |
|
5337 |
||
92 | 5338 |
|tally "{ Class: SmallInteger }" |
5339 |
start "{ Class: SmallInteger }" |
|
5340 |
mySize "{ Class: SmallInteger }" |
|
5341 |
stop ch| |
|
64 | 5342 |
|
5343 |
tally := 0. |
|
5344 |
start := 1. |
|
5345 |
mySize := self size. |
|
5346 |
[start <= mySize] whileTrue:[ |
|
154 | 5347 |
ch := self at:start. |
5348 |
ch isSeparator ifTrue:[ |
|
5349 |
start := start + 1 |
|
5350 |
] ifFalse:[ |
|
5351 |
stop := self indexOfSeparatorStartingAt:start. |
|
5352 |
(stop == 0) ifTrue:[ |
|
5353 |
stop := mySize + 1 |
|
5354 |
]. |
|
5355 |
tally := tally + 1. |
|
5356 |
start := stop |
|
5357 |
] |
|
64 | 5358 |
]. |
5359 |
^ tally |
|
5360 |
||
92 | 5361 |
" |
5362 |
'hello world isnt this nice' countWords' |
|
5363 |
" |
|
64 | 5364 |
! |
5365 |
||
1381 | 5366 |
endsWith:aString |
5367 |
"return true, if the receiver ends with something, aString." |
|
5368 |
||
5369 |
|s| |
|
5370 |
||
5371 |
(s := self string) ~~ self ifTrue:[ |
|
5372 |
^ s endsWith:aString |
|
5373 |
]. |
|
5374 |
^ super endsWith:aString |
|
5375 |
||
5376 |
" |
|
5377 |
'hello world' endsWith:'world' |
|
5378 |
'hello world' asText allBold endsWith:'world' |
|
5379 |
" |
|
5380 |
||
5381 |
"Modified: 12.5.1996 / 15:49:18 / cg" |
|
5382 |
! |
|
5383 |
||
608 | 5384 |
isAlphaNumeric |
5385 |
"return true, if the receiver is some alphanumeric word; |
|
5386 |
i.e. consists of a letter followed by letters or digits." |
|
64 | 5387 |
|
608 | 5388 |
self size == 0 ifTrue:[ |
5389 |
"mhmh what is this ?" |
|
5390 |
^ false |
|
64 | 5391 |
]. |
608 | 5392 |
(self at:1) isLetter ifFalse:[^ false]. |
5393 |
self do:[:char | |
|
5394 |
char isLetterOrDigit ifFalse:[^ false]. |
|
5395 |
]. |
|
5396 |
^ true |
|
64 | 5397 |
|
77 | 5398 |
" |
608 | 5399 |
'helloWorld' isAlphaNumeric |
5400 |
'foo1234' isAlphaNumeric |
|
5401 |
'f1234' isAlphaNumeric |
|
5402 |
'1234' isAlphaNumeric |
|
5403 |
'+' isAlphaNumeric |
|
77 | 5404 |
" |
5405 |
! |
|
5406 |
||
608 | 5407 |
isBlank |
5408 |
"return true, if the receiver contains spaces only" |
|
77 | 5409 |
|
608 | 5410 |
self do:[:char | |
5411 |
char ~~ Character space ifTrue:[^ false]. |
|
77 | 5412 |
]. |
608 | 5413 |
^ true |
64 | 5414 |
! |
5415 |
||
5416 |
levenshteinTo:aString |
|
5417 |
"return the levenshtein distance to the argument, aString; |
|
5418 |
this value corrensponds to the number of replacements that have to be |
|
5419 |
made to get aString from the receiver. |
|
196 | 5420 |
See IEEE transactions on Computers 1976 Pg 172 ff." |
64 | 5421 |
|
327 | 5422 |
" |
5423 |
in the following, we assum that ommiting a character |
|
5424 |
is less of an error than inserting an extra character. |
|
5425 |
Therefore the different insertion (i) and deletion (d) |
|
5426 |
values. |
|
5427 |
" |
|
5428 |
||
64 | 5429 |
^ self levenshteinTo:aString s:4 c:1 i:2 d:6 |
154 | 5430 |
|
5431 |
" |
|
5432 |
'ocmprt' levenshteinTo:'computer' |
|
5433 |
'computer' levenshteinTo:'computer' |
|
5434 |
'ocmputer' levenshteinTo:'computer' |
|
5435 |
'cmputer' levenshteinTo:'computer' |
|
327 | 5436 |
'computer' levenshteinTo:'cmputer' |
154 | 5437 |
'Computer' levenshteinTo:'computer' |
5438 |
" |
|
64 | 5439 |
! |
5440 |
||
5441 |
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight |
|
196 | 5442 |
"parametrized levenshtein. |
5443 |
return the levenshtein distance to the argument, aString; |
|
5444 |
this value corrensponds to the number of replacements that have to be |
|
5445 |
made to get aString from the receiver. |
|
5446 |
The arguments are the costs for substitution, case-change, insertion and |
|
5447 |
deletion of a character. |
|
5448 |
See IEEE transactions on Computers 1976 Pg 172 ff" |
|
64 | 5449 |
|
5450 |
|d "delta matrix" |
|
196 | 5451 |
len1 "{ Class: SmallInteger }" |
5452 |
len2 "{ Class: SmallInteger }" |
|
5453 |
dim "{ Class: SmallInteger }" |
|
5454 |
prevRow row col |
|
5455 |
dimPlus1 "{ Class: SmallInteger }" |
|
64 | 5456 |
min pp c1 c2| |
5457 |
||
5458 |
len1 := self size. |
|
5459 |
len2 := aString size. |
|
5460 |
||
5461 |
"create the help-matrix" |
|
5462 |
||
5463 |
dim := len1 max:len2. |
|
5464 |
dimPlus1 := dim + 1. |
|
5465 |
||
5466 |
d := Array new:dimPlus1. |
|
5467 |
1 to:dimPlus1 do:[:i | |
|
154 | 5468 |
d at:i put:(Array new:dimPlus1) |
64 | 5469 |
]. |
5470 |
||
5471 |
"init help-matrix" |
|
5472 |
||
5473 |
(d at:1) at:1 put:0. |
|
5474 |
row := d at:1. |
|
5475 |
1 to:dim do:[:j | |
|
154 | 5476 |
row at:(j + 1) put:( (row at:j) + insrtWeight ) |
64 | 5477 |
]. |
5478 |
||
5479 |
1 to:dim do:[:i | |
|
154 | 5480 |
(d at:(i + 1)) at:1 put:( ((d at:i) at:1) + deleteWeight ) |
64 | 5481 |
]. |
5482 |
||
5483 |
1 to:len1 do:[:i | |
|
154 | 5484 |
c1 := self at:i. |
5485 |
1 to:len2 do:[:j | |
|
5486 |
c2 := aString at:j. |
|
5487 |
(c1 == c2) ifTrue:[ |
|
5488 |
pp := 0 |
|
5489 |
] ifFalse:[ |
|
5490 |
(c1 asLowercase == c2 asLowercase) ifTrue:[ |
|
5491 |
pp := caseWeight |
|
5492 |
] ifFalse:[ |
|
5493 |
pp := substWeight |
|
5494 |
] |
|
5495 |
]. |
|
5496 |
prevRow := d at:i. |
|
5497 |
row := d at:(i + 1). |
|
5498 |
col := j + 1. |
|
5499 |
min := (prevRow at:j) + pp. |
|
5500 |
min := min min:( (row at:j) + insrtWeight). |
|
5501 |
min := min min:( (prevRow at:col) + deleteWeight). |
|
5502 |
row at:col put: min |
|
5503 |
] |
|
64 | 5504 |
]. |
5505 |
||
5506 |
^ (d at:(len1 + 1)) at:(len2 + 1) |
|
5507 |
! |
|
5508 |
||
608 | 5509 |
numArgs |
5510 |
"treating the receiver as a message selector, return how many arguments would it take" |
|
5511 |
||
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5512 |
|binopChars firstChar| |
608 | 5513 |
|
5514 |
(self size > 2) ifFalse:[ |
|
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5515 |
binopChars := Scanner binarySelectorCharacters. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5516 |
firstChar := self at:1. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5517 |
|
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5518 |
(self size == 1) ifTrue:[ |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5519 |
((binopChars occurrencesOf:firstChar) == 0) ifTrue:[^ 0]. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5520 |
^ 1 |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5521 |
]. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5522 |
((binopChars occurrencesOf:firstChar) == 0) ifFalse:[ |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5523 |
((binopChars occurrencesOf:(self at:2)) == 0) ifFalse:[^ 1] |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5524 |
] |
608 | 5525 |
]. |
5526 |
^ self occurrencesOf:$: |
|
5527 |
||
5528 |
" |
|
5529 |
'foo:bar:' numArgs |
|
5530 |
#foo:bar: numArgs |
|
5531 |
'hello' numArgs |
|
5532 |
'+' numArgs |
|
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5533 |
'|' numArgs |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5534 |
'?' numArgs |
608 | 5535 |
" |
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5536 |
|
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5537 |
"Modified: 4.1.1997 / 14:16:14 / cg" |
608 | 5538 |
! |
5539 |
||
5540 |
partsIfSelector |
|
5541 |
"treat the receiver as a message selector, return a collection of parts." |
|
5542 |
||
5543 |
|idx1 "{ Class: SmallInteger }" |
|
5544 |
coll idx2 sz| |
|
5545 |
||
5546 |
coll := OrderedCollection new. |
|
5547 |
idx1 := 1. |
|
5548 |
sz := self size. |
|
5549 |
[true] whileTrue:[ |
|
5550 |
idx2 := self indexOf:$: startingAt:idx1 + 1. |
|
5551 |
(idx2 == 0 or:[idx2 == sz]) ifTrue:[ |
|
5552 |
coll add:(self copyFrom:idx1). |
|
5553 |
^ coll |
|
5554 |
]. |
|
5555 |
coll add:(self copyFrom:idx1 to:idx2). |
|
5556 |
idx1 := idx2 + 1 |
|
5557 |
]. |
|
5558 |
||
5559 |
" |
|
5560 |
'foo:bar:' partsIfSelector |
|
5561 |
#foo:bar: partsIfSelector |
|
5562 |
'hello' partsIfSelector |
|
5563 |
'+' partsIfSelector |
|
5564 |
" |
|
5565 |
! |
|
5566 |
||
64 | 5567 |
spellAgainst: aString |
5568 |
"return an integer between 0 and 100 indicating how similar |
|
154 | 5569 |
the argument is to the receiver. No case conversion is done. |
5570 |
This algorithm is much simpler (but also less exact) than the |
|
5571 |
levenshtein distance. Experiment which is better for your |
|
5572 |
application." |
|
64 | 5573 |
|
5574 |
| i1 "{ Class: SmallInteger }" |
|
5575 |
i2 "{ Class: SmallInteger }" |
|
154 | 5576 |
next1 "{ Class: SmallInteger }" |
5577 |
next2 "{ Class: SmallInteger }" |
|
64 | 5578 |
size1 "{ Class: SmallInteger }" |
5579 |
size2 "{ Class: SmallInteger }" |
|
5580 |
score "{ Class: SmallInteger }" |
|
5581 |
maxLen "{ Class: SmallInteger }" | |
|
5582 |
||
5583 |
size1 := self size. |
|
5584 |
size2 := aString size. |
|
154 | 5585 |
maxLen := size1 max:size2. |
64 | 5586 |
score := 0. |
5587 |
i1 := i2 := 1. |
|
5588 |
[i1 <= size1 and: [i2 <= size2]] whileTrue:[ |
|
154 | 5589 |
next1 := i1 + 1. |
5590 |
next2 := i2 + 1. |
|
5591 |
(self at:i1) == (aString at:i2) ifTrue: [ |
|
5592 |
score := score+1. |
|
5593 |
i1 := next1. |
|
5594 |
i2 := next2 |
|
5595 |
] ifFalse: [ |
|
5596 |
(i2 < size2 and: [(self at:i1) == (aString at:next2)]) ifTrue: [ |
|
5597 |
i2 := next2 |
|
5598 |
] ifFalse: [ |
|
5599 |
(i1 < size1 and: [(self at:next1) == (aString at:i2)]) ifTrue: [ |
|
5600 |
i1 := next1 |
|
5601 |
] ifFalse: [ |
|
5602 |
i1 := next1. |
|
5603 |
i2 := next2 |
|
5604 |
] |
|
5605 |
] |
|
5606 |
] |
|
64 | 5607 |
]. |
5608 |
||
1124 | 5609 |
score == maxLen ifTrue: [^ 100]. |
154 | 5610 |
^ 100 * score // maxLen |
64 | 5611 |
|
154 | 5612 |
" |
5613 |
'Smalltalk' spellAgainst: 'Smalltlak' |
|
5614 |
'Smalltalk' spellAgainst: 'smalltlak' |
|
5615 |
'Smalltalk' spellAgainst: 'smalltalk' |
|
5616 |
'Smalltalk' spellAgainst: 'smalltlk' |
|
5617 |
'Smalltalk' spellAgainst: 'Smalltolk' |
|
5618 |
" |
|
1381 | 5619 |
! |
5620 |
||
5621 |
startsWith:aString |
|
4389
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4294
diff
changeset
|
5622 |
"return true, if the receiver starts with something, aString. |
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4294
diff
changeset
|
5623 |
If the argument is empty, true is returned." |
1381 | 5624 |
|
5625 |
|s| |
|
5626 |
||
5627 |
(s := self string) ~~ self ifTrue:[ |
|
5628 |
^ s startsWith:aString |
|
5629 |
]. |
|
5630 |
^ super startsWith:aString |
|
5631 |
||
5632 |
" |
|
5633 |
'hello world' startsWith:'hello' |
|
5634 |
'hello world' asText allBold startsWith:'hello' |
|
4389
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4294
diff
changeset
|
5635 |
'hello world' asText allBold startsWith:'' |
1381 | 5636 |
" |
5637 |
||
5638 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
5639 |
"Modified: 12.5.1996 / 15:49:24 / cg" |
|
64 | 5640 |
! ! |
5641 |
||
4662 | 5642 |
!CharacterArray methodsFor:'tracing'! |
5643 |
||
4682 | 5644 |
traceInto:aRequestor level:level from:referrer |
4662 | 5645 |
"double dispatch into tracer, passing my type implicitely in the selector" |
5646 |
||
4682 | 5647 |
^ aRequestor traceCharacterArray:self level:level from:referrer |
4662 | 5648 |
|
5649 |
||
5650 |
! ! |
|
5651 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
5652 |
!CharacterArray class methodsFor:'documentation'! |
629 | 5653 |
|
5654 |
version |
|
5714
df1aa9dff662
removed a few halts (which are really errors)
Claus Gittinger <cg@exept.de>
parents:
5632
diff
changeset
|
5655 |
^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.191 2000-11-16 16:00:58 cg Exp $' |
629 | 5656 |
! ! |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
5657 |
CharacterArray initialize! |