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