author | Claus Gittinger <cg@exept.de> |
Mon, 15 Jun 1998 17:22:56 +0200 | |
changeset 3578 | 46dc8399fdf8 |
parent 3537 | 916534e86f0c |
child 3599 | fea09a812f55 |
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 |
||
255 | 13 |
ByteArray subclass:#CharacterArray |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
14 |
instanceVariableNames:'' |
2734 | 15 |
classVariableNames:'PreviousMatch DecoderTables EncoderTables DecodingFailedSignal |
16 |
EncodingFailedSignal' |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
17 |
poolDictionaries:'' |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
18 |
category:'Collections-Text' |
64 | 19 |
! |
20 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
21 |
!CharacterArray class methodsFor:'documentation'! |
64 | 22 |
|
82 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
154 | 26 |
All Rights Reserved |
82 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
64 | 37 |
documentation |
38 |
" |
|
255 | 39 |
CharacterArray is a superclass for all kinds of Strings (i.e. |
68 | 40 |
(singleByte-)Strings, TwoByteStrings and whatever comes in the future. |
154 | 41 |
|
2537 | 42 |
This class is abstract, meaning that there are no instances of it. |
43 |
All this class does is provide common protocol for concrete subclasses. |
|
1290 | 44 |
|
45 |
[author:] |
|
46 |
Claus Gittinger |
|
47 |
||
48 |
[see also:] |
|
49 |
String TwoByteString |
|
50 |
StringCollection |
|
64 | 51 |
" |
52 |
! ! |
|
53 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
54 |
!CharacterArray class methodsFor:'initialization'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
55 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
56 |
initialize |
2730
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
57 |
DecodingFailedSignal := Signal new mayProceed:true. |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
58 |
DecodingFailedSignal notifierString:'decoding failure'. |
2833 | 59 |
DecodingFailedSignal nameClass:self message:#decodingFailedSignal. |
60 |
||
2734 | 61 |
EncodingFailedSignal := QuerySignal new mayProceed:true. |
62 |
EncodingFailedSignal notifierString:'encoding failure'. |
|
2833 | 63 |
EncodingFailedSignal nameClass:self message:#encodingFailedSignal. |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
64 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
65 |
" |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
66 |
CharacterArray initialize |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
67 |
" |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
68 |
|
2833 | 69 |
"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
|
70 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
71 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
72 |
!CharacterArray class methodsFor:'instance creation'! |
64 | 73 |
|
74 |
basicNew |
|
75 |
"return a new empty string" |
|
76 |
||
77 |
^ self basicNew:0 |
|
78 |
! |
|
79 |
||
2734 | 80 |
fromBytes:aByteCollection |
81 |
"return an instance of the receiver class, |
|
82 |
taking untranslated bytes from the argument, aByteCollection. |
|
83 |
Only useful, when reading twoByteStrings from external sources." |
|
84 |
||
85 |
|mySize nBytes newString dstIdx| |
|
86 |
||
87 |
nBytes := aByteCollection size. |
|
88 |
mySize := self basicNew bitsPerCharacter. |
|
89 |
mySize == 16 ifTrue:[ |
|
90 |
newString := self basicNew:(nBytes // 2). |
|
91 |
dstIdx := 1. |
|
92 |
aByteCollection pairWiseDo:[:hi :lo | |
|
93 |
newString at:dstIdx put:(Character value:(hi bitShift:8)+lo). |
|
94 |
dstIdx := dstIdx + 1 |
|
95 |
]. |
|
96 |
^ newString. |
|
97 |
]. |
|
98 |
||
99 |
^ (self basicNew:nBytes) replaceFrom:1 with:aByteCollection |
|
100 |
||
101 |
" |
|
102 |
TwoByteString fromBytes:#[16r21 16r21] |
|
103 |
" |
|
104 |
||
105 |
"Modified: 30.6.1997 / 20:08:37 / cg" |
|
106 |
! |
|
107 |
||
64 | 108 |
fromString:aString |
109 |
"return a copy of the argument, aString" |
|
110 |
||
68 | 111 |
^ (self basicNew:(aString size)) replaceFrom:1 with:aString |
112 |
||
113 |
"TwoByteString fromString:'hello'" |
|
581 | 114 |
! |
115 |
||
116 |
fromStringCollection:aCollectionOfStrings |
|
117 |
"return new string formed by concatenating a copy of the argument, aString" |
|
118 |
||
119 |
^ self fromStringCollection:aCollectionOfStrings separatedBy:'' |
|
120 |
||
121 |
" |
|
122 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') |
|
123 |
" |
|
124 |
||
125 |
"Created: 20.11.1995 / 15:26:59 / cg" |
|
126 |
! |
|
127 |
||
128 |
fromStringCollection:aCollectionOfStrings separatedBy:aSeparatorString |
|
129 |
"return new string formed by concatenating a copy of the argument, aString" |
|
130 |
||
131 |
|newString first| |
|
132 |
||
133 |
newString := ''. |
|
134 |
first := true. |
|
135 |
aCollectionOfStrings do:[:s | |
|
136 |
first ifFalse:[ |
|
137 |
newString := newString , aSeparatorString |
|
138 |
] ifTrue:[ |
|
139 |
first := false |
|
140 |
]. |
|
141 |
newString := newString , s |
|
142 |
]. |
|
143 |
^ newString |
|
144 |
||
145 |
" |
|
146 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:' ' |
|
147 |
" |
|
148 |
||
149 |
"Created: 20.11.1995 / 15:32:17 / cg" |
|
608 | 150 |
! |
151 |
||
152 |
new |
|
153 |
"return a new empty string" |
|
154 |
||
155 |
^ self basicNew:0 |
|
64 | 156 |
! ! |
157 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
158 |
!CharacterArray class methodsFor:'Signal constants'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
159 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
160 |
decodingFailedSignal |
2833 | 161 |
"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
|
162 |
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
|
163 |
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
|
164 |
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
|
165 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
166 |
^ DecodingFailedSignal |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
167 |
|
2833 | 168 |
"Created: 28.6.1997 / 20:09:55 / cg" |
169 |
"Modified: 3.8.1997 / 18:16:47 / cg" |
|
170 |
! |
|
171 |
||
172 |
encodingFailedSignal |
|
173 |
"return the (query-) signal, raised when encoding of a string is not possible |
|
174 |
due to invalid characters contained in the source." |
|
175 |
||
176 |
^ EncodingFailedSignal |
|
177 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
178 |
"Modified: 28.6.1997 / 20:09:35 / cg" |
2833 | 179 |
"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
|
180 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
181 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
182 |
!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
|
183 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
184 |
lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
185 |
"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
|
186 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
187 |
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
|
188 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
189 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
190 |
CharacterArray lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
191 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
192 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
193 |
"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
|
194 |
"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
|
195 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
196 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
197 |
!CharacterArray class methodsFor:'code tables'! |
443 | 198 |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
199 |
classForEncoding:encodingSymbol |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
200 |
"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
|
201 |
by encodingSymbol" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
202 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
203 |
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
|
204 |
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
|
205 |
encodingSymbol == #gb ifTrue:[^ GBEncodedString]. |
2734 | 206 |
encodingSymbol == #ksc ifTrue:[^ KSCEncodedString]. |
207 |
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
|
208 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
209 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
210 |
"/ 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
|
211 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
212 |
^ String |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
213 |
|
2734 | 214 |
"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
|
215 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
216 |
|
443 | 217 |
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
|
218 |
"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
|
219 |
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
|
220 |
This is an experimental interface - unfinished" |
443 | 221 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
222 |
|table unrepresentableCharacterCode x80Table| |
443 | 223 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
224 |
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
|
225 |
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
|
226 |
table notNil ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
227 |
table == #identity ifTrue:[^ nil]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
228 |
^ table |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
229 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
230 |
] ifFalse:[ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
231 |
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
|
232 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
233 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
234 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
235 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
236 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
237 |
"/ setup as identityTranslation |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
238 |
"/ |
443 | 239 |
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
|
240 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
241 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
242 |
"/ hp -> iso8859 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
243 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
244 |
"/ 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
|
245 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
246 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
247 |
encoding == #hp ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
248 |
unrepresentableCharacterCode := 16rA0. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
249 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
250 |
x80Table := |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
251 |
#( |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
252 |
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
|
253 |
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
|
254 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
255 |
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
|
256 |
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
|
257 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
258 |
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
|
259 |
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
|
260 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
261 |
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
|
262 |
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
|
263 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
264 |
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
|
265 |
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
|
266 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
267 |
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
|
268 |
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
|
269 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
270 |
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
|
271 |
"/ S ? s ? Y ? |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
272 |
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
|
273 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
274 |
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
|
275 |
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
|
276 |
). |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
277 |
]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
278 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
279 |
"/ |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
280 |
"/ mac -> iso8859 |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
281 |
"/ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
282 |
"/ 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
|
283 |
"/ - 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
|
284 |
"/ |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
285 |
"/ A0 (dagger) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
286 |
"/ A5 (dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
287 |
"/ AA (tm - trademark) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
288 |
"/ AD (not equal) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
289 |
"/ B0 (infinity) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
290 |
"/ B3 (less-double-equal <=) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
291 |
"/ B4 (greater-equal >-) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
292 |
"/ B6 (math lowercase delta) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
293 |
"/ B7 (math sum) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
294 |
"/ B8 (math uppercase pi) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
295 |
"/ B9 (math lowercase pi) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
296 |
"/ BA (math integral) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
297 |
"/ BD (math omega) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
298 |
"/ C3 (math union) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
299 |
"/ C4 (ext latin f) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
300 |
"/ C5 (math almost equal) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
301 |
"/ C6 (math uppercase delta) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
302 |
"/ C9 (dot-dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
303 |
"/ CE (OE ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
304 |
"/ CF (oe ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
305 |
"/ D1 (hyphen) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
306 |
"/ D2 (opening top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
307 |
"/ D3 (closing top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
308 |
"/ D4 (opening top quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
309 |
"/ D5 (closing top quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
310 |
"/ D7 (geometric: ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
311 |
"/ D9 (uppercase Y diacrit ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
312 |
"/ DA (slash2 ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
313 |
"/ DC (single oldStyle opening quote (<) ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
314 |
"/ DD (single oldStyle closing quote (>) ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
315 |
"/ DE (? ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
316 |
"/ DF (? ) |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
317 |
"/ E0 (double dagger ) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
318 |
"/ E2 (opening bottom quote ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
319 |
"/ E3 (opening bottom dquote ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
320 |
"/ F0 (? ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
321 |
"/ F5 (latin l ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
322 |
"/ F6 (diacrit circumflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
323 |
"/ F7 (diacrit tilde) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
324 |
"/ F8 (diacrit top line) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
325 |
"/ F9 (diacrit inverse circumflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
326 |
"/ FA (diacrit dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
327 |
"/ FB (diacrit ring) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
328 |
"/ FC (diacrit cedille left) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
329 |
"/ FD (diacrit dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
330 |
"/ FE (diacrit cedille right) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
331 |
"/ FF (diacrit circumflex2 ?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
332 |
"/ |
443 | 333 |
encoding == #mac ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
334 |
x80Table := |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
335 |
#( 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
|
336 |
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
|
337 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
338 |
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
|
339 |
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
|
340 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
341 |
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
|
342 |
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
|
343 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
344 |
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
|
345 |
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
|
346 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
347 |
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
|
348 |
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
|
349 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
350 |
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
|
351 |
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
|
352 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
353 |
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
|
354 |
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
|
355 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
356 |
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
|
357 |
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
|
358 |
). |
657 | 359 |
]. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
360 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
361 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
362 |
"/ next -> iso8859 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
363 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
364 |
"/ 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
|
365 |
"/ - 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
|
366 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
367 |
"/ A4 (diacrit /) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
368 |
"/ A9 (diacrit quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
369 |
"/ AA (top opening dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
370 |
"/ AC (single oldStyle opening quote (<)) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
371 |
"/ AD (single oldStyle closing quote (>)) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
372 |
"/ AE (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
373 |
"/ AF (?) |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
374 |
"/ B2 (dagger) |
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
375 |
"/ B3 (double dagger) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
376 |
"/ B7 (enter dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
377 |
"/ B8 (opening bottom quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
378 |
"/ B9 (opening bottom dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
379 |
"/ BA (closing top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
380 |
"/ BC (dot-dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
381 |
"/ BD (per-mille) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
382 |
"/ C0 (subscript 1) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
383 |
"/ C1 (accent grave) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
384 |
"/ C2 (accent degu) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
385 |
"/ C3 (accent circonflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
386 |
"/ C4 (accent tilde) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
387 |
"/ C5 (accent line) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
388 |
"/ C6 (accent circonflex reverse) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
389 |
"/ C7 (accent dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
390 |
"/ C8 (accent dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
391 |
"/ D0 (hline) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
392 |
"/ 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
|
393 |
"/ EA (OE ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
394 |
"/ F5 (latin l) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
395 |
"/ 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
|
396 |
"/ FE (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
397 |
"/ FF (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
398 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
399 |
encoding == #next ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
400 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
401 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
402 |
x80Table := |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
403 |
#( 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
|
404 |
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
|
405 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
406 |
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
|
407 |
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
|
408 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
409 |
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
|
410 |
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
|
411 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
412 |
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
|
413 |
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
|
414 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
415 |
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
|
416 |
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
|
417 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
418 |
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
|
419 |
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
|
420 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
421 |
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
|
422 |
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
|
423 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
424 |
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
|
425 |
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
|
426 |
). |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
427 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
428 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
429 |
"/ |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
430 |
"/ 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
|
431 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
432 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
433 |
"/ 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
|
434 |
"/ - 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
|
435 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
436 |
"/ 9E (pesetas) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
437 |
"/ 9F (latin f) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
438 |
"/ A9 (technical not) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
439 |
"/ B0 - BF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
440 |
"/ C0 - CF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
441 |
"/ D0 - DF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
442 |
"/ E0 (greek alpha) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
443 |
"/ E2 - E5 (greek) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
444 |
"/ E7 - EC (greek & math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
445 |
"/ EE - EF (greek & math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
446 |
"/ F0 (math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
447 |
"/ F2 - F5 (math & technical) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
448 |
"/ F7 (math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
449 |
"/ F9 (center dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
450 |
"/ FB (math sqrt) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
451 |
"/ FC (super n) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
452 |
"/ 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
|
453 |
"/ |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
454 |
encoding == #msdos437 ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
455 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
456 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
457 |
x80Table := |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
458 |
#( |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
459 |
"/ 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
|
460 |
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
|
461 |
"/ 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
|
462 |
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
|
463 |
"/ 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
|
464 |
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
|
465 |
"/ 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
|
466 |
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
|
467 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
468 |
"/ 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
|
469 |
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
|
470 |
"/ 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
|
471 |
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
|
472 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
473 |
"/ block graphics |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
474 |
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
|
475 |
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
|
476 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
477 |
"/ block graphics |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
478 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF "/ c0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
479 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
480 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
481 |
"/ block graphics |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
482 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF "/ d0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
483 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
484 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
485 |
"/ alpha beta ... mu |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
486 |
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
|
487 |
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
|
488 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
489 |
"/ 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
|
490 |
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
|
491 |
"/ 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
|
492 |
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
|
493 |
). |
443 | 494 |
]. |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
495 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
496 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
497 |
"/ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
498 |
"/ msdos (codePage 850 [=latin1]) -> iso8859 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
499 |
"/ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
500 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
501 |
(encoding == #msdos850 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
502 |
or:[encoding == #msdos]) ifTrue:[ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
503 |
unrepresentableCharacterCode := 16rBF. |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
504 |
x80Table := |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
505 |
#( |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
506 |
"/ 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
|
507 |
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
|
508 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
509 |
"/ 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
|
510 |
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
|
511 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
512 |
"/ 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
|
513 |
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
|
514 |
"/ 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
|
515 |
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
|
516 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
517 |
"/ 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
|
518 |
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
|
519 |
"/ 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
|
520 |
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
|
521 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
522 |
"/ Aacute Acirc Agrave |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
523 |
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
|
524 |
"/ cpyr cent Yen |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
525 |
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
|
526 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
527 |
"/ atilde Atilde |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
528 |
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
|
529 |
"/ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
530 |
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
|
531 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
532 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
533 |
"/ Ecirc Euml Egrave Iacute Icirc |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
534 |
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
|
535 |
"/ Iuml Igrave |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
536 |
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
|
537 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
538 |
"/ Oacute sz Ocirc Ograve otilde Otilde mu |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
539 |
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
|
540 |
"/ Uacute Ucirc Ugrav yacute Yacute ' |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
541 |
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
|
542 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
543 |
"/ plusmin = 3/4 para sect div "/ f0 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
544 |
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
|
545 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
546 |
"/ sup0 sup3 sup2 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
547 |
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
|
548 |
). |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
549 |
]. |
443 | 550 |
"/ more encodings needed here .... |
551 |
||
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
552 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
553 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
554 |
"/ 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
|
555 |
"/ 0x80..0xFF characters |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
556 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
557 |
x80Table isNil ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
558 |
table := #identity. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
559 |
] ifFalse:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
560 |
x80Table keysAndValuesDo:[:idx :repl | |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
561 |
|ch| |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
562 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
563 |
repl == 16rFFFF ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
564 |
ch := unrepresentableCharacterCode |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
565 |
] ifFalse:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
566 |
ch := repl |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
567 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
568 |
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
|
569 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
570 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
571 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
572 |
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
|
573 |
^ table |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
574 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
575 |
" |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
576 |
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
|
577 |
DecoderTables := nil |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
578 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
579 |
|
443 | 580 |
"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
|
581 |
"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
|
582 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
583 |
|
2734 | 584 |
defaultRomanCharacterValue |
585 |
"return the characterValue for unmappable roman characters |
|
586 |
(only applies to jis, gb, ksc etc.)" |
|
587 |
||
588 |
|romans| |
|
589 |
||
590 |
romans := self romanTable. |
|
591 |
romans isNil ifTrue:[^ 16r20]. |
|
592 |
^ romans at:1. "/ space characters xlation |
|
593 |
||
594 |
"Created: 30.6.1997 / 18:13:24 / cg" |
|
595 |
"Modified: 30.6.1997 / 18:19:26 / cg" |
|
596 |
! |
|
597 |
||
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
598 |
encoderTableFor:encoding |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
599 |
"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
|
600 |
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
|
601 |
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
|
602 |
|
2751 | 603 |
|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
|
604 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
605 |
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
|
606 |
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
|
607 |
table notNil ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
608 |
table == #identity ifTrue:[^ nil]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
609 |
^ table |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
610 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
611 |
] ifFalse:[ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
612 |
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
|
613 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
614 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
615 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
616 |
"/ iso8859 -> hp |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
617 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
618 |
encoding == #hp ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
619 |
decoderTable := self decoderTableFor:encoding. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
620 |
unrepresentableCharacterCode := 16rFF. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
621 |
]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
622 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
623 |
"/ |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
624 |
"/ iso8859 -> mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
625 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
626 |
encoding == #mac ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
627 |
decoderTable := self decoderTableFor:encoding. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
628 |
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
|
629 |
]. |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
630 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
631 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
632 |
"/ iso8859 -> msdos |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
633 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
634 |
encoding == #msdos ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
635 |
decoderTable := self decoderTableFor:encoding. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
636 |
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
|
637 |
]. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
638 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
639 |
"/ 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
|
640 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
641 |
decoderTable notNil ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
642 |
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
|
643 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
644 |
0 to:16rFF do:[:code | |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
645 |
|isoCode destIdex| |
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 |
isoCode := decoderTable at:(code+1). |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
648 |
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
|
649 |
] |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
650 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
651 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
652 |
table isNil ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
653 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
654 |
"/ 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
|
655 |
"/ use special #identity |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
656 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
657 |
table := #identity. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
658 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
659 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
660 |
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
|
661 |
^ table |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
662 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
663 |
" |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
664 |
EncoderTables := nil. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
665 |
DecoderTables := nil. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
666 |
CharacterArray decoderTableFor:#mac |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
667 |
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
|
668 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
669 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
670 |
"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
|
671 |
"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
|
672 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
673 |
|
2733 | 674 |
romanTable |
675 |
^ nil |
|
676 |
||
677 |
"Created: 30.6.1997 / 15:13:52 / cg" |
|
678 |
! |
|
679 |
||
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
680 |
supportedEncodings |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
681 |
"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
|
682 |
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
|
683 |
|
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
684 |
^ self supportedExternalEncodings at:2. |
2733 | 685 |
|
686 |
"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
|
687 |
! |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
688 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
689 |
supportedExternalEncodings |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
690 |
"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
|
691 |
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
|
692 |
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
|
693 |
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
|
694 |
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
|
695 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
696 |
^ #( |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
697 |
( |
2250 | 698 |
'iso8859 (ansi)' |
699 |
'iso8859-1 (latin1)' |
|
700 |
'iso8859-2 (latin2)' |
|
701 |
'iso8859-3 (latin3)' |
|
702 |
'iso8859-4 (latin4)' |
|
703 |
'iso8859-5 (cyrillic)' |
|
704 |
'iso8859-6 (arabic)' |
|
705 |
'iso8859-7 (greek)' |
|
706 |
'iso8859-8 (hebrew)' |
|
707 |
'msdos US (codepage 437)' |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
708 |
'msdos Latin1 (codepage 850)' |
2250 | 709 |
'macintosh (8 bit)' |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
710 |
'next (8 bit)' |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
711 |
'hp (8 bit)' |
2733 | 712 |
nil |
2250 | 713 |
'EUC (extended unix code japanese)' |
714 |
'JIS7 (jis 7bit escape codes japanese)' |
|
2759 | 715 |
'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
|
716 |
'SJIS (shift jis 8bit codes japanese)' |
2733 | 717 |
nil |
2250 | 718 |
'GB (mainland china)' |
719 |
'BIG5 (taiwan)' |
|
2733 | 720 |
"/ 'KSC (korean)' |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
721 |
) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
722 |
( |
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
723 |
#'iso8859' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
724 |
#'iso8859-1' "/ latin1 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
725 |
#'iso8859-2' "/ latin2 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
726 |
#'iso8859-3' "/ latin3 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
727 |
#'iso8859-4' "/ latin4 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
728 |
#'iso8859-5' "/ cyrillic |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
729 |
#'iso8859-6' "/ arabic |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
730 |
#'iso8859-7' "/ greek |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
731 |
#'iso8859-8' "/ hebrew |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
732 |
#'msdos437' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
733 |
#'msdos850' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
734 |
#'mac' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
735 |
#'next' |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
736 |
#'hp' |
2733 | 737 |
nil |
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
738 |
#'euc' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
739 |
#'jis7' |
2759 | 740 |
#'iso-2022-jp' |
2721 | 741 |
#'sjis' |
2733 | 742 |
nil |
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
743 |
#'gb' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
744 |
#'big5' |
2733 | 745 |
"/ #'ksc' "/ korean |
2250 | 746 |
) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
747 |
) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
748 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
749 |
"Created: 22.4.1996 / 14:39:39 / cg" |
2759 | 750 |
"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
|
751 |
! ! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
752 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
753 |
!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
|
754 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
755 |
decodeFromBIG5:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
756 |
"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
|
757 |
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
|
758 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
759 |
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
|
760 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
761 |
|newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
762 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
763 |
newString := BIG5EncodedString new:aString size. |
1204 | 764 |
^ self decodeFromBIG5_or_GB:aString into:newString. |
765 |
||
766 |
"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
|
767 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
768 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
769 |
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
|
770 |
"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
|
771 |
which is interpreted as a BIG5 encoded singleByte string. |
2748 | 772 |
The result is a Big5EncodedString (you need a BIG5 font to display that ...). |
773 |
||
774 |
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
|
775 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
776 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
777 |
dstIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
778 |
srcIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
779 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
780 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
781 |
val "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
782 |
c| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
783 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
784 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
785 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
786 |
dstIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
787 |
srcIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
788 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
789 |
[true] whileTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
790 |
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
|
791 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
792 |
"/ characters below 16rA1 are left untranslated |
2733 | 793 |
"/ (romans). |
794 |
"/ 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
|
795 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
796 |
b1 := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
797 |
b1 >= 16rA1 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
798 |
srcIdx := srcIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
799 |
srcIdx <= sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
800 |
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
|
801 |
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
|
802 |
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
|
803 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
804 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
805 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
806 |
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
|
807 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
808 |
srcIdx := srcIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
809 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
810 |
srcIdx > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
811 |
^ 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
|
812 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
813 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
814 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
815 |
^ a16BitString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
816 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
817 |
"Created: 17.4.1996 / 16:55:54 / cg" |
2748 | 818 |
"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
|
819 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
820 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
821 |
decodeFromEUC:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
822 |
"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
|
823 |
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
|
824 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
825 |
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
|
826 |
this one only understands New-JIS. |
2748 | 827 |
The result is a JISEncodedString (you need a JIS font to display that ...). |
828 |
||
829 |
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
|
830 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
831 |
|newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
832 |
sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
833 |
dstIdx "{ Class: SmallInteger }" |
2750 | 834 |
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
|
835 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
836 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
837 |
val "{ Class: SmallInteger }" |
2733 | 838 |
c c2| |
1202
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 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
841 |
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
|
842 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
843 |
dstIdx := 1. |
2750 | 844 |
srcIdx := 1. |
845 |
||
846 |
%{ |
|
847 |
if (__isString(aString) |
|
848 |
&& (__Class(newString) == @global(JISEncodedString))) { |
|
849 |
int _dstIdx = 1, _srcIdx = 1; |
|
850 |
int _sz = __intVal(sz); |
|
851 |
unsigned char *_cp = __stringVal(aString); |
|
852 |
unsigned char _c1; |
|
853 |
unsigned short *_jcp = (unsigned short *)__stringVal(newString); |
|
854 |
||
855 |
while (_srcIdx <= _sz) { |
|
856 |
_c1 = _cp[_srcIdx-1]; |
|
857 |
if (_c1 < 161) { |
|
858 |
_jcp[_dstIdx-1] = _c1; |
|
859 |
} else { |
|
860 |
_srcIdx++; |
|
861 |
if (_srcIdx <= _sz) { |
|
862 |
unsigned char _c2; |
|
863 |
int _val; |
|
864 |
int _b1, _b2; |
|
865 |
||
866 |
_b1 = _c1 - 128; |
|
867 |
_c2 = _cp[_srcIdx-1]; |
|
868 |
_b2 = _c2 - 128; |
|
869 |
_val = (_b1<<8) + _b2; |
|
870 |
if (_val < 0) { |
|
871 |
/* decoder errors are handled in smalltalk */ |
|
872 |
_srcIdx--; |
|
873 |
goto getOutOfHere; |
|
874 |
} |
|
875 |
_jcp[_dstIdx-1] = _val; |
|
876 |
} else { |
|
877 |
_jcp[_dstIdx-1] = _c1; |
|
878 |
} |
|
879 |
} |
|
880 |
_dstIdx++; |
|
881 |
_srcIdx++; |
|
882 |
} |
|
883 |
getOutOfHere: |
|
884 |
srcIdx = __MKSMALLINT(_srcIdx); |
|
885 |
dstIdx = __MKSMALLINT(_dstIdx); |
|
886 |
} |
|
887 |
%}. |
|
888 |
||
889 |
[srcIdx <= sz] whileTrue:[ |
|
890 |
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
|
891 |
b1 := c asciiValue. |
2748 | 892 |
b1 < 161 ifTrue:[ |
893 |
"/ characters below 16rA1 are left untranslated |
|
894 |
"/ (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
|
895 |
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
|
896 |
] ifFalse:[ |
2750 | 897 |
srcIdx := srcIdx + 1. |
898 |
srcIdx <= sz ifTrue:[ |
|
2748 | 899 |
b1 := b1 - 128. |
2750 | 900 |
b2 := (c2 := aString at:srcIdx) asciiValue. |
2748 | 901 |
b2 := b2 - 128. |
902 |
val := (b1 bitShift:8) bitOr:b2. |
|
903 |
val <= 0 ifTrue:[ |
|
904 |
DecodingFailedSignal |
|
905 |
raiseWith:aString |
|
906 |
errorString:'EUC decoding failed (not EUC encoded ?)'. |
|
907 |
newString at:dstIdx put:c. |
|
908 |
dstIdx := dstIdx + 1. |
|
909 |
newString at:dstIdx put:c2. |
|
910 |
] ifFalse:[ |
|
911 |
newString at:dstIdx put:(Character value:val). |
|
912 |
]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
913 |
] ifFalse:[ |
2748 | 914 |
newString at:dstIdx put:c. |
915 |
]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
916 |
]. |
2748 | 917 |
dstIdx := dstIdx + 1. |
2750 | 918 |
srcIdx := srcIdx + 1. |
919 |
]. |
|
920 |
||
921 |
(dstIdx-1) ~~ sz ifTrue:[ |
|
922 |
newString := newString copyFrom:1 to:dstIdx-1. |
|
923 |
]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
924 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
925 |
^ newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
926 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
927 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
928 |
|
2733 | 929 |
'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
|
930 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
931 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
932 |
"Created: 17.4.1996 / 16:10:22 / cg" |
2748 | 933 |
"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
|
934 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
935 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
936 |
decodeFromGB:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
937 |
"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
|
938 |
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
|
939 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
940 |
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
|
941 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
942 |
|newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
943 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
944 |
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
|
945 |
^ 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
|
946 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
947 |
"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
|
948 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
949 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
950 |
decodeFromJIS7:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
951 |
"return a new string containing the aStrings characters, |
2758 | 952 |
which are interpreted as a JIS7 or ISO2022-JP encoded singleByte string. |
953 |
There are various JIS encodings around (New-JIS, Old-JIS, NEC-JIS and ISO2022); |
|
954 |
this one understands New-JIS, ISO2022 and treats Old-JIS just the same. |
|
2748 | 955 |
The result is a JISEncodedString (you need a JIS font to display that ...). |
956 |
||
957 |
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
|
958 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
959 |
|newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
960 |
sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
961 |
dstIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
962 |
start "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
963 |
stop "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
964 |
n1 n2 n3 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
965 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
966 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
967 |
val "{ Class: SmallInteger }" |
2734 | 968 |
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
|
969 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
970 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
971 |
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
|
972 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
973 |
dstIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
974 |
start := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
975 |
singleBytes := true. |
2734 | 976 |
katakana := false. |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
977 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
978 |
[true] whileTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
979 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
980 |
"/ 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
|
981 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
982 |
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
|
983 |
stop == 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
984 |
stop := sz + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
985 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
986 |
(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
|
987 |
stop := sz + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
988 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
989 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
990 |
singleBytes ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
991 |
start to:(stop - 1) do:[:i | |
2758 | 992 |
c := aString at:i. |
2734 | 993 |
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
|
994 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
995 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
996 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
997 |
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
|
998 |
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
|
999 |
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
|
1000 |
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
|
1001 |
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
|
1002 |
dstIdx := dstIdx + 1. |
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 |
]. |
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 |
stop > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1007 |
^ 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
|
1008 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1009 |
start := stop. |
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 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1012 |
"/ 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
|
1013 |
"/ - 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
|
1014 |
"/ 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
|
1015 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1016 |
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
|
1017 |
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
|
1018 |
n3 := aString at:(start + 2). |
2734 | 1019 |
katakana := false. |
1020 |
||
1021 |
(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
|
1022 |
singleBytes := false. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1023 |
] ifFalse:[ |
2734 | 1024 |
(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
|
1025 |
singleBytes := false. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1026 |
] ifFalse:[ |
2734 | 1027 |
(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
|
1028 |
singleBytes := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1029 |
] ifFalse:[ |
2734 | 1030 |
(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
|
1031 |
singleBytes := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1032 |
] ifFalse:[ |
2734 | 1033 |
(n2 == $( and:[n3 == $I ]) ifTrue:[ |
1034 |
singleBytes := true. |
|
1035 |
katakana := true. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1036 |
] ifFalse:[ |
2734 | 1037 |
singleBytes ifTrue:[ |
1038 |
newString at:dstIdx put:n1. |
|
1039 |
newString at:(dstIdx + 1) put:n2. |
|
1040 |
newString at:(dstIdx + 2) put:n3. |
|
1041 |
dstIdx := dstIdx + 3. |
|
1042 |
] ifFalse:[ |
|
1043 |
DecodingFailedSignal |
|
1044 |
raiseWith:aString |
|
1045 |
errorString:'JIS7 decoding failed (not JIS7 encoded ?)'. |
|
1046 |
newString at:dstIdx put:n1. |
|
1047 |
newString at:(dstIdx + 1) put:n2. |
|
1048 |
newString at:(dstIdx + 2) put:n3. |
|
1049 |
dstIdx := dstIdx + 3. |
|
1050 |
] |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1051 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1052 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1053 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1054 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1055 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1056 |
start := start + 3. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1057 |
start > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1058 |
^ 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
|
1059 |
] |
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 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1062 |
^ newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1063 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1064 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1065 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1066 |
'hello' decodeFromJIS7 |
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 |
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
|
1069 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1070 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1071 |
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
|
1072 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1073 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1074 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1075 |
s := 'hello' copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1076 |
s := s copyWith:$A. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1077 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1078 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1079 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1080 |
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
|
1081 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1082 |
s decodeFromJIS7 |
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 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1085 |
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
|
1086 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1087 |
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
|
1088 |
s decodeFromJIS7 |
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 |
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
|
1091 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1092 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1093 |
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
|
1094 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1095 |
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
|
1096 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1097 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1098 |
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
|
1099 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1100 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1101 |
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
|
1102 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1103 |
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
|
1104 |
s := s , '$3'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1105 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1106 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1107 |
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
|
1108 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1109 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1110 |
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
|
1111 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1112 |
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
|
1113 |
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
|
1114 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1115 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1116 |
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
|
1117 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1118 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1119 |
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
|
1120 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1121 |
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
|
1122 |
s := s , '$3'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1123 |
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
|
1124 |
s := s copyWith:$(. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1125 |
s := s copyWith:$B. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1126 |
s := s , 'hello'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1127 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1128 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1129 |
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
|
1130 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1131 |
|s t l| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1132 |
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
|
1133 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1134 |
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
|
1135 |
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
|
1136 |
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
|
1137 |
s := s copyWith:$(. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1138 |
s := s copyWith:$B. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1139 |
s := s , ' kterm'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1140 |
t := s decodeFromJIS7. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1141 |
l := Label new. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1142 |
l label:t. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1143 |
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
|
1144 |
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
|
1145 |
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
|
1146 |
l realize |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1147 |
" |
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 |
"Created: 17.4.1996 / 16:11:57 / cg" |
2758 | 1150 |
"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
|
1151 |
! |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1152 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1153 |
decodeFromSJIS:aString |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1154 |
"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
|
1155 |
which are interpreted as a Shift-JIS encoded singleByte string. |
2748 | 1156 |
The result is a JISEncodedString (you need a JIS font to display that ...). |
1157 |
||
1158 |
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
|
1159 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1160 |
|newString char1 char2 |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1161 |
sz "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1162 |
dstIdx "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1163 |
srcIdx "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1164 |
b1 "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1165 |
b2 "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1166 |
val "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1167 |
| |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1168 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1169 |
sz := aString size. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1170 |
newString := JISEncodedString new:sz. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1171 |
sz ~~ 0 ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1172 |
dstIdx := 1. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1173 |
srcIdx := 1. |
2749 | 1174 |
%{ |
2757 | 1175 |
if (1 && __isString(aString) |
2749 | 1176 |
&& (__Class(newString) == @global(JISEncodedString))) { |
1177 |
int _dstIdx = 1, _srcIdx = 1; |
|
1178 |
int _sz = __intVal(sz); |
|
1179 |
unsigned char *_cp = __stringVal(aString); |
|
1180 |
unsigned char _c1, _c2; |
|
1181 |
unsigned short *_jcp = (unsigned short *)__stringVal(newString); |
|
1182 |
||
1183 |
while (_srcIdx <= _sz) { |
|
1184 |
int _val; |
|
1185 |
||
1186 |
_c1 = _cp[_srcIdx-1]; |
|
1187 |
_srcIdx++; |
|
1188 |
||
1189 |
if ((_srcIdx <= _sz) |
|
1190 |
&& (((_c1 >= 129) && (_c1 <= 159)) |
|
1191 |
|| ((_c1 >= 224) && (_c1 <= 239)))) { |
|
1192 |
_c2 = _cp[_srcIdx-1]; |
|
1193 |
_srcIdx++; |
|
1194 |
if ((_c2 >= 64) && (_c2 <= 252)) { |
|
1195 |
int _adjust, _rowOffs, _cellOffs; |
|
1196 |
int _b1, _b2; |
|
1197 |
||
1198 |
_adjust = (_c2 < 159) ? 1 : 0; |
|
1199 |
_rowOffs = (_c1 < 160) ? 112 : 176; |
|
1200 |
if (_adjust) { |
|
1201 |
_cellOffs = 31 + ((_c2 > 127) ? 1 : 0); |
|
1202 |
} else { |
|
1203 |
_cellOffs = 126; |
|
1204 |
} |
|
1205 |
_b1 = ((_c1 - _rowOffs) << 1) - _adjust; |
|
1206 |
_b2 = (_c2 - _cellOffs); |
|
1207 |
_val = (_b1<<8) + _b2; |
|
1208 |
if (_val <= 0) { |
|
1209 |
/* decoder error - let smalltalk handle that */ |
|
1210 |
_srcIdx -= 2; |
|
1211 |
goto getOutOfHere; |
|
1212 |
} |
|
1213 |
_jcp[_dstIdx-1] = _val; |
|
1214 |
} else { |
|
1215 |
/* mhmh - append untranslated */ |
|
1216 |
||
1217 |
_jcp[_dstIdx-1] = _c1; |
|
1218 |
_dstIdx++; |
|
1219 |
_jcp[_dstIdx-1] = _c2; |
|
1220 |
} |
|
1221 |
} else { |
|
1222 |
if ((_c1 >= 0xA1 /* 161 */) && (_c1 <= 0xDF /* 223 */)) { |
|
1223 |
/* HALFWIDTH KATAKANA |
|
1224 |
* map half-width katakana to 8E:xx |
|
1225 |
*/ |
|
1226 |
_val = _c1 - 128; |
|
1227 |
_val = _val + 0x8E00; |
|
1228 |
_jcp[_dstIdx-1] = _val; |
|
1229 |
} else { |
|
1230 |
/* roman characters left untranslated */ |
|
1231 |
_jcp[_dstIdx-1] = _c1; |
|
1232 |
} |
|
1233 |
} |
|
1234 |
_dstIdx++; |
|
1235 |
} |
|
1236 |
getOutOfHere: ; |
|
1237 |
dstIdx = __MKSMALLINT(_dstIdx); |
|
1238 |
srcIdx = __MKSMALLINT(_srcIdx); |
|
1239 |
} |
|
1240 |
%}. |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1241 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1242 |
[srcIdx <= sz] whileTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1243 |
"/ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1244 |
"/ 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
|
1245 |
"/ |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1246 |
char1 := aString at:srcIdx. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1247 |
srcIdx := srcIdx + 1. |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1248 |
b1 := char1 asciiValue. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1249 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1250 |
((srcIdx <= sz) |
2757 | 1251 |
and:[(b1 >= 129 and:[b1 <= 159]) "/ SJIS1 81 .. 9F |
1252 |
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
|
1253 |
char2 := aString at:srcIdx. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1254 |
srcIdx := srcIdx + 1. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1255 |
b2 := char2 asciiValue. |
2757 | 1256 |
(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
|
1257 |
|adjust rowOffs cellOffs| |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1258 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1259 |
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
|
1260 |
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
|
1261 |
adjust == 1 ifTrue:[ |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1262 |
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
|
1263 |
] ifFalse:[ |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1264 |
cellOffs := 126. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1265 |
]. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1266 |
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
|
1267 |
b2 := (b2 - cellOffs). |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1268 |
val := (b1 bitShift:8) + b2. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1269 |
val <= 0 ifTrue:[ |
2730
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1270 |
DecodingFailedSignal |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1271 |
raiseWith:aString |
2730
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1272 |
errorString:'SJIS decoding failed (not SJIS encoded ?)'. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1273 |
newString at:dstIdx put:char1. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1274 |
dstIdx := dstIdx + 1. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1275 |
newString at:dstIdx put:char2. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1276 |
] ifFalse:[ |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1277 |
newString at:dstIdx put:(Character value:val). |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1278 |
] |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1279 |
] ifFalse:[ |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1280 |
"/ mhmh - append untranslated |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1281 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1282 |
newString at:dstIdx put:char1. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1283 |
dstIdx := dstIdx + 1. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1284 |
newString at:dstIdx put:char2. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1285 |
] |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1286 |
] ifFalse:[ |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1287 |
(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
|
1288 |
"/ 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
|
1289 |
val := b1 - 128. |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1290 |
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
|
1291 |
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
|
1292 |
] ifFalse:[ |
2733 | 1293 |
"/ roman characters left untranslated |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1294 |
newString at:dstIdx put:char1 |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1295 |
] |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1296 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1297 |
dstIdx := dstIdx + 1. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1298 |
]. |
2749 | 1299 |
(dstIdx-1) ~~ sz ifTrue:[ |
1300 |
newString := newString copyTo:dstIdx - 1. |
|
1301 |
] |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1302 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1303 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1304 |
^ newString |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1305 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1306 |
"simple: |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1307 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1308 |
'hello' decodeFrom:#sjis |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1309 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1310 |
'../../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
|
1311 |
decodeFrom:#sjis |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1312 |
" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1313 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1314 |
"Created: 28.6.1997 / 19:19:23 / cg" |
2748 | 1315 |
"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
|
1316 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1317 |
|
2733 | 1318 |
encodeIntoBIG5:aBIG5String |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1319 |
"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
|
1320 |
The argument must be a BIG5String. |
2733 | 1321 |
This is used translate 16bit BIG5 strings into the external BIG5 encoded |
1322 |
representation. |
|
1323 |
The resulting string is only useful to be stored on some external file, |
|
2748 | 1324 |
not for being displayed in an ST/X view. |
1325 |
||
1326 |
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
|
1327 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1328 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1329 |
b "{ Class: SmallInteger }" |
2733 | 1330 |
c out| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1331 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1332 |
sz := aBIG5String size. |
2733 | 1333 |
out := WriteStream on:(String new:(sz * 2)). |
1334 |
||
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1335 |
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
|
1336 |
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
|
1337 |
b := c asciiValue. |
1203
a43528048cb8
code tables moved to BIG5/JISEncodedString classes
Claus Gittinger <cg@exept.de>
parents:
1202
diff
changeset
|
1338 |
|
2733 | 1339 |
b > 255 ifTrue:[ |
1340 |
"/ big5 character |
|
1341 |
||
1342 |
out nextPut:(Character value:(b bitShift:-8)). |
|
1343 |
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
|
1344 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1345 |
"/ |
2733 | 1346 |
"/ 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
|
1347 |
"/ |
2733 | 1348 |
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
|
1349 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1350 |
]. |
2733 | 1351 |
^ out contents |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1352 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1353 |
"Created: 17.4.1996 / 17:17:50 / cg" |
2748 | 1354 |
"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
|
1355 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1356 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1357 |
encodeIntoEUC:aJISString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1358 |
"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
|
1359 |
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
|
1360 |
The resulting string is only useful to be stored on some external file, |
2748 | 1361 |
not for being displayed in an ST/X view. |
1362 |
||
1363 |
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
|
1364 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1365 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1366 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1367 |
val "{ Class: SmallInteger }" |
2733 | 1368 |
c romans out| |
1369 |
||
1370 |
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
|
1371 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1372 |
sz := aJISString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1373 |
sz == 0 ifTrue:[^ '']. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1374 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1375 |
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
|
1376 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1377 |
1 to:sz do:[:srcIndex | |
2733 | 1378 |
b1 := (c := aJISString at:srcIndex) asciiValue. |
2748 | 1379 |
b1 < 161 ifTrue:[ |
1380 |
"/ a control or roman character |
|
2733 | 1381 |
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
|
1382 |
] ifFalse:[ |
2748 | 1383 |
"/ |
1384 |
"/ check for a roman character |
|
1385 |
"/ the two numbers below are romanTable min and romanTable max |
|
1386 |
"/ |
|
1387 |
(b1 between:16r2121 and:16r2573) ifTrue:[ |
|
1388 |
val := romans indexOf:b1. |
|
1389 |
(val ~~ 0 and:[val <= 127]) ifTrue:[ |
|
1390 |
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
|
1391 |
] ifFalse:[ |
2747 | 1392 |
out nextPut:(Character value:(b1 bitShift:-8) + 128). |
1393 |
out nextPut:(Character value:(b1 bitAnd:16rFF) + 128). |
|
2748 | 1394 |
]. |
1395 |
] ifFalse:[ |
|
1396 |
out nextPut:(Character value:(b1 bitShift:-8) + 128). |
|
1397 |
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
|
1398 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1399 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1400 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1401 |
^ out contents |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1402 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1403 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1404 |
|
2733 | 1405 |
('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
|
1406 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1407 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1408 |
"Created: 17.4.1996 / 16:13:33 / cg" |
2748 | 1409 |
"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
|
1410 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1411 |
|
2733 | 1412 |
encodeIntoGB:aGBString |
1413 |
"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
|
1414 |
The argument must be a GBString. |
2733 | 1415 |
This is used translate 16bit GB strings into the external GB encoded |
1416 |
representation. |
|
1417 |
The resulting string is only useful to be stored on some external file, |
|
2748 | 1418 |
not for being displayed in an ST/X view. |
1419 |
||
1420 |
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
|
1421 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1422 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1423 |
b "{ Class: SmallInteger }" |
2733 | 1424 |
c out| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1425 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1426 |
sz := aGBString size. |
2733 | 1427 |
out := WriteStream on:(String new:(sz * 2)). |
1428 |
||
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1429 |
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
|
1430 |
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
|
1431 |
b := c asciiValue. |
2733 | 1432 |
b > 255 ifTrue:[ |
1433 |
"/ big5 character |
|
1434 |
||
1435 |
out nextPut:(Character value:(b bitShift:-8)). |
|
1436 |
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
|
1437 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1438 |
"/ |
2733 | 1439 |
"/ 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
|
1440 |
"/ |
2733 | 1441 |
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
|
1442 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1443 |
]. |
2733 | 1444 |
^ out contents |
1445 |
||
1446 |
"Created: 30.6.1997 / 15:48:35 / cg" |
|
2748 | 1447 |
"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
|
1448 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1449 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1450 |
encodeIntoJIS7:aJISString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1451 |
"return a new string with aJISStrings characters as JIS7 encoded 7bit string, |
2733 | 1452 |
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
|
1453 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1454 |
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
|
1455 |
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
|
1456 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1457 |
|sz "{ Class:SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1458 |
b1 "{ Class:SmallInteger }" |
2757 | 1459 |
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
|
1460 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1461 |
inSingleByteMode := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1462 |
kanji := JISEncodedString jis7KanjiEscapeSequence. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1463 |
roman := JISEncodedString jis7RomanEscapeSequence. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1464 |
|
2733 | 1465 |
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
|
1466 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1467 |
sz := aJISString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1468 |
sz == 0 ifTrue:[^ '']. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1469 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1470 |
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
|
1471 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1472 |
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
|
1473 |
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
|
1474 |
b1 := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1475 |
b1 < 33 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1476 |
"/ a control character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1477 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1478 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1479 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1480 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1481 |
out nextPut:c. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1482 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1483 |
"/ 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
|
1484 |
"/ 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
|
1485 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1486 |
(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
|
1487 |
val := romans indexOf:b1. |
2757 | 1488 |
val2 := val - 1 + 32. |
1489 |
(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
|
1490 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1491 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1492 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1493 |
]. |
2757 | 1494 |
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
|
1495 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1496 |
inSingleByteMode ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1497 |
out nextPutAll:kanji. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1498 |
inSingleByteMode := false |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1499 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1500 |
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
|
1501 |
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
|
1502 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1503 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1504 |
b1 <= 255 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1505 |
"/ 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
|
1506 |
"/ b1 >= 160 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1507 |
"/ ('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
|
1508 |
"/ ]. |
2734 | 1509 |
EncodingFailedSignal |
1510 |
raiseWith:aJISString |
|
1511 |
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
|
1512 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1513 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1514 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1515 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1516 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1517 |
out nextPut:c |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1518 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1519 |
inSingleByteMode ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1520 |
out nextPutAll:kanji. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1521 |
inSingleByteMode := false |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1522 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1523 |
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
|
1524 |
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
|
1525 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1526 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1527 |
]. |
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 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1530 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1531 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1532 |
^ out contents |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1533 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1534 |
"simple: |
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 |
'hello' decodeFromJIS7 encodeIntoJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1537 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1538 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1539 |
"Created: 17.4.1996 / 16:17:40 / cg" |
2757 | 1540 |
"Modified: 16.7.1997 / 11:30:07 / cg" |
2721 | 1541 |
! |
1542 |
||
2731 | 1543 |
encodeIntoSJIS:aJISString |
1544 |
"return a new string with aJISStrings characters as SJIS encoded 8bit string. |
|
2733 | 1545 |
The receiver must be a JIS encoded character string. |
2731 | 1546 |
|
1547 |
The resulting string is only useful to be stored on some external file, |
|
1548 |
not for being displayed in an ST/X view." |
|
1549 |
||
1550 |
|sz "{ Class: SmallInteger }" |
|
1551 |
rval "{ Class: SmallInteger }" |
|
1552 |
val "{ Class: SmallInteger }" |
|
1553 |
romans c out isSJIS| |
|
1554 |
||
2733 | 1555 |
romans := JISEncodedString romanTable. |
2731 | 1556 |
|
1557 |
sz := aJISString size. |
|
1558 |
sz == 0 ifTrue:[^ '']. |
|
1559 |
||
1560 |
out := WriteStream on:(String new:(sz * 2)). |
|
1561 |
||
1562 |
1 to:sz do:[:srcIndex | |
|
1563 |
val := (c := aJISString at:srcIndex) asciiValue. |
|
2748 | 1564 |
val <= 128 ifTrue:[ |
1565 |
"/ a control or ascii character |
|
2731 | 1566 |
out nextPut:c. |
1567 |
] ifFalse:[ |
|
2748 | 1568 |
(val > 150 and:[val < 224]) ifTrue:[ |
2731 | 1569 |
"/ ascii subset |
1570 |
out nextPut:c. |
|
1571 |
] ifFalse:[ |
|
2748 | 1572 |
"/ should not happen ... |
1573 |
val <= 255 ifTrue:[ |
|
2731 | 1574 |
out nextPut:c. |
1575 |
] ifFalse:[ |
|
2748 | 1576 |
isSJIS := true. |
1577 |
||
1578 |
"/ check for HALFWIDTH KATAKANA |
|
1579 |
"/ 8E:xx |
|
2757 | 1580 |
"/ NO: halfwidth katakana no longer generated |
1581 |
"/ remains there as full-width katakana |
|
1582 |
||
1583 |
"/ (val bitAnd:16rFF00) == 16r8E00 ifTrue:[ |
|
1584 |
"/ |b| |
|
1585 |
"/ |
|
1586 |
"/ b := (val bitAnd:16rFF) + 128. |
|
1587 |
"/ (b >= 16rA1 "161" and:[b <= 16rDF "223"]) ifTrue:[ |
|
1588 |
"/ out nextPut:(Character value:b). |
|
1589 |
"/ isSJIS := false. |
|
1590 |
"/ ]. |
|
1591 |
"/ ]. |
|
2748 | 1592 |
|
1593 |
isSJIS ifTrue:[ |
|
1594 |
||
1595 |
"/ check for a roman character |
|
1596 |
"/ the two numbers below are romanTable min and romanTable max |
|
1597 |
"/ |
|
1598 |
(val between:16r2121 and:16r2573) ifTrue:[ |
|
1599 |
rval := romans indexOf:val. |
|
1600 |
rval ~~ 0 ifTrue:[ |
|
2757 | 1601 |
rval := rval - 1 + 32. |
1602 |
rval <= 16r7F ifTrue:[ "/ do not translate halfwidth katakana |
|
1603 |
out nextPut:(Character value:rval). |
|
1604 |
isSJIS := false. |
|
1605 |
] |
|
2731 | 1606 |
]. |
1607 |
]. |
|
2748 | 1608 |
]. |
1609 |
||
1610 |
isSJIS ifTrue:[ |
|
1611 |
|b1 b2 rowOffset cellOffset| |
|
1612 |
||
1613 |
b1 := (val bitShift:-8). |
|
1614 |
b2 := (val bitAnd:16rFF). |
|
1615 |
rowOffset := (b1 < 95) ifTrue:[112] ifFalse:[176]. |
|
1616 |
cellOffset := b1 odd ifTrue:[(b2 > 95) ifTrue:[32] ifFalse:[31]] |
|
1617 |
ifFalse:[126]. |
|
1618 |
||
1619 |
out nextPut:(Character value:(((b1 + 1) bitShift:-1) + rowOffset)). |
|
1620 |
out nextPut:(Character value:b2 + cellOffset). |
|
2731 | 1621 |
] |
1622 |
] |
|
1623 |
] |
|
1624 |
]. |
|
1625 |
]. |
|
1626 |
^ out contents |
|
1627 |
||
1628 |
"simple: |
|
1629 |
||
1630 |
'hello' decodeFromEUC encodeIntoEUC |
|
1631 |
" |
|
1632 |
||
1633 |
"Created: 28.6.1997 / 21:13:27 / cg" |
|
2757 | 1634 |
"Modified: 16.7.1997 / 11:30:45 / cg" |
2733 | 1635 |
! |
1636 |
||
1637 |
encodeRomans:aTwoByteString |
|
1638 |
"return a new (usually 2-byte) string with roman characters |
|
1639 |
encoded. The position of roman characters are encoding specific. |
|
1640 |
(see romanTable of concrete 16-bit string classes). |
|
1641 |
Used when displaying strings." |
|
1642 |
||
1643 |
|sz "{ Class: SmallInteger }" |
|
1644 |
b "{ Class: SmallInteger }" |
|
1645 |
c romans newString| |
|
1646 |
||
1647 |
romans := self romanTable. |
|
1648 |
romans isNil ifTrue:[^ aTwoByteString]. |
|
1649 |
||
1650 |
sz := aTwoByteString size. |
|
2734 | 1651 |
newString := self fromString:aTwoByteString. |
2733 | 1652 |
|
1653 |
1 to:sz do:[:index | |
|
1654 |
c := aTwoByteString at:index. |
|
1655 |
b := c asciiValue. |
|
1656 |
||
2735 | 1657 |
(b > 32 and:[b <= 255]) ifTrue:[ |
2734 | 1658 |
(b-32+1) <= romans size ifTrue:[ |
1659 |
"/ |
|
1660 |
"/ a roman character |
|
1661 |
"/ map to corresponding row |
|
1662 |
"/ |
|
1663 |
newString at:index put:(Character value:(romans at:b - 32 + 1)) |
|
1664 |
] ifFalse:[ |
|
1665 |
newString at:index put:(Character value:self defaultRomanCharacterValue) |
|
1666 |
] |
|
2733 | 1667 |
]. |
1668 |
]. |
|
1669 |
^ newString |
|
1670 |
||
1671 |
"Created: 30.6.1997 / 15:43:56 / cg" |
|
2735 | 1672 |
"Modified: 30.6.1997 / 21:16:20 / cg" |
2731 | 1673 |
! |
1674 |
||
2721 | 1675 |
guessEncodingFrom:aString |
1676 |
"try to guess some 8-bit strings encoding by |
|
1677 |
searching for certain escape sequences. |
|
1678 |
Returns a string or nil. |
|
1679 |
This may not find the strings real encoding." |
|
1680 |
||
2751 | 1681 |
|idx ascii| |
2721 | 1682 |
|
1683 |
"/ look for JIS7 / EUC encoding ... |
|
1684 |
||
2733 | 1685 |
(aString findString:(JISEncodedString jisISO2022EscapeSequence)) ~~ 0 ifTrue:[ |
2760 | 1686 |
^ #'iso2020-jp' |
2733 | 1687 |
]. |
2721 | 1688 |
(aString findString:(JISEncodedString jis7KanjiEscapeSequence)) ~~ 0 ifTrue:[ |
1689 |
^ #jis7 |
|
1690 |
]. |
|
1691 |
(aString findString:(JISEncodedString oldJis7KanjiEscapeSequence)) ~~ 0 ifTrue:[ |
|
1692 |
^ #jis7 |
|
1693 |
]. |
|
1694 |
||
1695 |
"/ TODO: |
|
1696 |
||
2735 | 1697 |
"/ "/ look for EUC |
1698 |
"/ idx := aString findFirst:[:char | |ascii| |
|
1699 |
"/ ((ascii := char asciiValue) >= 16rA1) |
|
1700 |
"/ and:[ascii <= 16rFE]]. |
|
1701 |
"/ idx ~~ 0 ifTrue:[ |
|
1702 |
"/ ascii := (aString at:(idx + 1)) asciiValue. |
|
1703 |
"/ (ascii >= 16rA1 and:[ascii <= 16rFE]) ifTrue:[ |
|
1704 |
"/ ^ #euc |
|
1705 |
"/ ] |
|
1706 |
"/ ]. |
|
1707 |
||
2721 | 1708 |
"/ look for SJIS ... |
1709 |
||
1710 |
"/ look for UTS ... |
|
1711 |
||
1712 |
^ nil |
|
1713 |
||
2760 | 1714 |
"Modified: 16.7.1997 / 13:54:59 / cg" |
443 | 1715 |
! ! |
1716 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
1717 |
!CharacterArray class methodsFor:'pattern matching'! |
64 | 1718 |
|
327 | 1719 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop ignoreCase:ignoreCase |
1720 |
"helper for match; return true if the characters from start to stop in |
|
1721 |
aString are matching the scan in matchScan from matchStart to matchStop. |
|
328 | 1722 |
The matchScan is as created by asMatchScanArray. |
327 | 1723 |
|
328 | 1724 |
This algorithm is not at all the most efficient; |
1725 |
for heavy duty pattern matching, an interface (primitive) to the regex |
|
1726 |
pattern matching package should be added." |
|
327 | 1727 |
|
1728 |
|matchEntry |
|
1729 |
mStart "{ Class: SmallInteger }" |
|
1730 |
mStop "{ Class: SmallInteger }" |
|
1731 |
sStart "{ Class: SmallInteger }" |
|
1732 |
sStop "{ Class: SmallInteger }" |
|
1733 |
mSize "{ Class: SmallInteger }" |
|
1734 |
sSize "{ Class: SmallInteger }" |
|
1735 |
index "{ Class: SmallInteger }" |
|
2561 | 1736 |
quickCheck matchLast nextMatchEntry |
986 | 1737 |
checkChar included| |
327 | 1738 |
|
1739 |
mStart := matchStart. |
|
1740 |
mStop := matchStop. |
|
1741 |
sStart := start. |
|
1742 |
sStop := stop. |
|
1743 |
||
1744 |
[true] whileTrue:[ |
|
3537 | 1745 |
"/ Transcript showCR:('match: ''' , (aString copyFrom:sStart to:sStop) , |
1746 |
"/ ''' against:' , (matchScanArray copyFrom:mStart to:mStop) printString). |
|
1747 |
||
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1748 |
mSize := mStop - mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1749 |
sSize := sStop - sStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1750 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1751 |
"empty strings match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1752 |
(mSize == 0) ifTrue:[^ (sSize == 0)]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1753 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1754 |
matchEntry := matchScanArray at:mStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1755 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1756 |
"/ the most common case first: |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1757 |
(sSize ~~ 0 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1758 |
and:[(checkChar := (aString at:sStart)) == matchEntry]) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1759 |
"advance by one and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1760 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1761 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1762 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1763 |
(matchEntry == #any) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1764 |
"restString empty -> no match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1765 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1766 |
"# matches single character" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1767 |
((sSize == 1) and:[mSize == 1]) ifTrue:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1768 |
"advance by one and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1769 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1770 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1771 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1772 |
(matchEntry == #anyString) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1773 |
"* alone matches anything" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1774 |
(mSize == 1) ifTrue:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1775 |
"restString empty & matchString not empty -> no match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1776 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1777 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1778 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1779 |
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
|
1780 |
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
|
1781 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1782 |
quickCheck := false. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1783 |
(mStop >= mStart) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1784 |
matchLast := matchScanArray at:mStop. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1785 |
(matchLast ~~ #anyString) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1786 |
(matchLast == #any) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1787 |
quickCheck := true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1788 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1789 |
matchLast == (aString at:sStop) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1790 |
quickCheck := true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1791 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1792 |
matchLast isString ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1793 |
quickCheck := matchLast includes:(aString at:sStop) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1794 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1795 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1796 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1797 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1798 |
]. |
3537 | 1799 |
quickCheck ifTrue:[ |
1800 |
" |
|
1801 |
quickCheck ok, advance from the right |
|
1802 |
" |
|
1803 |
mStop := mStop - 1. |
|
1804 |
sStop := sStop - 1 |
|
1805 |
] ifFalse:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1806 |
"/ no quick check; |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1807 |
"/ look for the next character(s) |
3537 | 1808 |
"/ and try matching there |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1809 |
"/ (to avoid recursion) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1810 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1811 |
mStart < mStop ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1812 |
nextMatchEntry := matchScanArray at:mStart+1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1813 |
nextMatchEntry isCharacter ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1814 |
sStart <= sStop ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1815 |
[true] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1816 |
ignoreCase ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1817 |
index := aString indexOf:nextMatchEntry startingAt:sStart |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1818 |
] ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1819 |
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
|
1820 |
startingAt:sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1821 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1822 |
index == 0 ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1823 |
^ false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1824 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1825 |
(self matchScan:matchScanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1826 |
from:(mStart + 1) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1827 |
to:mStop |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1828 |
with:aString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1829 |
from:index |
3537 | 1830 |
to:sStop |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1831 |
ignoreCase:ignoreCase |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1832 |
) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1833 |
^ true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1834 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1835 |
sStart := index + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1836 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1837 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1838 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1839 |
]. |
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 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1842 |
no quick check possible; |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1843 |
loop over all possible substrings |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1844 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1845 |
index := sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1846 |
[index <= sStop] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1847 |
(self matchScan:matchScanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1848 |
from:(mStart + 1) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1849 |
to:mStop |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1850 |
with:aString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1851 |
from:index |
3537 | 1852 |
to:sStop |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1853 |
ignoreCase:ignoreCase |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1854 |
) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1855 |
^ true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1856 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1857 |
index := index + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1858 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1859 |
^ false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1860 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1861 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1862 |
(matchEntry isString) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1863 |
"testString empty -> no match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1864 |
(sSize == 0) ifTrue:[^ false]. |
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 |
included := false. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1867 |
"/ checkChar := aString at:sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1868 |
included := matchEntry includes:checkChar. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1869 |
included ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1870 |
ignoreCase ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1871 |
checkChar isUppercase ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1872 |
included := matchEntry includes:checkChar asLowercase. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1873 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1874 |
included := matchEntry includes:checkChar asUppercase. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1875 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1876 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1877 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1878 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1879 |
mSize := mSize - 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1880 |
included ifFalse:[^ false]. |
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 |
((sSize == 1) and:[mSize == 0]) ifTrue:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1883 |
"cut off 1st char and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1884 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1885 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1886 |
"/ must be single character |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1887 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1888 |
"testString empty ?" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1889 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1890 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1891 |
"first characters equal ?" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1892 |
"/ checkChar := aString at:sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1893 |
ignoreCase ifFalse:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1894 |
(checkChar asUppercase ~~ matchEntry asUppercase) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1895 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1896 |
"advance and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1897 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1898 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1899 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1900 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1901 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1902 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1903 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1904 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1905 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1906 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1907 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1908 |
scanArray := self matchScanArrayFrom:'*hello'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1909 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1910 |
CharacterArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1911 |
matchScan:scanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1912 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1913 |
to:scanArray size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1914 |
with:s |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1915 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1916 |
to:s size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1917 |
ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1918 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1919 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1920 |
|scanArray s| |
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 |
scanArray := self matchScanArrayFrom:'*hello*'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1923 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1924 |
CharacterArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1925 |
matchScan:scanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1926 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1927 |
to:scanArray size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1928 |
with:s |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1929 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1930 |
to:s size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1931 |
ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1932 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1933 |
|
3537 | 1934 |
"Modified: / 9.6.1998 / 19:02:42 / cg" |
608 | 1935 |
! |
1936 |
||
1937 |
matchScanArrayFrom:aString |
|
1938 |
"scan a pattern string and decompose it into a scanArray. |
|
1939 |
This is processed faster (especially with character ranges), and |
|
1940 |
can also be reused later. (if the same pattern is to be searched again)" |
|
1941 |
||
1942 |
|coll |
|
1943 |
idx "{ Class: SmallInteger }" |
|
1944 |
end c1 c2 matchSet previous| |
|
1945 |
||
1946 |
coll := OrderedCollection new. |
|
1947 |
idx := 1. end := aString size. |
|
1948 |
[idx <= end] whileTrue:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1949 |
|char this| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1950 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1951 |
char := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1952 |
char == $* ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1953 |
previous ~~ #anyString ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1954 |
this := #anyString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1955 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1956 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1957 |
char == $# ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1958 |
previous ~~ #anyString ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1959 |
this := #any |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1960 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1961 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1962 |
char == $[ ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1963 |
matchSet := IdentitySet new. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1964 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1965 |
idx > end ifTrue:[^ nil]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1966 |
char := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1967 |
c1 := nil. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1968 |
[char ~~ $]] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1969 |
((char == $-) and:[c1 notNil]) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1970 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1971 |
idx > end ifTrue:[^ nil]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1972 |
c2 := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1973 |
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
|
1974 |
c1 := nil. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1975 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1976 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1977 |
(char ~~ $]) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1978 |
matchSet add:char. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1979 |
c1 := char. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1980 |
idx := idx + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1981 |
] |
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 |
idx > end ifTrue:[^ nil]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1984 |
char := aString at:idx |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1985 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1986 |
this := matchSet asString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1987 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1988 |
char == $\ ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1989 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1990 |
idx > end ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1991 |
"/ mhmh - what should we do here ? |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1992 |
this := char |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1993 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1994 |
this := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1995 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1996 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1997 |
this := char |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1998 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1999 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2000 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2001 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2002 |
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
|
2003 |
idx := idx + 1 |
608 | 2004 |
]. |
2005 |
||
2006 |
^ coll asArray |
|
2007 |
||
2008 |
" |
|
2009 |
String matchScanArrayFrom:'*ute*' |
|
2010 |
String matchScanArrayFrom:'**ute**' |
|
2011 |
String matchScanArrayFrom:'*uter' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2012 |
String matchScanArrayFrom:'\*uter' |
608 | 2013 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
2014 |
String matchScanArrayFrom:'[abcd]*' |
|
2015 |
String matchScanArrayFrom:'[a-k]*' |
|
2016 |
String matchScanArrayFrom:'*some*compl*ern*' |
|
2017 |
String matchScanArrayFrom:'[a-' |
|
2018 |
String matchScanArrayFrom:'[a-zA-Z]' |
|
2019 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
|
2020 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2021 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2022 |
"Modified: 2.4.1997 / 16:20:29 / cg" |
608 | 2023 |
! ! |
2024 |
||
2025 |
!CharacterArray methodsFor:'Compatibility - ST/V'! |
|
2026 |
||
2027 |
byteAt:index put:aByte |
|
2028 |
"store a byte at given index. |
|
2029 |
This is an ST/V compatibility method." |
|
2030 |
||
1333
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2031 |
"/ (aByte == 0) ifTrue:[ |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2032 |
"/ "store a space instead" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2033 |
"/ ^ 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
|
2034 |
"/ ]. |
608 | 2035 |
^ 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
|
2036 |
|
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2037 |
" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2038 |
'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
|
2039 |
'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
|
2040 |
'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
|
2041 |
" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2042 |
|
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2043 |
"Modified: 6.5.1996 / 10:35:26 / cg" |
608 | 2044 |
! |
2045 |
||
2046 |
replChar:oldChar with:newChar |
|
2047 |
"return a copy of the receiver, with all oldChars replaced |
|
2048 |
by newChar. |
|
2049 |
This is an ST/V compatibility method." |
|
2050 |
||
2916 | 2051 |
^ self copy replaceAll:oldChar with:newChar |
608 | 2052 |
|
2053 |
" |
|
2054 |
'12345678901234567890' replChar:$0 with:$* |
|
2055 |
" |
|
2056 |
! |
|
2057 |
||
2058 |
replChar:oldChar withString:newString |
|
2059 |
"return a copy of the receiver, with all oldChars replaced |
|
2060 |
by newString (i.e. slice in the newString in place of the oldChar). |
|
2061 |
This is an ST/V compatibility method." |
|
2062 |
||
2063 |
|tmpStream| |
|
2064 |
||
2065 |
tmpStream := WriteStream on:(self class new). |
|
2066 |
self do:[:element | |
|
2067 |
element = oldChar ifTrue:[ |
|
2068 |
tmpStream nextPutAll:newString |
|
2069 |
] ifFalse:[ |
|
2070 |
tmpStream nextPut:element |
|
2071 |
]. |
|
2072 |
]. |
|
2073 |
^ tmpStream contents |
|
2074 |
||
2075 |
" |
|
2076 |
'12345678901234567890' replChar:$0 withString:'foo' |
|
2077 |
'a string with spaces' replChar:$ withString:' foo ' |
|
2078 |
" |
|
2079 |
! |
|
2080 |
||
2081 |
trimBlanks |
|
2082 |
"return a copy of the receiver without leading |
|
2083 |
and trailing spaces. |
|
2084 |
This is an ST/V compatibility method." |
|
2085 |
||
2086 |
^ self withoutSpaces |
|
2087 |
||
2088 |
" |
|
2089 |
' spaces at beginning' trimBlanks |
|
2090 |
'spaces at end ' trimBlanks |
|
2091 |
' spaces at beginning and end ' trimBlanks |
|
2092 |
'no spaces' trimBlanks |
|
2093 |
" |
|
2094 |
! ! |
|
2095 |
||
3073 | 2096 |
!CharacterArray methodsFor:'Compatibility - ST80'! |
2097 |
||
2098 |
expandMacrosWith:arg |
|
2099 |
"ST80 compatibility - expand '<..>' macros with |
|
2100 |
argument strings. Similar to #bindWith:. |
|
2101 |
Read the comment in #expandMacrosWithArguments: about |
|
2102 |
limited compatibility issues." |
|
2103 |
||
2104 |
^ self expandMacrosWithArguments:(Array with:arg) |
|
2105 |
||
2106 |
"Created: / 1.11.1997 / 13:01:28 / cg" |
|
2107 |
"Modified: / 1.11.1997 / 13:30:50 / cg" |
|
2108 |
! |
|
2109 |
||
2110 |
expandMacrosWithArguments:argArray |
|
2111 |
"ST80 compatibility - expand '<..>' macros with |
|
2112 |
argument strings. Similar to #bindWith:. |
|
2113 |
WARNING: possibly not all ST80 expansions are supported here." |
|
2114 |
||
2115 |
"/ supported expansions: |
|
2116 |
"/ |
|
2117 |
"/ <#p> # is arg Number; slice in the args printString |
|
2118 |
"/ <#s> # is arg Number; slice in the arg itself (must be a String) |
|
2119 |
"/ <n> replace by a newLine character |
|
2120 |
||
2121 |
|in out c fmt nr| |
|
2122 |
||
2123 |
in := self readStream. |
|
2124 |
out := '' writeStream. |
|
2125 |
||
2126 |
[in atEnd] whileFalse:[ |
|
2127 |
c := in next. |
|
2128 |
c == $< ifTrue:[ |
|
2129 |
in peek == $n ifTrue:[ |
|
2130 |
out nextPut:Character cr. |
|
2131 |
in next |
|
2132 |
] ifFalse:[ |
|
2133 |
"/ start an argument expansion ... |
|
2134 |
nr := Integer readFrom:in onError:nil. |
|
2135 |
nr isNil ifTrue:[ |
|
2136 |
"/ what does VW do here ? |
|
2137 |
self halt:'invalid format'. |
|
2138 |
^ self |
|
2139 |
] ifFalse:[ |
|
2140 |
(nr between:1 and:argArray size) ifFalse:[ |
|
2141 |
"/ what does VW do here ? |
|
2142 |
self halt:'invalid format'. |
|
2143 |
^ self |
|
2144 |
] ifTrue:[ |
|
2145 |
fmt := in next. |
|
2146 |
(fmt == $p) ifTrue:[ |
|
2147 |
"/ expand with args printString |
|
2148 |
out nextPutAll:(argArray at:nr) printString. |
|
2149 |
] ifFalse:[ |
|
2150 |
(fmt == $s) ifTrue:[ |
|
2151 |
"/ expand with arg itself |
|
2152 |
out nextPutAll:(argArray at:nr). |
|
2153 |
] ifFalse:[ |
|
2154 |
"/ what does VW do here ? |
|
2155 |
self halt:'invalid format'. |
|
2156 |
^ self |
|
2157 |
] |
|
2158 |
] |
|
2159 |
] |
|
2160 |
]. |
|
2161 |
]. |
|
2162 |
c := in next. |
|
2163 |
c ~~ $> ifTrue:[ |
|
2164 |
"/ what does VW do here ? |
|
2165 |
self halt:'invalid format'. |
|
2166 |
^ self |
|
2167 |
] |
|
2168 |
] ifFalse:[ |
|
2169 |
out nextPut:c |
|
2170 |
]. |
|
2171 |
]. |
|
2172 |
^ out contents |
|
2173 |
||
2174 |
" |
|
2175 |
'hello <1p> how are you' expandMacrosWith:(OperatingSystem getLoginName) |
|
2176 |
" |
|
2177 |
||
2178 |
"Modified: / 1.11.1997 / 13:31:50 / cg" |
|
2179 |
! ! |
|
2180 |
||
1978 | 2181 |
!CharacterArray methodsFor:'Compatibility - V''Age'! |
608 | 2182 |
|
2183 |
addLineDelimiter |
|
2184 |
"replace all '\'-characters by line delimiter (cr) - characters. |
|
2185 |
This has been added for VisualAge compatibility." |
|
2186 |
||
2187 |
^ self withCRs |
|
2188 |
! |
|
2189 |
||
2190 |
bindWith:aString |
|
2191 |
"return a copy of the receiver, where a '%1' escape is |
|
2192 |
replaced by aString. |
|
2193 |
This has been added for VisualAge compatibility." |
|
2194 |
||
2195 |
^ self expandPlaceholdersWith:(Array with:aString) |
|
2196 |
||
2197 |
" |
|
2198 |
'do you like %1 ?' bindWith:'smalltalk' |
|
2199 |
" |
|
2200 |
! |
|
2201 |
||
2202 |
bindWith:string1 with:string2 |
|
2203 |
"return a copy of the receiver, where a '%1' escape is |
|
2204 |
replaced by string1 and '%2' is replaced by string2. |
|
2205 |
This has been added for VisualAge compatibility." |
|
2206 |
||
2207 |
^ self expandPlaceholdersWith:(Array with:string1 with:string2) |
|
2208 |
||
2209 |
" |
|
2210 |
'do you prefer %1 or rather %2 ?' |
|
2211 |
bindWith:'smalltalk' with:'c++' |
|
2212 |
" |
|
2213 |
! |
|
2214 |
||
2215 |
bindWith:str1 with:str2 with:str3 |
|
2216 |
"return a copy of the receiver, where a '%1', '%2' and '%3' escapes |
|
2217 |
are replaced by str1, str2 and str3 respectively. |
|
2218 |
This has been added for VisualAge compatibility." |
|
2219 |
||
2220 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3) |
|
2221 |
||
2222 |
" |
|
2223 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
2224 |
bindWith:'smalltalk' with:'c++' with:'c' |
|
2225 |
" |
|
2226 |
! |
|
2227 |
||
2228 |
bindWith:str1 with:str2 with:str3 with:str4 |
|
2229 |
"return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes |
|
2230 |
are replaced by str1, str2, str3 and str4 respectively. |
|
2231 |
This has been added for VisualAge compatibility." |
|
2232 |
||
2233 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4) |
|
2234 |
||
2235 |
" |
|
2236 |
'do you prefer %1 or rather %2 (not talking about %3 or even %4) ?' |
|
2237 |
bindWith:'smalltalk' with:'c++' with:'c' with:'assembler' |
|
2238 |
" |
|
2239 |
! |
|
2240 |
||
2344 | 2241 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 |
2242 |
"return a copy of the receiver, where a '%1' .. '%5' escapes |
|
2243 |
are replaced by str1 .. str5 respectively. |
|
2244 |
This has been added for VisualAge compatibility." |
|
2245 |
||
2246 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5) |
|
2247 |
||
2248 |
"Created: 31.1.1997 / 16:25:42 / cg" |
|
2249 |
! |
|
2250 |
||
608 | 2251 |
bindWithArguments:anArrayOfStrings |
2252 |
"return a copy of the receiver, where a '%i' escape |
|
2253 |
is replaced by the coresponding string from the argument array. |
|
2254 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
2255 |
This has been added for VisualAge compatibility." |
|
2256 |
||
2257 |
^ self expandPlaceholdersWith:anArrayOfStrings |
|
2258 |
||
2259 |
" |
|
2260 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
2261 |
bindWithArguments:#('smalltalk' 'c++' 'c') |
|
2262 |
" |
|
2263 |
! |
|
2264 |
||
2265 |
subStrings |
|
2266 |
"return an array consisting of all words contained in the receiver. |
|
2267 |
Words are separated by whitespace. |
|
2268 |
This has been added for VisualAge compatibility." |
|
2269 |
||
2270 |
^ self asCollectionOfWords |
|
2271 |
||
2272 |
" |
|
2273 |
'hello world, this is smalltalk' subStrings |
|
2274 |
" |
|
2275 |
! |
|
2276 |
||
2277 |
subStrings:separatorCharacter |
|
2278 |
"return an array consisting of all words contained in the receiver. |
|
2279 |
Words are separated by separatorCharacter. |
|
2280 |
This has been added for VisualAge compatibility." |
|
2281 |
||
2282 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter |
|
2283 |
||
2284 |
" |
|
2285 |
'foo:bar:baz:smalltalk' subStrings:$: |
|
2286 |
" |
|
2287 |
! |
|
2288 |
||
2289 |
trimSeparators |
|
2290 |
"return a copy of the receiver without leading and trailing whiteSpace" |
|
2291 |
||
2292 |
^ self withoutSeparators |
|
2293 |
! ! |
|
2294 |
||
2295 |
!CharacterArray methodsFor:'character searching'! |
|
2296 |
||
2297 |
includesMatchCharacters |
|
2298 |
"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
|
2299 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2300 |
Here, do not care for $\ escapes" |
608 | 2301 |
|
2302 |
^ self includesAny:'*#[' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2303 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2304 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2305 |
'*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2306 |
'\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2307 |
'\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2308 |
'*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2309 |
'\\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2310 |
'foo*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2311 |
'foo\*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2312 |
'foo\' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2313 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2314 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2315 |
"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
|
2316 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2317 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2318 |
includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2319 |
"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
|
2320 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2321 |
Here, care for $\ escapes" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2322 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2323 |
|idx sz| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2324 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2325 |
idx := 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2326 |
sz := self size. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2327 |
[true] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2328 |
idx := self indexOfAny:'*#[\' startingAt:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2329 |
idx == 0 ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2330 |
(self at:idx) == $\ ifFalse:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2331 |
idx := idx + 2. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2332 |
idx > sz ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2333 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2334 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2335 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2336 |
'*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2337 |
'\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2338 |
'*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2339 |
'\\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2340 |
'foo*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2341 |
'foo\*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2342 |
'foo\' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2343 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2344 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2345 |
"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
|
2346 |
"Created: 2.4.1997 / 17:23:26 / cg" |
608 | 2347 |
! |
2348 |
||
2349 |
indexOfNonSeparatorStartingAt:startIndex |
|
2350 |
"return the index of the next non-whitespace character" |
|
2351 |
||
2352 |
|start "{ Class: SmallInteger }" |
|
2353 |
mySize "{ Class: SmallInteger }"| |
|
2354 |
||
2355 |
start := startIndex. |
|
2356 |
mySize := self size. |
|
2357 |
||
2358 |
start to:mySize do:[:index | |
|
2359 |
(self at:index) isSeparator ifFalse:[^ index] |
|
2360 |
]. |
|
2361 |
^ 0 |
|
2362 |
||
2363 |
" |
|
2364 |
' hello world' indexOfNonSeparatorStartingAt:1 |
|
2365 |
" |
|
2366 |
" |
|
2367 |
|s index1 index2| |
|
2368 |
s := ' foo bar baz'. |
|
2369 |
index1 := s indexOfNonSeparatorStartingAt:1. |
|
2370 |
index2 := s indexOfSeparatorStartingAt:index1. |
|
2371 |
s copyFrom:index1 to:index2 - 1 |
|
2372 |
" |
|
2373 |
! |
|
2374 |
||
2375 |
indexOfSeparator |
|
2376 |
"return the index of the first whitespace character" |
|
2377 |
||
2378 |
^ self indexOfSeparatorStartingAt:1 |
|
2379 |
||
2380 |
"'hello world' indexOfSeparator" |
|
2381 |
! |
|
2382 |
||
2383 |
indexOfSeparatorStartingAt:startIndex |
|
2384 |
"return the index of the next whitespace character" |
|
2385 |
||
2386 |
|start "{ Class: SmallInteger }" |
|
2387 |
mySize "{ Class: SmallInteger }"| |
|
2388 |
||
2389 |
start := startIndex. |
|
2390 |
mySize := self size. |
|
2391 |
||
2392 |
start to:mySize do:[:index | |
|
2393 |
(self at:index) isSeparator ifTrue:[^ index] |
|
2394 |
]. |
|
2395 |
^ 0 |
|
2396 |
||
2397 |
"'hello world' indexOfSeparatorStartingAt:3" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2398 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2399 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2400 |
withMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2401 |
"return a copy of the receiver with all match characters escaped |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2402 |
by $\ characters (to be usable as a match string). |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2403 |
Return the receiver, if there are none." |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2404 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2405 |
|in out c| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2406 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2407 |
in := self readStream. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2408 |
out := '' writeStream. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2409 |
[in atEnd] whileFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2410 |
c := in next. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2411 |
('*[#\' includes:c) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2412 |
out nextPut:$\. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2413 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2414 |
out nextPut:c. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2415 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2416 |
^ out contents. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2417 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2418 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2419 |
'*foo' withMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2420 |
'\*foo' withMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2421 |
'*foo' withMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2422 |
'\\*foo' withMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2423 |
'foo*' withMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2424 |
'foo\*' withMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2425 |
'foo\' withMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2426 |
'f*o*o' withMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2427 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2428 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2429 |
"Modified: 2.4.1997 / 18:13:04 / cg" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2430 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2431 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2432 |
withoutMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2433 |
"return a copy of the receiver with all $\ removed or |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2434 |
the receiver, if there are none." |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2435 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2436 |
|in out c| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2437 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2438 |
in := self readStream. |
2733 | 2439 |
out := self species new writeStream. |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2440 |
[in atEnd] whileFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2441 |
c := in next. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2442 |
c == $\ ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2443 |
in atEnd ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2444 |
c := in next. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2445 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2446 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2447 |
out nextPut:c. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2448 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2449 |
^ out contents. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2450 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2451 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2452 |
'*foo' withoutMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2453 |
'\*foo' withoutMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2454 |
'*foo' withoutMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2455 |
'\\*foo' withoutMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2456 |
'foo*' withoutMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2457 |
'foo\*' withoutMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2458 |
'foo\' withoutMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2459 |
'f\*o\*o' withoutMatchEscapes |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2460 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2461 |
|
2733 | 2462 |
"Modified: 30.6.1997 / 13:40:23 / cg" |
608 | 2463 |
! ! |
2464 |
||
2465 |
!CharacterArray methodsFor:'comparing'! |
|
2466 |
||
2467 |
< something |
|
2468 |
"Compare the receiver with the argument and return true if the |
|
1252 | 2469 |
receiver is less than the argument. Otherwise return false. |
2470 |
This comparison is based on the elements ascii code - |
|
2471 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 2472 |
|
2473 |
^ (something > self) |
|
1252 | 2474 |
|
2475 |
"Modified: 22.4.1996 / 15:54:54 / cg" |
|
608 | 2476 |
! |
2477 |
||
2478 |
<= something |
|
2479 |
"Compare the receiver with the argument and return true if the |
|
1252 | 2480 |
receiver is less than or equal to the argument. Otherwise return false. |
2481 |
This comparison is based on the elements ascii code - |
|
2482 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 2483 |
|
2484 |
^ (self > something) not |
|
1252 | 2485 |
|
2486 |
"Modified: 22.4.1996 / 15:54:56 / cg" |
|
608 | 2487 |
! |
2488 |
||
2489 |
= aString |
|
2490 |
"Compare the receiver with the argument and return true if the |
|
2491 |
receiver is equal to the argument. Otherwise return false. |
|
1252 | 2492 |
|
608 | 2493 |
This compare does NOT ignore case differences, |
2494 |
therefore 'foo' = 'Foo' will return false. |
|
2495 |
Since this is incompatible to ST-80 (at least, V2.x) , this may change." |
|
2496 |
||
2497 |
|mySize "{ Class: SmallInteger }" |
|
2498 |
otherSize | |
|
2499 |
||
2500 |
aString species == self species ifFalse:[^ false]. |
|
2501 |
mySize := self size. |
|
2502 |
otherSize := aString size. |
|
2503 |
mySize == otherSize ifFalse:[^ false]. |
|
2504 |
||
2505 |
1 to:mySize do:[:index | |
|
1252 | 2506 |
(self at:index) = (aString at:index) ifFalse:[^ false]. |
608 | 2507 |
]. |
2508 |
^ true |
|
2509 |
||
2510 |
" |
|
2511 |
'foo' = 'Foo' |
|
2512 |
'foo' = 'bar' |
|
2513 |
'foo' = 'foo' |
|
2514 |
" |
|
1252 | 2515 |
|
2516 |
"Modified: 22.4.1996 / 15:53:58 / cg" |
|
608 | 2517 |
! |
2518 |
||
2519 |
> aString |
|
2520 |
"Compare the receiver with the argument and return true if the |
|
2521 |
receiver is greater than the argument. Otherwise return false. |
|
1252 | 2522 |
This comparison is based on the elements ascii code - |
2523 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
|
608 | 2524 |
|
2525 |
|mySize "{ Class: SmallInteger }" |
|
2526 |
otherSize "{ Class: SmallInteger }" |
|
2527 |
n "{ Class: SmallInteger }" |
|
2528 |
c1 c2| |
|
2529 |
||
2530 |
mySize := self size. |
|
2531 |
otherSize := aString size. |
|
2532 |
n := mySize min:otherSize. |
|
2533 |
||
2534 |
1 to:n do:[:index | |
|
1252 | 2535 |
c1 := self at:index. |
2536 |
c2 := aString at:index. |
|
2537 |
c1 > c2 ifTrue:[^ true]. |
|
2538 |
c1 < c2 ifTrue:[^ false]. |
|
608 | 2539 |
]. |
2540 |
^ mySize > otherSize |
|
1252 | 2541 |
|
2542 |
"Modified: 22.4.1996 / 15:55:00 / cg" |
|
608 | 2543 |
! |
2544 |
||
2545 |
>= something |
|
2546 |
"Compare the receiver with the argument and return true if the |
|
2547 |
receiver is greater than or equal to the argument. |
|
1252 | 2548 |
Otherwise return false. |
2549 |
This comparison is based on the elements ascii code - |
|
2550 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 2551 |
|
2552 |
^ (something > self) not |
|
1252 | 2553 |
|
2554 |
"Modified: 22.4.1996 / 15:55:03 / cg" |
|
608 | 2555 |
! |
2556 |
||
2557 |
compareWith:aString |
|
2558 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
2559 |
greater, 0 if equal and -1 if less than the argument. |
|
1252 | 2560 |
This comparison is based on the elements ascii code - |
2561 |
i.e. upper/lowercase & national characters are NOT treated specially. |
|
2562 |
'foo' compareWith: 'Foo' will return 1. |
|
2563 |
while 'foo' sameAs:'Foo' will return true" |
|
608 | 2564 |
|
2565 |
|mySize "{ Class: SmallInteger }" |
|
2566 |
otherSize "{ Class: SmallInteger }" |
|
2567 |
n "{ Class: SmallInteger }" |
|
2568 |
c1 c2| |
|
2569 |
||
2570 |
mySize := self size. |
|
2571 |
otherSize := aString size. |
|
2572 |
n := mySize min:otherSize. |
|
2573 |
||
2574 |
1 to:n do:[:index | |
|
1252 | 2575 |
c1 := self at:index. |
2576 |
c2 := aString at:index. |
|
2577 |
c1 > c2 ifTrue:[^ 1]. |
|
2578 |
c1 < c2 ifTrue:[^ -1]. |
|
608 | 2579 |
]. |
2580 |
mySize > otherSize ifTrue:[^ 1]. |
|
2581 |
mySize < otherSize ifTrue:[^ -1]. |
|
2582 |
^ 0 |
|
1252 | 2583 |
|
2584 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
608 | 2585 |
! |
2586 |
||
2587 |
hash |
|
2588 |
"return an integer useful as a hash-key" |
|
2589 |
||
2590 |
%{ /* NOCONTEXT */ |
|
2591 |
||
2592 |
REGISTER int g, val; |
|
2593 |
REGISTER unsigned char *cp, *cp0; |
|
2594 |
int l; |
|
2595 |
||
1133 | 2596 |
cp = __stringVal(self); |
2597 |
l = __stringSize(self); |
|
2598 |
if (__qClass(self) != @global(String)) { |
|
2599 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
|
608 | 2600 |
|
2601 |
cp += n; |
|
2602 |
l -= n; |
|
2603 |
} |
|
2604 |
||
2605 |
/* |
|
2606 |
* this is the dragon-book algorithm with a funny start |
|
2607 |
* value (to give short strings a number above 8192) |
|
2608 |
*/ |
|
2609 |
val = 12345; |
|
2610 |
for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) { |
|
2611 |
val = (val << 5) + (*cp & 0x1F); |
|
2612 |
if (g = (val & 0x3E000000)) |
|
2613 |
val ^= g >> 25 /* 23 */ /* 25 */; |
|
2614 |
val &= 0x3FFFFFFF; |
|
2615 |
} |
|
2616 |
||
2617 |
if (l) { |
|
2618 |
l |= 1; |
|
2619 |
val = (val * l) & 0x3FFFFFFF; |
|
2620 |
} |
|
2621 |
||
1133 | 2622 |
RETURN ( __MKSMALLINT(val) ); |
608 | 2623 |
%} |
2624 |
! |
|
2625 |
||
2626 |
sameAs:aString |
|
2627 |
"Compare the receiver with the argument like =, but ignore |
|
1252 | 2628 |
case differences. |
2629 |
Return true or false." |
|
608 | 2630 |
|
2631 |
|mySize "{ Class: SmallInteger }" |
|
2632 |
otherSize c1 c2| |
|
2633 |
||
3195
0a1a7a4c6184
oops- sameAs returned self instead of true
Claus Gittinger <cg@exept.de>
parents:
3073
diff
changeset
|
2634 |
self == aString ifTrue:[^ true]. |
2581
d06e3bbfc294
faster #sameAs: if string is identical
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
2635 |
|
608 | 2636 |
mySize := self size. |
2637 |
otherSize := aString size. |
|
2638 |
mySize == otherSize ifFalse:[^ false]. |
|
2639 |
||
2640 |
1 to:mySize do:[:index | |
|
1252 | 2641 |
c1 := self at:index. |
2642 |
c2 := aString at:index. |
|
2643 |
c1 == c2 ifFalse:[ |
|
2644 |
c1 asLowercase = c2 asLowercase ifFalse:[^ false]. |
|
2645 |
] |
|
608 | 2646 |
]. |
2647 |
^ true |
|
2648 |
||
2649 |
" |
|
2650 |
'foo' sameAs: 'Foo' |
|
2651 |
'foo' sameAs: 'bar' |
|
2652 |
'foo' sameAs: 'foo' |
|
2653 |
" |
|
1252 | 2654 |
|
2655 |
"Modified: 22.4.1996 / 15:56:17 / cg" |
|
608 | 2656 |
! |
2657 |
||
2658 |
sameCharacters:aString |
|
2659 |
"count & return the number of characters which are the same |
|
2660 |
(ignoring case) in the receiver and the argument, aString." |
|
2661 |
||
2662 |
|n "{ Class: SmallInteger }" |
|
986 | 2663 |
c1 c2 cnt| |
608 | 2664 |
|
2665 |
n := self size. |
|
2666 |
n := n min:(aString size). |
|
2667 |
||
2668 |
cnt := 0. |
|
2669 |
1 to:n do:[:index | |
|
2670 |
c1 := self at:index. |
|
2671 |
c2 := aString at:index. |
|
2672 |
((c1 == c2) |
|
2673 |
or:[c1 asLowercase = c2 asLowercase]) ifTrue:[ |
|
2674 |
cnt := cnt + 1 |
|
2675 |
] |
|
2676 |
]. |
|
2677 |
^ cnt |
|
2678 |
||
2679 |
" |
|
2680 |
'foobarbaz' sameCharacters: 'foo' |
|
2681 |
'foobarbaz' sameCharacters: 'Foo' |
|
2682 |
'foobarbaz' sameCharacters: 'baz' |
|
2683 |
" |
|
2684 |
! ! |
|
2685 |
||
2686 |
!CharacterArray methodsFor:'converting'! |
|
2687 |
||
2688 |
asArrayOfSubstrings |
|
2689 |
"return an array of substrings from the receiver, interpreting |
|
2690 |
separators (i.e. spaces & newlines) as word-delimiters. |
|
2691 |
This is a compatibility method - the actual work is done in |
|
2692 |
asCollectionOfWords." |
|
2693 |
||
2694 |
^ self asCollectionOfWords asArray |
|
2695 |
||
2696 |
" |
|
2697 |
'1 one two three four 5 five' asArrayOfSubstrings |
|
2698 |
" |
|
2699 |
! |
|
2700 |
||
2701 |
asCollectionOfLines |
|
2702 |
"return a collection containing the lines (separated by cr) |
|
2703 |
of the receiver. If multiple cr's occur in a row, the result will |
|
2704 |
contain empty strings." |
|
2705 |
||
2706 |
^ self asCollectionOfSubstringsSeparatedBy:Character cr |
|
2707 |
||
2708 |
" |
|
2709 |
'1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines |
|
2710 |
'1 one\\\\2 two\3 three' withCRs asCollectionOfLines |
|
2711 |
" |
|
2712 |
! |
|
2713 |
||
2714 |
asCollectionOfSubstringsSeparatedBy:aCharacter |
|
2715 |
"return a collection containing the lines (separated by aCharacter) |
|
2716 |
of the receiver. If aCharacter occurs multiple times in a row, |
|
2717 |
the result will contain empty strings." |
|
2718 |
||
2719 |
|lines myClass |
|
2720 |
numberOfLines "{ Class:SmallInteger }" |
|
2721 |
startIndex "{ Class:SmallInteger }" |
|
2722 |
stopIndex "{ Class:SmallInteger }" | |
|
2723 |
||
2724 |
" |
|
2725 |
count first, to avoid regrowing of the OC |
|
2726 |
" |
|
2727 |
numberOfLines := (self occurrencesOf:aCharacter) + 1. |
|
2728 |
lines := OrderedCollection new:numberOfLines. |
|
2729 |
myClass := self species. |
|
2730 |
||
2731 |
startIndex := 1. |
|
2732 |
1 to:numberOfLines do:[:lineNr | |
|
2733 |
stopIndex := self indexOf:aCharacter startingAt:startIndex. |
|
2734 |
stopIndex == 0 ifTrue:[ |
|
2735 |
stopIndex := self size |
|
2736 |
] ifFalse: [ |
|
2737 |
stopIndex := stopIndex - 1. |
|
2738 |
]. |
|
2739 |
||
2740 |
(stopIndex < startIndex) ifTrue: [ |
|
2741 |
lines add:(myClass new:0) |
|
2742 |
] ifFalse: [ |
|
2743 |
lines add:(self copyFrom:startIndex to:stopIndex) |
|
2744 |
]. |
|
2745 |
startIndex := stopIndex + 2 |
|
2746 |
]. |
|
2747 |
^ lines |
|
2748 |
||
2749 |
" |
|
2750 |
'1 one:2 two:3 three:4 four:5 five' withCRs asCollectionOfSubstringsSeparatedBy:$: |
|
2751 |
'1 one 2 two 3 three 4 four 5 five' withCRs asCollectionOfSubstringsSeparatedBy:Character space |
|
2752 |
" |
|
2753 |
! |
|
2754 |
||
2755 |
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators |
|
2756 |
"return a collection containing the words (separated by any character |
|
2757 |
from aCollectionOfSeparators) of the receiver. |
|
2758 |
This allows breaking up strings using any character as separator." |
|
2759 |
||
2760 |
|words |
|
2761 |
start "{ Class:SmallInteger }" |
|
2762 |
stop "{ Class:SmallInteger }" |
|
2763 |
mySize "{ Class:SmallInteger }"| |
|
2764 |
||
2765 |
words := OrderedCollection new. |
|
2766 |
start := 1. |
|
2767 |
mySize := self size. |
|
2768 |
[start <= mySize] whileTrue:[ |
|
2769 |
"skip multiple separators" |
|
2770 |
[aCollectionOfSeparators includes:(self at:start)] whileTrue:[ |
|
2771 |
start := start + 1 . |
|
2772 |
start > mySize ifTrue:[ |
|
2773 |
^ words |
|
2774 |
]. |
|
2775 |
]. |
|
2776 |
||
2777 |
stop := self indexOfAny:aCollectionOfSeparators startingAt:start. |
|
2778 |
stop == 0 ifTrue:[ |
|
2779 |
words add:(self copyFrom:start to:mySize). |
|
2780 |
^ words |
|
2781 |
]. |
|
2782 |
words add:(self copyFrom:start to:(stop - 1)). |
|
2783 |
start := stop |
|
2784 |
]. |
|
2785 |
^ words |
|
2786 |
||
2787 |
" |
|
2788 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:) |
|
2789 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' |
|
2790 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) |
|
2791 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' |
|
2792 |
'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) |
|
2793 |
" |
|
2794 |
! |
|
2795 |
||
2796 |
asCollectionOfWords |
|
2797 |
"return a collection containing the words (separated by whitespace) |
|
2798 |
of the receiver. Multiple occurences of whitespace characters will |
|
2799 |
be treated like one - i.e. whitespace is skipped." |
|
2800 |
||
2801 |
|words |
|
2802 |
start "{ Class:SmallInteger }" |
|
2803 |
stop "{ Class:SmallInteger }" |
|
2804 |
mySize "{ Class:SmallInteger }"| |
|
2805 |
||
2806 |
words := OrderedCollection new. |
|
2807 |
start := 1. |
|
2808 |
mySize := self size. |
|
2809 |
[start <= mySize] whileTrue:[ |
|
2810 |
start := self indexOfNonSeparatorStartingAt:start. |
|
2811 |
start == 0 ifTrue:[ |
|
2812 |
^ words |
|
2813 |
]. |
|
2814 |
stop := self indexOfSeparatorStartingAt:start. |
|
2815 |
stop == 0 ifTrue:[ |
|
2816 |
words add:(self copyFrom:start to:mySize). |
|
2817 |
^ words |
|
2818 |
]. |
|
2819 |
words add:(self copyFrom:start to:(stop - 1)). |
|
2820 |
start := stop |
|
2821 |
]. |
|
2822 |
^ words |
|
2823 |
||
2824 |
" |
|
2825 |
'hello world isnt this nice' asCollectionOfWords |
|
2826 |
' hello world isnt this nice ' asCollectionOfWords |
|
2827 |
'hello' asCollectionOfWords |
|
2828 |
'' asCollectionOfWords |
|
2829 |
' ' asCollectionOfWords |
|
2830 |
" |
|
2831 |
! |
|
2832 |
||
2833 |
asComposedText |
|
1312 | 2834 |
"ST-80 compatibility |
2835 |
- ST/X does not (as today) support composedTexts." |
|
2836 |
||
608 | 2837 |
^ ComposedText fromString:self |
1312 | 2838 |
|
2839 |
"Modified: 27.4.1996 / 13:30:30 / cg" |
|
608 | 2840 |
! |
2841 |
||
2842 |
asFilename |
|
2843 |
"return a Filename with pathname taken from the receiver" |
|
2844 |
||
1423 | 2845 |
^ Filename named:self string |
2846 |
||
2847 |
"Modified: 20.5.1996 / 09:38:15 / cg" |
|
608 | 2848 |
! |
2849 |
||
3060 | 2850 |
asFixedPoint |
2851 |
"read a fixedPoint number from the receiver. |
|
2852 |
Notice, that errors may occur during the read, so you better |
|
2853 |
setup some signal handler when using this method." |
|
2854 |
||
2855 |
^ FixedPoint readFromString:self |
|
2856 |
||
2857 |
" |
|
2858 |
'0.123' asFixedPoint |
|
2859 |
'12345' asFixedPoint |
|
2860 |
'(1/5)' asFixedPoint |
|
2861 |
'foo' asFixedPoint |
|
2862 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asFixedPoint] |
|
2863 |
" |
|
2864 |
||
2865 |
"Modified: / 25.10.1997 / 15:19:00 / cg" |
|
2866 |
! |
|
2867 |
||
2868 |
asFixedPoint:scale |
|
2869 |
"read a fixedPoint number with scale number of post-decimal digits |
|
2870 |
from the receiver. Scale controls the number of displayed digits, |
|
2871 |
not the number of actually valid digits. |
|
2872 |
Notice, that errors may occur during the read, so you better |
|
2873 |
setup some signal handler when using this method." |
|
2874 |
||
2875 |
^ (FixedPoint readFromString:self) scale:scale |
|
2876 |
||
2877 |
" |
|
2878 |
'0.123' asFixedPoint:2 |
|
2879 |
'123456' asFixedPoint:2 |
|
2880 |
('3.14157' asFixedPoint:1) asFixedPoint:5 |
|
2881 |
" |
|
2882 |
||
2883 |
"Modified: / 25.10.1997 / 15:21:57 / cg" |
|
2884 |
! |
|
2885 |
||
608 | 2886 |
asFloat |
2887 |
"read a float number from the receiver. |
|
2888 |
Notice, that errors may occur during the read, so you better |
|
2889 |
setup some signal handler when using this method." |
|
2890 |
||
2891 |
^ (Number readFromString:self) asFloat |
|
2892 |
||
2893 |
" |
|
2894 |
'0.123' asFloat |
|
2895 |
'12345' asFloat |
|
2896 |
'(1/5)' asFloat |
|
2897 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asFloat] |
|
2898 |
" |
|
2899 |
! |
|
2900 |
||
2901 |
asInteger |
|
2902 |
"read an integer from the receiver. |
|
2903 |
Notice, that errors may occur during the read, so you better |
|
2904 |
setup some signal handler when using this method." |
|
2905 |
||
2906 |
^ Integer readFromString:self |
|
2907 |
||
2908 |
" |
|
2909 |
'12345678901234567890' asInteger |
|
2910 |
'-1234' asInteger |
|
2911 |
'0.123' asInteger <- reader stops at ., returning 0 here |
|
2912 |
'0.123' asNumber <- returns what you expect |
|
2913 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asInteger] |
|
2914 |
" |
|
2915 |
! |
|
2916 |
||
2917 |
asLowercase |
|
2918 |
"return a copy of myself in lowercase letters" |
|
2919 |
||
2920 |
|newStr |
|
2921 |
mySize "{ Class: SmallInteger }" | |
|
2922 |
||
2923 |
mySize := self size. |
|
2924 |
newStr := self species new:mySize. |
|
2925 |
1 to:mySize do:[:i | |
|
2926 |
newStr at:i put:(self at:i) asLowercase |
|
2927 |
]. |
|
2928 |
^ newStr |
|
2929 |
||
2930 |
" |
|
2931 |
'HelloWorld' asLowercase |
|
2932 |
'HelloWorld' asLowercaseFirst |
|
2933 |
" |
|
2934 |
! |
|
2935 |
||
2936 |
asLowercaseFirst |
|
2937 |
"return a copy of myself where the first character is |
|
2938 |
converted to lowercase." |
|
2939 |
||
2940 |
|newString sz| |
|
2941 |
||
2942 |
sz := self size. |
|
2943 |
newString := self copyFrom:1 to:sz. |
|
2944 |
sz > 0 ifTrue:[ |
|
2945 |
newString at:1 put:(newString at:1) asLowercase |
|
2946 |
]. |
|
2947 |
^ newString |
|
2948 |
||
2949 |
" |
|
2950 |
'HelloWorld' asLowercase |
|
2951 |
'HelloWorld' asLowercaseFirst |
|
2952 |
" |
|
2953 |
! |
|
2954 |
||
2955 |
asNumber |
|
2956 |
"read a number from the receiver. |
|
2957 |
Notice, that (in contrast to ST-80) errors may occur during the read, |
|
2958 |
so you better setup some signal handler when using this method. |
|
2959 |
This may change if ANSI specifies it." |
|
2960 |
||
2961 |
"/ ST-80 behavior: |
|
2962 |
"/ ^ Number readFromString:self onError:0 |
|
2963 |
||
2964 |
^ Number readFromString:self |
|
2965 |
||
2966 |
" |
|
2967 |
'123' asNumber |
|
2968 |
'123.567' asNumber |
|
2969 |
'(5/6)' asNumber |
|
2970 |
'foo' asNumber |
|
2971 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] |
|
2972 |
" |
|
2973 |
! |
|
2974 |
||
2975 |
asNumberFromFormatString:ignored |
|
2976 |
"read a number from the receiver, ignoring any nonDigit characters. |
|
2977 |
This is typically used to convert from strings which include |
|
2978 |
dollar-signs or millenium digits. However, this method also ignores |
|
2979 |
the decimal point (if any) and therefore should be used with care." |
|
2980 |
||
2981 |
|tempString| |
|
2982 |
||
2983 |
tempString := self collect:[:char | char isDigit]. |
|
2984 |
^ Number readFromString:tempString onError:0 |
|
2985 |
||
2986 |
" |
|
2987 |
'USD 123' asNumberFromFormatString:'foo' |
|
2988 |
'DM 123' asNumberFromFormatString:'foo' |
|
2989 |
'123' asNumberFromFormatString:'foo' |
|
2990 |
'123.567' asNumberFromFormatString:'foo' |
|
2991 |
'(5/6)' asNumberFromFormatString:'foo' |
|
2992 |
'foo' asNumberFromFormatString:'foo' |
|
2993 |
" |
|
2994 |
! |
|
2995 |
||
2996 |
asSingleByteString |
|
2997 |
"return the receiver converted to a 'normal' string" |
|
2998 |
||
2999 |
^ String fromString:self |
|
3000 |
! |
|
3001 |
||
2732 | 3002 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
3003 |
"return the receiver converted to a 'normal' string, |
|
3004 |
with invalid characters replaced by replacementCharacter. |
|
3005 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
3006 |
and replace characters above code-255 with some replacement." |
|
3007 |
||
3008 |
|newString| |
|
3009 |
||
3010 |
newString := String new:(self size). |
|
3011 |
1 to:self size do:[:idx | |
|
3012 |
|char| |
|
3013 |
||
3014 |
char := self at:idx. |
|
3015 |
char asciiValue <= 16rFF ifTrue:[ |
|
3016 |
newString at:idx put:char |
|
3017 |
] ifFalse:[ |
|
3018 |
newString at:idx put:replacementCharacter |
|
3019 |
]. |
|
3020 |
]. |
|
3021 |
^ newString |
|
3022 |
||
3023 |
"Created: 30.6.1997 / 13:02:14 / cg" |
|
3024 |
! |
|
3025 |
||
608 | 3026 |
asString |
3027 |
"return myself - I am a string" |
|
3028 |
||
3029 |
^ self |
|
3030 |
! |
|
3031 |
||
3032 |
asStringCollection |
|
3033 |
"return a collection of lines from myself." |
|
3034 |
||
1393 | 3035 |
^ StringCollection from:self "string" |
3036 |
||
3037 |
"Modified: 13.5.1996 / 20:36:59 / cg" |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3038 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3039 |
|
1434 | 3040 |
asSymbol |
3041 |
"return a unique symbol with the name taken from my characters. |
|
3042 |
The receiver must be a singleByte-String; twoByteSymbols are |
|
3043 |
(currently) not allowed." |
|
3044 |
||
3045 |
^ self string asSymbol |
|
3046 |
||
3047 |
"Created: 22.5.1996 / 15:56:11 / cg" |
|
3048 |
! |
|
3049 |
||
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3050 |
asSymbolIfInterned |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3051 |
"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
|
3052 |
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
|
3053 |
symbol and is the same as |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3054 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3055 |
but slightly faster, since the symbol lookup operation is only |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3056 |
performed once. |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3057 |
The receiver must be a singleByte-String; twoByteSymbols are |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3058 |
(currently) not allowed." |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3059 |
|
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3060 |
^ self string asSymbolIfInterned |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3061 |
|
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3062 |
"Created: 22.5.1996 / 16:37:04 / cg" |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3063 |
! |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3064 |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3065 |
asText |
1381 | 3066 |
"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
|
3067 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3068 |
^ Text fromString:self |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3069 |
|
1381 | 3070 |
"Created: 12.5.1996 / 10:41:14 / cg" |
608 | 3071 |
! |
3072 |
||
3073 |
asTwoByteString |
|
3074 |
"return the receiver converted to a two-byte string" |
|
3075 |
||
3076 |
^ TwoByteString fromString:self |
|
3077 |
! |
|
3078 |
||
3079 |
asUppercase |
|
3080 |
"return a copy of myself in uppercase letters" |
|
3081 |
||
3082 |
|newStr |
|
3083 |
mySize "{ Class: SmallInteger }" | |
|
3084 |
||
3085 |
mySize := self size. |
|
3086 |
newStr := self species new:mySize. |
|
3087 |
1 to:mySize do:[:i | |
|
3088 |
newStr at:i put:(self at:i) asUppercase |
|
3089 |
]. |
|
3090 |
^ newStr |
|
3091 |
||
3092 |
" |
|
3093 |
'helloWorld' asUppercase |
|
3094 |
'helloWorld' asUppercaseFirst |
|
3095 |
" |
|
3096 |
! |
|
3097 |
||
3098 |
asUppercaseFirst |
|
3099 |
"return a copy of myself where the first character is |
|
3100 |
converted to uppercase." |
|
3101 |
||
3102 |
|newString sz| |
|
3103 |
||
3104 |
sz := self size. |
|
3105 |
newString := self copyFrom:1 to:sz. |
|
3106 |
sz > 0 ifTrue:[ |
|
3107 |
newString at:1 put:(newString at:1) asUppercase |
|
3108 |
]. |
|
3109 |
^ newString |
|
3110 |
||
3111 |
" |
|
3112 |
'helloWorld' asUppercase |
|
3113 |
'helloWorld' asUppercaseFirst |
|
3114 |
'HelloWorld' asUppercaseFirst |
|
3115 |
" |
|
3116 |
! |
|
3117 |
||
3118 |
string |
|
1312 | 3119 |
"return the receiver - for ST-80 compatibility" |
3120 |
||
608 | 3121 |
^ self |
1312 | 3122 |
|
3123 |
"Modified: 27.4.1996 / 13:29:30 / cg" |
|
608 | 3124 |
! |
3125 |
||
3126 |
tokensBasedOn:aCharacter |
|
3127 |
"this is an ST-80 alias for the ST/X method |
|
3128 |
asCollectionOfSubstringsSeparatedBy:" |
|
3129 |
||
3130 |
^ self asCollectionOfSubstringsSeparatedBy:aCharacter |
|
3131 |
||
3132 |
" |
|
3133 |
'hello:world:isnt:this nice' tokensBasedOn:$: |
|
3134 |
'foo,bar,baz' tokensBasedOn:$, |
|
3135 |
'/etc/passwd' asFilename readStream nextLine tokensBasedOn:$: |
|
3136 |
" |
|
3137 |
! ! |
|
3138 |
||
3139 |
!CharacterArray methodsFor:'copying'! |
|
3140 |
||
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3141 |
, aStringOrCharacter |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3142 |
"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
|
3143 |
This is nonStandard, but convenient" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3144 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3145 |
|myWidth otherWidth| |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3146 |
|
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3147 |
aStringOrCharacter isCharacter ifTrue:[ |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3148 |
^ self , aStringOrCharacter asString |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3149 |
]. |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3150 |
aStringOrCharacter isText ifTrue:[ |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3151 |
^ aStringOrCharacter concatenateFromString:self |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3152 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3153 |
aStringOrCharacter isString ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3154 |
(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
|
3155 |
otherWidth > myWidth ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3156 |
^ (aStringOrCharacter species fromString:self) , aStringOrCharacter |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3157 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3158 |
^ self , (self species fromString:aStringOrCharacter) |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3159 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3160 |
]. |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3161 |
^ super , aStringOrCharacter |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3162 |
|
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3163 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3164 |
'hello' , $1 |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3165 |
'hello' , '1' |
1411 | 3166 |
'hello' , (' world' asText allBold) |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3167 |
'hello' , (JISEncodedString fromString:' world') |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3168 |
(JISEncodedString fromString:'hello') , ' world' |
1411 | 3169 |
|
1422 | 3170 |
Transcript showCR: |
1411 | 3171 |
(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
|
3172 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3173 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3174 |
"Modified: 28.6.1997 / 00:13:17 / cg" |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3175 |
! |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
3176 |
|
608 | 3177 |
concatenate:string1 and:string2 |
3178 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
3179 |
This is equivalent to self , string1 , string2 |
|
3180 |
- generated by compiler when such a construct is detected and the receiver |
|
3181 |
is known to be a string." |
|
3182 |
||
3183 |
^ self , string1 , string2 |
|
3184 |
! |
|
3185 |
||
3186 |
concatenate:string1 and:string2 and:string3 |
|
3187 |
"return the concatenation of myself and the string arguments. |
|
3188 |
This is equivalent to self , string1 , string2 , string3 |
|
3189 |
- generated by compiler when such a construct is detected and the receiver |
|
3190 |
is known to be a string." |
|
3191 |
||
3192 |
^ self , string1 , string2 , string3 |
|
3193 |
! ! |
|
3194 |
||
3195 |
!CharacterArray methodsFor:'displaying'! |
|
3196 |
||
2762 | 3197 |
displayOn:aGC x:x y:y from:start to:stop |
3198 |
"display the receiver on a GC" |
|
3199 |
||
3200 |
"q&d hack" |
|
3201 |
||
3202 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:false |
|
3203 |
||
3204 |
"Modified: 12.5.1996 / 12:49:33 / cg" |
|
3205 |
! |
|
3206 |
||
3207 |
displayOn:aGc x:x y:y opaque:opq |
|
3208 |
"display the receiver in a graphicsContext - this method allows |
|
3209 |
strings to be used like DisplayObjects." |
|
3210 |
||
3211 |
|s| |
|
3212 |
||
3213 |
s := self string. |
|
3214 |
opq ifTrue:[ |
|
3215 |
aGc displayOpaqueString:s x:x y:y. |
|
3216 |
] ifFalse:[ |
|
3217 |
aGc displayString:s x:x y:y. |
|
3218 |
]. |
|
1381 | 3219 |
|
3220 |
"Modified: 11.5.1996 / 14:42:48 / cg" |
|
3221 |
! |
|
3222 |
||
2762 | 3223 |
displayOpaqueOn:aGC x:x y:y from:start to:stop |
3224 |
"display the receiver on a GC" |
|
3225 |
||
3226 |
"q&d hack" |
|
3227 |
||
3228 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:true |
|
3229 |
||
3230 |
"Created: 12.5.1996 / 12:29:37 / cg" |
|
3231 |
"Modified: 12.5.1996 / 12:49:19 / cg" |
|
608 | 3232 |
! ! |
3233 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3234 |
!CharacterArray methodsFor:'emphasis'! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3235 |
|
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3236 |
emphasis |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3237 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3238 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3239 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3240 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3241 |
^ RunArray new:self size withAll:nil |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3242 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3243 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3244 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3245 |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3246 |
emphasisAt:characterIndex |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3247 |
"return the emphasis at some index. |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3248 |
Since characterArrays do not hold any emphasis information, |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3249 |
nil (no emphasis) is returned here." |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3250 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3251 |
^ nil |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3252 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3253 |
"Created: 11.5.1996 / 14:13:27 / cg" |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3254 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3255 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3256 |
emphasisCollection |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3257 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3258 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3259 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3260 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3261 |
^ RunArray new:(self size) |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3262 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3263 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3264 |
"Modified: 14.5.1996 / 15:02:29 / cg" |
3404 | 3265 |
! |
3266 |
||
3267 |
emphasizeAllWith:emphasis |
|
3268 |
^ self asText emphasizeAllWith:emphasis |
|
3269 |
||
3270 |
" |
|
3271 |
Transcript showCR:('hello' emphasizeAllWith:#bold) |
|
3272 |
" |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3273 |
! ! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3274 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3275 |
!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
|
3276 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3277 |
decodeFrom:encodingSymbol |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3278 |
"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
|
3279 |
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
|
3280 |
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
|
3281 |
(and those are untested/incomplete): |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3282 |
#euc |
997
6c7f1815ed02
more encoding & decoding support
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
3283 |
#jis7 |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
3284 |
#sjis |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3285 |
#mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3286 |
#msdos |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3287 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3288 |
|
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3289 |
|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
|
3290 |
|
2736 | 3291 |
encodingSymbol == #'x-jis7' ifTrue:[ |
2733 | 3292 |
^ JISEncodedString decodeFromJIS7:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3293 |
]. |
2758 | 3294 |
encodingSymbol == #'x-iso2022-jp' ifTrue:[ |
3295 |
^ JISEncodedString decodeFromJIS7:self |
|
3296 |
]. |
|
2759 | 3297 |
encodingSymbol == #'iso2022-jp' ifTrue:[ |
3298 |
^ JISEncodedString decodeFromJIS7:self |
|
3299 |
]. |
|
2736 | 3300 |
encodingSymbol == #'x-sjis' ifTrue:[ |
2733 | 3301 |
^ JISEncodedString decodeFromSJIS:self |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
3302 |
]. |
2736 | 3303 |
encodingSymbol == #'x-shift-jis' ifTrue:[ |
3304 |
^ JISEncodedString decodeFromSJIS:self |
|
3305 |
]. |
|
3306 |
encodingSymbol == #'x-euc-jp' ifTrue:[ |
|
2733 | 3307 |
^ 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
|
3308 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3309 |
encodingSymbol == #big5 ifTrue:[ |
2733 | 3310 |
^ 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
|
3311 |
]. |
2736 | 3312 |
encodingSymbol == #gb2312 ifTrue:[ |
2733 | 3313 |
^ GBEncodedString decodeFromGB:self |
3314 |
]. |
|
2736 | 3315 |
encodingSymbol == #'x-euc-gb' ifTrue:[ |
3316 |
^ GBEncodedString decodeFromEUC:self |
|
3317 |
]. |
|
3318 |
encodingSymbol == #'x-euc-kr' ifTrue:[ |
|
3319 |
^ KSCEncodedString decodeFromEUC:self |
|
2733 | 3320 |
]. |
3321 |
||
3322 |
encodingSymbol == #ucs2 ifTrue:[ |
|
3323 |
^ UnicodeString decodeFromUCS2:self |
|
3324 |
]. |
|
3325 |
encodingSymbol == #ucs4 ifTrue:[ |
|
3326 |
^ UnicodeString decodeFromUCS4:self |
|
3327 |
]. |
|
3328 |
encodingSymbol == #utf7 ifTrue:[ |
|
3329 |
^ UnicodeString decodeFromUTF7:self |
|
3330 |
]. |
|
3331 |
encodingSymbol == #utf8 ifTrue:[ |
|
3332 |
^ UnicodeString decodeFromUTF8:self |
|
3333 |
]. |
|
3334 |
encodingSymbol == #utf16 ifTrue:[ |
|
3335 |
^ 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
|
3336 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3337 |
|
2736 | 3338 |
|
3339 |
"/ soon obsolete ... |
|
3340 |
encodingSymbol == #jis7 ifTrue:[ |
|
3341 |
^ JISEncodedString decodeFromJIS7:self |
|
3342 |
]. |
|
3343 |
encodingSymbol == #sjis ifTrue:[ |
|
3344 |
^ JISEncodedString decodeFromSJIS:self |
|
3345 |
]. |
|
3346 |
encodingSymbol == #euc ifTrue:[ |
|
3347 |
^ JISEncodedString decodeFromEUC:self |
|
3348 |
]. |
|
3349 |
||
3350 |
encodingSymbol == #gb ifTrue:[ |
|
3351 |
^ GBEncodedString decodeFromGB:self |
|
3352 |
]. |
|
3353 |
encodingSymbol == #ksc ifTrue:[ |
|
3354 |
^ KSCEncodedString decodeFromKSC:self |
|
3355 |
]. |
|
3356 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3357 |
table := self class decoderTableFor:encodingSymbol. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3358 |
table isNil ifTrue:[^ self]. |
2736 | 3359 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3360 |
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
|
3361 |
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
|
3362 |
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
|
3363 |
^ newString |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3364 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3365 |
"Created: 22.2.1996 / 15:06:49 / cg" |
2759 | 3366 |
"Modified: 16.7.1997 / 13:45:33 / cg" |
2733 | 3367 |
! |
3368 |
||
3369 |
encodeForDisplayInto:encodingSymbol |
|
3370 |
"given the receiver in internal ST/X encoding, |
|
3371 |
convert it into the format as described by encodingSymbol |
|
3372 |
for display. |
|
3373 |
The receiver may contain roman characters in 0..255, which |
|
3374 |
are translated according to the encodings roman translation. |
|
3375 |
For example: in JIS, roman $a is found at 16r2361. |
|
3376 |
" |
|
3377 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3378 |
|newString table| |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3379 |
|
2733 | 3380 |
encodingSymbol isNil ifTrue:[^ self]. |
3381 |
||
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3382 |
"/ notice: this method may not be moved to |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3383 |
"/ concrete TwoByte classes; it is also invoked |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3384 |
"/ to convert singleByte strings ... |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3385 |
|
2733 | 3386 |
(encodingSymbol startsWith:'jis') ifTrue:[ |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3387 |
newString := JISEncodedString encodeRomans:self. |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3388 |
|
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3389 |
"/ jisx0208.1983 has no half-width katakana |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3390 |
(encodingSymbol startsWith:'jisx0208.1983') ifTrue:[ |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3391 |
newString := JISEncodedString encodeHalfWidthKatakana:newString. |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3392 |
]. |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3393 |
^ newString |
2733 | 3394 |
]. |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3395 |
|
2733 | 3396 |
(encodingSymbol startsWith:'big5') ifTrue:[ |
3397 |
^ BIG5EncodedString encodeRomans:self |
|
3398 |
]. |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3399 |
|
2733 | 3400 |
(encodingSymbol startsWith:'gb') ifTrue:[ |
3401 |
^ GBEncodedString encodeRomans:self |
|
3402 |
]. |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3403 |
|
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3404 |
(encodingSymbol startsWith:'ksc') ifTrue:[ |
2733 | 3405 |
^ KSCEncodedString encodeRomans:self |
3406 |
]. |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3407 |
|
2733 | 3408 |
(encodingSymbol startsWith:'uni') ifTrue:[ |
3409 |
^ UnicodeString encodeRomans:self |
|
3410 |
]. |
|
3411 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3412 |
table := self class encoderTableFor:encodingSymbol. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3413 |
table isNil ifTrue:[^ self]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3414 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3415 |
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
|
3416 |
newString replaceFrom:self translateBy:table. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3417 |
newString = self ifTrue:[^ self]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3418 |
^ newString |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3419 |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
3420 |
"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
|
3421 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3422 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3423 |
encodeInto:encodingSymbol |
2733 | 3424 |
"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
|
3425 |
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
|
3426 |
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
|
3427 |
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
|
3428 |
(and those are untested/incomplete): |
2736 | 3429 |
#x-euc-jp |
2760 | 3430 |
#x-jis7 (== iso2022-jp) |
2736 | 3431 |
#x-sjis |
3432 |
#x-shift-jis |
|
2733 | 3433 |
#big5 |
3434 |
#gb |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3435 |
#mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3436 |
#msdos |
2733 | 3437 |
#next |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3438 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3439 |
|
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3440 |
|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
|
3441 |
|
1204 | 3442 |
"/ 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
|
3443 |
|
1028 | 3444 |
encodingSymbol isNil ifTrue:[^ self]. |
3445 |
||
2736 | 3446 |
encodingSymbol == #'x-jis7' ifTrue:[ |
2733 | 3447 |
^ JISEncodedString encodeIntoJIS7:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3448 |
]. |
2759 | 3449 |
encodingSymbol == #'x-iso2022-jp' ifTrue:[ |
3450 |
^ JISEncodedString encodeIntoJIS7:self |
|
3451 |
]. |
|
3452 |
encodingSymbol == #'iso2022-jp' ifTrue:[ |
|
3453 |
^ JISEncodedString encodeIntoJIS7:self |
|
3454 |
]. |
|
2736 | 3455 |
encodingSymbol == #'x-sjis' ifTrue:[ |
2733 | 3456 |
^ JISEncodedString encodeIntoSJIS:self |
1013
0e54ddc990cb
more 16bit & encoding support
Claus Gittinger <cg@exept.de>
parents:
1012
diff
changeset
|
3457 |
]. |
2736 | 3458 |
encodingSymbol == #'x-shift-jis' ifTrue:[ |
3459 |
^ JISEncodedString encodeIntoSJIS:self |
|
3460 |
]. |
|
3461 |
encodingSymbol == #'x-euc-jp' ifTrue:[ |
|
2733 | 3462 |
^ 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
|
3463 |
]. |
2733 | 3464 |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3465 |
encodingSymbol == #big5 ifTrue:[ |
2733 | 3466 |
^ BIG5EncodedString encodeIntoBIG5:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3467 |
]. |
2736 | 3468 |
|
3469 |
encodingSymbol == #gb2312 ifTrue:[ |
|
2733 | 3470 |
^ GBEncodedString encodeIntoGB:self |
3471 |
]. |
|
2736 | 3472 |
encodingSymbol == #'x-euc-gb' ifTrue:[ |
3473 |
^ GBEncodedString encodeIntoGB:self |
|
3474 |
]. |
|
3475 |
||
3476 |
encodingSymbol == #'x-euc-kr' ifTrue:[ |
|
2733 | 3477 |
^ KSCEncodedString encodeIntoKSC:self |
3478 |
]. |
|
3479 |
||
3480 |
encodingSymbol == #ucs2 ifTrue:[ |
|
3481 |
^ 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
|
3482 |
]. |
2733 | 3483 |
encodingSymbol == #ucs4 ifTrue:[ |
3484 |
^ UnicodeString encodeIntoUCS4:self |
|
3485 |
]. |
|
3486 |
encodingSymbol == #utf7 ifTrue:[ |
|
3487 |
^ UnicodeString encodeIntoUTF7:self |
|
3488 |
]. |
|
3489 |
encodingSymbol == #utf8 ifTrue:[ |
|
3490 |
^ UnicodeString encodeIntoUTF8:self |
|
3491 |
]. |
|
3492 |
encodingSymbol == #utf16 ifTrue:[ |
|
3493 |
^ 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
|
3494 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3495 |
|
2736 | 3496 |
|
3497 |
"/ to be obsoleted ... |
|
3498 |
encodingSymbol == #jis7 ifTrue:[ |
|
3499 |
^ JISEncodedString encodeIntoJIS7:self |
|
3500 |
]. |
|
3501 |
encodingSymbol == #sjis ifTrue:[ |
|
3502 |
^ JISEncodedString encodeIntoSJIS:self |
|
3503 |
]. |
|
3504 |
encodingSymbol == #euc ifTrue:[ |
|
3505 |
^ JISEncodedString encodeIntoEUC:self |
|
3506 |
]. |
|
3507 |
||
3508 |
encodingSymbol == #gb ifTrue:[ |
|
3509 |
^ GBEncodedString encodeIntoGB:self |
|
3510 |
]. |
|
3511 |
encodingSymbol == #ksc ifTrue:[ |
|
3512 |
^ KSCEncodedString encodeIntoKSC:self |
|
3513 |
]. |
|
3514 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3515 |
table := self class encoderTableFor:encodingSymbol. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3516 |
table isNil ifTrue:[^ self]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3517 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3518 |
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
|
3519 |
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
|
3520 |
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
|
3521 |
^ newString |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3522 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3523 |
"Created: 22.2.1996 / 15:07:31 / cg" |
2760 | 3524 |
"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
|
3525 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3526 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3527 |
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
|
3528 |
"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
|
3529 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3530 |
^ 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
|
3531 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3532 |
"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
|
3533 |
"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
|
3534 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3535 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3536 |
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
|
3537 |
"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
|
3538 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3539 |
^ 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
|
3540 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3541 |
"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
|
3542 |
"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
|
3543 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3544 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3545 |
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
|
3546 |
"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
|
3547 |
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
|
3548 |
|
2520
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3549 |
|mySize "{ Class: SmallInteger }" |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3550 |
maxCode "{ Class: SmallInteger }" |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3551 |
char |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3552 |
oldCode "{ Class: SmallInteger }" |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3553 |
newCode| |
1023 | 3554 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3555 |
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
|
3556 |
encodingTable isNil ifTrue:[^ self]. |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
3557 |
|
2520
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3558 |
maxCode := encodingTable size. |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3559 |
mySize := self size. |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3560 |
|
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3561 |
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
|
3562 |
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
|
3563 |
oldCode := char asciiValue. |
2520
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
3564 |
oldCode >= maxCode ifFalse:[ |
1023 | 3565 |
newCode := encodingTable at:(oldCode + 1). |
3566 |
newCode ~~ oldCode ifTrue:[ |
|
3567 |
self at:index put:(Character value:newCode) |
|
3568 |
] |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3569 |
] |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3570 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3571 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3572 |
"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
|
3573 |
"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
|
3574 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
3575 |
|
608 | 3576 |
!CharacterArray methodsFor:'padded copying'! |
3577 |
||
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3578 |
centerPaddedTo:newSize |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3579 |
"return a new string consisting of the receivers characters, |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3580 |
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
|
3581 |
the resulting string. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3582 |
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
|
3583 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3584 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3585 |
^ self centerPaddedTo:newSize with:(Character space) |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3586 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3587 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3588 |
'foo' centerPaddedTo:10 |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3589 |
123 printString centerPaddedTo:10 |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3590 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3591 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3592 |
"Created: 25.11.1995 / 10:53:57 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3593 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3594 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3595 |
centerPaddedTo:size with:padCharacter |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3596 |
"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
|
3597 |
centered (i.e. padded on both sides). |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3598 |
Characters are filled with padCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3599 |
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
|
3600 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3601 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3602 |
|len s| |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3603 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3604 |
len := self size. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3605 |
(len < size) ifTrue:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3606 |
s := self species new:size withAll:padCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3607 |
s replaceFrom:(size - len) // 2 + 1 with:self. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3608 |
^ s |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3609 |
] |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3610 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3611 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3612 |
'foo' centerPaddedTo:11 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3613 |
'fooBar' centerPaddedTo:5 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3614 |
123 printString centerPaddedTo:10 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3615 |
(' ' , 123 printString) centerPaddedTo:10 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3616 |
(Float pi printString) centerPaddedTo:15 with:(Character space) |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3617 |
(Float pi printString) centerPaddedTo:15 with:$- |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3618 |
(' ' , Float pi class name) centerPaddedTo:15 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3619 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3620 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3621 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3622 |
decimalPaddedTo:size and:afterPeriod at:decimalCharacter |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3623 |
"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
|
3624 |
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
|
3625 |
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
|
3626 |
to be padded). |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3627 |
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
|
3628 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3629 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3630 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3631 |
^ self |
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3632 |
decimalPaddedTo:size |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3633 |
and:afterPeriod |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3634 |
at:decimalCharacter |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3635 |
withLeft:(Character space) |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3636 |
right:$0 |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3637 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3638 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3639 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123 ' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3640 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3641 |
'123.' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3642 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.100' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3643 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.1 ' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3644 |
'123.123' decimalPaddedTo:10 and:3 at:$. -> ' 123.123' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3645 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3646 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3647 |
"Created: 23.12.1995 / 13:11:52 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3648 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3649 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3650 |
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
|
3651 |
"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
|
3652 |
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
|
3653 |
of the period. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3654 |
Characters on the left are filled with leftPadChar. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3655 |
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
|
3656 |
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
|
3657 |
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
|
3658 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3659 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3660 |
|
986 | 3661 |
|s idx n| |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3662 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3663 |
idx := self indexOf:decimalCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3664 |
idx == 0 ifTrue:[ |
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3665 |
"/ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3666 |
"/ no decimal point found; adjust string to the left of the period column |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3667 |
"/ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3668 |
rightPadChar isNil ifTrue:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3669 |
s := self , (self species new:afterPeriod + 1 withAll:leftPadChar) |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3670 |
] ifFalse:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3671 |
s:= self , decimalCharacter asString , (self species new:afterPeriod withAll:rightPadChar). |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3672 |
]. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3673 |
] ifFalse:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3674 |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3675 |
"/ the number of after-decimalPoint characters |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3676 |
n := self size - idx. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3677 |
rightPadChar isNil ifTrue:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3678 |
s := self , (self species new:afterPeriod - n withAll:leftPadChar). |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3679 |
] ifFalse:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3680 |
s := self , (self species new:afterPeriod - n withAll:rightPadChar). |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3681 |
]. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3682 |
]. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3683 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3684 |
^ s leftPaddedTo:size with:leftPadChar |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3685 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3686 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3687 |
'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
|
3688 |
'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
|
3689 |
'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
|
3690 |
'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
|
3691 |
'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
|
3692 |
'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
|
3693 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3694 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3695 |
"Modified: 23.12.1995 / 13:08:18 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3696 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3697 |
|
608 | 3698 |
leftPaddedTo:size |
3699 |
"return a new string of length size, which contains the receiver |
|
3700 |
right-adjusted (i.e. padded on the left). |
|
3701 |
Characters on the left are filled with spaces. |
|
3702 |
If the receivers size is equal or greater than the length argument, |
|
3703 |
the original receiver is returned unchanged." |
|
3704 |
||
3705 |
^ self leftPaddedTo:size with:(Character space) |
|
3706 |
||
3707 |
" |
|
3708 |
'foo' leftPaddedTo:10 |
|
3709 |
'fooBar' leftPaddedTo:5 |
|
3710 |
123 printString leftPaddedTo:10 |
|
3711 |
" |
|
3712 |
! |
|
3713 |
||
3714 |
leftPaddedTo:size with:padCharacter |
|
3715 |
"return a new string of length size, which contains the receiver |
|
3716 |
right-adjusted (i.e. padded on the left). |
|
3717 |
Characters on the left are filled with padCharacter. |
|
3718 |
If the receivers size is equal or greater than the length argument, |
|
3719 |
the original receiver is returned unchanged." |
|
3720 |
||
3721 |
|len s| |
|
3722 |
||
3723 |
len := self size. |
|
3724 |
(len < size) ifTrue:[ |
|
3725 |
s := self species new:size withAll:padCharacter. |
|
3726 |
s replaceFrom:(size - len + 1) with:self. |
|
3727 |
^ s |
|
3728 |
] |
|
3729 |
||
3730 |
" |
|
3731 |
'foo' leftPaddedTo:10 with:$. |
|
3732 |
'fooBar' leftPaddedTo:5 with:$. |
|
3733 |
123 printString leftPaddedTo:10 with:$. |
|
3734 |
(' ' , 123 printString) leftPaddedTo:10 with:$. |
|
3735 |
(Float pi printString) leftPaddedTo:15 with:(Character space) |
|
3736 |
(Float pi printString) leftPaddedTo:15 with:$- |
|
3737 |
(' ' , Float pi class name) leftPaddedTo:15 with:$. |
|
3738 |
" |
|
3739 |
! |
|
3740 |
||
3741 |
paddedTo:newSize |
|
3742 |
"return a new string consisting of the receivers characters, |
|
3743 |
plus spaces up to length. |
|
3744 |
If the receivers size is equal or greater than the length argument, |
|
3745 |
the original receiver is returned unchanged." |
|
3746 |
||
3747 |
^ self paddedTo:newSize with:(Character space) |
|
3748 |
||
3749 |
" |
|
3750 |
'foo' paddedTo:10 |
|
3751 |
123 printString paddedTo:10 |
|
3752 |
" |
|
3753 |
! |
|
3754 |
||
3755 |
paddedTo:newSize with:padCharacter |
|
3756 |
"return a new string consisting of the receivers characters, |
|
3757 |
plus pad characters up to length. |
|
3758 |
If the receivers size is equal or greater than the length argument, |
|
3759 |
the original receiver is returned unchanged." |
|
3760 |
||
3761 |
|s len| |
|
3762 |
||
3763 |
len := self size. |
|
3764 |
len < newSize ifTrue:[ |
|
3765 |
s := self species new:newSize withAll:padCharacter. |
|
3766 |
s replaceFrom:1 to:len with:self. |
|
3767 |
^ s |
|
3768 |
] |
|
3769 |
||
3770 |
" |
|
3771 |
'foo' paddedTo:10 with:$. |
|
3772 |
123 printString paddedTo:10 with:$* |
|
3773 |
(Float pi printString) paddedTo:15 with:(Character space) |
|
3774 |
(Float pi printString) paddedTo:15 with:$- |
|
3775 |
(Float pi class name , ' ') paddedTo:15 with:$. |
|
3776 |
" |
|
64 | 3777 |
! ! |
3778 |
||
328 | 3779 |
!CharacterArray methodsFor:'pattern matching'! |
3780 |
||
2551 | 3781 |
compoundMatch:aString |
3253 | 3782 |
"like match, but the receiver may be a compound match pattern, |
2551 | 3783 |
consisting of multiple simple patterns, separated by semicolons. |
3784 |
This is usable with fileName pattern fields." |
|
3785 |
||
3786 |
|matchers| |
|
3787 |
||
3788 |
matchers := self asCollectionOfSubstringsSeparatedBy:$;. |
|
3789 |
matchers do:[:aPattern | |
|
3790 |
(aPattern match:aString) ifTrue:[^ true]. |
|
3791 |
]. |
|
3792 |
^ false. |
|
3793 |
||
3794 |
" |
|
3795 |
'f*' match:'foo' |
|
3796 |
'b*' match:'foo' |
|
3797 |
'f*;b*' match:'foo' |
|
3798 |
'f*;b*' match:'bar' |
|
3799 |
'f*;b*' compoundMatch:'foo' |
|
3800 |
'f*;b*' compoundMatch:'bar' |
|
3801 |
" |
|
3802 |
||
3253 | 3803 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
3804 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
2551 | 3805 |
! |
3806 |
||
328 | 3807 |
findMatchString:matchString |
368 | 3808 |
"like findString/indexOfSubCollection, but allowing match patterns. |
328 | 3809 |
find matchstring; if found, return the index; |
3810 |
if not found, return 0." |
|
3811 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3812 |
^ self findMatchString:matchString startingAt:1 ignoreCase:false ifAbsent:0 |
328 | 3813 |
! |
3814 |
||
3815 |
findMatchString:matchString startingAt:index |
|
3816 |
"like findString, but allowing match patterns. |
|
3817 |
find matchstring, starting at index. if found, return the index; |
|
3818 |
if not found, return 0." |
|
3819 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3820 |
^ self findMatchString:matchString startingAt:index ignoreCase:false ifAbsent:0 |
328 | 3821 |
! |
3822 |
||
3823 |
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock |
|
3824 |
"like findString, but allowing match patterns. |
|
3825 |
find matchstring, starting at index. if found, return the index; |
|
3826 |
if not found, return the result of evaluating exceptionBlock. |
|
3827 |
This is a q&d hack - not very efficient" |
|
3828 |
||
2916 | 3829 |
|firstChar firstSet |
328 | 3830 |
startIndex "{ Class: SmallInteger }" |
3831 |
matchSize "{ Class: SmallInteger }" |
|
3832 |
mySize "{ Class: SmallInteger }" |
|
3833 |
realMatchString| |
|
3834 |
||
3835 |
matchSize := matchString size. |
|
3836 |
matchSize == 0 ifTrue:[^ index]. "empty string matches" |
|
3837 |
||
3838 |
realMatchString := matchString. |
|
3839 |
(realMatchString endsWith:$*) ifFalse:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3840 |
realMatchString := realMatchString , '*'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3841 |
matchSize := matchSize + 1 |
328 | 3842 |
]. |
3843 |
||
3844 |
mySize := self size. |
|
3845 |
firstChar := realMatchString at:1. |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3846 |
firstChar == $\ ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3847 |
firstChar := realMatchString at:2. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3848 |
]. |
328 | 3849 |
|
3850 |
firstChar asString includesMatchCharacters ifTrue:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3851 |
index to:mySize do:[:col | |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3852 |
(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
|
3853 |
ifTrue:[^ col] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3854 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3855 |
^ exceptionBlock value. |
328 | 3856 |
]. |
2916 | 3857 |
ignoreCase ifTrue:[ |
3858 |
firstSet := String with:(firstChar asUppercase) with:(firstChar asLowercase). |
|
3859 |
startIndex := self indexOfAny:firstSet startingAt:index. |
|
3860 |
] ifFalse:[ |
|
3861 |
startIndex := self indexOf:firstChar startingAt:index. |
|
3862 |
]. |
|
328 | 3863 |
[startIndex == 0] whileFalse:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3864 |
(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
|
3865 |
ifTrue:[^ startIndex]. |
2916 | 3866 |
ignoreCase ifTrue:[ |
3867 |
startIndex := self indexOfAny:firstSet startingAt:(startIndex + 1). |
|
3868 |
] ifFalse:[ |
|
3869 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1). |
|
3870 |
]. |
|
328 | 3871 |
]. |
3872 |
^ exceptionBlock value |
|
3873 |
||
3874 |
" |
|
3875 |
'one two three four' findMatchString:'o[nu]' |
|
3876 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
2916 | 3877 |
'one two three four one' findMatchString:'ONE' startingAt:3 ignoreCase:true ifAbsent:0 |
328 | 3878 |
" |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3879 |
|
2916 | 3880 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
328 | 3881 |
! |
3882 |
||
608 | 3883 |
includesMatchString:matchString |
3884 |
"like includesString, but allowing match patterns. |
|
3885 |
find matchstring; if found, return true, otherwise return false" |
|
3886 |
||
3887 |
^ (self findMatchString:matchString) ~~ 0 |
|
3888 |
||
3889 |
" |
|
3890 |
'hello world' includesMatchString:'h*' |
|
3891 |
'hello world' includesMatchString:'h[aeiou]llo' |
|
3892 |
'hello world' includesMatchString:'wor*' |
|
3893 |
'hello world' includesMatchString:'woR*' |
|
3894 |
" |
|
3895 |
! |
|
3896 |
||
328 | 3897 |
match:aString |
3898 |
"return true if aString matches self, where self may contain meta-match |
|
3899 |
characters $* (to match any string) or $# (to match any character). |
|
3900 |
or [...] to match a set of characters. |
|
345 | 3901 |
Lower/uppercase are considered different. |
3902 |
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
|
3903 |
NOT the ST-80 meaning." |
328 | 3904 |
|
3905 |
^ self match:aString from:1 to:aString size ignoreCase:false |
|
3906 |
||
3907 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3908 |
'\*f*' match:'f' |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3909 |
'\*f*' match:'*f' |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3910 |
'*\*f*' match:'*f' |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3911 |
'*f*' match:'*f' |
328 | 3912 |
'*ute*' match:'computer' |
3913 |
'*uter' match:'computer' |
|
3914 |
'uter*' match:'computer' |
|
3915 |
'*ute*' match:'' |
|
3916 |
'[abcd]*' match:'computer' |
|
3917 |
'[abcd]*' match:'komputer' |
|
3918 |
'*some*compl*ern*' match:'this is some more complicated pattern match' |
|
3919 |
'*some*compl*ern*' match:'this is another complicated pattern match' |
|
3537 | 3920 |
'*-hh' match:'anton-h' |
3921 |
" |
|
3922 |
||
3923 |
"Modified: / 9.6.1998 / 18:50:00 / cg" |
|
328 | 3924 |
! |
3925 |
||
3926 |
match:aString from:start to:stop ignoreCase:ignoreCase |
|
3927 |
"return true if part of aString matches myself, |
|
3928 |
where self may contain meta-match |
|
3929 |
characters $* (to match any string) or $# (to match any character) |
|
3930 |
or [...] to match a set of characters. |
|
345 | 3931 |
If ignoreCase is true, lower/uppercase are considered the same. |
3932 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
1429 | 3933 |
NOT the ST-80 meaning." |
328 | 3934 |
|
3935 |
|matchScanArray| |
|
3936 |
||
3937 |
" |
|
3938 |
keep the matchScanArray from the most recent match - |
|
3939 |
avoids parsing the pattern over-and over if multiple searches |
|
3940 |
are done with the same pattern. |
|
3941 |
" |
|
3942 |
(PreviousMatch notNil |
|
3943 |
and:[PreviousMatch key = self]) ifTrue:[ |
|
1429 | 3944 |
matchScanArray := PreviousMatch value |
328 | 3945 |
] ifFalse:[ |
1429 | 3946 |
matchScanArray := self class matchScanArrayFrom:self. |
3947 |
matchScanArray isNil ifTrue:[ |
|
2124 | 3948 |
'CharacterArray [info]: invalid matchpattern:' infoPrint. self infoPrintCR. |
1429 | 3949 |
^ false |
3950 |
]. |
|
3951 |
PreviousMatch := self -> matchScanArray. |
|
328 | 3952 |
]. |
3953 |
||
3954 |
^ self class |
|
1429 | 3955 |
matchScan:matchScanArray |
3956 |
from:1 to:matchScanArray size |
|
3957 |
with:aString |
|
3958 |
from:start to:stop |
|
3959 |
ignoreCase:ignoreCase |
|
328 | 3960 |
|
3961 |
" |
|
3962 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
3963 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
3964 |
" |
|
1429 | 3965 |
|
3537 | 3966 |
"Modified: / 9.6.1998 / 18:49:57 / cg" |
359 | 3967 |
! |
3968 |
||
608 | 3969 |
match:aString ignoreCase:ignoreCase |
3970 |
"return true if aString matches self, where self may contain meta-match |
|
3971 |
characters $* (to match any string) or $# (to match any character) |
|
3972 |
or [...] to match a set of characters. |
|
3973 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
3974 |
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
|
3975 |
NOT the ST-80 meaning." |
608 | 3976 |
|
3977 |
^ self match:aString from:1 to:aString size ignoreCase:ignoreCase |
|
3978 |
||
3979 |
" |
|
3980 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
3981 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
3982 |
'[abcd]*' match:'computer' ignoreCase:false |
|
3983 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
3984 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
3985 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
3986 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
3987 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
3988 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
3989 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
3990 |
||
3991 |
Time millisecondsToRun:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3992 |
Symbol allInstancesDo:[:sym | |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3993 |
'[ab]*' match:sym ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3994 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3995 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3996 |
Time millisecondsToRun:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3997 |
Symbol allInstancesDo:[:sym | |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3998 |
'*at:*' match:sym ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3999 |
] |
608 | 4000 |
]. |
4001 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4002 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4003 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
608 | 4004 |
! ! |
4005 |
||
4006 |
!CharacterArray methodsFor:'printing & storing'! |
|
4007 |
||
4008 |
article |
|
4009 |
"return an article string for the receiver." |
|
4010 |
||
4011 |
|firstChar| |
|
4012 |
||
4013 |
firstChar := (self at:1) asLowercase. |
|
4014 |
(firstChar isVowel or:[firstChar == $x]) ifTrue:[ |
|
4015 |
firstChar ~~ $u ifTrue:[ |
|
4016 |
^ 'an' |
|
4017 |
] |
|
4018 |
]. |
|
4019 |
^ 'a' |
|
4020 |
! |
|
4021 |
||
4022 |
displayString |
|
4023 |
"return a string to display the receiver - use storeString to have |
|
4024 |
quotes around." |
|
4025 |
||
4026 |
^ self storeString |
|
4027 |
! |
|
4028 |
||
4029 |
printOn:aStream |
|
4030 |
"print the receiver on aStream" |
|
4031 |
||
4032 |
aStream nextPutAll:self |
|
4033 |
! |
|
4034 |
||
4035 |
printString |
|
4036 |
"return a string for printing - thats myself" |
|
4037 |
||
4038 |
^ self |
|
3578 | 4039 |
! |
4040 |
||
4041 |
printWithQuotesDoubledOn:aStream |
|
4042 |
"put the raw storeString of myself on aStream" |
|
4043 |
||
4044 |
self do:[:thisChar | |
|
4045 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
4046 |
aStream nextPut:thisChar |
|
4047 |
] |
|
4048 |
||
4049 |
"Modified: / 15.6.1998 / 17:21:17 / cg" |
|
4050 |
"Created: / 15.6.1998 / 17:22:13 / cg" |
|
608 | 4051 |
! ! |
4052 |
||
4053 |
!CharacterArray methodsFor:'queries'! |
|
4054 |
||
4055 |
encoding |
|
1311 | 4056 |
"return the strings encoding, as a symbol. |
4057 |
Here, by default, we assume #iso8859 encoding. |
|
1241 | 4058 |
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
|
4059 |
|
1311 | 4060 |
^ #iso8859 |
4061 |
||
4062 |
"Modified: 27.4.1996 / 13:23:49 / cg" |
|
608 | 4063 |
! |
4064 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4065 |
hasChangeOfEmphasis |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4066 |
^ false |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4067 |
|
1381 | 4068 |
"Created: 12.5.1996 / 12:31:39 / cg" |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4069 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4070 |
|
1388 | 4071 |
heightOn:aGC |
4072 |
"return the size of the recevier in device units if displayed on aGC" |
|
4073 |
||
3337 | 4074 |
^ (aGC font on:aGC device) heightOf:self |
1388 | 4075 |
|
4076 |
" |
|
4077 |
'hello world' heightOn:(View new) |
|
4078 |
" |
|
4079 |
||
4080 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
4081 |
"Modified: 12.5.1996 / 20:32:05 / cg" |
|
4082 |
! |
|
4083 |
||
608 | 4084 |
isString |
4085 |
"return true, if the receiver is some kind of string; |
|
4086 |
true is returned here - redefinition of Object>>isString." |
|
4087 |
||
4088 |
^ true |
|
1235 | 4089 |
! |
4090 |
||
4091 |
leftIndent |
|
4092 |
"if the receiver starts with spaces, return the number of spaces |
|
4093 |
at the left - otherwise, return 0. |
|
4094 |
If the receiver consists of spaces only, return the receivers size." |
|
4095 |
||
4096 |
|index "{Class: SmallInteger }" |
|
4097 |
end "{Class: SmallInteger }"| |
|
4098 |
||
4099 |
index := 1. |
|
4100 |
end := self size. |
|
4101 |
[index <= end] whileTrue:[ |
|
4102 |
(self at:index) isSeparator ifFalse:[^ index - 1]. |
|
4103 |
index := index + 1 |
|
4104 |
]. |
|
4105 |
^ end |
|
4106 |
||
4107 |
" |
|
4108 |
' hello' leftIndent |
|
4109 |
'foo ' leftIndent |
|
4110 |
' ' leftIndent |
|
4111 |
" |
|
4112 |
||
4113 |
"Modified: 20.4.1996 / 19:28:43 / cg" |
|
1388 | 4114 |
! |
4115 |
||
4116 |
widthOn:aGC |
|
4117 |
"return ths size of the recevier in device units if displayed on aGC" |
|
4118 |
||
2554 | 4119 |
^ (aGC font on:aGC device) widthOf:self |
1388 | 4120 |
|
4121 |
" |
|
4122 |
'hello world' widthOn:(View new) |
|
4123 |
" |
|
4124 |
||
4125 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
2554 | 4126 |
"Modified: 17.4.1997 / 12:50:23 / cg" |
608 | 4127 |
! ! |
4128 |
||
4129 |
!CharacterArray methodsFor:'special string converting'! |
|
4130 |
||
4131 |
chopTo:maxLen |
|
4132 |
"if the receivers size is less or equal to maxLen, return it. |
|
4133 |
Otherwise, return a copy of the receiver, where some characters |
|
4134 |
in the middle have been removed for a total string length |
|
4135 |
of maxLen." |
|
4136 |
||
4137 |
|sz n1 n2| |
|
4138 |
||
4139 |
(sz := self size) > maxLen ifTrue:[ |
|
4140 |
n1 := n2 := maxLen // 2. |
|
4141 |
maxLen odd ifTrue:[ |
|
4142 |
n2 := n1 + 1 |
|
4143 |
]. |
|
4144 |
^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1) |
|
4145 |
] |
|
4146 |
||
4147 |
" |
|
4148 |
'12345678901234' chopTo:15 |
|
4149 |
'123456789012345' chopTo:15 |
|
4150 |
'1234567890123456' chopTo:15 |
|
4151 |
'aShortString' chopTo:15 |
|
4152 |
'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 |
|
4153 |
" |
|
4154 |
! |
|
4155 |
||
4156 |
contractAtBeginningTo:maxLen |
|
4157 |
"if the receivers size is less or equal to maxLen, return it. |
|
4158 |
Otherwise, return a copy of the receiver, where some characters |
|
4159 |
at the beginning have been replaced by '...' for a total string length |
|
4160 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
4161 |
||
4162 |
|sz| |
|
4163 |
||
4164 |
(sz := self size) > maxLen ifTrue:[ |
|
4165 |
^ '...' , (self copyFrom:(sz - (maxLen - 4))) |
|
4166 |
] |
|
4167 |
||
4168 |
" |
|
4169 |
'12345678901234' contractAtBeginningTo:15 |
|
4170 |
'123456789012345' contractAtBeginningTo:15 |
|
4171 |
'1234567890123456' contractAtBeginningTo:15 |
|
4172 |
'aShortString' contractAtBeginningTo:15 |
|
4173 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15 |
|
4174 |
" |
|
4175 |
! |
|
359 | 4176 |
|
608 | 4177 |
contractAtEndTo:maxLen |
4178 |
"if the receivers size is less or equal to maxLen, return it. |
|
4179 |
Otherwise, return a copy of the receiver, where some characters |
|
4180 |
at the end have been replaced by '...' for a total string length |
|
4181 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
4182 |
||
4183 |
|sz| |
|
4184 |
||
4185 |
(sz := self size) > maxLen ifTrue:[ |
|
4186 |
^ self copyReplaceFrom:maxLen - 3 |
|
4187 |
with:'...' |
|
4188 |
] |
|
4189 |
||
4190 |
" |
|
4191 |
'12345678901234' contractAtEndTo:15 |
|
4192 |
'123456789012345' contractAtEndTo:15 |
|
4193 |
'1234567890123456' contractAtEndTo:15 |
|
4194 |
'aShortString' contractAtEndTo:15 |
|
4195 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 |
|
4196 |
" |
|
4197 |
! |
|
4198 |
||
4199 |
contractTo:maxLen |
|
4200 |
"if the receivers size is less or equal to maxLen, return it. |
|
4201 |
Otherwise, return a copy of the receiver, where some characters |
|
4202 |
in the middle have been replaced by '...' for a total string length |
|
4203 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
4204 |
||
4205 |
|sz "{ SmallInteger }" |
|
4206 |
halfSize "{ SmallInteger }"| |
|
4207 |
||
4208 |
(sz := self size) > maxLen ifTrue:[ |
|
4209 |
halfSize := maxLen // 2. |
|
4210 |
^ self copyReplaceFrom:halfSize - 1 |
|
4211 |
to:sz - maxLen + halfSize + 1 |
|
4212 |
with:'...' |
|
4213 |
] |
|
4214 |
||
4215 |
" |
|
4216 |
'12345678901234' contractTo:15 |
|
4217 |
'123456789012345' contractTo:15 |
|
4218 |
'1234567890123456' contractTo:15 |
|
4219 |
'aShortString' contractTo:15 |
|
4220 |
'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 |
|
4221 |
" |
|
4222 |
! |
|
4223 |
||
4224 |
expandPlaceholdersWith:argArray |
|
4225 |
"return a copy of the receiver, where all %i escapes are |
|
1308 | 4226 |
replaced by corresponding arguments' printStrings from the argArray. |
608 | 4227 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
4228 |
in the new string 'hello world; how is this'. |
|
4229 |
To get a '%' character, use a '%%'-escape. |
|
4230 |
See also bindWith:... for VisualAge compatibility." |
|
4231 |
||
4232 |
|expandedString next |
|
4233 |
idx "{ SmallInteger }" |
|
4234 |
start "{ SmallInteger }" |
|
4235 |
stop "{ SmallInteger }"| |
|
4236 |
||
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4237 |
expandedString := self species new:0. |
608 | 4238 |
stop := self size. |
4239 |
start := 1. |
|
4240 |
[start <= stop] whileTrue:[ |
|
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4241 |
idx := self indexOf:$% startingAt:start. |
2737
9f29aecea39d
care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents:
2736
diff
changeset
|
4242 |
(idx == 0 or:[idx == stop]) ifTrue:[ |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4243 |
^ expandedString , (self copyFrom:start to:stop) |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4244 |
]. |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4245 |
"found a %" |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4246 |
expandedString := expandedString , (self copyFrom:start to:(idx - 1)). |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4247 |
next := self at:(idx + 1). |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4248 |
(next == $%) ifTrue:[ |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4249 |
expandedString := expandedString , '%' |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4250 |
] ifFalse:[ |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4251 |
expandedString := expandedString , (argArray at:(next digitValue)) printString |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4252 |
]. |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4253 |
start := idx + 2 |
608 | 4254 |
]. |
4255 |
^ expandedString |
|
4256 |
||
4257 |
" |
|
4258 |
'hello %1' expandPlaceholdersWith:#('world') |
|
4259 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
4260 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
1308 | 4261 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
608 | 4262 |
" |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
4263 |
|
2737
9f29aecea39d
care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents:
2736
diff
changeset
|
4264 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
608 | 4265 |
! |
4266 |
||
4267 |
withCRs |
|
4268 |
"return a new string consisting of receivers characters |
|
4269 |
with all \-characters replaced by cr-characters." |
|
4270 |
||
2916 | 4271 |
^ self copy replaceAll:$\ with:(Character cr) |
608 | 4272 |
|
4273 |
" |
|
4274 |
'hello\world' withCRs |
|
4275 |
" |
|
4276 |
! |
|
4277 |
||
4278 |
withEscapes |
|
4279 |
"return a new string consisting of receivers characters |
|
4280 |
with all \X-character escapes replaced by corresponding-characters. |
|
4281 |
(similar to the way C-language Strings are converted). |
|
4282 |
The following escapes are supported: |
|
1008 | 4283 |
\r return character |
4284 |
\n newline character |
|
4285 |
\b backspace character |
|
4286 |
\f formfeed character |
|
4287 |
\t tab character |
|
4288 |
\e escape character |
|
4289 |
\\ the \ character itself |
|
4290 |
\nnn three digit octal number defining the characters ascii value |
|
4291 |
\other other |
|
608 | 4292 |
|
4293 |
Notice, that \' is NOT a valid escape, since the general syntax of |
|
4294 |
string constants is not affected by this method. |
|
4295 |
||
4296 |
Although easily implementable, this is NOT done automatically |
|
4297 |
by the compiler (due to a lack of a language standard for this). |
|
4298 |
However, the compiler may detect sends ot #withEscapes to string literals |
|
4299 |
and place a modified string constant into the binary/byte-code. |
|
4300 |
Therefore, no runtime penalty will be payed for using these escapes. |
|
4301 |
(not in pre 2.11 versions) |
|
4302 |
" |
|
4303 |
||
4304 |
|sz "{ SmallInteger }" |
|
4305 |
newSize "{ SmallInteger }" |
|
4306 |
srcIdx "{ SmallInteger }" |
|
4307 |
dstIdx "{ SmallInteger }" |
|
4308 |
val "{ SmallInteger }" |
|
1381 | 4309 |
newString next hasEmphasis e| |
359 | 4310 |
|
4311 |
" |
|
608 | 4312 |
first, count the number of escapes, to allow preallocation |
4313 |
of the new string ... |
|
4314 |
(it is faster to scan the string twice than to reallocate it multiple |
|
4315 |
times in a WriteStream) |
|
4316 |
" |
|
4317 |
sz := newSize := self size. |
|
4318 |
srcIdx := 1. |
|
4319 |
[(srcIdx := self indexOf:$\ startingAt:srcIdx) ~~ 0] whileTrue:[ |
|
1008 | 4320 |
srcIdx == sz ifFalse:[ |
4321 |
newSize := newSize - 1. |
|
4322 |
srcIdx := srcIdx + 1. |
|
4323 |
next := self at:srcIdx. |
|
4324 |
next == $0 ifTrue:[ |
|
3527
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4325 |
[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
|
4326 |
newSize := newSize - 1. srcIdx := srcIdx + 1. next := self at:srcIdx. |
1008 | 4327 |
] |
4328 |
]. |
|
4329 |
]. |
|
4330 |
srcIdx := srcIdx + 1. |
|
608 | 4331 |
]. |
4332 |
||
4333 |
newSize == sz ifTrue:[ |
|
1008 | 4334 |
^ self |
608 | 4335 |
]. |
4336 |
||
4337 |
newString := self species new:newSize. |
|
1381 | 4338 |
|
4339 |
hasEmphasis := self hasChangeOfEmphasis. |
|
4340 |
||
608 | 4341 |
" |
4342 |
copy over, replace escapes |
|
4343 |
" |
|
4344 |
srcIdx := dstIdx := 1. |
|
4345 |
[srcIdx <= sz] whileTrue:[ |
|
1008 | 4346 |
next := self at:srcIdx. |
1381 | 4347 |
hasEmphasis ifTrue:[ |
4348 |
e := self emphasisAt:srcIdx |
|
4349 |
]. |
|
1008 | 4350 |
srcIdx := srcIdx + 1. |
4351 |
next == $\ ifTrue:[ |
|
4352 |
srcIdx <= sz ifTrue:[ |
|
4353 |
next := self at:srcIdx. |
|
4354 |
srcIdx := srcIdx + 1. |
|
4355 |
next == $r ifTrue:[ |
|
4356 |
next := Character return |
|
4357 |
] ifFalse:[ |
|
4358 |
next == $n ifTrue:[ |
|
4359 |
next := Character nl |
|
4360 |
] ifFalse:[ |
|
4361 |
next == $b ifTrue:[ |
|
4362 |
next := Character backspace |
|
4363 |
] ifFalse:[ |
|
4364 |
next == $f ifTrue:[ |
|
4365 |
next := Character newPage |
|
4366 |
] ifFalse:[ |
|
4367 |
next == $t ifTrue:[ |
|
4368 |
next := Character tab |
|
4369 |
] ifFalse:[ |
|
4370 |
next == $e ifTrue:[ |
|
4371 |
next := Character esc |
|
4372 |
] ifFalse:[ |
|
4373 |
next == $0 ifTrue:[ |
|
4374 |
val := 0. |
|
3527
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4375 |
[next notNil and:[next isDigit]] whileTrue:[ |
1008 | 4376 |
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
|
4377 |
srcIdx <= sz ifTrue:[ |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4378 |
next := self at:srcIdx. |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4379 |
srcIdx := srcIdx + 1. |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4380 |
] ifFalse:[ |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4381 |
next := nil |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
4382 |
] |
1008 | 4383 |
]. |
4384 |
next := Character value:val. |
|
4385 |
] |
|
4386 |
] |
|
4387 |
] |
|
4388 |
] |
|
4389 |
] |
|
4390 |
] |
|
4391 |
]. |
|
4392 |
]. |
|
4393 |
]. |
|
4394 |
newString at:dstIdx put:next. |
|
1381 | 4395 |
hasEmphasis ifTrue:[ |
4396 |
newString emphasisAt:dstIdx put:e |
|
4397 |
]. |
|
1008 | 4398 |
dstIdx := dstIdx + 1. |
608 | 4399 |
]. |
4400 |
^ newString |
|
4401 |
||
4402 |
" |
|
4403 |
'hello world' withEscapes |
|
4404 |
'hello\world' withEscapes |
|
4405 |
'hello\world\' withEscapes |
|
4406 |
'hello world\' withEscapes |
|
4407 |
'hello\tworld' withEscapes |
|
4408 |
'hello\nworld\na\n\tnice\n\t\tstring' withEscapes |
|
4409 |
'hello\tworld\n' withEscapes |
|
4410 |
'hello\010world' withEscapes |
|
4411 |
'hello\r\nworld' withEscapes |
|
4412 |
" |
|
1008 | 4413 |
|
1381 | 4414 |
"Modified: 12.5.1996 / 12:53:34 / cg" |
608 | 4415 |
! |
4416 |
||
4417 |
withTabs |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4418 |
"return a string consisting of the receivers characters |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4419 |
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
|
4420 |
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
|
4421 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4422 |
Limitation: only the very first spaces are replaced |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4423 |
(i.e. if the receiver contains newLine characters, |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4424 |
no tabs are inserted after those lineBreaks)" |
608 | 4425 |
|
4426 |
|idx "{ SmallInteger }" |
|
4427 |
nTabs "{ SmallInteger }" |
|
4428 |
newString| |
|
4429 |
||
4430 |
idx := self findFirst:[:c | (c ~~ Character space)]. |
|
4431 |
nTabs := (idx-1) // 8. |
|
4432 |
nTabs == 0 ifTrue:[^ self]. |
|
4433 |
||
4434 |
"any tabs" |
|
4435 |
newString := self class new:(self size - (nTabs * 7)). |
|
4436 |
newString atAll:(1 to:nTabs) put:(Character tab). |
|
4437 |
newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1). |
|
4438 |
^ newString |
|
4439 |
||
4440 |
" |
|
4441 |
'12345678901234567890' withTabs |
|
4442 |
' 8901234567890' withTabs |
|
4443 |
' 901234567890' withTabs |
|
4444 |
' 67890' withTabs |
|
4445 |
' 7890' withTabs |
|
4446 |
' 890' withTabs |
|
4447 |
" |
|
4448 |
! |
|
4449 |
||
4450 |
withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4451 |
"return a string consisting of the receivers characters, |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4452 |
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
|
4453 |
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
|
4454 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4455 |
This does handle multiline strings." |
608 | 4456 |
|
1381 | 4457 |
|col "{ SmallInteger }" |
4458 |
str ch |
|
4459 |
dstIdx "{ SmallInteger }" |
|
4460 |
newSz "{ SmallInteger }" |
|
4461 |
sz "{ SmallInteger }" |
|
4462 |
hasEmphasis e| |
|
608 | 4463 |
|
4464 |
(self includes:(Character tab)) ifFalse:[^ self]. |
|
1381 | 4465 |
|
4466 |
sz := self size. |
|
4467 |
||
4468 |
"/ count the new size first, instead of |
|
4469 |
"/ multiple resizing (better for large strings) |
|
4470 |
||
4471 |
col := 1. newSz := 0. |
|
4472 |
1 to:sz do:[:srcIdx | |
|
4473 |
ch := self at:srcIdx. |
|
4474 |
ch == Character tab ifFalse:[ |
|
4475 |
col := col + 1. |
|
4476 |
newSz := newSz + 1. |
|
4477 |
ch == Character cr ifTrue:[ |
|
4478 |
col := 1 |
|
4479 |
]. |
|
4480 |
] ifTrue:[ |
|
4481 |
(col \\ 8) to:8 do:[:ii | |
|
4482 |
newSz := newSz + 1. |
|
4483 |
col := col + 1 |
|
4484 |
]. |
|
4485 |
] |
|
608 | 4486 |
]. |
1381 | 4487 |
|
4488 |
str := self species new:newSz. |
|
4489 |
||
4490 |
hasEmphasis := self hasChangeOfEmphasis. |
|
4491 |
||
4492 |
col := 1. dstIdx := 1. |
|
4493 |
1 to:sz do:[:srcIdx | |
|
4494 |
ch := self at:srcIdx. |
|
4495 |
||
4496 |
ch == Character tab ifFalse:[ |
|
4497 |
col := col + 1. |
|
4498 |
ch == Character cr ifTrue:[ |
|
4499 |
col := 1 |
|
4500 |
]. |
|
4501 |
hasEmphasis ifTrue:[ |
|
4502 |
e := self emphasisAt:srcIdx. |
|
4503 |
str emphasisAt:dstIdx put:e |
|
4504 |
]. |
|
4505 |
str at:dstIdx put:ch. |
|
4506 |
dstIdx := dstIdx + 1 |
|
4507 |
] ifTrue:[ |
|
4508 |
(col \\ 8) to:8 do:[:ii | |
|
4509 |
str at:dstIdx put:Character space. |
|
4510 |
dstIdx := dstIdx + 1. |
|
4511 |
col := col + 1 |
|
4512 |
]. |
|
4513 |
] |
|
4514 |
]. |
|
4515 |
^ str |
|
608 | 4516 |
|
4517 |
" |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4518 |
('1' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4519 |
('12345' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4520 |
('123456' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4521 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4522 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4523 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4524 |
|
608 | 4525 |
(String with:Character tab |
1381 | 4526 |
with:Character tab |
4527 |
with:$1) withTabsExpanded |
|
608 | 4528 |
|
4529 |
(String with:Character tab |
|
1381 | 4530 |
with:$1 |
4531 |
with:Character tab |
|
4532 |
with:$2) withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4533 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4534 |
(String with:Character tab |
1381 | 4535 |
with:$1 |
4536 |
with:Character cr |
|
4537 |
with:Character tab |
|
4538 |
with:$2) withTabsExpanded |
|
608 | 4539 |
" |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
4540 |
|
1381 | 4541 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
608 | 4542 |
! |
4543 |
||
4544 |
withoutCRs |
|
4545 |
"return a new collection consisting of receivers elements |
|
4546 |
with all cr-characters replaced by \-characters. |
|
4547 |
This is the reverse operation of withCRs." |
|
4548 |
||
2916 | 4549 |
^ self copy replaceAll:(Character cr) with:$\ |
608 | 4550 |
" |
4551 |
'hello |
|
4552 |
world' withoutCRs |
|
359 | 4553 |
" |
608 | 4554 |
! |
4555 |
||
4556 |
withoutLeadingSeparators |
|
4557 |
"return a copy of myself without leading separators. |
|
4558 |
Notice: this does remove tabs, newline or any other whitespace. |
|
4559 |
Returns an empty string, if the receiver consist only of whitespace." |
|
4560 |
||
4561 |
|index| |
|
4562 |
||
4563 |
index := self indexOfNonSeparatorStartingAt:1. |
|
4564 |
index ~~ 0 ifTrue:[ |
|
4565 |
index == 1 ifTrue:[ |
|
4566 |
^ self |
|
4567 |
]. |
|
4568 |
^ self copyFrom:index |
|
4569 |
]. |
|
4570 |
^ '' |
|
4571 |
||
4572 |
" |
|
4573 |
' foo ' withoutLeadingSeparators |
|
4574 |
'foo ' withoutLeadingSeparators |
|
4575 |
' foo' withoutLeadingSeparators |
|
4576 |
' ' withoutLeadingSeparators |
|
4577 |
'foo' withoutLeadingSeparators |
|
4578 |
(' ' , Character tab asString , ' foo ') withoutLeadingSeparators inspect |
|
4579 |
" |
|
4580 |
! |
|
4581 |
||
4582 |
withoutSeparators |
|
4583 |
"return a copy of myself without leading and trailing whitespace. |
|
4584 |
Whitespace is space, tab, newline, formfeed. |
|
4585 |
Use withoutSpaces, if you want to remove spaces only." |
|
4586 |
||
4587 |
|startIndex "{ Class: SmallInteger }" |
|
4588 |
endIndex "{ Class: SmallInteger }" |
|
4589 |
sz| |
|
4590 |
||
4591 |
sz := self size. |
|
4592 |
startIndex := 1. |
|
4593 |
endIndex := sz. |
|
4594 |
||
4595 |
[(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[ |
|
4596 |
startIndex := startIndex + 1 |
|
4597 |
]. |
|
4598 |
[(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[ |
|
4599 |
endIndex := endIndex - 1 |
|
4600 |
]. |
|
4601 |
startIndex > endIndex ifTrue:[ |
|
4602 |
^ '' |
|
4603 |
]. |
|
4604 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
|
4605 |
^ self |
|
4606 |
]. |
|
4607 |
^ self copyFrom:startIndex to:endIndex |
|
4608 |
||
4609 |
" |
|
4610 |
' foo ' withoutSeparators |
|
4611 |
' foo' withoutSeparators |
|
4612 |
'foo ' withoutSeparators |
|
4613 |
' ' withoutSeparators |
|
4614 |
(' foo' , Character tab asString , ' ') withoutSeparators inspect |
|
4615 |
" |
|
4616 |
! |
|
4617 |
||
4618 |
withoutSpaces |
|
4619 |
"return a copy of myself without leading and trailing spaces. |
|
4620 |
Notice: this does NOT remove tabs, newline or any other whitespace. |
|
4621 |
Use withoutSeparators for this." |
|
4622 |
||
4623 |
|startIndex "{ Class: SmallInteger }" |
|
4624 |
endIndex "{ Class: SmallInteger }" |
|
4625 |
sz| |
|
4626 |
||
4627 |
sz := self size. |
|
4628 |
startIndex := 1. |
|
4629 |
endIndex := sz. |
|
4630 |
||
4631 |
[(startIndex < endIndex) and:[(self at:startIndex) == Character space]] whileTrue:[ |
|
4632 |
startIndex := startIndex + 1 |
|
4633 |
]. |
|
4634 |
[(endIndex > 1) and:[(self at:endIndex) == Character space]] whileTrue:[ |
|
4635 |
endIndex := endIndex - 1 |
|
4636 |
]. |
|
4637 |
startIndex > endIndex ifTrue:[ |
|
4638 |
^ '' |
|
4639 |
]. |
|
4640 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
|
4641 |
^ self |
|
4642 |
]. |
|
4643 |
^ self copyFrom:startIndex to:endIndex |
|
4644 |
||
4645 |
" |
|
4646 |
' foo ' withoutSpaces |
|
4647 |
'foo ' withoutSpaces |
|
4648 |
' foo' withoutSpaces |
|
4649 |
' ' withoutSpaces |
|
4650 |
(' foo' , Character tab asString , ' ') withoutSpaces inspect |
|
4651 |
" |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4652 |
! |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4653 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4654 |
withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4655 |
"return a copy of myself without trailing separators. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4656 |
Notice: this does remove tabs, newline or any other whitespace. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4657 |
Returns an empty string, if the receiver consist only of whitespace." |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4658 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4659 |
|index| |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4660 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4661 |
index := self size. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4662 |
[index ~~ 0] whileTrue:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4663 |
(self at:index) isSeparator ifFalse:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4664 |
^ self copyTo:index |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4665 |
]. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4666 |
index := index - 1 |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4667 |
]. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4668 |
^ '' |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4669 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4670 |
" |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4671 |
' foo ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4672 |
'foo ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4673 |
' foo' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4674 |
' ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4675 |
'foo' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4676 |
(' ' , Character tab asString , ' foo ') withoutTrailingSeparators inspect |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4677 |
(' foo' , Character tab asString) withoutTrailingSeparators inspect |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4678 |
" |
608 | 4679 |
! ! |
4680 |
||
4681 |
!CharacterArray methodsFor:'substring searching'! |
|
4682 |
||
4683 |
findString:subString |
|
4684 |
"find a substring. if found, return the index; |
|
4685 |
if not found, return 0." |
|
4686 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
4687 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 |
608 | 4688 |
|
4689 |
" |
|
4690 |
'hello world' findString:'llo' |
|
4691 |
'hello world' findString:'ole' |
|
4692 |
" |
|
4693 |
! |
|
4694 |
||
4695 |
findString:subString ifAbsent:exceptionBlock |
|
4696 |
"find a substring. If found, return the index; |
|
4697 |
if not found, return the result of evaluating exceptionBlock." |
|
4698 |
||
4699 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock |
|
4700 |
! |
|
4701 |
||
4702 |
findString:subString startingAt:index |
|
4703 |
"find a substring, starting at index. if found, return the index; |
|
4704 |
if not found, return 0." |
|
4705 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
4706 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:0 |
608 | 4707 |
|
4708 |
" |
|
4709 |
'hello yello' findString:'llo' startingAt:1 |
|
4710 |
'hello yello' findString:'llo' startingAt:5 |
|
4711 |
'hello yello' findString:'llo' startingAt:15 |
|
4712 |
" |
|
4713 |
! |
|
4714 |
||
4715 |
findString:subString startingAt:index ifAbsent:exceptionBlock |
|
4716 |
"find a substring, starting at index. if found, return the index; |
|
4717 |
if not found, return the result of evaluating exceptionBlock." |
|
4718 |
||
4719 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
|
4720 |
! |
|
4721 |
||
4722 |
includesString:aString |
|
4723 |
"return true, if a substring is contained in the receiver" |
|
4724 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
4725 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0) ~~ 0 |
608 | 4726 |
|
4727 |
" |
|
4728 |
'hello world' includesString:'hel' |
|
4729 |
'hello world' includesString:'rld' |
|
4730 |
'hello world' includesString:'llo' |
|
4731 |
'hello world' includesString:'LLO' |
|
4732 |
" |
|
4733 |
! |
|
4734 |
||
4735 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
|
4736 |
"find a substring, starting at index. if found, return the index; |
|
4737 |
if not found, return the result of evaluating exceptionBlock. |
|
4738 |
This is a q&d hack - not very efficient" |
|
4739 |
||
4740 |
|firstChar found |
|
4741 |
startIndex "{ Class: SmallInteger }" |
|
4742 |
subSize "{ Class: SmallInteger }" |
|
4743 |
mySize "{ Class: SmallInteger }" |
|
4744 |
runIdx "{ Class: SmallInteger }" | |
|
4745 |
||
4746 |
subSize := subString size. |
|
4747 |
subSize == 0 ifTrue:[^ index]. "empty string matches" |
|
4748 |
mySize := self size. |
|
4749 |
firstChar := subString at:1. |
|
4750 |
startIndex := self indexOf:firstChar startingAt:index. |
|
4751 |
[startIndex == 0] whileFalse:[ |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4752 |
runIdx := startIndex. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4753 |
found := true. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4754 |
1 to:subSize do:[:i | |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4755 |
runIdx > mySize ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4756 |
found := false |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4757 |
] ifFalse:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4758 |
(subString at:i) ~= (self at:runIdx) ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4759 |
found := false |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4760 |
] |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4761 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4762 |
runIdx := runIdx + 1 |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4763 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4764 |
found ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4765 |
^ startIndex |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4766 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4767 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1) |
608 | 4768 |
]. |
4769 |
^ exceptionBlock value |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4770 |
|
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4771 |
"Modified: 23.2.1996 / 15:35:15 / cg" |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4772 |
! |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4773 |
|
652 | 4774 |
restAfter:keyword withoutSeparators:strip |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4775 |
"compare the left of the receiver with keyword, |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4776 |
if it matches return the right. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4777 |
Finally, if strip is true, remove whiteSpace. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4778 |
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
|
4779 |
something: rest |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
4780 |
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
|
4781 |
begins with something. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4782 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4783 |
You may wonder why such a specialized method exists here |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4784 |
- this is so common when processing mailboxes, |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4785 |
rcs files, nntp/pop3 responses, that is was considered worth |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4786 |
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
|
4787 |
times in variuos places." |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4788 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4789 |
|rest| |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4790 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4791 |
(self startsWith:keyword) ifTrue:[ |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4792 |
rest := self copyFrom:(keyword size + 1). |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4793 |
strip ifTrue:[ |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4794 |
rest := rest withoutSeparators |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4795 |
]. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4796 |
^ rest |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4797 |
]. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4798 |
^ nil |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4799 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4800 |
" |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4801 |
'foo: hello world' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4802 |
'funny: something' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4803 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4804 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4805 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:false |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4806 |
" |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4807 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
4808 |
"Created: 25.11.1995 / 11:04:18 / cg" |
328 | 4809 |
! ! |
4810 |
||
255 | 4811 |
!CharacterArray methodsFor:'testing'! |
64 | 4812 |
|
1613 | 4813 |
continuesWith:aString startingAt:startIndex |
4814 |
"return true, if the receiver beginning at startIndex |
|
4815 |
contains the characters in aString." |
|
4816 |
||
4817 |
|sz "{Class: SmallInteger }" |
|
4818 |
idx "{Class: SmallInteger }"| |
|
4819 |
||
4820 |
sz := aString size. |
|
4821 |
idx := startIndex. |
|
4822 |
||
4823 |
1 to:sz do:[:i | |
|
4824 |
(self at:idx) ~~ (aString at:i) ifTrue:[^ false]. |
|
4825 |
idx := idx + 1 |
|
4826 |
]. |
|
4827 |
^ true |
|
4828 |
||
4829 |
" |
|
4830 |
'hello world' continuesWith:'world' startingAt:6 |
|
4831 |
'hello world' continuesWith:'world' startingAt:7 |
|
4832 |
" |
|
4833 |
||
4834 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
4835 |
"Modified: 26.7.1996 / 19:08:36 / cg" |
|
4836 |
! |
|
4837 |
||
64 | 4838 |
countWords |
4839 |
"return the number of words, which are separated by separators" |
|
4840 |
||
92 | 4841 |
|tally "{ Class: SmallInteger }" |
4842 |
start "{ Class: SmallInteger }" |
|
4843 |
mySize "{ Class: SmallInteger }" |
|
4844 |
stop ch| |
|
64 | 4845 |
|
4846 |
tally := 0. |
|
4847 |
start := 1. |
|
4848 |
mySize := self size. |
|
4849 |
[start <= mySize] whileTrue:[ |
|
154 | 4850 |
ch := self at:start. |
4851 |
ch isSeparator ifTrue:[ |
|
4852 |
start := start + 1 |
|
4853 |
] ifFalse:[ |
|
4854 |
stop := self indexOfSeparatorStartingAt:start. |
|
4855 |
(stop == 0) ifTrue:[ |
|
4856 |
stop := mySize + 1 |
|
4857 |
]. |
|
4858 |
tally := tally + 1. |
|
4859 |
start := stop |
|
4860 |
] |
|
64 | 4861 |
]. |
4862 |
^ tally |
|
4863 |
||
92 | 4864 |
" |
4865 |
'hello world isnt this nice' countWords' |
|
4866 |
" |
|
64 | 4867 |
! |
4868 |
||
1381 | 4869 |
endsWith:aString |
4870 |
"return true, if the receiver ends with something, aString." |
|
4871 |
||
4872 |
|s| |
|
4873 |
||
4874 |
(s := self string) ~~ self ifTrue:[ |
|
4875 |
^ s endsWith:aString |
|
4876 |
]. |
|
4877 |
^ super endsWith:aString |
|
4878 |
||
4879 |
" |
|
4880 |
'hello world' endsWith:'world' |
|
4881 |
'hello world' asText allBold endsWith:'world' |
|
4882 |
" |
|
4883 |
||
4884 |
"Modified: 12.5.1996 / 15:49:18 / cg" |
|
4885 |
! |
|
4886 |
||
608 | 4887 |
isAlphaNumeric |
4888 |
"return true, if the receiver is some alphanumeric word; |
|
4889 |
i.e. consists of a letter followed by letters or digits." |
|
64 | 4890 |
|
608 | 4891 |
self size == 0 ifTrue:[ |
4892 |
"mhmh what is this ?" |
|
4893 |
^ false |
|
64 | 4894 |
]. |
608 | 4895 |
(self at:1) isLetter ifFalse:[^ false]. |
4896 |
self do:[:char | |
|
4897 |
char isLetterOrDigit ifFalse:[^ false]. |
|
4898 |
]. |
|
4899 |
^ true |
|
64 | 4900 |
|
77 | 4901 |
" |
608 | 4902 |
'helloWorld' isAlphaNumeric |
4903 |
'foo1234' isAlphaNumeric |
|
4904 |
'f1234' isAlphaNumeric |
|
4905 |
'1234' isAlphaNumeric |
|
4906 |
'+' isAlphaNumeric |
|
77 | 4907 |
" |
4908 |
! |
|
4909 |
||
608 | 4910 |
isBlank |
4911 |
"return true, if the receiver contains spaces only" |
|
77 | 4912 |
|
608 | 4913 |
self do:[:char | |
4914 |
char ~~ Character space ifTrue:[^ false]. |
|
77 | 4915 |
]. |
608 | 4916 |
^ true |
64 | 4917 |
! |
4918 |
||
4919 |
levenshteinTo:aString |
|
4920 |
"return the levenshtein distance to the argument, aString; |
|
4921 |
this value corrensponds to the number of replacements that have to be |
|
4922 |
made to get aString from the receiver. |
|
196 | 4923 |
See IEEE transactions on Computers 1976 Pg 172 ff." |
64 | 4924 |
|
327 | 4925 |
" |
4926 |
in the following, we assum that ommiting a character |
|
4927 |
is less of an error than inserting an extra character. |
|
4928 |
Therefore the different insertion (i) and deletion (d) |
|
4929 |
values. |
|
4930 |
" |
|
4931 |
||
64 | 4932 |
^ self levenshteinTo:aString s:4 c:1 i:2 d:6 |
154 | 4933 |
|
4934 |
" |
|
4935 |
'ocmprt' levenshteinTo:'computer' |
|
4936 |
'computer' levenshteinTo:'computer' |
|
4937 |
'ocmputer' levenshteinTo:'computer' |
|
4938 |
'cmputer' levenshteinTo:'computer' |
|
327 | 4939 |
'computer' levenshteinTo:'cmputer' |
154 | 4940 |
'Computer' levenshteinTo:'computer' |
4941 |
" |
|
64 | 4942 |
! |
4943 |
||
4944 |
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight |
|
196 | 4945 |
"parametrized levenshtein. |
4946 |
return the levenshtein distance to the argument, aString; |
|
4947 |
this value corrensponds to the number of replacements that have to be |
|
4948 |
made to get aString from the receiver. |
|
4949 |
The arguments are the costs for substitution, case-change, insertion and |
|
4950 |
deletion of a character. |
|
4951 |
See IEEE transactions on Computers 1976 Pg 172 ff" |
|
64 | 4952 |
|
4953 |
|d "delta matrix" |
|
196 | 4954 |
len1 "{ Class: SmallInteger }" |
4955 |
len2 "{ Class: SmallInteger }" |
|
4956 |
dim "{ Class: SmallInteger }" |
|
4957 |
prevRow row col |
|
4958 |
dimPlus1 "{ Class: SmallInteger }" |
|
64 | 4959 |
min pp c1 c2| |
4960 |
||
4961 |
len1 := self size. |
|
4962 |
len2 := aString size. |
|
4963 |
||
4964 |
"create the help-matrix" |
|
4965 |
||
4966 |
dim := len1 max:len2. |
|
4967 |
dimPlus1 := dim + 1. |
|
4968 |
||
4969 |
d := Array new:dimPlus1. |
|
4970 |
1 to:dimPlus1 do:[:i | |
|
154 | 4971 |
d at:i put:(Array new:dimPlus1) |
64 | 4972 |
]. |
4973 |
||
4974 |
"init help-matrix" |
|
4975 |
||
4976 |
(d at:1) at:1 put:0. |
|
4977 |
row := d at:1. |
|
4978 |
1 to:dim do:[:j | |
|
154 | 4979 |
row at:(j + 1) put:( (row at:j) + insrtWeight ) |
64 | 4980 |
]. |
4981 |
||
4982 |
1 to:dim do:[:i | |
|
154 | 4983 |
(d at:(i + 1)) at:1 put:( ((d at:i) at:1) + deleteWeight ) |
64 | 4984 |
]. |
4985 |
||
4986 |
1 to:len1 do:[:i | |
|
154 | 4987 |
c1 := self at:i. |
4988 |
1 to:len2 do:[:j | |
|
4989 |
c2 := aString at:j. |
|
4990 |
(c1 == c2) ifTrue:[ |
|
4991 |
pp := 0 |
|
4992 |
] ifFalse:[ |
|
4993 |
(c1 asLowercase == c2 asLowercase) ifTrue:[ |
|
4994 |
pp := caseWeight |
|
4995 |
] ifFalse:[ |
|
4996 |
pp := substWeight |
|
4997 |
] |
|
4998 |
]. |
|
4999 |
prevRow := d at:i. |
|
5000 |
row := d at:(i + 1). |
|
5001 |
col := j + 1. |
|
5002 |
min := (prevRow at:j) + pp. |
|
5003 |
min := min min:( (row at:j) + insrtWeight). |
|
5004 |
min := min min:( (prevRow at:col) + deleteWeight). |
|
5005 |
row at:col put: min |
|
5006 |
] |
|
64 | 5007 |
]. |
5008 |
||
5009 |
^ (d at:(len1 + 1)) at:(len2 + 1) |
|
5010 |
! |
|
5011 |
||
608 | 5012 |
numArgs |
5013 |
"treating the receiver as a message selector, return how many arguments would it take" |
|
5014 |
||
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5015 |
|binopChars firstChar| |
608 | 5016 |
|
5017 |
(self size > 2) ifFalse:[ |
|
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5018 |
binopChars := Scanner binarySelectorCharacters. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5019 |
firstChar := self at:1. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5020 |
|
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5021 |
(self size == 1) ifTrue:[ |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5022 |
((binopChars occurrencesOf:firstChar) == 0) ifTrue:[^ 0]. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5023 |
^ 1 |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5024 |
]. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5025 |
((binopChars occurrencesOf:firstChar) == 0) ifFalse:[ |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5026 |
((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
|
5027 |
] |
608 | 5028 |
]. |
5029 |
^ self occurrencesOf:$: |
|
5030 |
||
5031 |
" |
|
5032 |
'foo:bar:' numArgs |
|
5033 |
#foo:bar: numArgs |
|
5034 |
'hello' numArgs |
|
5035 |
'+' numArgs |
|
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5036 |
'|' numArgs |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5037 |
'?' numArgs |
608 | 5038 |
" |
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5039 |
|
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
5040 |
"Modified: 4.1.1997 / 14:16:14 / cg" |
608 | 5041 |
! |
5042 |
||
5043 |
partsIfSelector |
|
5044 |
"treat the receiver as a message selector, return a collection of parts." |
|
5045 |
||
5046 |
|idx1 "{ Class: SmallInteger }" |
|
5047 |
coll idx2 sz| |
|
5048 |
||
5049 |
coll := OrderedCollection new. |
|
5050 |
idx1 := 1. |
|
5051 |
sz := self size. |
|
5052 |
[true] whileTrue:[ |
|
5053 |
idx2 := self indexOf:$: startingAt:idx1 + 1. |
|
5054 |
(idx2 == 0 or:[idx2 == sz]) ifTrue:[ |
|
5055 |
coll add:(self copyFrom:idx1). |
|
5056 |
^ coll |
|
5057 |
]. |
|
5058 |
coll add:(self copyFrom:idx1 to:idx2). |
|
5059 |
idx1 := idx2 + 1 |
|
5060 |
]. |
|
5061 |
||
5062 |
" |
|
5063 |
'foo:bar:' partsIfSelector |
|
5064 |
#foo:bar: partsIfSelector |
|
5065 |
'hello' partsIfSelector |
|
5066 |
'+' partsIfSelector |
|
5067 |
" |
|
5068 |
! |
|
5069 |
||
64 | 5070 |
spellAgainst: aString |
5071 |
"return an integer between 0 and 100 indicating how similar |
|
154 | 5072 |
the argument is to the receiver. No case conversion is done. |
5073 |
This algorithm is much simpler (but also less exact) than the |
|
5074 |
levenshtein distance. Experiment which is better for your |
|
5075 |
application." |
|
64 | 5076 |
|
5077 |
| i1 "{ Class: SmallInteger }" |
|
5078 |
i2 "{ Class: SmallInteger }" |
|
154 | 5079 |
next1 "{ Class: SmallInteger }" |
5080 |
next2 "{ Class: SmallInteger }" |
|
64 | 5081 |
size1 "{ Class: SmallInteger }" |
5082 |
size2 "{ Class: SmallInteger }" |
|
5083 |
score "{ Class: SmallInteger }" |
|
5084 |
maxLen "{ Class: SmallInteger }" | |
|
5085 |
||
5086 |
size1 := self size. |
|
5087 |
size2 := aString size. |
|
154 | 5088 |
maxLen := size1 max:size2. |
64 | 5089 |
score := 0. |
5090 |
i1 := i2 := 1. |
|
5091 |
[i1 <= size1 and: [i2 <= size2]] whileTrue:[ |
|
154 | 5092 |
next1 := i1 + 1. |
5093 |
next2 := i2 + 1. |
|
5094 |
(self at:i1) == (aString at:i2) ifTrue: [ |
|
5095 |
score := score+1. |
|
5096 |
i1 := next1. |
|
5097 |
i2 := next2 |
|
5098 |
] ifFalse: [ |
|
5099 |
(i2 < size2 and: [(self at:i1) == (aString at:next2)]) ifTrue: [ |
|
5100 |
i2 := next2 |
|
5101 |
] ifFalse: [ |
|
5102 |
(i1 < size1 and: [(self at:next1) == (aString at:i2)]) ifTrue: [ |
|
5103 |
i1 := next1 |
|
5104 |
] ifFalse: [ |
|
5105 |
i1 := next1. |
|
5106 |
i2 := next2 |
|
5107 |
] |
|
5108 |
] |
|
5109 |
] |
|
64 | 5110 |
]. |
5111 |
||
1124 | 5112 |
score == maxLen ifTrue: [^ 100]. |
154 | 5113 |
^ 100 * score // maxLen |
64 | 5114 |
|
154 | 5115 |
" |
5116 |
'Smalltalk' spellAgainst: 'Smalltlak' |
|
5117 |
'Smalltalk' spellAgainst: 'smalltlak' |
|
5118 |
'Smalltalk' spellAgainst: 'smalltalk' |
|
5119 |
'Smalltalk' spellAgainst: 'smalltlk' |
|
5120 |
'Smalltalk' spellAgainst: 'Smalltolk' |
|
5121 |
" |
|
1381 | 5122 |
! |
5123 |
||
5124 |
startsWith:aString |
|
5125 |
"return true, if the receiver starts with something, aString." |
|
5126 |
||
5127 |
|s| |
|
5128 |
||
5129 |
(s := self string) ~~ self ifTrue:[ |
|
5130 |
^ s startsWith:aString |
|
5131 |
]. |
|
5132 |
^ super startsWith:aString |
|
5133 |
||
5134 |
" |
|
5135 |
'hello world' startsWith:'hello' |
|
5136 |
'hello world' asText allBold startsWith:'hello' |
|
5137 |
" |
|
5138 |
||
5139 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
5140 |
"Modified: 12.5.1996 / 15:49:24 / cg" |
|
64 | 5141 |
! ! |
5142 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
5143 |
!CharacterArray class methodsFor:'documentation'! |
629 | 5144 |
|
5145 |
version |
|
3578 | 5146 |
^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.147 1998-06-15 15:22:56 cg Exp $' |
629 | 5147 |
! ! |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
5148 |
CharacterArray initialize! |