author | Claus Gittinger <cg@exept.de> |
Fri, 06 Feb 2004 10:03:12 +0100 | |
changeset 7880 | 069f34892789 |
parent 7879 | a7a0a7fe9b54 |
child 7882 | 6e1883fa220d |
permissions | -rw-r--r-- |
64 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
154 | 3 |
All Rights Reserved |
64 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
14 |
|
3926 | 15 |
ByteArray variableByteSubclass:#CharacterArray |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
16 |
instanceVariableNames:'' |
2734 | 17 |
classVariableNames:'PreviousMatch DecoderTables EncoderTables DecodingFailedSignal |
18 |
EncodingFailedSignal' |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
19 |
poolDictionaries:'' |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
20 |
category:'Collections-Text' |
64 | 21 |
! |
22 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
23 |
!CharacterArray class methodsFor:'documentation'! |
64 | 24 |
|
82 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
154 | 28 |
All Rights Reserved |
82 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
64 | 39 |
documentation |
40 |
" |
|
255 | 41 |
CharacterArray is a superclass for all kinds of Strings (i.e. |
68 | 42 |
(singleByte-)Strings, TwoByteStrings and whatever comes in the future. |
154 | 43 |
|
2537 | 44 |
This class is abstract, meaning that there are no instances of it. |
45 |
All this class does is provide common protocol for concrete subclasses. |
|
1290 | 46 |
|
47 |
[author:] |
|
48 |
Claus Gittinger |
|
49 |
||
50 |
[see also:] |
|
51 |
String TwoByteString |
|
52 |
StringCollection |
|
64 | 53 |
" |
54 |
! ! |
|
55 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
56 |
!CharacterArray class methodsFor:'initialization'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
57 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
58 |
initialize |
5440 | 59 |
DecodingFailedSignal isNil ifTrue:[ |
60 |
DecodingFailedSignal := Signal new mayProceed:true. |
|
61 |
DecodingFailedSignal notifierString:'decoding failure'. |
|
62 |
DecodingFailedSignal nameClass:self message:#decodingFailedSignal. |
|
63 |
||
64 |
EncodingFailedSignal := QuerySignal new mayProceed:true. |
|
65 |
EncodingFailedSignal notifierString:'encoding failure'. |
|
66 |
EncodingFailedSignal nameClass:self message:#encodingFailedSignal. |
|
67 |
] |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
68 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
69 |
" |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
70 |
CharacterArray initialize |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
71 |
" |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
72 |
|
2833 | 73 |
"Modified: 3.8.1997 / 18:15:59 / cg" |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
74 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
75 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
76 |
!CharacterArray class methodsFor:'instance creation'! |
64 | 77 |
|
78 |
basicNew |
|
79 |
"return a new empty string" |
|
80 |
||
81 |
^ self basicNew:0 |
|
82 |
! |
|
83 |
||
2734 | 84 |
fromBytes:aByteCollection |
85 |
"return an instance of the receiver class, |
|
86 |
taking untranslated bytes from the argument, aByteCollection. |
|
87 |
Only useful, when reading twoByteStrings from external sources." |
|
88 |
||
89 |
|mySize nBytes newString dstIdx| |
|
90 |
||
91 |
nBytes := aByteCollection size. |
|
92 |
mySize := self basicNew bitsPerCharacter. |
|
93 |
mySize == 16 ifTrue:[ |
|
94 |
newString := self basicNew:(nBytes // 2). |
|
95 |
dstIdx := 1. |
|
96 |
aByteCollection pairWiseDo:[:hi :lo | |
|
97 |
newString at:dstIdx put:(Character value:(hi bitShift:8)+lo). |
|
98 |
dstIdx := dstIdx + 1 |
|
99 |
]. |
|
100 |
^ newString. |
|
101 |
]. |
|
102 |
||
103 |
^ (self basicNew:nBytes) replaceFrom:1 with:aByteCollection |
|
104 |
||
105 |
" |
|
106 |
TwoByteString fromBytes:#[16r21 16r21] |
|
107 |
" |
|
108 |
||
109 |
"Modified: 30.6.1997 / 20:08:37 / cg" |
|
110 |
! |
|
111 |
||
64 | 112 |
fromString:aString |
113 |
"return a copy of the argument, aString" |
|
114 |
||
68 | 115 |
^ (self basicNew:(aString size)) replaceFrom:1 with:aString |
116 |
||
117 |
"TwoByteString fromString:'hello'" |
|
581 | 118 |
! |
119 |
||
120 |
fromStringCollection:aCollectionOfStrings |
|
121 |
"return new string formed by concatenating a copy of the argument, aString" |
|
122 |
||
123 |
^ self fromStringCollection:aCollectionOfStrings separatedBy:'' |
|
124 |
||
125 |
" |
|
126 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') |
|
127 |
" |
|
128 |
||
129 |
"Created: 20.11.1995 / 15:26:59 / cg" |
|
130 |
! |
|
131 |
||
132 |
fromStringCollection:aCollectionOfStrings separatedBy:aSeparatorString |
|
133 |
"return new string formed by concatenating a copy of the argument, aString" |
|
134 |
||
135 |
|newString first| |
|
136 |
||
137 |
newString := ''. |
|
138 |
first := true. |
|
139 |
aCollectionOfStrings do:[:s | |
|
140 |
first ifFalse:[ |
|
141 |
newString := newString , aSeparatorString |
|
142 |
] ifTrue:[ |
|
143 |
first := false |
|
144 |
]. |
|
145 |
newString := newString , s |
|
146 |
]. |
|
147 |
^ newString |
|
148 |
||
149 |
" |
|
150 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:' ' |
|
151 |
" |
|
152 |
||
153 |
"Created: 20.11.1995 / 15:32:17 / cg" |
|
608 | 154 |
! |
155 |
||
5757 | 156 |
fromUTF8Bytes:aByteCollection |
5758 | 157 |
"return a new string which represents the characters as decoded |
158 |
from the utf8 encoded bytes, aByteCollection. |
|
159 |
Returns either a normal String, or a TwoByteString instance. |
|
6810 | 160 |
Only useful, when reading twoByteStrings from external sources. |
161 |
This only handles up-to 16bit characters" |
|
5757 | 162 |
|
7876 | 163 |
^ self decodeFromUTF8:aByteCollection. |
5757 | 164 |
|
165 |
" |
|
166 |
CharacterArray fromUTF8Bytes:#[ 16r41 16r42 ] |
|
167 |
CharacterArray fromUTF8Bytes:#[ 16rC1 16r02 ] |
|
168 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r81 16r02 ] |
|
6810 | 169 |
CharacterArray fromUTF8Bytes:#[ 16rEF 16rBF 16rBF ] |
170 |
||
171 |
rfc2279 examples: |
|
172 |
CharacterArray fromUTF8Bytes:#[ 16r41 16rE2 16r89 16rA2 16rCE 16r91 16r2E ] |
|
173 |
CharacterArray fromUTF8Bytes:#[ 16rED 16r95 16r9C 16rEA 16rB5 16rAD 16rEC 16r96 16rB4 ] |
|
174 |
CharacterArray fromUTF8Bytes:#[ 16rE6 16r97 16rA5 16rE6 16r9C 16rAC 16rE8 16rAA 16r9E ] |
|
175 |
||
176 |
invalid: |
|
177 |
CharacterArray fromUTF8Bytes:#[ 16rC0 16r80 ] |
|
178 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r80 16r80 ] |
|
5757 | 179 |
" |
180 |
! |
|
181 |
||
608 | 182 |
new |
183 |
"return a new empty string" |
|
184 |
||
185 |
^ self basicNew:0 |
|
64 | 186 |
! ! |
187 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
188 |
!CharacterArray class methodsFor:'Signal constants'! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
189 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
190 |
decodingFailedSignal |
2833 | 191 |
"return the signal, raised when decoding of a string is not possible |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
192 |
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
|
193 |
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
|
194 |
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
|
195 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
196 |
^ DecodingFailedSignal |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
197 |
|
2833 | 198 |
"Created: 28.6.1997 / 20:09:55 / cg" |
199 |
"Modified: 3.8.1997 / 18:16:47 / cg" |
|
200 |
! |
|
201 |
||
202 |
encodingFailedSignal |
|
203 |
"return the (query-) signal, raised when encoding of a string is not possible |
|
204 |
due to invalid characters contained in the source." |
|
205 |
||
206 |
^ EncodingFailedSignal |
|
207 |
||
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
208 |
"Modified: 28.6.1997 / 20:09:35 / cg" |
2833 | 209 |
"Created: 3.8.1997 / 18:16:40 / cg" |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
210 |
! ! |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
211 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
212 |
!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
|
213 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
214 |
lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
215 |
"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
|
216 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
217 |
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
|
218 |
|
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 |
CharacterArray lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
221 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
222 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
223 |
"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
|
224 |
"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
|
225 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
226 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
227 |
!CharacterArray class methodsFor:'code tables'! |
443 | 228 |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
229 |
classForEncoding:encodingSymbol |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
230 |
"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
|
231 |
by encodingSymbol" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
232 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
233 |
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
|
234 |
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
|
235 |
encodingSymbol == #gb ifTrue:[^ GBEncodedString]. |
2734 | 236 |
encodingSymbol == #ksc ifTrue:[^ KSCEncodedString]. |
237 |
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
|
238 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
239 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
240 |
"/ 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
|
241 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
242 |
^ String |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
243 |
|
2734 | 244 |
"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
|
245 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
246 |
|
443 | 247 |
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
|
248 |
"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
|
249 |
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
|
250 |
This is an experimental interface - unfinished" |
443 | 251 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
252 |
|table unrepresentableCharacterCode x80Table| |
443 | 253 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
254 |
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
|
255 |
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
|
256 |
table notNil ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
257 |
table == #identity ifTrue:[^ nil]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
258 |
^ table |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
259 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
260 |
] ifFalse:[ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
261 |
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
|
262 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
263 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
264 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
265 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
266 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
267 |
"/ setup as identityTranslation |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
268 |
"/ |
443 | 269 |
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
|
270 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
271 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
272 |
"/ hp -> iso8859 |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
273 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
274 |
"/ 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
|
275 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
276 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
277 |
encoding == #hp ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
278 |
unrepresentableCharacterCode := 16rA0. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
279 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
280 |
x80Table := |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
281 |
#( |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
282 |
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
|
283 |
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
|
284 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
285 |
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
|
286 |
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
|
287 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
288 |
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
|
289 |
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
|
290 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
291 |
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
|
292 |
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
|
293 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
294 |
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
|
295 |
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
|
296 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
297 |
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
|
298 |
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
|
299 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
300 |
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
|
301 |
"/ S ? s ? Y ? |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
302 |
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
|
303 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
304 |
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
|
305 |
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
|
306 |
). |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
307 |
]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
308 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
309 |
"/ |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
310 |
"/ mac -> iso8859 |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
311 |
"/ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
312 |
"/ 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
|
313 |
"/ - 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
|
314 |
"/ |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
315 |
"/ A0 (dagger) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
316 |
"/ A5 (dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
317 |
"/ AA (tm - trademark) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
318 |
"/ AD (not equal) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
319 |
"/ B0 (infinity) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
320 |
"/ B3 (less-double-equal <=) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
321 |
"/ B4 (greater-equal >-) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
322 |
"/ B6 (math lowercase delta) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
323 |
"/ B7 (math sum) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
324 |
"/ B8 (math uppercase pi) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
325 |
"/ B9 (math lowercase pi) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
326 |
"/ BA (math integral) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
327 |
"/ BD (math omega) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
328 |
"/ C3 (math union) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
329 |
"/ C4 (ext latin f) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
330 |
"/ C5 (math almost equal) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
331 |
"/ C6 (math uppercase delta) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
332 |
"/ C9 (dot-dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
333 |
"/ CE (OE ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
334 |
"/ CF (oe ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
335 |
"/ D1 (hyphen) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
336 |
"/ D2 (opening top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
337 |
"/ D3 (closing top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
338 |
"/ D4 (opening top quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
339 |
"/ D5 (closing top quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
340 |
"/ D7 (geometric: ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
341 |
"/ D9 (uppercase Y diacrit ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
342 |
"/ DA (slash2 ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
343 |
"/ DC (single oldStyle opening quote (<) ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
344 |
"/ DD (single oldStyle closing quote (>) ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
345 |
"/ DE (? ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
346 |
"/ DF (? ) |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
347 |
"/ E0 (double dagger ) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
348 |
"/ E2 (opening bottom quote ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
349 |
"/ E3 (opening bottom dquote ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
350 |
"/ F0 (? ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
351 |
"/ F5 (latin l ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
352 |
"/ F6 (diacrit circumflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
353 |
"/ F7 (diacrit tilde) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
354 |
"/ F8 (diacrit top line) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
355 |
"/ F9 (diacrit inverse circumflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
356 |
"/ FA (diacrit dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
357 |
"/ FB (diacrit ring) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
358 |
"/ FC (diacrit cedille left) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
359 |
"/ FD (diacrit dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
360 |
"/ FE (diacrit cedille right) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
361 |
"/ FF (diacrit circumflex2 ?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
362 |
"/ |
443 | 363 |
encoding == #mac ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
364 |
x80Table := |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
365 |
#( 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
|
366 |
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
|
367 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
368 |
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
|
369 |
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
|
370 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
371 |
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
|
372 |
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
|
373 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
374 |
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
|
375 |
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
|
376 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
377 |
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
|
378 |
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
|
379 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
380 |
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
|
381 |
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
|
382 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
383 |
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
|
384 |
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
|
385 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
386 |
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
|
387 |
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
|
388 |
). |
657 | 389 |
]. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
390 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
391 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
392 |
"/ next -> iso8859 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
393 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
394 |
"/ 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
|
395 |
"/ - 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
|
396 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
397 |
"/ A4 (diacrit /) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
398 |
"/ A9 (diacrit quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
399 |
"/ AA (top opening dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
400 |
"/ AC (single oldStyle opening quote (<)) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
401 |
"/ AD (single oldStyle closing quote (>)) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
402 |
"/ AE (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
403 |
"/ AF (?) |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
404 |
"/ B2 (dagger) |
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
405 |
"/ B3 (double dagger) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
406 |
"/ B7 (enter dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
407 |
"/ B8 (opening bottom quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
408 |
"/ B9 (opening bottom dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
409 |
"/ BA (closing top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
410 |
"/ BC (dot-dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
411 |
"/ BD (per-mille) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
412 |
"/ C0 (subscript 1) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
413 |
"/ C1 (accent grave) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
414 |
"/ C2 (accent degu) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
415 |
"/ C3 (accent circonflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
416 |
"/ C4 (accent tilde) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
417 |
"/ C5 (accent line) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
418 |
"/ C6 (accent circonflex reverse) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
419 |
"/ C7 (accent dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
420 |
"/ C8 (accent dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
421 |
"/ D0 (hline) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
422 |
"/ 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
|
423 |
"/ EA (OE ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
424 |
"/ F5 (latin l) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
425 |
"/ 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
|
426 |
"/ FE (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
427 |
"/ FF (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
428 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
429 |
encoding == #next ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
430 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
431 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
432 |
x80Table := |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
433 |
#( 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
|
434 |
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
|
435 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
436 |
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
|
437 |
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
|
438 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
439 |
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
|
440 |
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
|
441 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
442 |
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
|
443 |
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
|
444 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
445 |
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
|
446 |
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
|
447 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
448 |
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
|
449 |
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
|
450 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
451 |
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
|
452 |
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
|
453 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
454 |
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
|
455 |
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
|
456 |
). |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
457 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
458 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
459 |
"/ |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
460 |
"/ 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
|
461 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
462 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
463 |
"/ 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
|
464 |
"/ - 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
|
465 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
466 |
"/ 9E (pesetas) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
467 |
"/ 9F (latin f) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
468 |
"/ A9 (technical not) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
469 |
"/ B0 - BF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
470 |
"/ C0 - CF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
471 |
"/ D0 - DF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
472 |
"/ E0 (greek alpha) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
473 |
"/ E2 - E5 (greek) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
474 |
"/ E7 - EC (greek & math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
475 |
"/ EE - EF (greek & math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
476 |
"/ F0 (math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
477 |
"/ F2 - F5 (math & technical) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
478 |
"/ F7 (math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
479 |
"/ F9 (center dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
480 |
"/ FB (math sqrt) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
481 |
"/ FC (super n) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
482 |
"/ 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
|
483 |
"/ |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
484 |
encoding == #msdos437 ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
485 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
486 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
487 |
x80Table := |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
488 |
#( |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
489 |
"/ 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
|
490 |
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
|
491 |
"/ 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
|
492 |
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
|
493 |
"/ 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
|
494 |
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
|
495 |
"/ 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
|
496 |
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
|
497 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
498 |
"/ 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
|
499 |
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
|
500 |
"/ 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
|
501 |
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
|
502 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
503 |
"/ block graphics |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
504 |
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
|
505 |
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
|
506 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
507 |
"/ block graphics |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
508 |
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
|
509 |
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
|
510 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
511 |
"/ block graphics |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
512 |
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
|
513 |
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
|
514 |
|
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
515 |
"/ alpha beta ... mu |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
516 |
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
|
517 |
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
|
518 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
519 |
"/ 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
|
520 |
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
|
521 |
"/ 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
|
522 |
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
|
523 |
). |
443 | 524 |
]. |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
525 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
526 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
527 |
"/ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
528 |
"/ msdos (codePage 850 [=latin1]) -> iso8859 |
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 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
531 |
(encoding == #msdos850 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
532 |
or:[encoding == #msdos]) ifTrue:[ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
533 |
unrepresentableCharacterCode := 16rBF. |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
534 |
x80Table := |
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 |
"/ 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
|
537 |
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
|
538 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
539 |
"/ 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
|
540 |
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
|
541 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
542 |
"/ Eacute ae AE ocirc ouml ograve ucirc ugrave |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
543 |
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
|
544 |
"/ 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
|
545 |
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
|
546 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
547 |
"/ aacute iacute oacute uacute ntilde Ntilde asup 0sup |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
548 |
16r00e1 16r00ed 16r00f3 16r00fa 16r00f1 16r00d1 16r00aa 16r00da "/ a0 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
549 |
"/ 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
|
550 |
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
|
551 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
552 |
"/ Aacute Acirc Agrave |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
553 |
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
|
554 |
"/ cpyr cent Yen |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
555 |
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
|
556 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
557 |
"/ atilde Atilde |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
558 |
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
|
559 |
"/ |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
560 |
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
|
561 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
562 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
563 |
"/ Ecirc Euml Egrave Iacute Icirc |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
564 |
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
|
565 |
"/ Iuml Igrave |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
566 |
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
|
567 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
568 |
"/ Oacute sz Ocirc Ograve otilde Otilde mu |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
569 |
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
|
570 |
"/ Uacute Ucirc Ugrav yacute Yacute ' |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
571 |
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
|
572 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
573 |
"/ plusmin = 3/4 para sect div "/ f0 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
574 |
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
|
575 |
|
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
576 |
"/ sup0 sup3 sup2 |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
577 |
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
|
578 |
). |
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
579 |
]. |
443 | 580 |
"/ more encodings needed here .... |
581 |
||
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
582 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
583 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
584 |
"/ 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
|
585 |
"/ 0x80..0xFF characters |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
586 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
587 |
x80Table isNil ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
588 |
table := #identity. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
589 |
] ifFalse:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
590 |
x80Table keysAndValuesDo:[:idx :repl | |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
591 |
|ch| |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
592 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
593 |
repl == 16rFFFF ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
594 |
ch := unrepresentableCharacterCode |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
595 |
] ifFalse:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
596 |
ch := repl |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
597 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
598 |
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
|
599 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
600 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
601 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
602 |
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
|
603 |
^ table |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
604 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
605 |
" |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
606 |
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
|
607 |
DecoderTables := nil |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
608 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
609 |
|
443 | 610 |
"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
|
611 |
"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
|
612 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
613 |
|
2734 | 614 |
defaultRomanCharacterValue |
615 |
"return the characterValue for unmappable roman characters |
|
616 |
(only applies to jis, gb, ksc etc.)" |
|
617 |
||
618 |
|romans| |
|
619 |
||
620 |
romans := self romanTable. |
|
621 |
romans isNil ifTrue:[^ 16r20]. |
|
622 |
^ romans at:1. "/ space characters xlation |
|
623 |
||
624 |
"Created: 30.6.1997 / 18:13:24 / cg" |
|
625 |
"Modified: 30.6.1997 / 18:19:26 / cg" |
|
626 |
! |
|
627 |
||
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
628 |
encoderTableFor:encoding |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
629 |
"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
|
630 |
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
|
631 |
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
|
632 |
|
2751 | 633 |
|table decoderTable unrepresentableCharacterCode| |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
634 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
635 |
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
|
636 |
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
|
637 |
table notNil ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
638 |
table == #identity ifTrue:[^ nil]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
639 |
^ table |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
640 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
641 |
] ifFalse:[ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
642 |
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
|
643 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
644 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
645 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
646 |
"/ iso8859 -> hp |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
647 |
"/ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
648 |
encoding == #hp ifTrue:[ |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
649 |
decoderTable := self decoderTableFor:encoding. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
650 |
unrepresentableCharacterCode := 16rFF. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
651 |
]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
652 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
653 |
"/ |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
654 |
"/ iso8859 -> mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
655 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
656 |
encoding == #mac ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
657 |
decoderTable := self decoderTableFor:encoding. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
658 |
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
|
659 |
]. |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
660 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
661 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
662 |
"/ iso8859 -> msdos |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
663 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
664 |
encoding == #msdos ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
665 |
decoderTable := self decoderTableFor:encoding. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
666 |
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
|
667 |
]. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
668 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
669 |
"/ 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
|
670 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
671 |
decoderTable notNil ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
672 |
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
|
673 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
674 |
0 to:16rFF do:[:code | |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
675 |
|isoCode destIdex| |
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 |
isoCode := decoderTable at:(code+1). |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
678 |
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
|
679 |
] |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
680 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
681 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
682 |
table isNil ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
683 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
684 |
"/ 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
|
685 |
"/ use special #identity |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
686 |
"/ |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
687 |
table := #identity. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
688 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
689 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
690 |
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
|
691 |
^ table |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
692 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
693 |
" |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
694 |
EncoderTables := nil. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
695 |
DecoderTables := nil. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
696 |
CharacterArray decoderTableFor:#mac |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
697 |
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
|
698 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
699 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
700 |
"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
|
701 |
"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
|
702 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
703 |
|
2733 | 704 |
romanTable |
705 |
^ nil |
|
706 |
||
707 |
"Created: 30.6.1997 / 15:13:52 / cg" |
|
708 |
! |
|
709 |
||
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
710 |
supportedEncodings |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
711 |
"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
|
712 |
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
|
713 |
|
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
714 |
^ self supportedExternalEncodings at:2. |
2733 | 715 |
|
716 |
"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
|
717 |
! |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
718 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
719 |
supportedExternalEncodings |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
720 |
"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
|
721 |
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
|
722 |
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
|
723 |
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
|
724 |
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
|
725 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
726 |
^ #( |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
727 |
( |
7879 | 728 |
'utf8 (unicode as 8Bit characters)' |
729 |
'utf7 (unicode as 7Bit characters)' |
|
730 |
nil |
|
2250 | 731 |
'iso8859 (ansi)' |
732 |
'iso8859-1 (latin1)' |
|
733 |
'iso8859-2 (latin2)' |
|
734 |
'iso8859-3 (latin3)' |
|
735 |
'iso8859-4 (latin4)' |
|
736 |
'iso8859-5 (cyrillic)' |
|
737 |
'iso8859-6 (arabic)' |
|
738 |
'iso8859-7 (greek)' |
|
739 |
'iso8859-8 (hebrew)' |
|
7879 | 740 |
nil |
7880 | 741 |
'koi8-r (cyrillic)' |
742 |
nil |
|
2250 | 743 |
'msdos US (codepage 437)' |
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
744 |
'msdos Latin1 (codepage 850)' |
2250 | 745 |
'macintosh (8 bit)' |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
746 |
'next (8 bit)' |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
747 |
'hp (8 bit)' |
2733 | 748 |
nil |
2250 | 749 |
'EUC (extended unix code japanese)' |
750 |
'JIS7 (jis 7bit escape codes japanese)' |
|
2759 | 751 |
'ISO-2022-JP (same as jis 7bit)' |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
752 |
'SJIS (shift jis 8bit codes japanese)' |
2733 | 753 |
nil |
2250 | 754 |
'GB (mainland china)' |
755 |
'BIG5 (taiwan)' |
|
2733 | 756 |
"/ 'KSC (korean)' |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
757 |
) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
758 |
( |
7879 | 759 |
#'utf8' |
760 |
#'utf7' |
|
761 |
nil |
|
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
762 |
#'iso8859' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
763 |
#'iso8859-1' "/ latin1 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
764 |
#'iso8859-2' "/ latin2 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
765 |
#'iso8859-3' "/ latin3 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
766 |
#'iso8859-4' "/ latin4 |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
767 |
#'iso8859-5' "/ cyrillic |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
768 |
#'iso8859-6' "/ arabic |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
769 |
#'iso8859-7' "/ greek |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
770 |
#'iso8859-8' "/ hebrew |
7879 | 771 |
nil |
7880 | 772 |
#'koi8-r' |
773 |
nil |
|
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
774 |
#'msdos437' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
775 |
#'msdos850' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
776 |
#'mac' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
777 |
#'next' |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
778 |
#'hp' |
2733 | 779 |
nil |
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
780 |
#'euc' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
781 |
#'jis7' |
2759 | 782 |
#'iso-2022-jp' |
2721 | 783 |
#'sjis' |
2733 | 784 |
nil |
2452
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
785 |
#'gb' |
7262e3b2c20a
fixed supportedExternalEncodings
Claus Gittinger <cg@exept.de>
parents:
2344
diff
changeset
|
786 |
#'big5' |
2733 | 787 |
"/ #'ksc' "/ korean |
2250 | 788 |
) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
789 |
) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
790 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
791 |
"Created: 22.4.1996 / 14:39:39 / cg" |
2759 | 792 |
"Modified: 16.7.1997 / 13:47:16 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
793 |
! ! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
794 |
|
7421 | 795 |
!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
|
796 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
797 |
decodeFromBIG5:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
798 |
"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
|
799 |
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
|
800 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
801 |
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
|
802 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
803 |
|newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
804 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
805 |
newString := BIG5EncodedString new:aString size. |
1204 | 806 |
^ self decodeFromBIG5_or_GB:aString into:newString. |
807 |
||
808 |
"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
|
809 |
! |
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 |
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
|
812 |
"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
|
813 |
which is interpreted as a BIG5 encoded singleByte string. |
2748 | 814 |
The result is a Big5EncodedString (you need a BIG5 font to display that ...). |
815 |
||
816 |
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
|
817 |
|
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 |
srcIdx "{ 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 }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
824 |
c| |
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 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
828 |
dstIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
829 |
srcIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
830 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
831 |
[true] whileTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
832 |
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
|
833 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
834 |
"/ characters below 16rA1 are left untranslated |
2733 | 835 |
"/ (romans). |
836 |
"/ 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
|
837 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
838 |
b1 := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
839 |
b1 >= 16rA1 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
840 |
srcIdx := srcIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
841 |
srcIdx <= sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
842 |
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
|
843 |
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
|
844 |
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
|
845 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
846 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
847 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
848 |
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
|
849 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
850 |
srcIdx := srcIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
851 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
852 |
srcIdx > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
853 |
^ 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
|
854 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
855 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
856 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
857 |
^ a16BitString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
858 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
859 |
"Created: 17.4.1996 / 16:55:54 / cg" |
2748 | 860 |
"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
|
861 |
! |
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 |
decodeFromEUC:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
864 |
"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
|
865 |
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
|
866 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
867 |
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
|
868 |
this one only understands New-JIS. |
2748 | 869 |
The result is a JISEncodedString (you need a JIS font to display that ...). |
870 |
||
871 |
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
|
872 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
873 |
|newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
874 |
sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
875 |
dstIdx "{ Class: SmallInteger }" |
2750 | 876 |
srcIdx "{ Class: SmallInteger }" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
877 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
878 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
879 |
val "{ Class: SmallInteger }" |
2733 | 880 |
c c2| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
881 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
882 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
883 |
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
|
884 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
885 |
dstIdx := 1. |
2750 | 886 |
srcIdx := 1. |
887 |
||
888 |
%{ |
|
889 |
if (__isString(aString) |
|
890 |
&& (__Class(newString) == @global(JISEncodedString))) { |
|
891 |
int _dstIdx = 1, _srcIdx = 1; |
|
892 |
int _sz = __intVal(sz); |
|
893 |
unsigned char *_cp = __stringVal(aString); |
|
894 |
unsigned char _c1; |
|
895 |
unsigned short *_jcp = (unsigned short *)__stringVal(newString); |
|
896 |
||
897 |
while (_srcIdx <= _sz) { |
|
898 |
_c1 = _cp[_srcIdx-1]; |
|
899 |
if (_c1 < 161) { |
|
900 |
_jcp[_dstIdx-1] = _c1; |
|
901 |
} else { |
|
902 |
_srcIdx++; |
|
903 |
if (_srcIdx <= _sz) { |
|
904 |
unsigned char _c2; |
|
905 |
int _val; |
|
906 |
int _b1, _b2; |
|
907 |
||
908 |
_b1 = _c1 - 128; |
|
909 |
_c2 = _cp[_srcIdx-1]; |
|
910 |
_b2 = _c2 - 128; |
|
911 |
_val = (_b1<<8) + _b2; |
|
912 |
if (_val < 0) { |
|
913 |
/* decoder errors are handled in smalltalk */ |
|
914 |
_srcIdx--; |
|
915 |
goto getOutOfHere; |
|
916 |
} |
|
917 |
_jcp[_dstIdx-1] = _val; |
|
918 |
} else { |
|
919 |
_jcp[_dstIdx-1] = _c1; |
|
920 |
} |
|
921 |
} |
|
922 |
_dstIdx++; |
|
923 |
_srcIdx++; |
|
924 |
} |
|
925 |
getOutOfHere: |
|
926 |
srcIdx = __MKSMALLINT(_srcIdx); |
|
927 |
dstIdx = __MKSMALLINT(_dstIdx); |
|
928 |
} |
|
929 |
%}. |
|
930 |
||
931 |
[srcIdx <= sz] whileTrue:[ |
|
932 |
c := aString at:srcIdx. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
933 |
b1 := c asciiValue. |
2748 | 934 |
b1 < 161 ifTrue:[ |
935 |
"/ characters below 16rA1 are left untranslated |
|
936 |
"/ (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
|
937 |
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
|
938 |
] ifFalse:[ |
2750 | 939 |
srcIdx := srcIdx + 1. |
940 |
srcIdx <= sz ifTrue:[ |
|
2748 | 941 |
b1 := b1 - 128. |
2750 | 942 |
b2 := (c2 := aString at:srcIdx) asciiValue. |
2748 | 943 |
b2 := b2 - 128. |
944 |
val := (b1 bitShift:8) bitOr:b2. |
|
945 |
val <= 0 ifTrue:[ |
|
946 |
DecodingFailedSignal |
|
947 |
raiseWith:aString |
|
948 |
errorString:'EUC decoding failed (not EUC encoded ?)'. |
|
949 |
newString at:dstIdx put:c. |
|
950 |
dstIdx := dstIdx + 1. |
|
951 |
newString at:dstIdx put:c2. |
|
952 |
] ifFalse:[ |
|
953 |
newString at:dstIdx put:(Character value:val). |
|
954 |
]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
955 |
] ifFalse:[ |
2748 | 956 |
newString at:dstIdx put:c. |
957 |
]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
958 |
]. |
2748 | 959 |
dstIdx := dstIdx + 1. |
2750 | 960 |
srcIdx := srcIdx + 1. |
961 |
]. |
|
962 |
||
963 |
(dstIdx-1) ~~ sz ifTrue:[ |
|
964 |
newString := newString copyFrom:1 to:dstIdx-1. |
|
965 |
]. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
966 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
967 |
^ newString |
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 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
970 |
|
2733 | 971 |
'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
|
972 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
973 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
974 |
"Created: 17.4.1996 / 16:10:22 / cg" |
2748 | 975 |
"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
|
976 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
977 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
978 |
decodeFromGB:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
979 |
"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
|
980 |
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
|
981 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
982 |
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
|
983 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
984 |
|newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
985 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
986 |
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
|
987 |
^ 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
|
988 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
989 |
"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
|
990 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
991 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
992 |
decodeFromJIS7:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
993 |
"return a new string containing the aStrings characters, |
2758 | 994 |
which are interpreted as a JIS7 or ISO2022-JP encoded singleByte string. |
995 |
There are various JIS encodings around (New-JIS, Old-JIS, NEC-JIS and ISO2022); |
|
996 |
this one understands New-JIS, ISO2022 and treats Old-JIS just the same. |
|
2748 | 997 |
The result is a JISEncodedString (you need a JIS font to display that ...). |
998 |
||
999 |
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
|
1000 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1001 |
|newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1002 |
sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1003 |
dstIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1004 |
start "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1005 |
stop "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1006 |
n1 n2 n3 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1007 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1008 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1009 |
val "{ Class: SmallInteger }" |
2734 | 1010 |
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
|
1011 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1012 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1013 |
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
|
1014 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1015 |
dstIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1016 |
start := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1017 |
singleBytes := true. |
2734 | 1018 |
katakana := false. |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1019 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1020 |
[true] whileTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1021 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1022 |
"/ 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
|
1023 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1024 |
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
|
1025 |
stop == 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1026 |
stop := sz + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1027 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1028 |
(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
|
1029 |
stop := sz + 1. |
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 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1032 |
singleBytes ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1033 |
start to:(stop - 1) do:[:i | |
2758 | 1034 |
c := aString at:i. |
2734 | 1035 |
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
|
1036 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1037 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1038 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1039 |
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
|
1040 |
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
|
1041 |
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
|
1042 |
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
|
1043 |
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
|
1044 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1045 |
] |
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 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1048 |
stop > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1049 |
^ 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
|
1050 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1051 |
start := stop. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1052 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1053 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1054 |
"/ 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
|
1055 |
"/ - 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
|
1056 |
"/ 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
|
1057 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1058 |
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
|
1059 |
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
|
1060 |
n3 := aString at:(start + 2). |
2734 | 1061 |
katakana := false. |
1062 |
||
1063 |
(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
|
1064 |
singleBytes := false. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1065 |
] ifFalse:[ |
2734 | 1066 |
(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
|
1067 |
singleBytes := false. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1068 |
] ifFalse:[ |
2734 | 1069 |
(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
|
1070 |
singleBytes := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1071 |
] ifFalse:[ |
2734 | 1072 |
(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
|
1073 |
singleBytes := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1074 |
] ifFalse:[ |
2734 | 1075 |
(n2 == $( and:[n3 == $I ]) ifTrue:[ |
1076 |
singleBytes := true. |
|
1077 |
katakana := true. |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1078 |
] ifFalse:[ |
2734 | 1079 |
singleBytes ifTrue:[ |
1080 |
newString at:dstIdx put:n1. |
|
1081 |
newString at:(dstIdx + 1) put:n2. |
|
1082 |
newString at:(dstIdx + 2) put:n3. |
|
1083 |
dstIdx := dstIdx + 3. |
|
1084 |
] ifFalse:[ |
|
1085 |
DecodingFailedSignal |
|
1086 |
raiseWith:aString |
|
1087 |
errorString:'JIS7 decoding failed (not JIS7 encoded ?)'. |
|
1088 |
newString at:dstIdx put:n1. |
|
1089 |
newString at:(dstIdx + 1) put:n2. |
|
1090 |
newString at:(dstIdx + 2) put:n3. |
|
1091 |
dstIdx := dstIdx + 3. |
|
1092 |
] |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1093 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1094 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1095 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1096 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1097 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1098 |
start := start + 3. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1099 |
start > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1100 |
^ 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
|
1101 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1102 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1103 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1104 |
^ newString |
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 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1107 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1108 |
'hello' decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1109 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1110 |
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
|
1111 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1112 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1113 |
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
|
1114 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1115 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1116 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1117 |
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
|
1118 |
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
|
1119 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1120 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1121 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1122 |
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
|
1123 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1124 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1125 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1126 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1127 |
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
|
1128 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1129 |
s := s copyWith:$A. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1130 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1131 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1132 |
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
|
1133 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1134 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1135 |
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
|
1136 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1137 |
s := s copyWith:$B. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1138 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1139 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1140 |
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
|
1141 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1142 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1143 |
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
|
1144 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1145 |
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
|
1146 |
s := s , '$3'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1147 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1148 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1149 |
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
|
1150 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1151 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1152 |
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
|
1153 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1154 |
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
|
1155 |
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
|
1156 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1157 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1158 |
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
|
1159 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1160 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1161 |
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
|
1162 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1163 |
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
|
1164 |
s := s , '$3'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1165 |
s := s copyWith:Character esc. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1166 |
s := s copyWith:$(. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1167 |
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
|
1168 |
s := s , 'hello'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1169 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1170 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1171 |
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
|
1172 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1173 |
|s t l| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1174 |
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
|
1175 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1176 |
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
|
1177 |
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
|
1178 |
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
|
1179 |
s := s copyWith:$(. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1180 |
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
|
1181 |
s := s , ' kterm'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1182 |
t := s decodeFromJIS7. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1183 |
l := Label new. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1184 |
l label:t. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1185 |
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
|
1186 |
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
|
1187 |
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
|
1188 |
l realize |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1189 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1190 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1191 |
"Created: 17.4.1996 / 16:11:57 / cg" |
2758 | 1192 |
"Modified: 16.7.1997 / 12:50:55 / cg" |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1193 |
! |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1194 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1195 |
decodeFromSJIS:aString |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1196 |
"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
|
1197 |
which are interpreted as a Shift-JIS encoded singleByte string. |
2748 | 1198 |
The result is a JISEncodedString (you need a JIS font to display that ...). |
1199 |
||
1200 |
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
|
1201 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1202 |
|newString char1 char2 |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1203 |
sz "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1204 |
dstIdx "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1205 |
srcIdx "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1206 |
b1 "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1207 |
b2 "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1208 |
val "{ Class: SmallInteger }" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1209 |
| |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1210 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1211 |
sz := aString size. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1212 |
newString := JISEncodedString new:sz. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1213 |
sz ~~ 0 ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1214 |
dstIdx := 1. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1215 |
srcIdx := 1. |
2749 | 1216 |
%{ |
2757 | 1217 |
if (1 && __isString(aString) |
2749 | 1218 |
&& (__Class(newString) == @global(JISEncodedString))) { |
1219 |
int _dstIdx = 1, _srcIdx = 1; |
|
1220 |
int _sz = __intVal(sz); |
|
1221 |
unsigned char *_cp = __stringVal(aString); |
|
1222 |
unsigned char _c1, _c2; |
|
1223 |
unsigned short *_jcp = (unsigned short *)__stringVal(newString); |
|
1224 |
||
1225 |
while (_srcIdx <= _sz) { |
|
1226 |
int _val; |
|
1227 |
||
1228 |
_c1 = _cp[_srcIdx-1]; |
|
1229 |
_srcIdx++; |
|
1230 |
||
1231 |
if ((_srcIdx <= _sz) |
|
1232 |
&& (((_c1 >= 129) && (_c1 <= 159)) |
|
1233 |
|| ((_c1 >= 224) && (_c1 <= 239)))) { |
|
1234 |
_c2 = _cp[_srcIdx-1]; |
|
1235 |
_srcIdx++; |
|
1236 |
if ((_c2 >= 64) && (_c2 <= 252)) { |
|
1237 |
int _adjust, _rowOffs, _cellOffs; |
|
1238 |
int _b1, _b2; |
|
1239 |
||
1240 |
_adjust = (_c2 < 159) ? 1 : 0; |
|
1241 |
_rowOffs = (_c1 < 160) ? 112 : 176; |
|
1242 |
if (_adjust) { |
|
1243 |
_cellOffs = 31 + ((_c2 > 127) ? 1 : 0); |
|
1244 |
} else { |
|
1245 |
_cellOffs = 126; |
|
1246 |
} |
|
1247 |
_b1 = ((_c1 - _rowOffs) << 1) - _adjust; |
|
1248 |
_b2 = (_c2 - _cellOffs); |
|
1249 |
_val = (_b1<<8) + _b2; |
|
1250 |
if (_val <= 0) { |
|
1251 |
/* decoder error - let smalltalk handle that */ |
|
1252 |
_srcIdx -= 2; |
|
1253 |
goto getOutOfHere; |
|
1254 |
} |
|
1255 |
_jcp[_dstIdx-1] = _val; |
|
1256 |
} else { |
|
1257 |
/* mhmh - append untranslated */ |
|
1258 |
||
1259 |
_jcp[_dstIdx-1] = _c1; |
|
1260 |
_dstIdx++; |
|
1261 |
_jcp[_dstIdx-1] = _c2; |
|
1262 |
} |
|
1263 |
} else { |
|
1264 |
if ((_c1 >= 0xA1 /* 161 */) && (_c1 <= 0xDF /* 223 */)) { |
|
1265 |
/* HALFWIDTH KATAKANA |
|
1266 |
* map half-width katakana to 8E:xx |
|
1267 |
*/ |
|
1268 |
_val = _c1 - 128; |
|
1269 |
_val = _val + 0x8E00; |
|
1270 |
_jcp[_dstIdx-1] = _val; |
|
1271 |
} else { |
|
1272 |
/* roman characters left untranslated */ |
|
1273 |
_jcp[_dstIdx-1] = _c1; |
|
1274 |
} |
|
1275 |
} |
|
1276 |
_dstIdx++; |
|
1277 |
} |
|
1278 |
getOutOfHere: ; |
|
1279 |
dstIdx = __MKSMALLINT(_dstIdx); |
|
1280 |
srcIdx = __MKSMALLINT(_srcIdx); |
|
1281 |
} |
|
1282 |
%}. |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1283 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1284 |
[srcIdx <= sz] whileTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1285 |
"/ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1286 |
"/ 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
|
1287 |
"/ |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1288 |
char1 := aString at:srcIdx. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1289 |
srcIdx := srcIdx + 1. |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1290 |
b1 := char1 asciiValue. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1291 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1292 |
((srcIdx <= sz) |
2757 | 1293 |
and:[(b1 >= 129 and:[b1 <= 159]) "/ SJIS1 81 .. 9F |
1294 |
or:[b1 >= 224 and:[b1 <= 239]]]) ifTrue:[ "/ E0 .. EF |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1295 |
char2 := aString at:srcIdx. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1296 |
srcIdx := srcIdx + 1. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1297 |
b2 := char2 asciiValue. |
2757 | 1298 |
(b2 >= 64 and:[b2 <= 252]) ifTrue:[ "/ SJIS2 40 .. FC |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1299 |
|adjust rowOffs cellOffs| |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1300 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1301 |
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
|
1302 |
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
|
1303 |
adjust == 1 ifTrue:[ |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1304 |
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
|
1305 |
] ifFalse:[ |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1306 |
cellOffs := 126. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1307 |
]. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1308 |
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
|
1309 |
b2 := (b2 - cellOffs). |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1310 |
val := (b1 bitShift:8) + b2. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1311 |
val <= 0 ifTrue:[ |
2730
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1312 |
DecodingFailedSignal |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1313 |
raiseWith:aString |
2730
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1314 |
errorString:'SJIS decoding failed (not SJIS encoded ?)'. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1315 |
newString at:dstIdx put:char1. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1316 |
dstIdx := dstIdx + 1. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1317 |
newString at:dstIdx put:char2. |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1318 |
] ifFalse:[ |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1319 |
newString at:dstIdx put:(Character value:val). |
1fbfddfa1d3f
allow proceeding after a decoder error
Claus Gittinger <cg@exept.de>
parents:
2728
diff
changeset
|
1320 |
] |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1321 |
] ifFalse:[ |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1322 |
"/ mhmh - append untranslated |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1323 |
|
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1324 |
newString at:dstIdx put:char1. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1325 |
dstIdx := dstIdx + 1. |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1326 |
newString at:dstIdx put:char2. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1327 |
] |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1328 |
] ifFalse:[ |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1329 |
(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
|
1330 |
"/ 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
|
1331 |
val := b1 - 128. |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
1332 |
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
|
1333 |
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
|
1334 |
] ifFalse:[ |
2733 | 1335 |
"/ roman characters left untranslated |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1336 |
newString at:dstIdx put:char1 |
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1337 |
] |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1338 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1339 |
dstIdx := dstIdx + 1. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1340 |
]. |
2749 | 1341 |
(dstIdx-1) ~~ sz ifTrue:[ |
1342 |
newString := newString copyTo:dstIdx - 1. |
|
1343 |
] |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1344 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1345 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1346 |
^ newString |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1347 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1348 |
"simple: |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1349 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1350 |
'hello' decodeFrom:#sjis |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1351 |
|
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1352 |
'../../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
|
1353 |
decodeFrom:#sjis |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1354 |
" |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
1355 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
1356 |
"Created: 28.6.1997 / 19:19:23 / cg" |
2748 | 1357 |
"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
|
1358 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1359 |
|
7876 | 1360 |
decodeFromUTF8:aStringOrByteCollection |
1361 |
"return a string which represents the characters as decoded |
|
1362 |
from the utf8 encoded bytes, aByteCollection. |
|
1363 |
Returns either a normal String, or a TwoByteString instance. |
|
1364 |
Only useful, when reading twoByteStrings from external sources. |
|
1365 |
This only handles up-to 16bit characters." |
|
1366 |
||
1367 |
|sz nBitsRequired ascii s byte newString idx| |
|
1368 |
||
1369 |
nBitsRequired := 8. |
|
1370 |
sz := 0. |
|
1371 |
s := aStringOrByteCollection readStream. |
|
1372 |
[s atEnd] whileFalse:[ |
|
1373 |
byte := ascii := s nextByte. |
|
1374 |
(byte bitAnd:16r80) ~~ 0 ifTrue:[ |
|
1375 |
(byte bitAnd:16rE0) == 16rC0 ifTrue:[ |
|
1376 |
ascii := (byte bitAnd:16r1F). |
|
1377 |
byte := s nextByte. |
|
1378 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:16r3F). |
|
1379 |
ascii > 16rFF ifTrue:[ |
|
1380 |
nBitsRequired := nBitsRequired max:16 |
|
1381 |
]. |
|
1382 |
ascii <= 16r7F ifTrue:[ |
|
1383 |
"/ self error:'invalid utf encoding' mayProceed:true. |
|
1384 |
]. |
|
1385 |
] ifFalse:[ |
|
1386 |
(byte bitAnd:16rF0) == 16rE0 ifTrue:[ |
|
1387 |
ascii := (byte bitAnd:16r0F). |
|
1388 |
byte := s nextByte. |
|
1389 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:16r3F). |
|
1390 |
byte := s nextByte. |
|
1391 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:16r3F). |
|
1392 |
ascii > 16rFF ifTrue:[ |
|
1393 |
nBitsRequired := nBitsRequired max:16 |
|
1394 |
]. |
|
1395 |
ascii <= 16r7FF ifTrue:[ |
|
1396 |
self error:'invalid utf encoding'. |
|
1397 |
]. |
|
1398 |
] ifFalse:[ |
|
1399 |
self error:'bad/unsupported utf encoding'. |
|
1400 |
^ nil. |
|
1401 |
] |
|
1402 |
]. |
|
1403 |
]. |
|
1404 |
sz := sz + 1. |
|
1405 |
]. |
|
1406 |
nBitsRequired == 8 ifTrue:[ |
|
1407 |
aStringOrByteCollection isString ifTrue:[^ aStringOrByteCollection]. |
|
1408 |
newString := String uninitializedNew:sz |
|
1409 |
] ifFalse:[ |
|
1410 |
newString := UnicodeString new:sz |
|
1411 |
]. |
|
1412 |
||
1413 |
s := aStringOrByteCollection readStream. |
|
1414 |
idx := 1. |
|
1415 |
[s atEnd] whileFalse:[ |
|
1416 |
byte := ascii := s nextByte. |
|
1417 |
(byte bitAnd:16r80) ~~ 0 ifTrue:[ |
|
1418 |
(byte bitAnd:16rE0) == 16rC0 ifTrue:[ |
|
1419 |
ascii := (byte bitAnd:16r1F). |
|
1420 |
byte := s nextByte. |
|
1421 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:16r3F). |
|
1422 |
] ifFalse:[ |
|
1423 |
ascii := (byte bitAnd:16r0F). |
|
1424 |
byte := s nextByte. |
|
1425 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:16r3F). |
|
1426 |
byte := s nextByte. |
|
1427 |
ascii := (ascii bitShift:6) bitOr:(byte bitAnd:16r3F). |
|
1428 |
]. |
|
1429 |
]. |
|
1430 |
newString at:idx put:(Character value:ascii). |
|
1431 |
idx := idx + 1. |
|
1432 |
]. |
|
1433 |
^ newString |
|
1434 |
||
1435 |
" |
|
1436 |
CharacterArray fromUTF8Bytes:#[ 16r41 16r42 ] |
|
1437 |
CharacterArray fromUTF8Bytes:#[ 16rC1 16r02 ] |
|
1438 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r81 16r02 ] |
|
1439 |
CharacterArray fromUTF8Bytes:#[ 16rEF 16rBF 16rBF ] |
|
1440 |
||
1441 |
rfc2279 examples: |
|
1442 |
CharacterArray fromUTF8Bytes:#[ 16r41 16rE2 16r89 16rA2 16rCE 16r91 16r2E ] |
|
1443 |
CharacterArray fromUTF8Bytes:#[ 16rED 16r95 16r9C 16rEA 16rB5 16rAD 16rEC 16r96 16rB4 ] |
|
1444 |
CharacterArray fromUTF8Bytes:#[ 16rE6 16r97 16rA5 16rE6 16r9C 16rAC 16rE8 16rAA 16r9E ] |
|
1445 |
||
1446 |
invalid: |
|
1447 |
CharacterArray fromUTF8Bytes:#[ 16rC0 16r80 ] |
|
1448 |
CharacterArray fromUTF8Bytes:#[ 16rE0 16r80 16r80 ] |
|
1449 |
" |
|
1450 |
! |
|
1451 |
||
2733 | 1452 |
encodeIntoBIG5:aBIG5String |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1453 |
"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
|
1454 |
The argument must be a BIG5String. |
2733 | 1455 |
This is used translate 16bit BIG5 strings into the external BIG5 encoded |
1456 |
representation. |
|
1457 |
The resulting string is only useful to be stored on some external file, |
|
2748 | 1458 |
not for being displayed in an ST/X view. |
1459 |
||
1460 |
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
|
1461 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1462 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1463 |
b "{ Class: SmallInteger }" |
2733 | 1464 |
c out| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1465 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1466 |
sz := aBIG5String size. |
2733 | 1467 |
out := WriteStream on:(String new:(sz * 2)). |
1468 |
||
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1469 |
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
|
1470 |
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
|
1471 |
b := c asciiValue. |
1203
a43528048cb8
code tables moved to BIG5/JISEncodedString classes
Claus Gittinger <cg@exept.de>
parents:
1202
diff
changeset
|
1472 |
|
2733 | 1473 |
b > 255 ifTrue:[ |
1474 |
"/ big5 character |
|
1475 |
||
1476 |
out nextPut:(Character value:(b bitShift:-8)). |
|
1477 |
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
|
1478 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1479 |
"/ |
2733 | 1480 |
"/ 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
|
1481 |
"/ |
2733 | 1482 |
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
|
1483 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1484 |
]. |
2733 | 1485 |
^ out contents |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1486 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1487 |
"Created: 17.4.1996 / 17:17:50 / cg" |
2748 | 1488 |
"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
|
1489 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1490 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1491 |
encodeIntoEUC:aJISString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1492 |
"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
|
1493 |
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
|
1494 |
The resulting string is only useful to be stored on some external file, |
2748 | 1495 |
not for being displayed in an ST/X view. |
1496 |
||
1497 |
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
|
1498 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1499 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1500 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1501 |
val "{ Class: SmallInteger }" |
2733 | 1502 |
c romans out| |
1503 |
||
1504 |
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
|
1505 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1506 |
sz := aJISString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1507 |
sz == 0 ifTrue:[^ '']. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1508 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1509 |
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
|
1510 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1511 |
1 to:sz do:[:srcIndex | |
2733 | 1512 |
b1 := (c := aJISString at:srcIndex) asciiValue. |
2748 | 1513 |
b1 < 161 ifTrue:[ |
1514 |
"/ a control or roman character |
|
2733 | 1515 |
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
|
1516 |
] ifFalse:[ |
2748 | 1517 |
"/ |
1518 |
"/ check for a roman character |
|
1519 |
"/ the two numbers below are romanTable min and romanTable max |
|
1520 |
"/ |
|
1521 |
(b1 between:16r2121 and:16r2573) ifTrue:[ |
|
1522 |
val := romans indexOf:b1. |
|
1523 |
(val ~~ 0 and:[val <= 127]) ifTrue:[ |
|
1524 |
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
|
1525 |
] ifFalse:[ |
2747 | 1526 |
out nextPut:(Character value:(b1 bitShift:-8) + 128). |
1527 |
out nextPut:(Character value:(b1 bitAnd:16rFF) + 128). |
|
2748 | 1528 |
]. |
1529 |
] ifFalse:[ |
|
1530 |
out nextPut:(Character value:(b1 bitShift:-8) + 128). |
|
1531 |
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
|
1532 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1533 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1534 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1535 |
^ out contents |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1536 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1537 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1538 |
|
2733 | 1539 |
('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
|
1540 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1541 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1542 |
"Created: 17.4.1996 / 16:13:33 / cg" |
2748 | 1543 |
"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
|
1544 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1545 |
|
2733 | 1546 |
encodeIntoGB:aGBString |
1547 |
"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
|
1548 |
The argument must be a GBString. |
2733 | 1549 |
This is used translate 16bit GB strings into the external GB encoded |
1550 |
representation. |
|
1551 |
The resulting string is only useful to be stored on some external file, |
|
2748 | 1552 |
not for being displayed in an ST/X view. |
1553 |
||
1554 |
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
|
1555 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1556 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1557 |
b "{ Class: SmallInteger }" |
2733 | 1558 |
c out| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1559 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1560 |
sz := aGBString size. |
2733 | 1561 |
out := WriteStream on:(String new:(sz * 2)). |
1562 |
||
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1563 |
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
|
1564 |
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
|
1565 |
b := c asciiValue. |
2733 | 1566 |
b > 255 ifTrue:[ |
1567 |
"/ big5 character |
|
1568 |
||
1569 |
out nextPut:(Character value:(b bitShift:-8)). |
|
1570 |
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
|
1571 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1572 |
"/ |
2733 | 1573 |
"/ 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
|
1574 |
"/ |
2733 | 1575 |
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
|
1576 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1577 |
]. |
2733 | 1578 |
^ out contents |
1579 |
||
1580 |
"Created: 30.6.1997 / 15:48:35 / cg" |
|
2748 | 1581 |
"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
|
1582 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1583 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1584 |
encodeIntoJIS7:aJISString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1585 |
"return a new string with aJISStrings characters as JIS7 encoded 7bit string, |
2733 | 1586 |
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
|
1587 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1588 |
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
|
1589 |
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
|
1590 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1591 |
|sz "{ Class:SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1592 |
b1 "{ Class:SmallInteger }" |
2757 | 1593 |
val romans out inSingleByteMode c kanji roman val2| |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1594 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1595 |
inSingleByteMode := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1596 |
kanji := JISEncodedString jis7KanjiEscapeSequence. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1597 |
roman := JISEncodedString jis7RomanEscapeSequence. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1598 |
|
2733 | 1599 |
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
|
1600 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1601 |
sz := aJISString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1602 |
sz == 0 ifTrue:[^ '']. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1603 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1604 |
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
|
1605 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1606 |
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
|
1607 |
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
|
1608 |
b1 := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1609 |
b1 < 33 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1610 |
"/ a control character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1611 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1612 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1613 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1614 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1615 |
out nextPut:c. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1616 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1617 |
"/ 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
|
1618 |
"/ 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
|
1619 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1620 |
(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
|
1621 |
val := romans indexOf:b1. |
2757 | 1622 |
val2 := val - 1 + 32. |
1623 |
(val ~~ 0 and:[val2 <= 16r7F]) ifTrue:[ |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1624 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1625 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1626 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1627 |
]. |
2757 | 1628 |
out nextPut:(Character value:val2) |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1629 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1630 |
inSingleByteMode ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1631 |
out nextPutAll:kanji. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1632 |
inSingleByteMode := false |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1633 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1634 |
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
|
1635 |
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
|
1636 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1637 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1638 |
b1 <= 255 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1639 |
"/ 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
|
1640 |
"/ b1 >= 160 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1641 |
"/ ('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
|
1642 |
"/ ]. |
2734 | 1643 |
EncodingFailedSignal |
1644 |
raiseWith:aJISString |
|
1645 |
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
|
1646 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1647 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1648 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1649 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1650 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1651 |
out nextPut:c |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1652 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1653 |
inSingleByteMode ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1654 |
out nextPutAll:kanji. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1655 |
inSingleByteMode := false |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1656 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1657 |
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
|
1658 |
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
|
1659 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1660 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1661 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1662 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1663 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1664 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1665 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1666 |
^ out contents |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1667 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1668 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1669 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1670 |
'hello' decodeFromJIS7 encodeIntoJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1671 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1672 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1673 |
"Created: 17.4.1996 / 16:17:40 / cg" |
2757 | 1674 |
"Modified: 16.7.1997 / 11:30:07 / cg" |
2721 | 1675 |
! |
1676 |
||
2731 | 1677 |
encodeIntoSJIS:aJISString |
1678 |
"return a new string with aJISStrings characters as SJIS encoded 8bit string. |
|
2733 | 1679 |
The receiver must be a JIS encoded character string. |
2731 | 1680 |
|
1681 |
The resulting string is only useful to be stored on some external file, |
|
1682 |
not for being displayed in an ST/X view." |
|
1683 |
||
1684 |
|sz "{ Class: SmallInteger }" |
|
1685 |
rval "{ Class: SmallInteger }" |
|
1686 |
val "{ Class: SmallInteger }" |
|
1687 |
romans c out isSJIS| |
|
1688 |
||
2733 | 1689 |
romans := JISEncodedString romanTable. |
2731 | 1690 |
|
1691 |
sz := aJISString size. |
|
1692 |
sz == 0 ifTrue:[^ '']. |
|
1693 |
||
1694 |
out := WriteStream on:(String new:(sz * 2)). |
|
1695 |
||
1696 |
1 to:sz do:[:srcIndex | |
|
1697 |
val := (c := aJISString at:srcIndex) asciiValue. |
|
2748 | 1698 |
val <= 128 ifTrue:[ |
1699 |
"/ a control or ascii character |
|
2731 | 1700 |
out nextPut:c. |
1701 |
] ifFalse:[ |
|
2748 | 1702 |
(val > 150 and:[val < 224]) ifTrue:[ |
2731 | 1703 |
"/ ascii subset |
1704 |
out nextPut:c. |
|
1705 |
] ifFalse:[ |
|
2748 | 1706 |
"/ should not happen ... |
1707 |
val <= 255 ifTrue:[ |
|
2731 | 1708 |
out nextPut:c. |
1709 |
] ifFalse:[ |
|
2748 | 1710 |
isSJIS := true. |
1711 |
||
1712 |
"/ check for HALFWIDTH KATAKANA |
|
1713 |
"/ 8E:xx |
|
2757 | 1714 |
"/ NO: halfwidth katakana no longer generated |
1715 |
"/ remains there as full-width katakana |
|
1716 |
||
1717 |
"/ (val bitAnd:16rFF00) == 16r8E00 ifTrue:[ |
|
1718 |
"/ |b| |
|
1719 |
"/ |
|
1720 |
"/ b := (val bitAnd:16rFF) + 128. |
|
1721 |
"/ (b >= 16rA1 "161" and:[b <= 16rDF "223"]) ifTrue:[ |
|
1722 |
"/ out nextPut:(Character value:b). |
|
1723 |
"/ isSJIS := false. |
|
1724 |
"/ ]. |
|
1725 |
"/ ]. |
|
2748 | 1726 |
|
1727 |
isSJIS ifTrue:[ |
|
1728 |
||
1729 |
"/ check for a roman character |
|
1730 |
"/ the two numbers below are romanTable min and romanTable max |
|
1731 |
"/ |
|
1732 |
(val between:16r2121 and:16r2573) ifTrue:[ |
|
1733 |
rval := romans indexOf:val. |
|
1734 |
rval ~~ 0 ifTrue:[ |
|
2757 | 1735 |
rval := rval - 1 + 32. |
1736 |
rval <= 16r7F ifTrue:[ "/ do not translate halfwidth katakana |
|
1737 |
out nextPut:(Character value:rval). |
|
1738 |
isSJIS := false. |
|
1739 |
] |
|
2731 | 1740 |
]. |
1741 |
]. |
|
2748 | 1742 |
]. |
1743 |
||
1744 |
isSJIS ifTrue:[ |
|
1745 |
|b1 b2 rowOffset cellOffset| |
|
1746 |
||
1747 |
b1 := (val bitShift:-8). |
|
1748 |
b2 := (val bitAnd:16rFF). |
|
1749 |
rowOffset := (b1 < 95) ifTrue:[112] ifFalse:[176]. |
|
1750 |
cellOffset := b1 odd ifTrue:[(b2 > 95) ifTrue:[32] ifFalse:[31]] |
|
1751 |
ifFalse:[126]. |
|
1752 |
||
1753 |
out nextPut:(Character value:(((b1 + 1) bitShift:-1) + rowOffset)). |
|
1754 |
out nextPut:(Character value:b2 + cellOffset). |
|
2731 | 1755 |
] |
1756 |
] |
|
1757 |
] |
|
1758 |
]. |
|
1759 |
]. |
|
1760 |
^ out contents |
|
1761 |
||
1762 |
"simple: |
|
1763 |
||
1764 |
'hello' decodeFromEUC encodeIntoEUC |
|
1765 |
" |
|
1766 |
||
1767 |
"Created: 28.6.1997 / 21:13:27 / cg" |
|
2757 | 1768 |
"Modified: 16.7.1997 / 11:30:45 / cg" |
2733 | 1769 |
! |
1770 |
||
7879 | 1771 |
encodeIntoUTF8:aString |
1772 |
^ aString utf8Encoded |
|
1773 |
! |
|
1774 |
||
2733 | 1775 |
encodeRomans:aTwoByteString |
1776 |
"return a new (usually 2-byte) string with roman characters |
|
1777 |
encoded. The position of roman characters are encoding specific. |
|
1778 |
(see romanTable of concrete 16-bit string classes). |
|
1779 |
Used when displaying strings." |
|
1780 |
||
1781 |
|sz "{ Class: SmallInteger }" |
|
1782 |
b "{ Class: SmallInteger }" |
|
4294 | 1783 |
c i nCode romans newString| |
2733 | 1784 |
|
1785 |
romans := self romanTable. |
|
1786 |
romans isNil ifTrue:[^ aTwoByteString]. |
|
1787 |
||
1788 |
sz := aTwoByteString size. |
|
2734 | 1789 |
newString := self fromString:aTwoByteString. |
2733 | 1790 |
|
1791 |
1 to:sz do:[:index | |
|
1792 |
c := aTwoByteString at:index. |
|
1793 |
b := c asciiValue. |
|
1794 |
||
2735 | 1795 |
(b > 32 and:[b <= 255]) ifTrue:[ |
4294 | 1796 |
(i := b - 32 + 1) <= romans size ifTrue:[ |
2734 | 1797 |
"/ |
1798 |
"/ a roman character |
|
1799 |
"/ map to corresponding row |
|
1800 |
"/ |
|
4294 | 1801 |
nCode := romans at:i. |
2734 | 1802 |
] ifFalse:[ |
4294 | 1803 |
nCode := self defaultRomanCharacterValue |
1804 |
]. |
|
1805 |
newString at:index put:(Character value:nCode). |
|
2733 | 1806 |
]. |
1807 |
]. |
|
1808 |
^ newString |
|
1809 |
||
1810 |
"Created: 30.6.1997 / 15:43:56 / cg" |
|
2735 | 1811 |
"Modified: 30.6.1997 / 21:16:20 / cg" |
2731 | 1812 |
! |
1813 |
||
2721 | 1814 |
guessEncodingFrom:aString |
1815 |
"try to guess some 8-bit strings encoding by |
|
1816 |
searching for certain escape sequences. |
|
1817 |
Returns a string or nil. |
|
1818 |
This may not find the strings real encoding." |
|
1819 |
||
1820 |
"/ look for JIS7 / EUC encoding ... |
|
1821 |
||
2733 | 1822 |
(aString findString:(JISEncodedString jisISO2022EscapeSequence)) ~~ 0 ifTrue:[ |
2760 | 1823 |
^ #'iso2020-jp' |
2733 | 1824 |
]. |
2721 | 1825 |
(aString findString:(JISEncodedString jis7KanjiEscapeSequence)) ~~ 0 ifTrue:[ |
1826 |
^ #jis7 |
|
1827 |
]. |
|
1828 |
(aString findString:(JISEncodedString oldJis7KanjiEscapeSequence)) ~~ 0 ifTrue:[ |
|
1829 |
^ #jis7 |
|
1830 |
]. |
|
1831 |
||
1832 |
"/ TODO: |
|
1833 |
||
2735 | 1834 |
"/ "/ look for EUC |
1835 |
"/ idx := aString findFirst:[:char | |ascii| |
|
1836 |
"/ ((ascii := char asciiValue) >= 16rA1) |
|
1837 |
"/ and:[ascii <= 16rFE]]. |
|
1838 |
"/ idx ~~ 0 ifTrue:[ |
|
1839 |
"/ ascii := (aString at:(idx + 1)) asciiValue. |
|
1840 |
"/ (ascii >= 16rA1 and:[ascii <= 16rFE]) ifTrue:[ |
|
1841 |
"/ ^ #euc |
|
1842 |
"/ ] |
|
1843 |
"/ ]. |
|
1844 |
||
2721 | 1845 |
"/ look for SJIS ... |
1846 |
||
1847 |
"/ look for UTS ... |
|
1848 |
||
1849 |
^ nil |
|
1850 |
||
2760 | 1851 |
"Modified: 16.7.1997 / 13:54:59 / cg" |
443 | 1852 |
! ! |
1853 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
1854 |
!CharacterArray class methodsFor:'pattern matching'! |
64 | 1855 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1856 |
matchEscapeCharacter |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1857 |
"return the character used to escape a matchCharacter |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1858 |
(i.e. make it a regular character in a matchPattern)" |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1859 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1860 |
^ $\ |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1861 |
! |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
1862 |
|
327 | 1863 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop ignoreCase:ignoreCase |
1864 |
"helper for match; return true if the characters from start to stop in |
|
1865 |
aString are matching the scan in matchScan from matchStart to matchStop. |
|
328 | 1866 |
The matchScan is as created by asMatchScanArray. |
327 | 1867 |
|
328 | 1868 |
This algorithm is not at all the most efficient; |
1869 |
for heavy duty pattern matching, an interface (primitive) to the regex |
|
1870 |
pattern matching package should be added." |
|
327 | 1871 |
|
1872 |
|matchEntry |
|
1873 |
mStart "{ Class: SmallInteger }" |
|
1874 |
mStop "{ Class: SmallInteger }" |
|
1875 |
sStart "{ Class: SmallInteger }" |
|
1876 |
sStop "{ Class: SmallInteger }" |
|
1877 |
mSize "{ Class: SmallInteger }" |
|
1878 |
sSize "{ Class: SmallInteger }" |
|
1879 |
index "{ Class: SmallInteger }" |
|
2561 | 1880 |
quickCheck matchLast nextMatchEntry |
986 | 1881 |
checkChar included| |
327 | 1882 |
|
1883 |
mStart := matchStart. |
|
1884 |
mStop := matchStop. |
|
1885 |
sStart := start. |
|
1886 |
sStop := stop. |
|
1887 |
||
1888 |
[true] whileTrue:[ |
|
3537 | 1889 |
"/ Transcript showCR:('match: ''' , (aString copyFrom:sStart to:sStop) , |
1890 |
"/ ''' against:' , (matchScanArray copyFrom:mStart to:mStop) printString). |
|
1891 |
||
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1892 |
mSize := mStop - mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1893 |
sSize := sStop - sStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1894 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1895 |
"empty strings match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1896 |
(mSize == 0) ifTrue:[^ (sSize == 0)]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1897 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1898 |
matchEntry := matchScanArray at:mStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1899 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1900 |
"/ the most common case first: |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1901 |
(sSize ~~ 0 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1902 |
and:[(checkChar := (aString at:sStart)) == matchEntry]) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1903 |
"advance by one and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1904 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1905 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1906 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1907 |
(matchEntry == #any) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1908 |
"restString empty -> no match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1909 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1910 |
"# matches single character" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1911 |
((sSize == 1) and:[mSize == 1]) ifTrue:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1912 |
"advance by one and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1913 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1914 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1915 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1916 |
(matchEntry == #anyString) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1917 |
"* alone matches anything" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1918 |
(mSize == 1) ifTrue:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1919 |
"restString empty & matchString not empty -> no match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1920 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1921 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1922 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1923 |
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
|
1924 |
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
|
1925 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1926 |
quickCheck := false. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1927 |
(mStop >= mStart) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1928 |
matchLast := matchScanArray at:mStop. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1929 |
(matchLast ~~ #anyString) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1930 |
(matchLast == #any) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1931 |
quickCheck := true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1932 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1933 |
matchLast == (aString at:sStop) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1934 |
quickCheck := true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1935 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1936 |
matchLast isString ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1937 |
quickCheck := matchLast includes:(aString at:sStop) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1938 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1939 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1940 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1941 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1942 |
]. |
3537 | 1943 |
quickCheck ifTrue:[ |
1944 |
" |
|
1945 |
quickCheck ok, advance from the right |
|
1946 |
" |
|
1947 |
mStop := mStop - 1. |
|
1948 |
sStop := sStop - 1 |
|
1949 |
] ifFalse:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1950 |
"/ no quick check; |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1951 |
"/ look for the next character(s) |
3537 | 1952 |
"/ and try matching there |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1953 |
"/ (to avoid recursion) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1954 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1955 |
mStart < mStop ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1956 |
nextMatchEntry := matchScanArray at:mStart+1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1957 |
nextMatchEntry isCharacter ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1958 |
sStart <= sStop ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1959 |
[true] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1960 |
ignoreCase ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1961 |
index := aString indexOf:nextMatchEntry startingAt:sStart |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1962 |
] ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1963 |
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
|
1964 |
startingAt:sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1965 |
]. |
3879 | 1966 |
(index == 0 or:[index > sStop]) ifTrue:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1967 |
^ false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1968 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1969 |
(self matchScan:matchScanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1970 |
from:(mStart + 1) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1971 |
to:mStop |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1972 |
with:aString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1973 |
from:index |
3537 | 1974 |
to:sStop |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1975 |
ignoreCase:ignoreCase |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1976 |
) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1977 |
^ true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1978 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1979 |
sStart := index + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1980 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1981 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1982 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1983 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1984 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1985 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1986 |
no quick check possible; |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1987 |
loop over all possible substrings |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1988 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1989 |
index := sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1990 |
[index <= sStop] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1991 |
(self matchScan:matchScanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1992 |
from:(mStart + 1) |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1993 |
to:mStop |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1994 |
with:aString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1995 |
from:index |
3537 | 1996 |
to:sStop |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1997 |
ignoreCase:ignoreCase |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1998 |
) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1999 |
^ true |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2000 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2001 |
index := index + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2002 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2003 |
^ false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2004 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2005 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2006 |
(matchEntry isString) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2007 |
"testString empty -> no match" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2008 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2009 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2010 |
included := false. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2011 |
"/ checkChar := aString at:sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2012 |
included := matchEntry includes:checkChar. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2013 |
included ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2014 |
ignoreCase ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2015 |
checkChar isUppercase ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2016 |
included := matchEntry includes:checkChar asLowercase. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2017 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2018 |
included := matchEntry includes:checkChar asUppercase. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2019 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2020 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2021 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2022 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2023 |
mSize := mSize - 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2024 |
included ifFalse:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2025 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2026 |
((sSize == 1) and:[mSize == 0]) ifTrue:[^ true]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2027 |
"cut off 1st char and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2028 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2029 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2030 |
"/ must be single character |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2031 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2032 |
"testString empty ?" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2033 |
(sSize == 0) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2034 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2035 |
"first characters equal ?" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2036 |
"/ checkChar := aString at:sStart. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2037 |
ignoreCase ifFalse:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2038 |
(checkChar asUppercase ~~ matchEntry asUppercase) ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2039 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2040 |
"advance and continue" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2041 |
mStart := mStart + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2042 |
sStart := sStart + 1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2043 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2044 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2045 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2046 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2047 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2048 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2049 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2050 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2051 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2052 |
scanArray := self matchScanArrayFrom:'*hello'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2053 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2054 |
CharacterArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2055 |
matchScan:scanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2056 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2057 |
to:scanArray size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2058 |
with:s |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2059 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2060 |
to:s size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2061 |
ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2062 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2063 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2064 |
|scanArray s| |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2065 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2066 |
scanArray := self matchScanArrayFrom:'*hello*'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2067 |
s := 'foo bar hello world'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2068 |
CharacterArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2069 |
matchScan:scanArray |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2070 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2071 |
to:scanArray size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2072 |
with:s |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2073 |
from:1 |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2074 |
to:s size |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2075 |
ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2076 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2077 |
|
3879 | 2078 |
"Modified: / 15.10.1998 / 13:39:25 / cg" |
608 | 2079 |
! |
2080 |
||
2081 |
matchScanArrayFrom:aString |
|
2082 |
"scan a pattern string and decompose it into a scanArray. |
|
2083 |
This is processed faster (especially with character ranges), and |
|
2084 |
can also be reused later. (if the same pattern is to be searched again)" |
|
2085 |
||
2086 |
|coll |
|
2087 |
idx "{ Class: SmallInteger }" |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2088 |
end c1 c2 matchSet previous escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2089 |
|
5487 | 2090 |
previous := nil. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2091 |
escape := self matchEscapeCharacter. |
608 | 2092 |
|
2093 |
coll := OrderedCollection new. |
|
2094 |
idx := 1. end := aString size. |
|
2095 |
[idx <= end] whileTrue:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2096 |
|char this| |
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 |
char := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2099 |
char == $* ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2100 |
previous ~~ #anyString ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2101 |
this := #anyString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2102 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2103 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2104 |
char == $# ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2105 |
previous ~~ #anyString ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2106 |
this := #any |
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 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2109 |
char == $[ ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2110 |
matchSet := IdentitySet new. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2111 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2112 |
idx > end ifTrue:[^ nil]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2113 |
char := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2114 |
c1 := nil. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2115 |
[char ~~ $]] whileTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2116 |
((char == $-) and:[c1 notNil]) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2117 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2118 |
idx > end ifTrue:[^ nil]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2119 |
c2 := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2120 |
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
|
2121 |
c1 := nil. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2122 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2123 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2124 |
(char ~~ $]) ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2125 |
matchSet add:char. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2126 |
c1 := char. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2127 |
idx := idx + 1 |
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 |
idx > end ifTrue:[^ nil]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2131 |
char := aString at:idx |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2132 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2133 |
this := matchSet asString |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2134 |
] ifFalse:[ |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2135 |
char == escape ifTrue:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2136 |
idx := idx + 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2137 |
idx > end ifTrue:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2138 |
"/ mhmh - what should we do here ? |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2139 |
this := char |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2140 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2141 |
this := aString at:idx. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2142 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2143 |
] ifFalse:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2144 |
this := char |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2145 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2146 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2147 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2148 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2149 |
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
|
2150 |
idx := idx + 1 |
608 | 2151 |
]. |
2152 |
||
2153 |
^ coll asArray |
|
2154 |
||
2155 |
" |
|
2156 |
String matchScanArrayFrom:'*ute*' |
|
2157 |
String matchScanArrayFrom:'**ute**' |
|
2158 |
String matchScanArrayFrom:'*uter' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2159 |
String matchScanArrayFrom:'\*uter' |
608 | 2160 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
2161 |
String matchScanArrayFrom:'[abcd]*' |
|
2162 |
String matchScanArrayFrom:'[a-k]*' |
|
2163 |
String matchScanArrayFrom:'*some*compl*ern*' |
|
2164 |
String matchScanArrayFrom:'[a-' |
|
2165 |
String matchScanArrayFrom:'[a-zA-Z]' |
|
2166 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
|
2167 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2168 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2169 |
"Modified: 2.4.1997 / 16:20:29 / cg" |
608 | 2170 |
! ! |
2171 |
||
7261 | 2172 |
!CharacterArray methodsFor:'Compatibility-ANSI'! |
5301
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2173 |
|
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2174 |
addLineDelimiters |
6184 | 2175 |
"Ansi compatibility - same as withCRs" |
2176 |
||
5301
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2177 |
^ self withCRs |
6184 | 2178 |
|
2179 |
"Modified: / 13.11.2001 / 19:16:25 / cg" |
|
5301
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2180 |
! ! |
7bef885c778a
compatibility stuff: <s> in #expandMacros
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
2181 |
|
7261 | 2182 |
!CharacterArray methodsFor:'Compatibility-Dolphin'! |
6391 | 2183 |
|
2184 |
argumentCount |
|
6870 | 2185 |
"same as #numArgs - return the number of arguments a message with myself |
2186 |
as selector would take." |
|
2187 |
||
6391 | 2188 |
^ self numArgs |
6870 | 2189 |
! |
2190 |
||
2191 |
copyExpanding:expandTable |
|
2192 |
"return a copy of myself, with translations from the expandTable sliced in. |
|
2193 |
The argument is supposed to map from characters to either characters or strings." |
|
2194 |
||
2195 |
|ds| |
|
2196 |
||
2197 |
ds := WriteStream on:(self species new). |
|
2198 |
self do:[:eachChar | |
|
2199 |
|repl| |
|
2200 |
||
2201 |
repl := expandTable at:eachChar ifAbsent:nil. |
|
2202 |
repl isNil ifTrue:[ |
|
2203 |
ds nextPut:eachChar |
|
2204 |
] ifFalse:[ |
|
2205 |
repl size == 0 ifTrue:[ |
|
2206 |
ds nextPut:repl |
|
2207 |
] ifFalse:[ |
|
2208 |
ds nextPutAll:repl |
|
2209 |
] |
|
2210 |
]. |
|
2211 |
]. |
|
2212 |
^ ds contents. |
|
2213 |
! |
|
2214 |
||
2215 |
formatWith:aString |
|
2216 |
"same as #bindWith: for dolphin compatibility" |
|
2217 |
||
2218 |
^ self bindWith:aString |
|
2219 |
||
2220 |
" |
|
2221 |
'hello%1world' formatWith:'123' |
|
2222 |
" |
|
2223 |
! |
|
2224 |
||
2225 |
formatWith:arg1 with:arg2 |
|
2226 |
"same as #bindWith: for dolphin compatibility" |
|
2227 |
||
2228 |
^ self bindWith:arg1 with:arg2 |
|
2229 |
||
2230 |
" |
|
2231 |
'hello%1 %2world' formatWith:'123' with:234 |
|
2232 |
" |
|
2233 |
! |
|
2234 |
||
2235 |
formatWith:arg1 with:arg2 with:arg3 |
|
2236 |
"same as #bindWith: for dolphin compatibility" |
|
2237 |
||
2238 |
^ self bindWith:arg1 with:arg2 with:arg3 |
|
2239 |
||
2240 |
" |
|
2241 |
'hello%1 %2 %3world' formatWith:'123' with:234 with:345 |
|
2242 |
" |
|
6391 | 2243 |
! ! |
2244 |
||
7261 | 2245 |
!CharacterArray methodsFor:'Compatibility-ST/V'! |
608 | 2246 |
|
2247 |
byteAt:index put:aByte |
|
2248 |
"store a byte at given index. |
|
2249 |
This is an ST/V compatibility method." |
|
2250 |
||
1333
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2251 |
"/ (aByte == 0) ifTrue:[ |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2252 |
"/ "store a space instead" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2253 |
"/ ^ 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
|
2254 |
"/ ]. |
608 | 2255 |
^ 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
|
2256 |
|
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2257 |
" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2258 |
'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
|
2259 |
'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
|
2260 |
'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
|
2261 |
" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2262 |
|
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
2263 |
"Modified: 6.5.1996 / 10:35:26 / cg" |
608 | 2264 |
! |
2265 |
||
2266 |
replChar:oldChar with:newChar |
|
2267 |
"return a copy of the receiver, with all oldChars replaced |
|
2268 |
by newChar. |
|
2269 |
This is an ST/V compatibility method." |
|
2270 |
||
3656 | 2271 |
^ self copyReplaceAll:oldChar with:newChar |
608 | 2272 |
|
2273 |
" |
|
2274 |
'12345678901234567890' replChar:$0 with:$* |
|
2275 |
" |
|
3656 | 2276 |
|
2277 |
"Modified: / 18.7.1998 / 22:52:57 / cg" |
|
608 | 2278 |
! |
2279 |
||
2280 |
replChar:oldChar withString:newString |
|
2281 |
"return a copy of the receiver, with all oldChars replaced |
|
2282 |
by newString (i.e. slice in the newString in place of the oldChar). |
|
2283 |
This is an ST/V compatibility method." |
|
2284 |
||
2285 |
|tmpStream| |
|
2286 |
||
2287 |
tmpStream := WriteStream on:(self class new). |
|
2288 |
self do:[:element | |
|
2289 |
element = oldChar ifTrue:[ |
|
2290 |
tmpStream nextPutAll:newString |
|
2291 |
] ifFalse:[ |
|
2292 |
tmpStream nextPut:element |
|
2293 |
]. |
|
2294 |
]. |
|
2295 |
^ tmpStream contents |
|
2296 |
||
2297 |
" |
|
2298 |
'12345678901234567890' replChar:$0 withString:'foo' |
|
2299 |
'a string with spaces' replChar:$ withString:' foo ' |
|
2300 |
" |
|
2301 |
! |
|
2302 |
||
4244
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2303 |
replString:subString withString:newString |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2304 |
"return a copy of the receiver, with all sequences of subString replaced |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2305 |
by newString (i.e. slice in the newString in place of the oldString)." |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2306 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2307 |
|tmpStream idx idx1| |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2308 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2309 |
tmpStream := WriteStream on:(self class new). |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2310 |
idx := 1. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2311 |
[idx ~~ 0] whileTrue:[ |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2312 |
idx1 := idx. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2313 |
idx := self indexOfSubCollection:subString startingAt:idx. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2314 |
idx ~~ 0 ifTrue:[ |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2315 |
tmpStream nextPutAll:(self copyFrom:idx1 to:idx-1). |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2316 |
tmpStream nextPutAll:newString. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2317 |
idx := idx + subString size |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2318 |
] |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2319 |
]. |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2320 |
tmpStream nextPutAll:(self copyFrom:idx1). |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2321 |
^ tmpStream contents |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2322 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2323 |
" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2324 |
'12345678901234567890' replString:'123' withString:'OneTwoThree' |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2325 |
'12345678901234567890' replString:'123' withString:'*' |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2326 |
'12345678901234567890' replString:'234' withString:'foo' |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2327 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2328 |
('a string with spaces' replChar:$ withString:' foo ') |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2329 |
replString:'foo' withString:'bar' |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2330 |
" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2331 |
|
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2332 |
"Modified: / 31.5.1999 / 12:33:59 / cg" |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2333 |
! |
5deefa3144fb
added #replString:withString:
Claus Gittinger <cg@exept.de>
parents:
4156
diff
changeset
|
2334 |
|
608 | 2335 |
trimBlanks |
2336 |
"return a copy of the receiver without leading |
|
2337 |
and trailing spaces. |
|
2338 |
This is an ST/V compatibility method." |
|
2339 |
||
2340 |
^ self withoutSpaces |
|
2341 |
||
2342 |
" |
|
2343 |
' spaces at beginning' trimBlanks |
|
2344 |
'spaces at end ' trimBlanks |
|
2345 |
' spaces at beginning and end ' trimBlanks |
|
2346 |
'no spaces' trimBlanks |
|
2347 |
" |
|
2348 |
! ! |
|
2349 |
||
7261 | 2350 |
!CharacterArray methodsFor:'Compatibility-Squeak'! |
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2351 |
|
6148 | 2352 |
asDate |
2353 |
"Many allowed forms, see Date.readFrom:" |
|
2354 |
||
2355 |
^ Date readFrom: (ReadStream on: self) |
|
2356 |
||
2357 |
" |
|
2358 |
'30 Apr 1999' asDate dayName capitalized |
|
2359 |
" |
|
2360 |
! |
|
2361 |
||
4989 | 2362 |
capitalized |
2363 |
^ self asUppercaseFirst |
|
2364 |
||
2365 |
" |
|
2366 |
'hello' capitalized |
|
2367 |
" |
|
2368 |
! |
|
2369 |
||
5632 | 2370 |
displayProgressAt:aPointOrNil from:start to:stop during:aBlock |
2371 |
ProgressIndicator |
|
2372 |
displayProgress:self |
|
2373 |
at:aPointOrNil |
|
2374 |
from:start |
|
2375 |
to:stop |
|
2376 |
during:aBlock. |
|
2377 |
||
2378 |
" |
|
2379 |
'dobedobedoobedoo' |
|
2380 |
displayProgressAt:(Screen current center) |
|
2381 |
from:0 to:100 |
|
2382 |
during:[:val | |
|
2383 |
0 to:100 do:[:i | |
|
2384 |
val value:i. |
|
2385 |
Delay waitForSeconds:0.05. |
|
2386 |
] |
|
2387 |
] |
|
2388 |
" |
|
2389 |
! |
|
2390 |
||
5794 | 2391 |
endsWithDigit |
2392 |
"Answer whether the receiver's final character represents a digit. 3/11/96 sw" |
|
2393 |
||
2394 |
^ self size > 0 and: [self last isDigit] |
|
2395 |
! |
|
2396 |
||
4981 | 2397 |
findTokens:delimiters |
7270 | 2398 |
"cg: I am not sure, if this is really the squeak semantics (w.r.t. empty fields)" |
2399 |
||
4981 | 2400 |
^ self asCollectionOfSubstringsSeparatedByAny:delimiters |
7270 | 2401 |
|
2402 |
" |
|
2403 |
'a|b#c||e' findTokens:#($# $|) |
|
2404 |
" |
|
4981 | 2405 |
! |
2406 |
||
4974 | 2407 |
includesSubString:aString |
2408 |
"return true, if a substring is contained in the receiver. |
|
2409 |
The compare is case sensitive." |
|
2410 |
||
2411 |
^ self includesString:aString |
|
2412 |
||
2413 |
" |
|
2414 |
'hello world' includesSubString:'Hel' |
|
2415 |
'hello world' includesSubString:'hel' |
|
2416 |
'hello world' includesSubString:'llo' |
|
2417 |
" |
|
2418 |
||
2419 |
||
2420 |
||
2421 |
! |
|
2422 |
||
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2423 |
includesSubstring:aString caseSensitive:caseSensitive |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2424 |
"return true, if a substring is contained in the receiver. |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2425 |
The argument, caseSensitive controls if case is ignored in the compare." |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2426 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2427 |
"/ for now, a q&d hack ... |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2428 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2429 |
caseSensitive ifFalse:[ |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2430 |
^ self asLowercase includesString:aString asLowercase |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2431 |
]. |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2432 |
^ self includesString:aString |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2433 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2434 |
" |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2435 |
'hello world' includesSubstring:'Hel' caseSensitive:true |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2436 |
'hello world' includesSubstring:'Hel' caseSensitive:false |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2437 |
" |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2438 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2439 |
|
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2440 |
|
4890 | 2441 |
! |
2442 |
||
6979 | 2443 |
isAllDigits |
2444 |
"Answer whether the receiver's characters are all digits" |
|
2445 |
||
2446 |
^ self conform:[:eachChar | eachChar isDigit] |
|
2447 |
||
2448 |
" |
|
2449 |
'hello world' isAllDigits |
|
2450 |
'12344' isAllDigits |
|
2451 |
" |
|
2452 |
! |
|
2453 |
||
4890 | 2454 |
lastSpacePosition |
2455 |
^ self lastIndexOfSeparator |
|
2456 |
! |
|
2457 |
||
7022 | 2458 |
padded:leftOrRight to:paddedSize with:padCharacter |
2459 |
leftOrRight == #left ifTrue:[ |
|
2460 |
^ self leftPaddedTo:paddedSize with:padCharacter |
|
2461 |
]. |
|
2462 |
^ self paddedTo:paddedSize with:padCharacter |
|
2463 |
||
2464 |
" |
|
2465 |
'hello' padded:#right to:10 with:$. |
|
2466 |
'hello' padded:#left to:10 with:$. |
|
2467 |
" |
|
2468 |
! |
|
2469 |
||
7691 | 2470 |
skipDelimiters:delimiters startingAt:start |
2471 |
"Answer the index of the character within the receiver, starting at start, |
|
2472 |
that does NOT match one of the delimiters. |
|
2473 |
If the receiver does not contain any of the delimiters, answer size + 1. |
|
2474 |
Assumes the delimiters to be a non-empty string." |
|
2475 |
||
2476 |
start to:self size do:[:i | |
|
2477 |
delimiters detect:[:delim | delim = (self at:i) ] ifNone:[ ^ i ] |
|
2478 |
]. |
|
2479 |
^ self size + 1 |
|
2480 |
||
2481 |
" |
|
2482 |
'123***7890' skipDelimiters:'*' startingAt:4 |
|
2483 |
'123***7890' skipDelimiters:'*' startingAt:3 |
|
2484 |
'123***7890' skipDelimiters:'*' startingAt:10 |
|
2485 |
'123*******' skipDelimiters:'*' startingAt:10 |
|
2486 |
" |
|
2487 |
! |
|
2488 |
||
6948 | 2489 |
substrings |
2490 |
^ self asCollectionOfWords |
|
2491 |
||
2492 |
" |
|
2493 |
'foo bar baz' substrings |
|
2494 |
" |
|
2495 |
! |
|
2496 |
||
5795 | 2497 |
truncateTo:smallSize |
2498 |
"return myself or a copy shortened to smallSize. 1/18/96 sw" |
|
2499 |
||
2500 |
self size <= smallSize ifTrue:[^ self]. |
|
2501 |
^ self copyFrom: 1 to: smallSize |
|
2502 |
||
2503 |
" |
|
2504 |
'hello world' truncateTo:5 |
|
2505 |
'hello' truncateTo:10 |
|
2506 |
||
2507 |
'hello world' copyTo:5 |
|
2508 |
'hello' copyTo:10 |
|
2509 |
" |
|
2510 |
! |
|
2511 |
||
4890 | 2512 |
withBlanksTrimmed |
2513 |
"Return a copy of the receiver from which leading and trailing blanks have been trimmed." |
|
2514 |
||
2515 |
^ self withoutSpaces |
|
2516 |
||
2517 |
" |
|
2518 |
' hello world ' withBlanksTrimmed |
|
2519 |
" |
|
2520 |
||
2521 |
||
2522 |
||
2523 |
! |
|
2524 |
||
2525 |
withNoLineLongerThan: aNumber |
|
2526 |
"Answer a string with the same content as receiver, but rewrapped so that no line has more characters than the given number" |
|
2527 |
||
2528 |
| listOfLines currentLast currentStart resultString putativeLast putativeLine crPosition | |
|
2529 |
||
2530 |
aNumber isNumber not | (aNumber < 1) ifTrue: [self error: 'too narrow']. |
|
2531 |
listOfLines _ OrderedCollection new. |
|
2532 |
currentLast _ 0. |
|
2533 |
[currentLast < self size] whileTrue: |
|
2534 |
[currentStart _ currentLast + 1. |
|
2535 |
putativeLast _ (currentStart + aNumber - 1) min: self size. |
|
2536 |
putativeLine _ self copyFrom: currentStart to: putativeLast. |
|
2537 |
(crPosition _ putativeLine indexOf: Character cr) > 0 ifTrue: |
|
2538 |
[putativeLast _ currentStart + crPosition - 1. |
|
2539 |
putativeLine _ self copyFrom: currentStart to: putativeLast]. |
|
2540 |
currentLast _ putativeLast == self size |
|
2541 |
ifTrue: |
|
2542 |
[putativeLast] |
|
2543 |
ifFalse: |
|
2544 |
[currentStart + putativeLine lastSpacePosition - 1]. |
|
2545 |
currentLast <= currentStart ifTrue: |
|
2546 |
["line has NO spaces; baleout!!" |
|
2547 |
currentLast _ putativeLast]. |
|
2548 |
listOfLines add: (self copyFrom: currentStart to: currentLast) withBlanksTrimmed]. |
|
2549 |
||
2550 |
listOfLines size > 0 ifFalse: [^ '']. |
|
2551 |
resultString _ listOfLines first. |
|
2552 |
2 to: listOfLines size do: |
|
2553 |
[:i | resultString _ resultString, Character cr asString, (listOfLines at: i)]. |
|
2554 |
^ resultString |
|
2555 |
||
2556 |
" |
|
2557 |
#(5 7 20) collect: |
|
2558 |
[:i | 'Fred the bear went down to the brook to read his book in silence' withNoLineLongerThan: i] |
|
2559 |
" |
|
2560 |
||
2561 |
||
2562 |
||
4409
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2563 |
! ! |
86e049b21f8d
added #includesSubstring:caseSensitive:
Claus Gittinger <cg@exept.de>
parents:
4389
diff
changeset
|
2564 |
|
7261 | 2565 |
!CharacterArray methodsFor:'Compatibility-V''Age'! |
608 | 2566 |
|
2567 |
addLineDelimiter |
|
2568 |
"replace all '\'-characters by line delimiter (cr) - characters. |
|
2569 |
This has been added for VisualAge compatibility." |
|
2570 |
||
2571 |
^ self withCRs |
|
2572 |
! |
|
2573 |
||
2574 |
bindWith:aString |
|
2575 |
"return a copy of the receiver, where a '%1' escape is |
|
2576 |
replaced by aString. |
|
2577 |
This has been added for VisualAge compatibility." |
|
2578 |
||
2579 |
^ self expandPlaceholdersWith:(Array with:aString) |
|
2580 |
||
2581 |
" |
|
2582 |
'do you like %1 ?' bindWith:'smalltalk' |
|
2583 |
" |
|
2584 |
! |
|
2585 |
||
2586 |
bindWith:string1 with:string2 |
|
2587 |
"return a copy of the receiver, where a '%1' escape is |
|
2588 |
replaced by string1 and '%2' is replaced by string2. |
|
2589 |
This has been added for VisualAge compatibility." |
|
2590 |
||
2591 |
^ self expandPlaceholdersWith:(Array with:string1 with:string2) |
|
2592 |
||
2593 |
" |
|
2594 |
'do you prefer %1 or rather %2 ?' |
|
2595 |
bindWith:'smalltalk' with:'c++' |
|
2596 |
" |
|
2597 |
! |
|
2598 |
||
2599 |
bindWith:str1 with:str2 with:str3 |
|
2600 |
"return a copy of the receiver, where a '%1', '%2' and '%3' escapes |
|
2601 |
are replaced by str1, str2 and str3 respectively. |
|
2602 |
This has been added for VisualAge compatibility." |
|
2603 |
||
2604 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3) |
|
2605 |
||
2606 |
" |
|
2607 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
2608 |
bindWith:'smalltalk' with:'c++' with:'c' |
|
2609 |
" |
|
2610 |
! |
|
2611 |
||
2612 |
bindWith:str1 with:str2 with:str3 with:str4 |
|
2613 |
"return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes |
|
2614 |
are replaced by str1, str2, str3 and str4 respectively. |
|
2615 |
This has been added for VisualAge compatibility." |
|
2616 |
||
2617 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4) |
|
2618 |
||
2619 |
" |
|
2620 |
'do you prefer %1 or rather %2 (not talking about %3 or even %4) ?' |
|
2621 |
bindWith:'smalltalk' with:'c++' with:'c' with:'assembler' |
|
2622 |
" |
|
2623 |
! |
|
2624 |
||
2344 | 2625 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 |
2626 |
"return a copy of the receiver, where a '%1' .. '%5' escapes |
|
2627 |
are replaced by str1 .. str5 respectively. |
|
2628 |
This has been added for VisualAge compatibility." |
|
2629 |
||
2630 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5) |
|
2631 |
||
2632 |
"Created: 31.1.1997 / 16:25:42 / cg" |
|
2633 |
! |
|
2634 |
||
5343 | 2635 |
bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 |
2636 |
"return a copy of the receiver, where a '%1' .. '%6' escapes |
|
2637 |
are replaced by str1 .. str5 respectively. |
|
2638 |
This has been added for VisualAge compatibility." |
|
2639 |
||
2640 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
|
2641 |
with:str3 with:str4 |
|
2642 |
with:str5 with:str6) |
|
2643 |
||
2644 |
! |
|
2645 |
||
608 | 2646 |
bindWithArguments:anArrayOfStrings |
2647 |
"return a copy of the receiver, where a '%i' escape |
|
2648 |
is replaced by the coresponding string from the argument array. |
|
2649 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
2650 |
This has been added for VisualAge compatibility." |
|
2651 |
||
2652 |
^ self expandPlaceholdersWith:anArrayOfStrings |
|
2653 |
||
2654 |
" |
|
2655 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
2656 |
bindWithArguments:#('smalltalk' 'c++' 'c') |
|
2657 |
" |
|
2658 |
! |
|
2659 |
||
2660 |
subStrings |
|
2661 |
"return an array consisting of all words contained in the receiver. |
|
2662 |
Words are separated by whitespace. |
|
2663 |
This has been added for VisualAge compatibility." |
|
2664 |
||
2665 |
^ self asCollectionOfWords |
|
2666 |
||
2667 |
" |
|
2668 |
'hello world, this is smalltalk' subStrings |
|
2669 |
" |
|
2670 |
! |
|
2671 |
||
2672 |
subStrings:separatorCharacter |
|
2673 |
"return an array consisting of all words contained in the receiver. |
|
2674 |
Words are separated by separatorCharacter. |
|
2675 |
This has been added for VisualAge compatibility." |
|
2676 |
||
2677 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter |
|
2678 |
||
2679 |
" |
|
2680 |
'foo:bar:baz:smalltalk' subStrings:$: |
|
2681 |
" |
|
2682 |
! |
|
2683 |
||
2684 |
trimSeparators |
|
2685 |
"return a copy of the receiver without leading and trailing whiteSpace" |
|
2686 |
||
2687 |
^ self withoutSeparators |
|
2688 |
! ! |
|
2689 |
||
7261 | 2690 |
!CharacterArray methodsFor:'Compatibility-VW'! |
5964 | 2691 |
|
6139 | 2692 |
asLogicalFileSpecification |
2693 |
^ self asFilename |
|
2694 |
||
2695 |
"Created: / 30.10.2001 / 17:29:53 / cg" |
|
2696 |
! |
|
2697 |
||
6119 | 2698 |
asQualifiedReference |
2699 |
^ BindingReference pathString:(self string) |
|
2700 |
||
2701 |
! |
|
2702 |
||
5964 | 2703 |
expandMacros |
2704 |
"ST80 compatibility - expand '<..>' macros with |
|
2705 |
argument strings. Similar to #bindWith:. |
|
2706 |
Read the comment in #expandMacrosWithArguments: about |
|
2707 |
limited compatibility issues." |
|
2708 |
||
2709 |
^ self expandMacrosWithArguments:#() |
|
2710 |
||
2711 |
" |
|
2712 |
'hello<n>foo' expandMacros |
|
2713 |
" |
|
2714 |
||
2715 |
"Modified: / 18.6.1998 / 16:03:02 / cg" |
|
2716 |
! |
|
2717 |
||
2718 |
expandMacrosWith:arg |
|
2719 |
"ST80 compatibility - expand '<..>' macros with |
|
2720 |
argument strings. Similar to #bindWith:. |
|
2721 |
Read the comment in #expandMacrosWithArguments: about |
|
2722 |
limited compatibility issues." |
|
2723 |
||
2724 |
^ self expandMacrosWithArguments:(Array with:arg) |
|
2725 |
||
2726 |
"Created: / 1.11.1997 / 13:01:28 / cg" |
|
2727 |
"Modified: / 1.11.1997 / 13:30:50 / cg" |
|
2728 |
! |
|
2729 |
||
2730 |
expandMacrosWith:arg1 with:arg2 |
|
2731 |
"ST80 compatibility - expand '<..>' macros with |
|
2732 |
argument strings. Similar to #bindWith:. |
|
2733 |
Read the comment in #expandMacrosWithArguments: about |
|
2734 |
limited compatibility issues." |
|
2735 |
||
2736 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2) |
|
2737 |
||
2738 |
"Modified: / 6.7.1998 / 21:58:14 / cg" |
|
2739 |
! |
|
2740 |
||
2741 |
expandMacrosWith:arg1 with:arg2 with:arg3 |
|
2742 |
"ST80 compatibility - expand '<..>' macros with |
|
2743 |
argument strings. Similar to #bindWith:. |
|
2744 |
Read the comment in #expandMacrosWithArguments: about |
|
2745 |
limited compatibility issues." |
|
2746 |
||
2747 |
^ self expandMacrosWithArguments:(Array with:arg1 with:arg2 with:arg3) |
|
2748 |
! |
|
2749 |
||
2750 |
expandMacrosWithArguments:argArray |
|
2751 |
"ST80 compatibility - expand '<..>' macros with |
|
2752 |
argument strings. Similar to #bindWith:. |
|
2753 |
WARNING: possibly not all ST80 expansions are supported here." |
|
2754 |
||
2755 |
"/ supported expansions: |
|
2756 |
"/ |
|
2757 |
"/ <#p> # is arg Number; slice in the args printString |
|
2758 |
"/ <#s> # is arg Number; slice in the arg itself (must be a String) |
|
2759 |
"/ <#?s1:s2> # is arg Number; slice in s1 if the arg is true, s2 otherwise |
|
7643 | 2760 |
"/ use first arg if # is not given (i.e. no number before s,p ...) |
5964 | 2761 |
"/ <n> replace by a newLine character |
2762 |
"/ <t> replace by a tab character |
|
6834
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2763 |
"/ %X the X character itself |
5964 | 2764 |
|
2765 |
|in out c fmt nr arg s1 s2| |
|
2766 |
||
2767 |
in := self readStream. |
|
2768 |
out := '' writeStream. |
|
2769 |
||
2770 |
[in atEnd] whileFalse:[ |
|
2771 |
c := in next. |
|
6834
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2772 |
c == $% ifTrue:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2773 |
c := in next. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2774 |
out nextPut:c |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2775 |
] ifFalse:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2776 |
c == $< ifTrue:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2777 |
[in peek == $<] whileTrue:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2778 |
out nextPut:$<. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2779 |
in next. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2780 |
]. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2781 |
in peek == $n ifTrue:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2782 |
out nextPut:Character cr. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2783 |
in next |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2784 |
] ifFalse:[in peek == $t ifTrue:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2785 |
out nextPut:Character tab. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2786 |
in next |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2787 |
] ifFalse:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2788 |
in peek isDigit ifFalse:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2789 |
nr := 1 |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2790 |
] ifTrue:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2791 |
"/ start an argument expansion ... |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2792 |
nr := Integer readFrom:in onError:nil. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2793 |
nr isNil ifTrue:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2794 |
"/ what does VW do here ? |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2795 |
self error:'invalid format' mayProceed:true. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2796 |
^ self |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2797 |
]. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2798 |
(nr between:1 and:argArray size) ifFalse:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2799 |
"/ what does VW do here ? |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2800 |
self error:'invalid format - bad argNr' mayProceed:true. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2801 |
^ self |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2802 |
]. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2803 |
]. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2804 |
arg := argArray at:nr. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2805 |
|
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2806 |
fmt := in next. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2807 |
(fmt == $p) ifTrue:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2808 |
"/ expand with args printString |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2809 |
out nextPutAll:arg printString. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2810 |
] ifFalse:[ (fmt == $s) ifTrue:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2811 |
"/ expand with arg itself |
7569
a90fffe48d5e
handle text arguments (bold...)
Claus Gittinger <cg@exept.de>
parents:
7555
diff
changeset
|
2812 |
arg isText ifTrue:[ |
a90fffe48d5e
handle text arguments (bold...)
Claus Gittinger <cg@exept.de>
parents:
7555
diff
changeset
|
2813 |
out := (WriteStream on:(Text new)) nextPutAll:(out contents); yourself. |
a90fffe48d5e
handle text arguments (bold...)
Claus Gittinger <cg@exept.de>
parents:
7555
diff
changeset
|
2814 |
out nextPutAll:arg asText. |
a90fffe48d5e
handle text arguments (bold...)
Claus Gittinger <cg@exept.de>
parents:
7555
diff
changeset
|
2815 |
] ifFalse:[ |
a90fffe48d5e
handle text arguments (bold...)
Claus Gittinger <cg@exept.de>
parents:
7555
diff
changeset
|
2816 |
out nextPutAll:arg asString. |
a90fffe48d5e
handle text arguments (bold...)
Claus Gittinger <cg@exept.de>
parents:
7555
diff
changeset
|
2817 |
] |
6834
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2818 |
] ifFalse:[ (fmt == $?) ifTrue:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2819 |
s1 := in upTo:$:. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2820 |
s2 := in nextUpTo:$>. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2821 |
arg ifTrue:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2822 |
out nextPutAll:s1 |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2823 |
] ifFalse:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2824 |
out nextPutAll:s2 |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2825 |
]. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2826 |
] ifFalse:[ |
5964 | 2827 |
"/ what does VW do here ? |
2828 |
self error:'invalid format' mayProceed:true. |
|
2829 |
^ self |
|
6834
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2830 |
]]]. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2831 |
]]. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2832 |
c := in next. |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2833 |
c ~~ $> ifTrue:[ |
5964 | 2834 |
"/ what does VW do here ? |
2835 |
self error:'invalid format' mayProceed:true. |
|
2836 |
^ self |
|
6834
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2837 |
] |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2838 |
] ifFalse:[ |
eba4b58b8692
fixed expandMacros (%-escape)
Claus Gittinger <cg@exept.de>
parents:
6810
diff
changeset
|
2839 |
out nextPut:c |
5964 | 2840 |
] |
2841 |
]. |
|
2842 |
]. |
|
2843 |
^ out contents |
|
2844 |
||
2845 |
" |
|
2846 |
'hello <1p> how are you' expandMacrosWith:(OperatingSystem getLoginName) |
|
2847 |
" |
|
2848 |
||
2849 |
"Modified: / 18.6.1998 / 16:04:46 / cg" |
|
2850 |
! ! |
|
2851 |
||
608 | 2852 |
!CharacterArray methodsFor:'character searching'! |
2853 |
||
2854 |
includesMatchCharacters |
|
2855 |
"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
|
2856 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2857 |
Here, do not care for $\ escapes" |
608 | 2858 |
|
2859 |
^ self includesAny:'*#[' |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2860 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2861 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2862 |
'*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2863 |
'\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2864 |
'\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2865 |
'*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2866 |
'\\*foo' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2867 |
'foo*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2868 |
'foo\*' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2869 |
'foo\' includesMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2870 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2871 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2872 |
"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
|
2873 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2874 |
|
6998 | 2875 |
includesSeparator |
2876 |
"return true, if the receiver contains any whitespace characters" |
|
2877 |
||
2878 |
^ (self indexOfSeparator ~~ 0) |
|
2879 |
||
2880 |
" |
|
2881 |
'hello world' includesSeparator |
|
2882 |
'helloworld' includesSeparator |
|
2883 |
" |
|
2884 |
! |
|
2885 |
||
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2886 |
includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2887 |
"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
|
2888 |
for match operations; false if not. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2889 |
Here, care for $\ escapes" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2890 |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2891 |
|idx sz specialChars escape| |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2892 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2893 |
idx := 1. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2894 |
sz := self size. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2895 |
specialChars := '*#[\'. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2896 |
(escape := self class matchEscapeCharacter) ~~ $\ ifTrue:[ |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2897 |
specialChars := specialChars copy. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2898 |
specialChars at:specialChars size put:escape |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2899 |
]. |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2900 |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2901 |
[true] whileTrue:[ |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2902 |
idx := self indexOfAny:specialChars startingAt:idx. |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2903 |
idx == 0 ifTrue:[^ false]. |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2904 |
(self at:idx) == escape ifFalse:[^ true]. |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2905 |
idx := idx + 2. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2906 |
idx > sz ifTrue:[^ false]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2907 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2908 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2909 |
" |
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2910 |
'*foo' includesUnescapedMatchCharacters |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2911 |
'\*foo' includesUnescapedMatchCharacters |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2912 |
'\\foo' includesUnescapedMatchCharacters |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
2913 |
'\\\$foo' includesUnescapedMatchCharacters |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2914 |
'*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2915 |
'\\*foo' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2916 |
'foo*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2917 |
'foo\*' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2918 |
'foo\' includesUnescapedMatchCharacters |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2919 |
" |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2920 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
2921 |
"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
|
2922 |
"Created: 2.4.1997 / 17:23:26 / cg" |
608 | 2923 |
! |
2924 |
||
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2925 |
indexOfControlCharacterStartingAt:startIndex |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2926 |
"return the index of the next control character; |
4117 | 2927 |
starting the search at startIndex, searching forward; |
3668
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2928 |
that is a character with asciiValue < 32. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2929 |
Return 0 if none is found." |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2930 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2931 |
|start "{ Class: SmallInteger }" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2932 |
mySize "{ Class: SmallInteger }"| |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2933 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2934 |
start := startIndex. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2935 |
mySize := self size. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2936 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2937 |
start to:mySize do:[:index | |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2938 |
(self at:index) isControlCharacter ifTrue:[^ index] |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2939 |
]. |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2940 |
^ 0 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2941 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2942 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2943 |
'hello world' asTwoByteString indexOfControlCharacterStartingAt:1 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2944 |
'hello world\foo' withCRsasTwoByteString indexOfControlCharacterStartingAt:1 |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2945 |
" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2946 |
|
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2947 |
"Modified: / 21.7.1998 / 17:25:07 / cg" |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2948 |
! |
76271941f044
added #indexOfControlCharacterStartingAt:
Claus Gittinger <cg@exept.de>
parents:
3656
diff
changeset
|
2949 |
|
608 | 2950 |
indexOfNonSeparatorStartingAt:startIndex |
4117 | 2951 |
"return the index of the next non-whitespace character, |
2952 |
starting the search at startIndex, searching forward; |
|
2953 |
return 0 if no non-separator was found" |
|
608 | 2954 |
|
2955 |
|start "{ Class: SmallInteger }" |
|
2956 |
mySize "{ Class: SmallInteger }"| |
|
2957 |
||
2958 |
start := startIndex. |
|
2959 |
mySize := self size. |
|
2960 |
||
2961 |
start to:mySize do:[:index | |
|
4117 | 2962 |
(self at:index) isSeparator ifFalse:[^ index] |
608 | 2963 |
]. |
2964 |
^ 0 |
|
2965 |
||
2966 |
" |
|
2967 |
' hello world' indexOfNonSeparatorStartingAt:1 |
|
4117 | 2968 |
' ' indexOfNonSeparatorStartingAt:1 |
2969 |
'a ' indexOfNonSeparatorStartingAt:2 |
|
2970 |
" |
|
2971 |
||
608 | 2972 |
" |
2973 |
|s index1 index2| |
|
2974 |
s := ' foo bar baz'. |
|
2975 |
index1 := s indexOfNonSeparatorStartingAt:1. |
|
2976 |
index2 := s indexOfSeparatorStartingAt:index1. |
|
2977 |
s copyFrom:index1 to:index2 - 1 |
|
2978 |
" |
|
2979 |
! |
|
2980 |
||
2981 |
indexOfSeparator |
|
4117 | 2982 |
"return the index of the first whitespace character; |
2983 |
starting the search at the beginning, searching forward; |
|
2984 |
return 0 if no separator was found" |
|
608 | 2985 |
|
2986 |
^ self indexOfSeparatorStartingAt:1 |
|
2987 |
||
4117 | 2988 |
" |
2989 |
'hello world' indexOfSeparator |
|
2990 |
'helloworld' indexOfSeparator |
|
2991 |
'hello ' indexOfSeparator |
|
2992 |
' hello' indexOfSeparator |
|
2993 |
" |
|
608 | 2994 |
! |
2995 |
||
2996 |
indexOfSeparatorStartingAt:startIndex |
|
4117 | 2997 |
"return the index of the next whitespace character, |
2998 |
starting the search at startIndex, searching forward; |
|
2999 |
return 0 if no separator was found" |
|
608 | 3000 |
|
3001 |
|start "{ Class: SmallInteger }" |
|
3002 |
mySize "{ Class: SmallInteger }"| |
|
3003 |
||
3004 |
start := startIndex. |
|
3005 |
mySize := self size. |
|
3006 |
||
3007 |
start to:mySize do:[:index | |
|
4117 | 3008 |
(self at:index) isSeparator ifTrue:[^ index] |
608 | 3009 |
]. |
3010 |
^ 0 |
|
3011 |
||
4117 | 3012 |
" |
3013 |
'hello world' indexOfSeparatorStartingAt:3 |
|
3014 |
' hello world' indexOfSeparatorStartingAt:3 |
|
3015 |
'hello world ' indexOfSeparatorStartingAt:3 |
|
3016 |
'hello world ' indexOfSeparatorStartingAt:6 |
|
3017 |
'hello world ' indexOfSeparatorStartingAt:7 |
|
3018 |
'helloworld ' indexOfSeparatorStartingAt:7 |
|
3019 |
'helloworld' indexOfSeparatorStartingAt:7 |
|
3020 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3021 |
! |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3022 |
|
4117 | 3023 |
lastIndexOfSeparator |
3024 |
"return the last index of the whitespace character. |
|
3025 |
(i.e. start the search at the end and search backwards); |
|
3026 |
Returns 0 if no separator is found." |
|
3027 |
||
3028 |
^ self lastIndexOfSeparatorStartingAt:(self size) |
|
3029 |
||
3030 |
" |
|
3031 |
'hello world' lastIndexOfSeparator |
|
3032 |
'helloworld' lastIndexOfSeparator |
|
3033 |
'hel lo wor ld' lastIndexOfSeparator |
|
3034 |
'hel ' lastIndexOfSeparator 6 |
|
3035 |
" |
|
3036 |
! |
|
3037 |
||
3038 |
lastIndexOfSeparatorStartingAt:startIndex |
|
3039 |
"return the index of the previous whitespace character, |
|
3040 |
starting the search at startIndex (and searching backwards); |
|
3041 |
returns 0 if no separator was found" |
|
3042 |
||
5487 | 3043 |
|start "{ Class: SmallInteger }"| |
4117 | 3044 |
|
3045 |
start := startIndex. |
|
3046 |
||
3047 |
start to:1 by:-1 do:[:index | |
|
3048 |
(self at:index) isSeparator ifTrue:[^ index] |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
3049 |
]. |
4117 | 3050 |
^ 0 |
3051 |
||
3052 |
" |
|
3053 |
'hello world' lastIndexOfSeparatorStartingAt:3 |
|
3054 |
'hello world' lastIndexOfSeparatorStartingAt:7 |
|
3055 |
'helloworld' lastIndexOfSeparatorStartingAt:7 |
|
3056 |
' helloworld' lastIndexOfSeparatorStartingAt:7 |
|
3057 |
" |
|
608 | 3058 |
! ! |
3059 |
||
3060 |
!CharacterArray methodsFor:'comparing'! |
|
3061 |
||
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3062 |
< aString |
608 | 3063 |
"Compare the receiver with the argument and return true if the |
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3064 |
receiver is greater than the argument. Otherwise return false. |
1252 | 3065 |
This comparison is based on the elements ascii code - |
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3066 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3067 |
|
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3068 |
|mySize "{ Class: SmallInteger }" |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3069 |
otherSize "{ Class: SmallInteger }" |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3070 |
n "{ Class: SmallInteger }" |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3071 |
c1 c2| |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3072 |
|
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3073 |
mySize := self size. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3074 |
otherSize := aString string size. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3075 |
n := mySize min:otherSize. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3076 |
|
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3077 |
1 to:n do:[:index | |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3078 |
c1 := self at:index. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3079 |
c2 := aString at:index. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3080 |
c1 < c2 ifTrue:[^ true]. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3081 |
c1 > c2 ifTrue:[^ false]. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3082 |
]. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
3083 |
^ mySize < otherSize |
608 | 3084 |
! |
3085 |
||
3086 |
<= something |
|
3087 |
"Compare the receiver with the argument and return true if the |
|
1252 | 3088 |
receiver is less than or equal to the argument. Otherwise return false. |
3089 |
This comparison is based on the elements ascii code - |
|
3090 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 3091 |
|
3092 |
^ (self > something) not |
|
1252 | 3093 |
|
3094 |
"Modified: 22.4.1996 / 15:54:56 / cg" |
|
608 | 3095 |
! |
3096 |
||
3097 |
= aString |
|
3098 |
"Compare the receiver with the argument and return true if the |
|
3099 |
receiver is equal to the argument. Otherwise return false. |
|
1252 | 3100 |
|
608 | 3101 |
This compare does NOT ignore case differences, |
3102 |
therefore 'foo' = 'Foo' will return false. |
|
3103 |
Since this is incompatible to ST-80 (at least, V2.x) , this may change." |
|
3104 |
||
3105 |
|mySize "{ Class: SmallInteger }" |
|
3106 |
otherSize | |
|
3107 |
||
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
3108 |
(aString isString or:[aString species == self species]) ifFalse:[ |
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
3109 |
^ false |
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
3110 |
]. |
608 | 3111 |
mySize := self size. |
3112 |
otherSize := aString size. |
|
3113 |
mySize == otherSize ifFalse:[^ false]. |
|
3114 |
||
3115 |
1 to:mySize do:[:index | |
|
1252 | 3116 |
(self at:index) = (aString at:index) ifFalse:[^ false]. |
608 | 3117 |
]. |
3118 |
^ true |
|
3119 |
||
3120 |
" |
|
3121 |
'foo' = 'Foo' |
|
3122 |
'foo' = 'bar' |
|
5963
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
3123 |
'foo' = 'foo' |
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
3124 |
'foo' = 'foo' asText |
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
3125 |
'foo' asText = 'foo' |
23462e06dcff
compare with Texts fixed (should compare equal if strings are)
Claus Gittinger <cg@exept.de>
parents:
5946
diff
changeset
|
3126 |
'foo' asText = 'foo' asText |
608 | 3127 |
" |
1252 | 3128 |
|
3129 |
"Modified: 22.4.1996 / 15:53:58 / cg" |
|
608 | 3130 |
! |
3131 |
||
3132 |
> aString |
|
3133 |
"Compare the receiver with the argument and return true if the |
|
3134 |
receiver is greater than the argument. Otherwise return false. |
|
1252 | 3135 |
This comparison is based on the elements ascii code - |
3136 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
|
608 | 3137 |
|
3138 |
|mySize "{ Class: SmallInteger }" |
|
3139 |
otherSize "{ Class: SmallInteger }" |
|
3140 |
n "{ Class: SmallInteger }" |
|
3141 |
c1 c2| |
|
3142 |
||
3143 |
mySize := self size. |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3144 |
otherSize := aString string size. |
608 | 3145 |
n := mySize min:otherSize. |
3146 |
||
3147 |
1 to:n do:[:index | |
|
1252 | 3148 |
c1 := self at:index. |
3149 |
c2 := aString at:index. |
|
3150 |
c1 > c2 ifTrue:[^ true]. |
|
3151 |
c1 < c2 ifTrue:[^ false]. |
|
608 | 3152 |
]. |
3153 |
^ mySize > otherSize |
|
1252 | 3154 |
|
3155 |
"Modified: 22.4.1996 / 15:55:00 / cg" |
|
608 | 3156 |
! |
3157 |
||
3158 |
>= something |
|
3159 |
"Compare the receiver with the argument and return true if the |
|
3160 |
receiver is greater than or equal to the argument. |
|
1252 | 3161 |
Otherwise return false. |
3162 |
This comparison is based on the elements ascii code - |
|
3163 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 3164 |
|
3165 |
^ (something > self) not |
|
1252 | 3166 |
|
3167 |
"Modified: 22.4.1996 / 15:55:03 / cg" |
|
608 | 3168 |
! |
3169 |
||
5929 | 3170 |
compareCaselessWith:aString |
3171 |
"Compare the receiver against the argument, ignoreing case. |
|
3172 |
Return 1 if the receiver is greater, 0 if equal and -1 if less than the argument. |
|
3173 |
||
3174 |
This comparison is based on the elements ascii code - |
|
3175 |
i.e. national characters are NOT treated specially. |
|
3176 |
'foo' compareWith: 'Foo' will return 0" |
|
3177 |
||
3178 |
|mySize "{ Class: SmallInteger }" |
|
3179 |
otherSize "{ Class: SmallInteger }" |
|
3180 |
n "{ Class: SmallInteger }" |
|
3181 |
c1 c2| |
|
3182 |
||
3183 |
mySize := self size. |
|
3184 |
otherSize := aString string size. |
|
3185 |
n := mySize min:otherSize. |
|
3186 |
||
3187 |
1 to:n do:[:index | |
|
3188 |
c1 := (self at:index) asLowercase. |
|
3189 |
c2 := (aString at:index) asLowercase. |
|
3190 |
c1 > c2 ifTrue:[^ 1]. |
|
3191 |
c1 < c2 ifTrue:[^ -1]. |
|
3192 |
]. |
|
3193 |
mySize > otherSize ifTrue:[^ 1]. |
|
3194 |
mySize < otherSize ifTrue:[^ -1]. |
|
3195 |
^ 0 |
|
3196 |
||
3197 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
3198 |
! |
|
3199 |
||
608 | 3200 |
compareWith:aString |
3201 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
3202 |
greater, 0 if equal and -1 if less than the argument. |
|
1252 | 3203 |
This comparison is based on the elements ascii code - |
3204 |
i.e. upper/lowercase & national characters are NOT treated specially. |
|
3205 |
'foo' compareWith: 'Foo' will return 1. |
|
3206 |
while 'foo' sameAs:'Foo' will return true" |
|
608 | 3207 |
|
3208 |
|mySize "{ Class: SmallInteger }" |
|
3209 |
otherSize "{ Class: SmallInteger }" |
|
3210 |
n "{ Class: SmallInteger }" |
|
3211 |
c1 c2| |
|
3212 |
||
3213 |
mySize := self size. |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3214 |
otherSize := aString string size. |
608 | 3215 |
n := mySize min:otherSize. |
3216 |
||
3217 |
1 to:n do:[:index | |
|
1252 | 3218 |
c1 := self at:index. |
3219 |
c2 := aString at:index. |
|
3220 |
c1 > c2 ifTrue:[^ 1]. |
|
3221 |
c1 < c2 ifTrue:[^ -1]. |
|
608 | 3222 |
]. |
3223 |
mySize > otherSize ifTrue:[^ 1]. |
|
3224 |
mySize < otherSize ifTrue:[^ -1]. |
|
3225 |
^ 0 |
|
1252 | 3226 |
|
3227 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
608 | 3228 |
! |
3229 |
||
3230 |
hash |
|
3231 |
"return an integer useful as a hash-key" |
|
3232 |
||
3233 |
%{ /* NOCONTEXT */ |
|
3234 |
||
3985 | 3235 |
REGISTER unsigned g, val; |
608 | 3236 |
REGISTER unsigned char *cp, *cp0; |
3237 |
int l; |
|
3238 |
||
1133 | 3239 |
cp = __stringVal(self); |
3240 |
l = __stringSize(self); |
|
3987 | 3241 |
if (__qClass(self) != @global(String)) { |
3985 | 3242 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
3243 |
||
3244 |
cp += n; |
|
3245 |
l -= n; |
|
608 | 3246 |
} |
3247 |
||
3248 |
/* |
|
3985 | 3249 |
* this is the dragon-book algorithm |
608 | 3250 |
*/ |
3985 | 3251 |
|
3252 |
val = 0; |
|
3253 |
switch (l) { |
|
3254 |
default: |
|
3255 |
for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) { |
|
3256 |
val = (val << 4) + *cp; |
|
3257 |
if (g = (val & 0xF0000000)) { |
|
3258 |
val ^= g >> 24; |
|
3259 |
val ^= g; |
|
3260 |
} |
|
3261 |
} |
|
3262 |
break; |
|
3263 |
case 7: |
|
3264 |
val = cp[6] << 4; |
|
3265 |
case 6: |
|
3266 |
val = (val + cp[5]) << 4; |
|
3267 |
case 5: |
|
3268 |
val = (val + cp[4]) << 4; |
|
3269 |
case 4: |
|
3270 |
val = (val + cp[3]) << 4; |
|
3271 |
case 3: |
|
3272 |
val = (val + cp[2]) << 4; |
|
3273 |
case 2: |
|
3274 |
val = (val + cp[1]) << 4; |
|
3275 |
case 1: |
|
3276 |
val = val + cp[0]; |
|
3277 |
case 0: |
|
3278 |
break; |
|
608 | 3279 |
} |
3280 |
||
3985 | 3281 |
/* |
3282 |
* multiply by large prime to spread values |
|
3283 |
* This speeds up Set and Dictionary by a factor of 10! |
|
3284 |
*/ |
|
3285 |
val *= 31415821; |
|
3286 |
RETURN ( __MKSMALLINT(val & 0x3fffffff)); |
|
608 | 3287 |
%} |
3985 | 3288 |
|
608 | 3289 |
! |
3290 |
||
3291 |
sameAs:aString |
|
3292 |
"Compare the receiver with the argument like =, but ignore |
|
1252 | 3293 |
case differences. |
3294 |
Return true or false." |
|
608 | 3295 |
|
3296 |
|mySize "{ Class: SmallInteger }" |
|
3297 |
otherSize c1 c2| |
|
3298 |
||
3195
0a1a7a4c6184
oops- sameAs returned self instead of true
Claus Gittinger <cg@exept.de>
parents:
3073
diff
changeset
|
3299 |
self == aString ifTrue:[^ true]. |
2581
d06e3bbfc294
faster #sameAs: if string is identical
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
3300 |
|
608 | 3301 |
mySize := self size. |
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3302 |
otherSize := aString string size. |
608 | 3303 |
mySize == otherSize ifFalse:[^ false]. |
3304 |
||
3305 |
1 to:mySize do:[:index | |
|
1252 | 3306 |
c1 := self at:index. |
3307 |
c2 := aString at:index. |
|
3308 |
c1 == c2 ifFalse:[ |
|
3309 |
c1 asLowercase = c2 asLowercase ifFalse:[^ false]. |
|
3310 |
] |
|
608 | 3311 |
]. |
3312 |
^ true |
|
3313 |
||
3314 |
" |
|
3315 |
'foo' sameAs: 'Foo' |
|
3316 |
'foo' sameAs: 'bar' |
|
3317 |
'foo' sameAs: 'foo' |
|
3318 |
" |
|
1252 | 3319 |
|
3320 |
"Modified: 22.4.1996 / 15:56:17 / cg" |
|
608 | 3321 |
! |
3322 |
||
5242 | 3323 |
sameAs:aString ignoreCase:ignoreCase |
3324 |
"Compare the receiver with the argument. |
|
3325 |
If ignoreCase is true, this is the same as #sameAs:, |
|
3326 |
if false, this is the same as #=." |
|
3327 |
||
3328 |
ignoreCase ifTrue:[ |
|
3329 |
^ self sameAs:aString |
|
3330 |
]. |
|
3331 |
^ self = aString |
|
3332 |
||
3333 |
" |
|
3334 |
'foo' sameAs:'Foo' ignoreCase:false |
|
3335 |
'foo' sameAs:'foo' ignoreCase:true |
|
3336 |
" |
|
3337 |
||
3338 |
! |
|
3339 |
||
608 | 3340 |
sameCharacters:aString |
3341 |
"count & return the number of characters which are the same |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3342 |
(ignoring case and emphasis) in the receiver and the argument, aString." |
608 | 3343 |
|
3344 |
|n "{ Class: SmallInteger }" |
|
986 | 3345 |
c1 c2 cnt| |
608 | 3346 |
|
3347 |
n := self size. |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3348 |
n := n min:(aString string size). |
608 | 3349 |
|
3350 |
cnt := 0. |
|
3351 |
1 to:n do:[:index | |
|
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3352 |
c1 := self at:index. |
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3353 |
c2 := aString at:index. |
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3354 |
((c1 == c2) |
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3355 |
or:[c1 asLowercase = c2 asLowercase]) ifTrue:[ |
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3356 |
cnt := cnt + 1 |
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3357 |
] |
608 | 3358 |
]. |
3359 |
^ cnt |
|
3360 |
||
3361 |
" |
|
3362 |
'foobarbaz' sameCharacters: 'foo' |
|
3363 |
'foobarbaz' sameCharacters: 'Foo' |
|
3364 |
'foobarbaz' sameCharacters: 'baz' |
|
3365 |
" |
|
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3366 |
! |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3367 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3368 |
sameEmphasisAs:aStringOrText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3369 |
"compare the receivers and the arguments emphasis" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3370 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3371 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3372 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3373 |
" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3374 |
'hello' asText sameEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3375 |
'hello' asText sameEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3376 |
'hello' asText allBold sameEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3377 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3378 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3379 |
" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3380 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3381 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3382 |
! |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3383 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3384 |
sameStringAndEmphasisAs:aStringOrText |
5739
4fd3be7ccc75
oops some relational ops did accept a non-string arg
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
3385 |
"compare both emphasis and string of the receiver and the argument" |
5510
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3386 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3387 |
aStringOrText isString ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3388 |
(self string = aStringOrText string) ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3389 |
self hasChangeOfEmphasis = aStringOrText hasChangeOfEmphasis ifFalse:[^ false]. |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3390 |
^ self emphasis = aStringOrText emphasis |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3391 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3392 |
" |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3393 |
'hello' asText sameEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3394 |
'hello' asText sameEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3395 |
'hello' asText allBold sameEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3396 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3397 |
'hello' asText allBold sameEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3398 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3399 |
'hello' sameEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3400 |
'hello' sameEmphasisAs: 'hello' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3401 |
'hello' sameEmphasisAs: 'fooba' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3402 |
'hello' sameEmphasisAs: 'fooba' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3403 |
'hello' sameEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3404 |
'hello' sameEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3405 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3406 |
'hello' asText sameStringAndEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3407 |
'hello' asText sameStringAndEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3408 |
'hello' asText allBold sameStringAndEmphasisAs: 'hello' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3409 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3410 |
'hello' asText allBold sameStringAndEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3411 |
|
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3412 |
'hello' sameStringAndEmphasisAs: 'hello' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3413 |
'hello' sameStringAndEmphasisAs: 'hello' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3414 |
'hello' sameStringAndEmphasisAs: 'fooba' |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3415 |
'hello' sameStringAndEmphasisAs: 'fooba' asText |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3416 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allBold |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3417 |
'hello' sameStringAndEmphasisAs: 'fooba' asText allItalic |
a261b8f5d66f
moved #sameEmphasisAs: and #sameStringAndEmphasisAs:
Claus Gittinger <cg@exept.de>
parents:
5487
diff
changeset
|
3418 |
" |
608 | 3419 |
! ! |
3420 |
||
3421 |
!CharacterArray methodsFor:'converting'! |
|
3422 |
||
3423 |
asArrayOfSubstrings |
|
3424 |
"return an array of substrings from the receiver, interpreting |
|
3425 |
separators (i.e. spaces & newlines) as word-delimiters. |
|
3426 |
This is a compatibility method - the actual work is done in |
|
3427 |
asCollectionOfWords." |
|
3428 |
||
3429 |
^ self asCollectionOfWords asArray |
|
3430 |
||
3431 |
" |
|
3432 |
'1 one two three four 5 five' asArrayOfSubstrings |
|
6892 | 3433 |
'1 |
3434 |
one |
|
3435 |
two three four 5 five' asArrayOfSubstrings |
|
608 | 3436 |
" |
3437 |
! |
|
3438 |
||
3439 |
asCollectionOfLines |
|
3440 |
"return a collection containing the lines (separated by cr) |
|
3441 |
of the receiver. If multiple cr's occur in a row, the result will |
|
3442 |
contain empty strings." |
|
3443 |
||
3444 |
^ self asCollectionOfSubstringsSeparatedBy:Character cr |
|
3445 |
||
3446 |
" |
|
3447 |
'1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines |
|
3448 |
'1 one\\\\2 two\3 three' withCRs asCollectionOfLines |
|
3449 |
" |
|
3450 |
! |
|
3451 |
||
3452 |
asCollectionOfSubstringsSeparatedBy:aCharacter |
|
3453 |
"return a collection containing the lines (separated by aCharacter) |
|
3454 |
of the receiver. If aCharacter occurs multiple times in a row, |
|
3455 |
the result will contain empty strings." |
|
3456 |
||
3457 |
|lines myClass |
|
3458 |
numberOfLines "{ Class:SmallInteger }" |
|
3459 |
startIndex "{ Class:SmallInteger }" |
|
3460 |
stopIndex "{ Class:SmallInteger }" | |
|
3461 |
||
3462 |
" |
|
3463 |
count first, to avoid regrowing of the OC |
|
3464 |
" |
|
3465 |
numberOfLines := (self occurrencesOf:aCharacter) + 1. |
|
3466 |
lines := OrderedCollection new:numberOfLines. |
|
3467 |
myClass := self species. |
|
3468 |
||
3469 |
startIndex := 1. |
|
3470 |
1 to:numberOfLines do:[:lineNr | |
|
3471 |
stopIndex := self indexOf:aCharacter startingAt:startIndex. |
|
3472 |
stopIndex == 0 ifTrue:[ |
|
3473 |
stopIndex := self size |
|
3474 |
] ifFalse: [ |
|
3475 |
stopIndex := stopIndex - 1. |
|
3476 |
]. |
|
3477 |
||
3478 |
(stopIndex < startIndex) ifTrue: [ |
|
3479 |
lines add:(myClass new:0) |
|
3480 |
] ifFalse: [ |
|
3481 |
lines add:(self copyFrom:startIndex to:stopIndex) |
|
3482 |
]. |
|
3483 |
startIndex := stopIndex + 2 |
|
3484 |
]. |
|
3485 |
^ lines |
|
3486 |
||
3487 |
" |
|
3488 |
'1 one:2 two:3 three:4 four:5 five' withCRs asCollectionOfSubstringsSeparatedBy:$: |
|
3489 |
'1 one 2 two 3 three 4 four 5 five' withCRs asCollectionOfSubstringsSeparatedBy:Character space |
|
3490 |
" |
|
3491 |
! |
|
3492 |
||
7339
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3493 |
asCollectionOfSubstringsSeparatedByAll:aSeparatorString |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3494 |
"return a collection containing the lines (separated by aSeparatorString) |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3495 |
of the receiver. If aSeparatorString occurs multiple times in a row, |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3496 |
the result will contain empty strings." |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3497 |
|
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3498 |
|items done myClass |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3499 |
startIndex "{ Class:SmallInteger }" |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3500 |
stopIndex "{ Class:SmallInteger }" | |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3501 |
|
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3502 |
items := OrderedCollection new. |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3503 |
myClass := self species. |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3504 |
|
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3505 |
startIndex := 1. |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3506 |
done := false. |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3507 |
[done] whileFalse:[ |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3508 |
stopIndex := self indexOfSubCollection:aSeparatorString startingAt:startIndex. |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3509 |
stopIndex == 0 ifTrue:[ |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3510 |
stopIndex := self size. |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3511 |
done := true. |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3512 |
] ifFalse: [ |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3513 |
stopIndex := stopIndex - 1. |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3514 |
]. |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3515 |
|
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3516 |
(stopIndex < startIndex) ifTrue: [ |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3517 |
items add:(myClass new:0) |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3518 |
] ifFalse: [ |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3519 |
items add:(self copyFrom:startIndex to:stopIndex) |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3520 |
]. |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3521 |
startIndex := stopIndex + (aSeparatorString size) + 1. |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3522 |
]. |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3523 |
^ items |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3524 |
|
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3525 |
" |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3526 |
'1::2::3::4::5::' withCRs asCollectionOfSubstringsSeparatedByAll:'::' |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3527 |
" |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3528 |
! |
20969b5770c9
asCollectionOfSubstringsSeparatedByAll:
Claus Gittinger <cg@exept.de>
parents:
7318
diff
changeset
|
3529 |
|
608 | 3530 |
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators |
3531 |
"return a collection containing the words (separated by any character |
|
3532 |
from aCollectionOfSeparators) of the receiver. |
|
3533 |
This allows breaking up strings using any character as separator." |
|
3534 |
||
3535 |
|words |
|
3536 |
start "{ Class:SmallInteger }" |
|
3537 |
stop "{ Class:SmallInteger }" |
|
3538 |
mySize "{ Class:SmallInteger }"| |
|
3539 |
||
3540 |
words := OrderedCollection new. |
|
3541 |
start := 1. |
|
3542 |
mySize := self size. |
|
3543 |
[start <= mySize] whileTrue:[ |
|
3544 |
"skip multiple separators" |
|
3545 |
[aCollectionOfSeparators includes:(self at:start)] whileTrue:[ |
|
3546 |
start := start + 1 . |
|
3547 |
start > mySize ifTrue:[ |
|
3548 |
^ words |
|
3549 |
]. |
|
3550 |
]. |
|
3551 |
||
3552 |
stop := self indexOfAny:aCollectionOfSeparators startingAt:start. |
|
3553 |
stop == 0 ifTrue:[ |
|
3554 |
words add:(self copyFrom:start to:mySize). |
|
3555 |
^ words |
|
3556 |
]. |
|
3557 |
words add:(self copyFrom:start to:(stop - 1)). |
|
3558 |
start := stop |
|
3559 |
]. |
|
3560 |
^ words |
|
3561 |
||
3562 |
" |
|
3563 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:) |
|
3564 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' |
|
3565 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) |
|
3566 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' |
|
3567 |
'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) |
|
3568 |
" |
|
3569 |
! |
|
3570 |
||
3571 |
asCollectionOfWords |
|
3572 |
"return a collection containing the words (separated by whitespace) |
|
3573 |
of the receiver. Multiple occurences of whitespace characters will |
|
3574 |
be treated like one - i.e. whitespace is skipped." |
|
3575 |
||
7797 | 3576 |
|words| |
608 | 3577 |
|
3578 |
words := OrderedCollection new. |
|
7797 | 3579 |
self asCollectionOfWordsDo:[:w | words add:w]. |
608 | 3580 |
^ words |
3581 |
||
3582 |
" |
|
3583 |
'hello world isnt this nice' asCollectionOfWords |
|
3584 |
' hello world isnt this nice ' asCollectionOfWords |
|
3585 |
'hello' asCollectionOfWords |
|
3586 |
'' asCollectionOfWords |
|
3587 |
' ' asCollectionOfWords |
|
3588 |
" |
|
3589 |
! |
|
3590 |
||
7797 | 3591 |
asCollectionOfWordsDo:aBlock |
3592 |
"evaluate aBlock for each word (separated by whitespace) of the receiver. |
|
3593 |
Multiple occurences of whitespace characters will be treated like one |
|
3594 |
- i.e. whitespace is skipped. |
|
3595 |
Returns the number of words (i.e. the number of invocations of aBlock)." |
|
3596 |
||
3597 |
|count "{ Class:SmallInteger }" |
|
3598 |
start "{ Class:SmallInteger }" |
|
3599 |
stop "{ Class:SmallInteger }" |
|
3600 |
mySize "{ Class:SmallInteger }"| |
|
3601 |
||
3602 |
count := 0. |
|
3603 |
start := 1. |
|
3604 |
mySize := self size. |
|
3605 |
[start <= mySize] whileTrue:[ |
|
3606 |
start := self indexOfNonSeparatorStartingAt:start. |
|
3607 |
start == 0 ifTrue:[ |
|
3608 |
^ count |
|
3609 |
]. |
|
3610 |
stop := self indexOfSeparatorStartingAt:start. |
|
3611 |
stop == 0 ifTrue:[ |
|
3612 |
aBlock value:(self copyFrom:start to:mySize). |
|
3613 |
^ count + 1 |
|
3614 |
]. |
|
3615 |
aBlock value:(self copyFrom:start to:(stop - 1)). |
|
3616 |
start := stop. |
|
3617 |
count := count + 1 |
|
3618 |
]. |
|
3619 |
^ count |
|
3620 |
||
3621 |
" |
|
3622 |
'hello world isnt this nice' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3623 |
' hello world isnt this nice ' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3624 |
'hello' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3625 |
'' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3626 |
' ' asCollectionOfWordsDo:[:w | Transcript showCR:w] |
|
3627 |
" |
|
3628 |
! |
|
3629 |
||
608 | 3630 |
asComposedText |
1312 | 3631 |
"ST-80 compatibility |
3632 |
- ST/X does not (as today) support composedTexts." |
|
3633 |
||
7555 | 3634 |
^ ComposedText fromString:self string |
1312 | 3635 |
|
3636 |
"Modified: 27.4.1996 / 13:30:30 / cg" |
|
608 | 3637 |
! |
3638 |
||
3639 |
asFilename |
|
3640 |
"return a Filename with pathname taken from the receiver" |
|
3641 |
||
7879 | 3642 |
^ Filename named:self "(self asSingleByteStringReplaceInvalidWith:$?)" |
1423 | 3643 |
|
3644 |
"Modified: 20.5.1996 / 09:38:15 / cg" |
|
608 | 3645 |
! |
3646 |
||
3060 | 3647 |
asFixedPoint |
3648 |
"read a fixedPoint number from the receiver. |
|
7423 | 3649 |
Notice, that errors may occur during the read, |
3650 |
so you better setup some signal handler when using this method." |
|
3060 | 3651 |
|
3652 |
^ FixedPoint readFromString:self |
|
3653 |
||
3654 |
" |
|
3655 |
'0.123' asFixedPoint |
|
3656 |
'12345' asFixedPoint |
|
3657 |
'(1/5)' asFixedPoint |
|
3658 |
'foo' asFixedPoint |
|
7423 | 3659 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asFixedPoint] |
3060 | 3660 |
" |
3661 |
||
3662 |
"Modified: / 25.10.1997 / 15:19:00 / cg" |
|
3663 |
! |
|
3664 |
||
3665 |
asFixedPoint:scale |
|
3666 |
"read a fixedPoint number with scale number of post-decimal digits |
|
3667 |
from the receiver. Scale controls the number of displayed digits, |
|
3668 |
not the number of actually valid digits. |
|
7423 | 3669 |
Notice, that errors may occur during the read, |
3670 |
so you better setup some signal handler when using this method." |
|
3060 | 3671 |
|
3672 |
^ (FixedPoint readFromString:self) scale:scale |
|
3673 |
||
3674 |
" |
|
3675 |
'0.123' asFixedPoint:2 |
|
3676 |
'123456' asFixedPoint:2 |
|
3677 |
('3.14157' asFixedPoint:1) asFixedPoint:5 |
|
7423 | 3678 |
'3.14157' asFixedPoint:2 |
3679 |
'foo' asFixedPoint:2 |
|
3060 | 3680 |
" |
3681 |
||
3682 |
"Modified: / 25.10.1997 / 15:21:57 / cg" |
|
3683 |
! |
|
3684 |
||
608 | 3685 |
asFloat |
3686 |
"read a float number from the receiver. |
|
7422 | 3687 |
Notice, that errors may occur during the read, |
3688 |
so you better setup some exception handler when using this method." |
|
608 | 3689 |
|
3690 |
^ (Number readFromString:self) asFloat |
|
3691 |
||
3692 |
" |
|
3693 |
'0.123' asFloat |
|
3694 |
'12345' asFloat |
|
3695 |
'(1/5)' asFloat |
|
7422 | 3696 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asFloat] |
608 | 3697 |
" |
3698 |
! |
|
3699 |
||
3700 |
asInteger |
|
3701 |
"read an integer from the receiver. |
|
7422 | 3702 |
Notice, that errors may occur during the read, |
3703 |
so you better setup some exception handler when using this method." |
|
608 | 3704 |
|
3705 |
^ Integer readFromString:self |
|
3706 |
||
3707 |
" |
|
3708 |
'12345678901234567890' asInteger |
|
3709 |
'-1234' asInteger |
|
3710 |
'0.123' asInteger <- reader stops at ., returning 0 here |
|
3711 |
'0.123' asNumber <- returns what you expect |
|
7422 | 3712 |
Object errorSignal handle:[:ex | ex return:0] do:['foo' asInteger] |
608 | 3713 |
" |
3714 |
! |
|
3715 |
||
3716 |
asLowercase |
|
3717 |
"return a copy of myself in lowercase letters" |
|
3718 |
||
3719 |
|newStr |
|
3720 |
mySize "{ Class: SmallInteger }" | |
|
3721 |
||
3722 |
mySize := self size. |
|
3723 |
newStr := self species new:mySize. |
|
3724 |
1 to:mySize do:[:i | |
|
3725 |
newStr at:i put:(self at:i) asLowercase |
|
3726 |
]. |
|
3727 |
^ newStr |
|
3728 |
||
3729 |
" |
|
3730 |
'HelloWorld' asLowercase |
|
3731 |
'HelloWorld' asLowercaseFirst |
|
3732 |
" |
|
3733 |
! |
|
3734 |
||
3735 |
asLowercaseFirst |
|
3736 |
"return a copy of myself where the first character is |
|
3737 |
converted to lowercase." |
|
3738 |
||
3739 |
|newString sz| |
|
3740 |
||
3741 |
sz := self size. |
|
3742 |
newString := self copyFrom:1 to:sz. |
|
3743 |
sz > 0 ifTrue:[ |
|
3744 |
newString at:1 put:(newString at:1) asLowercase |
|
3745 |
]. |
|
3746 |
^ newString |
|
3747 |
||
3748 |
" |
|
3749 |
'HelloWorld' asLowercase |
|
3750 |
'HelloWorld' asLowercaseFirst |
|
3751 |
" |
|
3752 |
! |
|
3753 |
||
3754 |
asNumber |
|
3755 |
"read a number from the receiver. |
|
3756 |
Notice, that (in contrast to ST-80) errors may occur during the read, |
|
3757 |
so you better setup some signal handler when using this method. |
|
3758 |
This may change if ANSI specifies it." |
|
3759 |
||
3760 |
"/ ST-80 behavior: |
|
3761 |
"/ ^ Number readFromString:self onError:0 |
|
3762 |
||
3763 |
^ Number readFromString:self |
|
3764 |
||
3765 |
" |
|
3766 |
'123' asNumber |
|
3767 |
'123.567' asNumber |
|
3768 |
'(5/6)' asNumber |
|
3769 |
'foo' asNumber |
|
3770 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] |
|
3771 |
" |
|
3772 |
! |
|
3773 |
||
3774 |
asNumberFromFormatString:ignored |
|
3775 |
"read a number from the receiver, ignoring any nonDigit characters. |
|
3776 |
This is typically used to convert from strings which include |
|
3777 |
dollar-signs or millenium digits. However, this method also ignores |
|
3778 |
the decimal point (if any) and therefore should be used with care." |
|
3779 |
||
3780 |
|tempString| |
|
3781 |
||
3782 |
tempString := self collect:[:char | char isDigit]. |
|
3783 |
^ Number readFromString:tempString onError:0 |
|
3784 |
||
3785 |
" |
|
3786 |
'USD 123' asNumberFromFormatString:'foo' |
|
3787 |
'DM 123' asNumberFromFormatString:'foo' |
|
3788 |
'123' asNumberFromFormatString:'foo' |
|
3789 |
'123.567' asNumberFromFormatString:'foo' |
|
3790 |
'(5/6)' asNumberFromFormatString:'foo' |
|
3791 |
'foo' asNumberFromFormatString:'foo' |
|
3792 |
" |
|
3793 |
! |
|
3794 |
||
7877
bef56f06d2f8
asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents:
7876
diff
changeset
|
3795 |
asOneByteString |
bef56f06d2f8
asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents:
7876
diff
changeset
|
3796 |
"return the receiver converted to a 'normal' string. |
bef56f06d2f8
asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents:
7876
diff
changeset
|
3797 |
Same as asSingleByteString - for compatibility." |
bef56f06d2f8
asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents:
7876
diff
changeset
|
3798 |
|
bef56f06d2f8
asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents:
7876
diff
changeset
|
3799 |
^ self asSingleByteString |
bef56f06d2f8
asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents:
7876
diff
changeset
|
3800 |
! |
bef56f06d2f8
asOneByteString -> asSingleByteString
Claus Gittinger <cg@exept.de>
parents:
7876
diff
changeset
|
3801 |
|
608 | 3802 |
asSingleByteString |
3803 |
"return the receiver converted to a 'normal' string" |
|
3804 |
||
3805 |
^ String fromString:self |
|
3806 |
! |
|
3807 |
||
2732 | 3808 |
asSingleByteStringReplaceInvalidWith:replacementCharacter |
3809 |
"return the receiver converted to a 'normal' string, |
|
3810 |
with invalid characters replaced by replacementCharacter. |
|
3811 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
3812 |
and replace characters above code-255 with some replacement." |
|
3813 |
||
3814 |
|newString| |
|
3815 |
||
3816 |
newString := String new:(self size). |
|
3817 |
1 to:self size do:[:idx | |
|
3818 |
|char| |
|
3819 |
||
3820 |
char := self at:idx. |
|
3821 |
char asciiValue <= 16rFF ifTrue:[ |
|
3822 |
newString at:idx put:char |
|
3823 |
] ifFalse:[ |
|
3824 |
newString at:idx put:replacementCharacter |
|
3825 |
]. |
|
3826 |
]. |
|
3827 |
^ newString |
|
3828 |
||
3829 |
"Created: 30.6.1997 / 13:02:14 / cg" |
|
3830 |
! |
|
3831 |
||
5843 | 3832 |
asSoundexCode |
7423 | 3833 |
"return a soundex string or nil |
3834 |
(read Knuth or search the web if you dont know what a soundex code is)" |
|
5843 | 3835 |
|
6643 | 3836 |
|s d ch last lch n codes sc| |
5843 | 3837 |
|
3838 |
s := self readStream. |
|
3839 |
s skipSeparators. |
|
3840 |
s atEnd ifTrue:[ |
|
3841 |
^ nil |
|
3842 |
]. |
|
3843 |
ch := s next. |
|
3844 |
ch isLetter ifFalse:[ |
|
3845 |
^ nil |
|
3846 |
]. |
|
3847 |
n := 0. |
|
3848 |
||
3849 |
codes := Dictionary new. |
|
3850 |
codes at:$b put:$1. |
|
3851 |
codes at:$p put:$1. |
|
3852 |
codes at:$f put:$1. |
|
3853 |
codes at:$v put:$1. |
|
3854 |
codes at:$c put:$2. |
|
3855 |
codes at:$s put:$2. |
|
3856 |
codes at:$k put:$2. |
|
3857 |
codes at:$g put:$2. |
|
3858 |
codes at:$j put:$2. |
|
3859 |
codes at:$q put:$2. |
|
3860 |
codes at:$x put:$2. |
|
3861 |
codes at:$z put:$2. |
|
3862 |
codes at:$d put:$3. |
|
3863 |
codes at:$t put:$3. |
|
3864 |
codes at:$l put:$4. |
|
3865 |
codes at:$m put:$5. |
|
3866 |
codes at:$n put:$5. |
|
3867 |
codes at:$r put:$6. |
|
3868 |
||
3869 |
d := '' writeStream. |
|
3870 |
d nextPut:(ch asUppercase). |
|
3871 |
||
3872 |
[s atEnd] whileFalse:[ |
|
3873 |
ch := s next. |
|
3874 |
lch := ch asLowercase. |
|
3875 |
lch = last ifFalse:[ |
|
3876 |
last := lch. |
|
3877 |
||
3878 |
sc := codes at:ch ifAbsent:nil. |
|
3879 |
sc notNil ifTrue:[ |
|
3880 |
n < 3 ifTrue:[ |
|
3881 |
d nextPut:sc. |
|
3882 |
n := n + 1. |
|
3883 |
] |
|
3884 |
] ifFalse:[ |
|
3885 |
"/ ch isLetter ifFalse:[ |
|
3886 |
"/ "/ something else - ignore it |
|
3887 |
"/ ] ifTrue:[ |
|
3888 |
"/ "/ else its a vowel and we ignore it |
|
3889 |
"/ ] |
|
3890 |
]. |
|
3891 |
] |
|
3892 |
]. |
|
3893 |
[ n < 3 ] whileTrue:[ |
|
3894 |
d nextPut:$0. |
|
3895 |
n := n + 1. |
|
3896 |
]. |
|
3897 |
||
3898 |
^ d contents |
|
3899 |
||
3900 |
" |
|
7423 | 3901 |
'claus' asSoundexCode |
5843 | 3902 |
'clause' asSoundexCode |
3903 |
'close' asSoundexCode |
|
3904 |
'smalltalk' asSoundexCode |
|
3905 |
'smaltalk' asSoundexCode |
|
3906 |
'smaltak' asSoundexCode |
|
3907 |
'smaltok' asSoundexCode |
|
7423 | 3908 |
'smoltok' asSoundexCode |
5843 | 3909 |
'aa' asSoundexCode |
3910 |
'by' asSoundexCode |
|
3911 |
'bab' asSoundexCode |
|
3912 |
'bob' asSoundexCode |
|
3913 |
'bop' asSoundexCode |
|
3914 |
" |
|
3915 |
! |
|
3916 |
||
608 | 3917 |
asString |
3918 |
"return myself - I am a string" |
|
3919 |
||
3920 |
^ self |
|
3921 |
! |
|
3922 |
||
3923 |
asStringCollection |
|
3924 |
"return a collection of lines from myself." |
|
3925 |
||
1393 | 3926 |
^ StringCollection from:self "string" |
3927 |
||
3928 |
"Modified: 13.5.1996 / 20:36:59 / cg" |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3929 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3930 |
|
1434 | 3931 |
asSymbol |
3932 |
"return a unique symbol with the name taken from my characters. |
|
3933 |
The receiver must be a singleByte-String; twoByteSymbols are |
|
3934 |
(currently) not allowed." |
|
3935 |
||
3936 |
^ self string asSymbol |
|
3937 |
||
3938 |
"Created: 22.5.1996 / 15:56:11 / cg" |
|
3939 |
! |
|
3940 |
||
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3941 |
asSymbolIfInterned |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3942 |
"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
|
3943 |
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
|
3944 |
symbol and is the same as |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3945 |
self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil] |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3946 |
but slightly faster, since the symbol lookup operation is only |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3947 |
performed once. |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3948 |
The receiver must be a singleByte-String; twoByteSymbols are |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3949 |
(currently) not allowed." |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3950 |
|
6642 | 3951 |
|s| |
3952 |
||
3953 |
||
3954 |
s := self string. |
|
3955 |
s ~~ self ifTrue:[ |
|
3956 |
^ s asSymbolIfInterned |
|
3957 |
]. |
|
3958 |
^ nil. |
|
1435
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3959 |
|
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3960 |
"Created: 22.5.1996 / 16:37:04 / cg" |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3961 |
! |
3ee1fde2aa58
allow asSymbolIfInterned for Texts
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
3962 |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3963 |
asText |
1381 | 3964 |
"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
|
3965 |
|
7780 | 3966 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
4974 | 3967 |
Text isNil ifTrue:[^ self]. |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3968 |
^ Text fromString:self |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
3969 |
|
1381 | 3970 |
"Created: 12.5.1996 / 10:41:14 / cg" |
608 | 3971 |
! |
3972 |
||
3973 |
asTwoByteString |
|
3974 |
"return the receiver converted to a two-byte string" |
|
3975 |
||
3976 |
^ TwoByteString fromString:self |
|
3977 |
! |
|
3978 |
||
5776 | 3979 |
asURL |
3980 |
"return an URL-object from myself." |
|
3981 |
||
3982 |
^ URL fromString:self |
|
3983 |
||
3984 |
" |
|
3985 |
'http://www.exept.de:80/index.html' asURL host |
|
3986 |
'http://www.exept.de:80/index.html' asURL port |
|
3987 |
'http://www.exept.de:80/index.html' asURL method |
|
3988 |
'http://www.exept.de:80/index.html' asURL path |
|
3989 |
" |
|
3990 |
! |
|
3991 |
||
608 | 3992 |
asUppercase |
3993 |
"return a copy of myself in uppercase letters" |
|
3994 |
||
3995 |
|newStr |
|
3996 |
mySize "{ Class: SmallInteger }" | |
|
3997 |
||
3998 |
mySize := self size. |
|
3999 |
newStr := self species new:mySize. |
|
4000 |
1 to:mySize do:[:i | |
|
4001 |
newStr at:i put:(self at:i) asUppercase |
|
4002 |
]. |
|
4003 |
^ newStr |
|
4004 |
||
4005 |
" |
|
4006 |
'helloWorld' asUppercase |
|
4007 |
'helloWorld' asUppercaseFirst |
|
4008 |
" |
|
4009 |
! |
|
4010 |
||
4011 |
asUppercaseFirst |
|
4012 |
"return a copy of myself where the first character is |
|
4013 |
converted to uppercase." |
|
4014 |
||
4015 |
|newString sz| |
|
4016 |
||
4017 |
sz := self size. |
|
4018 |
newString := self copyFrom:1 to:sz. |
|
4019 |
sz > 0 ifTrue:[ |
|
4020 |
newString at:1 put:(newString at:1) asUppercase |
|
4021 |
]. |
|
4022 |
^ newString |
|
4023 |
||
4024 |
" |
|
4025 |
'helloWorld' asUppercase |
|
4026 |
'helloWorld' asUppercaseFirst |
|
4027 |
'HelloWorld' asUppercaseFirst |
|
4028 |
" |
|
4029 |
! |
|
4030 |
||
4031 |
string |
|
1312 | 4032 |
"return the receiver - for ST-80 compatibility" |
4033 |
||
608 | 4034 |
^ self |
1312 | 4035 |
|
4036 |
"Modified: 27.4.1996 / 13:29:30 / cg" |
|
608 | 4037 |
! |
4038 |
||
4039 |
tokensBasedOn:aCharacter |
|
4040 |
"this is an ST-80 alias for the ST/X method |
|
4041 |
asCollectionOfSubstringsSeparatedBy:" |
|
4042 |
||
4043 |
^ self asCollectionOfSubstringsSeparatedBy:aCharacter |
|
4044 |
||
4045 |
" |
|
4046 |
'hello:world:isnt:this nice' tokensBasedOn:$: |
|
4047 |
'foo,bar,baz' tokensBasedOn:$, |
|
4048 |
'/etc/passwd' asFilename readStream nextLine tokensBasedOn:$: |
|
4049 |
" |
|
4050 |
! ! |
|
4051 |
||
4052 |
!CharacterArray methodsFor:'copying'! |
|
4053 |
||
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
4054 |
, aStringOrCharacter |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4055 |
"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
|
4056 |
This is nonStandard, but convenient" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
4057 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4058 |
|myWidth otherWidth| |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4059 |
|
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
4060 |
aStringOrCharacter isCharacter ifTrue:[ |
6965 | 4061 |
^ self copyWith:aStringOrCharacter |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
4062 |
]. |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4063 |
aStringOrCharacter isText ifTrue:[ |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4064 |
^ aStringOrCharacter concatenateFromString:self |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4065 |
]. |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4066 |
aStringOrCharacter isString ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4067 |
(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
|
4068 |
otherWidth > myWidth ifTrue:[ |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4069 |
^ (aStringOrCharacter species fromString:self) , aStringOrCharacter |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4070 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4071 |
^ self , (self species fromString:aStringOrCharacter) |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4072 |
]. |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4073 |
]. |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
4074 |
^ super , aStringOrCharacter |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
4075 |
|
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
4076 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
4077 |
'hello' , $1 |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
4078 |
'hello' , '1' |
1411 | 4079 |
'hello' , (' world' asText allBold) |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4080 |
'hello' , (JISEncodedString fromString:' world') |
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4081 |
(JISEncodedString fromString:'hello') , ' world' |
1411 | 4082 |
|
1422 | 4083 |
Transcript showCR: |
1411 | 4084 |
(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
|
4085 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
4086 |
|
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4087 |
"Modified: 28.6.1997 / 00:13:17 / cg" |
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
4088 |
! |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
4089 |
|
6965 | 4090 |
,, aString |
7020 | 4091 |
"concatenate with a newLine in between" |
6965 | 4092 |
|
4093 |
^ (self copyWith:Character cr) , aString |
|
4094 |
||
4095 |
" |
|
4096 |
hello ,, world |
|
7020 | 4097 |
'hello' ,, 'world' |
6965 | 4098 |
" |
4099 |
! |
|
4100 |
||
608 | 4101 |
concatenate:string1 and:string2 |
4102 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
4103 |
This is equivalent to self , string1 , string2 |
|
4104 |
- generated by compiler when such a construct is detected and the receiver |
|
4105 |
is known to be a string." |
|
4106 |
||
4107 |
^ self , string1 , string2 |
|
4108 |
! |
|
4109 |
||
4110 |
concatenate:string1 and:string2 and:string3 |
|
4111 |
"return the concatenation of myself and the string arguments. |
|
4112 |
This is equivalent to self , string1 , string2 , string3 |
|
4113 |
- generated by compiler when such a construct is detected and the receiver |
|
4114 |
is known to be a string." |
|
4115 |
||
4116 |
^ self , string1 , string2 , string3 |
|
4117 |
! ! |
|
4118 |
||
4119 |
!CharacterArray methodsFor:'displaying'! |
|
4120 |
||
2762 | 4121 |
displayOn:aGC x:x y:y from:start to:stop |
4122 |
"display the receiver on a GC" |
|
4123 |
||
4124 |
"q&d hack" |
|
4125 |
||
4126 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:false |
|
4127 |
||
4128 |
"Modified: 12.5.1996 / 12:49:33 / cg" |
|
4129 |
! |
|
4130 |
||
7082 | 4131 |
displayOn:aGc x:x y:y opaque:opaque |
2762 | 4132 |
"display the receiver in a graphicsContext - this method allows |
4133 |
strings to be used like DisplayObjects." |
|
4134 |
||
4135 |
|s| |
|
4136 |
||
4137 |
s := self string. |
|
7082 | 4138 |
opaque ifTrue:[ |
2762 | 4139 |
aGc displayOpaqueString:s x:x y:y. |
4140 |
] ifFalse:[ |
|
4141 |
aGc displayString:s x:x y:y. |
|
4142 |
]. |
|
1381 | 4143 |
|
4144 |
"Modified: 11.5.1996 / 14:42:48 / cg" |
|
4145 |
! |
|
4146 |
||
2762 | 4147 |
displayOpaqueOn:aGC x:x y:y from:start to:stop |
4148 |
"display the receiver on a GC" |
|
4149 |
||
4150 |
"q&d hack" |
|
4151 |
||
4152 |
(self copyFrom:start to:stop) displayOn:aGC x:x y:y opaque:true |
|
4153 |
||
4154 |
"Created: 12.5.1996 / 12:29:37 / cg" |
|
4155 |
"Modified: 12.5.1996 / 12:49:19 / cg" |
|
608 | 4156 |
! ! |
4157 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4158 |
!CharacterArray methodsFor:'emphasis'! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4159 |
|
5732 | 4160 |
allBold |
4161 |
"return a test object representing the receiver, but all boldified" |
|
4162 |
||
7780 | 4163 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
6187 | 4164 |
Text isNil ifTrue:[^ self]. |
5732 | 4165 |
^ self asText allBold |
4166 |
||
4167 |
" |
|
4168 |
Transcript showCR:'hello' asText allBold |
|
4169 |
Transcript showCR:'hello' allBold |
|
4170 |
" |
|
4171 |
! |
|
4172 |
||
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4173 |
allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4174 |
"return a test object representing the receiver, but all in italic" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4175 |
|
7780 | 4176 |
"this test allows for small non-gui apps to be built without libbasic2 (where Text is)" |
6187 | 4177 |
Text isNil ifTrue:[^ self]. |
5898
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4178 |
^ self asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4179 |
|
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4180 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4181 |
Transcript showCR:'hello' asText allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4182 |
Transcript showCR:'hello' allItalic |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4183 |
" |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4184 |
! |
7bc4f1593b4e
allItalic now understood by CharacterArray
Claus Gittinger <cg@exept.de>
parents:
5848
diff
changeset
|
4185 |
|
6228 | 4186 |
colorizeAllWith:aColor |
4187 |
^ self asText colorizeAllWith:aColor |
|
4188 |
||
4189 |
" |
|
4190 |
Transcript showCR:('hello' colorizeAllWith:Color red) |
|
4191 |
Transcript showCR:('world' colorizeAllWith:Color green darkened) |
|
4192 |
" |
|
4193 |
! |
|
4194 |
||
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4195 |
emphasis |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4196 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4197 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4198 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4199 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4200 |
^ RunArray new:self size withAll:nil |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4201 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4202 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4203 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4204 |
|
6655 | 4205 |
emphasis:emphasisCollection |
4206 |
^ self asText emphasis:emphasisCollection |
|
4207 |
||
4208 |
" |
|
4209 |
Transcript showCR:('hello' emphasis:#(bold bold bold bold bold)) |
|
4210 |
" |
|
4211 |
! |
|
4212 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4213 |
emphasisAt:characterIndex |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4214 |
"return the emphasis at some index. |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4215 |
Since characterArrays do not hold any emphasis information, |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4216 |
nil (no emphasis) is returned here." |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4217 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4218 |
^ nil |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4219 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4220 |
"Created: 11.5.1996 / 14:13:27 / cg" |
1396
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4221 |
! |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4222 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4223 |
emphasisCollection |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4224 |
"return the emphasis. |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4225 |
Since characterArrays do not hold any emphasis information, |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4226 |
nil (no emphasis) is returned here." |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4227 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4228 |
^ RunArray new:(self size) |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4229 |
|
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4230 |
"Created: 14.5.1996 / 13:58:58 / cg" |
5b5386311dbd
concatenating mixed texts & strings
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
4231 |
"Modified: 14.5.1996 / 15:02:29 / cg" |
3404 | 4232 |
! |
4233 |
||
4234 |
emphasizeAllWith:emphasis |
|
4235 |
^ self asText emphasizeAllWith:emphasis |
|
4236 |
||
4237 |
" |
|
4238 |
Transcript showCR:('hello' emphasizeAllWith:#bold) |
|
3599 | 4239 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
4240 |
Transcript showCR:('hello' emphasizeAllWith:(#color -> Color red)) |
|
4241 |
" |
|
4242 |
||
4243 |
"Modified: / 17.6.1998 / 12:51:44 / cg" |
|
5097 | 4244 |
! |
4245 |
||
4246 |
makeSelectorBoldIn:aClass |
|
4247 |
"the receiver represents some source code for |
|
4248 |
a method in aClass. |
|
4249 |
Change myself to boldify the selector. |
|
4250 |
Not yet implemented (could easily use the syntaxHighlighter |
|
4251 |
for this ...)" |
|
4252 |
||
4253 |
^ self |
|
4254 |
||
4255 |
"Modified: / 13.12.1999 / 21:49:11 / cg" |
|
4256 |
"Created: / 13.12.1999 / 21:49:24 / cg" |
|
6653 | 4257 |
! |
4258 |
||
4259 |
withoutEmphasis:emphasisToRemove |
|
4260 |
^ self |
|
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4261 |
! ! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
4262 |
|
7265 | 4263 |
!CharacterArray methodsFor:'encoding & decoding'! |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4264 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4265 |
decodeFrom:encodingSymbol |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4266 |
"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
|
4267 |
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
|
4268 |
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
|
4269 |
(and those are untested/incomplete): |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4270 |
#euc |
997
6c7f1815ed02
more encoding & decoding support
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
4271 |
#jis7 |
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
4272 |
#sjis |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4273 |
#mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4274 |
#msdos |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4275 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4276 |
|
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4277 |
|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
|
4278 |
|
2736 | 4279 |
encodingSymbol == #'x-jis7' ifTrue:[ |
2733 | 4280 |
^ JISEncodedString decodeFromJIS7:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4281 |
]. |
2758 | 4282 |
encodingSymbol == #'x-iso2022-jp' ifTrue:[ |
4283 |
^ JISEncodedString decodeFromJIS7:self |
|
4284 |
]. |
|
2759 | 4285 |
encodingSymbol == #'iso2022-jp' ifTrue:[ |
4286 |
^ JISEncodedString decodeFromJIS7:self |
|
4287 |
]. |
|
2736 | 4288 |
encodingSymbol == #'x-sjis' ifTrue:[ |
2733 | 4289 |
^ JISEncodedString decodeFromSJIS:self |
2720
98c21d9a07c0
allow mixed strings to be concatenated using comma
Claus Gittinger <cg@exept.de>
parents:
2692
diff
changeset
|
4290 |
]. |
2736 | 4291 |
encodingSymbol == #'x-shift-jis' ifTrue:[ |
4292 |
^ JISEncodedString decodeFromSJIS:self |
|
4293 |
]. |
|
4294 |
encodingSymbol == #'x-euc-jp' ifTrue:[ |
|
2733 | 4295 |
^ 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
|
4296 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
4297 |
encodingSymbol == #big5 ifTrue:[ |
2733 | 4298 |
^ 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
|
4299 |
]. |
2736 | 4300 |
encodingSymbol == #gb2312 ifTrue:[ |
2733 | 4301 |
^ GBEncodedString decodeFromGB:self |
4302 |
]. |
|
2736 | 4303 |
encodingSymbol == #'x-euc-gb' ifTrue:[ |
4304 |
^ GBEncodedString decodeFromEUC:self |
|
4305 |
]. |
|
4306 |
encodingSymbol == #'x-euc-kr' ifTrue:[ |
|
4307 |
^ KSCEncodedString decodeFromEUC:self |
|
2733 | 4308 |
]. |
4309 |
||
4310 |
encodingSymbol == #ucs2 ifTrue:[ |
|
4311 |
^ UnicodeString decodeFromUCS2:self |
|
4312 |
]. |
|
4313 |
encodingSymbol == #ucs4 ifTrue:[ |
|
4314 |
^ UnicodeString decodeFromUCS4:self |
|
4315 |
]. |
|
4316 |
encodingSymbol == #utf7 ifTrue:[ |
|
4317 |
^ UnicodeString decodeFromUTF7:self |
|
4318 |
]. |
|
4319 |
encodingSymbol == #utf8 ifTrue:[ |
|
4320 |
^ UnicodeString decodeFromUTF8:self |
|
4321 |
]. |
|
4322 |
encodingSymbol == #utf16 ifTrue:[ |
|
4323 |
^ 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
|
4324 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
4325 |
|
2736 | 4326 |
|
4327 |
"/ soon obsolete ... |
|
4328 |
encodingSymbol == #jis7 ifTrue:[ |
|
4329 |
^ JISEncodedString decodeFromJIS7:self |
|
4330 |
]. |
|
4331 |
encodingSymbol == #sjis ifTrue:[ |
|
4332 |
^ JISEncodedString decodeFromSJIS:self |
|
4333 |
]. |
|
4334 |
encodingSymbol == #euc ifTrue:[ |
|
4335 |
^ JISEncodedString decodeFromEUC:self |
|
4336 |
]. |
|
4337 |
||
4338 |
encodingSymbol == #gb ifTrue:[ |
|
4339 |
^ GBEncodedString decodeFromGB:self |
|
4340 |
]. |
|
4341 |
encodingSymbol == #ksc ifTrue:[ |
|
4342 |
^ KSCEncodedString decodeFromKSC:self |
|
4343 |
]. |
|
4344 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4345 |
table := self class decoderTableFor:encodingSymbol. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4346 |
table isNil ifTrue:[^ self]. |
2736 | 4347 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4348 |
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
|
4349 |
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
|
4350 |
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
|
4351 |
^ newString |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4352 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4353 |
"Created: 22.2.1996 / 15:06:49 / cg" |
2759 | 4354 |
"Modified: 16.7.1997 / 13:45:33 / cg" |
2733 | 4355 |
! |
4356 |
||
4357 |
encodeForDisplayInto:encodingSymbol |
|
4358 |
"given the receiver in internal ST/X encoding, |
|
4359 |
convert it into the format as described by encodingSymbol |
|
4360 |
for display. |
|
4361 |
The receiver may contain roman characters in 0..255, which |
|
4362 |
are translated according to the encodings roman translation. |
|
4363 |
For example: in JIS, roman $a is found at 16r2361. |
|
4364 |
" |
|
4365 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4366 |
|newString table| |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4367 |
|
2733 | 4368 |
encodingSymbol isNil ifTrue:[^ self]. |
4369 |
||
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4370 |
"/ notice: this method may not be moved to |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4371 |
"/ concrete TwoByte classes; it is also invoked |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4372 |
"/ to convert singleByte strings ... |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4373 |
|
2733 | 4374 |
(encodingSymbol startsWith:'jis') ifTrue:[ |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4375 |
newString := JISEncodedString encodeRomans:self. |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4376 |
|
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4377 |
"/ jisx0208.1983 has no half-width katakana |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4378 |
(encodingSymbol startsWith:'jisx0208.1983') ifTrue:[ |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4379 |
newString := JISEncodedString encodeHalfWidthKatakana:newString. |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4380 |
]. |
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4381 |
^ newString |
2733 | 4382 |
]. |
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4383 |
|
2733 | 4384 |
(encodingSymbol startsWith:'big5') ifTrue:[ |
4385 |
^ BIG5EncodedString encodeRomans:self |
|
4386 |
]. |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4387 |
|
2733 | 4388 |
(encodingSymbol startsWith:'gb') ifTrue:[ |
4389 |
^ GBEncodedString encodeRomans:self |
|
4390 |
]. |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4391 |
|
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4392 |
(encodingSymbol startsWith:'ksc') ifTrue:[ |
2733 | 4393 |
^ KSCEncodedString encodeRomans:self |
4394 |
]. |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4395 |
|
2733 | 4396 |
(encodingSymbol startsWith:'uni') ifTrue:[ |
4397 |
^ UnicodeString encodeRomans:self |
|
4398 |
]. |
|
4399 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4400 |
table := self class encoderTableFor:encodingSymbol. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4401 |
table isNil ifTrue:[^ self]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4402 |
|
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4403 |
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
|
4404 |
newString replaceFrom:self translateBy:table. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4405 |
newString = self ifTrue:[^ self]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4406 |
^ newString |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4407 |
|
2742
3add77872fea
care for halfWidth kanakana characters
Claus Gittinger <cg@exept.de>
parents:
2740
diff
changeset
|
4408 |
"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
|
4409 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4410 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4411 |
encodeInto:encodingSymbol |
2733 | 4412 |
"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
|
4413 |
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
|
4414 |
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
|
4415 |
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
|
4416 |
(and those are untested/incomplete): |
2736 | 4417 |
#x-euc-jp |
2760 | 4418 |
#x-jis7 (== iso2022-jp) |
2736 | 4419 |
#x-sjis |
4420 |
#x-shift-jis |
|
2733 | 4421 |
#big5 |
4422 |
#gb |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4423 |
#mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4424 |
#msdos |
2733 | 4425 |
#next |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4426 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4427 |
|
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4428 |
|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
|
4429 |
|
1204 | 4430 |
"/ 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
|
4431 |
|
1028 | 4432 |
encodingSymbol isNil ifTrue:[^ self]. |
4433 |
||
2736 | 4434 |
encodingSymbol == #'x-jis7' ifTrue:[ |
2733 | 4435 |
^ JISEncodedString encodeIntoJIS7:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4436 |
]. |
2759 | 4437 |
encodingSymbol == #'x-iso2022-jp' ifTrue:[ |
4438 |
^ JISEncodedString encodeIntoJIS7:self |
|
4439 |
]. |
|
4440 |
encodingSymbol == #'iso2022-jp' ifTrue:[ |
|
4441 |
^ JISEncodedString encodeIntoJIS7:self |
|
4442 |
]. |
|
2736 | 4443 |
encodingSymbol == #'x-sjis' ifTrue:[ |
2733 | 4444 |
^ JISEncodedString encodeIntoSJIS:self |
1013
0e54ddc990cb
more 16bit & encoding support
Claus Gittinger <cg@exept.de>
parents:
1012
diff
changeset
|
4445 |
]. |
2736 | 4446 |
encodingSymbol == #'x-shift-jis' ifTrue:[ |
4447 |
^ JISEncodedString encodeIntoSJIS:self |
|
4448 |
]. |
|
4449 |
encodingSymbol == #'x-euc-jp' ifTrue:[ |
|
2733 | 4450 |
^ 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
|
4451 |
]. |
2733 | 4452 |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
4453 |
encodingSymbol == #big5 ifTrue:[ |
2733 | 4454 |
^ BIG5EncodedString encodeIntoBIG5:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
4455 |
]. |
2736 | 4456 |
|
4457 |
encodingSymbol == #gb2312 ifTrue:[ |
|
2733 | 4458 |
^ GBEncodedString encodeIntoGB:self |
4459 |
]. |
|
2736 | 4460 |
encodingSymbol == #'x-euc-gb' ifTrue:[ |
4461 |
^ GBEncodedString encodeIntoGB:self |
|
4462 |
]. |
|
4463 |
||
4464 |
encodingSymbol == #'x-euc-kr' ifTrue:[ |
|
2733 | 4465 |
^ KSCEncodedString encodeIntoKSC:self |
4466 |
]. |
|
4467 |
||
4468 |
encodingSymbol == #ucs2 ifTrue:[ |
|
4469 |
^ 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
|
4470 |
]. |
2733 | 4471 |
encodingSymbol == #ucs4 ifTrue:[ |
4472 |
^ UnicodeString encodeIntoUCS4:self |
|
4473 |
]. |
|
4474 |
encodingSymbol == #utf7 ifTrue:[ |
|
4475 |
^ UnicodeString encodeIntoUTF7:self |
|
4476 |
]. |
|
4477 |
encodingSymbol == #utf8 ifTrue:[ |
|
4478 |
^ UnicodeString encodeIntoUTF8:self |
|
4479 |
]. |
|
4480 |
encodingSymbol == #utf16 ifTrue:[ |
|
4481 |
^ 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
|
4482 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
4483 |
|
2736 | 4484 |
|
4485 |
"/ to be obsoleted ... |
|
4486 |
encodingSymbol == #jis7 ifTrue:[ |
|
4487 |
^ JISEncodedString encodeIntoJIS7:self |
|
4488 |
]. |
|
4489 |
encodingSymbol == #sjis ifTrue:[ |
|
4490 |
^ JISEncodedString encodeIntoSJIS:self |
|
4491 |
]. |
|
4492 |
encodingSymbol == #euc ifTrue:[ |
|
4493 |
^ JISEncodedString encodeIntoEUC:self |
|
4494 |
]. |
|
4495 |
||
4496 |
encodingSymbol == #gb ifTrue:[ |
|
4497 |
^ GBEncodedString encodeIntoGB:self |
|
4498 |
]. |
|
4499 |
encodingSymbol == #ksc ifTrue:[ |
|
4500 |
^ KSCEncodedString encodeIntoKSC:self |
|
4501 |
]. |
|
4502 |
||
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4503 |
table := self class encoderTableFor:encodingSymbol. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4504 |
table isNil ifTrue:[^ self]. |
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4505 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4506 |
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
|
4507 |
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
|
4508 |
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
|
4509 |
^ newString |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4510 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4511 |
"Created: 22.2.1996 / 15:07:31 / cg" |
2760 | 4512 |
"Modified: 16.7.1997 / 13:56:21 / cg" |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4513 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4514 |
|
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4515 |
encodeOn:anEncoder with:aParameter |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4516 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4517 |
anEncoder encodeString:self with:aParameter |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4518 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4519 |
! |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4520 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4521 |
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
|
4522 |
"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
|
4523 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4524 |
^ 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
|
4525 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4526 |
"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
|
4527 |
"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
|
4528 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4529 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4530 |
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
|
4531 |
"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
|
4532 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4533 |
^ 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
|
4534 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4535 |
"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
|
4536 |
"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
|
4537 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4538 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4539 |
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
|
4540 |
"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
|
4541 |
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
|
4542 |
|
2520
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4543 |
|mySize "{ Class: SmallInteger }" |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4544 |
maxCode "{ Class: SmallInteger }" |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4545 |
char |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4546 |
oldCode "{ Class: SmallInteger }" |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4547 |
newCode| |
1023 | 4548 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4549 |
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
|
4550 |
encodingTable isNil ifTrue:[^ self]. |
2740
8649f17f9148
added support for hp's non-iso font encodings
Claus Gittinger <cg@exept.de>
parents:
2737
diff
changeset
|
4551 |
|
2520
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4552 |
maxCode := encodingTable size. |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4553 |
mySize := self size. |
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4554 |
|
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4555 |
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
|
4556 |
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
|
4557 |
oldCode := char asciiValue. |
2520
4a7a2f2f0132
tuned #replaceFrom:translateBy:
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
4558 |
oldCode >= maxCode ifFalse:[ |
1023 | 4559 |
newCode := encodingTable at:(oldCode + 1). |
4560 |
newCode ~~ oldCode ifTrue:[ |
|
4561 |
self at:index put:(Character value:newCode) |
|
4562 |
] |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4563 |
] |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4564 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4565 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4566 |
"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
|
4567 |
"Modified: 1.7.1997 / 17:18:06 / cg" |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4568 |
! |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4569 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4570 |
rot13 |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4571 |
"Usenet: from `rotate alphabet 13 places'] |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4572 |
The simple Caesar-cypher encryption that replaces each English |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4573 |
letter with the one 13 places forward or back along the alphabet, |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4574 |
so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4575 |
Most Usenet news reading and posting programs include a rot13 feature. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4576 |
It is used to enclose the text in a sealed wrapper that the reader must choose |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4577 |
to open -- e.g., for posting things that might offend some readers, or spoilers. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4578 |
A major advantage of rot13 over rot(N) for other N is that it |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4579 |
is self-inverse, so the same code can be used for encoding and decoding." |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4580 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4581 |
^ self species |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4582 |
streamContents:[:aStream | |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4583 |
self do:[:char | |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4584 |
aStream nextPut:char rot13 ]] |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4585 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4586 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4587 |
'hello world' rot13 |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4588 |
'hello world' rot13 rot13 |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4589 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4590 |
! |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4591 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4592 |
utf8Decoded |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4593 |
"Interpreting myself as an UTF-8 representation, decode and return |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4594 |
the decoded string." |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4595 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4596 |
|in out is16Bit c| |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4597 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4598 |
is16Bit := false. |
7685
535a69a7cd69
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7643
diff
changeset
|
4599 |
out := (String uninitializedNew:self size) writeStream. |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4600 |
in := self readStream. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4601 |
[in atEnd] whileFalse:[ |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4602 |
c := Character utf8DecodeFrom:in. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4603 |
is16Bit ifFalse:[ |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4604 |
c asciiValue > 16rFF ifTrue:[ |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4605 |
"/ c := Character space. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4606 |
out := WriteStream with:(UnicodeString fromString:out contents). |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4607 |
is16Bit := true. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4608 |
]. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4609 |
]. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4610 |
out nextPut:c. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4611 |
]. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4612 |
^ out contents |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4613 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4614 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4615 |
#[16rC8 16rA0] asString utf8Decoded |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4616 |
(Character value:16r220) utf8Encoded |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4617 |
(Character value:16r220) utf8Encoded utf8Decoded |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4618 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4619 |
(Character value:16r800) utf8Encoded |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4620 |
(Character value:16r220) utf8Encoded utf8Decoded |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4621 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4622 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4623 |
"test: |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4624 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4625 |
|utf8Encoding original readBack| |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4626 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4627 |
1 to:16rFFFF do:[:ascii | |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4628 |
original := (Character value:ascii) asString. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4629 |
utf8Encoding := original utf8Encoded. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4630 |
readBack := utf8Encoding utf8Decoded. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4631 |
readBack = original ifFalse:[ |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4632 |
self halt |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4633 |
] |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4634 |
] |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4635 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4636 |
! |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4637 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4638 |
utf8DecodedWithTwoByteCharactersReplacedBy:replacementCharacter |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4639 |
"Interpreting myself as an UTF-8 representation, decode and return |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4640 |
the decoded string. Suppress all 2-byte (above 16rFF) characters, |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4641 |
and replace them with replacementCharacter" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4642 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4643 |
|in out c| |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4644 |
|
7685
535a69a7cd69
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7643
diff
changeset
|
4645 |
out := (String uninitializedNew:self size) writeStream. |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4646 |
in := self readStream. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4647 |
[in atEnd] whileFalse:[ |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4648 |
c := Character utf8DecodeFrom:in. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4649 |
c asciiValue > 16rFF ifTrue:[ |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4650 |
c := replacementCharacter |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4651 |
]. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4652 |
out nextPut:c. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4653 |
]. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4654 |
^ out contents |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4655 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4656 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4657 |
(Character value:16r220) utf8Encoded |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4658 |
utf8DecodedWithTwoByteCharactersReplacedBy:(Character space) |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4659 |
" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4660 |
! |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4661 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4662 |
utf8Encoded |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4663 |
"Return my UTF-8 representation as a new String" |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4664 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4665 |
|s| |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4666 |
|
7685
535a69a7cd69
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7643
diff
changeset
|
4667 |
s := (String uninitializedNew:self size) writeStream. |
6835
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4668 |
self utf8EncodedOn:s. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4669 |
^ s contents |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4670 |
! |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4671 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4672 |
utf8EncodedOn:aStream |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4673 |
"append my UTF-8 representation to the argument, aStream." |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4674 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4675 |
|
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4676 |
self do:[:c| |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4677 |
c utf8EncodedOn:aStream. |
bdb2cb03200c
added utf8Decode with 8-bit chars only
Claus Gittinger <cg@exept.de>
parents:
6834
diff
changeset
|
4678 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4679 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
4680 |
|
608 | 4681 |
!CharacterArray methodsFor:'padded copying'! |
4682 |
||
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4683 |
centerPaddedTo:newSize |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4684 |
"return a new string consisting of the receivers characters, |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4685 |
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
|
4686 |
the resulting string. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4687 |
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
|
4688 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4689 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4690 |
^ self centerPaddedTo:newSize with:(Character space) |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4691 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4692 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4693 |
'foo' centerPaddedTo:10 |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4694 |
123 printString centerPaddedTo:10 |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4695 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4696 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4697 |
"Created: 25.11.1995 / 10:53:57 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4698 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4699 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4700 |
centerPaddedTo:size with:padCharacter |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4701 |
"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
|
4702 |
centered (i.e. padded on both sides). |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4703 |
Characters are filled with padCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4704 |
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
|
4705 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4706 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4707 |
|len s| |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4708 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4709 |
len := self size. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4710 |
(len < size) ifTrue:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4711 |
s := self species new:size withAll:padCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4712 |
s replaceFrom:(size - len) // 2 + 1 with:self. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4713 |
^ s |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4714 |
] |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4715 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4716 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4717 |
'foo' centerPaddedTo:11 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4718 |
'fooBar' centerPaddedTo:5 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4719 |
123 printString centerPaddedTo:10 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4720 |
(' ' , 123 printString) centerPaddedTo:10 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4721 |
(Float pi printString) centerPaddedTo:15 with:(Character space) |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4722 |
(Float pi printString) centerPaddedTo:15 with:$- |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4723 |
(' ' , Float pi class name) centerPaddedTo:15 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4724 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4725 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4726 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4727 |
decimalPaddedTo:size and:afterPeriod at:decimalCharacter |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4728 |
"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
|
4729 |
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
|
4730 |
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
|
4731 |
to be padded). |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4732 |
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
|
4733 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4734 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4735 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4736 |
^ self |
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4737 |
decimalPaddedTo:size |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4738 |
and:afterPeriod |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4739 |
at:decimalCharacter |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4740 |
withLeft:(Character space) |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
4741 |
right:$0 |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4742 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4743 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4744 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123 ' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4745 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4746 |
'123.' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4747 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.100' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4748 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.1 ' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4749 |
'123.123' decimalPaddedTo:10 and:3 at:$. -> ' 123.123' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4750 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4751 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4752 |
"Created: 23.12.1995 / 13:11:52 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4753 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4754 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4755 |
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
|
4756 |
"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
|
4757 |
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
|
4758 |
of the period. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4759 |
Characters on the left are filled with leftPadChar. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4760 |
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
|
4761 |
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
|
4762 |
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
|
4763 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4764 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4765 |
|
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4766 |
|s idx n rest| |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4767 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4768 |
idx := self indexOf:decimalCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4769 |
idx == 0 ifTrue:[ |
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4770 |
"/ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4771 |
"/ no decimal point found; adjust string to the left of the period column |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4772 |
"/ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4773 |
rightPadChar isNil ifTrue:[ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4774 |
s := self , (self species new:afterPeriod + 1 withAll:leftPadChar) |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4775 |
] ifFalse:[ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4776 |
s:= self , decimalCharacter asString , (self species new:afterPeriod withAll:rightPadChar). |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4777 |
]. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4778 |
] ifFalse:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4779 |
|
5230
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4780 |
"/ the number of after-decimalPoint characters |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4781 |
n := self size - idx. |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4782 |
rest := afterPeriod - n. |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4783 |
rest > 0 ifTrue:[ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4784 |
s := (self species new:rest withAll:(rightPadChar ? leftPadChar)). |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4785 |
] ifFalse:[ |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4786 |
s := '' |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4787 |
]. |
655c21ffe6cc
care for negative size of rest-string when decimalPadding
Claus Gittinger <cg@exept.de>
parents:
5221
diff
changeset
|
4788 |
s := self , s. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4789 |
]. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4790 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4791 |
^ s leftPaddedTo:size with:leftPadChar |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4792 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4793 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4794 |
'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
|
4795 |
'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
|
4796 |
'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
|
4797 |
'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
|
4798 |
'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
|
4799 |
'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
|
4800 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4801 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4802 |
"Modified: 23.12.1995 / 13:08:18 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4803 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4804 |
|
608 | 4805 |
leftPaddedTo:size |
4806 |
"return a new string of length size, which contains the receiver |
|
4807 |
right-adjusted (i.e. padded on the left). |
|
4808 |
Characters on the left are filled with spaces. |
|
4809 |
If the receivers size is equal or greater than the length argument, |
|
4810 |
the original receiver is returned unchanged." |
|
4811 |
||
4812 |
^ self leftPaddedTo:size with:(Character space) |
|
4813 |
||
4814 |
" |
|
4815 |
'foo' leftPaddedTo:10 |
|
4816 |
'fooBar' leftPaddedTo:5 |
|
4817 |
123 printString leftPaddedTo:10 |
|
4818 |
" |
|
4819 |
! |
|
4820 |
||
4821 |
paddedTo:newSize |
|
4822 |
"return a new string consisting of the receivers characters, |
|
4823 |
plus spaces up to length. |
|
4824 |
If the receivers size is equal or greater than the length argument, |
|
4825 |
the original receiver is returned unchanged." |
|
4826 |
||
4827 |
^ self paddedTo:newSize with:(Character space) |
|
4828 |
||
4829 |
" |
|
4830 |
'foo' paddedTo:10 |
|
4831 |
123 printString paddedTo:10 |
|
4832 |
" |
|
64 | 4833 |
! ! |
4834 |
||
328 | 4835 |
!CharacterArray methodsFor:'pattern matching'! |
4836 |
||
2551 | 4837 |
compoundMatch:aString |
3253 | 4838 |
"like match, but the receiver may be a compound match pattern, |
2551 | 4839 |
consisting of multiple simple patterns, separated by semicolons. |
4840 |
This is usable with fileName pattern fields." |
|
4841 |
||
5124
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4842 |
^self compoundMatch:aString ignoreCase:false |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4843 |
|
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4844 |
" |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4845 |
'f*' match:'foo' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4846 |
'b*' match:'foo' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4847 |
'f*;b*' match:'foo' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4848 |
'f*;b*' match:'bar' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4849 |
'f*;b*' compoundMatch:'foo' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4850 |
'f*;b*' compoundMatch:'bar' |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4851 |
" |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4852 |
|
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4853 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4854 |
"Modified: / 16.12.1999 / 01:22:08 / cg" |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4855 |
! |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4856 |
|
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4857 |
compoundMatch:aString ignoreCase:ignoreCase |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4858 |
"like match, but the receiver may be a compound match pattern, |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4859 |
consisting of multiple simple patterns, separated by semicolons. |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4860 |
This is usable with fileName pattern fields." |
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4861 |
|
2551 | 4862 |
|matchers| |
4863 |
||
4864 |
matchers := self asCollectionOfSubstringsSeparatedBy:$;. |
|
4865 |
matchers do:[:aPattern | |
|
5124
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4866 |
(aPattern match:aString ignoreCase:ignoreCase) ifTrue:[^ true]. |
2551 | 4867 |
]. |
4868 |
^ false. |
|
4869 |
||
4870 |
" |
|
4871 |
'f*' match:'foo' |
|
4872 |
'b*' match:'foo' |
|
4873 |
'f*;b*' match:'foo' |
|
4874 |
'f*;b*' match:'bar' |
|
4875 |
'f*;b*' compoundMatch:'foo' |
|
4876 |
'f*;b*' compoundMatch:'bar' |
|
5124
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4877 |
'f*;b*' compoundMatch:'Foo' ignoreCase:true |
2551 | 4878 |
" |
4879 |
||
3253 | 4880 |
"Modified: / 15.4.1997 / 15:50:33 / cg" |
4881 |
"Modified: / 30.1.1998 / 11:40:18 / stefan" |
|
5124
727f88b16fb3
case-insensitive version of compoundMatch: added
Claus Gittinger <cg@exept.de>
parents:
5097
diff
changeset
|
4882 |
"Created: / 16.12.1999 / 01:21:35 / cg" |
2551 | 4883 |
! |
4884 |
||
328 | 4885 |
findMatchString:matchString |
368 | 4886 |
"like findString/indexOfSubCollection, but allowing match patterns. |
328 | 4887 |
find matchstring; if found, return the index; |
4888 |
if not found, return 0." |
|
4889 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
4890 |
^ self findMatchString:matchString startingAt:1 ignoreCase:false ifAbsent:0 |
328 | 4891 |
! |
4892 |
||
4893 |
findMatchString:matchString startingAt:index |
|
4894 |
"like findString, but allowing match patterns. |
|
4895 |
find matchstring, starting at index. if found, return the index; |
|
4896 |
if not found, return 0." |
|
4897 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
4898 |
^ self findMatchString:matchString startingAt:index ignoreCase:false ifAbsent:0 |
328 | 4899 |
! |
4900 |
||
4901 |
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock |
|
4902 |
"like findString, but allowing match patterns. |
|
4903 |
find matchstring, starting at index. if found, return the index; |
|
4904 |
if not found, return the result of evaluating exceptionBlock. |
|
4905 |
This is a q&d hack - not very efficient" |
|
4906 |
||
2916 | 4907 |
|firstChar firstSet |
328 | 4908 |
startIndex "{ Class: SmallInteger }" |
4909 |
matchSize "{ Class: SmallInteger }" |
|
4910 |
mySize "{ Class: SmallInteger }" |
|
4911 |
realMatchString| |
|
4912 |
||
4913 |
matchSize := matchString size. |
|
4914 |
matchSize == 0 ifTrue:[^ index]. "empty string matches" |
|
4915 |
||
4916 |
realMatchString := matchString. |
|
4917 |
(realMatchString endsWith:$*) ifFalse:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4918 |
realMatchString := realMatchString , '*'. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4919 |
matchSize := matchSize + 1 |
328 | 4920 |
]. |
4921 |
||
4922 |
mySize := self size. |
|
4923 |
firstChar := realMatchString at:1. |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
4924 |
firstChar == self class matchEscapeCharacter ifTrue:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4925 |
firstChar := realMatchString at:2. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4926 |
]. |
328 | 4927 |
|
4928 |
firstChar asString includesMatchCharacters ifTrue:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4929 |
index to:mySize do:[:col | |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4930 |
(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
|
4931 |
ifTrue:[^ col] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4932 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4933 |
^ exceptionBlock value. |
328 | 4934 |
]. |
2916 | 4935 |
ignoreCase ifTrue:[ |
4936 |
firstSet := String with:(firstChar asUppercase) with:(firstChar asLowercase). |
|
4937 |
startIndex := self indexOfAny:firstSet startingAt:index. |
|
4938 |
] ifFalse:[ |
|
4939 |
startIndex := self indexOf:firstChar startingAt:index. |
|
4940 |
]. |
|
328 | 4941 |
[startIndex == 0] whileFalse:[ |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4942 |
(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
|
4943 |
ifTrue:[^ startIndex]. |
2916 | 4944 |
ignoreCase ifTrue:[ |
4945 |
startIndex := self indexOfAny:firstSet startingAt:(startIndex + 1). |
|
4946 |
] ifFalse:[ |
|
4947 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1). |
|
4948 |
]. |
|
328 | 4949 |
]. |
4950 |
^ exceptionBlock value |
|
4951 |
||
4952 |
" |
|
4953 |
'one two three four' findMatchString:'o[nu]' |
|
4954 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
2916 | 4955 |
'one two three four one' findMatchString:'ONE' startingAt:3 ignoreCase:true ifAbsent:0 |
328 | 4956 |
" |
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4957 |
|
2916 | 4958 |
"Modified: 13.9.1997 / 06:31:22 / cg" |
328 | 4959 |
! |
4960 |
||
608 | 4961 |
includesMatchString:matchString |
4962 |
"like includesString, but allowing match patterns. |
|
4963 |
find matchstring; if found, return true, otherwise return false" |
|
4964 |
||
4965 |
^ (self findMatchString:matchString) ~~ 0 |
|
4966 |
||
4967 |
" |
|
4968 |
'hello world' includesMatchString:'h*' |
|
4969 |
'hello world' includesMatchString:'h[aeiou]llo' |
|
4970 |
'hello world' includesMatchString:'wor*' |
|
4971 |
'hello world' includesMatchString:'woR*' |
|
4972 |
" |
|
4973 |
! |
|
4974 |
||
328 | 4975 |
match:aString |
4976 |
"return true if aString matches self, where self may contain meta-match |
|
4977 |
characters $* (to match any string) or $# (to match any character). |
|
4978 |
or [...] to match a set of characters. |
|
345 | 4979 |
Lower/uppercase are considered different. |
4980 |
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
|
4981 |
NOT the ST-80 meaning." |
328 | 4982 |
|
4983 |
^ self match:aString from:1 to:aString size ignoreCase:false |
|
4984 |
||
4985 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4986 |
'\*f*' match:'f' |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4987 |
'\*f*' match:'*f' |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4988 |
'*\*f*' match:'*f' |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
4989 |
'*f*' match:'*f' |
328 | 4990 |
'*ute*' match:'computer' |
4991 |
'*uter' match:'computer' |
|
4992 |
'uter*' match:'computer' |
|
4993 |
'*ute*' match:'' |
|
4994 |
'[abcd]*' match:'computer' |
|
4995 |
'[abcd]*' match:'komputer' |
|
4996 |
'*some*compl*ern*' match:'this is some more complicated pattern match' |
|
4997 |
'*some*compl*ern*' match:'this is another complicated pattern match' |
|
3537 | 4998 |
'*-hh' match:'anton-h' |
4999 |
" |
|
5000 |
||
5001 |
"Modified: / 9.6.1998 / 18:50:00 / cg" |
|
328 | 5002 |
! |
5003 |
||
5004 |
match:aString from:start to:stop ignoreCase:ignoreCase |
|
5005 |
"return true if part of aString matches myself, |
|
5006 |
where self may contain meta-match |
|
5007 |
characters $* (to match any string) or $# (to match any character) |
|
5008 |
or [...] to match a set of characters. |
|
345 | 5009 |
If ignoreCase is true, lower/uppercase are considered the same. |
5010 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
1429 | 5011 |
NOT the ST-80 meaning." |
328 | 5012 |
|
5013 |
|matchScanArray| |
|
5014 |
||
5015 |
" |
|
5016 |
keep the matchScanArray from the most recent match - |
|
5017 |
avoids parsing the pattern over-and over if multiple searches |
|
5018 |
are done with the same pattern. |
|
5019 |
" |
|
5020 |
(PreviousMatch notNil |
|
5021 |
and:[PreviousMatch key = self]) ifTrue:[ |
|
1429 | 5022 |
matchScanArray := PreviousMatch value |
328 | 5023 |
] ifFalse:[ |
1429 | 5024 |
matchScanArray := self class matchScanArrayFrom:self. |
5025 |
matchScanArray isNil ifTrue:[ |
|
3926 | 5026 |
'CharacterArray [info]: invalid matchpattern:''' infoPrint. self infoPrint. ''' comparing for equality.' infoPrintCR. |
5027 |
^ self = aString |
|
5028 |
"/ ^ false |
|
1429 | 5029 |
]. |
5030 |
PreviousMatch := self -> matchScanArray. |
|
328 | 5031 |
]. |
5032 |
||
5033 |
^ self class |
|
1429 | 5034 |
matchScan:matchScanArray |
5035 |
from:1 to:matchScanArray size |
|
5036 |
with:aString |
|
5037 |
from:start to:stop |
|
5038 |
ignoreCase:ignoreCase |
|
328 | 5039 |
|
5040 |
" |
|
5041 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
5042 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
5043 |
" |
|
1429 | 5044 |
|
3926 | 5045 |
"Modified: / 10.11.1998 / 21:43:46 / cg" |
359 | 5046 |
! |
5047 |
||
608 | 5048 |
match:aString ignoreCase:ignoreCase |
5049 |
"return true if aString matches self, where self may contain meta-match |
|
5050 |
characters $* (to match any string) or $# (to match any character) |
|
5051 |
or [...] to match a set of characters. |
|
5052 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
5053 |
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
|
5054 |
NOT the ST-80 meaning." |
608 | 5055 |
|
5056 |
^ self match:aString from:1 to:aString size ignoreCase:ignoreCase |
|
5057 |
||
5058 |
" |
|
5059 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
5060 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
5061 |
'[abcd]*' match:'computer' ignoreCase:false |
|
5062 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
5063 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
5064 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
5065 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
5066 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
5067 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
5068 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
5069 |
||
5070 |
Time millisecondsToRun:[ |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
5071 |
Symbol allInstancesDo:[:sym | |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
5072 |
'[ab]*' match:sym ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
5073 |
] |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
5074 |
]. |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
5075 |
Time millisecondsToRun:[ |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
5076 |
Symbol allInstancesDo:[:sym | |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
5077 |
'*at:*' match:sym ignoreCase:false |
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
5078 |
] |
608 | 5079 |
]. |
5080 |
" |
|
2519
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
5081 |
|
07674cea76dd
allow escaping a * when doing a match
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
5082 |
"Modified: 2.4.1997 / 17:28:58 / cg" |
5609 | 5083 |
! |
5084 |
||
5085 |
matches:aPatternString |
|
5086 |
"return true if the receiver matches aString, where aPatternString may contain meta-match |
|
5087 |
characters $* (to match any string) or $# (to match any character). |
|
5088 |
or [...] to match a set of characters. |
|
5089 |
Lower/uppercase are considered different. |
|
5090 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
5091 |
NOT the ST-80 meaning." |
|
5092 |
||
5093 |
^ aPatternString match:self |
|
5094 |
||
5095 |
||
608 | 5096 |
! ! |
5097 |
||
5098 |
!CharacterArray methodsFor:'printing & storing'! |
|
5099 |
||
5100 |
article |
|
5101 |
"return an article string for the receiver." |
|
5102 |
||
5103 |
|firstChar| |
|
5104 |
||
5105 |
firstChar := (self at:1) asLowercase. |
|
5848 | 5106 |
((firstChar isVowel and:[firstChar ~~ $u]) or:[firstChar == $x]) ifTrue:[ |
5107 |
^ 'an' |
|
608 | 5108 |
]. |
5109 |
^ 'a' |
|
5848 | 5110 |
|
5111 |
" |
|
5112 |
'uboot' article. |
|
5113 |
'xmas' article. |
|
5114 |
'alarm' article. |
|
5115 |
'baby' article. |
|
5116 |
" |
|
608 | 5117 |
! |
5118 |
||
5119 |
displayString |
|
5120 |
"return a string to display the receiver - use storeString to have |
|
5121 |
quotes around." |
|
5122 |
||
5123 |
^ self storeString |
|
5124 |
! |
|
5125 |
||
5126 |
printOn:aStream |
|
5127 |
"print the receiver on aStream" |
|
5128 |
||
5129 |
aStream nextPutAll:self |
|
5130 |
! |
|
5131 |
||
5132 |
printString |
|
5133 |
"return a string for printing - thats myself" |
|
5134 |
||
5135 |
^ self |
|
3578 | 5136 |
! |
5137 |
||
5138 |
printWithQuotesDoubledOn:aStream |
|
5139 |
"put the raw storeString of myself on aStream" |
|
5140 |
||
5141 |
self do:[:thisChar | |
|
5142 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
5143 |
aStream nextPut:thisChar |
|
5144 |
] |
|
5145 |
||
5146 |
"Modified: / 15.6.1998 / 17:21:17 / cg" |
|
5147 |
"Created: / 15.6.1998 / 17:22:13 / cg" |
|
608 | 5148 |
! ! |
5149 |
||
5150 |
!CharacterArray methodsFor:'queries'! |
|
5151 |
||
4429 | 5152 |
bitsPerCharacter |
5153 |
"return the underlying strings bitsPerCharacter |
|
5154 |
(i.e. is it a regular String or a TwoByteString)" |
|
5155 |
||
5156 |
^ self string bitsPerCharacter |
|
5157 |
||
5158 |
" |
|
5159 |
'hello' bitsPerCharacter |
|
5160 |
'hello' asText allBold bitsPerCharacter |
|
5161 |
" |
|
5162 |
! |
|
5163 |
||
608 | 5164 |
encoding |
1311 | 5165 |
"return the strings encoding, as a symbol. |
5166 |
Here, by default, we assume #iso8859 encoding. |
|
1241 | 5167 |
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
|
5168 |
|
1311 | 5169 |
^ #iso8859 |
5170 |
||
5171 |
"Modified: 27.4.1996 / 13:23:49 / cg" |
|
608 | 5172 |
! |
5173 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5174 |
hasChangeOfEmphasis |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5175 |
^ false |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5176 |
|
1381 | 5177 |
"Created: 12.5.1996 / 12:31:39 / cg" |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5178 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
5179 |
|
1388 | 5180 |
heightOn:aGC |
5181 |
"return the size of the recevier in device units if displayed on aGC" |
|
5182 |
||
6528 | 5183 |
^ (aGC font onDevice:aGC device) heightOf:self |
1388 | 5184 |
|
5185 |
" |
|
5186 |
'hello world' heightOn:(View new) |
|
5187 |
" |
|
5188 |
||
5189 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
5190 |
"Modified: 12.5.1996 / 20:32:05 / cg" |
|
5191 |
! |
|
5192 |
||
608 | 5193 |
isString |
5194 |
"return true, if the receiver is some kind of string; |
|
5195 |
true is returned here - redefinition of Object>>isString." |
|
5196 |
||
5197 |
^ true |
|
1235 | 5198 |
! |
5199 |
||
5200 |
leftIndent |
|
5201 |
"if the receiver starts with spaces, return the number of spaces |
|
5202 |
at the left - otherwise, return 0. |
|
5203 |
If the receiver consists of spaces only, return the receivers size." |
|
5204 |
||
5205 |
|index "{Class: SmallInteger }" |
|
5206 |
end "{Class: SmallInteger }"| |
|
5207 |
||
5208 |
index := 1. |
|
5209 |
end := self size. |
|
5210 |
[index <= end] whileTrue:[ |
|
5211 |
(self at:index) isSeparator ifFalse:[^ index - 1]. |
|
5212 |
index := index + 1 |
|
5213 |
]. |
|
5214 |
^ end |
|
5215 |
||
5216 |
" |
|
5217 |
' hello' leftIndent |
|
5218 |
'foo ' leftIndent |
|
5219 |
' ' leftIndent |
|
5220 |
" |
|
5221 |
||
5222 |
"Modified: 20.4.1996 / 19:28:43 / cg" |
|
1388 | 5223 |
! |
5224 |
||
6653 | 5225 |
widthFrom:startIndex to:endIndex on:aGC |
5226 |
"return ths size of part of the recevier in device units if displayed on aGC" |
|
5227 |
||
5228 |
^ (aGC font onDevice:aGC device) widthOf:self from:startIndex to:endIndex |
|
5229 |
||
5230 |
" |
|
5231 |
'hello world' widthFrom:1 to:5 on:(View new) |
|
5232 |
'hello' widthOn:(View new) |
|
5233 |
" |
|
5234 |
! |
|
5235 |
||
1388 | 5236 |
widthOn:aGC |
5237 |
"return ths size of the recevier in device units if displayed on aGC" |
|
5238 |
||
6528 | 5239 |
^ (aGC font onDevice:aGC device) widthOf:self |
1388 | 5240 |
|
5241 |
" |
|
5242 |
'hello world' widthOn:(View new) |
|
5243 |
" |
|
5244 |
||
5245 |
"Created: 12.5.1996 / 20:09:29 / cg" |
|
2554 | 5246 |
"Modified: 17.4.1997 / 12:50:23 / cg" |
608 | 5247 |
! ! |
5248 |
||
7349 | 5249 |
!CharacterArray methodsFor:'regular expressions'! |
5250 |
||
5251 |
allRegexMatches: rxString |
|
5252 |
"return a collection of substrings in the receiver, which match the regular expression in rxString" |
|
5253 |
||
5254 |
^ rxString asRegex matchesIn: self |
|
5255 |
||
5256 |
" |
|
5257 |
'1234 abcd 3456 defg' allRegexMatches:'[0-9]+' |
|
5258 |
||
5259 |
'[0-9]+' asRegex matchesIn:'1234 abcd 3456 defg' |
|
5260 |
" |
|
5261 |
! |
|
5262 |
||
5263 |
asRegex |
|
5264 |
"Compile the receiver as a regex matcher. |
|
5265 |
May raise RxParser>>syntaxErrorSignal or RxParser>>compilationErrorSignal. |
|
5266 |
This is a part of the Regular Expression Matcher package, |
|
5267 |
(c) 1996, 1999 Vassili Bykov. |
|
5268 |
Refer to `documentation' protocol of RxParser class for details." |
|
5269 |
||
5270 |
^ Regex::RxParser preferredMatcherClass |
|
5271 |
for: (Regex::RxParser new parse: self) |
|
5272 |
! |
|
5273 |
||
5274 |
asRegexIgnoringCase |
|
5275 |
"Compile the receiver as a regex matcher. |
|
5276 |
May raise RxParser>>syntaxErrorSignal or RxParser>>compilationErrorSignal. |
|
5277 |
This is a part of the Regular Expression Matcher package, |
|
5278 |
(c) 1996, 1999 Vassili Bykov. |
|
5279 |
Refer to `documentation' protocol of RxParser class for details." |
|
5280 |
||
5281 |
^ Regex::RxParser preferredMatcherClass |
|
5282 |
for: (Regex::RxParser new parse: self) |
|
5283 |
ignoreCase: true |
|
5284 |
! |
|
5285 |
||
5286 |
copyWithRegex: rxString matchesReplacedWith: aString |
|
5287 |
^ rxString asRegex copy: self replacingMatchesWith: aString |
|
5288 |
! |
|
5289 |
||
5290 |
copyWithRegex: rxString matchesTranslatedUsing: aBlock |
|
5291 |
^ rxString asRegex copy: self translatingMatchesUsing: aBlock |
|
5292 |
! |
|
5293 |
||
5294 |
matchesRegex: regexString |
|
5295 |
"Test if the receiver matches a regex. |
|
5296 |
May raise RxParser>>regexErrorSignal or child signals. |
|
5297 |
This is a part of the Regular Expression Matcher package, |
|
5298 |
(c) 1996, 1999 Vassili Bykov. |
|
5299 |
Refer to `documentation' protocol of RxParser class for details." |
|
5300 |
||
5301 |
^regexString asRegex matches: self |
|
5302 |
||
5303 |
" |
|
5304 |
'hello world' matchesRegex:'h.*d'. |
|
5305 |
" |
|
5306 |
! |
|
5307 |
||
5308 |
matchesRegexIgnoringCase: regexString |
|
5309 |
"Test if the receiver matches a regex. |
|
5310 |
May raise RxParser>>regexErrorSignal or child signals. |
|
5311 |
This is a part of the Regular Expression Matcher package, |
|
5312 |
(c) 1996, 1999 Vassili Bykov. |
|
5313 |
Refer to `documentation' protocol of RxParser class for details." |
|
5314 |
||
5315 |
^regexString asRegexIgnoringCase matches: self |
|
5316 |
||
5317 |
" |
|
5318 |
'hElLo wOrld' matchesRegexIgnoringCase:'h.*d'. |
|
5319 |
" |
|
5320 |
! |
|
5321 |
||
5322 |
prefixMatchesRegex: regexString |
|
5323 |
"Test if the receiver's prefix matches a regex. |
|
5324 |
May raise RxParser class>>regexErrorSignal or child signals. |
|
5325 |
This is a part of the Regular Expression Matcher package, |
|
5326 |
(c) 1996, 1999 Vassili Bykov. |
|
5327 |
Refer to `documentation' protocol of RxParser class for details." |
|
5328 |
||
5329 |
^regexString asRegex matchesPrefix: self |
|
5330 |
! |
|
5331 |
||
5332 |
prefixMatchesRegexIgnoringCase: regexString |
|
5333 |
"Test if the receiver's prefix matches a regex. |
|
5334 |
May raise RxParser class>>regexErrorSignal or child signals. |
|
5335 |
This is a part of the Regular Expression Matcher package, |
|
5336 |
(c) 1996, 1999 Vassili Bykov. |
|
5337 |
Refer to `documentation' protocol of RxParser class for details." |
|
5338 |
||
5339 |
^regexString asRegexIgnoringCase matchesPrefix: self |
|
5340 |
! |
|
5341 |
||
5342 |
regex: rxString matchesCollect: aBlock |
|
5343 |
"for all substrings in the receiver which match the regular expression in rxString, evaluate aBlock, |
|
5344 |
and collect the returned values." |
|
5345 |
||
5346 |
^ rxString asRegex matchesIn: self collect: aBlock |
|
5347 |
||
5348 |
" |
|
5349 |
'hello world' regex:'\w+' matchesCollect:[:each | each asUppercase ]. |
|
5350 |
'1234 hello 456 world' regex:'\d+' matchesCollect:[:each | Number readFrom:each ]. |
|
5351 |
" |
|
5352 |
! |
|
5353 |
||
5354 |
regex:rxString matchesDo: aBlock |
|
5355 |
"for all substrings in the receiver which match the regular expression in rxString, evaluate aBlock" |
|
5356 |
||
5357 |
^ rxString asRegex matchesIn: self do: aBlock |
|
5358 |
||
5359 |
" |
|
5360 |
'hello world' regex:'\w+' matchesDo:[:each | Transcript showCR:each ]. |
|
5361 |
" |
|
5362 |
! ! |
|
5363 |
||
608 | 5364 |
!CharacterArray methodsFor:'special string converting'! |
5365 |
||
5366 |
chopTo:maxLen |
|
5367 |
"if the receivers size is less or equal to maxLen, return it. |
|
5368 |
Otherwise, return a copy of the receiver, where some characters |
|
5369 |
in the middle have been removed for a total string length |
|
5370 |
of maxLen." |
|
5371 |
||
5372 |
|sz n1 n2| |
|
5373 |
||
5374 |
(sz := self size) > maxLen ifTrue:[ |
|
5375 |
n1 := n2 := maxLen // 2. |
|
5376 |
maxLen odd ifTrue:[ |
|
5377 |
n2 := n1 + 1 |
|
5378 |
]. |
|
5379 |
^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1) |
|
5380 |
] |
|
5381 |
||
5382 |
" |
|
5383 |
'12345678901234' chopTo:15 |
|
5384 |
'123456789012345' chopTo:15 |
|
5385 |
'1234567890123456' chopTo:15 |
|
5386 |
'aShortString' chopTo:15 |
|
5387 |
'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 |
|
5388 |
" |
|
5389 |
! |
|
5390 |
||
5391 |
contractAtBeginningTo:maxLen |
|
5392 |
"if the receivers size is less or equal to maxLen, return it. |
|
5393 |
Otherwise, return a copy of the receiver, where some characters |
|
5394 |
at the beginning have been replaced by '...' for a total string length |
|
5395 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
5396 |
||
5397 |
|sz| |
|
5398 |
||
5399 |
(sz := self size) > maxLen ifTrue:[ |
|
5400 |
^ '...' , (self copyFrom:(sz - (maxLen - 4))) |
|
5401 |
] |
|
5402 |
||
5403 |
" |
|
5404 |
'12345678901234' contractAtBeginningTo:15 |
|
5405 |
'123456789012345' contractAtBeginningTo:15 |
|
5406 |
'1234567890123456' contractAtBeginningTo:15 |
|
5407 |
'aShortString' contractAtBeginningTo:15 |
|
5408 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15 |
|
5409 |
" |
|
5410 |
! |
|
359 | 5411 |
|
608 | 5412 |
contractAtEndTo:maxLen |
5413 |
"if the receivers size is less or equal to maxLen, return it. |
|
5414 |
Otherwise, return a copy of the receiver, where some characters |
|
5415 |
at the end have been replaced by '...' for a total string length |
|
5416 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
5417 |
||
5418 |
|sz| |
|
5419 |
||
5420 |
(sz := self size) > maxLen ifTrue:[ |
|
5421 |
^ self copyReplaceFrom:maxLen - 3 |
|
5422 |
with:'...' |
|
5423 |
] |
|
5424 |
||
5425 |
" |
|
5426 |
'12345678901234' contractAtEndTo:15 |
|
5427 |
'123456789012345' contractAtEndTo:15 |
|
5428 |
'1234567890123456' contractAtEndTo:15 |
|
5429 |
'aShortString' contractAtEndTo:15 |
|
5430 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 |
|
5431 |
" |
|
5432 |
! |
|
5433 |
||
5434 |
contractTo:maxLen |
|
5435 |
"if the receivers size is less or equal to maxLen, return it. |
|
5436 |
Otherwise, return a copy of the receiver, where some characters |
|
5437 |
in the middle have been replaced by '...' for a total string length |
|
5438 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
5439 |
||
5440 |
|sz "{ SmallInteger }" |
|
5441 |
halfSize "{ SmallInteger }"| |
|
5442 |
||
5443 |
(sz := self size) > maxLen ifTrue:[ |
|
5444 |
halfSize := maxLen // 2. |
|
5445 |
^ self copyReplaceFrom:halfSize - 1 |
|
5446 |
to:sz - maxLen + halfSize + 1 |
|
5447 |
with:'...' |
|
5448 |
] |
|
5449 |
||
5450 |
" |
|
5451 |
'12345678901234' contractTo:15 |
|
5452 |
'123456789012345' contractTo:15 |
|
5453 |
'1234567890123456' contractTo:15 |
|
5454 |
'aShortString' contractTo:15 |
|
5455 |
'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 |
|
5456 |
" |
|
5457 |
! |
|
5458 |
||
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5459 |
expandPlaceholdersWith:argArrayOrDictionary |
608 | 5460 |
"return a copy of the receiver, where all %i escapes are |
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5461 |
replaced by corresponding arguments' printStrings from the argArrayOrDictionary. |
608 | 5462 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
5463 |
in the new string 'hello world; how is this'. |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5464 |
As an extension, the argument may also be a dictionary, providing |
7313 | 5465 |
values for symbolic keys. |
4842 | 5466 |
In this case, %a .. %z and %(...) are also allowed. |
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5467 |
(%1..%9 require a numeric key in the dictionary, however) |
608 | 5468 |
To get a '%' character, use a '%%'-escape. |
7313 | 5469 |
To get an integer-indexed placeHolder followed by another digit, |
5470 |
or an index > 9, you must use %(digit). |
|
608 | 5471 |
See also bindWith:... for VisualAge compatibility." |
5472 |
||
4842 | 5473 |
|expandedString next v key |
608 | 5474 |
idx "{ SmallInteger }" |
4842 | 5475 |
idx2 "{ SmallInteger }" |
608 | 5476 |
start "{ SmallInteger }" |
5477 |
stop "{ SmallInteger }"| |
|
5478 |
||
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
5479 |
expandedString := self species new:0. |
608 | 5480 |
stop := self size. |
5481 |
start := 1. |
|
5482 |
[start <= stop] whileTrue:[ |
|
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5483 |
idx := self indexOf:$% startingAt:start. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5484 |
(idx == 0 or:[idx == stop]) ifTrue:[ |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5485 |
^ expandedString , (self copyFrom:start to:stop) |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5486 |
]. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5487 |
"found a %" |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5488 |
expandedString := expandedString , (self copyFrom:start to:(idx - 1)). |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5489 |
next := self at:(idx + 1). |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5490 |
(next == $%) ifTrue:[ |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5491 |
expandedString := expandedString , '%' |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5492 |
] ifFalse:[ |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5493 |
(next between:$1 and:$9) ifTrue:[ |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5494 |
v := argArrayOrDictionary at:(next digitValue) ifAbsent:nil |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5495 |
] ifFalse:[ |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5496 |
next == $( ifTrue:[ |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5497 |
idx2 := self indexOf:$) startingAt:idx+2. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5498 |
key := self copyFrom:idx+2 to:idx2-1. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5499 |
idx := idx2 - 1. |
7312
d84ad62592c3
oops - care for %(digit) to allow embedded string followed
Claus Gittinger <cg@exept.de>
parents:
7270
diff
changeset
|
5500 |
(argArrayOrDictionary includesKey:key asSymbol) ifTrue:[ |
d84ad62592c3
oops - care for %(digit) to allow embedded string followed
Claus Gittinger <cg@exept.de>
parents:
7270
diff
changeset
|
5501 |
v := argArrayOrDictionary at:key asSymbol |
d84ad62592c3
oops - care for %(digit) to allow embedded string followed
Claus Gittinger <cg@exept.de>
parents:
7270
diff
changeset
|
5502 |
] ifFalse:[ |
d84ad62592c3
oops - care for %(digit) to allow embedded string followed
Claus Gittinger <cg@exept.de>
parents:
7270
diff
changeset
|
5503 |
(key conform:[:each | each isDigit]) ifTrue:[ |
d84ad62592c3
oops - care for %(digit) to allow embedded string followed
Claus Gittinger <cg@exept.de>
parents:
7270
diff
changeset
|
5504 |
key := Number readFrom:key onError:nil. |
d84ad62592c3
oops - care for %(digit) to allow embedded string followed
Claus Gittinger <cg@exept.de>
parents:
7270
diff
changeset
|
5505 |
]. |
d84ad62592c3
oops - care for %(digit) to allow embedded string followed
Claus Gittinger <cg@exept.de>
parents:
7270
diff
changeset
|
5506 |
v := argArrayOrDictionary at:key ifAbsent:nil |
d84ad62592c3
oops - care for %(digit) to allow embedded string followed
Claus Gittinger <cg@exept.de>
parents:
7270
diff
changeset
|
5507 |
]. |
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5508 |
] ifFalse:[ |
7189 | 5509 |
v := argArrayOrDictionary at:next ifAbsent:nil. |
6743
1ee6a789faed
oops - expandPlaceHolders must handle characters and strings
Claus Gittinger <cg@exept.de>
parents:
6742
diff
changeset
|
5510 |
v isNil ifTrue:[ |
1ee6a789faed
oops - expandPlaceHolders must handle characters and strings
Claus Gittinger <cg@exept.de>
parents:
6742
diff
changeset
|
5511 |
(argArrayOrDictionary includesKey:next asString) ifTrue:[ |
1ee6a789faed
oops - expandPlaceHolders must handle characters and strings
Claus Gittinger <cg@exept.de>
parents:
6742
diff
changeset
|
5512 |
v := argArrayOrDictionary at:next asString asSymbol ifAbsent:nil. |
1ee6a789faed
oops - expandPlaceHolders must handle characters and strings
Claus Gittinger <cg@exept.de>
parents:
6742
diff
changeset
|
5513 |
] ifFalse:[ |
7189 | 5514 |
v := String with:$% with:next. "/ next asString. |
6743
1ee6a789faed
oops - expandPlaceHolders must handle characters and strings
Claus Gittinger <cg@exept.de>
parents:
6742
diff
changeset
|
5515 |
] |
1ee6a789faed
oops - expandPlaceHolders must handle characters and strings
Claus Gittinger <cg@exept.de>
parents:
6742
diff
changeset
|
5516 |
]. |
6742
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5517 |
] |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5518 |
]. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5519 |
v isNil ifTrue:[v := '']. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5520 |
expandedString := expandedString , v printString |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5521 |
]. |
292775fda600
avoid endless recursion when comparing int < string
Claus Gittinger <cg@exept.de>
parents:
6655
diff
changeset
|
5522 |
start := idx + 2 |
608 | 5523 |
]. |
5524 |
^ expandedString |
|
5525 |
||
5526 |
" |
|
5527 |
'hello %1' expandPlaceholdersWith:#('world') |
|
5528 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
5529 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
1308 | 5530 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
7313 | 5531 |
'%%(1)0 gives %(1)0' expandPlaceholdersWith:#(123) |
5532 |
'%%10 gives %10' expandPlaceholdersWith:#(123) |
|
5533 |
'%%(10) gives %(10)' expandPlaceholdersWith:#(123) |
|
608 | 5534 |
" |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
5535 |
|
4410
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5536 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5537 |
|dict| |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5538 |
|
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5539 |
dict := Dictionary new. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5540 |
dict at:1 put:'one'. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5541 |
dict at:$a put:'AAAAA'. |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5542 |
'hello %1 %a' expandPlaceholdersWith:dict |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5543 |
" |
2bdc0c89a42e
enhanced #exapndPlaceHolders, to allow for a dictionary arg
Claus Gittinger <cg@exept.de>
parents:
4409
diff
changeset
|
5544 |
|
2737
9f29aecea39d
care for % at end in expandPlaceHolders.
Claus Gittinger <cg@exept.de>
parents:
2736
diff
changeset
|
5545 |
"Modified: 1.7.1997 / 00:53:24 / cg" |
608 | 5546 |
! |
5547 |
||
5548 |
withCRs |
|
5549 |
"return a new string consisting of receivers characters |
|
5550 |
with all \-characters replaced by cr-characters." |
|
5551 |
||
3656 | 5552 |
^ self copyReplaceAll:$\ with:(Character cr) |
608 | 5553 |
|
5554 |
" |
|
5555 |
'hello\world' withCRs |
|
5556 |
" |
|
3656 | 5557 |
|
5558 |
"Modified: / 18.7.1998 / 22:53:02 / cg" |
|
608 | 5559 |
! |
5560 |
||
5561 |
withEscapes |
|
5562 |
"return a new string consisting of receivers characters |
|
5563 |
with all \X-character escapes replaced by corresponding-characters. |
|
5564 |
(similar to the way C-language Strings are converted). |
|
5565 |
The following escapes are supported: |
|
1008 | 5566 |
\r return character |
5567 |
\n newline character |
|
5568 |
\b backspace character |
|
5569 |
\f formfeed character |
|
5570 |
\t tab character |
|
5571 |
\e escape character |
|
5572 |
\\ the \ character itself |
|
5573 |
\nnn three digit octal number defining the characters ascii value |
|
5574 |
\other other |
|
608 | 5575 |
|
5576 |
Notice, that \' is NOT a valid escape, since the general syntax of |
|
5577 |
string constants is not affected by this method. |
|
5578 |
||
5579 |
Although easily implementable, this is NOT done automatically |
|
5580 |
by the compiler (due to a lack of a language standard for this). |
|
5581 |
However, the compiler may detect sends ot #withEscapes to string literals |
|
5582 |
and place a modified string constant into the binary/byte-code. |
|
5583 |
Therefore, no runtime penalty will be payed for using these escapes. |
|
5584 |
(not in pre 2.11 versions) |
|
5585 |
" |
|
5586 |
||
5587 |
|sz "{ SmallInteger }" |
|
5588 |
newSize "{ SmallInteger }" |
|
5589 |
srcIdx "{ SmallInteger }" |
|
5590 |
dstIdx "{ SmallInteger }" |
|
5591 |
val "{ SmallInteger }" |
|
1381 | 5592 |
newString next hasEmphasis e| |
359 | 5593 |
|
5594 |
" |
|
608 | 5595 |
first, count the number of escapes, to allow preallocation |
5596 |
of the new string ... |
|
5597 |
(it is faster to scan the string twice than to reallocate it multiple |
|
5598 |
times in a WriteStream) |
|
5599 |
" |
|
5600 |
sz := newSize := self size. |
|
5601 |
srcIdx := 1. |
|
5602 |
[(srcIdx := self indexOf:$\ startingAt:srcIdx) ~~ 0] whileTrue:[ |
|
1008 | 5603 |
srcIdx == sz ifFalse:[ |
5604 |
newSize := newSize - 1. |
|
5605 |
srcIdx := srcIdx + 1. |
|
5606 |
next := self at:srcIdx. |
|
5607 |
next == $0 ifTrue:[ |
|
3527
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5608 |
[srcIdx < sz and:[next isDigit]] whileTrue:[ |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5609 |
newSize := newSize - 1. srcIdx := srcIdx + 1. next := self at:srcIdx. |
1008 | 5610 |
] |
5611 |
]. |
|
5612 |
]. |
|
5613 |
srcIdx := srcIdx + 1. |
|
608 | 5614 |
]. |
5615 |
||
5616 |
newSize == sz ifTrue:[ |
|
1008 | 5617 |
^ self |
608 | 5618 |
]. |
5619 |
||
5620 |
newString := self species new:newSize. |
|
1381 | 5621 |
|
5622 |
hasEmphasis := self hasChangeOfEmphasis. |
|
5623 |
||
608 | 5624 |
" |
5625 |
copy over, replace escapes |
|
5626 |
" |
|
5627 |
srcIdx := dstIdx := 1. |
|
5628 |
[srcIdx <= sz] whileTrue:[ |
|
1008 | 5629 |
next := self at:srcIdx. |
1381 | 5630 |
hasEmphasis ifTrue:[ |
5631 |
e := self emphasisAt:srcIdx |
|
5632 |
]. |
|
1008 | 5633 |
srcIdx := srcIdx + 1. |
5634 |
next == $\ ifTrue:[ |
|
5635 |
srcIdx <= sz ifTrue:[ |
|
5636 |
next := self at:srcIdx. |
|
5637 |
srcIdx := srcIdx + 1. |
|
5638 |
next == $r ifTrue:[ |
|
5639 |
next := Character return |
|
5640 |
] ifFalse:[ |
|
5641 |
next == $n ifTrue:[ |
|
5642 |
next := Character nl |
|
5643 |
] ifFalse:[ |
|
5644 |
next == $b ifTrue:[ |
|
5645 |
next := Character backspace |
|
5646 |
] ifFalse:[ |
|
5647 |
next == $f ifTrue:[ |
|
5648 |
next := Character newPage |
|
5649 |
] ifFalse:[ |
|
5650 |
next == $t ifTrue:[ |
|
5651 |
next := Character tab |
|
5652 |
] ifFalse:[ |
|
5653 |
next == $e ifTrue:[ |
|
5654 |
next := Character esc |
|
5655 |
] ifFalse:[ |
|
5656 |
next == $0 ifTrue:[ |
|
5657 |
val := 0. |
|
3527
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5658 |
[next notNil and:[next isDigit]] whileTrue:[ |
1008 | 5659 |
val := val * 8 + next digitValue. |
3527
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5660 |
srcIdx <= sz ifTrue:[ |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5661 |
next := self at:srcIdx. |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5662 |
srcIdx := srcIdx + 1. |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5663 |
] ifFalse:[ |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5664 |
next := nil |
55b61fce23f0
oops - fixed withEscapes of octal character at the end
Claus Gittinger <cg@exept.de>
parents:
3404
diff
changeset
|
5665 |
] |
1008 | 5666 |
]. |
5667 |
next := Character value:val. |
|
5668 |
] |
|
5669 |
] |
|
5670 |
] |
|
5671 |
] |
|
5672 |
] |
|
5673 |
] |
|
5674 |
]. |
|
5675 |
]. |
|
5676 |
]. |
|
5677 |
newString at:dstIdx put:next. |
|
1381 | 5678 |
hasEmphasis ifTrue:[ |
5679 |
newString emphasisAt:dstIdx put:e |
|
5680 |
]. |
|
1008 | 5681 |
dstIdx := dstIdx + 1. |
608 | 5682 |
]. |
5683 |
^ newString |
|
5684 |
||
5685 |
" |
|
5686 |
'hello world' withEscapes |
|
5687 |
'hello\world' withEscapes |
|
5688 |
'hello\world\' withEscapes |
|
5689 |
'hello world\' withEscapes |
|
5690 |
'hello\tworld' withEscapes |
|
5691 |
'hello\nworld\na\n\tnice\n\t\tstring' withEscapes |
|
5692 |
'hello\tworld\n' withEscapes |
|
5693 |
'hello\010world' withEscapes |
|
5694 |
'hello\r\nworld' withEscapes |
|
5695 |
" |
|
1008 | 5696 |
|
1381 | 5697 |
"Modified: 12.5.1996 / 12:53:34 / cg" |
608 | 5698 |
! |
5699 |
||
4117 | 5700 |
withMatchEscapes |
5701 |
"return a copy of the receiver with all match characters escaped |
|
5702 |
by $\ characters (to be usable as a match string). |
|
5703 |
Return the receiver, if there are none." |
|
5704 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5705 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5706 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5707 |
escape := self class matchEscapeCharacter. |
4117 | 5708 |
|
5709 |
in := self readStream. |
|
5710 |
out := '' writeStream. |
|
5711 |
[in atEnd] whileFalse:[ |
|
5712 |
c := in next. |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5713 |
(c == escape or:['*[#' includes:c]) ifTrue:[ |
4117 | 5714 |
out nextPut:$\. |
5715 |
]. |
|
5716 |
out nextPut:c. |
|
5717 |
]. |
|
5718 |
^ out contents. |
|
5719 |
||
5720 |
" |
|
5721 |
'*foo' withMatchEscapes |
|
5722 |
'\*foo' withMatchEscapes |
|
5723 |
'*foo' withMatchEscapes |
|
5724 |
'\\*foo' withMatchEscapes |
|
5725 |
'foo*' withMatchEscapes |
|
5726 |
'foo\*' withMatchEscapes |
|
5727 |
'foo\' withMatchEscapes |
|
5728 |
'f*o*o' withMatchEscapes |
|
5729 |
" |
|
5730 |
||
5731 |
"Modified: 2.4.1997 / 18:13:04 / cg" |
|
5732 |
! |
|
5733 |
||
608 | 5734 |
withTabs |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5735 |
"return a string consisting of the receivers characters |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5736 |
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
|
5737 |
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
|
5738 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5739 |
Limitation: only the very first spaces are replaced |
5815
4acdd87a77d4
// can return negative numbers.
Stefan Vogel <sv@exept.de>
parents:
5795
diff
changeset
|
5740 |
(i.e. if the receiver contains newLine characters, |
4acdd87a77d4
// can return negative numbers.
Stefan Vogel <sv@exept.de>
parents:
5795
diff
changeset
|
5741 |
no tabs are inserted after those lineBreaks)" |
608 | 5742 |
|
5743 |
|idx "{ SmallInteger }" |
|
5744 |
nTabs "{ SmallInteger }" |
|
5745 |
newString| |
|
5746 |
||
5747 |
idx := self findFirst:[:c | (c ~~ Character space)]. |
|
5748 |
nTabs := (idx-1) // 8. |
|
5815
4acdd87a77d4
// can return negative numbers.
Stefan Vogel <sv@exept.de>
parents:
5795
diff
changeset
|
5749 |
nTabs <= 0 ifTrue:[^ self]. |
608 | 5750 |
|
5751 |
"any tabs" |
|
5752 |
newString := self class new:(self size - (nTabs * 7)). |
|
5753 |
newString atAll:(1 to:nTabs) put:(Character tab). |
|
5754 |
newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1). |
|
5755 |
^ newString |
|
5756 |
||
5757 |
" |
|
5758 |
'12345678901234567890' withTabs |
|
5759 |
' 8901234567890' withTabs |
|
5760 |
' 901234567890' withTabs |
|
5761 |
' 67890' withTabs |
|
5762 |
' 7890' withTabs |
|
5763 |
' 890' withTabs |
|
5764 |
" |
|
5765 |
! |
|
5766 |
||
5767 |
withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5768 |
"return a string consisting of the receivers characters, |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5769 |
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
|
5770 |
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
|
5771 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5772 |
This does handle multiline strings." |
608 | 5773 |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5774 |
^ self withTabsExpanded:8 |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5775 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5776 |
" |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5777 |
('1' , Character tab asString , 'x') withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5778 |
('12345' , Character tab asString , 'x') withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5779 |
('123456' , Character tab asString , 'x') withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5780 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5781 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5782 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5783 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5784 |
(String with:Character tab |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5785 |
with:Character tab |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5786 |
with:$1) withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5787 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5788 |
(String with:Character tab |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5789 |
with:$1 |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5790 |
with:Character tab |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5791 |
with:$2) withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5792 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5793 |
(String with:Character tab |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5794 |
with:$1 |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5795 |
with:Character cr |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5796 |
with:Character tab |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5797 |
with:$2) withTabsExpanded |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5798 |
" |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5799 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5800 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5801 |
! |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5802 |
|
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5803 |
withTabsExpanded:numSpaces |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5804 |
"return a string consisting of the receivers characters, |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5805 |
where all tabulator characters are expanded into spaces (assuming numSpaces-col tabs). |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5806 |
Notice: if the receiver does not contain any tabs, it is returned unchanged; |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5807 |
otherwise a new string is returned. |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5808 |
This does handle multiline strings." |
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5809 |
|
1381 | 5810 |
|col "{ SmallInteger }" |
5811 |
str ch |
|
5812 |
dstIdx "{ SmallInteger }" |
|
5813 |
newSz "{ SmallInteger }" |
|
5814 |
sz "{ SmallInteger }" |
|
5815 |
hasEmphasis e| |
|
608 | 5816 |
|
5817 |
(self includes:(Character tab)) ifFalse:[^ self]. |
|
1381 | 5818 |
|
5819 |
sz := self size. |
|
5820 |
||
5821 |
"/ count the new size first, instead of |
|
5822 |
"/ multiple resizing (better for large strings) |
|
5823 |
||
5824 |
col := 1. newSz := 0. |
|
5825 |
1 to:sz do:[:srcIdx | |
|
5826 |
ch := self at:srcIdx. |
|
5827 |
ch == Character tab ifFalse:[ |
|
5828 |
col := col + 1. |
|
5829 |
newSz := newSz + 1. |
|
5830 |
ch == Character cr ifTrue:[ |
|
5831 |
col := 1 |
|
5832 |
]. |
|
5833 |
] ifTrue:[ |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5834 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
1381 | 5835 |
newSz := newSz + 1. |
5836 |
col := col + 1 |
|
5837 |
]. |
|
5838 |
] |
|
608 | 5839 |
]. |
1381 | 5840 |
|
5841 |
str := self species new:newSz. |
|
5842 |
||
5843 |
hasEmphasis := self hasChangeOfEmphasis. |
|
5844 |
||
5845 |
col := 1. dstIdx := 1. |
|
5846 |
1 to:sz do:[:srcIdx | |
|
5847 |
ch := self at:srcIdx. |
|
5848 |
||
5849 |
ch == Character tab ifFalse:[ |
|
5850 |
col := col + 1. |
|
5851 |
ch == Character cr ifTrue:[ |
|
5852 |
col := 1 |
|
5853 |
]. |
|
5854 |
hasEmphasis ifTrue:[ |
|
5855 |
e := self emphasisAt:srcIdx. |
|
5856 |
str emphasisAt:dstIdx put:e |
|
5857 |
]. |
|
5858 |
str at:dstIdx put:ch. |
|
5859 |
dstIdx := dstIdx + 1 |
|
5860 |
] ifTrue:[ |
|
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5861 |
(col \\ numSpaces) to:numSpaces do:[:ii | |
1381 | 5862 |
str at:dstIdx put:Character space. |
5863 |
dstIdx := dstIdx + 1. |
|
5864 |
col := col + 1 |
|
5865 |
]. |
|
5866 |
] |
|
5867 |
]. |
|
5868 |
^ str |
|
608 | 5869 |
|
5870 |
" |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5871 |
('1' , Character tab asString , 'x') withTabsExpanded |
5741
3a6086774d38
added #withTabsExpanded: (i.e. arg to specify tab-column width)
Claus Gittinger <cg@exept.de>
parents:
5739
diff
changeset
|
5872 |
('1' , Character tab asString , 'x') withTabsExpanded:4 |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5873 |
('12345' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5874 |
('123456' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5875 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5876 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5877 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5878 |
|
608 | 5879 |
(String with:Character tab |
1381 | 5880 |
with:Character tab |
5881 |
with:$1) withTabsExpanded |
|
608 | 5882 |
|
5883 |
(String with:Character tab |
|
1381 | 5884 |
with:$1 |
5885 |
with:Character tab |
|
5886 |
with:$2) withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5887 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5888 |
(String with:Character tab |
1381 | 5889 |
with:$1 |
5890 |
with:Character cr |
|
5891 |
with:Character tab |
|
5892 |
with:$2) withTabsExpanded |
|
608 | 5893 |
" |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
5894 |
|
1381 | 5895 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
608 | 5896 |
! |
5897 |
||
5898 |
withoutCRs |
|
5899 |
"return a new collection consisting of receivers elements |
|
5900 |
with all cr-characters replaced by \-characters. |
|
5901 |
This is the reverse operation of withCRs." |
|
5902 |
||
3656 | 5903 |
^ self copyReplaceAll:(Character cr) with:$\ |
608 | 5904 |
" |
5905 |
'hello |
|
5906 |
world' withoutCRs |
|
359 | 5907 |
" |
3656 | 5908 |
|
5909 |
"Modified: / 18.7.1998 / 22:53:08 / cg" |
|
608 | 5910 |
! |
5911 |
||
5912 |
withoutLeadingSeparators |
|
5913 |
"return a copy of myself without leading separators. |
|
5914 |
Notice: this does remove tabs, newline or any other whitespace. |
|
5915 |
Returns an empty string, if the receiver consist only of whitespace." |
|
5916 |
||
5917 |
|index| |
|
5918 |
||
5919 |
index := self indexOfNonSeparatorStartingAt:1. |
|
5920 |
index ~~ 0 ifTrue:[ |
|
5921 |
index == 1 ifTrue:[ |
|
5922 |
^ self |
|
5923 |
]. |
|
5924 |
^ self copyFrom:index |
|
5925 |
]. |
|
5926 |
^ '' |
|
5927 |
||
5928 |
" |
|
5929 |
' foo ' withoutLeadingSeparators |
|
5930 |
'foo ' withoutLeadingSeparators |
|
5931 |
' foo' withoutLeadingSeparators |
|
5932 |
' ' withoutLeadingSeparators |
|
5933 |
'foo' withoutLeadingSeparators |
|
5934 |
(' ' , Character tab asString , ' foo ') withoutLeadingSeparators inspect |
|
5935 |
" |
|
5936 |
! |
|
5937 |
||
4117 | 5938 |
withoutMatchEscapes |
5939 |
"return a copy of the receiver with all $\ removed or |
|
5940 |
the receiver, if there are none." |
|
5941 |
||
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5942 |
|in out c escape| |
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5943 |
|
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5944 |
escape := self class matchEscapeCharacter. |
4117 | 5945 |
|
5946 |
in := self readStream. |
|
5947 |
out := self species new writeStream. |
|
5948 |
[in atEnd] whileFalse:[ |
|
5949 |
c := in next. |
|
5342
5010cea0ffd4
match-escape character definition in one place
Claus Gittinger <cg@exept.de>
parents:
5316
diff
changeset
|
5950 |
c == escape ifTrue:[ |
4117 | 5951 |
in atEnd ifFalse:[ |
5952 |
c := in next. |
|
5953 |
] |
|
5954 |
]. |
|
5955 |
out nextPut:c. |
|
5956 |
]. |
|
5957 |
^ out contents. |
|
5958 |
||
5959 |
" |
|
5960 |
'*foo' withoutMatchEscapes |
|
5961 |
'\*foo' withoutMatchEscapes |
|
5962 |
'*foo' withoutMatchEscapes |
|
5963 |
'\\*foo' withoutMatchEscapes |
|
5964 |
'foo*' withoutMatchEscapes |
|
5965 |
'foo\*' withoutMatchEscapes |
|
5966 |
'foo\' withoutMatchEscapes |
|
5967 |
'f\*o\*o' withoutMatchEscapes |
|
5968 |
" |
|
5969 |
||
5970 |
"Modified: 30.6.1997 / 13:40:23 / cg" |
|
5971 |
! |
|
5972 |
||
7247 | 5973 |
withoutPrefix:aString |
5974 |
"if the receiver startsWith aPrefix, return a copy without it. |
|
5975 |
Otherwise return the receiver" |
|
5976 |
||
5977 |
(self startsWith:aString) ifTrue:[ |
|
5978 |
^ self copyFrom:aString size + 1 |
|
5979 |
]. |
|
5980 |
^ self |
|
5981 |
||
5982 |
" |
|
5983 |
'helloworld' withoutPrefix:'hello' |
|
5984 |
'helloworld' withoutPrefix:'foo' |
|
5985 |
" |
|
5986 |
! |
|
5987 |
||
608 | 5988 |
withoutSeparators |
5989 |
"return a copy of myself without leading and trailing whitespace. |
|
4156 | 5990 |
(but whiteSpace in-between is preserved) |
608 | 5991 |
Whitespace is space, tab, newline, formfeed. |
5992 |
Use withoutSpaces, if you want to remove spaces only." |
|
5993 |
||
5994 |
|startIndex "{ Class: SmallInteger }" |
|
5995 |
endIndex "{ Class: SmallInteger }" |
|
5996 |
sz| |
|
5997 |
||
5998 |
sz := self size. |
|
5999 |
startIndex := 1. |
|
6000 |
endIndex := sz. |
|
6001 |
||
6002 |
[(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[ |
|
4156 | 6003 |
startIndex := startIndex + 1 |
608 | 6004 |
]. |
6005 |
[(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[ |
|
4156 | 6006 |
endIndex := endIndex - 1 |
608 | 6007 |
]. |
6008 |
startIndex > endIndex ifTrue:[ |
|
4156 | 6009 |
^ '' |
608 | 6010 |
]. |
6011 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
|
4156 | 6012 |
^ self |
608 | 6013 |
]. |
6014 |
^ self copyFrom:startIndex to:endIndex |
|
6015 |
||
6016 |
" |
|
6017 |
' foo ' withoutSeparators |
|
6018 |
' foo' withoutSeparators |
|
6019 |
'foo ' withoutSeparators |
|
6020 |
' ' withoutSeparators |
|
6021 |
(' foo' , Character tab asString , ' ') withoutSeparators inspect |
|
6022 |
" |
|
6023 |
! |
|
6024 |
||
6025 |
withoutSpaces |
|
6026 |
"return a copy of myself without leading and trailing spaces. |
|
4156 | 6027 |
(but spaces in-between are preserved) |
608 | 6028 |
Notice: this does NOT remove tabs, newline or any other whitespace. |
6029 |
Use withoutSeparators for this." |
|
6030 |
||
6031 |
|startIndex "{ Class: SmallInteger }" |
|
6032 |
endIndex "{ Class: SmallInteger }" |
|
6033 |
sz| |
|
6034 |
||
6035 |
sz := self size. |
|
6036 |
startIndex := 1. |
|
6037 |
endIndex := sz. |
|
6038 |
||
6039 |
[(startIndex < endIndex) and:[(self at:startIndex) == Character space]] whileTrue:[ |
|
4156 | 6040 |
startIndex := startIndex + 1 |
608 | 6041 |
]. |
6042 |
[(endIndex > 1) and:[(self at:endIndex) == Character space]] whileTrue:[ |
|
4156 | 6043 |
endIndex := endIndex - 1 |
608 | 6044 |
]. |
6045 |
startIndex > endIndex ifTrue:[ |
|
4156 | 6046 |
^ '' |
608 | 6047 |
]. |
6048 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
|
4156 | 6049 |
^ self |
608 | 6050 |
]. |
6051 |
^ self copyFrom:startIndex to:endIndex |
|
6052 |
||
6053 |
" |
|
6054 |
' foo ' withoutSpaces |
|
6055 |
'foo ' withoutSpaces |
|
6056 |
' foo' withoutSpaces |
|
6057 |
' ' withoutSpaces |
|
4156 | 6058 |
'a b' withoutSpaces |
608 | 6059 |
(' foo' , Character tab asString , ' ') withoutSpaces inspect |
6060 |
" |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6061 |
! |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6062 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6063 |
withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6064 |
"return a copy of myself without trailing separators. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6065 |
Notice: this does remove tabs, newline or any other whitespace. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6066 |
Returns an empty string, if the receiver consist only of whitespace." |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6067 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6068 |
|index| |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6069 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6070 |
index := self size. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6071 |
[index ~~ 0] whileTrue:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6072 |
(self at:index) isSeparator ifFalse:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6073 |
^ self copyTo:index |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6074 |
]. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6075 |
index := index - 1 |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6076 |
]. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6077 |
^ '' |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6078 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6079 |
" |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6080 |
' foo ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6081 |
'foo ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6082 |
' foo' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6083 |
' ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6084 |
'foo' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6085 |
(' ' , Character tab asString , ' foo ') withoutTrailingSeparators inspect |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6086 |
(' foo' , Character tab asString) withoutTrailingSeparators inspect |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
6087 |
" |
608 | 6088 |
! ! |
6089 |
||
6090 |
!CharacterArray methodsFor:'substring searching'! |
|
6091 |
||
6092 |
findString:subString |
|
6093 |
"find a substring. if found, return the index; |
|
6094 |
if not found, return 0." |
|
6095 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
6096 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 |
608 | 6097 |
|
6098 |
" |
|
6099 |
'hello world' findString:'llo' |
|
6100 |
'hello world' findString:'ole' |
|
6101 |
" |
|
6102 |
! |
|
6103 |
||
6104 |
findString:subString ifAbsent:exceptionBlock |
|
6105 |
"find a substring. If found, return the index; |
|
6106 |
if not found, return the result of evaluating exceptionBlock." |
|
6107 |
||
6108 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock |
|
6109 |
! |
|
6110 |
||
6111 |
findString:subString startingAt:index |
|
6112 |
"find a substring, starting at index. if found, return the index; |
|
6113 |
if not found, return 0." |
|
6114 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
6115 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:0 |
608 | 6116 |
|
6117 |
" |
|
6118 |
'hello yello' findString:'llo' startingAt:1 |
|
6119 |
'hello yello' findString:'llo' startingAt:5 |
|
6120 |
'hello yello' findString:'llo' startingAt:15 |
|
6121 |
" |
|
6122 |
! |
|
6123 |
||
6124 |
findString:subString startingAt:index ifAbsent:exceptionBlock |
|
6125 |
"find a substring, starting at index. if found, return the index; |
|
6126 |
if not found, return the result of evaluating exceptionBlock." |
|
6127 |
||
6128 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
|
6129 |
! |
|
6130 |
||
6131 |
includesString:aString |
|
6132 |
"return true, if a substring is contained in the receiver" |
|
6133 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
6134 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0) ~~ 0 |
608 | 6135 |
|
6136 |
" |
|
6137 |
'hello world' includesString:'hel' |
|
6138 |
'hello world' includesString:'rld' |
|
6139 |
'hello world' includesString:'llo' |
|
6140 |
'hello world' includesString:'LLO' |
|
6141 |
" |
|
6142 |
! |
|
6143 |
||
6144 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
|
6145 |
"find a substring, starting at index. if found, return the index; |
|
6146 |
if not found, return the result of evaluating exceptionBlock. |
|
6147 |
This is a q&d hack - not very efficient" |
|
6148 |
||
6149 |
|firstChar found |
|
6150 |
startIndex "{ Class: SmallInteger }" |
|
6151 |
subSize "{ Class: SmallInteger }" |
|
6152 |
mySize "{ Class: SmallInteger }" |
|
6153 |
runIdx "{ Class: SmallInteger }" | |
|
6154 |
||
6155 |
subSize := subString size. |
|
6122
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
6156 |
subSize == 0 ifTrue:[ "empty string matches" |
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
6157 |
subString isString ifFalse:[ |
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
6158 |
self error:'non string argument' mayProceed:true. |
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
6159 |
]. |
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
6160 |
^ index |
a98958f1c85f
handle non-string arg to indexOfSubString:
Claus Gittinger <cg@exept.de>
parents:
6119
diff
changeset
|
6161 |
]. |
608 | 6162 |
mySize := self size. |
6163 |
firstChar := subString at:1. |
|
6164 |
startIndex := self indexOf:firstChar startingAt:index. |
|
6165 |
[startIndex == 0] whileFalse:[ |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6166 |
runIdx := startIndex. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6167 |
found := true. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6168 |
1 to:subSize do:[:i | |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6169 |
runIdx > mySize ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6170 |
found := false |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6171 |
] ifFalse:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6172 |
(subString at:i) ~= (self at:runIdx) ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6173 |
found := false |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6174 |
] |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6175 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6176 |
runIdx := runIdx + 1 |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6177 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6178 |
found ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6179 |
^ startIndex |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6180 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6181 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1) |
608 | 6182 |
]. |
6183 |
^ exceptionBlock value |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6184 |
|
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6185 |
"Modified: 23.2.1996 / 15:35:15 / cg" |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6186 |
! |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6187 |
|
652 | 6188 |
restAfter:keyword withoutSeparators:strip |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6189 |
"compare the left of the receiver with keyword, |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6190 |
if it matches return the right. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6191 |
Finally, if strip is true, remove whiteSpace. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6192 |
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
|
6193 |
something: rest |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
6194 |
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
|
6195 |
begins with something. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6196 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6197 |
You may wonder why such a specialized method exists here |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6198 |
- this is so common when processing mailboxes, |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6199 |
rcs files, nntp/pop3 responses, that is was considered worth |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6200 |
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
|
6201 |
times in variuos places." |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6202 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6203 |
|rest| |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6204 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6205 |
(self startsWith:keyword) ifTrue:[ |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6206 |
rest := self copyFrom:(keyword size + 1). |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6207 |
strip ifTrue:[ |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6208 |
rest := rest withoutSeparators |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6209 |
]. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6210 |
^ rest |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6211 |
]. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6212 |
^ nil |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6213 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6214 |
" |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6215 |
'foo: hello world' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6216 |
'funny: something' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6217 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6218 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6219 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:false |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6220 |
" |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6221 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
6222 |
"Created: 25.11.1995 / 11:04:18 / cg" |
328 | 6223 |
! ! |
6224 |
||
255 | 6225 |
!CharacterArray methodsFor:'testing'! |
64 | 6226 |
|
1613 | 6227 |
continuesWith:aString startingAt:startIndex |
6228 |
"return true, if the receiver beginning at startIndex |
|
6229 |
contains the characters in aString." |
|
6230 |
||
6231 |
|sz "{Class: SmallInteger }" |
|
6232 |
idx "{Class: SmallInteger }"| |
|
6233 |
||
6234 |
sz := aString size. |
|
6235 |
idx := startIndex. |
|
6236 |
||
6237 |
1 to:sz do:[:i | |
|
6238 |
(self at:idx) ~~ (aString at:i) ifTrue:[^ false]. |
|
6239 |
idx := idx + 1 |
|
6240 |
]. |
|
6241 |
^ true |
|
6242 |
||
6243 |
" |
|
6244 |
'hello world' continuesWith:'world' startingAt:6 |
|
6245 |
'hello world' continuesWith:'world' startingAt:7 |
|
6246 |
" |
|
6247 |
||
6248 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
6249 |
"Modified: 26.7.1996 / 19:08:36 / cg" |
|
6250 |
! |
|
6251 |
||
64 | 6252 |
countWords |
6253 |
"return the number of words, which are separated by separators" |
|
6254 |
||
92 | 6255 |
|tally "{ Class: SmallInteger }" |
6256 |
start "{ Class: SmallInteger }" |
|
6257 |
mySize "{ Class: SmallInteger }" |
|
6258 |
stop ch| |
|
64 | 6259 |
|
6260 |
tally := 0. |
|
6261 |
start := 1. |
|
6262 |
mySize := self size. |
|
6263 |
[start <= mySize] whileTrue:[ |
|
154 | 6264 |
ch := self at:start. |
6265 |
ch isSeparator ifTrue:[ |
|
6266 |
start := start + 1 |
|
6267 |
] ifFalse:[ |
|
6268 |
stop := self indexOfSeparatorStartingAt:start. |
|
6269 |
(stop == 0) ifTrue:[ |
|
6270 |
stop := mySize + 1 |
|
6271 |
]. |
|
6272 |
tally := tally + 1. |
|
6273 |
start := stop |
|
6274 |
] |
|
64 | 6275 |
]. |
6276 |
^ tally |
|
6277 |
||
92 | 6278 |
" |
6279 |
'hello world isnt this nice' countWords' |
|
6280 |
" |
|
64 | 6281 |
! |
6282 |
||
1381 | 6283 |
endsWith:aString |
6284 |
"return true, if the receiver ends with something, aString." |
|
6285 |
||
6286 |
|s| |
|
6287 |
||
6288 |
(s := self string) ~~ self ifTrue:[ |
|
6289 |
^ s endsWith:aString |
|
6290 |
]. |
|
6291 |
^ super endsWith:aString |
|
6292 |
||
6293 |
" |
|
6294 |
'hello world' endsWith:'world' |
|
6295 |
'hello world' asText allBold endsWith:'world' |
|
6296 |
" |
|
6297 |
||
6298 |
"Modified: 12.5.1996 / 15:49:18 / cg" |
|
6299 |
! |
|
6300 |
||
608 | 6301 |
isAlphaNumeric |
6302 |
"return true, if the receiver is some alphanumeric word; |
|
6303 |
i.e. consists of a letter followed by letters or digits." |
|
64 | 6304 |
|
608 | 6305 |
self size == 0 ifTrue:[ |
6306 |
"mhmh what is this ?" |
|
6307 |
^ false |
|
64 | 6308 |
]. |
608 | 6309 |
(self at:1) isLetter ifFalse:[^ false]. |
6310 |
self do:[:char | |
|
6311 |
char isLetterOrDigit ifFalse:[^ false]. |
|
6312 |
]. |
|
6313 |
^ true |
|
64 | 6314 |
|
77 | 6315 |
" |
608 | 6316 |
'helloWorld' isAlphaNumeric |
6317 |
'foo1234' isAlphaNumeric |
|
6318 |
'f1234' isAlphaNumeric |
|
6319 |
'1234' isAlphaNumeric |
|
6320 |
'+' isAlphaNumeric |
|
77 | 6321 |
" |
6322 |
! |
|
6323 |
||
7482 | 6324 |
isBinarySelector |
6325 |
"treating the receiver as a message selector, return true if its a binary selector" |
|
6326 |
||
6327 |
|binopChars| |
|
6328 |
||
6329 |
(self size > 3) ifTrue:[^ false]. |
|
6330 |
||
6331 |
binopChars := Scanner binarySelectorCharacters. |
|
6332 |
^ (self conform:[:char | (binopChars includes:char)]) |
|
6333 |
||
6334 |
" |
|
6335 |
'foo:bar:' isBinarySelector |
|
6336 |
#foo:bar: isBinarySelector |
|
6337 |
'hello' isBinarySelector |
|
6338 |
'+' isBinarySelector |
|
6339 |
'|' isBinarySelector |
|
6340 |
'?' isBinarySelector |
|
6341 |
':' isBinarySelector |
|
6342 |
'a:' isBinarySelector |
|
6343 |
'->' isBinarySelector |
|
6344 |
'<->' isBinarySelector |
|
6345 |
'::' isBinarySelector |
|
6346 |
" |
|
6347 |
||
6348 |
"Modified: 4.1.1997 / 14:16:14 / cg" |
|
6349 |
! |
|
6350 |
||
608 | 6351 |
isBlank |
6352 |
"return true, if the receiver contains spaces only" |
|
77 | 6353 |
|
608 | 6354 |
self do:[:char | |
6355 |
char ~~ Character space ifTrue:[^ false]. |
|
77 | 6356 |
]. |
608 | 6357 |
^ true |
64 | 6358 |
! |
6359 |
||
6360 |
levenshteinTo:aString |
|
6361 |
"return the levenshtein distance to the argument, aString; |
|
7318 | 6362 |
this value corresponds to the number of replacements that have to be |
64 | 6363 |
made to get aString from the receiver. |
196 | 6364 |
See IEEE transactions on Computers 1976 Pg 172 ff." |
64 | 6365 |
|
327 | 6366 |
" |
7318 | 6367 |
in the following, we assume that ommiting a character |
327 | 6368 |
is less of an error than inserting an extra character. |
7318 | 6369 |
Therefore the different insertion (i) and deletion (d) values. |
6370 |
s: substitution weight |
|
6371 |
c: case weight |
|
6372 |
i: insertion of extra character weight |
|
6373 |
d: delete of a character weight |
|
6374 |
" |
|
6375 |
||
6376 |
^ self levenshteinTo:aString s:4 k:2 c:1 i:2 d:6 |
|
6377 |
||
6378 |
" |
|
6379 |
'computer' levenshteinTo:'computer' |
|
6380 |
'cOmputer' levenshteinTo:'computer' |
|
6381 |
'cOmpuTer' levenshteinTo:'computer' |
|
6382 |
'cimputer' levenshteinTo:'computer' |
|
6383 |
'cumputer' levenshteinTo:'computer' |
|
6384 |
||
6385 |
'cmputer' levenshteinTo:'computer' |
|
6386 |
'coomputer' levenshteinTo:'computer' |
|
6387 |
||
6388 |
'ocmprt' levenshteinTo:'computer' |
|
154 | 6389 |
'computer' levenshteinTo:'computer' |
6390 |
'ocmputer' levenshteinTo:'computer' |
|
6391 |
'cmputer' levenshteinTo:'computer' |
|
327 | 6392 |
'computer' levenshteinTo:'cmputer' |
154 | 6393 |
'Computer' levenshteinTo:'computer' |
6394 |
" |
|
64 | 6395 |
! |
6396 |
||
6397 |
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight |
|
196 | 6398 |
"parametrized levenshtein. |
6399 |
return the levenshtein distance to the argument, aString; |
|
6400 |
this value corrensponds to the number of replacements that have to be |
|
6401 |
made to get aString from the receiver. |
|
7318 | 6402 |
The arguments are the costs for |
6403 |
substitution, case-change, insertion and deletion of a character. |
|
6404 |
See IEEE transactions on Computers 1976 Pg 172 ff" |
|
6405 |
||
6406 |
^ self |
|
6407 |
levenshteinTo:aString |
|
6408 |
s:substWeight |
|
6409 |
k:substWeight |
|
6410 |
c:caseWeight |
|
6411 |
i:insrtWeight |
|
6412 |
d:deleteWeight |
|
6413 |
! |
|
6414 |
||
6415 |
levenshteinTo:aString s:substWeight k:kbdTypoWeight c:caseWeight i:insrtWeight d:deleteWeight |
|
6416 |
"parametrized levenshtein. |
|
6417 |
return the levenshtein distance to the argument, aString; |
|
6418 |
this value corrensponds to the number of replacements that have to be |
|
6419 |
made to get aString from the receiver. |
|
6420 |
The arguments are the costs for |
|
6421 |
s:substitution, |
|
6422 |
k:keyboard type (substitution), |
|
6423 |
c:case-change, |
|
6424 |
i:insertion |
|
6425 |
d:deletion |
|
6426 |
of a character. |
|
196 | 6427 |
See IEEE transactions on Computers 1976 Pg 172 ff" |
64 | 6428 |
|
6429 |
|d "delta matrix" |
|
196 | 6430 |
len1 "{ Class: SmallInteger }" |
6431 |
len2 "{ Class: SmallInteger }" |
|
6432 |
dim "{ Class: SmallInteger }" |
|
6433 |
prevRow row col |
|
6434 |
dimPlus1 "{ Class: SmallInteger }" |
|
64 | 6435 |
min pp c1 c2| |
6436 |
||
6437 |
len1 := self size. |
|
6438 |
len2 := aString size. |
|
6439 |
||
6440 |
"create the help-matrix" |
|
6441 |
||
6442 |
dim := len1 max:len2. |
|
6443 |
dimPlus1 := dim + 1. |
|
6444 |
||
6445 |
d := Array new:dimPlus1. |
|
6446 |
1 to:dimPlus1 do:[:i | |
|
7318 | 6447 |
d at:i put:(Array new:dimPlus1) |
64 | 6448 |
]. |
6449 |
||
6450 |
"init help-matrix" |
|
6451 |
||
6452 |
(d at:1) at:1 put:0. |
|
6453 |
row := d at:1. |
|
6454 |
1 to:dim do:[:j | |
|
7318 | 6455 |
row at:(j + 1) put:( (row at:j) + insrtWeight ) |
64 | 6456 |
]. |
6457 |
||
6458 |
1 to:dim do:[:i | |
|
7318 | 6459 |
(d at:(i + 1)) at:1 put:( ((d at:i) at:1) + deleteWeight ) |
64 | 6460 |
]. |
6461 |
||
6462 |
1 to:len1 do:[:i | |
|
7318 | 6463 |
c1 := self at:i. |
6464 |
1 to:len2 do:[:j | |
|
6465 |
c2 := aString at:j. |
|
6466 |
(c1 == c2) ifTrue:[ |
|
6467 |
pp := 0 |
|
6468 |
] ifFalse:[ |
|
6469 |
(c1 asLowercase == c2 asLowercase) ifTrue:[ |
|
6470 |
pp := caseWeight |
|
6471 |
] ifFalse:[ |
|
6472 |
pp := substWeight. |
|
6473 |
substWeight ~~ kbdTypoWeight ifTrue:[ |
|
6474 |
(DoWhatIMeanSupport isKey:c1 asLowercase nextTo:c2 asLowercase) ifTrue:[ |
|
6475 |
pp := kbdTypoWeight. |
|
6476 |
]. |
|
6477 |
]. |
|
6478 |
] |
|
6479 |
]. |
|
6480 |
prevRow := d at:i. |
|
6481 |
row := d at:(i + 1). |
|
6482 |
col := j + 1. |
|
6483 |
min := (prevRow at:j) + pp. |
|
6484 |
min := min min:( (row at:j) + insrtWeight). |
|
6485 |
min := min min:( (prevRow at:col) + deleteWeight). |
|
6486 |
row at:col put: min |
|
6487 |
] |
|
64 | 6488 |
]. |
6489 |
||
6490 |
^ (d at:(len1 + 1)) at:(len2 + 1) |
|
6491 |
! |
|
6492 |
||
608 | 6493 |
numArgs |
6494 |
"treating the receiver as a message selector, return how many arguments would it take" |
|
6495 |
||
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
6496 |
|binopChars firstChar| |
608 | 6497 |
|
6498 |
(self size > 2) ifFalse:[ |
|
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
6499 |
binopChars := Scanner binarySelectorCharacters. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
6500 |
firstChar := self at:1. |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
6501 |
|
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
6502 |
(self size == 1) ifTrue:[ |
7641 | 6503 |
(binopChars includes:firstChar) ifFalse:[^ 0]. |
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
6504 |
^ 1 |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
6505 |
]. |
7641 | 6506 |
(binopChars includes:firstChar) ifTrue:[ |
6507 |
(binopChars includes:(self at:2)) ifTrue:[^ 1] |
|
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
6508 |
] |
608 | 6509 |
]. |
6510 |
^ self occurrencesOf:$: |
|
6511 |
||
6512 |
" |
|
6513 |
'foo:bar:' numArgs |
|
6514 |
#foo:bar: numArgs |
|
6515 |
'hello' numArgs |
|
6516 |
'+' numArgs |
|
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
6517 |
'|' numArgs |
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
6518 |
'?' numArgs |
608 | 6519 |
" |
2051
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
6520 |
|
08fd6a693ee3
ask Scanner for valid binarySelector characters in numArgs
Claus Gittinger <cg@exept.de>
parents:
1978
diff
changeset
|
6521 |
"Modified: 4.1.1997 / 14:16:14 / cg" |
608 | 6522 |
! |
6523 |
||
6524 |
partsIfSelector |
|
6525 |
"treat the receiver as a message selector, return a collection of parts." |
|
6526 |
||
6527 |
|idx1 "{ Class: SmallInteger }" |
|
6528 |
coll idx2 sz| |
|
6529 |
||
6530 |
coll := OrderedCollection new. |
|
6531 |
idx1 := 1. |
|
6532 |
sz := self size. |
|
6533 |
[true] whileTrue:[ |
|
6534 |
idx2 := self indexOf:$: startingAt:idx1 + 1. |
|
6535 |
(idx2 == 0 or:[idx2 == sz]) ifTrue:[ |
|
6536 |
coll add:(self copyFrom:idx1). |
|
6537 |
^ coll |
|
6538 |
]. |
|
6539 |
coll add:(self copyFrom:idx1 to:idx2). |
|
6540 |
idx1 := idx2 + 1 |
|
6541 |
]. |
|
6542 |
||
6543 |
" |
|
6544 |
'foo:bar:' partsIfSelector |
|
6545 |
#foo:bar: partsIfSelector |
|
6546 |
'hello' partsIfSelector |
|
6547 |
'+' partsIfSelector |
|
6548 |
" |
|
6549 |
! |
|
6550 |
||
64 | 6551 |
spellAgainst: aString |
6552 |
"return an integer between 0 and 100 indicating how similar |
|
154 | 6553 |
the argument is to the receiver. No case conversion is done. |
6554 |
This algorithm is much simpler (but also less exact) than the |
|
6555 |
levenshtein distance. Experiment which is better for your |
|
6556 |
application." |
|
64 | 6557 |
|
6558 |
| i1 "{ Class: SmallInteger }" |
|
6559 |
i2 "{ Class: SmallInteger }" |
|
154 | 6560 |
next1 "{ Class: SmallInteger }" |
6561 |
next2 "{ Class: SmallInteger }" |
|
64 | 6562 |
size1 "{ Class: SmallInteger }" |
6563 |
size2 "{ Class: SmallInteger }" |
|
6564 |
score "{ Class: SmallInteger }" |
|
6565 |
maxLen "{ Class: SmallInteger }" | |
|
6566 |
||
6567 |
size1 := self size. |
|
6568 |
size2 := aString size. |
|
154 | 6569 |
maxLen := size1 max:size2. |
64 | 6570 |
score := 0. |
6571 |
i1 := i2 := 1. |
|
6572 |
[i1 <= size1 and: [i2 <= size2]] whileTrue:[ |
|
154 | 6573 |
next1 := i1 + 1. |
6574 |
next2 := i2 + 1. |
|
6575 |
(self at:i1) == (aString at:i2) ifTrue: [ |
|
6576 |
score := score+1. |
|
6577 |
i1 := next1. |
|
6578 |
i2 := next2 |
|
6579 |
] ifFalse: [ |
|
6580 |
(i2 < size2 and: [(self at:i1) == (aString at:next2)]) ifTrue: [ |
|
6581 |
i2 := next2 |
|
6582 |
] ifFalse: [ |
|
6583 |
(i1 < size1 and: [(self at:next1) == (aString at:i2)]) ifTrue: [ |
|
6584 |
i1 := next1 |
|
6585 |
] ifFalse: [ |
|
6586 |
i1 := next1. |
|
6587 |
i2 := next2 |
|
6588 |
] |
|
6589 |
] |
|
6590 |
] |
|
64 | 6591 |
]. |
6592 |
||
1124 | 6593 |
score == maxLen ifTrue: [^ 100]. |
154 | 6594 |
^ 100 * score // maxLen |
64 | 6595 |
|
154 | 6596 |
" |
6597 |
'Smalltalk' spellAgainst: 'Smalltlak' |
|
6598 |
'Smalltalk' spellAgainst: 'smalltlak' |
|
6599 |
'Smalltalk' spellAgainst: 'smalltalk' |
|
6600 |
'Smalltalk' spellAgainst: 'smalltlk' |
|
6601 |
'Smalltalk' spellAgainst: 'Smalltolk' |
|
6602 |
" |
|
1381 | 6603 |
! |
6604 |
||
6605 |
startsWith:aString |
|
4389
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4294
diff
changeset
|
6606 |
"return true, if the receiver starts with something, aString. |
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4294
diff
changeset
|
6607 |
If the argument is empty, true is returned." |
1381 | 6608 |
|
6609 |
|s| |
|
6610 |
||
6611 |
(s := self string) ~~ self ifTrue:[ |
|
6612 |
^ s startsWith:aString |
|
6613 |
]. |
|
6614 |
^ super startsWith:aString |
|
6615 |
||
6616 |
" |
|
6617 |
'hello world' startsWith:'hello' |
|
6618 |
'hello world' asText allBold startsWith:'hello' |
|
4389
3655a0fea430
definite (true) return for zero-length arg in #startsWith:
Claus Gittinger <cg@exept.de>
parents:
4294
diff
changeset
|
6619 |
'hello world' asText allBold startsWith:'' |
1381 | 6620 |
" |
6621 |
||
6622 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
6623 |
"Modified: 12.5.1996 / 15:49:24 / cg" |
|
64 | 6624 |
! ! |
6625 |
||
4662 | 6626 |
!CharacterArray methodsFor:'tracing'! |
6627 |
||
4682 | 6628 |
traceInto:aRequestor level:level from:referrer |
4662 | 6629 |
"double dispatch into tracer, passing my type implicitely in the selector" |
6630 |
||
4682 | 6631 |
^ aRequestor traceCharacterArray:self level:level from:referrer |
4662 | 6632 |
|
6633 |
||
6634 |
! ! |
|
6635 |
||
1849
9f35f5934ec6
added msdos-latin1 en/decoder (code = #msdos850)
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
6636 |
!CharacterArray class methodsFor:'documentation'! |
629 | 6637 |
|
6638 |
version |
|
7880 | 6639 |
^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.268 2004-02-06 09:03:12 cg Exp $' |
629 | 6640 |
! ! |
6809 | 6641 |
|
2728
7569e45a4d15
raise error signal if anything goes wrong while decoding.
Claus Gittinger <cg@exept.de>
parents:
2721
diff
changeset
|
6642 |
CharacterArray initialize! |