author | Claus Gittinger <cg@exept.de> |
Fri, 26 Oct 2001 15:41:46 +0200 | |
changeset 6122 | a98958f1c85f |
parent 6119 | b6cee2c2b2ea |
child 6139 | 1b86d43f8eb7 |
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 |
||
5757 | 156 |
fromUTF8Bytes:aByteCollection |
5758 | 157 |
"return a new string which represents the characters as decoded |
158 |
from the utf8 encoded bytes, aByteCollection. |
|
159 |
Returns either a normal String, or a TwoByteString instance. |
|
5757 | 160 |
Only useful, when reading twoByteStrings from external sources." |
161 |
||
162 |
|sz nBitsRequired ascii s byte newString idx| |
|
163 |
||
164 |
nBitsRequired := 8. |
|
165 |
sz := 0. |
|
166 |
s := aByteCollection readStream. |
|
167 |
[s atEnd] whileFalse:[ |
|
168 |
byte := ascii := s nextByte. |
|
169 |
(byte bitAnd:16r80) ~~ 0 ifTrue:[ |
|
170 |
(byte bitAnd:16rE0) == 16rC0 ifTrue:[ |
|
171 |
ascii := (byte bitAnd:16r1F). |
|
172 |
byte := s nextByte. |
|
173 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:16r3F). |
|
174 |
ascii > 16rFF ifTrue:[ |
|
175 |
nBitsRequired := nBitsRequired max:16 |
|
176 |
] |
|
177 |
] ifFalse:[ |
|
178 |
(byte bitAnd:16rF0) == 16rE0 ifTrue:[ |
|
179 |
ascii := (byte bitAnd:16r0F). |
|
180 |
byte := s nextByte. |
|
181 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:16r3F). |
|
182 |
byte := s nextByte. |
|
183 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:16r3F). |
|
184 |
ascii > 16rFF ifTrue:[ |
|
185 |
nBitsRequired := nBitsRequired max:16 |
|
186 |
] |
|
187 |
] ifFalse:[ |
|
188 |
self error:'bad utf encoding'. |
|
189 |
^ nil. |
|
190 |
] |
|
191 |
]. |
|
192 |
]. |
|
193 |
sz := sz + 1. |
|
194 |
]. |
|
195 |
nBitsRequired == 8 ifTrue:[ |
|
196 |
newString := String new:sz |
|
197 |
] ifFalse:[ |
|
5759 | 198 |
newString := UnicodeString new:sz |
5757 | 199 |
]. |
200 |
||
201 |
s := aByteCollection readStream. |
|
202 |
idx := 1. |
|
203 |
[s atEnd] whileFalse:[ |
|
204 |
byte := ascii := s nextByte. |
|
205 |
(byte bitAnd:16r80) ~~ 0 ifTrue:[ |
|
206 |
(byte bitAnd:16rE0) == 16rC0 ifTrue:[ |
|
207 |
ascii := (byte bitAnd:16r1F). |
|
208 |
byte := s nextByte. |
|
209 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:16r3F). |
|
210 |
] ifFalse:[ |
|
211 |
ascii := (byte bitAnd:16r0F). |
|
212 |
byte := s nextByte. |
|
213 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:16r3F). |
|
214 |
byte := s nextByte. |
|
215 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:16r3F). |
|
216 |
]. |
|
217 |
]. |
|
218 |
newString at:idx put:(Character value:ascii). |
|
219 |
idx := idx + 1. |
|
220 |
]. |
|
221 |
^ newString |
|
222 |
||
223 |
" |
|
224 |
CharacterArray fromUTF8Bytes:#[ 16r41 16r42 ] |
|
225 |
CharacterArray fromUTF8Bytes:#[ 16rC1 16r02 ] |
|
226 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r81 16r02 ] |
|
227 |
CharacterArray fromUTF8Bytes:#[ 16rEF 16rBF 16rBF ] |
|
228 |
" |
|
229 |
! |
|
230 |
||
608 | 231 |
new |
232 |
"return a new empty string" |
|
233 |
||
234 |
^ self basicNew:0 |
|
64 | 235 |
! ! |
236 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
237 |
!CharacterArray class methodsFor:'Signal constants'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
238 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
239 |
decodingFailedSignal |
2833 | 240 |
"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
|
241 |
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
|
242 |
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
|
243 |
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
|
244 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
245 |
^ DecodingFailedSignal |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
246 |
|
2833 | 247 |
"Created: 28.6.1997 / 20:09:55 / cg" |
248 |
"Modified: 3.8.1997 / 18:16:47 / cg" |
|
249 |
! |
|
250 |
||
251 |
encodingFailedSignal |
|
252 |
"return the (query-) signal, raised when encoding of a string is not possible |
|
253 |
due to invalid characters contained in the source." |
|
254 |
||
255 |
^ EncodingFailedSignal |
|
256 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
257 |
"Modified: 28.6.1997 / 20:09:35 / cg" |
2833 | 258 |
"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
|
259 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
260 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
261 |
!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
|
262 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
263 |
lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
264 |
"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
|
265 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
266 |
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
|
267 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
268 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
269 |
CharacterArray lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
270 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
271 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
272 |
"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
|
273 |
"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
|
274 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
275 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
276 |
!CharacterArray class methodsFor:'code tables'! |
443 | 277 |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
278 |
classForEncoding:encodingSymbol |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
279 |
"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
|
280 |
by encodingSymbol" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
281 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
282 |
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
|
283 |
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
|
284 |
encodingSymbol == #gb ifTrue:[^ GBEncodedString]. |
2734 | 285 |
encodingSymbol == #ksc ifTrue:[^ KSCEncodedString]. |
286 |
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
|
287 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
288 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
289 |
"/ 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
|
290 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
291 |
^ String |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
292 |
|
2734 | 293 |
"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
|
294 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
295 |
|
443 | 296 |
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
|
297 |
"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
|
298 |
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
|
299 |
This is an experimental interface - unfinished" |
443 | 300 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
301 |
|table unrepresentableCharacterCode x80Table| |
443 | 302 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
303 |
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
|
304 |
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
|
305 |
table notNil ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
306 |
table == #identity ifTrue:[^ nil]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
307 |
^ table |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
308 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
309 |
] ifFalse:[ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
310 |
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
|
311 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
312 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
313 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
314 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
315 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
316 |
"/ setup as identityTranslation |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
317 |
"/ |
443 | 318 |
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
|
319 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
320 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
321 |
"/ hp -> iso8859 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
322 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
323 |
"/ 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
|
324 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
325 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
326 |
encoding == #hp ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
327 |
unrepresentableCharacterCode := 16rA0. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
328 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
329 |
x80Table := |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
330 |
#( |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
331 |
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
|
332 |
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
|
333 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
334 |
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
|
335 |
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
|
336 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
337 |
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
|
338 |
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
|
339 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
340 |
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
|
341 |
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
|
342 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
343 |
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
|
344 |
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
|
345 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
346 |
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
|
347 |
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
|
348 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
349 |
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
|
350 |
"/ S ? s ? Y ? |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
351 |
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
|
352 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
353 |
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
|
354 |
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
|
355 |
). |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
356 |
]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
357 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
358 |
"/ |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
359 |
"/ mac -> iso8859 |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
360 |
"/ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
361 |
"/ 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
|
362 |
"/ - 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
|
363 |
"/ |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
364 |
"/ A0 (dagger) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
365 |
"/ A5 (dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
366 |
"/ AA (tm - trademark) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
367 |
"/ AD (not equal) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
368 |
"/ B0 (infinity) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
369 |
"/ B3 (less-double-equal <=) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
370 |
"/ B4 (greater-equal >-) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
371 |
"/ B6 (math lowercase delta) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
372 |
"/ B7 (math sum) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
373 |
"/ B8 (math uppercase pi) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
374 |
"/ B9 (math lowercase pi) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
375 |
"/ BA (math integral) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
376 |
"/ BD (math omega) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
377 |
"/ C3 (math union) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
378 |
"/ C4 (ext latin f) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
379 |
"/ C5 (math almost equal) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
380 |
"/ C6 (math uppercase delta) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
381 |
"/ C9 (dot-dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
382 |
"/ CE (OE ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
383 |
"/ CF (oe ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
384 |
"/ D1 (hyphen) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
385 |
"/ D2 (opening top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
386 |
"/ D3 (closing top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
387 |
"/ D4 (opening top quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
388 |
"/ D5 (closing top quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
389 |
"/ D7 (geometric: ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
390 |
"/ D9 (uppercase Y diacrit ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
391 |
"/ DA (slash2 ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
392 |
"/ DC (single oldStyle opening quote (<) ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
393 |
"/ DD (single oldStyle closing quote (>) ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
394 |
"/ DE (? ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
395 |
"/ DF (? ) |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
396 |
"/ E0 (double dagger ) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
397 |
"/ E2 (opening bottom quote ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
398 |
"/ E3 (opening bottom dquote ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
399 |
"/ F0 (? ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
400 |
"/ F5 (latin l ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
401 |
"/ F6 (diacrit circumflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
402 |
"/ F7 (diacrit tilde) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
403 |
"/ F8 (diacrit top line) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
404 |
"/ F9 (diacrit inverse circumflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
405 |
"/ FA (diacrit dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
406 |
"/ FB (diacrit ring) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
407 |
"/ FC (diacrit cedille left) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
408 |
"/ FD (diacrit dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
409 |
"/ FE (diacrit cedille right) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
410 |
"/ FF (diacrit circumflex2 ?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
411 |
"/ |
443 | 412 |
encoding == #mac ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
413 |
x80Table := |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
414 |
#( 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
|
415 |
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
|
416 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
417 |
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
|
418 |
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
|
419 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
420 |
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
|
421 |
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
|
422 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
423 |
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
|
424 |
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
|
425 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
426 |
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
|
427 |
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
|
428 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
429 |
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
|
430 |
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
|
431 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
432 |
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
|
433 |
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
|
434 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
435 |
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
|
436 |
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
|
437 |
). |
657 | 438 |
]. |
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 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
441 |
"/ next -> iso8859 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
442 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
443 |
"/ 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
|
444 |
"/ - 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
|
445 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
446 |
"/ A4 (diacrit /) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
447 |
"/ A9 (diacrit quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
448 |
"/ AA (top opening dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
449 |
"/ AC (single oldStyle opening quote (<)) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
450 |
"/ AD (single oldStyle closing quote (>)) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
451 |
"/ AE (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
452 |
"/ AF (?) |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
453 |
"/ B2 (dagger) |
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
454 |
"/ B3 (double dagger) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
455 |
"/ B7 (enter dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
456 |
"/ B8 (opening bottom quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
457 |
"/ B9 (opening bottom dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
458 |
"/ BA (closing top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
459 |
"/ BC (dot-dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
460 |
"/ BD (per-mille) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
461 |
"/ C0 (subscript 1) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
462 |
"/ C1 (accent grave) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
463 |
"/ C2 (accent degu) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
464 |
"/ C3 (accent circonflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
465 |
"/ C4 (accent tilde) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
466 |
"/ C5 (accent line) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
467 |
"/ C6 (accent circonflex reverse) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
468 |
"/ C7 (accent dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
469 |
"/ C8 (accent dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
470 |
"/ D0 (hline) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
471 |
"/ 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
|
472 |
"/ EA (OE ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
473 |
"/ F5 (latin l) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
474 |
"/ 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
|
475 |
"/ FE (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
476 |
"/ FF (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
477 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
478 |
encoding == #next ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
479 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
480 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
481 |
x80Table := |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
482 |
#( 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
|
483 |
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
|
484 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
485 |
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
|
486 |
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
|
487 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
488 |
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
|
489 |
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
|
490 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
491 |
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
|
492 |
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
|
493 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
494 |
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
|
495 |
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
|
496 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
497 |
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
|
498 |
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
|
499 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
500 |
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
|
501 |
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
|
502 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
503 |
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
|
504 |
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
|
505 |
). |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
506 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
507 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
508 |
"/ |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
509 |
"/ 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
|
510 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
511 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
512 |
"/ 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
|
513 |
"/ - 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
|
514 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
515 |
"/ 9E (pesetas) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
516 |
"/ 9F (latin f) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
517 |
"/ A9 (technical not) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
518 |
"/ B0 - BF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
519 |
"/ C0 - CF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
520 |
"/ D0 - DF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
521 |
"/ E0 (greek alpha) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
522 |
"/ E2 - E5 (greek) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
523 |
"/ E7 - EC (greek & math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
524 |
"/ EE - EF (greek & math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
525 |
"/ F0 (math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
526 |
"/ F2 - F5 (math & technical) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
527 |
"/ F7 (math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
528 |
"/ F9 (center dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
529 |
"/ FB (math sqrt) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
530 |
"/ FC (super n) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
531 |
"/ 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
|
532 |
"/ |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
533 |
encoding == #msdos437 ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
534 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
535 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
536 |
x80Table := |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
537 |
#( |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
538 |
"/ 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
|
539 |
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
|
540 |
"/ 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
|
541 |
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
|
542 |
"/ 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
|
543 |
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
|
544 |
"/ 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
|
545 |
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
|
546 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
547 |
"/ 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
|
548 |
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
|
549 |
"/ 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
|
550 |
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
|
551 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
552 |
"/ block graphics |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
553 |
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
|
554 |
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
|
555 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
556 |
"/ block graphics |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
557 |
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
|
558 |
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
|
559 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
560 |
"/ block graphics |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
561 |
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
|
562 |
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
|
563 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
564 |
"/ alpha beta ... mu |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
565 |
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
|
566 |
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
|
567 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
568 |
"/ 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
|
569 |
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
|
570 |
"/ 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
|
571 |
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
|
572 |
). |
443 | 573 |
]. |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
574 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
575 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
576 |
"/ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
577 |
"/ msdos (codePage 850 [=latin1]) -> iso8859 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
578 |
"/ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
579 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
580 |
(encoding == #msdos850 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
581 |
or:[encoding == #msdos]) ifTrue:[ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
582 |
unrepresentableCharacterCode := 16rBF. |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
583 |
x80Table := |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
584 |
#( |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
585 |
"/ 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
|
586 |
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
|
587 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
588 |
"/ 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
|
589 |
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
|
590 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
591 |
"/ 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
|
592 |
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
|
593 |
"/ 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
|
594 |
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
|
595 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
596 |
"/ 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
|
597 |
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
|
598 |
"/ 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
|
599 |
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
|
600 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
601 |
"/ Aacute Acirc Agrave |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
602 |
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
|
603 |
"/ cpyr cent Yen |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
604 |
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
|
605 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
606 |
"/ atilde Atilde |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
607 |
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
|
608 |
"/ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
609 |
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
|
610 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
611 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
612 |
"/ Ecirc Euml Egrave Iacute Icirc |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
613 |
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
|
614 |
"/ Iuml Igrave |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
615 |
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
|
616 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
617 |
"/ Oacute sz Ocirc Ograve otilde Otilde mu |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
618 |
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
|
619 |
"/ Uacute Ucirc Ugrav yacute Yacute ' |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
620 |
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
|
621 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
622 |
"/ plusmin = 3/4 para sect div "/ f0 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
623 |
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
|
624 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
625 |
"/ sup0 sup3 sup2 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
626 |
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
|
627 |
). |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
628 |
]. |
443 | 629 |
"/ more encodings needed here .... |
630 |
||
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
631 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
632 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
633 |
"/ 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
|
634 |
"/ 0x80..0xFF characters |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
635 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
636 |
x80Table isNil ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
637 |
table := #identity. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
638 |
] ifFalse:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
639 |
x80Table keysAndValuesDo:[:idx :repl | |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
640 |
|ch| |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
641 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
642 |
repl == 16rFFFF ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
643 |
ch := unrepresentableCharacterCode |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
644 |
] ifFalse:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
645 |
ch := repl |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
646 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
647 |
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
|
648 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
649 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
650 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
651 |
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
|
652 |
^ table |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
653 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
654 |
" |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
655 |
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
|
656 |
DecoderTables := nil |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
657 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
658 |
|
443 | 659 |
"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
|
660 |
"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
|
661 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
662 |
|
2734 | 663 |
defaultRomanCharacterValue |
664 |
"return the characterValue for unmappable roman characters |
|
665 |
(only applies to jis, gb, ksc etc.)" |
|
666 |
||
667 |
|romans| |
|
668 |
||
669 |
romans := self romanTable. |
|
670 |
romans isNil ifTrue:[^ 16r20]. |
|
671 |
^ romans at:1. "/ space characters xlation |
|
672 |
||
673 |
"Created: 30.6.1997 / 18:13:24 / cg" |
|
674 |
"Modified: 30.6.1997 / 18:19:26 / cg" |
|
675 |
! |
|
676 |
||
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
677 |
encoderTableFor:encoding |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
678 |
"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
|
679 |
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
|
680 |
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
|
681 |
|
2751 | 682 |
|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
|
683 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
684 |
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
|
685 |
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
|
686 |
table notNil ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
687 |
table == #identity ifTrue:[^ nil]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
688 |
^ table |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
689 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
690 |
] ifFalse:[ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
691 |
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
|
692 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
693 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
694 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
695 |
"/ iso8859 -> hp |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
696 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
697 |
encoding == #hp ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
698 |
decoderTable := self decoderTableFor:encoding. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
699 |
unrepresentableCharacterCode := 16rFF. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
700 |
]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
701 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
702 |
"/ |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
703 |
"/ iso8859 -> mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
704 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
705 |
encoding == #mac ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
706 |
decoderTable := self decoderTableFor:encoding. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
707 |
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
|
708 |
]. |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
709 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
710 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
711 |
"/ iso8859 -> msdos |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
712 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
713 |
encoding == #msdos ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
714 |
decoderTable := self decoderTableFor:encoding. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
715 |
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
|
716 |
]. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
717 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
718 |
"/ 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
|
719 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
720 |
decoderTable notNil ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
721 |
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
|
722 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
723 |
0 to:16rFF do:[:code | |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
724 |
|isoCode destIdex| |
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 |
isoCode := decoderTable at:(code+1). |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
727 |
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
|
728 |
] |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
729 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
730 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
731 |
table isNil ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
732 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
733 |
"/ 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
|
734 |
"/ use special #identity |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
735 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
736 |
table := #identity. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
737 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
738 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
739 |
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
|
740 |
^ table |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
741 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
742 |
" |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
743 |
EncoderTables := nil. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
744 |
DecoderTables := nil. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
745 |
CharacterArray decoderTableFor:#mac |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
746 |
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
|
747 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
748 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
749 |
"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
|
750 |
"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
|
751 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
752 |
|
2733 | 753 |
romanTable |
754 |
^ nil |
|
755 |
||
756 |
"Created: 30.6.1997 / 15:13:52 / cg" |
|
757 |
! |
|
758 |
||
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
759 |
supportedEncodings |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
760 |
"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
|
761 |
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
|
762 |
|
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
763 |
^ self supportedExternalEncodings at:2. |
2733 | 764 |
|
765 |
"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
|
766 |
! |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
767 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
768 |
supportedExternalEncodings |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
769 |
"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
|
770 |
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
|
771 |
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
|
772 |
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
|
773 |
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
|
774 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
775 |
^ #( |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
776 |
( |
2250 | 777 |
'iso8859 (ansi)' |
778 |
'iso8859-1 (latin1)' |
|
779 |
'iso8859-2 (latin2)' |
|
780 |
'iso8859-3 (latin3)' |
|
781 |
'iso8859-4 (latin4)' |
|
782 |
'iso8859-5 (cyrillic)' |
|
783 |
'iso8859-6 (arabic)' |
|
784 |
'iso8859-7 (greek)' |
|
785 |
'iso8859-8 (hebrew)' |
|
786 |
'msdos US (codepage 437)' |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
787 |
'msdos Latin1 (codepage 850)' |
2250 | 788 |
'macintosh (8 bit)' |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
789 |
'next (8 bit)' |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
790 |
'hp (8 bit)' |
2733 | 791 |
nil |
2250 | 792 |
'EUC (extended unix code japanese)' |
793 |
'JIS7 (jis 7bit escape codes japanese)' |
|
2759 | 794 |
'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
|
795 |
'SJIS (shift jis 8bit codes japanese)' |
2733 | 796 |
nil |
2250 | 797 |
'GB (mainland china)' |
798 |
'BIG5 (taiwan)' |
|
2733 | 799 |
"/ 'KSC (korean)' |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
800 |
) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
801 |
( |
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
802 |
#'iso8859' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
803 |
#'iso8859-1' "/ latin1 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
804 |
#'iso8859-2' "/ latin2 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
805 |
#'iso8859-3' "/ latin3 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
806 |
#'iso8859-4' "/ latin4 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
807 |
#'iso8859-5' "/ cyrillic |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
808 |
#'iso8859-6' "/ arabic |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
809 |
#'iso8859-7' "/ greek |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
810 |
#'iso8859-8' "/ hebrew |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
811 |
#'msdos437' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
812 |
#'msdos850' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
813 |
#'mac' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
814 |
#'next' |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
815 |
#'hp' |
2733 | 816 |
nil |
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
817 |
#'euc' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
818 |
#'jis7' |
2759 | 819 |
#'iso-2022-jp' |
2721 | 820 |
#'sjis' |
2733 | 821 |
nil |
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
822 |
#'gb' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
823 |
#'big5' |
2733 | 824 |
"/ #'ksc' "/ korean |
2250 | 825 |
) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
826 |
) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
827 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
828 |
"Created: 22.4.1996 / 14:39:39 / cg" |
2759 | 829 |
"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
|
830 |
! ! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
831 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
832 |
!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
|
833 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
834 |
decodeFromBIG5:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
835 |
"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
|
836 |
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
|
837 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
838 |
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
|
839 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
840 |
|newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
841 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
842 |
newString := BIG5EncodedString new:aString size. |
1204 | 843 |
^ self decodeFromBIG5_or_GB:aString into:newString. |
844 |
||
845 |
"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
|
846 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
847 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
848 |
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
|
849 |
"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
|
850 |
which is interpreted as a BIG5 encoded singleByte string. |
2748 | 851 |
The result is a Big5EncodedString (you need a BIG5 font to display that ...). |
852 |
||
853 |
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
|
854 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
855 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
856 |
dstIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
857 |
srcIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
858 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
859 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
860 |
val "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
861 |
c| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
862 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
863 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
864 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
865 |
dstIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
866 |
srcIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
867 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
868 |
[true] whileTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
869 |
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
|
870 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
871 |
"/ characters below 16rA1 are left untranslated |
2733 | 872 |
"/ (romans). |
873 |
"/ 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
|
874 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
875 |
b1 := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
876 |
b1 >= 16rA1 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
877 |
srcIdx := srcIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
878 |
srcIdx <= sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
879 |
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
|
880 |
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
|
881 |
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
|
882 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
883 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
884 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
885 |
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
|
886 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
887 |
srcIdx := srcIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
888 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
889 |
srcIdx > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
890 |
^ 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
|
891 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
892 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
893 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
894 |
^ a16BitString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
895 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
896 |
"Created: 17.4.1996 / 16:55:54 / cg" |
2748 | 897 |
"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
|
898 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
899 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
900 |
decodeFromEUC:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
901 |
"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
|
902 |
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
|
903 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
904 |
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
|
905 |
this one only understands New-JIS. |
2748 | 906 |
The result is a JISEncodedString (you need a JIS font to display that ...). |
907 |
||
908 |
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
|
909 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
910 |
|newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
911 |
sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
912 |
dstIdx "{ Class: SmallInteger }" |
2750 | 913 |
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
|
914 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
915 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
916 |
val "{ Class: SmallInteger }" |
2733 | 917 |
c c2| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
918 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
919 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
920 |
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
|
921 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
922 |
dstIdx := 1. |
2750 | 923 |
srcIdx := 1. |
924 |
||
925 |
%{ |
|
926 |
if (__isString(aString) |
|
927 |
&& (__Class(newString) == @global(JISEncodedString))) { |
|
928 |
int _dstIdx = 1, _srcIdx = 1; |
|
929 |
int _sz = __intVal(sz); |
|
930 |
unsigned char *_cp = __stringVal(aString); |
|
931 |
unsigned char _c1; |
|
932 |
unsigned short *_jcp = (unsigned short *)__stringVal(newString); |
|
933 |
||
934 |
while (_srcIdx <= _sz) { |
|
935 |
_c1 = _cp[_srcIdx-1]; |
|
936 |
if (_c1 < 161) { |
|
937 |
_jcp[_dstIdx-1] = _c1; |
|
938 |
} else { |
|
939 |
_srcIdx++; |
|
940 |
if (_srcIdx <= _sz) { |
|
941 |
unsigned char _c2; |
|
942 |
int _val; |
|
943 |
int _b1, _b2; |
|
944 |
||
945 |
_b1 = _c1 - 128; |
|
946 |
_c2 = _cp[_srcIdx-1]; |
|
947 |
_b2 = _c2 - 128; |
|
948 |
_val = (_b1<<8) + _b2; |
|
949 |
if (_val < 0) { |
|
950 |
/* decoder errors are handled in smalltalk */ |
|
951 |
_srcIdx--; |
|
952 |
goto getOutOfHere; |
|
953 |
} |
|
954 |
_jcp[_dstIdx-1] = _val; |
|
955 |
} else { |
|
956 |
_jcp[_dstIdx-1] = _c1; |
|
957 |
} |
|
958 |
} |
|
959 |
_dstIdx++; |
|
960 |
_srcIdx++; |
|
961 |
} |
|
962 |
getOutOfHere: |
|
963 |
srcIdx = __MKSMALLINT(_srcIdx); |
|
964 |
dstIdx = __MKSMALLINT(_dstIdx); |
|
965 |
} |
|
966 |
%}. |
|
967 |
||
968 |
[srcIdx <= sz] whileTrue:[ |
|
969 |
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
|
970 |
b1 := c asciiValue. |
2748 | 971 |
b1 < 161 ifTrue:[ |
972 |
"/ characters below 16rA1 are left untranslated |
|
973 |
"/ (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
|
974 |
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
|
975 |
] ifFalse:[ |
2750 | 976 |
srcIdx := srcIdx + 1. |
977 |
srcIdx <= sz ifTrue:[ |
|
2748 | 978 |
b1 := b1 - 128. |
2750 | 979 |
b2 := (c2 := aString at:srcIdx) asciiValue. |
2748 | 980 |
b2 := b2 - 128. |
981 |
val := (b1 bitShift:8) bitOr:b2. |
|
982 |
val <= 0 ifTrue:[ |
|
983 |
DecodingFailedSignal |
|
984 |
raiseWith:aString |
|
985 |
errorString:'EUC decoding failed (not EUC encoded ?)'. |
|
986 |
newString at:dstIdx put:c. |
|
987 |
dstIdx := dstIdx + 1. |
|
988 |
newString at:dstIdx put:c2. |
|
989 |
] ifFalse:[ |
|
990 |
newString at:dstIdx put:(Character value:val). |
|
991 |
]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
992 |
] ifFalse:[ |
2748 | 993 |
newString at:dstIdx put:c. |
994 |
]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
995 |
]. |
2748 | 996 |
dstIdx := dstIdx + 1. |
2750 | 997 |
srcIdx := srcIdx + 1. |
998 |
]. |
|
999 |
||
1000 |
(dstIdx-1) ~~ sz ifTrue:[ |
|
1001 |
newString := newString copyFrom:1 to:dstIdx-1. |
|
1002 |
]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1003 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1004 |
^ newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1005 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1006 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1007 |
|
2733 | 1008 |
'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
|
1009 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1010 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1011 |
"Created: 17.4.1996 / 16:10:22 / cg" |
2748 | 1012 |
"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
|
1013 |
! |
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 |
decodeFromGB:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1016 |
"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
|
1017 |
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
|
1018 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1019 |
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
|
1020 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1021 |
|newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1022 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1023 |
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
|
1024 |
^ 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
|
1025 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1026 |
"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
|
1027 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1028 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1029 |
decodeFromJIS7:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1030 |
"return a new string containing the aStrings characters, |
2758 | 1031 |
which are interpreted as a JIS7 or ISO2022-JP encoded singleByte string. |
1032 |
There are various JIS encodings around (New-JIS, Old-JIS, NEC-JIS and ISO2022); |
|
1033 |
this one understands New-JIS, ISO2022 and treats Old-JIS just the same. |
|
2748 | 1034 |
The result is a JISEncodedString (you need a JIS font to display that ...). |
1035 |
||
1036 |
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
|
1037 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1038 |
|newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1039 |
sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1040 |
dstIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1041 |
start "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1042 |
stop "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1043 |
n1 n2 n3 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1044 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1045 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1046 |
val "{ Class: SmallInteger }" |
2734 | 1047 |
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
|
1048 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1049 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1050 |
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
|
1051 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1052 |
dstIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1053 |
start := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1054 |
singleBytes := true. |
2734 | 1055 |
katakana := false. |
1202
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 |
[true] whileTrue:[ |
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 |
"/ 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
|
1060 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1061 |
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
|
1062 |
stop == 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1063 |
stop := sz + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1064 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1065 |
(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
|
1066 |
stop := sz + 1. |
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 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1069 |
singleBytes ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1070 |
start to:(stop - 1) do:[:i | |
2758 | 1071 |
c := aString at:i. |
2734 | 1072 |
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
|
1073 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1074 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1075 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1076 |
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
|
1077 |
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
|
1078 |
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
|
1079 |
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
|
1080 |
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
|
1081 |
dstIdx := dstIdx + 1. |
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 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1084 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1085 |
stop > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1086 |
^ 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
|
1087 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1088 |
start := stop. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1089 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1090 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1091 |
"/ 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
|
1092 |
"/ - 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
|
1093 |
"/ 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
|
1094 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1095 |
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
|
1096 |
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
|
1097 |
n3 := aString at:(start + 2). |
2734 | 1098 |
katakana := false. |
1099 |
||
1100 |
(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
|
1101 |
singleBytes := false. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1102 |
] ifFalse:[ |
2734 | 1103 |
(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
|
1104 |
singleBytes := false. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1105 |
] ifFalse:[ |
2734 | 1106 |
(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
|
1107 |
singleBytes := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1108 |
] ifFalse:[ |
2734 | 1109 |
(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
|
1110 |
singleBytes := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1111 |
] ifFalse:[ |
2734 | 1112 |
(n2 == $( and:[n3 == $I ]) ifTrue:[ |
1113 |
singleBytes := true. |
|
1114 |
katakana := true. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1115 |
] ifFalse:[ |
2734 | 1116 |
singleBytes ifTrue:[ |
1117 |
newString at:dstIdx put:n1. |
|
1118 |
newString at:(dstIdx + 1) put:n2. |
|
1119 |
newString at:(dstIdx + 2) put:n3. |
|
1120 |
dstIdx := dstIdx + 3. |
|
1121 |
] ifFalse:[ |
|
1122 |
DecodingFailedSignal |
|
1123 |
raiseWith:aString |
|
1124 |
errorString:'JIS7 decoding failed (not JIS7 encoded ?)'. |
|
1125 |
newString at:dstIdx put:n1. |
|
1126 |
newString at:(dstIdx + 1) put:n2. |
|
1127 |
newString at:(dstIdx + 2) put:n3. |
|
1128 |
dstIdx := dstIdx + 3. |
|
1129 |
] |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1130 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1131 |
] |
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 |
] |
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 |
start := start + 3. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1136 |
start > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1137 |
^ 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
|
1138 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1139 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1140 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1141 |
^ newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1142 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1143 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1144 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1145 |
'hello' decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1146 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1147 |
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
|
1148 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1149 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1150 |
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
|
1151 |
s decodeFromJIS7 |
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 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1154 |
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
|
1155 |
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
|
1156 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1157 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1158 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1159 |
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
|
1160 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1161 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1162 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1163 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1164 |
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
|
1165 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1166 |
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
|
1167 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1168 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1169 |
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
|
1170 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1171 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1172 |
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
|
1173 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1174 |
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
|
1175 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1176 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1177 |
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
|
1178 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1179 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1180 |
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
|
1181 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1182 |
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
|
1183 |
s := s , '$3'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1184 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1185 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1186 |
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
|
1187 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1188 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1189 |
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
|
1190 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1191 |
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
|
1192 |
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
|
1193 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1194 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1195 |
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
|
1196 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1197 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1198 |
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
|
1199 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1200 |
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
|
1201 |
s := s , '$3'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1202 |
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
|
1203 |
s := s copyWith:$(. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1204 |
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
|
1205 |
s := s , 'hello'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1206 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1207 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1208 |
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
|
1209 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1210 |
|s t l| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1211 |
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
|
1212 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1213 |
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
|
1214 |
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
|
1215 |
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
|
1216 |
s := s copyWith:$(. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1217 |
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
|
1218 |
s := s , ' kterm'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1219 |
t := s decodeFromJIS7. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1220 |
l := Label new. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1221 |
l label:t. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1222 |
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
|
1223 |
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
|
1224 |
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
|
1225 |
l realize |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1226 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1227 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1228 |
"Created: 17.4.1996 / 16:11:57 / cg" |
2758 | 1229 |
"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
|
1230 |
! |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1231 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1232 |
decodeFromSJIS:aString |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1233 |
"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
|
1234 |
which are interpreted as a Shift-JIS encoded singleByte string. |
2748 | 1235 |
The result is a JISEncodedString (you need a JIS font to display that ...). |
1236 |
||
1237 |
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
|
1238 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1239 |
|newString char1 char2 |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1240 |
sz "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1241 |
dstIdx "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1242 |
srcIdx "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1243 |
b1 "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1244 |
b2 "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1245 |
val "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1246 |
| |
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 |
sz := aString size. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1249 |
newString := JISEncodedString new:sz. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1250 |
sz ~~ 0 ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1251 |
dstIdx := 1. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1252 |
srcIdx := 1. |
2749 | 1253 |
%{ |
2757 | 1254 |
if (1 && __isString(aString) |
2749 | 1255 |
&& (__Class(newString) == @global(JISEncodedString))) { |
1256 |
int _dstIdx = 1, _srcIdx = 1; |
|
1257 |
int _sz = __intVal(sz); |
|
1258 |
unsigned char *_cp = __stringVal(aString); |
|
1259 |
unsigned char _c1, _c2; |
|
1260 |
unsigned short *_jcp = (unsigned short *)__stringVal(newString); |
|
1261 |
||
1262 |
while (_srcIdx <= _sz) { |
|
1263 |
int _val; |
|
1264 |
||
1265 |
_c1 = _cp[_srcIdx-1]; |
|
1266 |
_srcIdx++; |
|
1267 |
||
1268 |
if ((_srcIdx <= _sz) |
|
1269 |
&& (((_c1 >= 129) && (_c1 <= 159)) |
|
1270 |
|| ((_c1 >= 224) && (_c1 <= 239)))) { |
|
1271 |
_c2 = _cp[_srcIdx-1]; |
|
1272 |
_srcIdx++; |
|
1273 |
if ((_c2 >= 64) && (_c2 <= 252)) { |
|
1274 |
int _adjust, _rowOffs, _cellOffs; |
|
1275 |
int _b1, _b2; |
|
1276 |
||
1277 |
_adjust = (_c2 < 159) ? 1 : 0; |
|
1278 |
_rowOffs = (_c1 < 160) ? 112 : 176; |
|
1279 |
if (_adjust) { |
|
1280 |
_cellOffs = 31 + ((_c2 > 127) ? 1 : 0); |
|
1281 |
} else { |
|
1282 |
_cellOffs = 126; |
|
1283 |
} |
|
1284 |
_b1 = ((_c1 - _rowOffs) << 1) - _adjust; |
|
1285 |
_b2 = (_c2 - _cellOffs); |
|
1286 |
_val = (_b1<<8) + _b2; |
|
1287 |
if (_val <= 0) { |
|
1288 |
/* decoder error - let smalltalk handle that */ |
|
1289 |
_srcIdx -= 2; |
|
1290 |
goto getOutOfHere; |
|
1291 |
} |
|
1292 |
_jcp[_dstIdx-1] = _val; |
|
1293 |
} else { |
|
1294 |
/* mhmh - append untranslated */ |
|
1295 |
||
1296 |
_jcp[_dstIdx-1] = _c1; |
|
1297 |
_dstIdx++; |
|
1298 |
_jcp[_dstIdx-1] = _c2; |
|
1299 |
} |
|
1300 |
} else { |
|
1301 |
if ((_c1 >= 0xA1 /* 161 */) && (_c1 <= 0xDF /* 223 */)) { |
|
1302 |
/* HALFWIDTH KATAKANA |
|
1303 |
* map half-width katakana to 8E:xx |
|
1304 |
*/ |
|
1305 |
_val = _c1 - 128; |
|
1306 |
_val = _val + 0x8E00; |
|
1307 |
_jcp[_dstIdx-1] = _val; |
|
1308 |
} else { |
|
1309 |
/* roman characters left untranslated */ |
|
1310 |
_jcp[_dstIdx-1] = _c1; |
|
1311 |
} |
|
1312 |
} |
|
1313 |
_dstIdx++; |
|
1314 |
} |
|
1315 |
getOutOfHere: ; |
|
1316 |
dstIdx = __MKSMALLINT(_dstIdx); |
|
1317 |
srcIdx = __MKSMALLINT(_srcIdx); |
|
1318 |
} |
|
1319 |
%}. |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1320 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1321 |
[srcIdx <= sz] whileTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1322 |
"/ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1323 |
"/ 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
|
1324 |
"/ |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1325 |
char1 := aString at:srcIdx. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1326 |
srcIdx := srcIdx + 1. |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1327 |
b1 := char1 asciiValue. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1328 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1329 |
((srcIdx <= sz) |
2757 | 1330 |
and:[(b1 >= 129 and:[b1 <= 159]) "/ SJIS1 81 .. 9F |
1331 |
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
|
1332 |
char2 := aString at:srcIdx. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1333 |
srcIdx := srcIdx + 1. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1334 |
b2 := char2 asciiValue. |
2757 | 1335 |
(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
|
1336 |
|adjust rowOffs cellOffs| |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1337 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1338 |
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
|
1339 |
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
|
1340 |
adjust == 1 ifTrue:[ |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1341 |
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
|
1342 |
] ifFalse:[ |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1343 |
cellOffs := 126. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1344 |
]. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1345 |
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
|
1346 |
b2 := (b2 - cellOffs). |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1347 |
val := (b1 bitShift:8) + b2. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1348 |
val <= 0 ifTrue:[ |
2730
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1349 |
DecodingFailedSignal |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1350 |
raiseWith:aString |
2730
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1351 |
errorString:'SJIS decoding failed (not SJIS encoded ?)'. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1352 |
newString at:dstIdx put:char1. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1353 |
dstIdx := dstIdx + 1. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1354 |
newString at:dstIdx put:char2. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1355 |
] ifFalse:[ |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1356 |
newString at:dstIdx put:(Character value:val). |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1357 |
] |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1358 |
] ifFalse:[ |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1359 |
"/ mhmh - append untranslated |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1360 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1361 |
newString at:dstIdx put:char1. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1362 |
dstIdx := dstIdx + 1. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1363 |
newString at:dstIdx put:char2. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1364 |
] |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1365 |
] ifFalse:[ |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1366 |
(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
|
1367 |
"/ 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
|
1368 |
val := b1 - 128. |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1369 |
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
|
1370 |
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
|
1371 |
] ifFalse:[ |
2733 | 1372 |
"/ roman characters left untranslated |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1373 |
newString at:dstIdx put:char1 |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1374 |
] |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1375 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1376 |
dstIdx := dstIdx + 1. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1377 |
]. |
2749 | 1378 |
(dstIdx-1) ~~ sz ifTrue:[ |
1379 |
newString := newString copyTo:dstIdx - 1. |
|
1380 |
] |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1381 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1382 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1383 |
^ newString |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1384 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1385 |
"simple: |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1386 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1387 |
'hello' decodeFrom:#sjis |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1388 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1389 |
'../../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
|
1390 |
decodeFrom:#sjis |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1391 |
" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1392 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1393 |
"Created: 28.6.1997 / 19:19:23 / cg" |
2748 | 1394 |
"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
|
1395 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1396 |
|
2733 | 1397 |
encodeIntoBIG5:aBIG5String |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1398 |
"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
|
1399 |
The argument must be a BIG5String. |
2733 | 1400 |
This is used translate 16bit BIG5 strings into the external BIG5 encoded |
1401 |
representation. |
|
1402 |
The resulting string is only useful to be stored on some external file, |
|
2748 | 1403 |
not for being displayed in an ST/X view. |
1404 |
||
1405 |
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
|
1406 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1407 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1408 |
b "{ Class: SmallInteger }" |
2733 | 1409 |
c out| |
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 |
sz := aBIG5String size. |
2733 | 1412 |
out := WriteStream on:(String new:(sz * 2)). |
1413 |
||
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1414 |
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
|
1415 |
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
|
1416 |
b := c asciiValue. |
1203
a43528048cb8
code tables moved to BIG5/JISEncodedString classes
Claus Gittinger <cg@exept.de>
parents:
1202
diff
changeset
|
1417 |
|
2733 | 1418 |
b > 255 ifTrue:[ |
1419 |
"/ big5 character |
|
1420 |
||
1421 |
out nextPut:(Character value:(b bitShift:-8)). |
|
1422 |
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
|
1423 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1424 |
"/ |
2733 | 1425 |
"/ 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
|
1426 |
"/ |
2733 | 1427 |
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
|
1428 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1429 |
]. |
2733 | 1430 |
^ out contents |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1431 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1432 |
"Created: 17.4.1996 / 17:17:50 / cg" |
2748 | 1433 |
"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
|
1434 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1435 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1436 |
encodeIntoEUC:aJISString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1437 |
"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
|
1438 |
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
|
1439 |
The resulting string is only useful to be stored on some external file, |
2748 | 1440 |
not for being displayed in an ST/X view. |
1441 |
||
1442 |
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
|
1443 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1444 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1445 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1446 |
val "{ Class: SmallInteger }" |
2733 | 1447 |
c romans out| |
1448 |
||
1449 |
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
|
1450 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1451 |
sz := aJISString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1452 |
sz == 0 ifTrue:[^ '']. |
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 |
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
|
1455 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1456 |
1 to:sz do:[:srcIndex | |
2733 | 1457 |
b1 := (c := aJISString at:srcIndex) asciiValue. |
2748 | 1458 |
b1 < 161 ifTrue:[ |
1459 |
"/ a control or roman character |
|
2733 | 1460 |
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
|
1461 |
] ifFalse:[ |
2748 | 1462 |
"/ |
1463 |
"/ check for a roman character |
|
1464 |
"/ the two numbers below are romanTable min and romanTable max |
|
1465 |
"/ |
|
1466 |
(b1 between:16r2121 and:16r2573) ifTrue:[ |
|
1467 |
val := romans indexOf:b1. |
|
1468 |
(val ~~ 0 and:[val <= 127]) ifTrue:[ |
|
1469 |
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
|
1470 |
] ifFalse:[ |
2747 | 1471 |
out nextPut:(Character value:(b1 bitShift:-8) + 128). |
1472 |
out nextPut:(Character value:(b1 bitAnd:16rFF) + 128). |
|
2748 | 1473 |
]. |
1474 |
] ifFalse:[ |
|
1475 |
out nextPut:(Character value:(b1 bitShift:-8) + 128). |
|
1476 |
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
|
1477 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1478 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1479 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1480 |
^ out contents |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1481 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1482 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1483 |
|
2733 | 1484 |
('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
|
1485 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1486 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1487 |
"Created: 17.4.1996 / 16:13:33 / cg" |
2748 | 1488 |
"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
|
1489 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1490 |
|
2733 | 1491 |
encodeIntoGB:aGBString |
1492 |
"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
|
1493 |
The argument must be a GBString. |
2733 | 1494 |
This is used translate 16bit GB strings into the external GB encoded |
1495 |
representation. |
|
1496 |
The resulting string is only useful to be stored on some external file, |
|
2748 | 1497 |
not for being displayed in an ST/X view. |
1498 |
||
1499 |
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
|
1500 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1501 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1502 |
b "{ Class: SmallInteger }" |
2733 | 1503 |
c out| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1504 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1505 |
sz := aGBString size. |
2733 | 1506 |
out := WriteStream on:(String new:(sz * 2)). |
1507 |
||
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1508 |
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
|
1509 |
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
|
1510 |
b := c asciiValue. |
2733 | 1511 |
b > 255 ifTrue:[ |
1512 |
"/ big5 character |
|
1513 |
||
1514 |
out nextPut:(Character value:(b bitShift:-8)). |
|
1515 |
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
|
1516 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1517 |
"/ |
2733 | 1518 |
"/ 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
|
1519 |
"/ |
2733 | 1520 |
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
|
1521 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1522 |
]. |
2733 | 1523 |
^ out contents |
1524 |
||
1525 |
"Created: 30.6.1997 / 15:48:35 / cg" |
|
2748 | 1526 |
"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
|
1527 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1528 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1529 |
encodeIntoJIS7:aJISString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1530 |
"return a new string with aJISStrings characters as JIS7 encoded 7bit string, |
2733 | 1531 |
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
|
1532 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1533 |
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
|
1534 |
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
|
1535 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1536 |
|sz "{ Class:SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1537 |
b1 "{ Class:SmallInteger }" |
2757 | 1538 |
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
|
1539 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1540 |
inSingleByteMode := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1541 |
kanji := JISEncodedString jis7KanjiEscapeSequence. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1542 |
roman := JISEncodedString jis7RomanEscapeSequence. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1543 |
|
2733 | 1544 |
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
|
1545 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1546 |
sz := aJISString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1547 |
sz == 0 ifTrue:[^ '']. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1548 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1549 |
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
|
1550 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1551 |
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
|
1552 |
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
|
1553 |
b1 := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1554 |
b1 < 33 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1555 |
"/ a control character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1556 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1557 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1558 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1559 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1560 |
out nextPut:c. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1561 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1562 |
"/ 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
|
1563 |
"/ 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
|
1564 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1565 |
(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
|
1566 |
val := romans indexOf:b1. |
2757 | 1567 |
val2 := val - 1 + 32. |
1568 |
(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
|
1569 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1570 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1571 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1572 |
]. |
2757 | 1573 |
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
|
1574 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1575 |
inSingleByteMode ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1576 |
out nextPutAll:kanji. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1577 |
inSingleByteMode := false |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1578 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1579 |
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
|
1580 |
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
|
1581 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1582 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1583 |
b1 <= 255 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1584 |
"/ 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
|
1585 |
"/ b1 >= 160 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1586 |
"/ ('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
|
1587 |
"/ ]. |
2734 | 1588 |
EncodingFailedSignal |
1589 |
raiseWith:aJISString |
|
1590 |
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
|
1591 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1592 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1593 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1594 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1595 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1596 |
out nextPut:c |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1597 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1598 |
inSingleByteMode ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1599 |
out nextPutAll:kanji. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1600 |
inSingleByteMode := false |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1601 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1602 |
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
|
1603 |
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
|
1604 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1605 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1606 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1607 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1608 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1609 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1610 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1611 |
^ out contents |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1612 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1613 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1614 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1615 |
'hello' decodeFromJIS7 encodeIntoJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1616 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1617 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1618 |
"Created: 17.4.1996 / 16:17:40 / cg" |
2757 | 1619 |
"Modified: 16.7.1997 / 11:30:07 / cg" |
2721 | 1620 |
! |
1621 |
||
2731 | 1622 |
encodeIntoSJIS:aJISString |
1623 |
"return a new string with aJISStrings characters as SJIS encoded 8bit string. |
|
2733 | 1624 |
The receiver must be a JIS encoded character string. |
2731 | 1625 |
|
1626 |
The resulting string is only useful to be stored on some external file, |
|
1627 |
not for being displayed in an ST/X view." |
|
1628 |
||
1629 |
|sz "{ Class: SmallInteger }" |
|
1630 |
rval "{ Class: SmallInteger }" |
|
1631 |
val "{ Class: SmallInteger }" |
|
1632 |
romans c out isSJIS| |
|
1633 |
||
2733 | 1634 |
romans := JISEncodedString romanTable. |
2731 | 1635 |
|
1636 |
sz := aJISString size. |
|
1637 |
sz == 0 ifTrue:[^ '']. |
|
1638 |
||
1639 |
out := WriteStream on:(String new:(sz * 2)). |
|
1640 |
||
1641 |
1 to:sz do:[:srcIndex | |
|
1642 |
val := (c := aJISString at:srcIndex) asciiValue. |
|
2748 | 1643 |
val <= 128 ifTrue:[ |
1644 |
"/ a control or ascii character |
|
2731 | 1645 |
out nextPut:c. |
1646 |
] ifFalse:[ |
|
2748 | 1647 |
(val > 150 and:[val < 224]) ifTrue:[ |
2731 | 1648 |
"/ ascii subset |
1649 |
out nextPut:c. |
|
1650 |
] ifFalse:[ |
|
2748 | 1651 |
"/ should not happen ... |
1652 |
val <= 255 ifTrue:[ |
|
2731 | 1653 |
out nextPut:c. |
1654 |
] ifFalse:[ |
|
2748 | 1655 |
isSJIS := true. |
1656 |
||
1657 |
"/ check for HALFWIDTH KATAKANA |
|
1658 |
"/ 8E:xx |
|
2757 | 1659 |
"/ NO: halfwidth katakana no longer generated |
1660 |
"/ remains there as full-width katakana |
|
1661 |
||
1662 |
"/ (val bitAnd:16rFF00) == 16r8E00 ifTrue:[ |
|
1663 |
"/ |b| |
|
1664 |
"/ |
|
1665 |
"/ b := (val bitAnd:16rFF) + 128. |
|
1666 |
"/ (b >= 16rA1 "161" and:[b <= 16rDF "223"]) ifTrue:[ |
|
1667 |
"/ out nextPut:(Character value:b). |
|
1668 |
"/ isSJIS := false. |
|
1669 |
"/ ]. |
|
1670 |
"/ ]. |
|
2748 | 1671 |
|
1672 |
isSJIS ifTrue:[ |
|
1673 |
||
1674 |
"/ check for a roman character |
|
1675 |
"/ the two numbers below are romanTable min and romanTable max |
|
1676 |
"/ |
|
1677 |
(val between:16r2121 and:16r2573) ifTrue:[ |
|
1678 |
rval := romans indexOf:val. |
|
1679 |
rval ~~ 0 ifTrue:[ |
|
2757 | 1680 |
rval := rval - 1 + 32. |
1681 |
rval <= 16r7F ifTrue:[ "/ do not translate halfwidth katakana |
|
1682 |
out nextPut:(Character value:rval). |
|
1683 |
isSJIS := false. |
|
1684 |
] |
|
2731 | 1685 |
]. |
1686 |
]. |
|
2748 | 1687 |
]. |
1688 |
||
1689 |
isSJIS ifTrue:[ |
|
1690 |
|b1 b2 rowOffset cellOffset| |
|
1691 |
||
1692 |
b1 := (val bitShift:-8). |
|
1693 |
b2 := (val bitAnd:16rFF). |
|
1694 |
rowOffset := (b1 < 95) ifTrue:[112] ifFalse:[176]. |
|
1695 |
cellOffset := b1 odd ifTrue:[(b2 > 95) ifTrue:[32] ifFalse:[31]] |
|
1696 |
ifFalse:[126]. |
|
1697 |
||
1698 |
out nextPut:(Character value:(((b1 + 1) bitShift:-1) + rowOffset)). |
|
1699 |
out nextPut:(Character value:b2 + cellOffset). |
|
2731 | 1700 |
] |
1701 |
] |
|
1702 |
] |
|
1703 |
]. |
|
1704 |
]. |
|
1705 |
^ out contents |
|
1706 |
||
1707 |
"simple: |
|
1708 |
||
1709 |
'hello' decodeFromEUC encodeIntoEUC |
|
1710 |
" |
|
1711 |
||
1712 |
"Created: 28.6.1997 / 21:13:27 / cg" |
|
2757 | 1713 |
"Modified: 16.7.1997 / 11:30:45 / cg" |
2733 | 1714 |
! |
1715 |
||
1716 |
encodeRomans:aTwoByteString |
|
1717 |
"return a new (usually 2-byte) string with roman characters |
|
1718 |
encoded. The position of roman characters are encoding specific. |
|
1719 |
(see romanTable of concrete 16-bit string classes). |
|
1720 |
Used when displaying strings." |
|
1721 |
||
1722 |
|sz "{ Class: SmallInteger }" |
|
1723 |
b "{ Class: SmallInteger }" |
|
4294 | 1724 |
c i nCode romans newString| |
2733 | 1725 |
|
1726 |
romans := self romanTable. |
|
1727 |
romans isNil ifTrue:[^ aTwoByteString]. |
|
1728 |
||
1729 |
sz := aTwoByteString size. |
|
2734 | 1730 |
newString := self fromString:aTwoByteString. |
2733 | 1731 |
|
1732 |
1 to:sz do:[:index | |
|
1733 |
c := aTwoByteString at:index. |
|
1734 |
b := c asciiValue. |
|
1735 |
||
2735 | 1736 |
(b > 32 and:[b <= 255]) ifTrue:[ |
4294 | 1737 |
(i := b - 32 + 1) <= romans size ifTrue:[ |
2734 | 1738 |
"/ |
1739 |
"/ a roman character |
|
1740 |
"/ map to corresponding row |
|
1741 |
"/ |
|
4294 | 1742 |
nCode := romans at:i. |
2734 | 1743 |
] ifFalse:[ |
4294 | 1744 |
nCode := self defaultRomanCharacterValue |
1745 |
]. |
|
1746 |
newString at:index put:(Character value:nCode). |
|
2733 | 1747 |
]. |
1748 |
]. |
|
1749 |
^ newString |
|
1750 |
||
1751 |
"Created: 30.6.1997 / 15:43:56 / cg" |
|
2735 | 1752 |
"Modified: 30.6.1997 / 21:16:20 / cg" |
2731 | 1753 |
! |
1754 |
||
2721 | 1755 |
guessEncodingFrom:aString |
1756 |
"try to guess some 8-bit strings encoding by |
|
1757 |
searching for certain escape sequences. |
|
1758 |
Returns a string or nil. |
|
1759 |
This may not find the strings real encoding." |
|
1760 |
||
2751 | 1761 |
|idx ascii| |
2721 | 1762 |
|
1763 |
"/ look for JIS7 / EUC encoding ... |
|
1764 |
||
2733 | 1765 |
(aString findString:(JISEncodedString jisISO2022EscapeSequence)) ~~ 0 ifTrue:[ |
2760 | 1766 |
^ #'iso2020-jp' |
2733 | 1767 |
]. |
2721 | 1768 |
(aString findString:(JISEncodedString jis7KanjiEscapeSequence)) ~~ 0 ifTrue:[ |
1769 |
^ #jis7 |
|
1770 |
]. |
|
1771 |
(aString findString:(JISEncodedString oldJis7KanjiEscapeSequence)) ~~ 0 ifTrue:[ |
|
1772 |
^ #jis7 |
|
1773 |
]. |
|
1774 |
||
1775 |
"/ TODO: |
|
1776 |
||
2735 | 1777 |
"/ "/ look for EUC |
1778 |
"/ idx := aString findFirst:[:char | |ascii| |
|
1779 |
"/ ((ascii := char asciiValue) >= 16rA1) |
|
1780 |
"/ and:[ascii <= 16rFE]]. |
|
1781 |
"/ idx ~~ 0 ifTrue:[ |
|
1782 |
"/ ascii := (aString at:(idx + 1)) asciiValue. |
|
1783 |
"/ (ascii >= 16rA1 and:[ascii <= 16rFE]) ifTrue:[ |
|
1784 |
"/ ^ #euc |
|
1785 |
"/ ] |
|
1786 |
"/ ]. |
|
1787 |
||
2721 | 1788 |
"/ look for SJIS ... |
1789 |
||
1790 |
"/ look for UTS ... |
|
1791 |
||
1792 |
^ nil |
|
1793 |
||
2760 | 1794 |
"Modified: 16.7.1997 / 13:54:59 / cg" |
443 | 1795 |
! ! |
1796 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
1797 |
!CharacterArray class methodsFor:'pattern matching'! |
64 | 1798 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1799 |
matchEscapeCharacter |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1800 |
"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
|
1801 |
(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
|
1802 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1803 |
^ $\ |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1804 |
! |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1805 |
|
327 | 1806 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop ignoreCase:ignoreCase |
1807 |
"helper for match; return true if the characters from start to stop in |
|
1808 |
aString are matching the scan in matchScan from matchStart to matchStop. |
|
328 | 1809 |
The matchScan is as created by asMatchScanArray. |
327 | 1810 |
|
328 | 1811 |
This algorithm is not at all the most efficient; |
1812 |
for heavy duty pattern matching, an interface (primitive) to the regex |
|
1813 |
pattern matching package should be added." |
|
327 | 1814 |
|
1815 |
|matchEntry |
|
1816 |
mStart "{ Class: SmallInteger }" |
|
1817 |
mStop "{ Class: SmallInteger }" |
|
1818 |
sStart "{ Class: SmallInteger }" |
|
1819 |
sStop "{ Class: SmallInteger }" |
|
1820 |
mSize "{ Class: SmallInteger }" |
|
1821 |
sSize "{ Class: SmallInteger }" |
|
1822 |
index "{ Class: SmallInteger }" |
|
2561 | 1823 |
quickCheck matchLast nextMatchEntry |
986 | 1824 |
checkChar included| |
327 | 1825 |
|
1826 |
mStart := matchStart. |
|
1827 |
mStop := matchStop. |
|
1828 |
sStart := start. |
|
1829 |
sStop := stop. |
|
1830 |
||
1831 |
[true] whileTrue:[ |
|
3537 | 1832 |
"/ Transcript showCR:('match: ''' , (aString copyFrom:sStart to:sStop) , |
1833 |
"/ ''' against:' , (matchScanArray copyFrom:mStart to:mStop) printString). |
|
1834 |
||
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1835 |
mSize := mStop - mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1836 |
sSize := sStop - sStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1837 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1838 |
"empty strings match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1839 |
(mSize == 0) ifTrue:[^ (sSize == 0)]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1840 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1841 |
matchEntry := matchScanArray at:mStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1842 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1843 |
"/ the most common case first: |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1844 |
(sSize ~~ 0 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1845 |
and:[(checkChar := (aString at:sStart)) == matchEntry]) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1846 |
"advance by one and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1847 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1848 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1849 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1850 |
(matchEntry == #any) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1851 |
"restString empty -> no match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1852 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1853 |
"# matches single character" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1854 |
((sSize == 1) and:[mSize == 1]) ifTrue:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1855 |
"advance by one and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1856 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1857 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1858 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1859 |
(matchEntry == #anyString) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1860 |
"* alone matches anything" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1861 |
(mSize == 1) ifTrue:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1862 |
"restString empty & matchString not empty -> no match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1863 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1864 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1865 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1866 |
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
|
1867 |
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
|
1868 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1869 |
quickCheck := false. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1870 |
(mStop >= mStart) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1871 |
matchLast := matchScanArray at:mStop. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1872 |
(matchLast ~~ #anyString) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1873 |
(matchLast == #any) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1874 |
quickCheck := true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1875 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1876 |
matchLast == (aString at:sStop) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1877 |
quickCheck := true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1878 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1879 |
matchLast isString ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1880 |
quickCheck := matchLast includes:(aString at:sStop) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1881 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1882 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1883 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1884 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1885 |
]. |
3537 | 1886 |
quickCheck ifTrue:[ |
1887 |
" |
|
1888 |
quickCheck ok, advance from the right |
|
1889 |
" |
|
1890 |
mStop := mStop - 1. |
|
1891 |
sStop := sStop - 1 |
|
1892 |
] ifFalse:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1893 |
"/ no quick check; |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1894 |
"/ look for the next character(s) |
3537 | 1895 |
"/ and try matching there |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1896 |
"/ (to avoid recursion) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1897 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1898 |
mStart < mStop ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1899 |
nextMatchEntry := matchScanArray at:mStart+1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1900 |
nextMatchEntry isCharacter ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1901 |
sStart <= sStop ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1902 |
[true] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1903 |
ignoreCase ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1904 |
index := aString indexOf:nextMatchEntry startingAt:sStart |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1905 |
] ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1906 |
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
|
1907 |
startingAt:sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1908 |
]. |
3879 | 1909 |
(index == 0 or:[index > sStop]) ifTrue:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1910 |
^ false |
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 |
(self matchScan:matchScanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1913 |
from:(mStart + 1) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1914 |
to:mStop |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1915 |
with:aString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1916 |
from:index |
3537 | 1917 |
to:sStop |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1918 |
ignoreCase:ignoreCase |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1919 |
) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1920 |
^ true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1921 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1922 |
sStart := index + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1923 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1924 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1925 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1926 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1927 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1928 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1929 |
no quick check possible; |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1930 |
loop over all possible substrings |
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 |
index := sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1933 |
[index <= sStop] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1934 |
(self matchScan:matchScanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1935 |
from:(mStart + 1) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1936 |
to:mStop |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1937 |
with:aString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1938 |
from:index |
3537 | 1939 |
to:sStop |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1940 |
ignoreCase:ignoreCase |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1941 |
) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1942 |
^ true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1943 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1944 |
index := index + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1945 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1946 |
^ false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1947 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1948 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1949 |
(matchEntry isString) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1950 |
"testString empty -> no match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1951 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1952 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1953 |
included := false. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1954 |
"/ checkChar := aString at:sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1955 |
included := matchEntry includes:checkChar. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1956 |
included ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1957 |
ignoreCase ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1958 |
checkChar isUppercase ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1959 |
included := matchEntry includes:checkChar asLowercase. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1960 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1961 |
included := matchEntry includes:checkChar asUppercase. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1962 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1963 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1964 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1965 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1966 |
mSize := mSize - 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1967 |
included ifFalse:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1968 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1969 |
((sSize == 1) and:[mSize == 0]) ifTrue:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1970 |
"cut off 1st char and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1971 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1972 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1973 |
"/ must be single character |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1974 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1975 |
"testString empty ?" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1976 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1977 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1978 |
"first characters equal ?" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1979 |
"/ checkChar := aString at:sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1980 |
ignoreCase ifFalse:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1981 |
(checkChar asUppercase ~~ matchEntry asUppercase) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1982 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1983 |
"advance and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1984 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1985 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1986 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1987 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1988 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1989 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1990 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1991 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1992 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1993 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1994 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1995 |
scanArray := self matchScanArrayFrom:'*hello'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1996 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1997 |
CharacterArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1998 |
matchScan:scanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1999 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2000 |
to:scanArray size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2001 |
with:s |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2002 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2003 |
to:s size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2004 |
ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2005 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2006 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2007 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2008 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2009 |
scanArray := self matchScanArrayFrom:'*hello*'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2010 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2011 |
CharacterArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2012 |
matchScan:scanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2013 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2014 |
to:scanArray size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2015 |
with:s |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2016 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2017 |
to:s size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2018 |
ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2019 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2020 |
|
3879 | 2021 |
"Modified: / 15.10.1998 / 13:39:25 / cg" |
608 | 2022 |
! |
2023 |
||
2024 |
matchScanArrayFrom:aString |
|
2025 |
"scan a pattern string and decompose it into a scanArray. |
|
2026 |
This is processed faster (especially with character ranges), and |
|
2027 |
can also be reused later. (if the same pattern is to be searched again)" |
|
2028 |
||
2029 |
|coll |
|
2030 |
idx "{ Class: SmallInteger }" |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2031 |
end c1 c2 matchSet previous escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2032 |
|
5487 | 2033 |
previous := nil. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2034 |
escape := self matchEscapeCharacter. |
608 | 2035 |
|
2036 |
coll := OrderedCollection new. |
|
2037 |
idx := 1. end := aString size. |
|
2038 |
[idx <= end] whileTrue:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2039 |
|char this| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2040 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2041 |
char := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2042 |
char == $* ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2043 |
previous ~~ #anyString ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2044 |
this := #anyString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2045 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2046 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2047 |
char == $# ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2048 |
previous ~~ #anyString ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2049 |
this := #any |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2050 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2051 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2052 |
char == $[ ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2053 |
matchSet := IdentitySet new. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2054 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2055 |
idx > end ifTrue:[^ nil]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2056 |
char := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2057 |
c1 := nil. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2058 |
[char ~~ $]] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2059 |
((char == $-) and:[c1 notNil]) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2060 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2061 |
idx > end ifTrue:[^ nil]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2062 |
c2 := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2063 |
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
|
2064 |
c1 := nil. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2065 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2066 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2067 |
(char ~~ $]) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2068 |
matchSet add:char. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2069 |
c1 := char. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2070 |
idx := idx + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2071 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2072 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2073 |
idx > end ifTrue:[^ nil]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2074 |
char := aString at:idx |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2075 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2076 |
this := matchSet asString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2077 |
] ifFalse:[ |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2078 |
char == escape ifTrue:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2079 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2080 |
idx > end ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2081 |
"/ mhmh - what should we do here ? |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2082 |
this := char |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2083 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2084 |
this := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2085 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2086 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2087 |
this := char |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2088 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2089 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2090 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2091 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2092 |
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
|
2093 |
idx := idx + 1 |
608 | 2094 |
]. |
2095 |
||
2096 |
^ coll asArray |
|
2097 |
||
2098 |
" |
|
2099 |
String matchScanArrayFrom:'*ute*' |
|
2100 |
String matchScanArrayFrom:'**ute**' |
|
2101 |
String matchScanArrayFrom:'*uter' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2102 |
String matchScanArrayFrom:'\*uter' |
608 | 2103 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
2104 |
String matchScanArrayFrom:'[abcd]*' |
|
2105 |
String matchScanArrayFrom:'[a-k]*' |
|
2106 |
String matchScanArrayFrom:'*some*compl*ern*' |
|
2107 |
String matchScanArrayFrom:'[a-' |
|
2108 |
String matchScanArrayFrom:'[a-zA-Z]' |
|
2109 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
|
2110 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2111 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2112 |
"Modified: 2.4.1997 / 16:20:29 / cg" |
608 | 2113 |
! ! |
2114 |
||
5945 | 2115 |
!CharacterArray methodsFor:'Compatibility - ANSI'! |
5301
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2116 |
|
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2117 |
addLineDelimiters |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2118 |
^ self withCRs |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2119 |
! ! |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2120 |
|
608 | 2121 |
!CharacterArray methodsFor:'Compatibility - ST/V'! |
2122 |
||
2123 |
byteAt:index put:aByte |
|
2124 |
"store a byte at given index. |
|
2125 |
This is an ST/V compatibility method." |
|
2126 |
||
1333
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2127 |
"/ (aByte == 0) ifTrue:[ |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2128 |
"/ "store a space instead" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2129 |
"/ ^ 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
|
2130 |
"/ ]. |
608 | 2131 |
^ 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
|
2132 |
|
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2133 |
" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2134 |
'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
|
2135 |
'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
|
2136 |
'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
|
2137 |
" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2138 |
|
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2139 |
"Modified: 6.5.1996 / 10:35:26 / cg" |
608 | 2140 |
! |
2141 |
||
2142 |
replChar:oldChar with:newChar |
|
2143 |
"return a copy of the receiver, with all oldChars replaced |
|
2144 |
by newChar. |
|
2145 |
This is an ST/V compatibility method." |
|
2146 |
||
3656 | 2147 |
^ self copyReplaceAll:oldChar with:newChar |
608 | 2148 |
|
2149 |
" |
|
2150 |
'12345678901234567890' replChar:$0 with:$* |
|
2151 |
" |
|
3656 | 2152 |
|
2153 |
"Modified: / 18.7.1998 / 22:52:57 / cg" |
|
608 | 2154 |
! |
2155 |
||
2156 |
replChar:oldChar withString:newString |
|
2157 |
"return a copy of the receiver, with all oldChars replaced |
|
2158 |
by newString (i.e. slice in the newString in place of the oldChar). |
|
2159 |
This is an ST/V compatibility method." |
|
2160 |
||
2161 |
|tmpStream| |
|
2162 |
||
2163 |
tmpStream := WriteStream on:(self class new). |
|
2164 |
self do:[:element | |
|
2165 |
element = oldChar ifTrue:[ |
|
2166 |
tmpStream nextPutAll:newString |
|
2167 |
] ifFalse:[ |
|
2168 |
tmpStream nextPut:element |
|
2169 |
]. |
|
2170 |
]. |
|
2171 |
^ tmpStream contents |
|
2172 |
||
2173 |
" |
|
2174 |
'12345678901234567890' replChar:$0 withString:'foo' |
|
2175 |
'a string with spaces' replChar:$ withString:' foo ' |
|
2176 |
" |
|
2177 |
! |
|
2178 |
||
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2179 |
replString:subString withString:newString |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2180 |
"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
|
2181 |
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
|
2182 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2183 |
|tmpStream idx idx1| |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2184 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2185 |
tmpStream := WriteStream on:(self class new). |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2186 |
idx := 1. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2187 |
[idx ~~ 0] whileTrue:[ |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2188 |
idx1 := idx. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2189 |
idx := self indexOfSubCollection:subString startingAt:idx. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2190 |
idx ~~ 0 ifTrue:[ |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2191 |
tmpStream nextPutAll:(self copyFrom:idx1 to:idx-1). |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2192 |
tmpStream nextPutAll:newString. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2193 |
idx := idx + subString size |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2194 |
] |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2195 |
]. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2196 |
tmpStream nextPutAll:(self copyFrom:idx1). |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2197 |
^ tmpStream contents |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2198 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2199 |
" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2200 |
'12345678901234567890' replString:'123' withString:'OneTwoThree' |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2201 |
'12345678901234567890' replString:'123' withString:'*' |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2202 |
'12345678901234567890' replString:'234' withString:'foo' |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2203 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2204 |
('a string with spaces' replChar:$ withString:' foo ') |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2205 |
replString:'foo' withString:'bar' |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2206 |
" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2207 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2208 |
"Modified: / 31.5.1999 / 12:33:59 / cg" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2209 |
! |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2210 |
|
608 | 2211 |
trimBlanks |
2212 |
"return a copy of the receiver without leading |
|
2213 |
and trailing spaces. |
|
2214 |
This is an ST/V compatibility method." |
|
2215 |
||
2216 |
^ self withoutSpaces |
|
2217 |
||
2218 |
" |
|
2219 |
' spaces at beginning' trimBlanks |
|
2220 |
'spaces at end ' trimBlanks |
|
2221 |
' spaces at beginning and end ' trimBlanks |
|
2222 |
'no spaces' trimBlanks |
|
2223 |
" |
|
2224 |
! ! |
|
2225 |
||
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2226 |
!CharacterArray methodsFor:'Compatibility - Squeak'! |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2227 |
|
4989 | 2228 |
capitalized |
2229 |
^ self asUppercaseFirst |
|
2230 |
||
2231 |
" |
|
2232 |
'hello' capitalized |
|
2233 |
" |
|
2234 |
! |
|
2235 |
||
5632 | 2236 |
displayProgressAt:aPointOrNil from:start to:stop during:aBlock |
2237 |
ProgressIndicator |
|
2238 |
displayProgress:self |
|
2239 |
at:aPointOrNil |
|
2240 |
from:start |
|
2241 |
to:stop |
|
2242 |
during:aBlock. |
|
2243 |
||
2244 |
" |
|
2245 |
'dobedobedoobedoo' |
|
2246 |
displayProgressAt:(Screen current center) |
|
2247 |
from:0 to:100 |
|
2248 |
during:[:val | |
|
2249 |
0 to:100 do:[:i | |
|
2250 |
val value:i. |
|
2251 |
Delay waitForSeconds:0.05. |
|
2252 |
] |
|
2253 |
] |
|
2254 |
" |
|
2255 |
! |
|
2256 |
||
5794 | 2257 |
endsWithDigit |
2258 |
"Answer whether the receiver's final character represents a digit. 3/11/96 sw" |
|
2259 |
||
2260 |
^ self size > 0 and: [self last isDigit] |
|
2261 |
! |
|
2262 |
||
4981 | 2263 |
findTokens:delimiters |
2264 |
^ self asCollectionOfSubstringsSeparatedByAny:delimiters |
|
2265 |
! |
|
2266 |
||
4974 | 2267 |
includesSubString:aString |
2268 |
"return true, if a substring is contained in the receiver. |
|
2269 |
The compare is case sensitive." |
|
2270 |
||
2271 |
^ self includesString:aString |
|
2272 |
||
2273 |
" |
|
2274 |
'hello world' includesSubString:'Hel' |
|
2275 |
'hello world' includesSubString:'hel' |
|
2276 |
'hello world' includesSubString:'llo' |
|
2277 |
" |
|
2278 |
||
2279 |
||
2280 |
||
2281 |
! |
|
2282 |
||
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2283 |
includesSubstring:aString caseSensitive:caseSensitive |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2284 |
"return true, if a substring is contained in the receiver. |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2285 |
The argument, caseSensitive controls if case is ignored in the compare." |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2286 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2287 |
"/ for now, a q&d hack ... |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2288 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2289 |
caseSensitive ifFalse:[ |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2290 |
^ self asLowercase includesString:aString asLowercase |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2291 |
]. |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2292 |
^ self includesString:aString |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2293 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2294 |
" |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2295 |
'hello world' includesSubstring:'Hel' caseSensitive:true |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2296 |
'hello world' includesSubstring:'Hel' caseSensitive:false |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2297 |
" |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2298 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2299 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2300 |
|
4890 | 2301 |
! |
2302 |
||
2303 |
lastSpacePosition |
|
2304 |
^ self lastIndexOfSeparator |
|
2305 |
! |
|
2306 |
||
5795 | 2307 |
truncateTo:smallSize |
2308 |
"return myself or a copy shortened to smallSize. 1/18/96 sw" |
|
2309 |
||
2310 |
self size <= smallSize ifTrue:[^ self]. |
|
2311 |
^ self copyFrom: 1 to: smallSize |
|
2312 |
||
2313 |
" |
|
2314 |
'hello world' truncateTo:5 |
|
2315 |
'hello' truncateTo:10 |
|
2316 |
||
2317 |
'hello world' copyTo:5 |
|
2318 |
'hello' copyTo:10 |
|
2319 |
" |
|
2320 |
! |
|
2321 |
||
4890 | 2322 |
withBlanksTrimmed |
2323 |
"Return a copy of the receiver from which leading and trailing blanks have been trimmed." |
|
2324 |
||
2325 |
^ self withoutSpaces |
|
2326 |
||
2327 |
" |
|
2328 |
' hello world ' withBlanksTrimmed |
|
2329 |
" |
|
2330 |
||
2331 |
||
2332 |
||
2333 |
! |
|
2334 |
||
2335 |
withNoLineLongerThan: aNumber |
|
2336 |
"Answer a string with the same content as receiver, but rewrapped so that no line has more characters than the given number" |
|
2337 |
||
2338 |
| listOfLines currentLast currentStart resultString putativeLast putativeLine crPosition | |
|
2339 |
||
2340 |
aNumber isNumber not | (aNumber < 1) ifTrue: [self error: 'too narrow']. |
|
2341 |
listOfLines _ OrderedCollection new. |
|
2342 |
currentLast _ 0. |
|
2343 |
[currentLast < self size] whileTrue: |
|
2344 |
[currentStart _ currentLast + 1. |
|
2345 |
putativeLast _ (currentStart + aNumber - 1) min: self size. |
|
2346 |
putativeLine _ self copyFrom: currentStart to: putativeLast. |
|
2347 |
(crPosition _ putativeLine indexOf: Character cr) > 0 ifTrue: |
|
2348 |
[putativeLast _ currentStart + crPosition - 1. |
|
2349 |
putativeLine _ self copyFrom: currentStart to: putativeLast]. |
|
2350 |
currentLast _ putativeLast == self size |
|
2351 |
ifTrue: |
|
2352 |
[putativeLast] |
|
2353 |
ifFalse: |
|
2354 |
[currentStart + putativeLine lastSpacePosition - 1]. |
|
2355 |
currentLast <= currentStart ifTrue: |
|
2356 |
["line has NO spaces; baleout!!" |
|
2357 |
currentLast _ putativeLast]. |
|
2358 |
listOfLines add: (self copyFrom: currentStart to: currentLast) withBlanksTrimmed]. |
|
2359 |
||
2360 |
listOfLines size > 0 ifFalse: [^ '']. |
|
2361 |
resultString _ listOfLines first. |
|
2362 |
2 to: listOfLines size do: |
|
2363 |
[:i | resultString _ resultString, Character cr asString, (listOfLines at: i)]. |
|
2364 |
^ resultString |
|
2365 |
||
2366 |
" |
|
2367 |
#(5 7 20) collect: |
|
2368 |
[:i | 'Fred the bear went down to the brook to read his book in silence' withNoLineLongerThan: i] |
|
2369 |
" |
|
2370 |
||
2371 |
||
2372 |
||
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2373 |
! ! |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2374 |
|
1978 | 2375 |
!CharacterArray methodsFor:'Compatibility - V''Age'! |
608 | 2376 |
|
2377 |
addLineDelimiter |
|
2378 |
"replace all '\'-characters by line delimiter (cr) - characters. |
|
2379 |
This has been added for VisualAge compatibility." |
|
2380 |
||
2381 |
^ self withCRs |
|
2382 |
! |
|
2383 |
||
2384 |
bindWith:aString |
|
2385 |
"return a copy of the receiver, where a '%1' escape is |
|
2386 |
replaced by aString. |
|
2387 |
This has been added for VisualAge compatibility." |
|
2388 |
||
2389 |
^ self expandPlaceholdersWith:(Array with:aString) |
|
2390 |
||
2391 |
" |
|
2392 |
'do you like %1 ?' bindWith:'smalltalk' |
|
2393 |
" |
|
2394 |
! |
|
2395 |
||
2396 |
bindWith:string1 with:string2 |
|
2397 |
"return a copy of the receiver, where a '%1' escape is |
|
2398 |
replaced by string1 and '%2' is replaced by string2. |
|
2399 |
This has been added for VisualAge compatibility." |
|
2400 |
||
2401 |
^ self expandPlaceholdersWith:(Array with:string1 with:string2) |
|
2402 |
||
2403 |
" |
|
2404 |
'do you prefer %1 or rather %2 ?' |
|
2405 |
bindWith:'smalltalk' with:'c++' |
|
2406 |
" |
|
2407 |
! |
|
2408 |
||
2409 |
bindWith:str1 with:str2 with:str3 |
|
2410 |
"return a copy of the receiver, where a '%1', '%2' and '%3' escapes |
|
2411 |
are replaced by str1, str2 and str3 respectively. |
|
2412 |
This has been added for VisualAge compatibility." |
|
2413 |
||
2414 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3) |
|
2415 |
||
2416 |
" |
|
2417 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
2418 |
bindWith:'smalltalk' with:'c++' with:'c' |
|
2419 |
" |
|
2420 |
! |
|
2421 |
||
2422 |
bindWith:str1 with:str2 with:str3 with:str4 |
|
2423 |
"return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes |
|
2424 |
are replaced by str1, str2, str3 and str4 respectively. |
|
2425 |
This has been added for VisualAge compatibility." |
|
2426 |
||
2427 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4) |
|
2428 |
||
2429 |
" |
|
2430 |
'do you prefer %1 or rather %2 (not talking about %3 or even %4) ?' |
|
2431 |
bindWith:'smalltalk' with:'c++' with:'c' with:'assembler' |
|
2432 |
" |
|
2433 |
! |
|
2434 |
||
2344 | 2435 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 |
2436 |
"return a copy of the receiver, where a '%1' .. '%5' escapes |
|
2437 |
are replaced by str1 .. str5 respectively. |
|
2438 |
This has been added for VisualAge compatibility." |
|
2439 |
||
2440 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5) |
|
2441 |
||
2442 |
"Created: 31.1.1997 / 16:25:42 / cg" |
|
2443 |
! |
|
2444 |
||
5343 | 2445 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 |
2446 |
"return a copy of the receiver, where a '%1' .. '%6' escapes |
|
2447 |
are replaced by str1 .. str5 respectively. |
|
2448 |
This has been added for VisualAge compatibility." |
|
2449 |
||
2450 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
|
2451 |
with:str3 with:str4 |
|
2452 |
with:str5 with:str6) |
|
2453 |
||
2454 |
! |
|
2455 |
||
608 | 2456 |
bindWithArguments:anArrayOfStrings |
2457 |
"return a copy of the receiver, where a '%i' escape |
|
2458 |
is replaced by the coresponding string from the argument array. |
|
2459 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
2460 |
This has been added for VisualAge compatibility." |
|
2461 |
||
2462 |
^ self expandPlaceholdersWith:anArrayOfStrings |
|
2463 |
||
2464 |
" |
|
2465 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
2466 |
bindWithArguments:#('smalltalk' 'c++' 'c') |
|
2467 |
" |
|
2468 |
! |
|
2469 |
||
2470 |
subStrings |
|
2471 |
"return an array consisting of all words contained in the receiver. |
|
2472 |
Words are separated by whitespace. |
|
2473 |
This has been added for VisualAge compatibility." |
|
2474 |
||
2475 |
^ self asCollectionOfWords |
|
2476 |
||
2477 |
" |
|
2478 |
'hello world, this is smalltalk' subStrings |
|
2479 |
" |
|
2480 |
! |
|
2481 |
||
2482 |
subStrings:separatorCharacter |
|
2483 |
"return an array consisting of all words contained in the receiver. |
|
2484 |
Words are separated by separatorCharacter. |
|
2485 |
This has been added for VisualAge compatibility." |
|
2486 |
||
2487 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter |
|
2488 |
||
2489 |
" |
|
2490 |
'foo:bar:baz:smalltalk' subStrings:$: |
|
2491 |
" |
|
2492 |
! |
|
2493 |
||
2494 |
trimSeparators |
|
2495 |
"return a copy of the receiver without leading and trailing whiteSpace" |
|
2496 |
||
2497 |
^ self withoutSeparators |
|
2498 |
! ! |
|
2499 |
||
5964 | 2500 |
!CharacterArray methodsFor:'Compatibility - VW'! |
2501 |
||
6119 | 2502 |
asQualifiedReference |
2503 |
^ BindingReference pathString:(self string) |
|
2504 |
||
2505 |
! |
|
2506 |
||
5964 | 2507 |
expandMacros |
2508 |
"ST80 compatibility - expand '<..>' macros with |
|
2509 |
argument strings. Similar to #bindWith:. |
|
2510 |
Read the comment in #expandMacrosWithArguments: about |
|
2511 |
limited compatibility issues." |
|
2512 |
||
2513 |
^ self expandMacrosWithArguments:#() |
|
2514 |
||
2515 |
" |
|
2516 |
'hello<n>foo' expandMacros |
|
2517 |
" |
|
2518 |
||
2519 |
"Modified: / 18.6.1998 / 16:03:02 / cg" |
|
2520 |
! |
|
2521 |
||
2522 |
expandMacrosWith:arg |
|
2523 |
"ST80 compatibility - expand '<..>' macros with |
|
2524 |
argument strings. Similar to #bindWith:. |
|
2525 |
Read the comment in #expandMacrosWithArguments: about |
|
2526 |
limited compatibility issues." |
|
2527 |
||
2528 |
^ self expandMacrosWithArguments:(Array with:arg) |
|
2529 |
||
2530 |
"Created: / 1.11.1997 / 13:01:28 / cg" |
|
2531 |
"Modified: / 1.11.1997 / 13:30:50 / cg" |
|
2532 |
! |
|
2533 |
||
2534 |
expandMacrosWith:arg1 with:arg2 |
|
2535 |
"ST80 compatibility - expand '<..>' macros with |
|
2536 |
argument strings. Similar to #bindWith:. |
|
2537 |
Read the comment in #expandMacrosWithArguments: about |
|
2538 |
limited compatibility issues." |
|
2539 |
||
2540 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2) |
|
2541 |
||
2542 |
"Modified: / 6.7.1998 / 21:58:14 / cg" |
|
2543 |
! |
|
2544 |
||
2545 |
expandMacrosWith:arg1 with:arg2 with:arg3 |
|
2546 |
"ST80 compatibility - expand '<..>' macros with |
|
2547 |
argument strings. Similar to #bindWith:. |
|
2548 |
Read the comment in #expandMacrosWithArguments: about |
|
2549 |
limited compatibility issues." |
|
2550 |
||
2551 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2 with:arg3) |
|
2552 |
! |
|
2553 |
||
2554 |
expandMacrosWithArguments:argArray |
|
2555 |
"ST80 compatibility - expand '<..>' macros with |
|
2556 |
argument strings. Similar to #bindWith:. |
|
2557 |
WARNING: possibly not all ST80 expansions are supported here." |
|
2558 |
||
2559 |
"/ supported expansions: |
|
2560 |
"/ |
|
2561 |
"/ <#p> # is arg Number; slice in the args printString |
|
2562 |
"/ <#s> # is arg Number; slice in the arg itself (must be a String) |
|
2563 |
"/ <#?s1:s2> # is arg Number; slice in s1 if the arg is true, s2 otherwise |
|
2564 |
"/ <s> slice in the arg |
|
2565 |
"/ <n> replace by a newLine character |
|
2566 |
"/ <t> replace by a tab character |
|
2567 |
||
2568 |
|in out c fmt nr arg s1 s2| |
|
2569 |
||
2570 |
in := self readStream. |
|
2571 |
out := '' writeStream. |
|
2572 |
||
2573 |
[in atEnd] whileFalse:[ |
|
2574 |
c := in next. |
|
2575 |
c == $< ifTrue:[ |
|
2576 |
[in peek == $<] whileTrue:[ |
|
2577 |
out nextPut:$<. |
|
2578 |
in next. |
|
2579 |
]. |
|
2580 |
in peek == $n ifTrue:[ |
|
2581 |
out nextPut:Character cr. |
|
2582 |
in next |
|
2583 |
] ifFalse:[in peek == $t ifTrue:[ |
|
2584 |
out nextPut:Character tab. |
|
2585 |
in next |
|
2586 |
] ifFalse:[ |
|
2587 |
in peek isDigit ifFalse:[ |
|
2588 |
nr := 1 |
|
2589 |
] ifTrue:[ |
|
2590 |
"/ start an argument expansion ... |
|
2591 |
nr := Integer readFrom:in onError:nil. |
|
2592 |
nr isNil ifTrue:[ |
|
2593 |
"/ what does VW do here ? |
|
2594 |
self error:'invalid format' mayProceed:true. |
|
2595 |
^ self |
|
2596 |
]. |
|
2597 |
(nr between:1 and:argArray size) ifFalse:[ |
|
2598 |
"/ what does VW do here ? |
|
2599 |
self error:'invalid format - bad argNr' mayProceed:true. |
|
2600 |
^ self |
|
2601 |
]. |
|
2602 |
]. |
|
2603 |
arg := argArray at:nr. |
|
2604 |
||
2605 |
fmt := in next. |
|
2606 |
(fmt == $p) ifTrue:[ |
|
2607 |
"/ expand with args printString |
|
2608 |
out nextPutAll:arg printString. |
|
2609 |
] ifFalse:[ (fmt == $s) ifTrue:[ |
|
2610 |
"/ expand with arg itself |
|
2611 |
out nextPutAll:arg asString. |
|
2612 |
] ifFalse:[ (fmt == $?) ifTrue:[ |
|
2613 |
s1 := in upTo:$:. |
|
2614 |
s2 := in nextUpTo:$>. |
|
2615 |
arg ifTrue:[ |
|
2616 |
out nextPutAll:s1 |
|
2617 |
] ifFalse:[ |
|
2618 |
out nextPutAll:s2 |
|
2619 |
]. |
|
2620 |
] ifFalse:[ |
|
2621 |
"/ what does VW do here ? |
|
2622 |
self error:'invalid format' mayProceed:true. |
|
2623 |
^ self |
|
2624 |
]]]. |
|
2625 |
]]. |
|
2626 |
c := in next. |
|
2627 |
c ~~ $> ifTrue:[ |
|
2628 |
"/ what does VW do here ? |
|
2629 |
self error:'invalid format' mayProceed:true. |
|
2630 |
^ self |
|
2631 |
] |
|
2632 |
] ifFalse:[ |
|
2633 |
out nextPut:c |
|
2634 |
]. |
|
2635 |
]. |
|
2636 |
^ out contents |
|
2637 |
||
2638 |
" |
|
2639 |
'hello <1p> how are you' expandMacrosWith:(OperatingSystem getLoginName) |
|
2640 |
" |
|
2641 |
||
2642 |
"Modified: / 18.6.1998 / 16:04:46 / cg" |
|
2643 |
! ! |
|
2644 |
||
608 | 2645 |
!CharacterArray methodsFor:'character searching'! |
2646 |
||
2647 |
includesMatchCharacters |
|
2648 |
"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
|
2649 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2650 |
Here, do not care for $\ escapes" |
608 | 2651 |
|
2652 |
^ self includesAny:'*#[' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2653 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2654 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2655 |
'*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2656 |
'\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2657 |
'\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2658 |
'*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2659 |
'\\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2660 |
'foo*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2661 |
'foo\*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2662 |
'foo\' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2663 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2664 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2665 |
"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
|
2666 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2667 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2668 |
includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2669 |
"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
|
2670 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2671 |
Here, care for $\ escapes" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2672 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2673 |
|idx sz specialChars escape| |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2674 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2675 |
idx := 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2676 |
sz := self size. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2677 |
specialChars := '*#[\'. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2678 |
(escape := self class matchEscapeCharacter) ~~ $\ ifTrue:[ |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2679 |
specialChars := specialChars copy. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2680 |
specialChars at:specialChars size put:escape |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2681 |
]. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2682 |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2683 |
[true] whileTrue:[ |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2684 |
idx := self indexOfAny:specialChars startingAt:idx. |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2685 |
idx == 0 ifTrue:[^ false]. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2686 |
(self at:idx) == escape ifFalse:[^ true]. |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2687 |
idx := idx + 2. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2688 |
idx > sz ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2689 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2690 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2691 |
" |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2692 |
'*foo' includesUnescapedMatchCharacters |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2693 |
'\*foo' includesUnescapedMatchCharacters |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2694 |
'\\foo' includesUnescapedMatchCharacters |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2695 |
'\\\$foo' includesUnescapedMatchCharacters |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2696 |
'*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2697 |
'\\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2698 |
'foo*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2699 |
'foo\*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2700 |
'foo\' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2701 |
" |
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 |
"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
|
2704 |
"Created: 2.4.1997 / 17:23:26 / cg" |
608 | 2705 |
! |
2706 |
||
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2707 |
indexOfControlCharacterStartingAt:startIndex |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2708 |
"return the index of the next control character; |
4117 | 2709 |
starting the search at startIndex, searching forward; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2710 |
that is a character with asciiValue < 32. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2711 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2712 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2713 |
|start "{ Class: SmallInteger }" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2714 |
mySize "{ Class: SmallInteger }"| |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2715 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2716 |
start := startIndex. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2717 |
mySize := self size. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2718 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2719 |
start to:mySize do:[:index | |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2720 |
(self at:index) isControlCharacter ifTrue:[^ index] |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2721 |
]. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2722 |
^ 0 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2723 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2724 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2725 |
'hello world' asTwoByteString indexOfControlCharacterStartingAt:1 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2726 |
'hello world\foo' withCRsasTwoByteString indexOfControlCharacterStartingAt:1 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2727 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2728 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2729 |
"Modified: / 21.7.1998 / 17:25:07 / cg" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2730 |
! |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2731 |
|
608 | 2732 |
indexOfNonSeparatorStartingAt:startIndex |
4117 | 2733 |
"return the index of the next non-whitespace character, |
2734 |
starting the search at startIndex, searching forward; |
|
2735 |
return 0 if no non-separator was found" |
|
608 | 2736 |
|
2737 |
|start "{ Class: SmallInteger }" |
|
2738 |
mySize "{ Class: SmallInteger }"| |
|
2739 |
||
2740 |
start := startIndex. |
|
2741 |
mySize := self size. |
|
2742 |
||
2743 |
start to:mySize do:[:index | |
|
4117 | 2744 |
(self at:index) isSeparator ifFalse:[^ index] |
608 | 2745 |
]. |
2746 |
^ 0 |
|
2747 |
||
2748 |
" |
|
2749 |
' hello world' indexOfNonSeparatorStartingAt:1 |
|
4117 | 2750 |
' ' indexOfNonSeparatorStartingAt:1 |
2751 |
'a ' indexOfNonSeparatorStartingAt:2 |
|
2752 |
" |
|
2753 |
||
608 | 2754 |
" |
2755 |
|s index1 index2| |
|
2756 |
s := ' foo bar baz'. |
|
2757 |
index1 := s indexOfNonSeparatorStartingAt:1. |
|
2758 |
index2 := s indexOfSeparatorStartingAt:index1. |
|
2759 |
s copyFrom:index1 to:index2 - 1 |
|
2760 |
" |
|
2761 |
! |
|
2762 |
||
2763 |
indexOfSeparator |
|
4117 | 2764 |
"return the index of the first whitespace character; |
2765 |
starting the search at the beginning, searching forward; |
|
2766 |
return 0 if no separator was found" |
|
608 | 2767 |
|
2768 |
^ self indexOfSeparatorStartingAt:1 |
|
2769 |
||
4117 | 2770 |
" |
2771 |
'hello world' indexOfSeparator |
|
2772 |
'helloworld' indexOfSeparator |
|
2773 |
'hello ' indexOfSeparator |
|
2774 |
' hello' indexOfSeparator |
|
2775 |
" |
|
608 | 2776 |
! |
2777 |
||
2778 |
indexOfSeparatorStartingAt:startIndex |
|
4117 | 2779 |
"return the index of the next whitespace character, |
2780 |
starting the search at startIndex, searching forward; |
|
2781 |
return 0 if no separator was found" |
|
608 | 2782 |
|
2783 |
|start "{ Class: SmallInteger }" |
|
2784 |
mySize "{ Class: SmallInteger }"| |
|
2785 |
||
2786 |
start := startIndex. |
|
2787 |
mySize := self size. |
|
2788 |
||
2789 |
start to:mySize do:[:index | |
|
4117 | 2790 |
(self at:index) isSeparator ifTrue:[^ index] |
608 | 2791 |
]. |
2792 |
^ 0 |
|
2793 |
||
4117 | 2794 |
" |
2795 |
'hello world' indexOfSeparatorStartingAt:3 |
|
2796 |
' hello world' indexOfSeparatorStartingAt:3 |
|
2797 |
'hello world ' indexOfSeparatorStartingAt:3 |
|
2798 |
'hello world ' indexOfSeparatorStartingAt:6 |
|
2799 |
'hello world ' indexOfSeparatorStartingAt:7 |
|
2800 |
'helloworld ' indexOfSeparatorStartingAt:7 |
|
2801 |
'helloworld' indexOfSeparatorStartingAt:7 |
|
2802 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2803 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2804 |
|
4117 | 2805 |
lastIndexOfSeparator |
2806 |
"return the last index of the whitespace character. |
|
2807 |
(i.e. start the search at the end and search backwards); |
|
2808 |
Returns 0 if no separator is found." |
|
2809 |
||
2810 |
^ self lastIndexOfSeparatorStartingAt:(self size) |
|
2811 |
||
2812 |
" |
|
2813 |
'hello world' lastIndexOfSeparator |
|
2814 |
'helloworld' lastIndexOfSeparator |
|
2815 |
'hel lo wor ld' lastIndexOfSeparator |
|
2816 |
'hel ' lastIndexOfSeparator 6 |
|
2817 |
" |
|
2818 |
! |
|
2819 |
||
2820 |
lastIndexOfSeparatorStartingAt:startIndex |
|
2821 |
"return the index of the previous whitespace character, |
|
2822 |
starting the search at startIndex (and searching backwards); |
|
2823 |
returns 0 if no separator was found" |
|
2824 |
||
5487 | 2825 |
|start "{ Class: SmallInteger }"| |
4117 | 2826 |
|
2827 |
start := startIndex. |
|
2828 |
||
2829 |
start to:1 by:-1 do:[:index | |
|
2830 |
(self at:index) isSeparator ifTrue:[^ index] |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2831 |
]. |
4117 | 2832 |
^ 0 |
2833 |
||
2834 |
" |
|
2835 |
'hello world' lastIndexOfSeparatorStartingAt:3 |
|
2836 |
'hello world' lastIndexOfSeparatorStartingAt:7 |
|
2837 |
'helloworld' lastIndexOfSeparatorStartingAt:7 |
|
2838 |
' helloworld' lastIndexOfSeparatorStartingAt:7 |
|
2839 |
" |
|
608 | 2840 |
! ! |
2841 |
||
2842 |
!CharacterArray methodsFor:'comparing'! |
|
2843 |
||
2844 |
< something |
|
2845 |
"Compare the receiver with the argument and return true if the |
|
1252 | 2846 |
receiver is less than the argument. Otherwise return false. |
2847 |
This comparison is based on the elements ascii code - |
|
2848 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 2849 |
|
2850 |
^ (something > self) |
|
1252 | 2851 |
|
2852 |
"Modified: 22.4.1996 / 15:54:54 / cg" |
|
608 | 2853 |
! |
2854 |
||
2855 |
<= something |
|
2856 |
"Compare the receiver with the argument and return true if the |
|
1252 | 2857 |
receiver is less than or equal to the argument. Otherwise return false. |
2858 |
This comparison is based on the elements ascii code - |
|
2859 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 2860 |
|
2861 |
^ (self > something) not |
|
1252 | 2862 |
|
2863 |
"Modified: 22.4.1996 / 15:54:56 / cg" |
|
608 | 2864 |
! |
2865 |
||
2866 |
= aString |
|
2867 |
"Compare the receiver with the argument and return true if the |
|
2868 |
receiver is equal to the argument. Otherwise return false. |
|
1252 | 2869 |
|
608 | 2870 |
This compare does NOT ignore case differences, |
2871 |
therefore 'foo' = 'Foo' will return false. |
|
2872 |
Since this is incompatible to ST-80 (at least, V2.x) , this may change." |
|
2873 |
||
2874 |
|mySize "{ Class: SmallInteger }" |
|
2875 |
otherSize | |
|
2876 |
||
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2877 |
(aString isString or:[aString species == self species]) ifFalse:[ |
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2878 |
^ false |
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2879 |
]. |
608 | 2880 |
mySize := self size. |
2881 |
otherSize := aString size. |
|
2882 |
mySize == otherSize ifFalse:[^ false]. |
|
2883 |
||
2884 |
1 to:mySize do:[:index | |
|
1252 | 2885 |
(self at:index) = (aString at:index) ifFalse:[^ false]. |
608 | 2886 |
]. |
2887 |
^ true |
|
2888 |
||
2889 |
" |
|
2890 |
'foo' = 'Foo' |
|
2891 |
'foo' = 'bar' |
|
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2892 |
'foo' = 'foo' |
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2893 |
'foo' = 'foo' asText |
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2894 |
'foo' asText = 'foo' |
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
2895 |
'foo' asText = 'foo' asText |
608 | 2896 |
" |
1252 | 2897 |
|
2898 |
"Modified: 22.4.1996 / 15:53:58 / cg" |
|
608 | 2899 |
! |
2900 |
||
2901 |
> aString |
|
2902 |
"Compare the receiver with the argument and return true if the |
|
2903 |
receiver is greater than the argument. Otherwise return false. |
|
1252 | 2904 |
This comparison is based on the elements ascii code - |
2905 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
|
608 | 2906 |
|
2907 |
|mySize "{ Class: SmallInteger }" |
|
2908 |
otherSize "{ Class: SmallInteger }" |
|
2909 |
n "{ Class: SmallInteger }" |
|
2910 |
c1 c2| |
|
2911 |
||
2912 |
mySize := self size. |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
2913 |
otherSize := aString string size. |
608 | 2914 |
n := mySize min:otherSize. |
2915 |
||
2916 |
1 to:n do:[:index | |
|
1252 | 2917 |
c1 := self at:index. |
2918 |
c2 := aString at:index. |
|
2919 |
c1 > c2 ifTrue:[^ true]. |
|
2920 |
c1 < c2 ifTrue:[^ false]. |
|
608 | 2921 |
]. |
2922 |
^ mySize > otherSize |
|
1252 | 2923 |
|
2924 |
"Modified: 22.4.1996 / 15:55:00 / cg" |
|
608 | 2925 |
! |
2926 |
||
2927 |
>= something |
|
2928 |
"Compare the receiver with the argument and return true if the |
|
2929 |
receiver is greater than or equal to the argument. |
|
1252 | 2930 |
Otherwise return false. |
2931 |
This comparison is based on the elements ascii code - |
|
2932 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 2933 |
|
2934 |
^ (something > self) not |
|
1252 | 2935 |
|
2936 |
"Modified: 22.4.1996 / 15:55:03 / cg" |
|
608 | 2937 |
! |
2938 |
||
5929 | 2939 |
compareCaselessWith:aString |
2940 |
"Compare the receiver against the argument, ignoreing case. |
|
2941 |
Return 1 if the receiver is greater, 0 if equal and -1 if less than the argument. |
|
2942 |
||
2943 |
This comparison is based on the elements ascii code - |
|
2944 |
i.e. national characters are NOT treated specially. |
|
2945 |
'foo' compareWith: 'Foo' will return 0" |
|
2946 |
||
2947 |
|mySize "{ Class: SmallInteger }" |
|
2948 |
otherSize "{ Class: SmallInteger }" |
|
2949 |
n "{ Class: SmallInteger }" |
|
2950 |
c1 c2| |
|
2951 |
||
2952 |
mySize := self size. |
|
2953 |
otherSize := aString string size. |
|
2954 |
n := mySize min:otherSize. |
|
2955 |
||
2956 |
1 to:n do:[:index | |
|
2957 |
c1 := (self at:index) asLowercase. |
|
2958 |
c2 := (aString at:index) asLowercase. |
|
2959 |
c1 > c2 ifTrue:[^ 1]. |
|
2960 |
c1 < c2 ifTrue:[^ -1]. |
|
2961 |
]. |
|
2962 |
mySize > otherSize ifTrue:[^ 1]. |
|
2963 |
mySize < otherSize ifTrue:[^ -1]. |
|
2964 |
^ 0 |
|
2965 |
||
2966 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
2967 |
! |
|
2968 |
||
608 | 2969 |
compareWith:aString |
2970 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2971 |
greater, 0 if equal and -1 if less than the argument. |
|
1252 | 2972 |
This comparison is based on the elements ascii code - |
2973 |
i.e. upper/lowercase & national characters are NOT treated specially. |
|
2974 |
'foo' compareWith: 'Foo' will return 1. |
|
2975 |
while 'foo' sameAs:'Foo' will return true" |
|
608 | 2976 |
|
2977 |
|mySize "{ Class: SmallInteger }" |
|
2978 |
otherSize "{ Class: SmallInteger }" |
|
2979 |
n "{ Class: SmallInteger }" |
|
2980 |
c1 c2| |
|
2981 |
||
2982 |
mySize := self size. |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
2983 |
otherSize := aString string size. |
608 | 2984 |
n := mySize min:otherSize. |
2985 |
||
2986 |
1 to:n do:[:index | |
|
1252 | 2987 |
c1 := self at:index. |
2988 |
c2 := aString at:index. |
|
2989 |
c1 > c2 ifTrue:[^ 1]. |
|
2990 |
c1 < c2 ifTrue:[^ -1]. |
|
608 | 2991 |
]. |
2992 |
mySize > otherSize ifTrue:[^ 1]. |
|
2993 |
mySize < otherSize ifTrue:[^ -1]. |
|
2994 |
^ 0 |
|
1252 | 2995 |
|
2996 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
608 | 2997 |
! |
2998 |
||
2999 |
hash |
|
3000 |
"return an integer useful as a hash-key" |
|
3001 |
||
3002 |
%{ /* NOCONTEXT */ |
|
3003 |
||
3985 | 3004 |
REGISTER unsigned g, val; |
608 | 3005 |
REGISTER unsigned char *cp, *cp0; |
3006 |
int l; |
|
3007 |
||
1133 | 3008 |
cp = __stringVal(self); |
3009 |
l = __stringSize(self); |
|
3987 | 3010 |
if (__qClass(self) != @global(String)) { |
3985 | 3011 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
3012 |
||
3013 |
cp += n; |
|
3014 |
l -= n; |
|
608 | 3015 |
} |
3016 |
||
3017 |
/* |
|
3985 | 3018 |
* this is the dragon-book algorithm |
608 | 3019 |
*/ |
3985 | 3020 |
|
3021 |
val = 0; |
|
3022 |
switch (l) { |
|
3023 |
default: |
|
3024 |
for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) { |
|
3025 |
val = (val << 4) + *cp; |
|
3026 |
if (g = (val & 0xF0000000)) { |
|
3027 |
val ^= g >> 24; |
|
3028 |
val ^= g; |
|
3029 |
} |
|
3030 |
} |
|
3031 |
break; |
|
3032 |
case 7: |
|
3033 |
val = cp[6] << 4; |
|
3034 |
case 6: |
|
3035 |
val = (val + cp[5]) << 4; |
|
3036 |
case 5: |
|
3037 |
val = (val + cp[4]) << 4; |
|
3038 |
case 4: |
|
3039 |
val = (val + cp[3]) << 4; |
|
3040 |
case 3: |
|
3041 |
val = (val + cp[2]) << 4; |
|
3042 |
case 2: |
|
3043 |
val = (val + cp[1]) << 4; |
|
3044 |
case 1: |
|
3045 |
val = val + cp[0]; |
|
3046 |
case 0: |
|
3047 |
break; |
|
608 | 3048 |
} |
3049 |
||
3985 | 3050 |
/* |
3051 |
* multiply by large prime to spread values |
|
3052 |
* This speeds up Set and Dictionary by a factor of 10! |
|
3053 |
*/ |
|
3054 |
val *= 31415821; |
|
3055 |
RETURN ( __MKSMALLINT(val & 0x3fffffff)); |
|
608 | 3056 |
%} |
3985 | 3057 |
|
608 | 3058 |
! |
3059 |
||
3060 |
sameAs:aString |
|
3061 |
"Compare the receiver with the argument like =, but ignore |
|
1252 | 3062 |
case differences. |
3063 |
Return true or false." |
|
608 | 3064 |
|
3065 |
|mySize "{ Class: SmallInteger }" |
|
3066 |
otherSize c1 c2| |
|
3067 |
||
3195
0a1a7a4c6184
oops- sameAs returned self instead of true
Claus Gittinger <cg@exept.de>
parents:
3073
diff
changeset
|
3068 |
self == aString ifTrue:[^ true]. |
2581
d06e3bbfc294
faster #sameAs: if string is identical
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
3069 |
|
608 | 3070 |
mySize := self size. |
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3071 |
otherSize := aString string size. |
608 | 3072 |
mySize == otherSize ifFalse:[^ false]. |
3073 |
||
3074 |
1 to:mySize do:[:index | |
|
1252 | 3075 |
c1 := self at:index. |
3076 |
c2 := aString at:index. |
|
3077 |
c1 == c2 ifFalse:[ |
|
3078 |
c1 asLowercase = c2 asLowercase ifFalse:[^ false]. |
|
3079 |
] |
|
608 | 3080 |
]. |
3081 |
^ true |
|
3082 |
||
3083 |
" |
|
3084 |
'foo' sameAs: 'Foo' |
|
3085 |
'foo' sameAs: 'bar' |
|
3086 |
'foo' sameAs: 'foo' |
|
3087 |
" |
|
1252 | 3088 |
|
3089 |
"Modified: 22.4.1996 / 15:56:17 / cg" |
|
608 | 3090 |
! |
3091 |
||
5242 | 3092 |
sameAs:aString ignoreCase:ignoreCase |
3093 |
"Compare the receiver with the argument. |
|
3094 |
If ignoreCase is true, this is the same as #sameAs:, |
|
3095 |
if false, this is the same as #=." |
|
3096 |
||
3097 |
ignoreCase ifTrue:[ |
|
3098 |
^ self sameAs:aString |
|
3099 |
]. |
|
3100 |
^ self = aString |
|
3101 |
||
3102 |
" |
|
3103 |
'foo' sameAs:'Foo' ignoreCase:false |
|
3104 |
'foo' sameAs:'foo' ignoreCase:true |
|
3105 |
" |
|
3106 |
||
3107 |
! |
|
3108 |
||
608 | 3109 |
sameCharacters:aString |
3110 |
"count & return the number of characters which are the same |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3111 |
(ignoring case and emphasis) in the receiver and the argument, aString." |
608 | 3112 |
|
3113 |
|n "{ Class: SmallInteger }" |
|
986 | 3114 |
c1 c2 cnt| |
608 | 3115 |
|
3116 |
n := self size. |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3117 |
n := n min:(aString string size). |
608 | 3118 |
|
3119 |
cnt := 0. |
|
3120 |
1 to:n do:[:index | |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3121 |
c1 := self at:index. |
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3122 |
c2 := aString at:index. |
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3123 |
((c1 == c2) |
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3124 |
or:[c1 asLowercase = c2 asLowercase]) ifTrue:[ |
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3125 |
cnt := cnt + 1 |
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3126 |
] |
608 | 3127 |
]. |
3128 |
^ cnt |
|
3129 |
||
3130 |
" |
|
3131 |
'foobarbaz' sameCharacters: 'foo' |
|
3132 |
'foobarbaz' sameCharacters: 'Foo' |
|
3133 |
'foobarbaz' sameCharacters: 'baz' |
|
3134 |
" |
|
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3135 |
! |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3136 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3137 |
sameEmphasisAs:aStringOrText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3138 |
"compare the receivers and the arguments emphasis" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3139 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3140 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3141 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3142 |
" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3143 |
'hello' asText sameEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3144 |
'hello' asText sameEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3145 |
'hello' asText allBold sameEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3146 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3147 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3148 |
" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3149 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3150 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3151 |
! |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3152 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3153 |
sameStringAndEmphasisAs:aStringOrText |
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3154 |
"compare both emphasis and string of the receiver and the argument" |
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3155 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3156 |
aStringOrText isString ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3157 |
(self string = aStringOrText string) ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3158 |
self hasChangeOfEmphasis = aStringOrText hasChangeOfEmphasis ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3159 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3160 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3161 |
" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3162 |
'hello' asText sameEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3163 |
'hello' asText sameEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3164 |
'hello' asText allBold sameEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3165 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3166 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3167 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3168 |
'hello' sameEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3169 |
'hello' sameEmphasisAs: 'hello' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3170 |
'hello' sameEmphasisAs: 'fooba' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3171 |
'hello' sameEmphasisAs: 'fooba' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3172 |
'hello' sameEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3173 |
'hello' sameEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3174 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3175 |
'hello' asText sameStringAndEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3176 |
'hello' asText sameStringAndEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3177 |
'hello' asText allBold sameStringAndEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3178 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3179 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3180 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3181 |
'hello' sameStringAndEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3182 |
'hello' sameStringAndEmphasisAs: 'hello' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3183 |
'hello' sameStringAndEmphasisAs: 'fooba' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3184 |
'hello' sameStringAndEmphasisAs: 'fooba' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3185 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3186 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3187 |
" |
608 | 3188 |
! ! |
3189 |
||
3190 |
!CharacterArray methodsFor:'converting'! |
|
3191 |
||
3192 |
asArrayOfSubstrings |
|
3193 |
"return an array of substrings from the receiver, interpreting |
|
3194 |
separators (i.e. spaces & newlines) as word-delimiters. |
|
3195 |
This is a compatibility method - the actual work is done in |
|
3196 |
asCollectionOfWords." |
|
3197 |
||
3198 |
^ self asCollectionOfWords asArray |
|
3199 |
||
3200 |
" |
|
3201 |
'1 one two three four 5 five' asArrayOfSubstrings |
|
3202 |
" |
|
3203 |
! |
|
3204 |
||
3205 |
asCollectionOfLines |
|
3206 |
"return a collection containing the lines (separated by cr) |
|
3207 |
of the receiver. If multiple cr's occur in a row, the result will |
|
3208 |
contain empty strings." |
|
3209 |
||
3210 |
^ self asCollectionOfSubstringsSeparatedBy:Character cr |
|
3211 |
||
3212 |
" |
|
3213 |
'1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines |
|
3214 |
'1 one\\\\2 two\3 three' withCRs asCollectionOfLines |
|
3215 |
" |
|
3216 |
! |
|
3217 |
||
3218 |
asCollectionOfSubstringsSeparatedBy:aCharacter |
|
3219 |
"return a collection containing the lines (separated by aCharacter) |
|
3220 |
of the receiver. If aCharacter occurs multiple times in a row, |
|
3221 |
the result will contain empty strings." |
|
3222 |
||
3223 |
|lines myClass |
|
3224 |
numberOfLines "{ Class:SmallInteger }" |
|
3225 |
startIndex "{ Class:SmallInteger }" |
|
3226 |
stopIndex "{ Class:SmallInteger }" | |
|
3227 |
||
3228 |
" |
|
3229 |
count first, to avoid regrowing of the OC |
|
3230 |
" |
|
3231 |
numberOfLines := (self occurrencesOf:aCharacter) + 1. |
|
3232 |
lines := OrderedCollection new:numberOfLines. |
|
3233 |
myClass := self species. |
|
3234 |
||
3235 |
startIndex := 1. |
|
3236 |
1 to:numberOfLines do:[:lineNr | |
|
3237 |
stopIndex := self indexOf:aCharacter startingAt:startIndex. |
|
3238 |
stopIndex == 0 ifTrue:[ |
|
3239 |
stopIndex := self size |
|
3240 |
] ifFalse: [ |
|
3241 |
stopIndex := stopIndex - 1. |
|
3242 |
]. |
|
3243 |
||
3244 |
(stopIndex < startIndex) ifTrue: [ |
|
3245 |
lines add:(myClass new:0) |
|
3246 |
] ifFalse: [ |
|
3247 |
lines add:(self copyFrom:startIndex to:stopIndex) |
|
3248 |
]. |
|
3249 |
startIndex := stopIndex + 2 |
|
3250 |
]. |
|
3251 |
^ lines |
|
3252 |
||
3253 |
" |
|
3254 |
'1 one:2 two:3 three:4 four:5 five' withCRs asCollectionOfSubstringsSeparatedBy:$: |
|
3255 |
'1 one 2 two 3 three 4 four 5 five' withCRs asCollectionOfSubstringsSeparatedBy:Character space |
|
3256 |
" |
|
3257 |
! |
|
3258 |
||
3259 |
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators |
|
3260 |
"return a collection containing the words (separated by any character |
|
3261 |
from aCollectionOfSeparators) of the receiver. |
|
3262 |
This allows breaking up strings using any character as separator." |
|
3263 |
||
3264 |
|words |
|
3265 |
start "{ Class:SmallInteger }" |
|
3266 |
stop "{ Class:SmallInteger }" |
|
3267 |
mySize "{ Class:SmallInteger }"| |
|
3268 |
||
3269 |
words := OrderedCollection new. |
|
3270 |
start := 1. |
|
3271 |
mySize := self size. |
|
3272 |
[start <= mySize] whileTrue:[ |
|
3273 |
"skip multiple separators" |
|
3274 |
[aCollectionOfSeparators includes:(self at:start)] whileTrue:[ |
|
3275 |
start := start + 1 . |
|
3276 |
start > mySize ifTrue:[ |
|
3277 |
^ words |
|
3278 |
]. |
|
3279 |
]. |
|
3280 |
||
3281 |
stop := self indexOfAny:aCollectionOfSeparators startingAt:start. |
|
3282 |
stop == 0 ifTrue:[ |
|
3283 |
words add:(self copyFrom:start to:mySize). |
|
3284 |
^ words |
|
3285 |
]. |
|
3286 |
words add:(self copyFrom:start to:(stop - 1)). |
|
3287 |
start := stop |
|
3288 |
]. |
|
3289 |
^ words |
|
3290 |
||
3291 |
" |
|
3292 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:) |
|
3293 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' |
|
3294 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) |
|
3295 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' |
|
3296 |
'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) |
|
3297 |
" |
|
3298 |
! |
|
3299 |
||
3300 |
asCollectionOfWords |
|
3301 |
"return a collection containing the words (separated by whitespace) |
|
3302 |
of the receiver. Multiple occurences of whitespace characters will |
|
3303 |
be treated like one - i.e. whitespace is skipped." |
|
3304 |
||
3305 |
|words |
|
3306 |
start "{ Class:SmallInteger }" |
|
3307 |
stop "{ Class:SmallInteger }" |
|
3308 |
mySize "{ Class:SmallInteger }"| |
|
3309 |
||
3310 |
words := OrderedCollection new. |
|
3311 |
start := 1. |
|
3312 |
mySize := self size. |
|
3313 |
[start <= mySize] whileTrue:[ |
|
3314 |
start := self indexOfNonSeparatorStartingAt:start. |
|
3315 |
start == 0 ifTrue:[ |
|
3316 |
^ words |
|
3317 |
]. |
|
3318 |
stop := self indexOfSeparatorStartingAt:start. |
|
3319 |
stop == 0 ifTrue:[ |
|
3320 |
words add:(self copyFrom:start to:mySize). |
|
3321 |
^ words |
|
3322 |
]. |
|
3323 |
words add:(self copyFrom:start to:(stop - 1)). |
|
3324 |
start := stop |
|
3325 |
]. |
|
3326 |
^ words |
|
3327 |
||
3328 |
" |
|
3329 |
'hello world isnt this nice' asCollectionOfWords |
|
3330 |
' hello world isnt this nice ' asCollectionOfWords |
|
3331 |
'hello' asCollectionOfWords |
|
3332 |
'' asCollectionOfWords |
|
3333 |
' ' asCollectionOfWords |
|
3334 |
" |
|
3335 |
! |
|
3336 |
||
3337 |
asComposedText |
|
1312 | 3338 |
"ST-80 compatibility |
3339 |
- ST/X does not (as today) support composedTexts." |
|
3340 |
||
608 | 3341 |
^ ComposedText fromString:self |
1312 | 3342 |
|
3343 |
"Modified: 27.4.1996 / 13:30:30 / cg" |
|
608 | 3344 |
! |
3345 |
||
3346 |
asFilename |
|
3347 |
"return a Filename with pathname taken from the receiver" |
|
3348 |
||
1423 | 3349 |
^ Filename named:self string |
3350 |
||
3351 |
"Modified: 20.5.1996 / 09:38:15 / cg" |
|
608 | 3352 |
! |
3353 |
||
3060 | 3354 |
asFixedPoint |
3355 |
"read a fixedPoint number from the receiver. |
|
3356 |
Notice, that errors may occur during the read, so you better |
|
3357 |
setup some signal handler when using this method." |
|
3358 |
||
3359 |
^ FixedPoint readFromString:self |
|
3360 |
||
3361 |
" |
|
3362 |
'0.123' asFixedPoint |
|
3363 |
'12345' asFixedPoint |
|
3364 |
'(1/5)' asFixedPoint |
|
3365 |
'foo' asFixedPoint |
|
3366 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asFixedPoint] |
|
3367 |
" |
|
3368 |
||
3369 |
"Modified: / 25.10.1997 / 15:19:00 / cg" |
|
3370 |
! |
|
3371 |
||
3372 |
asFixedPoint:scale |
|
3373 |
"read a fixedPoint number with scale number of post-decimal digits |
|
3374 |
from the receiver. Scale controls the number of displayed digits, |
|
3375 |
not the number of actually valid digits. |
|
3376 |
Notice, that errors may occur during the read, so you better |
|
3377 |
setup some signal handler when using this method." |
|
3378 |
||
3379 |
^ (FixedPoint readFromString:self) scale:scale |
|
3380 |
||
3381 |
" |
|
3382 |
'0.123' asFixedPoint:2 |
|
3383 |
'123456' asFixedPoint:2 |
|
3384 |
('3.14157' asFixedPoint:1) asFixedPoint:5 |
|
3385 |
" |
|
3386 |
||
3387 |
"Modified: / 25.10.1997 / 15:21:57 / cg" |
|
3388 |
! |
|
3389 |
||
608 | 3390 |
asFloat |
3391 |
"read a float number from the receiver. |
|
3392 |
Notice, that errors may occur during the read, so you better |
|
3393 |
setup some signal handler when using this method." |
|
3394 |
||
3395 |
^ (Number readFromString:self) asFloat |
|
3396 |
||
3397 |
" |
|
3398 |
'0.123' asFloat |
|
3399 |
'12345' asFloat |
|
3400 |
'(1/5)' asFloat |
|
3401 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asFloat] |
|
3402 |
" |
|
3403 |
! |
|
3404 |
||
3405 |
asInteger |
|
3406 |
"read an integer from the receiver. |
|
3407 |
Notice, that errors may occur during the read, so you better |
|
3408 |
setup some signal handler when using this method." |
|
3409 |
||
3410 |
^ Integer readFromString:self |
|
3411 |
||
3412 |
" |
|
3413 |
'12345678901234567890' asInteger |
|
3414 |
'-1234' asInteger |
|
3415 |
'0.123' asInteger <- reader stops at ., returning 0 here |
|
3416 |
'0.123' asNumber <- returns what you expect |
|
3417 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asInteger] |
|
3418 |
" |
|
3419 |
! |
|
3420 |
||
3421 |
asLowercase |
|
3422 |
"return a copy of myself in lowercase letters" |
|
3423 |
||
3424 |
|newStr |
|
3425 |
mySize "{ Class: SmallInteger }" | |
|
3426 |
||
3427 |
mySize := self size. |
|
3428 |
newStr := self species new:mySize. |
|
3429 |
1 to:mySize do:[:i | |
|
3430 |
newStr at:i put:(self at:i) asLowercase |
|
3431 |
]. |
|
3432 |
^ newStr |
|
3433 |
||
3434 |
" |
|
3435 |
'HelloWorld' asLowercase |
|
3436 |
'HelloWorld' asLowercaseFirst |
|
3437 |
" |
|
3438 |
! |
|
3439 |
||
3440 |
asLowercaseFirst |
|
3441 |
"return a copy of myself where the first character is |
|
3442 |
converted to lowercase." |
|
3443 |
||
3444 |
|newString sz| |
|
3445 |
||
3446 |
sz := self size. |
|
3447 |
newString := self copyFrom:1 to:sz. |
|
3448 |
sz > 0 ifTrue:[ |
|
3449 |
newString at:1 put:(newString at:1) asLowercase |
|
3450 |
]. |
|
3451 |
^ newString |
|
3452 |
||
3453 |
" |
|
3454 |
'HelloWorld' asLowercase |
|
3455 |
'HelloWorld' asLowercaseFirst |
|
3456 |
" |
|
3457 |
! |
|
3458 |
||
3459 |
asNumber |
|
3460 |
"read a number from the receiver. |
|
3461 |
Notice, that (in contrast to ST-80) errors may occur during the read, |
|
3462 |
so you better setup some signal handler when using this method. |
|
3463 |
This may change if ANSI specifies it." |
|
3464 |
||
3465 |
"/ ST-80 behavior: |
|
3466 |
"/ ^ Number readFromString:self onError:0 |
|
3467 |
||
3468 |
^ Number readFromString:self |
|
3469 |
||
3470 |
" |
|
3471 |
'123' asNumber |
|
3472 |
'123.567' asNumber |
|
3473 |
'(5/6)' asNumber |
|
3474 |
'foo' asNumber |
|
3475 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] |
|
3476 |
" |
|
3477 |
! |
|
3478 |
||
3479 |
asNumberFromFormatString:ignored |
|
3480 |
"read a number from the receiver, ignoring any nonDigit characters. |
|
3481 |
This is typically used to convert from strings which include |
|
3482 |
dollar-signs or millenium digits. However, this method also ignores |
|
3483 |
the decimal point (if any) and therefore should be used with care." |
|
3484 |
||
3485 |
|tempString| |
|
3486 |
||
3487 |
tempString := self collect:[:char | char isDigit]. |
|
3488 |
^ Number readFromString:tempString onError:0 |
|
3489 |
||
3490 |
" |
|
3491 |
'USD 123' asNumberFromFormatString:'foo' |
|
3492 |
'DM 123' asNumberFromFormatString:'foo' |
|
3493 |
'123' asNumberFromFormatString:'foo' |
|
3494 |
'123.567' asNumberFromFormatString:'foo' |
|
3495 |
'(5/6)' asNumberFromFormatString:'foo' |
|
3496 |
'foo' asNumberFromFormatString:'foo' |
|
3497 |
" |
|
3498 |
! |
|
3499 |
||
3500 |
asSingleByteString |
|
3501 |
"return the receiver converted to a 'normal' string" |
|
3502 |
||
3503 |
^ String fromString:self |
|
3504 |
! |
|
3505 |
||
2732 | 3506 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
3507 |
"return the receiver converted to a 'normal' string, |
|
3508 |
with invalid characters replaced by replacementCharacter. |
|
3509 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
3510 |
and replace characters above code-255 with some replacement." |
|
3511 |
||
3512 |
|newString| |
|
3513 |
||
3514 |
newString := String new:(self size). |
|
3515 |
1 to:self size do:[:idx | |
|
3516 |
|char| |
|
3517 |
||
3518 |
char := self at:idx. |
|
3519 |
char asciiValue <= 16rFF ifTrue:[ |
|
3520 |
newString at:idx put:char |
|
3521 |
] ifFalse:[ |
|
3522 |
newString at:idx put:replacementCharacter |
|
3523 |
]. |
|
3524 |
]. |
|
3525 |
^ newString |
|
3526 |
||
3527 |
"Created: 30.6.1997 / 13:02:14 / cg" |
|
3528 |
! |
|
3529 |
||
5843 | 3530 |
asSoundexCode |
3531 |
"return a soundex string or nil" |
|
3532 |
||
3533 |
|sz s d ch last lch n codes sc| |
|
3534 |
||
3535 |
s := self readStream. |
|
3536 |
s skipSeparators. |
|
3537 |
s atEnd ifTrue:[ |
|
3538 |
^ nil |
|
3539 |
]. |
|
3540 |
ch := s next. |
|
3541 |
ch isLetter ifFalse:[ |
|
3542 |
^ nil |
|
3543 |
]. |
|
3544 |
n := 0. |
|
3545 |
||
3546 |
codes := Dictionary new. |
|
3547 |
codes at:$b put:$1. |
|
3548 |
codes at:$p put:$1. |
|
3549 |
codes at:$f put:$1. |
|
3550 |
codes at:$v put:$1. |
|
3551 |
codes at:$c put:$2. |
|
3552 |
codes at:$s put:$2. |
|
3553 |
codes at:$k put:$2. |
|
3554 |
codes at:$g put:$2. |
|
3555 |
codes at:$j put:$2. |
|
3556 |
codes at:$q put:$2. |
|
3557 |
codes at:$x put:$2. |
|
3558 |
codes at:$z put:$2. |
|
3559 |
codes at:$d put:$3. |
|
3560 |
codes at:$t put:$3. |
|
3561 |
codes at:$l put:$4. |
|
3562 |
codes at:$m put:$5. |
|
3563 |
codes at:$n put:$5. |
|
3564 |
codes at:$r put:$6. |
|
3565 |
||
3566 |
d := '' writeStream. |
|
3567 |
d nextPut:(ch asUppercase). |
|
3568 |
||
3569 |
[s atEnd] whileFalse:[ |
|
3570 |
ch := s next. |
|
3571 |
lch := ch asLowercase. |
|
3572 |
lch = last ifFalse:[ |
|
3573 |
last := lch. |
|
3574 |
||
3575 |
sc := codes at:ch ifAbsent:nil. |
|
3576 |
sc notNil ifTrue:[ |
|
3577 |
n < 3 ifTrue:[ |
|
3578 |
d nextPut:sc. |
|
3579 |
n := n + 1. |
|
3580 |
] |
|
3581 |
] ifFalse:[ |
|
3582 |
"/ ch isLetter ifFalse:[ |
|
3583 |
"/ "/ something else - ignore it |
|
3584 |
"/ ] ifTrue:[ |
|
3585 |
"/ "/ else its a vowel and we ignore it |
|
3586 |
"/ ] |
|
3587 |
]. |
|
3588 |
] |
|
3589 |
]. |
|
3590 |
[ n < 3 ] whileTrue:[ |
|
3591 |
d nextPut:$0. |
|
3592 |
n := n + 1. |
|
3593 |
]. |
|
3594 |
||
3595 |
^ d contents |
|
3596 |
||
3597 |
" |
|
3598 |
'claus' asSoundexCode |
|
3599 |
'clause' asSoundexCode |
|
3600 |
'close' asSoundexCode |
|
3601 |
'smalltalk' asSoundexCode |
|
3602 |
'smaltalk' asSoundexCode |
|
3603 |
'smaltak' asSoundexCode |
|
3604 |
'smaltok' asSoundexCode |
|
3605 |
'smoltok' asSoundexCode |
|
3606 |
'aa' asSoundexCode |
|
3607 |
'by' asSoundexCode |
|
3608 |
'bab' asSoundexCode |
|
3609 |
'bob' asSoundexCode |
|
3610 |
'bop' asSoundexCode |
|
3611 |
" |
|
3612 |
! |
|
3613 |
||
608 | 3614 |
asString |
3615 |
"return myself - I am a string" |
|
3616 |
||
3617 |
^ self |
|
3618 |
! |
|
3619 |
||
3620 |
asStringCollection |
|
3621 |
"return a collection of lines from myself." |
|
3622 |
||
1393 | 3623 |
^ StringCollection from:self "string" |
3624 |
||
3625 |
"Modified: 13.5.1996 / 20:36:59 / cg" |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3626 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3627 |
|
1434 | 3628 |
asSymbol |
3629 |
"return a unique symbol with the name taken from my characters. |
|
3630 |
The receiver must be a singleByte-String; twoByteSymbols are |
|
3631 |
(currently) not allowed." |
|
3632 |
||
3633 |
^ self string asSymbol |
|
3634 |
||
3635 |
"Created: 22.5.1996 / 15:56:11 / cg" |
|
3636 |
! |
|
3637 |
||
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3638 |
asSymbolIfInterned |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3639 |
"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
|
3640 |
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
|
3641 |
symbol and is the same as |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3642 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3643 |
but slightly faster, since the symbol lookup operation is only |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3644 |
performed once. |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3645 |
The receiver must be a singleByte-String; twoByteSymbols are |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3646 |
(currently) not allowed." |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3647 |
|
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3648 |
^ self string asSymbolIfInterned |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3649 |
|
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3650 |
"Created: 22.5.1996 / 16:37:04 / cg" |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3651 |
! |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3652 |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3653 |
asText |
1381 | 3654 |
"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
|
3655 |
|
4974 | 3656 |
Text isNil ifTrue:[^ self]. |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3657 |
^ Text fromString:self |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3658 |
|
1381 | 3659 |
"Created: 12.5.1996 / 10:41:14 / cg" |
608 | 3660 |
! |
3661 |
||
3662 |
asTwoByteString |
|
3663 |
"return the receiver converted to a two-byte string" |
|
3664 |
||
3665 |
^ TwoByteString fromString:self |
|
3666 |
! |
|
3667 |
||
5776 | 3668 |
asURL |
3669 |
"return an URL-object from myself." |
|
3670 |
||
3671 |
^ URL fromString:self |
|
3672 |
||
3673 |
" |
|
3674 |
'http://www.exept.de:80/index.html' asURL host |
|
3675 |
'http://www.exept.de:80/index.html' asURL port |
|
3676 |
'http://www.exept.de:80/index.html' asURL method |
|
3677 |
'http://www.exept.de:80/index.html' asURL path |
|
3678 |
" |
|
3679 |
! |
|
3680 |
||
608 | 3681 |
asUppercase |
3682 |
"return a copy of myself in uppercase letters" |
|
3683 |
||
3684 |
|newStr |
|
3685 |
mySize "{ Class: SmallInteger }" | |
|
3686 |
||
3687 |
mySize := self size. |
|
3688 |
newStr := self species new:mySize. |
|
3689 |
1 to:mySize do:[:i | |
|
3690 |
newStr at:i put:(self at:i) asUppercase |
|
3691 |
]. |
|
3692 |
^ newStr |
|
3693 |
||
3694 |
" |
|
3695 |
'helloWorld' asUppercase |
|
3696 |
'helloWorld' asUppercaseFirst |
|
3697 |
" |
|
3698 |
! |
|
3699 |
||
3700 |
asUppercaseFirst |
|
3701 |
"return a copy of myself where the first character is |
|
3702 |
converted to uppercase." |
|
3703 |
||
3704 |
|newString sz| |
|
3705 |
||
3706 |
sz := self size. |
|
3707 |
newString := self copyFrom:1 to:sz. |
|
3708 |
sz > 0 ifTrue:[ |
|
3709 |
newString at:1 put:(newString at:1) asUppercase |
|
3710 |
]. |
|
3711 |
^ newString |
|
3712 |
||
3713 |
" |
|
3714 |
'helloWorld' asUppercase |
|
3715 |
'helloWorld' asUppercaseFirst |
|
3716 |
'HelloWorld' asUppercaseFirst |
|
3717 |
" |
|
3718 |
! |
|
3719 |
||
3720 |
string |
|
1312 | 3721 |
"return the receiver - for ST-80 compatibility" |
3722 |
||
608 | 3723 |
^ self |
1312 | 3724 |
|
3725 |
"Modified: 27.4.1996 / 13:29:30 / cg" |
|
608 | 3726 |
! |
3727 |
||
3728 |
tokensBasedOn:aCharacter |
|
3729 |
"this is an ST-80 alias for the ST/X method |
|
3730 |
asCollectionOfSubstringsSeparatedBy:" |
|
3731 |
||
3732 |
^ self asCollectionOfSubstringsSeparatedBy:aCharacter |
|
3733 |
||
3734 |
" |
|
3735 |
'hello:world:isnt:this nice' tokensBasedOn:$: |
|
3736 |
'foo,bar,baz' tokensBasedOn:$, |
|
3737 |
'/etc/passwd' asFilename readStream nextLine tokensBasedOn:$: |
|
3738 |
" |
|
3739 |
! ! |
|
3740 |
||
3741 |
!CharacterArray methodsFor:'copying'! |
|
3742 |
||
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3743 |
, aStringOrCharacter |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3744 |
"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
|
3745 |
This is nonStandard, but convenient" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3746 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3747 |
|myWidth otherWidth| |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3748 |
|
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3749 |
aStringOrCharacter isCharacter ifTrue:[ |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3750 |
^ self , aStringOrCharacter asString |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3751 |
]. |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3752 |
aStringOrCharacter isText ifTrue:[ |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3753 |
^ aStringOrCharacter concatenateFromString:self |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3754 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3755 |
aStringOrCharacter isString ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3756 |
(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
|
3757 |
otherWidth > myWidth ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3758 |
^ (aStringOrCharacter species fromString:self) , aStringOrCharacter |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3759 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3760 |
^ self , (self species fromString:aStringOrCharacter) |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3761 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3762 |
]. |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3763 |
^ super , aStringOrCharacter |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3764 |
|
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3765 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3766 |
'hello' , $1 |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3767 |
'hello' , '1' |
1411 | 3768 |
'hello' , (' world' asText allBold) |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3769 |
'hello' , (JISEncodedString fromString:' world') |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3770 |
(JISEncodedString fromString:'hello') , ' world' |
1411 | 3771 |
|
1422 | 3772 |
Transcript showCR: |
1411 | 3773 |
(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
|
3774 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3775 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3776 |
"Modified: 28.6.1997 / 00:13:17 / cg" |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3777 |
! |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3778 |
|
608 | 3779 |
concatenate:string1 and:string2 |
3780 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
3781 |
This is equivalent to self , string1 , string2 |
|
3782 |
- generated by compiler when such a construct is detected and the receiver |
|
3783 |
is known to be a string." |
|
3784 |
||
3785 |
^ self , string1 , string2 |
|
3786 |
! |
|
3787 |
||
3788 |
concatenate:string1 and:string2 and:string3 |
|
3789 |
"return the concatenation of myself and the string arguments. |
|
3790 |
This is equivalent to self , string1 , string2 , string3 |
|
3791 |
- generated by compiler when such a construct is detected and the receiver |
|
3792 |
is known to be a string." |
|
3793 |
||
3794 |
^ self , string1 , string2 , string3 |
|
3795 |
! ! |
|
3796 |
||
3797 |
!CharacterArray methodsFor:'displaying'! |
|
3798 |
||
2762 | 3799 |
displayOn:aGC x:x y:y from:start to:stop |
3800 |
"display the receiver on a GC" |
|
3801 |
||
3802 |
"q&d hack" |
|
3803 |
||
3804 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:false |
|
3805 |
||
3806 |
"Modified: 12.5.1996 / 12:49:33 / cg" |
|
3807 |
! |
|
3808 |
||
3809 |
displayOn:aGc x:x y:y opaque:opq |
|
3810 |
"display the receiver in a graphicsContext - this method allows |
|
3811 |
strings to be used like DisplayObjects." |
|
3812 |
||
3813 |
|s| |
|
3814 |
||
3815 |
s := self string. |
|
3816 |
opq ifTrue:[ |
|
3817 |
aGc displayOpaqueString:s x:x y:y. |
|
3818 |
] ifFalse:[ |
|
3819 |
aGc displayString:s x:x y:y. |
|
3820 |
]. |
|
1381 | 3821 |
|
3822 |
"Modified: 11.5.1996 / 14:42:48 / cg" |
|
3823 |
! |
|
3824 |
||
2762 | 3825 |
displayOpaqueOn:aGC x:x y:y from:start to:stop |
3826 |
"display the receiver on a GC" |
|
3827 |
||
3828 |
"q&d hack" |
|
3829 |
||
3830 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:true |
|
3831 |
||
3832 |
"Created: 12.5.1996 / 12:29:37 / cg" |
|
3833 |
"Modified: 12.5.1996 / 12:49:19 / cg" |
|
608 | 3834 |
! ! |
3835 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3836 |
!CharacterArray methodsFor:'emphasis'! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3837 |
|
5732 | 3838 |
allBold |
3839 |
"return a test object representing the receiver, but all boldified" |
|
3840 |
||
3841 |
^ self asText allBold |
|
3842 |
||
3843 |
" |
|
3844 |
Transcript showCR:'hello' asText allBold |
|
3845 |
Transcript showCR:'hello' allBold |
|
3846 |
" |
|
3847 |
! |
|
3848 |
||
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3849 |
allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3850 |
"return a test object representing the receiver, but all in italic" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3851 |
|
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3852 |
^ self asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3853 |
|
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3854 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3855 |
Transcript showCR:'hello' asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3856 |
Transcript showCR:'hello' allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3857 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3858 |
! |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
3859 |
|
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3860 |
emphasis |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3861 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3862 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3863 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3864 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3865 |
^ RunArray new:self size withAll:nil |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3866 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3867 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3868 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3869 |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3870 |
emphasisAt:characterIndex |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3871 |
"return the emphasis at some index. |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3872 |
Since characterArrays do not hold any emphasis information, |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3873 |
nil (no emphasis) is returned here." |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3874 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3875 |
^ nil |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3876 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3877 |
"Created: 11.5.1996 / 14:13:27 / cg" |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3878 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3879 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3880 |
emphasisCollection |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3881 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3882 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3883 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3884 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3885 |
^ RunArray new:(self size) |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3886 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3887 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3888 |
"Modified: 14.5.1996 / 15:02:29 / cg" |
3404 | 3889 |
! |
3890 |
||
3891 |
emphasizeAllWith:emphasis |
|
3892 |
^ self asText emphasizeAllWith:emphasis |
|
3893 |
||
3894 |
" |
|
3895 |
Transcript showCR:('hello' emphasizeAllWith:#bold) |
|
3599 | 3896 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
3897 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
|
3898 |
" |
|
3899 |
||
3900 |
"Modified: / 17.6.1998 / 12:51:44 / cg" |
|
5097 | 3901 |
! |
3902 |
||
3903 |
makeSelectorBoldIn:aClass |
|
3904 |
"the receiver represents some source code for |
|
3905 |
a method in aClass. |
|
3906 |
Change myself to boldify the selector. |
|
3907 |
Not yet implemented (could easily use the syntaxHighlighter |
|
3908 |
for this ...)" |
|
3909 |
||
3910 |
^ self |
|
3911 |
||
3912 |
"Modified: / 13.12.1999 / 21:49:11 / cg" |
|
3913 |
"Created: / 13.12.1999 / 21:49:24 / cg" |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3914 |
! ! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3915 |
|
5469
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3916 |
!CharacterArray methodsFor:'encoding'! |
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3917 |
|
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3918 |
encodeOn:anEncoder with:aParameter |
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3919 |
|
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3920 |
anEncoder encodeString:self with:aParameter |
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3921 |
|
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3922 |
! ! |
8aca7ce5626f
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5440
diff
changeset
|
3923 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3924 |
!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
|
3925 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3926 |
decodeFrom:encodingSymbol |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3927 |
"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
|
3928 |
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
|
3929 |
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
|
3930 |
(and those are untested/incomplete): |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3931 |
#euc |
997
6c7f1815ed02
more encoding & decoding support
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
3932 |
#jis7 |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
3933 |
#sjis |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3934 |
#mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3935 |
#msdos |
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 |
|
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3938 |
|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
|
3939 |
|
2736 | 3940 |
encodingSymbol == #'x-jis7' ifTrue:[ |
2733 | 3941 |
^ JISEncodedString decodeFromJIS7:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3942 |
]. |
2758 | 3943 |
encodingSymbol == #'x-iso2022-jp' ifTrue:[ |
3944 |
^ JISEncodedString decodeFromJIS7:self |
|
3945 |
]. |
|
2759 | 3946 |
encodingSymbol == #'iso2022-jp' ifTrue:[ |
3947 |
^ JISEncodedString decodeFromJIS7:self |
|
3948 |
]. |
|
2736 | 3949 |
encodingSymbol == #'x-sjis' ifTrue:[ |
2733 | 3950 |
^ JISEncodedString decodeFromSJIS:self |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3951 |
]. |
2736 | 3952 |
encodingSymbol == #'x-shift-jis' ifTrue:[ |
3953 |
^ JISEncodedString decodeFromSJIS:self |
|
3954 |
]. |
|
3955 |
encodingSymbol == #'x-euc-jp' ifTrue:[ |
|
2733 | 3956 |
^ 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
|
3957 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3958 |
encodingSymbol == #big5 ifTrue:[ |
2733 | 3959 |
^ 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
|
3960 |
]. |
2736 | 3961 |
encodingSymbol == #gb2312 ifTrue:[ |
2733 | 3962 |
^ GBEncodedString decodeFromGB:self |
3963 |
]. |
|
2736 | 3964 |
encodingSymbol == #'x-euc-gb' ifTrue:[ |
3965 |
^ GBEncodedString decodeFromEUC:self |
|
3966 |
]. |
|
3967 |
encodingSymbol == #'x-euc-kr' ifTrue:[ |
|
3968 |
^ KSCEncodedString decodeFromEUC:self |
|
2733 | 3969 |
]. |
3970 |
||
3971 |
encodingSymbol == #ucs2 ifTrue:[ |
|
3972 |
^ UnicodeString decodeFromUCS2:self |
|
3973 |
]. |
|
3974 |
encodingSymbol == #ucs4 ifTrue:[ |
|
3975 |
^ UnicodeString decodeFromUCS4:self |
|
3976 |
]. |
|
3977 |
encodingSymbol == #utf7 ifTrue:[ |
|
3978 |
^ UnicodeString decodeFromUTF7:self |
|
3979 |
]. |
|
3980 |
encodingSymbol == #utf8 ifTrue:[ |
|
3981 |
^ UnicodeString decodeFromUTF8:self |
|
3982 |
]. |
|
3983 |
encodingSymbol == #utf16 ifTrue:[ |
|
3984 |
^ 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
|
3985 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3986 |
|
2736 | 3987 |
|
3988 |
"/ soon obsolete ... |
|
3989 |
encodingSymbol == #jis7 ifTrue:[ |
|
3990 |
^ JISEncodedString decodeFromJIS7:self |
|
3991 |
]. |
|
3992 |
encodingSymbol == #sjis ifTrue:[ |
|
3993 |
^ JISEncodedString decodeFromSJIS:self |
|
3994 |
]. |
|
3995 |
encodingSymbol == #euc ifTrue:[ |
|
3996 |
^ JISEncodedString decodeFromEUC:self |
|
3997 |
]. |
|
3998 |
||
3999 |
encodingSymbol == #gb ifTrue:[ |
|
4000 |
^ GBEncodedString decodeFromGB:self |
|
4001 |
]. |
|
4002 |
encodingSymbol == #ksc ifTrue:[ |
|
4003 |
^ KSCEncodedString decodeFromKSC:self |
|
4004 |
]. |
|
4005 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4006 |
table := self class decoderTableFor:encodingSymbol. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4007 |
table isNil ifTrue:[^ self]. |
2736 | 4008 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4009 |
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
|
4010 |
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
|
4011 |
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
|
4012 |
^ newString |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4013 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4014 |
"Created: 22.2.1996 / 15:06:49 / cg" |
2759 | 4015 |
"Modified: 16.7.1997 / 13:45:33 / cg" |
2733 | 4016 |
! |
4017 |
||
4018 |
encodeForDisplayInto:encodingSymbol |
|
4019 |
"given the receiver in internal ST/X encoding, |
|
4020 |
convert it into the format as described by encodingSymbol |
|
4021 |
for display. |
|
4022 |
The receiver may contain roman characters in 0..255, which |
|
4023 |
are translated according to the encodings roman translation. |
|
4024 |
For example: in JIS, roman $a is found at 16r2361. |
|
4025 |
" |
|
4026 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4027 |
|newString table| |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4028 |
|
2733 | 4029 |
encodingSymbol isNil ifTrue:[^ self]. |
4030 |
||
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4031 |
"/ notice: this method may not be moved to |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4032 |
"/ concrete TwoByte classes; it is also invoked |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4033 |
"/ to convert singleByte strings ... |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4034 |
|
2733 | 4035 |
(encodingSymbol startsWith:'jis') ifTrue:[ |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4036 |
newString := JISEncodedString encodeRomans:self. |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4037 |
|
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4038 |
"/ jisx0208.1983 has no half-width katakana |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4039 |
(encodingSymbol startsWith:'jisx0208.1983') ifTrue:[ |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4040 |
newString := JISEncodedString encodeHalfWidthKatakana:newString. |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4041 |
]. |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4042 |
^ newString |
2733 | 4043 |
]. |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4044 |
|
2733 | 4045 |
(encodingSymbol startsWith:'big5') ifTrue:[ |
4046 |
^ BIG5EncodedString encodeRomans:self |
|
4047 |
]. |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4048 |
|
2733 | 4049 |
(encodingSymbol startsWith:'gb') ifTrue:[ |
4050 |
^ GBEncodedString encodeRomans:self |
|
4051 |
]. |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4052 |
|
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4053 |
(encodingSymbol startsWith:'ksc') ifTrue:[ |
2733 | 4054 |
^ KSCEncodedString encodeRomans:self |
4055 |
]. |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4056 |
|
2733 | 4057 |
(encodingSymbol startsWith:'uni') ifTrue:[ |
4058 |
^ UnicodeString encodeRomans:self |
|
4059 |
]. |
|
4060 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4061 |
table := self class encoderTableFor:encodingSymbol. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4062 |
table isNil ifTrue:[^ self]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4063 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4064 |
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
|
4065 |
newString replaceFrom:self translateBy:table. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4066 |
newString = self ifTrue:[^ self]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4067 |
^ newString |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4068 |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4069 |
"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
|
4070 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4071 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4072 |
encodeInto:encodingSymbol |
2733 | 4073 |
"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
|
4074 |
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
|
4075 |
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
|
4076 |
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
|
4077 |
(and those are untested/incomplete): |
2736 | 4078 |
#x-euc-jp |
2760 | 4079 |
#x-jis7 (== iso2022-jp) |
2736 | 4080 |
#x-sjis |
4081 |
#x-shift-jis |
|
2733 | 4082 |
#big5 |
4083 |
#gb |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4084 |
#mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4085 |
#msdos |
2733 | 4086 |
#next |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4087 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4088 |
|
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4089 |
|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
|
4090 |
|
1204 | 4091 |
"/ 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
|
4092 |
|
1028 | 4093 |
encodingSymbol isNil ifTrue:[^ self]. |
4094 |
||
2736 | 4095 |
encodingSymbol == #'x-jis7' ifTrue:[ |
2733 | 4096 |
^ JISEncodedString encodeIntoJIS7:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4097 |
]. |
2759 | 4098 |
encodingSymbol == #'x-iso2022-jp' ifTrue:[ |
4099 |
^ JISEncodedString encodeIntoJIS7:self |
|
4100 |
]. |
|
4101 |
encodingSymbol == #'iso2022-jp' ifTrue:[ |
|
4102 |
^ JISEncodedString encodeIntoJIS7:self |
|
4103 |
]. |
|
2736 | 4104 |
encodingSymbol == #'x-sjis' ifTrue:[ |
2733 | 4105 |
^ JISEncodedString encodeIntoSJIS:self |
1013
0e54ddc990cb
more 16bit & encoding support
Claus Gittinger <cg@exept.de>
parents:
1012
diff
changeset
|
4106 |
]. |
2736 | 4107 |
encodingSymbol == #'x-shift-jis' ifTrue:[ |
4108 |
^ JISEncodedString encodeIntoSJIS:self |
|
4109 |
]. |
|
4110 |
encodingSymbol == #'x-euc-jp' ifTrue:[ |
|
2733 | 4111 |
^ 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
|
4112 |
]. |
2733 | 4113 |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
4114 |
encodingSymbol == #big5 ifTrue:[ |
2733 | 4115 |
^ BIG5EncodedString encodeIntoBIG5:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4116 |
]. |
2736 | 4117 |
|
4118 |
encodingSymbol == #gb2312 ifTrue:[ |
|
2733 | 4119 |
^ GBEncodedString encodeIntoGB:self |
4120 |
]. |
|
2736 | 4121 |
encodingSymbol == #'x-euc-gb' ifTrue:[ |
4122 |
^ GBEncodedString encodeIntoGB:self |
|
4123 |
]. |
|
4124 |
||
4125 |
encodingSymbol == #'x-euc-kr' ifTrue:[ |
|
2733 | 4126 |
^ KSCEncodedString encodeIntoKSC:self |
4127 |
]. |
|
4128 |
||
4129 |
encodingSymbol == #ucs2 ifTrue:[ |
|
4130 |
^ 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
|
4131 |
]. |
2733 | 4132 |
encodingSymbol == #ucs4 ifTrue:[ |
4133 |
^ UnicodeString encodeIntoUCS4:self |
|
4134 |
]. |
|
4135 |
encodingSymbol == #utf7 ifTrue:[ |
|
4136 |
^ UnicodeString encodeIntoUTF7:self |
|
4137 |
]. |
|
4138 |
encodingSymbol == #utf8 ifTrue:[ |
|
4139 |
^ UnicodeString encodeIntoUTF8:self |
|
4140 |
]. |
|
4141 |
encodingSymbol == #utf16 ifTrue:[ |
|
4142 |
^ 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
|
4143 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
4144 |
|
2736 | 4145 |
|
4146 |
"/ to be obsoleted ... |
|
4147 |
encodingSymbol == #jis7 ifTrue:[ |
|
4148 |
^ JISEncodedString encodeIntoJIS7:self |
|
4149 |
]. |
|
4150 |
encodingSymbol == #sjis ifTrue:[ |
|
4151 |
^ JISEncodedString encodeIntoSJIS:self |
|
4152 |
]. |
|
4153 |
encodingSymbol == #euc ifTrue:[ |
|
4154 |
^ JISEncodedString encodeIntoEUC:self |
|
4155 |
]. |
|
4156 |
||
4157 |
encodingSymbol == #gb ifTrue:[ |
|
4158 |
^ GBEncodedString encodeIntoGB:self |
|
4159 |
]. |
|
4160 |
encodingSymbol == #ksc ifTrue:[ |
|
4161 |
^ KSCEncodedString encodeIntoKSC:self |
|
4162 |
]. |
|
4163 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4164 |
table := self class encoderTableFor:encodingSymbol. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4165 |
table isNil ifTrue:[^ self]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4166 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4167 |
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
|
4168 |
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
|
4169 |
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
|
4170 |
^ newString |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4171 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4172 |
"Created: 22.2.1996 / 15:07:31 / cg" |
2760 | 4173 |
"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
|
4174 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4175 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4176 |
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
|
4177 |
"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
|
4178 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4179 |
^ 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
|
4180 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4181 |
"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
|
4182 |
"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
|
4183 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4184 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4185 |
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
|
4186 |
"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
|
4187 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4188 |
^ 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
|
4189 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4190 |
"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
|
4191 |
"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
|
4192 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4193 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4194 |
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
|
4195 |
"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
|
4196 |
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
|
4197 |
|
2520
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4198 |
|mySize "{ Class: SmallInteger }" |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4199 |
maxCode "{ Class: SmallInteger }" |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4200 |
char |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4201 |
oldCode "{ Class: SmallInteger }" |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4202 |
newCode| |
1023 | 4203 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4204 |
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
|
4205 |
encodingTable isNil ifTrue:[^ self]. |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4206 |
|
2520
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4207 |
maxCode := encodingTable size. |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4208 |
mySize := self size. |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4209 |
|
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4210 |
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
|
4211 |
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
|
4212 |
oldCode := char asciiValue. |
2520
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4213 |
oldCode >= maxCode ifFalse:[ |
1023 | 4214 |
newCode := encodingTable at:(oldCode + 1). |
4215 |
newCode ~~ oldCode ifTrue:[ |
|
4216 |
self at:index put:(Character value:newCode) |
|
4217 |
] |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4218 |
] |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4219 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4220 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4221 |
"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
|
4222 |
"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
|
4223 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4224 |
|
608 | 4225 |
!CharacterArray methodsFor:'padded copying'! |
4226 |
||
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4227 |
centerPaddedTo:newSize |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4228 |
"return a new string consisting of the receivers characters, |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4229 |
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
|
4230 |
the resulting string. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4231 |
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
|
4232 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4233 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4234 |
^ self centerPaddedTo:newSize with:(Character space) |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4235 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4236 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4237 |
'foo' centerPaddedTo:10 |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4238 |
123 printString centerPaddedTo:10 |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4239 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4240 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4241 |
"Created: 25.11.1995 / 10:53:57 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4242 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4243 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4244 |
centerPaddedTo:size with:padCharacter |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4245 |
"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
|
4246 |
centered (i.e. padded on both sides). |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4247 |
Characters are filled with padCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4248 |
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
|
4249 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4250 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4251 |
|len s| |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4252 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4253 |
len := self size. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4254 |
(len < size) ifTrue:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4255 |
s := self species new:size withAll:padCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4256 |
s replaceFrom:(size - len) // 2 + 1 with:self. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4257 |
^ s |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4258 |
] |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4259 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4260 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4261 |
'foo' centerPaddedTo:11 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4262 |
'fooBar' centerPaddedTo:5 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4263 |
123 printString centerPaddedTo:10 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4264 |
(' ' , 123 printString) centerPaddedTo:10 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4265 |
(Float pi printString) centerPaddedTo:15 with:(Character space) |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4266 |
(Float pi printString) centerPaddedTo:15 with:$- |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4267 |
(' ' , Float pi class name) centerPaddedTo:15 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4268 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4269 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4270 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4271 |
decimalPaddedTo:size and:afterPeriod at:decimalCharacter |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4272 |
"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
|
4273 |
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
|
4274 |
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
|
4275 |
to be padded). |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4276 |
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
|
4277 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4278 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4279 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4280 |
^ self |
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4281 |
decimalPaddedTo:size |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4282 |
and:afterPeriod |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4283 |
at:decimalCharacter |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4284 |
withLeft:(Character space) |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4285 |
right:$0 |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4286 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4287 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4288 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123 ' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4289 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4290 |
'123.' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4291 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.100' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4292 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.1 ' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4293 |
'123.123' decimalPaddedTo:10 and:3 at:$. -> ' 123.123' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4294 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4295 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4296 |
"Created: 23.12.1995 / 13:11:52 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4297 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4298 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4299 |
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
|
4300 |
"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
|
4301 |
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
|
4302 |
of the period. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4303 |
Characters on the left are filled with leftPadChar. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4304 |
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
|
4305 |
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
|
4306 |
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
|
4307 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4308 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4309 |
|
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4310 |
|s idx n rest| |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4311 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4312 |
idx := self indexOf:decimalCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4313 |
idx == 0 ifTrue:[ |
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4314 |
"/ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4315 |
"/ 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
|
4316 |
"/ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4317 |
rightPadChar isNil ifTrue:[ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4318 |
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
|
4319 |
] ifFalse:[ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4320 |
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
|
4321 |
]. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4322 |
] ifFalse:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4323 |
|
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4324 |
"/ 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
|
4325 |
n := self size - idx. |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4326 |
rest := afterPeriod - n. |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4327 |
rest > 0 ifTrue:[ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4328 |
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
|
4329 |
] ifFalse:[ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4330 |
s := '' |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4331 |
]. |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4332 |
s := self , s. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4333 |
]. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4334 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4335 |
^ s leftPaddedTo:size with:leftPadChar |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4336 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4337 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4338 |
'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
|
4339 |
'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
|
4340 |
'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
|
4341 |
'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
|
4342 |
'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
|
4343 |
'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
|
4344 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4345 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4346 |
"Modified: 23.12.1995 / 13:08:18 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4347 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4348 |
|
608 | 4349 |
leftPaddedTo:size |
4350 |
"return a new string of length size, which contains the receiver |
|
4351 |
right-adjusted (i.e. padded on the left). |
|
4352 |
Characters on the left are filled with spaces. |
|
4353 |
If the receivers size is equal or greater than the length argument, |
|
4354 |
the original receiver is returned unchanged." |
|
4355 |
||
4356 |
^ self leftPaddedTo:size with:(Character space) |
|
4357 |
||
4358 |
" |
|
4359 |
'foo' leftPaddedTo:10 |
|
4360 |
'fooBar' leftPaddedTo:5 |
|
4361 |
123 printString leftPaddedTo:10 |
|
4362 |
" |
|
4363 |
! |
|
4364 |
||
4365 |
paddedTo:newSize |
|
4366 |
"return a new string consisting of the receivers characters, |
|
4367 |
plus spaces up to length. |
|
4368 |
If the receivers size is equal or greater than the length argument, |
|
4369 |
the original receiver is returned unchanged." |
|
4370 |
||
4371 |
^ self paddedTo:newSize with:(Character space) |
|
4372 |
||
4373 |
" |
|
4374 |
'foo' paddedTo:10 |
|
4375 |
123 printString paddedTo:10 |
|
4376 |
" |
|
64 | 4377 |
! ! |
4378 |
||
328 | 4379 |
!CharacterArray methodsFor:'pattern matching'! |
4380 |
||
2551 | 4381 |
compoundMatch:aString |
3253 | 4382 |
"like match, but the receiver may be a compound match pattern, |
2551 | 4383 |
consisting of multiple simple patterns, separated by semicolons. |
4384 |
This is usable with fileName pattern fields." |
|
4385 |
||
5124
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4386 |
^self compoundMatch:aString ignoreCase:false |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4387 |
|
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4388 |
" |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4389 |
'f*' match:'foo' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4390 |
'b*' match:'foo' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4391 |
'f*;b*' match:'foo' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4392 |
'f*;b*' match:'bar' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4393 |
'f*;b*' compoundMatch:'foo' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4394 |
'f*;b*' compoundMatch:'bar' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4395 |
" |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4396 |
|
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4397 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4398 |
"Modified: / 16.12.1999 / 01:22:08 / cg" |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4399 |
! |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4400 |
|
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4401 |
compoundMatch:aString ignoreCase:ignoreCase |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4402 |
"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
|
4403 |
consisting of multiple simple patterns, separated by semicolons. |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4404 |
This is usable with fileName pattern fields." |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4405 |
|
2551 | 4406 |
|matchers| |
4407 |
||
4408 |
matchers := self asCollectionOfSubstringsSeparatedBy:$;. |
|
4409 |
matchers do:[:aPattern | |
|
5124
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4410 |
(aPattern match:aString ignoreCase:ignoreCase) ifTrue:[^ true]. |
2551 | 4411 |
]. |
4412 |
^ false. |
|
4413 |
||
4414 |
" |
|
4415 |
'f*' match:'foo' |
|
4416 |
'b*' match:'foo' |
|
4417 |
'f*;b*' match:'foo' |
|
4418 |
'f*;b*' match:'bar' |
|
4419 |
'f*;b*' compoundMatch:'foo' |
|
4420 |
'f*;b*' compoundMatch:'bar' |
|
5124
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4421 |
'f*;b*' compoundMatch:'Foo' ignoreCase:true |
2551 | 4422 |
" |
4423 |
||
3253 | 4424 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
4425 |
"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
|
4426 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
2551 | 4427 |
! |
4428 |
||
328 | 4429 |
findMatchString:matchString |
368 | 4430 |
"like findString/indexOfSubCollection, but allowing match patterns. |
328 | 4431 |
find matchstring; if found, return the index; |
4432 |
if not found, return 0." |
|
4433 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
4434 |
^ self findMatchString:matchString startingAt:1 ignoreCase:false ifAbsent:0 |
328 | 4435 |
! |
4436 |
||
4437 |
findMatchString:matchString startingAt:index |
|
4438 |
"like findString, but allowing match patterns. |
|
4439 |
find matchstring, starting at index. if found, return the index; |
|
4440 |
if not found, return 0." |
|
4441 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
4442 |
^ self findMatchString:matchString startingAt:index ignoreCase:false ifAbsent:0 |
328 | 4443 |
! |
4444 |
||
4445 |
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock |
|
4446 |
"like findString, but allowing match patterns. |
|
4447 |
find matchstring, starting at index. if found, return the index; |
|
4448 |
if not found, return the result of evaluating exceptionBlock. |
|
4449 |
This is a q&d hack - not very efficient" |
|
4450 |
||
2916 | 4451 |
|firstChar firstSet |
328 | 4452 |
startIndex "{ Class: SmallInteger }" |
4453 |
matchSize "{ Class: SmallInteger }" |
|
4454 |
mySize "{ Class: SmallInteger }" |
|
4455 |
realMatchString| |
|
4456 |
||
4457 |
matchSize := matchString size. |
|
4458 |
matchSize == 0 ifTrue:[^ index]. "empty string matches" |
|
4459 |
||
4460 |
realMatchString := matchString. |
|
4461 |
(realMatchString endsWith:$*) ifFalse:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4462 |
realMatchString := realMatchString , '*'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4463 |
matchSize := matchSize + 1 |
328 | 4464 |
]. |
4465 |
||
4466 |
mySize := self size. |
|
4467 |
firstChar := realMatchString at:1. |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
4468 |
firstChar == self class matchEscapeCharacter ifTrue:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4469 |
firstChar := realMatchString at:2. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4470 |
]. |
328 | 4471 |
|
4472 |
firstChar asString includesMatchCharacters ifTrue:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4473 |
index to:mySize do:[:col | |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4474 |
(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
|
4475 |
ifTrue:[^ col] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4476 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4477 |
^ exceptionBlock value. |
328 | 4478 |
]. |
2916 | 4479 |
ignoreCase ifTrue:[ |
4480 |
firstSet := String with:(firstChar asUppercase) with:(firstChar asLowercase). |
|
4481 |
startIndex := self indexOfAny:firstSet startingAt:index. |
|
4482 |
] ifFalse:[ |
|
4483 |
startIndex := self indexOf:firstChar startingAt:index. |
|
4484 |
]. |
|
328 | 4485 |
[startIndex == 0] whileFalse:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4486 |
(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
|
4487 |
ifTrue:[^ startIndex]. |
2916 | 4488 |
ignoreCase ifTrue:[ |
4489 |
startIndex := self indexOfAny:firstSet startingAt:(startIndex + 1). |
|
4490 |
] ifFalse:[ |
|
4491 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1). |
|
4492 |
]. |
|
328 | 4493 |
]. |
4494 |
^ exceptionBlock value |
|
4495 |
||
4496 |
" |
|
4497 |
'one two three four' findMatchString:'o[nu]' |
|
4498 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
2916 | 4499 |
'one two three four one' findMatchString:'ONE' startingAt:3 ignoreCase:true ifAbsent:0 |
328 | 4500 |
" |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4501 |
|
2916 | 4502 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
328 | 4503 |
! |
4504 |
||
608 | 4505 |
includesMatchString:matchString |
4506 |
"like includesString, but allowing match patterns. |
|
4507 |
find matchstring; if found, return true, otherwise return false" |
|
4508 |
||
4509 |
^ (self findMatchString:matchString) ~~ 0 |
|
4510 |
||
4511 |
" |
|
4512 |
'hello world' includesMatchString:'h*' |
|
4513 |
'hello world' includesMatchString:'h[aeiou]llo' |
|
4514 |
'hello world' includesMatchString:'wor*' |
|
4515 |
'hello world' includesMatchString:'woR*' |
|
4516 |
" |
|
4517 |
! |
|
4518 |
||
328 | 4519 |
match:aString |
4520 |
"return true if aString matches self, where self may contain meta-match |
|
4521 |
characters $* (to match any string) or $# (to match any character). |
|
4522 |
or [...] to match a set of characters. |
|
345 | 4523 |
Lower/uppercase are considered different. |
4524 |
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
|
4525 |
NOT the ST-80 meaning." |
328 | 4526 |
|
4527 |
^ self match:aString from:1 to:aString size ignoreCase:false |
|
4528 |
||
4529 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4530 |
'\*f*' match:'f' |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4531 |
'\*f*' match:'*f' |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4532 |
'*\*f*' match:'*f' |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4533 |
'*f*' match:'*f' |
328 | 4534 |
'*ute*' match:'computer' |
4535 |
'*uter' match:'computer' |
|
4536 |
'uter*' match:'computer' |
|
4537 |
'*ute*' match:'' |
|
4538 |
'[abcd]*' match:'computer' |
|
4539 |
'[abcd]*' match:'komputer' |
|
4540 |
'*some*compl*ern*' match:'this is some more complicated pattern match' |
|
4541 |
'*some*compl*ern*' match:'this is another complicated pattern match' |
|
3537 | 4542 |
'*-hh' match:'anton-h' |
4543 |
" |
|
4544 |
||
4545 |
"Modified: / 9.6.1998 / 18:50:00 / cg" |
|
328 | 4546 |
! |
4547 |
||
4548 |
match:aString from:start to:stop ignoreCase:ignoreCase |
|
4549 |
"return true if part of aString matches myself, |
|
4550 |
where self may contain meta-match |
|
4551 |
characters $* (to match any string) or $# (to match any character) |
|
4552 |
or [...] to match a set of characters. |
|
345 | 4553 |
If ignoreCase is true, lower/uppercase are considered the same. |
4554 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
1429 | 4555 |
NOT the ST-80 meaning." |
328 | 4556 |
|
4557 |
|matchScanArray| |
|
4558 |
||
4559 |
" |
|
4560 |
keep the matchScanArray from the most recent match - |
|
4561 |
avoids parsing the pattern over-and over if multiple searches |
|
4562 |
are done with the same pattern. |
|
4563 |
" |
|
4564 |
(PreviousMatch notNil |
|
4565 |
and:[PreviousMatch key = self]) ifTrue:[ |
|
1429 | 4566 |
matchScanArray := PreviousMatch value |
328 | 4567 |
] ifFalse:[ |
1429 | 4568 |
matchScanArray := self class matchScanArrayFrom:self. |
4569 |
matchScanArray isNil ifTrue:[ |
|
3926 | 4570 |
'CharacterArray [info]: invalid matchpattern:''' infoPrint. self infoPrint. ''' comparing for equality.' infoPrintCR. |
4571 |
^ self = aString |
|
4572 |
"/ ^ false |
|
1429 | 4573 |
]. |
4574 |
PreviousMatch := self -> matchScanArray. |
|
328 | 4575 |
]. |
4576 |
||
4577 |
^ self class |
|
1429 | 4578 |
matchScan:matchScanArray |
4579 |
from:1 to:matchScanArray size |
|
4580 |
with:aString |
|
4581 |
from:start to:stop |
|
4582 |
ignoreCase:ignoreCase |
|
328 | 4583 |
|
4584 |
" |
|
4585 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
4586 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
4587 |
" |
|
1429 | 4588 |
|
3926 | 4589 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
359 | 4590 |
! |
4591 |
||
608 | 4592 |
match:aString ignoreCase:ignoreCase |
4593 |
"return true if aString matches self, where self may contain meta-match |
|
4594 |
characters $* (to match any string) or $# (to match any character) |
|
4595 |
or [...] to match a set of characters. |
|
4596 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
4597 |
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
|
4598 |
NOT the ST-80 meaning." |
608 | 4599 |
|
4600 |
^ self match:aString from:1 to:aString size ignoreCase:ignoreCase |
|
4601 |
||
4602 |
" |
|
4603 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
4604 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
4605 |
'[abcd]*' match:'computer' ignoreCase:false |
|
4606 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
4607 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
4608 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
4609 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
4610 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
4611 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
4612 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
4613 |
||
4614 |
Time millisecondsToRun:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4615 |
Symbol allInstancesDo:[:sym | |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4616 |
'[ab]*' match:sym ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4617 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4618 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4619 |
Time millisecondsToRun:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4620 |
Symbol allInstancesDo:[:sym | |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4621 |
'*at:*' match:sym ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4622 |
] |
608 | 4623 |
]. |
4624 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4625 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4626 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
5609 | 4627 |
! |
4628 |
||
4629 |
matches:aPatternString |
|
4630 |
"return true if the receiver matches aString, where aPatternString may contain meta-match |
|
4631 |
characters $* (to match any string) or $# (to match any character). |
|
4632 |
or [...] to match a set of characters. |
|
4633 |
Lower/uppercase are considered different. |
|
4634 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
4635 |
NOT the ST-80 meaning." |
|
4636 |
||
4637 |
^ aPatternString match:self |
|
4638 |
||
4639 |
||
608 | 4640 |
! ! |
4641 |
||
4642 |
!CharacterArray methodsFor:'printing & storing'! |
|
4643 |
||
4644 |
article |
|
4645 |
"return an article string for the receiver." |
|
4646 |
||
4647 |
|firstChar| |
|
4648 |
||
4649 |
firstChar := (self at:1) asLowercase. |
|
5848 | 4650 |
((firstChar isVowel and:[firstChar ~~ $u]) or:[firstChar == $x]) ifTrue:[ |
4651 |
^ 'an' |
|
608 | 4652 |
]. |
4653 |
^ 'a' |
|
5848 | 4654 |
|
4655 |
" |
|
4656 |
'uboot' article. |
|
4657 |
'xmas' article. |
|
4658 |
'alarm' article. |
|
4659 |
'baby' article. |
|
4660 |
" |
|
608 | 4661 |
! |
4662 |
||
4663 |
displayString |
|
4664 |
"return a string to display the receiver - use storeString to have |
|
4665 |
quotes around." |
|
4666 |
||
4667 |
^ self storeString |
|
4668 |
! |
|
4669 |
||
4670 |
printOn:aStream |
|
4671 |
"print the receiver on aStream" |
|
4672 |
||
4673 |
aStream nextPutAll:self |
|
4674 |
! |
|
4675 |
||
4676 |
printString |
|
4677 |
"return a string for printing - thats myself" |
|
4678 |
||
4679 |
^ self |
|
3578 | 4680 |
! |
4681 |
||
4682 |
printWithQuotesDoubledOn:aStream |
|
4683 |
"put the raw storeString of myself on aStream" |
|
4684 |
||
4685 |
self do:[:thisChar | |
|
4686 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
4687 |
aStream nextPut:thisChar |
|
4688 |
] |
|
4689 |
||
4690 |
"Modified: / 15.6.1998 / 17:21:17 / cg" |
|
4691 |
"Created: / 15.6.1998 / 17:22:13 / cg" |
|
5848 | 4692 |
! |
4693 |
||
4694 |
utf8Encoded |
|
4695 |
"convert a string of ISO8859-1 charcters to its UTF-8 representation. |
|
4696 |
this returns a String" |
|
4697 |
||
4698 |
|s| |
|
4699 |
||
4700 |
s := (String new:self size) writeStream. |
|
4701 |
self utf8EncodedOn:s. |
|
4702 |
^ s contents |
|
4703 |
! |
|
4704 |
||
4705 |
utf8EncodedOn:aStream |
|
4706 |
||
4707 |
self do:[:c| |
|
4708 |
c utf8EncodedOn:aStream. |
|
4709 |
]. |
|
4710 |
||
4711 |
" |
|
4712 |
'Dies ist ein Test mit {} und Ümläuten' utf8Encoded |
|
4713 |
" |
|
608 | 4714 |
! ! |
4715 |
||
4716 |
!CharacterArray methodsFor:'queries'! |
|
4717 |
||
4429 | 4718 |
bitsPerCharacter |
4719 |
"return the underlying strings bitsPerCharacter |
|
4720 |
(i.e. is it a regular String or a TwoByteString)" |
|
4721 |
||
4722 |
^ self string bitsPerCharacter |
|
4723 |
||
4724 |
" |
|
4725 |
'hello' bitsPerCharacter |
|
4726 |
'hello' asText allBold bitsPerCharacter |
|
4727 |
" |
|
4728 |
! |
|
4729 |
||
608 | 4730 |
encoding |
1311 | 4731 |
"return the strings encoding, as a symbol. |
4732 |
Here, by default, we assume #iso8859 encoding. |
|
1241 | 4733 |
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
|
4734 |
|
1311 | 4735 |
^ #iso8859 |
4736 |
||
4737 |
"Modified: 27.4.1996 / 13:23:49 / cg" |
|
608 | 4738 |
! |
4739 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4740 |
hasChangeOfEmphasis |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4741 |
^ false |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4742 |
|
1381 | 4743 |
"Created: 12.5.1996 / 12:31:39 / cg" |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4744 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4745 |
|
1388 | 4746 |
heightOn:aGC |
4747 |
"return the size of the recevier in device units if displayed on aGC" |
|
4748 |
||
3337 | 4749 |
^ (aGC font on:aGC device) heightOf:self |
1388 | 4750 |
|
4751 |
" |
|
4752 |
'hello world' heightOn:(View new) |
|
4753 |
" |
|
4754 |
||
4755 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
4756 |
"Modified: 12.5.1996 / 20:32:05 / cg" |
|
4757 |
! |
|
4758 |
||
608 | 4759 |
isString |
4760 |
"return true, if the receiver is some kind of string; |
|
4761 |
true is returned here - redefinition of Object>>isString." |
|
4762 |
||
4763 |
^ true |
|
1235 | 4764 |
! |
4765 |
||
4766 |
leftIndent |
|
4767 |
"if the receiver starts with spaces, return the number of spaces |
|
4768 |
at the left - otherwise, return 0. |
|
4769 |
If the receiver consists of spaces only, return the receivers size." |
|
4770 |
||
4771 |
|index "{Class: SmallInteger }" |
|
4772 |
end "{Class: SmallInteger }"| |
|
4773 |
||
4774 |
index := 1. |
|
4775 |
end := self size. |
|
4776 |
[index <= end] whileTrue:[ |
|
4777 |
(self at:index) isSeparator ifFalse:[^ index - 1]. |
|
4778 |
index := index + 1 |
|
4779 |
]. |
|
4780 |
^ end |
|
4781 |
||
4782 |
" |
|
4783 |
' hello' leftIndent |
|
4784 |
'foo ' leftIndent |
|
4785 |
' ' leftIndent |
|
4786 |
" |
|
4787 |
||
4788 |
"Modified: 20.4.1996 / 19:28:43 / cg" |
|
1388 | 4789 |
! |
4790 |
||
4791 |
widthOn:aGC |
|
4792 |
"return ths size of the recevier in device units if displayed on aGC" |
|
4793 |
||
2554 | 4794 |
^ (aGC font on:aGC device) widthOf:self |
1388 | 4795 |
|
4796 |
" |
|
4797 |
'hello world' widthOn:(View new) |
|
4798 |
" |
|
4799 |
||
4800 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
2554 | 4801 |
"Modified: 17.4.1997 / 12:50:23 / cg" |
608 | 4802 |
! ! |
4803 |
||
4804 |
!CharacterArray methodsFor:'special string converting'! |
|
4805 |
||
4806 |
chopTo:maxLen |
|
4807 |
"if the receivers size is less or equal to maxLen, return it. |
|
4808 |
Otherwise, return a copy of the receiver, where some characters |
|
4809 |
in the middle have been removed for a total string length |
|
4810 |
of maxLen." |
|
4811 |
||
4812 |
|sz n1 n2| |
|
4813 |
||
4814 |
(sz := self size) > maxLen ifTrue:[ |
|
4815 |
n1 := n2 := maxLen // 2. |
|
4816 |
maxLen odd ifTrue:[ |
|
4817 |
n2 := n1 + 1 |
|
4818 |
]. |
|
4819 |
^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1) |
|
4820 |
] |
|
4821 |
||
4822 |
" |
|
4823 |
'12345678901234' chopTo:15 |
|
4824 |
'123456789012345' chopTo:15 |
|
4825 |
'1234567890123456' chopTo:15 |
|
4826 |
'aShortString' chopTo:15 |
|
4827 |
'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 |
|
4828 |
" |
|
4829 |
! |
|
4830 |
||
4831 |
contractAtBeginningTo:maxLen |
|
4832 |
"if the receivers size is less or equal to maxLen, return it. |
|
4833 |
Otherwise, return a copy of the receiver, where some characters |
|
4834 |
at the beginning have been replaced by '...' for a total string length |
|
4835 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
4836 |
||
4837 |
|sz| |
|
4838 |
||
4839 |
(sz := self size) > maxLen ifTrue:[ |
|
4840 |
^ '...' , (self copyFrom:(sz - (maxLen - 4))) |
|
4841 |
] |
|
4842 |
||
4843 |
" |
|
4844 |
'12345678901234' contractAtBeginningTo:15 |
|
4845 |
'123456789012345' contractAtBeginningTo:15 |
|
4846 |
'1234567890123456' contractAtBeginningTo:15 |
|
4847 |
'aShortString' contractAtBeginningTo:15 |
|
4848 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15 |
|
4849 |
" |
|
4850 |
! |
|
359 | 4851 |
|
608 | 4852 |
contractAtEndTo:maxLen |
4853 |
"if the receivers size is less or equal to maxLen, return it. |
|
4854 |
Otherwise, return a copy of the receiver, where some characters |
|
4855 |
at the end have been replaced by '...' for a total string length |
|
4856 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
4857 |
||
4858 |
|sz| |
|
4859 |
||
4860 |
(sz := self size) > maxLen ifTrue:[ |
|
4861 |
^ self copyReplaceFrom:maxLen - 3 |
|
4862 |
with:'...' |
|
4863 |
] |
|
4864 |
||
4865 |
" |
|
4866 |
'12345678901234' contractAtEndTo:15 |
|
4867 |
'123456789012345' contractAtEndTo:15 |
|
4868 |
'1234567890123456' contractAtEndTo:15 |
|
4869 |
'aShortString' contractAtEndTo:15 |
|
4870 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 |
|
4871 |
" |
|
4872 |
! |
|
4873 |
||
4874 |
contractTo:maxLen |
|
4875 |
"if the receivers size is less or equal to maxLen, return it. |
|
4876 |
Otherwise, return a copy of the receiver, where some characters |
|
4877 |
in the middle have been replaced by '...' for a total string length |
|
4878 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
4879 |
||
4880 |
|sz "{ SmallInteger }" |
|
4881 |
halfSize "{ SmallInteger }"| |
|
4882 |
||
4883 |
(sz := self size) > maxLen ifTrue:[ |
|
4884 |
halfSize := maxLen // 2. |
|
4885 |
^ self copyReplaceFrom:halfSize - 1 |
|
4886 |
to:sz - maxLen + halfSize + 1 |
|
4887 |
with:'...' |
|
4888 |
] |
|
4889 |
||
4890 |
" |
|
4891 |
'12345678901234' contractTo:15 |
|
4892 |
'123456789012345' contractTo:15 |
|
4893 |
'1234567890123456' contractTo:15 |
|
4894 |
'aShortString' contractTo:15 |
|
4895 |
'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 |
|
4896 |
" |
|
4897 |
! |
|
4898 |
||
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4899 |
expandPlaceholdersWith:argArrayOrDictionary |
608 | 4900 |
"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
|
4901 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
608 | 4902 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
4903 |
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
|
4904 |
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
|
4905 |
values for character keys. |
4842 | 4906 |
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
|
4907 |
(%1..%9 require a numeric key in the dictionary, however) |
608 | 4908 |
To get a '%' character, use a '%%'-escape. |
4909 |
See also bindWith:... for VisualAge compatibility." |
|
4910 |
||
4842 | 4911 |
|expandedString next v key |
608 | 4912 |
idx "{ SmallInteger }" |
4842 | 4913 |
idx2 "{ SmallInteger }" |
608 | 4914 |
start "{ SmallInteger }" |
4915 |
stop "{ SmallInteger }"| |
|
4916 |
||
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4917 |
expandedString := self species new:0. |
608 | 4918 |
stop := self size. |
4919 |
start := 1. |
|
4920 |
[start <= stop] whileTrue:[ |
|
5946 | 4921 |
idx := self indexOf:$% startingAt:start. |
4922 |
(idx == 0 or:[idx == stop]) ifTrue:[ |
|
4923 |
^ expandedString , (self copyFrom:start to:stop) |
|
4924 |
]. |
|
4925 |
"found a %" |
|
4926 |
expandedString := expandedString , (self copyFrom:start to:(idx - 1)). |
|
4927 |
next := self at:(idx + 1). |
|
4928 |
(next == $%) ifTrue:[ |
|
4929 |
expandedString := expandedString , '%' |
|
4930 |
] ifFalse:[ |
|
4931 |
(next between:$1 and:$9) ifTrue:[ |
|
4932 |
v := argArrayOrDictionary at:(next digitValue) ifAbsent:nil |
|
4933 |
] ifFalse:[ |
|
4934 |
next == $( ifTrue:[ |
|
4935 |
idx2 := self indexOf:$) startingAt:idx+2. |
|
4936 |
key := self copyFrom:idx+2 to:idx2-1. |
|
4937 |
idx := idx2 - 1. |
|
4938 |
v := argArrayOrDictionary at:key asSymbol ifAbsent:nil |
|
4939 |
] ifFalse:[ |
|
4940 |
v := argArrayOrDictionary at:next ifAbsent:nil. |
|
4941 |
v isNil ifTrue:[ |
|
4942 |
v := argArrayOrDictionary at:next asString asSymbol ifAbsent:nil. |
|
4943 |
]. |
|
4944 |
] |
|
4945 |
]. |
|
4946 |
v isNil ifTrue:[v := '']. |
|
4947 |
expandedString := expandedString , v printString |
|
4948 |
]. |
|
4949 |
start := idx + 2 |
|
608 | 4950 |
]. |
4951 |
^ expandedString |
|
4952 |
||
4953 |
" |
|
4954 |
'hello %1' expandPlaceholdersWith:#('world') |
|
4955 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
4956 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
1308 | 4957 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
608 | 4958 |
" |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4959 |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4960 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4961 |
|dict| |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4962 |
|
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4963 |
dict := Dictionary new. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4964 |
dict at:1 put:'one'. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4965 |
dict at:$a put:'AAAAA'. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4966 |
'hello %1 %a' expandPlaceholdersWith:dict |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4967 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
4968 |
|
2737
9f29aecea39d
care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents:
2736
diff
changeset
|
4969 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
608 | 4970 |
! |
4971 |
||
4972 |
withCRs |
|
4973 |
"return a new string consisting of receivers characters |
|
4974 |
with all \-characters replaced by cr-characters." |
|
4975 |
||
3656 | 4976 |
^ self copyReplaceAll:$\ with:(Character cr) |
608 | 4977 |
|
4978 |
" |
|
4979 |
'hello\world' withCRs |
|
4980 |
" |
|
3656 | 4981 |
|
4982 |
"Modified: / 18.7.1998 / 22:53:02 / cg" |
|
608 | 4983 |
! |
4984 |
||
4985 |
withEscapes |
|
4986 |
"return a new string consisting of receivers characters |
|
4987 |
with all \X-character escapes replaced by corresponding-characters. |
|
4988 |
(similar to the way C-language Strings are converted). |
|
4989 |
The following escapes are supported: |
|
1008 | 4990 |
\r return character |
4991 |
\n newline character |
|
4992 |
\b backspace character |
|
4993 |
\f formfeed character |
|
4994 |
\t tab character |
|
4995 |
\e escape character |
|
4996 |
\\ the \ character itself |
|
4997 |
\nnn three digit octal number defining the characters ascii value |
|
4998 |
\other other |
|
608 | 4999 |
|
5000 |
Notice, that \' is NOT a valid escape, since the general syntax of |
|
5001 |
string constants is not affected by this method. |
|
5002 |
||
5003 |
Although easily implementable, this is NOT done automatically |
|
5004 |
by the compiler (due to a lack of a language standard for this). |
|
5005 |
However, the compiler may detect sends ot #withEscapes to string literals |
|
5006 |
and place a modified string constant into the binary/byte-code. |
|
5007 |
Therefore, no runtime penalty will be payed for using these escapes. |
|
5008 |
(not in pre 2.11 versions) |
|
5009 |
" |
|
5010 |
||
5011 |
|sz "{ SmallInteger }" |
|
5012 |
newSize "{ SmallInteger }" |
|
5013 |
srcIdx "{ SmallInteger }" |
|
5014 |
dstIdx "{ SmallInteger }" |
|
5015 |
val "{ SmallInteger }" |
|
1381 | 5016 |
newString next hasEmphasis e| |
359 | 5017 |
|
5018 |
" |
|
608 | 5019 |
first, count the number of escapes, to allow preallocation |
5020 |
of the new string ... |
|
5021 |
(it is faster to scan the string twice than to reallocate it multiple |
|
5022 |
times in a WriteStream) |
|
5023 |
" |
|
5024 |
sz := newSize := self size. |
|
5025 |
srcIdx := 1. |
|
5026 |
[(srcIdx := self indexOf:$\ startingAt:srcIdx) ~~ 0] whileTrue:[ |
|
1008 | 5027 |
srcIdx == sz ifFalse:[ |
5028 |
newSize := newSize - 1. |
|
5029 |
srcIdx := srcIdx + 1. |
|
5030 |
next := self at:srcIdx. |
|
5031 |
next == $0 ifTrue:[ |
|
3527
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5032 |
[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
|
5033 |
newSize := newSize - 1. srcIdx := srcIdx + 1. next := self at:srcIdx. |
1008 | 5034 |
] |
5035 |
]. |
|
5036 |
]. |
|
5037 |
srcIdx := srcIdx + 1. |
|
608 | 5038 |
]. |
5039 |
||
5040 |
newSize == sz ifTrue:[ |
|
1008 | 5041 |
^ self |
608 | 5042 |
]. |
5043 |
||
5044 |
newString := self species new:newSize. |
|
1381 | 5045 |
|
5046 |
hasEmphasis := self hasChangeOfEmphasis. |
|
5047 |
||
608 | 5048 |
" |
5049 |
copy over, replace escapes |
|
5050 |
" |
|
5051 |
srcIdx := dstIdx := 1. |
|
5052 |
[srcIdx <= sz] whileTrue:[ |
|
1008 | 5053 |
next := self at:srcIdx. |
1381 | 5054 |
hasEmphasis ifTrue:[ |
5055 |
e := self emphasisAt:srcIdx |
|
5056 |
]. |
|
1008 | 5057 |
srcIdx := srcIdx + 1. |
5058 |
next == $\ ifTrue:[ |
|
5059 |
srcIdx <= sz ifTrue:[ |
|
5060 |
next := self at:srcIdx. |
|
5061 |
srcIdx := srcIdx + 1. |
|
5062 |
next == $r ifTrue:[ |
|
5063 |
next := Character return |
|
5064 |
] ifFalse:[ |
|
5065 |
next == $n ifTrue:[ |
|
5066 |
next := Character nl |
|
5067 |
] ifFalse:[ |
|
5068 |
next == $b ifTrue:[ |
|
5069 |
next := Character backspace |
|
5070 |
] ifFalse:[ |
|
5071 |
next == $f ifTrue:[ |
|
5072 |
next := Character newPage |
|
5073 |
] ifFalse:[ |
|
5074 |
next == $t ifTrue:[ |
|
5075 |
next := Character tab |
|
5076 |
] ifFalse:[ |
|
5077 |
next == $e ifTrue:[ |
|
5078 |
next := Character esc |
|
5079 |
] ifFalse:[ |
|
5080 |
next == $0 ifTrue:[ |
|
5081 |
val := 0. |
|
3527
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5082 |
[next notNil and:[next isDigit]] whileTrue:[ |
1008 | 5083 |
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
|
5084 |
srcIdx <= sz ifTrue:[ |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5085 |
next := self at:srcIdx. |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5086 |
srcIdx := srcIdx + 1. |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5087 |
] ifFalse:[ |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5088 |
next := nil |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5089 |
] |
1008 | 5090 |
]. |
5091 |
next := Character value:val. |
|
5092 |
] |
|
5093 |
] |
|
5094 |
] |
|
5095 |
] |
|
5096 |
] |
|
5097 |
] |
|
5098 |
]. |
|
5099 |
]. |
|
5100 |
]. |
|
5101 |
newString at:dstIdx put:next. |
|
1381 | 5102 |
hasEmphasis ifTrue:[ |
5103 |
newString emphasisAt:dstIdx put:e |
|
5104 |
]. |
|
1008 | 5105 |
dstIdx := dstIdx + 1. |
608 | 5106 |
]. |
5107 |
^ newString |
|
5108 |
||
5109 |
" |
|
5110 |
'hello world' withEscapes |
|
5111 |
'hello\world' withEscapes |
|
5112 |
'hello\world\' withEscapes |
|
5113 |
'hello world\' withEscapes |
|
5114 |
'hello\tworld' withEscapes |
|
5115 |
'hello\nworld\na\n\tnice\n\t\tstring' withEscapes |
|
5116 |
'hello\tworld\n' withEscapes |
|
5117 |
'hello\010world' withEscapes |
|
5118 |
'hello\r\nworld' withEscapes |
|
5119 |
" |
|
1008 | 5120 |
|
1381 | 5121 |
"Modified: 12.5.1996 / 12:53:34 / cg" |
608 | 5122 |
! |
5123 |
||
4117 | 5124 |
withMatchEscapes |
5125 |
"return a copy of the receiver with all match characters escaped |
|
5126 |
by $\ characters (to be usable as a match string). |
|
5127 |
Return the receiver, if there are none." |
|
5128 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5129 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5130 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5131 |
escape := self class matchEscapeCharacter. |
4117 | 5132 |
|
5133 |
in := self readStream. |
|
5134 |
out := '' writeStream. |
|
5135 |
[in atEnd] whileFalse:[ |
|
5136 |
c := in next. |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5137 |
(c == escape or:['*[#' includes:c]) ifTrue:[ |
4117 | 5138 |
out nextPut:$\. |
5139 |
]. |
|
5140 |
out nextPut:c. |
|
5141 |
]. |
|
5142 |
^ out contents. |
|
5143 |
||
5144 |
" |
|
5145 |
'*foo' withMatchEscapes |
|
5146 |
'\*foo' withMatchEscapes |
|
5147 |
'*foo' withMatchEscapes |
|
5148 |
'\\*foo' withMatchEscapes |
|
5149 |
'foo*' withMatchEscapes |
|
5150 |
'foo\*' withMatchEscapes |
|
5151 |
'foo\' withMatchEscapes |
|
5152 |
'f*o*o' withMatchEscapes |
|
5153 |
" |
|
5154 |
||
5155 |
"Modified: 2.4.1997 / 18:13:04 / cg" |
|
5156 |
! |
|
5157 |
||
608 | 5158 |
withTabs |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5159 |
"return a string consisting of the receivers characters |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5160 |
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
|
5161 |
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
|
5162 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5163 |
Limitation: only the very first spaces are replaced |
5815
4acdd87a77d4
// can return negative numbers.
Stefan Vogel <sv@exept.de>
parents:
5795
diff
changeset
|
5164 |
(i.e. if the receiver contains newLine characters, |
4acdd87a77d4
// can return negative numbers.
Stefan Vogel <sv@exept.de>
parents:
5795
diff
changeset
|
5165 |
no tabs are inserted after those lineBreaks)" |
608 | 5166 |
|
5167 |
|idx "{ SmallInteger }" |
|
5168 |
nTabs "{ SmallInteger }" |
|
5169 |
newString| |
|
5170 |
||
5171 |
idx := self findFirst:[:c | (c ~~ Character space)]. |
|
5172 |
nTabs := (idx-1) // 8. |
|
5815
4acdd87a77d4
// can return negative numbers.
Stefan Vogel <sv@exept.de>
parents:
5795
diff
changeset
|
5173 |
nTabs <= 0 ifTrue:[^ self]. |
608 | 5174 |
|
5175 |
"any tabs" |
|
5176 |
newString := self class new:(self size - (nTabs * 7)). |
|
5177 |
newString atAll:(1 to:nTabs) put:(Character tab). |
|
5178 |
newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1). |
|
5179 |
^ newString |
|
5180 |
||
5181 |
" |
|
5182 |
'12345678901234567890' withTabs |
|
5183 |
' 8901234567890' withTabs |
|
5184 |
' 901234567890' withTabs |
|
5185 |
' 67890' withTabs |
|
5186 |
' 7890' withTabs |
|
5187 |
' 890' withTabs |
|
5188 |
" |
|
5189 |
! |
|
5190 |
||
5191 |
withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5192 |
"return a string consisting of the receivers characters, |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5193 |
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
|
5194 |
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
|
5195 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5196 |
This does handle multiline strings." |
608 | 5197 |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5198 |
^ self withTabsExpanded:8 |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5199 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5200 |
" |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5201 |
('1' , Character tab asString , 'x') withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5202 |
('12345' , Character tab asString , 'x') withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5203 |
('123456' , Character tab asString , 'x') withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5204 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5205 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5206 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5207 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5208 |
(String with:Character tab |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5209 |
with:Character tab |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5210 |
with:$1) withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5211 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5212 |
(String with:Character tab |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5213 |
with:$1 |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5214 |
with:Character tab |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5215 |
with:$2) withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5216 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5217 |
(String with:Character tab |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5218 |
with:$1 |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5219 |
with:Character cr |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5220 |
with:Character tab |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5221 |
with:$2) withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5222 |
" |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5223 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5224 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5225 |
! |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5226 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5227 |
withTabsExpanded:numSpaces |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5228 |
"return a string consisting of the receivers characters, |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5229 |
where all tabulator characters are expanded into spaces (assuming numSpaces-col tabs). |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5230 |
Notice: if the receiver does not contain any tabs, it is returned unchanged; |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5231 |
otherwise a new string is returned. |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5232 |
This does handle multiline strings." |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5233 |
|
1381 | 5234 |
|col "{ SmallInteger }" |
5235 |
str ch |
|
5236 |
dstIdx "{ SmallInteger }" |
|
5237 |
newSz "{ SmallInteger }" |
|
5238 |
sz "{ SmallInteger }" |
|
5239 |
hasEmphasis e| |
|
608 | 5240 |
|
5241 |
(self includes:(Character tab)) ifFalse:[^ self]. |
|
1381 | 5242 |
|
5243 |
sz := self size. |
|
5244 |
||
5245 |
"/ count the new size first, instead of |
|
5246 |
"/ multiple resizing (better for large strings) |
|
5247 |
||
5248 |
col := 1. newSz := 0. |
|
5249 |
1 to:sz do:[:srcIdx | |
|
5250 |
ch := self at:srcIdx. |
|
5251 |
ch == Character tab ifFalse:[ |
|
5252 |
col := col + 1. |
|
5253 |
newSz := newSz + 1. |
|
5254 |
ch == Character cr ifTrue:[ |
|
5255 |
col := 1 |
|
5256 |
]. |
|
5257 |
] ifTrue:[ |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5258 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
1381 | 5259 |
newSz := newSz + 1. |
5260 |
col := col + 1 |
|
5261 |
]. |
|
5262 |
] |
|
608 | 5263 |
]. |
1381 | 5264 |
|
5265 |
str := self species new:newSz. |
|
5266 |
||
5267 |
hasEmphasis := self hasChangeOfEmphasis. |
|
5268 |
||
5269 |
col := 1. dstIdx := 1. |
|
5270 |
1 to:sz do:[:srcIdx | |
|
5271 |
ch := self at:srcIdx. |
|
5272 |
||
5273 |
ch == Character tab ifFalse:[ |
|
5274 |
col := col + 1. |
|
5275 |
ch == Character cr ifTrue:[ |
|
5276 |
col := 1 |
|
5277 |
]. |
|
5278 |
hasEmphasis ifTrue:[ |
|
5279 |
e := self emphasisAt:srcIdx. |
|
5280 |
str emphasisAt:dstIdx put:e |
|
5281 |
]. |
|
5282 |
str at:dstIdx put:ch. |
|
5283 |
dstIdx := dstIdx + 1 |
|
5284 |
] ifTrue:[ |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5285 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
1381 | 5286 |
str at:dstIdx put:Character space. |
5287 |
dstIdx := dstIdx + 1. |
|
5288 |
col := col + 1 |
|
5289 |
]. |
|
5290 |
] |
|
5291 |
]. |
|
5292 |
^ str |
|
608 | 5293 |
|
5294 |
" |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5295 |
('1' , Character tab asString , 'x') withTabsExpanded |
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5296 |
('1' , Character tab asString , 'x') withTabsExpanded:4 |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5297 |
('12345' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5298 |
('123456' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5299 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5300 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5301 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5302 |
|
608 | 5303 |
(String with:Character tab |
1381 | 5304 |
with:Character tab |
5305 |
with:$1) withTabsExpanded |
|
608 | 5306 |
|
5307 |
(String with:Character tab |
|
1381 | 5308 |
with:$1 |
5309 |
with:Character tab |
|
5310 |
with:$2) withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5311 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5312 |
(String with:Character tab |
1381 | 5313 |
with:$1 |
5314 |
with:Character cr |
|
5315 |
with:Character tab |
|
5316 |
with:$2) withTabsExpanded |
|
608 | 5317 |
" |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5318 |
|
1381 | 5319 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
608 | 5320 |
! |
5321 |
||
5322 |
withoutCRs |
|
5323 |
"return a new collection consisting of receivers elements |
|
5324 |
with all cr-characters replaced by \-characters. |
|
5325 |
This is the reverse operation of withCRs." |
|
5326 |
||
3656 | 5327 |
^ self copyReplaceAll:(Character cr) with:$\ |
608 | 5328 |
" |
5329 |
'hello |
|
5330 |
world' withoutCRs |
|
359 | 5331 |
" |
3656 | 5332 |
|
5333 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
608 | 5334 |
! |
5335 |
||
5336 |
withoutLeadingSeparators |
|
5337 |
"return a copy of myself without leading separators. |
|
5338 |
Notice: this does remove tabs, newline or any other whitespace. |
|
5339 |
Returns an empty string, if the receiver consist only of whitespace." |
|
5340 |
||
5341 |
|index| |
|
5342 |
||
5343 |
index := self indexOfNonSeparatorStartingAt:1. |
|
5344 |
index ~~ 0 ifTrue:[ |
|
5345 |
index == 1 ifTrue:[ |
|
5346 |
^ self |
|
5347 |
]. |
|
5348 |
^ self copyFrom:index |
|
5349 |
]. |
|
5350 |
^ '' |
|
5351 |
||
5352 |
" |
|
5353 |
' foo ' withoutLeadingSeparators |
|
5354 |
'foo ' withoutLeadingSeparators |
|
5355 |
' foo' withoutLeadingSeparators |
|
5356 |
' ' withoutLeadingSeparators |
|
5357 |
'foo' withoutLeadingSeparators |
|
5358 |
(' ' , Character tab asString , ' foo ') withoutLeadingSeparators inspect |
|
5359 |
" |
|
5360 |
! |
|
5361 |
||
4117 | 5362 |
withoutMatchEscapes |
5363 |
"return a copy of the receiver with all $\ removed or |
|
5364 |
the receiver, if there are none." |
|
5365 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5366 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5367 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5368 |
escape := self class matchEscapeCharacter. |
4117 | 5369 |
|
5370 |
in := self readStream. |
|
5371 |
out := self species new writeStream. |
|
5372 |
[in atEnd] whileFalse:[ |
|
5373 |
c := in next. |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5374 |
c == escape ifTrue:[ |
4117 | 5375 |
in atEnd ifFalse:[ |
5376 |
c := in next. |
|
5377 |
] |
|
5378 |
]. |
|
5379 |
out nextPut:c. |
|
5380 |
]. |
|
5381 |
^ out contents. |
|
5382 |
||
5383 |
" |
|
5384 |
'*foo' withoutMatchEscapes |
|
5385 |
'\*foo' withoutMatchEscapes |
|
5386 |
'*foo' withoutMatchEscapes |
|
5387 |
'\\*foo' withoutMatchEscapes |
|
5388 |
'foo*' withoutMatchEscapes |
|
5389 |
'foo\*' withoutMatchEscapes |
|
5390 |
'foo\' withoutMatchEscapes |
|
5391 |
'f\*o\*o' withoutMatchEscapes |
|
5392 |
" |
|
5393 |
||
5394 |
"Modified: 30.6.1997 / 13:40:23 / cg" |
|
5395 |
! |
|
5396 |
||
608 | 5397 |
withoutSeparators |
5398 |
"return a copy of myself without leading and trailing whitespace. |
|
4156 | 5399 |
(but whiteSpace in-between is preserved) |
608 | 5400 |
Whitespace is space, tab, newline, formfeed. |
5401 |
Use withoutSpaces, if you want to remove spaces only." |
|
5402 |
||
5403 |
|startIndex "{ Class: SmallInteger }" |
|
5404 |
endIndex "{ Class: SmallInteger }" |
|
5405 |
sz| |
|
5406 |
||
5407 |
sz := self size. |
|
5408 |
startIndex := 1. |
|
5409 |
endIndex := sz. |
|
5410 |
||
5411 |
[(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[ |
|
4156 | 5412 |
startIndex := startIndex + 1 |
608 | 5413 |
]. |
5414 |
[(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[ |
|
4156 | 5415 |
endIndex := endIndex - 1 |
608 | 5416 |
]. |
5417 |
startIndex > endIndex ifTrue:[ |
|
4156 | 5418 |
^ '' |
608 | 5419 |
]. |
5420 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
|
4156 | 5421 |
^ self |
608 | 5422 |
]. |
5423 |
^ self copyFrom:startIndex to:endIndex |
|
5424 |
||
5425 |
" |
|
5426 |
' foo ' withoutSeparators |
|
5427 |
' foo' withoutSeparators |
|
5428 |
'foo ' withoutSeparators |
|
5429 |
' ' withoutSeparators |
|
5430 |
(' foo' , Character tab asString , ' ') withoutSeparators inspect |
|
5431 |
" |
|
5432 |
! |
|
5433 |
||
5434 |
withoutSpaces |
|
5435 |
"return a copy of myself without leading and trailing spaces. |
|
4156 | 5436 |
(but spaces in-between are preserved) |
608 | 5437 |
Notice: this does NOT remove tabs, newline or any other whitespace. |
5438 |
Use withoutSeparators for this." |
|
5439 |
||
5440 |
|startIndex "{ Class: SmallInteger }" |
|
5441 |
endIndex "{ Class: SmallInteger }" |
|
5442 |
sz| |
|
5443 |
||
5444 |
sz := self size. |
|
5445 |
startIndex := 1. |
|
5446 |
endIndex := sz. |
|
5447 |
||
5448 |
[(startIndex < endIndex) and:[(self at:startIndex) == Character space]] whileTrue:[ |
|
4156 | 5449 |
startIndex := startIndex + 1 |
608 | 5450 |
]. |
5451 |
[(endIndex > 1) and:[(self at:endIndex) == Character space]] whileTrue:[ |
|
4156 | 5452 |
endIndex := endIndex - 1 |
608 | 5453 |
]. |
5454 |
startIndex > endIndex ifTrue:[ |
|
4156 | 5455 |
^ '' |
608 | 5456 |
]. |
5457 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
|
4156 | 5458 |
^ self |
608 | 5459 |
]. |
5460 |
^ self copyFrom:startIndex to:endIndex |
|
5461 |
||
5462 |
" |
|
5463 |
' foo ' withoutSpaces |
|
5464 |
'foo ' withoutSpaces |
|
5465 |
' foo' withoutSpaces |
|
5466 |
' ' withoutSpaces |
|
4156 | 5467 |
'a b' withoutSpaces |
608 | 5468 |
(' foo' , Character tab asString , ' ') withoutSpaces inspect |
5469 |
" |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5470 |
! |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5471 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5472 |
withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5473 |
"return a copy of myself without trailing separators. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5474 |
Notice: this does remove tabs, newline or any other whitespace. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5475 |
Returns an empty string, if the receiver consist only of whitespace." |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5476 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5477 |
|index| |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5478 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5479 |
index := self size. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5480 |
[index ~~ 0] whileTrue:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5481 |
(self at:index) isSeparator ifFalse:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5482 |
^ self copyTo:index |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5483 |
]. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5484 |
index := index - 1 |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5485 |
]. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5486 |
^ '' |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5487 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5488 |
" |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5489 |
' foo ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5490 |
'foo ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5491 |
' foo' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5492 |
' ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5493 |
'foo' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5494 |
(' ' , Character tab asString , ' foo ') withoutTrailingSeparators inspect |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5495 |
(' foo' , Character tab asString) withoutTrailingSeparators inspect |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
5496 |
" |
608 | 5497 |
! ! |
5498 |
||
5499 |
!CharacterArray methodsFor:'substring searching'! |
|
5500 |
||
5501 |
findString:subString |
|
5502 |
"find a substring. if found, return the index; |
|
5503 |
if not found, return 0." |
|
5504 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
5505 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 |
608 | 5506 |
|
5507 |
" |
|
5508 |
'hello world' findString:'llo' |
|
5509 |
'hello world' findString:'ole' |
|
5510 |
" |
|
5511 |
! |
|
5512 |
||
5513 |
findString:subString ifAbsent:exceptionBlock |
|
5514 |
"find a substring. If found, return the index; |
|
5515 |
if not found, return the result of evaluating exceptionBlock." |
|
5516 |
||
5517 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock |
|
5518 |
! |
|
5519 |
||
5520 |
findString:subString startingAt:index |
|
5521 |
"find a substring, starting at index. if found, return the index; |
|
5522 |
if not found, return 0." |
|
5523 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
5524 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:0 |
608 | 5525 |
|
5526 |
" |
|
5527 |
'hello yello' findString:'llo' startingAt:1 |
|
5528 |
'hello yello' findString:'llo' startingAt:5 |
|
5529 |
'hello yello' findString:'llo' startingAt:15 |
|
5530 |
" |
|
5531 |
! |
|
5532 |
||
5533 |
findString:subString startingAt:index ifAbsent:exceptionBlock |
|
5534 |
"find a substring, starting at index. if found, return the index; |
|
5535 |
if not found, return the result of evaluating exceptionBlock." |
|
5536 |
||
5537 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
|
5538 |
! |
|
5539 |
||
5540 |
includesString:aString |
|
5541 |
"return true, if a substring is contained in the receiver" |
|
5542 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
5543 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0) ~~ 0 |
608 | 5544 |
|
5545 |
" |
|
5546 |
'hello world' includesString:'hel' |
|
5547 |
'hello world' includesString:'rld' |
|
5548 |
'hello world' includesString:'llo' |
|
5549 |
'hello world' includesString:'LLO' |
|
5550 |
" |
|
5551 |
! |
|
5552 |
||
5553 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
|
5554 |
"find a substring, starting at index. if found, return the index; |
|
5555 |
if not found, return the result of evaluating exceptionBlock. |
|
5556 |
This is a q&d hack - not very efficient" |
|
5557 |
||
5558 |
|firstChar found |
|
5559 |
startIndex "{ Class: SmallInteger }" |
|
5560 |
subSize "{ Class: SmallInteger }" |
|
5561 |
mySize "{ Class: SmallInteger }" |
|
5562 |
runIdx "{ Class: SmallInteger }" | |
|
5563 |
||
5564 |
subSize := subString size. |
|
6122
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
5565 |
subSize == 0 ifTrue:[ "empty string matches" |
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
5566 |
subString isString ifFalse:[ |
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
5567 |
self error:'non string argument' mayProceed:true. |
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
5568 |
]. |
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
5569 |
^ index |
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
5570 |
]. |
608 | 5571 |
mySize := self size. |
5572 |
firstChar := subString at:1. |
|
5573 |
startIndex := self indexOf:firstChar startingAt:index. |
|
5574 |
[startIndex == 0] whileFalse:[ |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5575 |
runIdx := startIndex. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5576 |
found := true. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5577 |
1 to:subSize do:[:i | |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5578 |
runIdx > mySize ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5579 |
found := false |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5580 |
] ifFalse:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5581 |
(subString at:i) ~= (self at:runIdx) ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5582 |
found := false |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5583 |
] |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5584 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5585 |
runIdx := runIdx + 1 |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5586 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5587 |
found ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5588 |
^ startIndex |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5589 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5590 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1) |
608 | 5591 |
]. |
5592 |
^ exceptionBlock value |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5593 |
|
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5594 |
"Modified: 23.2.1996 / 15:35:15 / cg" |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5595 |
! |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5596 |
|
652 | 5597 |
restAfter:keyword withoutSeparators:strip |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5598 |
"compare the left of the receiver with keyword, |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5599 |
if it matches return the right. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5600 |
Finally, if strip is true, remove whiteSpace. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5601 |
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
|
5602 |
something: rest |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
5603 |
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
|
5604 |
begins with something. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5605 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5606 |
You may wonder why such a specialized method exists here |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5607 |
- this is so common when processing mailboxes, |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5608 |
rcs files, nntp/pop3 responses, that is was considered worth |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5609 |
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
|
5610 |
times in variuos places." |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5611 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5612 |
|rest| |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5613 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5614 |
(self startsWith:keyword) ifTrue:[ |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5615 |
rest := self copyFrom:(keyword size + 1). |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5616 |
strip ifTrue:[ |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5617 |
rest := rest withoutSeparators |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5618 |
]. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5619 |
^ rest |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5620 |
]. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5621 |
^ nil |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5622 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5623 |
" |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5624 |
'foo: hello world' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5625 |
'funny: something' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5626 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5627 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5628 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:false |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5629 |
" |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5630 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
5631 |
"Created: 25.11.1995 / 11:04:18 / cg" |
328 | 5632 |
! ! |
5633 |
||
255 | 5634 |
!CharacterArray methodsFor:'testing'! |
64 | 5635 |
|
1613 | 5636 |
continuesWith:aString startingAt:startIndex |
5637 |
"return true, if the receiver beginning at startIndex |
|
5638 |
contains the characters in aString." |
|
5639 |
||
5640 |
|sz "{Class: SmallInteger }" |
|
5641 |
idx "{Class: SmallInteger }"| |
|
5642 |
||
5643 |
sz := aString size. |
|
5644 |
idx := startIndex. |
|
5645 |
||
5646 |
1 to:sz do:[:i | |
|
5647 |
(self at:idx) ~~ (aString at:i) ifTrue:[^ false]. |
|
5648 |
idx := idx + 1 |
|
5649 |
]. |
|
5650 |
^ true |
|
5651 |
||
5652 |
" |
|
5653 |
'hello world' continuesWith:'world' startingAt:6 |
|
5654 |
'hello world' continuesWith:'world' startingAt:7 |
|
5655 |
" |
|
5656 |
||
5657 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
5658 |
"Modified: 26.7.1996 / 19:08:36 / cg" |
|
5659 |
! |
|
5660 |
||
64 | 5661 |
countWords |
5662 |
"return the number of words, which are separated by separators" |
|
5663 |
||
92 | 5664 |
|tally "{ Class: SmallInteger }" |
5665 |
start "{ Class: SmallInteger }" |
|
5666 |
mySize "{ Class: SmallInteger }" |
|
5667 |
stop ch| |
|
64 | 5668 |
|
5669 |
tally := 0. |
|
5670 |
start := 1. |
|
5671 |
mySize := self size. |
|
5672 |
[start <= mySize] whileTrue:[ |
|
154 | 5673 |
ch := self at:start. |
5674 |
ch isSeparator ifTrue:[ |
|
5675 |
start := start + 1 |
|
5676 |
] ifFalse:[ |
|
5677 |
stop := self indexOfSeparatorStartingAt:start. |
|
5678 |
(stop == 0) ifTrue:[ |
|
5679 |
stop := mySize + 1 |
|
5680 |
]. |
|
5681 |
tally := tally + 1. |
|
5682 |
start := stop |
|
5683 |
] |
|
64 | 5684 |
]. |
5685 |
^ tally |
|
5686 |
||
92 | 5687 |
" |
5688 |
'hello world isnt this nice' countWords' |
|
5689 |
" |
|
64 | 5690 |
! |
5691 |
||
1381 | 5692 |
endsWith:aString |
5693 |
"return true, if the receiver ends with something, aString." |
|
5694 |
||
5695 |
|s| |
|
5696 |
||
5697 |
(s := self string) ~~ self ifTrue:[ |
|
5698 |
^ s endsWith:aString |
|
5699 |
]. |
|
5700 |
^ super endsWith:aString |
|
5701 |
||
5702 |
" |
|
5703 |
'hello world' endsWith:'world' |
|
5704 |
'hello world' asText allBold endsWith:'world' |
|
5705 |
" |
|
5706 |
||
5707 |
"Modified: 12.5.1996 / 15:49:18 / cg" |
|
5708 |
! |
|
5709 |
||
608 | 5710 |
isAlphaNumeric |
5711 |
"return true, if the receiver is some alphanumeric word; |
|
5712 |
i.e. consists of a letter followed by letters or digits." |
|
64 | 5713 |
|
608 | 5714 |
self size == 0 ifTrue:[ |
5715 |
"mhmh what is this ?" |
|
5716 |
^ false |
|
64 | 5717 |
]. |
608 | 5718 |
(self at:1) isLetter ifFalse:[^ false]. |
5719 |
self do:[:char | |
|
5720 |
char isLetterOrDigit ifFalse:[^ false]. |
|
5721 |
]. |
|
5722 |
^ true |
|
64 | 5723 |
|
77 | 5724 |
" |
608 | 5725 |
'helloWorld' isAlphaNumeric |
5726 |
'foo1234' isAlphaNumeric |
|
5727 |
'f1234' isAlphaNumeric |
|
5728 |
'1234' isAlphaNumeric |
|
5729 |
'+' isAlphaNumeric |
|
77 | 5730 |
" |
5731 |
! |
|
5732 |
||
608 | 5733 |
isBlank |
5734 |
"return true, if the receiver contains spaces only" |
|
77 | 5735 |
|
608 | 5736 |
self do:[:char | |
5737 |
char ~~ Character space ifTrue:[^ false]. |
|
77 | 5738 |
]. |
608 | 5739 |
^ true |
64 | 5740 |
! |
5741 |
||
5742 |
levenshteinTo:aString |
|
5743 |
"return the levenshtein distance to the argument, aString; |
|
5744 |
this value corrensponds to the number of replacements that have to be |
|
5745 |
made to get aString from the receiver. |
|
196 | 5746 |
See IEEE transactions on Computers 1976 Pg 172 ff." |
64 | 5747 |
|
327 | 5748 |
" |
5749 |
in the following, we assum that ommiting a character |
|
5750 |
is less of an error than inserting an extra character. |
|
5751 |
Therefore the different insertion (i) and deletion (d) |
|
5752 |
values. |
|
5753 |
" |
|
5754 |
||
64 | 5755 |
^ self levenshteinTo:aString s:4 c:1 i:2 d:6 |
154 | 5756 |
|
5757 |
" |
|
5758 |
'ocmprt' levenshteinTo:'computer' |
|
5759 |
'computer' levenshteinTo:'computer' |
|
5760 |
'ocmputer' levenshteinTo:'computer' |
|
5761 |
'cmputer' levenshteinTo:'computer' |
|
327 | 5762 |
'computer' levenshteinTo:'cmputer' |
154 | 5763 |
'Computer' levenshteinTo:'computer' |
5764 |
" |
|
64 | 5765 |
! |
5766 |
||
5767 |
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight |
|
196 | 5768 |
"parametrized levenshtein. |
5769 |
return the levenshtein distance to the argument, aString; |
|
5770 |
this value corrensponds to the number of replacements that have to be |
|
5771 |
made to get aString from the receiver. |
|
5772 |
The arguments are the costs for substitution, case-change, insertion and |
|
5773 |
deletion of a character. |
|
5774 |
See IEEE transactions on Computers 1976 Pg 172 ff" |
|
64 | 5775 |
|
5776 |
|d "delta matrix" |
|
196 | 5777 |
len1 "{ Class: SmallInteger }" |
5778 |
len2 "{ Class: SmallInteger }" |
|
5779 |
dim "{ Class: SmallInteger }" |
|
5780 |
prevRow row col |
|
5781 |
dimPlus1 "{ Class: SmallInteger }" |
|
64 | 5782 |
min pp c1 c2| |
5783 |
||
5784 |
len1 := self size. |
|
5785 |
len2 := aString size. |
|
5786 |
||
5787 |
"create the help-matrix" |
|
5788 |
||
5789 |
dim := len1 max:len2. |
|
5790 |
dimPlus1 := dim + 1. |
|
5791 |
||
5792 |
d := Array new:dimPlus1. |
|
5793 |
1 to:dimPlus1 do:[:i | |
|
154 | 5794 |
d at:i put:(Array new:dimPlus1) |
64 | 5795 |
]. |
5796 |
||
5797 |
"init help-matrix" |
|
5798 |
||
5799 |
(d at:1) at:1 put:0. |
|
5800 |
row := d at:1. |
|
5801 |
1 to:dim do:[:j | |
|
154 | 5802 |
row at:(j + 1) put:( (row at:j) + insrtWeight ) |
64 | 5803 |
]. |
5804 |
||
5805 |
1 to:dim do:[:i | |
|
154 | 5806 |
(d at:(i + 1)) at:1 put:( ((d at:i) at:1) + deleteWeight ) |
64 | 5807 |
]. |
5808 |
||
5809 |
1 to:len1 do:[:i | |
|
154 | 5810 |
c1 := self at:i. |
5811 |
1 to:len2 do:[:j | |
|
5812 |
c2 := aString at:j. |
|
5813 |
(c1 == c2) ifTrue:[ |
|
5814 |
pp := 0 |
|
5815 |
] ifFalse:[ |
|
5816 |
(c1 asLowercase == c2 asLowercase) ifTrue:[ |
|
5817 |
pp := caseWeight |
|
5818 |
] ifFalse:[ |
|
5819 |
pp := substWeight |
|
5820 |
] |
|
5821 |
]. |
|
5822 |
prevRow := d at:i. |
|
5823 |
row := d at:(i + 1). |
|
5824 |
col := j + 1. |
|
5825 |
min := (prevRow at:j) + pp. |
|
5826 |
min := min min:( (row at:j) + insrtWeight). |
|
5827 |
min := min min:( (prevRow at:col) + deleteWeight). |
|
5828 |
row at:col put: min |
|
5829 |
] |
|
64 | 5830 |
]. |
5831 |
||
5832 |
^ (d at:(len1 + 1)) at:(len2 + 1) |
|
5833 |
! |
|
5834 |
||
608 | 5835 |
numArgs |
5836 |
"treating the receiver as a message selector, return how many arguments would it take" |
|
5837 |
||
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5838 |
|binopChars firstChar| |
608 | 5839 |
|
5840 |
(self size > 2) ifFalse:[ |
|
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5841 |
binopChars := Scanner binarySelectorCharacters. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5842 |
firstChar := self at:1. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5843 |
|
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5844 |
(self size == 1) ifTrue:[ |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5845 |
((binopChars occurrencesOf:firstChar) == 0) ifTrue:[^ 0]. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5846 |
^ 1 |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5847 |
]. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5848 |
((binopChars occurrencesOf:firstChar) == 0) ifFalse:[ |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5849 |
((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
|
5850 |
] |
608 | 5851 |
]. |
5852 |
^ self occurrencesOf:$: |
|
5853 |
||
5854 |
" |
|
5855 |
'foo:bar:' numArgs |
|
5856 |
#foo:bar: numArgs |
|
5857 |
'hello' numArgs |
|
5858 |
'+' numArgs |
|
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5859 |
'|' numArgs |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5860 |
'?' numArgs |
608 | 5861 |
" |
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5862 |
|
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5863 |
"Modified: 4.1.1997 / 14:16:14 / cg" |
608 | 5864 |
! |
5865 |
||
5866 |
partsIfSelector |
|
5867 |
"treat the receiver as a message selector, return a collection of parts." |
|
5868 |
||
5869 |
|idx1 "{ Class: SmallInteger }" |
|
5870 |
coll idx2 sz| |
|
5871 |
||
5872 |
coll := OrderedCollection new. |
|
5873 |
idx1 := 1. |
|
5874 |
sz := self size. |
|
5875 |
[true] whileTrue:[ |
|
5876 |
idx2 := self indexOf:$: startingAt:idx1 + 1. |
|
5877 |
(idx2 == 0 or:[idx2 == sz]) ifTrue:[ |
|
5878 |
coll add:(self copyFrom:idx1). |
|
5879 |
^ coll |
|
5880 |
]. |
|
5881 |
coll add:(self copyFrom:idx1 to:idx2). |
|
5882 |
idx1 := idx2 + 1 |
|
5883 |
]. |
|
5884 |
||
5885 |
" |
|
5886 |
'foo:bar:' partsIfSelector |
|
5887 |
#foo:bar: partsIfSelector |
|
5888 |
'hello' partsIfSelector |
|
5889 |
'+' partsIfSelector |
|
5890 |
" |
|
5891 |
! |
|
5892 |
||
64 | 5893 |
spellAgainst: aString |
5894 |
"return an integer between 0 and 100 indicating how similar |
|
154 | 5895 |
the argument is to the receiver. No case conversion is done. |
5896 |
This algorithm is much simpler (but also less exact) than the |
|
5897 |
levenshtein distance. Experiment which is better for your |
|
5898 |
application." |
|
64 | 5899 |
|
5900 |
| i1 "{ Class: SmallInteger }" |
|
5901 |
i2 "{ Class: SmallInteger }" |
|
154 | 5902 |
next1 "{ Class: SmallInteger }" |
5903 |
next2 "{ Class: SmallInteger }" |
|
64 | 5904 |
size1 "{ Class: SmallInteger }" |
5905 |
size2 "{ Class: SmallInteger }" |
|
5906 |
score "{ Class: SmallInteger }" |
|
5907 |
maxLen "{ Class: SmallInteger }" | |
|
5908 |
||
5909 |
size1 := self size. |
|
5910 |
size2 := aString size. |
|
154 | 5911 |
maxLen := size1 max:size2. |
64 | 5912 |
score := 0. |
5913 |
i1 := i2 := 1. |
|
5914 |
[i1 <= size1 and: [i2 <= size2]] whileTrue:[ |
|
154 | 5915 |
next1 := i1 + 1. |
5916 |
next2 := i2 + 1. |
|
5917 |
(self at:i1) == (aString at:i2) ifTrue: [ |
|
5918 |
score := score+1. |
|
5919 |
i1 := next1. |
|
5920 |
i2 := next2 |
|
5921 |
] ifFalse: [ |
|
5922 |
(i2 < size2 and: [(self at:i1) == (aString at:next2)]) ifTrue: [ |
|
5923 |
i2 := next2 |
|
5924 |
] ifFalse: [ |
|
5925 |
(i1 < size1 and: [(self at:next1) == (aString at:i2)]) ifTrue: [ |
|
5926 |
i1 := next1 |
|
5927 |
] ifFalse: [ |
|
5928 |
i1 := next1. |
|
5929 |
i2 := next2 |
|
5930 |
] |
|
5931 |
] |
|
5932 |
] |
|
64 | 5933 |
]. |
5934 |
||
1124 | 5935 |
score == maxLen ifTrue: [^ 100]. |
154 | 5936 |
^ 100 * score // maxLen |
64 | 5937 |
|
154 | 5938 |
" |
5939 |
'Smalltalk' spellAgainst: 'Smalltlak' |
|
5940 |
'Smalltalk' spellAgainst: 'smalltlak' |
|
5941 |
'Smalltalk' spellAgainst: 'smalltalk' |
|
5942 |
'Smalltalk' spellAgainst: 'smalltlk' |
|
5943 |
'Smalltalk' spellAgainst: 'Smalltolk' |
|
5944 |
" |
|
1381 | 5945 |
! |
5946 |
||
5947 |
startsWith:aString |
|
4389
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4294
diff
changeset
|
5948 |
"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
|
5949 |
If the argument is empty, true is returned." |
1381 | 5950 |
|
5951 |
|s| |
|
5952 |
||
5953 |
(s := self string) ~~ self ifTrue:[ |
|
5954 |
^ s startsWith:aString |
|
5955 |
]. |
|
5956 |
^ super startsWith:aString |
|
5957 |
||
5958 |
" |
|
5959 |
'hello world' startsWith:'hello' |
|
5960 |
'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
|
5961 |
'hello world' asText allBold startsWith:'' |
1381 | 5962 |
" |
5963 |
||
5964 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
5965 |
"Modified: 12.5.1996 / 15:49:24 / cg" |
|
64 | 5966 |
! ! |
5967 |
||
4662 | 5968 |
!CharacterArray methodsFor:'tracing'! |
5969 |
||
4682 | 5970 |
traceInto:aRequestor level:level from:referrer |
4662 | 5971 |
"double dispatch into tracer, passing my type implicitely in the selector" |
5972 |
||
4682 | 5973 |
^ aRequestor traceCharacterArray:self level:level from:referrer |
4662 | 5974 |
|
5975 |
||
5976 |
! ! |
|
5977 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
5978 |
!CharacterArray class methodsFor:'documentation'! |
629 | 5979 |
|
5980 |
version |
|
6122
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
5981 |
^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.211 2001-10-26 13:41:46 cg Exp $' |
629 | 5982 |
! ! |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
5983 |
CharacterArray initialize! |